<?php 
#######################CHECK ERROR ###################################
date_default_timezone_set("America/Sao_Paulo");
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL); 
include 'chk.php';
######################################################################

$dbboxbra = new SQLite3('./api/.boxbr_dash.db');
$dbboxbra->exec('CREATE TABLE IF NOT EXISTS boxbrdash(id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL, 
title_name VARCHAR(100), 
ateam_id VARCHAR(100), 
bteam_brand VARCHAR(100), 
cteam_model VARCHAR(100), 
dteam_user VARCHAR(100),
status VARCHAR(100),
expire VARCHAR(100),
createdon VARCHAR(100))');

$rows = $dbboxbra->query('SELECT COUNT(*) as count FROM boxbrdash');
$row = $rows->fetchArray();
$numRows = $row['count'];
#$HOSTa = $lurl = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off') ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/img/boxbr_demo.png';
$date = date('Y-m-d H:i:s');

	if(isset($_GET['delete'])){

	$dbboxbra->exec('DELETE FROM boxbrdash WHERE id=' . $_GET['delete']);
	
	$msg = '?messageE=Item Deletado!';
	header('Location: dash.php'.$msg);
	}


include 'includes/header.php';

echo ' <!-- Begin Page Content -->' . "\n";
echo '        <div class="container-fluid">' . "\n";

if (isset($_GET['message'])) {
	echo '<div class="alert alert-danger bg-primary py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-check"></i> '.$_GET['message'].'</h4></div>';
}
if (isset($_GET['messageA'])) {
	echo '<div class="alert alert-danger bg-primary py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-check"></i> '.$_GET['messageA'].'</h4></div>';
}
if (isset($_GET['messageE'])) {
	echo '<div class="alert alert-danger bg-danger py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-times"></i> '.$_GET['messageE'].'</h4></div>';
}
if (isset($_GET['messageS'])) {
	echo '<div class="alert alert-danger bg-success py-3" id="flash-msg"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="icon fa fa-check"></i> '.$_GET['messageS'].'</h4></div>';
}

echo '          <!-- Content Row -->' . "\n";
echo '          <div class="row">' . "\n";
echo "\n";
echo '            <!-- First Column -->' . "\n";
echo '            <div class="col-lg-12">' . "\n";
echo "\n";
echo '              <!-- Custom codes -->' . "\n";
echo '                <div class="card text-primary">' . "\n";
echo '                 <div class="card-header bg-primary py-3">
                   
  
  <div class="item2"><h4 align="center" class="m-0 font-weight-bold text-white"><i class="fas fa-server" style="font-size:20px">&nbsp;&nbsp;</i>
  Gerenciador de Clientes</h4>
                			</div>
                </div>

                         <div id="dash" style = "display:nonxe"  class="card-body">' . "\n";


echo '
  <div class="input-group "><div class="input-group-prepend ">
<a class="btn btn-success btn-icon-split" href="./dash_create.php">
    <span class="icon text-white-50"><i class="fas fa-plus" ></i></span><span class="text"> Add Cliente</span></a>' . "\n";
echo '                        </button></a>' . "\n";
echo '  </div>
    <div class="input-group-prepend ">
    <span class="input-group-text " style="font-size:24px;color:#1cc88a"><i class="fas fa-search"></i></span></div>
    <input class="form-control" type="text" id="search" placeholder="Buscar Titulo / Data / Tipo ..."  name="search_value"/>
    <div class="input-group-prepend ">
	<!--		Show Numbers Of Rows 		-->

			 		<select class  ="input-group-text" name="state" id="maxRows"  style="width:150px;">
						 <option value="5000">Mostrar Todos</option>
						 <option value="5">Mostrar 5 </option>
						 <option value="10">Mostrar 10</option>
						 <option value="15">Mostrar 15<s/option>
						 <option value="20">Mostrar 20</option>
						 <option value="50">Mostrar 50</option>
						 <option value="70">Mostrar 70</option>
						 <option value="100">Mostrar 100</option>
						</select>
                    </div></div>' . "\n";
 echo '                                       
<hr>

<div class="table-responsive">
<table id="myTable" cellpadding="0" cellspacing="0" border="0" class="table stable-striped table-sm datatable stable-bordered">
							<thead align="center" class="text-primary">
								<tr>
								<th><strong>Cliente</strong></th>
								<th><strong>Usuario</strong></th>
								<th><strong>ID</strong></th>
								<th><strong>Marca</strong></th>
								<th><strong>Modelo</strong></th>
								<th><strong>Criado em</strong></th>
								<th><strong>Validade</strong></th>
								<th><strong>Status</strong></th>
								<th><strong>Editar</strong></th>
								<th><strong>Deletar</strong></th>
								</tr>
							</thead>' . "\n";

$dbboxbra = new SQLite3('./api/.boxbr_dash.db');	
$res = $dbboxbra->query('SELECT * FROM boxbrdash');
 while ($row = $res->fetchArray()) {

	  echo '  
							<tbody align="center">
								<tr class="text-primary">
								
								<td>'.$row['title_name'].'</td>
								<td>'.$row['dteam_user'].'</td>
								<td>'.$row['ateam_id'].'</td>
								<td>'.$row['bteam_brand'].'</td>
								<td>'.$row['cteam_model'].'</td>
								<td>'.$row['createdon'].'</td>
								<td>'.$row['expire'].'</td>
								<td>'.$row['status'].'</td>
								
								<td><a class="btn btn-success btn-icon" href="./dash_update.php?update='.$row['id'].'"><i class="fas fa-edit"></i></a></td>

								<td><a class="btn btn-danger btn-icon" href="./dash.php?delete='.$row['id'].'"><i class="fas fa-trash"></i></a></td>


								</tr>
							</tbody>
							' . "\n";  }
$dbboxbra->close();
	 echo ' 	</table>' . "\n";
echo "\t\t" . '</div>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

	<div class="pagination-container">
  <nav>
    <ul class="pagination pagination-lgn">
      <li class="page-item" data-page="prev">
      <a class="page-link" href="#"> < &nbsp;&nbsp;&nbsp; <span class="sr-only ">(current)</span></a>
      </li>
      <li class="page-item" data-page="next" id="prev">
      <a class="page-link" href="#"> &nbsp;&nbsp;&nbsp; > <span class="sr-only">(current)</span></a>
      </li>
    </ul>
  </nav>
  
</div>
' . "\n";
echo '</main>' . "\n";
echo "\n";
echo '           ' . "\n";
echo '            ' . "\n";
echo '    <br>' . "\n";
	?>

				<script type="text/javascript">
				//	getPagination('#table-id');
					//getPagination('.table-class');
					getPagination('table');

				</script>

<?php
echo '

<script>
      function myFunction(DIV) {
  var x = document.getElementById(DIV);
  var y = document.getElementById(DIV+"show");
  if (x.style.display === "none") {
    x.style.display = "block";
     y.className = "fa fa-minus";
  } else if (x.style.display === "block") {
 
    x.style.display = "none";
     y.className = "fa fa-plus";
  }else {
    x.style.display = "none";
     y.className = "fa fa-plus";
  }
}
  </script>

'."\n";
echo '
<script>
$("#search").keyup(function () {
    var value = this.value.toLowerCase().trim();

    $("table tr").each(function (index) {
        if (!index) return;
        $(this).find("td").each(function () {
            var id = $(this).text().toLowerCase().trim();
            var not_found = (id.indexOf(value) == -1);
            $(this).closest(\'tr\').toggle(!not_found);
            return not_found;
        });
    });
});
</script>' . "\n";
echo '    <script>' . "\n";
echo '$(\'#confirm-delete\').on(\'show.bs.modal\', function(e) {' . "\n";
echo '    $(this).find(\'.btn-ok\').attr(\'href\', $(e.relatedTarget).data(\'href\'));' . "\n";
echo '});' . "\n";
echo '    </script>' . "\n";

############# end ##############
include 'includes/footer.php';
require ('includes/boxbr.php');
print "</body>\n";
?>