<?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';
######################################################################

$db = new SQLite3('./api/.boxbr_dash.db');
$res = $db->query('SELECT * FROM boxbrdash WHERE id=\'' . $_GET['update'] . '\'');
$row = $res->fetchArray();
$upu = '&update='.$_GET['update'];

if (isset($_POST['submit'])) {
	
	$createdon = date('Y-m-d H:i:s');
    $db->exec('INSERT INTO boxbrdash(title_name,ateam_id, bteam_brand, cteam_model, dteam_user, status, expire, createdon)
    VALUES(
    \'' . $_POST['title_name'] . '\',
    \'' . $_POST['ateam_id'] . '\',
    \'' . $_POST['bteam_brand'] . '\', 
    \''.$_POST['cteam_model'].'\',
    \''.$_POST['dteam_user'].'\',
    \''.$_POST['status'].'\',
    \''.$_POST['expire'].'\',
    \'' . $createdon . '\')');


	$db->close();
	$msg = '?message=Item Adicionado!';
	header('Location: dash.php'.$msg);
	
	

}

include ('includes/header.php');

echo ' <!-- Begin Page Content -->' . "\n";
echo '        <div class="container-fluid">' . "\n";
echo "\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-text-primary">' . "\n";
echo '                <div class="card-header bg-primary py-3">' . "\n";
echo '                <center><h4 align="center" class="m-0 text-white"><i class="fas fa-server" style="font-size:20px">&nbsp;&nbsp;</i> Adicionar Cliente</h4>
                        
						</center>
' . "\n";

echo '                </div>' . "\n";

?>

                         <div class="card-body">
								<form method="post" enctype="multipart/form-data">
                         <div class="form-group">
                          <label class="bmd-label-floating"><strong>Nome do Cliente</strong></label>
                          <input type="text" id="title" class="form-control text-primary" name="title_name" >
                        </div>
						  
							<div class="form-group ">
                             <label class="control-label"><strong> Usuario</strong></label>
                                <div class="input-group">
                                 <input  class="form-control" type="text" name="dteam_user" placeholder="">
                                </div>
                             </div>
                         
							<div class="form-group ">
                             <label class="control-label"><strong> ID do Dispositivo</strong></label>
                                <div class="input-group">
                                 <input  class="form-control" type="text" name="ateam_id" placeholder="">
                                </div>
                             </div>
                         
							<div class="form-group ">
                             <label class="control-label"><strong> Marca  do Dispositivo</strong></label>
                                <div class="input-group">
                                 <input  class="form-control" type="text" name="bteam_brand" placeholder="">
                                </div>
                             </div>
                         
							<div class="form-group ">
                             <label class="control-label"><strong> Modelo  do Dispositivo</strong></label>
                                <div class="input-group">
                                 <input  class="form-control" type="text" name="cteam_model" placeholder="">
                                </div>
                             </div>
							<div class="form-group ">
                             <label class="control-label"><strong> Tempo de uso</strong></label>
                                <div class="input-group">
                                 <input  class="form-control" id="datetimepicker" type="text" name="expire" placeholder="">
                                </div>
                             </div>
						 
						    <div class="form-group ">
                                   <label class="control-label " for="vpn_config">
                                       <strong>Status do Usuario</strong>
                                  </label>
                                 <div class="input-group">
									  <select class="form-control status" id="status" name="status">
										  <option data-value="op0" value="Ativo" selected>Ativo
										  </option>
										  <option data-value="op1" value="Inativo">Inativo
									  </select>
                                    </div>
                                </div>
							
                        <div align="center" class="form-group mb-3">
									<br>
										<button class="btn btn-success btn-icon-split" name="submit" type="submit"><span class="icon text-white-50"><i class="fas fa-save"></i>&nbsp;&nbsp;</span><span class="text"> Salvar Dados</span></button>
                                </div>
                            </form>
                            </div>
                        </div>
                    </div>
                    <!-- Column -->
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
//select activecode form
//var response = {};
//response.val = "op2";
//$("#codemode option[data-value='" + response.val +"']").attr("selected","selected");

//hide activecode form
$('.actived').show(); 

$('.activeu').hide(); 


//Show/hide activecode select
$(document).ready(function(){
  $('.linktype').change(function(){
    if($('.linktype').val() > 0) {
      $('.actived').hide(); 
      $('.activeu').show(); 
    } else {
      $('.activeu').hide(); 
      $('.actived').show(); 
     document.getElementById("activeu").value = ' ';
    } 
  });
  $('.linktype').ready(function(){
    if($('.linktype').val() > 0) {
      $('.actived').hide(); 
      $('.activeu').show(); 
    }else {
      $('.activeu').hide(); 
      $('.actived').show(); 
     document.getElementById("actived").value = ' ';
      
    } 
  });
});
</script>
<script>
function formSubmit(radioObj){
  if(radioObj.checked){
    document.getElementById("onoff").submit();

  }
}
</script>
<?php
// JAVA TARGET
echo '<script>';
echo 'function uploadintro(target) {' . "\n";
echo "\t" . 'document.getElementById("image-intro").innerHTML = target.files[0].name;' . "\n";
echo '}' . "\n";
echo "\n";
echo '$(document).ready(function() {' . "\n";
echo '    if (location.hash) {' . "\n";
echo '        $("a[href=\'" + location.hash + "\']").tab("show");' . "\n";
echo '    }' . "\n";
echo '    $(document.body).on("click", "a[data-toggle=\'tab\']", function(event) {' . "\n";
echo '        location.hash = this.getAttribute("href");' . "\n";
echo '    });' . "\n";
echo '});' . "\n";
echo '$(window).on("popstate", function() {' . "\n";
echo '    var anchor = location.hash || $("a[data-toggle=\'tab\']").first().attr("href");' . "\n";
echo '    $("a[href=\'" + anchor + "\']").tab("show");' . "\n";
echo '});' . "\n";
echo "\n";
echo '</script>';
//INCLUDE FUNCTIONS
echo '    <br><br><br>';
include 'includes/footer.php';
require 'includes/boxbr.php';
echo '      </body>' . "\n";

?>