

<?php

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

<?php 

// pickup the get variable

if (isset($_GET["idtrf"])) {

	$idtrf=$_GET["idtrf"]; }

if (isset($_POST["idtrf"])) {

	$idtrf=$_POST["idtrf"]; }



//include('include/alertcheckquery.php');



if (isset($_POST["virusprot"])) {

	$virusprot=$_POST["virusprot"]; }

else { $virusprot=""; }

if (isset($_POST["addinfo"])) {

	$addinfo=$_POST["addinfo"]; }

else { $addinfo=""; }

if (isset($_POST["slipping"])) {

	$slipping=$_POST["slipping"]; }

else { $slipping=""; }

if (isset($_POST["orthopedic"])) {

	$orthopedic=$_POST["orthopedic"]; }

else { $orthopedic=""; }

if (isset($_POST["autoclavable"])) {

	$autoclavable=$_POST["autoclavable"]; }

else { $autoclavable=""; }

if (isset($_POST["esd"])) {

	$esd=$_POST["esd"]; }

else { $esd=""; }

if (isset($_POST["ukcacert"])) {

	$ukcacert=$_POST["ukcacert"]; }

else { $ukcacert=""; }

if (isset($_POST["addreq"])) {

	$addreq=$_POST["addreq"]; }

if (isset($_POST["addreqform"])) {

	$addreqform=$_POST["addreqform"]; }

else { $addreqform=""; }

if (isset($_POST["codestep"])) {

	$code="5"; 



  $InsertQuery = new WA_MySQLi_Query($cmctrfdb);

  $InsertQuery->Action = "insert";

  $InsertQuery->Table = "wheretrfstep";

  $InsertQuery->bindColumn("idtrf", "i", "$idtrf", "WA_DEFAULT");

  $InsertQuery->bindColumn("code", "i", "$code", "WA_DEFAULT");

  $InsertQuery->saveInSession("");

  $InsertQuery->execute();

  $InsertGoTo = "";



  $InsertQuery->redirect($InsertGoTo);

	}

?>

<?php

	$conn = mysqli_connect($hostname_cmctrfdb, $username_cmctrfdb, $password_cmctrfdb, $database_cmctrfdb);

if (!$conn) {

    die("Connessione al database fallita: " . mysqli_connect_error());

}



// Controllo dei campi nulli



$sql = "SELECT COUNT(*) AS num_rows FROM trfstandards WHERE idtrfdetails = $idtrf AND (idprotectioncategory IS NULL OR iddpicategory IS NULL)";

$resultcat = mysqli_query($conn, $sql);

// Controllo degli errori

if (!$resultcat) {

    die("Errore nella query: " . mysqli_error($conn));

}

/*$row = mysqli_fetch_assoc($resultcat);

 if ($row['num_rows'] > 0) {

    // Campi nulli trovati, torna alla pagina standardstep.php e mostra il messaggio di errore

    header("Location: standardstep.php?idtrf=$idtrf&error=tuttiicampidevonoesserericompilati");

    exit;

}*/

?>

<?php



$trfnumberfinal = new WA_MySQLi_RS("trfnumberfinal",$cmctrfdb,1);

$trfnumberfinal->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.idtrfdetails='$idtrf'");

$trfnumberfinal->execute();

$idcertn=$trfnumberfinal->getColumnVal("idcertification");

$idstandards=$trfnumberfinal->getColumnVal("idstandards");

$idarticletype=$trfnumberfinal->getColumnVal("idarticletype");

?>

<?php

$standardlistsel = new WA_MySQLi_RS("standardlistsel",$cmctrfdb,0);

$standardlistsel->setQuery("SELECT * FROM trfstandards WHERE trfstandards.idtrfdetails='$idtrf'");

$standardlistsel->execute();

?>

<?php



$arraystd=array();   ?>

<?php

$wa_startindex = 0;

while(!$standardlistsel->atEnd()) {

  $wa_startindex = $standardlistsel->Index;

?>

<?php

$idstandards=$standardlistsel->getColumnVal("idstandards");

$arraystd[]=$idstandards;



?>



<?php

  $standardlistsel->moveNext();

}

$standardlistsel->moveFirst(); //return RS to first record

unset($wa_startindex);

unset($wa_repeatcount);

$array2std=implode("','",$arraystd);

$array3std="'".$array2std."'";

?>





<?php $idcert=$trfnumberfinal->getColumnVal("idcertification") ?>

<?php

$certname = new WA_MySQLi_RS("certname",$cmctrfdb,1);

$certname->setQuery("SELECT * FROM certificationtype WHERE certificationtype.idcertificationtype='$idcert'");

$certname->execute();?>

<?php //complete list add req

//$addreqlist = new WA_MySQLi_RS("addreqlist",$cmctrfdb,0);

//$addreqlist->setQuery("SELECT * FROM additionalrequirements WHERE additionalrequirements.idarticletype='$idarticletype' ORDER BY additionalrequirements.name_additionalrequirements");

//$addreqlist->execute();?>



<?php //  specific list of add req for std

// Determine the column to select based on the session variable

$additionalRequirementsField = ($_SESSION['langselect'] == 'en') ? 'name_additionalrequirements_en' : 'name_additionalrequirements_it';



// Specific list of add req for std

$addreqlist = new WA_MySQLi_RS("addreqlist", $cmctrfdb, 0);

$addreqlist->setQuery("SELECT DISTINCT stdreqlist.idadditionalrequirements, additionalrequirements." . $additionalRequirementsField . " FROM stdreqlist LEFT JOIN additionalrequirements ON stdreqlist.idadditionalrequirements=additionalrequirements.idadditionalrequirements WHERE stdreqlist.idstandards IN ($array3std)");

$addreqlist->execute();



?>

<?php



if ($addinfo=="Y") {

  $UpdateQuery = new WA_MySQLi_Query($cmctrfdb);

  $UpdateQuery->Action = "update";

  $UpdateQuery->Table = "`trf-details`";

  $UpdateQuery->bindColumn("virusprotection", "s", "$virusprot", "WA_DEFAULT");

  $UpdateQuery->bindColumn("shoesorthopedic", "s", "$orthopedic", "WA_DEFAULT");

  $UpdateQuery->bindColumn("autoclavable", "s", "$autoclavable", "WA_DEFAULT");

  $UpdateQuery->bindColumn("esd", "s", "$esd", "WA_DEFAULT");

  $UpdateQuery->bindColumn("slipping", "s", "$slipping", "WA_DEFAULT");

  $UpdateQuery->addFilter("idtrfdetails", "=", "i", "".($idtrf)  ."");

  $UpdateQuery->execute();

  $UpdateGoTo = "";

  if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";

  $UpdateQuery->redirect($UpdateGoTo);

} 

?>

<?php 

if ($addreqform=="Y") {

	

	

$addreqcheck = new WA_MySQLi_RS("addreqcheck",$cmctrfdb,1);

$addreqcheck->setQuery("SELECT * FROM trfaddrequirements WHERE trfaddrequirements.idtrf='$idtrf' AND trfaddrequirements.idadditionalrequirements='$addreq'");

$addreqcheck->execute();

 if (empty($addreqcheck->getColumnVal("idtrfaddrequirements"))) {



	

  $InsertQuery = new WA_MySQLi_Query($cmctrfdb);

  $InsertQuery->Action = "insert";

  $InsertQuery->Table = "trfaddrequirements";

  $InsertQuery->bindColumn("idtrf", "i", "$idtrf", "WA_DEFAULT");

  $InsertQuery->bindColumn("idadditionalrequirements", "i", "$addreq", "WA_DEFAULT");

  $InsertQuery->saveInSession("");

  $InsertQuery->execute();

  $InsertGoTo = "";

  if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";

  $InsertQuery->redirect($InsertGoTo);

}}

?>

<?php 

$addreqselectedlist = new WA_MySQLi_RS("addreqselectedlist",$cmctrfdb,0);

$addreqselectedlist->setQuery("SELECT * FROM trfaddrequirements LEFT JOIN additionalrequirements ON trfaddrequirements.idadditionalrequirements=additionalrequirements.idadditionalrequirements WHERE trfaddrequirements.idtrf='$idtrf'");

$addreqselectedlist->execute();?>



<!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">

							<div class="card">

                                <div class="card-body">

                                    <div class="media">

							

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

                                    </div><!--end media-->

                                                                          

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

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

							

							<div class="progress mb-4">

                              <div class="progress-bar" role="progressbar" style="width: 70%;" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">70%</div>

                          </div>

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

							

                          <div class="card">

                                <div class="card-body">

                                    <h4 class="mt-0 header-title"><?php echo $additionalreqtitle; ?></h4>

                                    <p class="text-muted mb-3"><?php echo $additionalreqtitle_help; ?></p> 

                            <form class="form-parsley" action="" method="post" name="myForm">

                                       <div class="form-group row">

                                                <?php // var for language translation table name and help

										   $colvarname=$addreqlist->getColumnVal("name_additionalrequirements");

										   $varnamelang=$colvarname.$lang;

										   $varhelplang="additionalrequirements_".$lang;

										   ?>

                                                <div class="col-sm-5">

                                                  <select class="form-control" id="addreq" name="addreq">

                                                      <option value=""><?php echo $pleaseselect; ?></option>

                                                      <?php

while(!$addreqlist->atEnd()) { //dyn select

?><?php

// Assuming the session_start() has been called earlier in the PHP code to start the session.

$nameField = ($_SESSION['langselect'] == 'en') ? "name_additionalrequirements_en" : "name_additionalrequirements_it";

?>



<option value="<?php echo($addreqlist->getColumnVal("idadditionalrequirements")); ?>">

    <?php echo($addreqlist->getColumnVal($nameField)); ?>

</option>                                                    <?php

  $addreqlist->moveNext();

} //dyn select

$addreqlist->moveFirst();

?>

                                                  </select>

                                                </div>

                                </div>



										

										

								  

							<input type="hidden" name="addreqform" id="addreqform" value="Y">

								  <input type="hidden" name="idtrf" id="idtrf" value="<?php echo($trfnumberfinal->getColumnVal("idtrfdetails")); ?>">

								  

								<br><br>

										<input type="button" onclick="formSubmit()" class="btn btn-gradient-success waves-effect waves-light" value="<?php echo $addtitle; ?>">

										

										</div>

                            </form>

								

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

							

						  <!-- card for show requirements -->

							<div class="card">

                              <div class="card-body">

                                    <h4 class="mt-0 header-title"><?php echo $additionalreqtitleselected; ?></h4>

                                <p class="text-muted mb-3"><?php echo $additionalreqtitleselected_help; ?></p> 

                             

								 

								  <table class="table table-striped mb-0">

									    <thead>

									      <tr>

									        <th><?php echo $addreqtitle; ?></th>

									        

									        <th><?php echo $action; ?></th>

								          </tr>

							        </thead>

									    <tbody>

									       <?php

$wa_startindex = 0;

while(!$addreqselectedlist->atEnd()) {

  $wa_startindex = $addreqselectedlist->Index;

?>

									      <tr>

									        <td>

    <?php

    // Assuming session_start() has already been called.

    $nameField = ($_SESSION['langselect'] == 'en') ? 'name_additionalrequirements_en' : 'name_additionalrequirements_it';

    echo($addreqselectedlist->getColumnVal($nameField));

    ?>

</td>

									        <td>                                                       

									          

									          <a href="deleteaddreq.php?idaddreq=<?php echo($addreqselectedlist->getColumnVal("idtrfaddrequirements")); ?>&idtrf=<?php echo $idtrf; ?>"><i class="fas fa-trash-alt text-danger font-16"></i></a>

								            </td>

								          </tr>

									      <?php

  $addreqselectedlist->moveNext();

}

$addreqselectedlist->moveFirst(); //return RS to first record

unset($wa_startindex);

unset($wa_repeatcount);

?>

									      

									      

							        </tbody>

							    </table>

								  

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

								  <?php if (!empty($chemicalstep)) { ?>

									  <a href="chemicalagent.php?idtrf=<?php echo $idtrf; ?>&codestep=5"><button type="button" class="btn btn-success waves-effect waves-light"><?php echo $nextsteptitle; ?></button> </a> 

								  <?php } else { ?>

								  	<a href="identificationparts.php?idtrf=<?php echo $idtrf; ?>&codestep=6"><button type="button" class="btn btn-success waves-effect waves-light"><?php echo $nextsteptitle; ?></button> </a>

								  <?php } ?>

								<button type="button" class="btn btn-dark waves-effect waves-light" onclick="history.back()"><?php echo $backstep; ?></button> 

                              </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>