<?php
   include('include/headscript.php');
?>
<?php
   // pickup the get variable
   if (isset($_POST["idtrf"])) {
       $idtrf=$_POST["idtrf"];
   }
   if (isset($_GET["idtrf"])) {
       $idtrf=$_GET["idtrf"];
   }
?>
<?php
   $trfnumberfinal = new WA_MySQLi_RS("trfnumberfinal", $cmctrfdb, 1);
   $trfnumberfinal->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.idtrfdetails='$idtrf'");
   $trfnumberfinal->execute();
   $idarticletype=$trfnumberfinal->getColumnVal("idarticletype");
   ?>
<?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
   $listinsertedpart = new WA_MySQLi_RS("listinsertedpart", $cmctrfdb, 0);
   $listinsertedpart->setQuery("SELECT * FROM identificationparts WHERE identificationparts.idtrfdetails='$idtrf'");
   $listinsertedpart->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" />

      <!-- Plugins css -->

      <link href="../plugins/daterangepicker/daterangepicker.css" rel="stylesheet" />

      <link href="../plugins/select2/select2.min.css" rel="stylesheet" type="text/css" />

      <link href="../plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet" type="text/css" />

      <link href="../plugins/timepicker/bootstrap-material-datetimepicker.css" rel="stylesheet">

      <link href="../plugins/bootstrap-touchspin/css/jquery.bootstrap-touchspin.min.css" rel="stylesheet" />

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

                           <div class="avatar-box thumb-xl align-self-center mr-2">

                              <span class="avatar-title bg-soft-purple rounded">TRF</span>

                           </div>

                           <div class="media-body align-self-center">

                              <h4 class="mt-0 header-title"><?php echo $etrfcodetitle; ?> <?php echo($trfnumberfinal->getColumnVal("iduser")); ?>-<?php echo($trfnumberfinal->getColumnVal("trfnumber")); ?></h4>

                              <p class="mt-0 header-title"><?php echo $certificationrequired; ?><?php echo($certname->getColumnVal("name_certification")); ?></p>

                           </div>

                           <!--end media-body-->

                        </div>

                        <!--end media-->

                     </div>

                     <!--end card-body-->

                  </div>

                  <!--end card-->

                  <div class="progress mb-4">

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

                  </div>

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

                  <!-- card for show requirements -->

                  <div class="card">

                     <div class="card-body">

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

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

                        <p>

                           <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#newpart" aria-expanded="false" aria-controls="newpart">

                           <?php echo $newtest; ?>
                           </button>

                           <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#cmcpart" aria-expanded="false" aria-controls="cmcpart">

                           <?php echo $oldcmctest; ?>
                           </button>

                           <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#thirdpart" aria-expanded="false" aria-controls="thirdpart">

                           <?php echo $trdparttest; ?>
                           </button>

                        </p>

                        <div class="collapse" id="newpart">

                           <div class="card">

                              <div class="card-body">

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

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

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

                                    <!-- div new parts -->

                                    <div class="form-row">

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer01"><?php echo $descriptionpart; ?></label>

                                          <input type="text" class="form-control is-valid" id="descriptionpartvalue" name="descriptionpartvalue" placeholder="<?php echo $descriptionpart; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer02"><?php echo $articlepart; ?></label>

                                          <input type="text" class="form-control is-valid" id="articlepartvalue" name="articlepartvalue"  placeholder="<?php echo $articlepart; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServerUsername"><?php echo $colorpart; ?></label>

                                          <div class="input-group">

                                             <div class="input-group-prepend">

                                             </div>

                                             <input type="text" class="form-control" id="colorvalue" name="colorvalue" placeholder="<?php echo $colorpart; ?>" aria-describedby="inputGroupPrepend3" required="">

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

                                             <input type="hidden" name="kindoftest" id="kindoftest" value="new">

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

                                          </div>

                                       </div>

                                    </div>

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

                                 </form>

                              </div>

                              <!--end card-body-->

                           </div>

                        </div>

                        <!-- end -->

                        <!-- div CMC parts -->

                        <div class="collapse" id="cmcpart">

                           <div class="card">

                              <div class="card-body">

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

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

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

                                    <!-- div new parts -->

                                    <div class="form-row">

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer01"><?php echo $descriptionpart; ?></label>

                                          <input type="text" class="form-control is-valid" id="descriptionpartvalue" name="descriptionpartvalue" placeholder="<?php echo $descriptionpart; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer02"><?php echo $articlepart; ?></label>

                                          <input type="text" class="form-control is-valid" id="articlepartvalue" name="articlepartvalue"  placeholder="<?php echo $articlepart; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServerUsername"><?php echo $colorpart; ?></label>

                                          <div class="input-group">

                                             <div class="input-group-prepend">

                                             </div>

                                             <input type="text" class="form-control" id="colorvalue" name="colorvalue" placeholder="<?php echo $colorpart; ?>" aria-describedby="inputGroupPrepend3" required="">

                                          </div>

                                       </div>

                                    </div>

                                    <div class="form-row">

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer01"><?php echo $reportnumbercmctitle; ?></label>

                                          <input type="text" class="form-control is-valid" id="cmcreportnumber" name="cmcreportnumber" placeholder="<?php echo $reportnumbercmctitle; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServerUsername"><?php echo $datereporttitle; ?></label>

                                          <div class="input-group">

                                             <div class="input-group-prepend">

                                             </div>

                                             <input name="datereport" type="date" required="" class="form-control" id="daterport" min="1999-01-01"  value="">

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

                                             <input type="hidden" name="kindoftest" id="kindoftest" value="cmc">

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

                                          </div>

                                       </div>

                                    </div>

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

                                 </form>

                              </div>

                              <!--end card-body-->

                           </div>

                        </div>

                        <!-- end -->

                        <!-- div 3rd lab parts -->

                        <div class="collapse" id="thirdpart">

                           <div class="card">

                              <div class="card-body">

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

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

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

                                    <!-- div new parts -->

                                    <div class="form-row">

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer01"><?php echo $descriptionpart; ?></label>

                                          <input type="text" class="form-control is-valid" id="descriptionpartvalue" name="descriptionpartvalue" placeholder="<?php echo $descriptionpart; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer02"><?php echo $articlepart; ?></label>

                                          <input type="text" class="form-control is-valid" id="articlepartvalue" name="articlepartvalue"  placeholder="<?php echo $articlepart; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServerUsername"><?php echo $colorpart; ?></label>

                                          <div class="input-group">

                                             <div class="input-group-prepend">

                                             </div>

                                             <input type="text" class="form-control" id="colorvalue" name="colorvalue" placeholder="<?php echo $colorpart; ?>" aria-describedby="inputGroupPrepend3" required="">

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

                                             <input type="hidden" name="kindoftest" id="kindoftest" value="trd">

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

                                          </div>

                                       </div>

                                    </div>

                                    <div class="form-row">

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServer01"><?php echo $reprtonumbertrdlabtitle; ?></label>

                                          <input type="text" class="form-control is-valid" id="trdreportnumber" name="trdreportnumber" placeholder="<?php echo $reprtonumbertrdlabtitle; ?>" required="">

                                       </div>

                                       <div class="col-md-4 mb-3">

                                          <label for="validationServerUsername"><?php echo $trddatereporttitle; ?></label>

                                          <div class="input-group">

                                             <div class="input-group-prepend">

                                             </div>

                                             <input name="trddatereport" type="date" required="" class="form-control" id="daterport" min="2000-01-01" onchange="validateDate(this.value)"  value="">

                                          </div>

                                       </div>

                                    </div>

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

                                 </form>

                              </div>

                              <!--end card-body-->

                           </div>

                           <!--end card-->

                           <!-- show the parts -->

                           <div class="col-lg-12">

                              <div class="card">

                                 <div class="card-body">

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

                                    <p class="text-muted mb-3">

                                       <?php echo $assignedstd_help; ?>.

                                    </p>

                                    <div class="table-responsive">

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

                                          <thead>

                                             <tr>

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

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

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

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

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

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

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

                                             </tr>

                                          </thead>

                                          <tbody>

                                             <?php
                                                $wa_startindex = 0;
                                                while (!$listinsertedpart->atEnd()) {
                                                    $wa_startindex = $listinsertedpart->Index; ?>
                                             <tr>

                                                <td><?php echo($listinsertedpart->getColumnVal("kindoftest")); ?></td>

                                                <td><?php echo($listinsertedpart->getColumnVal("description_identificationparts")); ?></td>

                                                <td><?php echo($listinsertedpart->getColumnVal("article_identificationparts")); ?></td>

                                                <td><?php echo($listinsertedpart->getColumnVal("color_identificationparts")); ?></td>

                                                <td><?php echo($listinsertedpart->getColumnVal("cmcreportnumber_identificationparts")); ?><?php echo($listinsertedpart->getColumnVal("thirdlabreportnumber_identificationparts")); ?></td>

                                                <td><?php echo($listinsertedpart->getColumnVal("cmcreportdate_identificationparts")); ?><?php echo($listinsertedpart->getColumnVal("thirdlabreportdate_identificationparts")); ?></td>

                                                <td>

                                                   <a href="#" class="mr-2"><i class="fas fa-edit text-info font-16"></i></a>

                                                   <a href="#"><i class="fas fa-trash-alt text-danger font-16"></i></a>

                                                </td>

                                             </tr>

                                             <?php
                                                $listinsertedpart->moveNext();
                                                }
                                                $listinsertedpart->moveFirst(); //return RS to first record
                                                unset($wa_startindex);
                                                unset($wa_repeatcount);
                                                ?>
                                          </tbody>

                                       </table>

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

                                       <!--end /table-->

                                    </div>

                                    <!--end /tableresponsive-->

                                 </div>

                                 <!--end card-body-->

                              </div>

                           </div>

                           <!-- end -->

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

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

      <script type="text/javascript">

          function validateDate(date) {

              var five_years_before_from_current = moment().subtract(5, 'years');

              var selected_date = moment(date);



              if (selected_date < five_years_before_from_current) {

                  alert('Alert the date must be maximum five year before today');

              }

          }

      </script>

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

      <!-- Plugins js -->

      <script src="../plugins/moment/moment.js"></script>

      <script src="../plugins/daterangepicker/daterangepicker.js"></script>

      <script src="../plugins/select2/select2.min.js"></script>

      <script src="../plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>

      <script src="../plugins/timepicker/bootstrap-material-datetimepicker.js"></script>

      <script src="../plugins/bootstrap-maxlength/bootstrap-maxlength.min.js"></script>

      <script src="../plugins/bootstrap-touchspin/js/jquery.bootstrap-touchspin.min.js"></script>

      <script src="assets/pages/jquery.forms-advanced.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>

