<?php
include('include/headscript.php'); ?>

<?php
// pickup the get variable
if (isset($_GET["idstandards"])) {
  $idstandards = $_GET["idstandards"];
}



?>
<?php
$standarddetail = new WA_MySQLi_RS("standarddetail", $cmctrfdb, 0);
$standarddetail->setQuery("SELECT * FROM standards WHERE standards.idstandards='$idstandards' ORDER BY standards.idarticletype, standards.standardcode");
$standarddetail->execute();

?>
<?php
$articletypelist = new WA_MySQLi_RS("articletypelist", $cmctrfdb, 0);
$articletypelist->setQuery("SELECT * FROM article_type ORDER BY article_type.name_articletype");
$articletypelist->execute();
?>
<?php
$articlecharacteristiclist = new WA_MySQLi_RS("articlecharacteristiclist", $cmctrfdb, 0);
$articlecharacteristiclist->setQuery("SELECT * FROM article_characteristic ORDER BY article_characteristic.idarticletype, article_characteristic.name_articlecharacteristic");
$articlecharacteristiclist->execute();
?>
<?php
$categorydpilist = new WA_MySQLi_RS("categorydpilist", $cmctrfdb, 0);
$categorydpilist->setQuery("SELECT * FROM dpicategory ORDER BY dpicategory.value_dpicategory");
$categorydpilist->execute(); ?>
<?php
$idarticletypen = $standarddetail->getColumnVal("idarticletype");
$articletypesel = new WA_MySQLi_RS("articletypesel", $cmctrfdb, 1);
$articletypesel->setQuery("SELECT * FROM article_type WHERE article_type.idarticletype='$idarticletypen'");
$articletypesel->execute(); ?>
<?php
$idarticlecharacteristicn = $standarddetail->getColumnVal("idarticlecharacteristic");
$artcharactcheck = new WA_MySQLi_RS("artcharactcheck", $cmctrfdb, 1);
$artcharactcheck->setQuery("SELECT * FROM article_characteristic WHERE article_characteristic.idarticlecharacteristic='$idarticlecharacteristicn'");
$artcharactcheck->execute(); ?>
<?php
$iddpicategoryn = $standarddetail->getColumnVal("iddpicategory");
$dpicategorycheck = new WA_MySQLi_RS("dpicategorycheck", $cmctrfdb, 1);
$dpicategorycheck->setQuery("SELECT * FROM dpicategory WHERE dpicategory.iddpicategory='$iddpicategoryn'");
$dpicategorycheck->execute();
?>
<?php
if (isset($formnameedit)) {
  echo "Ciao";
  $UpdateQuery = new WA_MySQLi_Query($cmctrfdb);
  $UpdateQuery->Action = "update";
  $UpdateQuery->Table = "standards";
  $UpdateQuery->bindColumn("fmidstandards", "i", "" . ((isset($_POST["fmcode"])) ? $_POST["fmcode"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("standardname", "s", "" . ((isset($_POST["itastdname"])) ? $_POST["itastdname"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("standardname_eng", "s", "" . ((isset($_POST["engstdname"])) ? $_POST["engstdname"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("standardcode", "s", "" . ((isset($_POST["standardcode"])) ? $_POST["standardcode"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("idarticletype", "i", "" . ((isset($_POST["idarticletype"])) ? $_POST["idarticletype"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("idarticlecharacteristic", "i", "" . ((isset($_POST["articlecharact"])) ? $_POST["articlecharact"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("iddpicategory", "i", "" . ((isset($_POST["categorydpi"])) ? $_POST["categorydpi"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("virusset", "s", "" . ((isset($_POST["virusprotection"])) ? $_POST["virusprotection"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->bindColumn("chemicalsset", "s", "" . ((isset($_POST["chemicalagent"])) ? $_POST["chemicalagent"] : "")  . "", "WA_DEFAULT");
  $UpdateQuery->addFilter("idstandards", "=", "i", "" . ($idstandards)  . "");
  $UpdateQuery->execute();
  $UpdateGoTo = "";
  if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo ? rel2abs($UpdateGoTo, dirname(__FILE__)) : "";
  $UpdateQuery->redirect($UpdateGoTo);
}
?>


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>TRF CIMAC </title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta content="CIMAC TRF Portal" name="description" />
  <meta content="" name="author" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />

  <!-- App favicon -->
  <link rel="shortcut icon" href="../images/favicon.ico">

  <!--Form Wizard-->
  <link href="../plugins/jquery-steps/jquery.steps.css" rel="stylesheet" type="text/css">

  <!-- App css -->
  <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  <link href="assets/css/jquery-ui.min.css" rel="stylesheet">
  <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
  <link href="assets/css/metisMenu.min.css" rel="stylesheet" type="text/css" />
  <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />


  <!-- submit form with button -->
  <script>
    function formSubmit() {
      document.forms["myForm"].submit();
    }
  </script>


</head>

<body>

  <!-- Top Bar Start -->
  <?php include('include/topbar.php'); ?>
  <!-- Top Bar End -->


  <!-- Left Sidenav -->
  <?php include('include/leftsidenav.php'); ?>
  <!-- end left-sidenav-->

  <div class="page-wrapper">
    <!-- Page Content-->
    <div class="page-content">

      <div class="container-fluid">
        <!-- Page-Title -->
        <div class="row">
          <div class="col-sm-12">
            <div class="page-title-box">
              <div class="float-right">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="javascript:void(0);">TRF</a></li>
                  <li class="breadcrumb-item active">Starter</li>
                </ol>
              </div>
              <h4 class="page-title"><?php echo $titlewb; ?></h4>
            </div><!--end page-title-box-->
          </div><!--end col-->
        </div>
        <div class="row">
          <div class="col-sm-12">



            <!-- card for additional info gloves -->

            <!--end card-body-->

            <!-- card for show requirements -->
            <div class="card">
              <div class="card-body">
                <h4 class="mt-0 header-title">Gestione Standards</h4>
                <p class="text-muted mb-3">Da questa pagina puoi gestire gli standards e tutti i dati correlati</p>
                <form class="was-validated" action="admin-standards.php" method="post" name="myForm">
                  <div class="form-group row">
                    <label for="standardcode" class="col-sm-2 col-form-label text-right">Standard Code</label>
                    <div class="col-sm-10">
                      <input class="form-control" type="text" value="<?php echo ($standarddetail->getColumnVal("standardcode")); ?>" id="standardcode" name="standardcode">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label for="itastdname" class="col-sm-2 col-form-label text-right">Nome STD Italiano</label>
                    <div class="col-sm-10">
                      <input class="form-control" type="text" value="<?php echo ($standarddetail->getColumnVal("standardname")); ?>" id="itastdname" name="itastdname">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label for="engstdname" class="col-sm-2 col-form-label text-right">Nome STD Inglese</label>
                    <div class="col-sm-10">
                      <input class="form-control" type="text" value="<?php echo ($standarddetail->getColumnVal("standardname_eng")); ?>" id="engstdname" name="engstdname">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label for="fmcode" class="col-sm-2 col-form-label text-right">Codice FM</label>
                    <div class="col-sm-10">
                      <input class="form-control" type="text" value="<?php echo ($standarddetail->getColumnVal("fmidstandards")); ?>" id="fmcode" name="fmcode">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label text-right">Tipologia Articolo</label>
                    <div class="col-sm-10">
                      <select class="form-control" name="idarticletype" id="idarticletype">
                        <option value="" <?php if (!(strcmp("", ($articletypesel->getColumnVal("idarticletype"))))) {
                                            echo "selected=\"selected\"";
                                          } ?>>Seleziona</option>
                        <?php
                        while (!$articletypelist->atEnd()) { //dyn select
                        ?>
                          <option value="<?php echo ($articletypelist->getColumnVal("idarticletype")); ?>" <?php if (!(strcmp($articletypelist->getColumnVal("idarticletype"), ($articletypesel->getColumnVal("idarticletype"))))) {
                                                                                                            echo "selected=\"selected\"";
                                                                                                          } ?>><?php echo ($articletypelist->getColumnVal("name_articletype")); ?></option>
                        <?php
                          $articletypelist->moveNext();
                        } //dyn select
                        $articletypelist->moveFirst();
                        ?>
                      </select>
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label text-right">Caratteristiche Articolo</label>
                    <div class="col-sm-10">
                      <select class="form-control" id="articlecharact" name="articlecharact">
                        <option value="" <?php if (!(strcmp("", ($standarddetail->getColumnVal("idarticlecharacteristic"))))) {
                                            echo "selected=\"selected\"";
                                          } ?>>Seleziona</option>
                        <?php
                        while (!$articlecharacteristiclist->atEnd()) { //dyn select
                        ?>
                          <option value="<?php echo ($articlecharacteristiclist->getColumnVal("idarticlecharacteristic")); ?>" <?php if (!(strcmp($articlecharacteristiclist->getColumnVal("idarticlecharacteristic"), ($standarddetail->getColumnVal("idarticlecharacteristic"))))) {
                                                                                                                                echo "selected=\"selected\"";
                                                                                                                              } ?>><?php echo ($articlecharacteristiclist->getColumnVal("name_articlecharacteristic")); ?></option>
                        <?php
                          $articlecharacteristiclist->moveNext();
                        } //dyn select
                        $articlecharacteristiclist->moveFirst();
                        ?>
                      </select>
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label text-right">Categoria DPI</label>
                    <div class="col-sm-10">
                      <select class="form-control" id="categorydpi" name="categorydpi">
                        <option value="" <?php if (!(strcmp("", ($standarddetail->getColumnVal("iddpicategory"))))) {
                                            echo "selected=\"selected\"";
                                          } ?>>Seleziona</option>
                        <?php
                        while (!$categorydpilist->atEnd()) { //dyn select
                        ?>
                          <option value="<?php echo ($categorydpilist->getColumnVal("iddpicategory")); ?>" <?php if (!(strcmp($categorydpilist->getColumnVal("iddpicategory"), ($standarddetail->getColumnVal("iddpicategory"))))) {
                                                                                                            echo "selected=\"selected\"";
                                                                                                          } ?>><?php echo ($categorydpilist->getColumnVal("value_dpicategory")); ?></option>
                        <?php
                          $categorydpilist->moveNext();
                        } //dyn select
                        $categorydpilist->moveFirst();
                        ?>
                      </select>
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-sm-2 col-form-label text-right">Active</label>
                    <div class="col-sm-10">
                      <select class="form-control" id="active" name="active">
                        <option value="" <?php if (!(strcmp("", ($standarddetail->getColumnVal("active"))))) {
                                            echo "selected=\"selected\"";
                                          } ?>>Seleziona</option>
                        <option value="Y" <?php if (!(strcmp("Y", ($standarddetail->getColumnVal("active"))))) {
                                            echo "selected=\"selected\"";
                                          } ?>>Y</option>
                        <option value="N" <?php if (!(strcmp("N", ($standarddetail->getColumnVal("active"))))) {
                                            echo "selected=\"selected\"";
                                          } ?>>N</option>
                      </select>
                    </div>
                  </div>


                  <div class="custom-control custom-checkbox">
                    <input <?php if (!(strcmp(($standarddetail->getColumnVal("virusset")), "Y"))) {
                              echo "checked=\"checked\"";
                            } ?> type="checkbox" class="custom-control-input" id="virusprotection" name="virusprotection" value="Y" data-parsley-multiple="groups" data-parsley-mincheck="2">
                    <label class="custom-control-label" for="virusprotection">Protezione Virus</label>
                  </div>
                  <br>
                  <div class="custom-control custom-checkbox">
                    <input <?php if (!(strcmp(($standarddetail->getColumnVal("chemicalsset")), "Y"))) {
                              echo "checked=\"checked\"";
                            } ?> type="checkbox" class="custom-control-input" id="chemicalagent" name="chemicalagent" value="Y" data-parsley-multiple="groups" data-parsley-mincheck="2">
                    <label class="custom-control-label" for="chemicalagent">Agenti Chimici</label>
                  </div>
                  <br>

                  <input type="hidden" name="idstandards" id="idstandards" value="<?php echo $idstandards; ?>">
                  <input type="hidden" name="formnameedit" id="formnameedit" value="stdeditform">
                  <input type="button" onclick="formSubmit()" class="btn btn-gradient-success waves-effect waves-light" value="Aggiorna"><br>

                </form>



              </div><!--end card-body-->


            </div><!--end card-->




          </div><!--end col-->
        </div>
        <!-- end page title end breadcrumb -->


      </div><!-- container -->
      <!-- footer start -->
      <?php include('include/footer.php'); ?>
      </footer><!--end footer-->
    </div>
    <!-- end page content -->
  </div>
  <!-- end page-wrapper -->




  <!-- jQuery  -->
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/js/bootstrap.bundle.min.js"></script>
  <script src="assets/js/metismenu.min.js"></script>
  <script src="assets/js/waves.js"></script>
  <script src="assets/js/feather.min.js"></script>
  <script src="assets/js/jquery.slimscroll.min.js"></script>
  <script src="assets/js/jquery-ui.min.js"></script>

  <script src="../plugins/jquery-steps/jquery.steps.min.js"></script>
  <script src="assets/pages/jquery.form-wizard.init.js"></script>

  <!-- App js -->
  <script src="assets/js/app.js"></script>

</body>

</html>