<?php require_once('../Connections/cmctrfdb.php'); ?>

<?php require_once('../webassist/mysqli/rsobj.php'); ?>

<?php

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

<?php 

// pickup the get variable

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

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

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

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

?>

<?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");

$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

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

$auditdpidetail->setQuery("SELECT * FROM auditdpi WHERE auditdpi.idauditdpi='$idauditdpi'");

$auditdpidetail->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>

<!-- upload image script -->

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

	<script> 

        $(document).ready(function() { 

            $(".upload-doc").click(function(){

                $(".form-horizontal").ajaxForm({target: '.preview'}).submit();

            });

        }); 

</script>

	

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

	

</head>

	

<body>

	

<div class="card">

                                <div class="card-body">

                                    <h4 class="mt-0 header-title"><?php echo $adddoctitle; ?> - <?php echo $dpireportnumbertitle; ?> <?php echo($auditdpidetail->getColumnVal("certificatenumber")); ?><i class="fas fa-info-circle" data-toggle="modal" data-animation="bounce" data-target=".bs-example-modal-center5"></i>

<div class="modal fade bs-example-modal-center5" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">

                                                        <div class="modal-dialog modal-dialog-centered">

                                                            <div class="modal-content">

                                                                <div class="modal-header">

                                                                    <h5 class="modal-title mt-0" id="exampleModalLabel"><?php echo $m18btitle; ?></h5>

                                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">

                                                                        <span aria-hidden="true">&times;</span>

                                                                    </button>

                                                                </div>

                                                                <div class="modal-body">

                                                                    <p><?php echo nl2br($documenthelp); ?>

                                                                    </p>

                                                                </div>

                                                            </div><!-- /.modal-content -->

                                                        </div><!-- /.modal-dialog -->

                                      </div><!-- /.modal --></h4>

									<?php if ($idcert!=5) { ?>

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

									<?php } else { ?>

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

									<?php } ?>

									

							

									<div class="upload-div">

    <!-- File upload form -->

    <form id="uploadForm" enctype="multipart/form-data">

		

	<div class="form-group row">

    	<label for="validationTooltip01" class="col-sm-2 col-form-label"><?php echo $filedescription; ?></label>

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

    		<input type="text" class="form-control" id="validationTooltip01" name="filedescription" placeholder="<?php echo $filedescription; ?>" required="">

															

    	</div>

	</div>

		

        <label><?php echo $selectfileonyourpc; ?></label>

        <input type="file" name="doc[]" id="fileInput" >

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

		<input type="hidden" name="idauditdpi" id="idauditdpi" value="<?php echo($auditdpidetail->getColumnVal("idauditdpi")); ?>">

		<input type="hidden" name="dpicode" id="dpicode" value="<?php echo($auditdpidetail->getColumnVal("dpicode")); ?>">

        <input type="submit" name="submit" value="UPLOAD"/>

		

    </form>

	

    <!-- Display upload status -->

    <div id="uploadStatus"></div>

	   

</div>

	



									<br>



						

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

</div>

	

	<!-- section file already uploaded -->

	

<?php

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

$filenamelist->setQuery("SELECT * FROM fileattached WHERE fileattached.idtrfdetails='$idtrf' AND fileattached.idauditdpi='$idauditdpi'");

$filenamelist->execute();?>





<div class="card" id="docaudit">

	 



                                <div class="card-body">

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

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

									

									

									<div class="upload-div">

    <!-- File upload form -->

    <div class="card-body">

    

                                    

    

                                    <div class="table-responsive">

                                      

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

                                            <thead>

                                              <tr>

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

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

                                                

                                                <th>Action</th>

                                              </tr>

                                          </thead>

                                            <tbody>

												

												  <?php

$wa_startindex = 0;

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

  $wa_startindex = $filenamelist->Index;

?>

                                              <tr>

                                                <td><a href="uploaddocuments/<?php echo($filenamelist->getColumnVal("filename_fileattached")); ?>" target="_blank">FILE</a></td>

                                                <td><?php echo($filenamelist->getColumnVal("description_fileattached")); ?></td>

                                                

                                                <td>                                                       

                                                 

                                                  <a href="deletefileauditdpi.php?idauditdpi=<?php echo $idauditdpi; ?>&idtrf=<?php echo $idtrf; ?>&idfileattached=<?php echo($filenamelist->getColumnVal("idfileattached")); ?>"><i class="fas fa-trash-alt text-danger font-16"></i></a>

                                                </td>

                                              </tr>

                                               <?php

  $filenamelist->moveNext();

}

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

unset($wa_startindex);

unset($wa_repeatcount);

?>

                                              

                                              

                                          </tbody>

                                      </table><br>

<button onclick="self.close()" type="button" class="btn btn-success waves-effect waves-light"><?php echo $closewindow; ?></button>

                                         

<!--end /table-->

                                    </div><!--end /tableresponsive-->

                                </div>

	



	   

</div>

	



									<br>



						

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

</div>

	

<!-- end of page -->

<script>

$(document).ready(function(){

    // File upload via Ajax

    $("#uploadForm").on('submit', function(e){

        e.preventDefault();

        $.ajax({

            type: 'POST',

            url: 'uploadfileauditdpi.php',

            data: new FormData(this),

            contentType: false,

            cache: false,

            processData:false,

            beforeSend: function(){

                $('#uploadStatus').html('<img src="images/uploading.gif"/>');

            },

            error:function(){

                $('#uploadStatus').html('<span style="color:#EA4335;">File upload failed, please try again.<span>');

            },

            success: function(data){

                $('#uploadForm')[0].reset();

                $('#uploadStatus').html('<span style="color:#28A74B;">File uploaded successfully.<span>');

                $('.gallery').html(data);

				$("#docaudit").load(location.href + " #docaudit");

            }

        });

    });

    

    // File type validation

    $("#fileInput").change(function(){

        var fileLength = this.files.length;

        var match= ["application/pdf","application/msword","image/jpg","image/gif"];

        var i;

        for(i = 0; i < fileLength; i++){ 

            var file = this.files[i];

            var imagefile = file.type;

            if(!((imagefile==match[0]) || (imagefile==match[1]) || (imagefile==match[2]) || (imagefile==match[3]))){

                alert('Please select a valid  file (PDF, word, excel).');

                $("#fileInput").val('');

                return false;

            }

        }

    });

});

</script>



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