<?php 
include("header.php");

if(!empty($_GET['sid']))
$upd=documents_status($_GET['sid'],$_GET['status']);

if(!empty($_GET['did']))
$upd=delete_documents($_GET['did']);

if(!empty($_POST['mid']))
$mid=$_POST['mid'];
else if(!empty($_GET['mid']))
$mid=$_GET['mid'];
else
$mid='';


if(isset($_POST['save'])){
documents_upload($mid);
}

if(!empty($_GET['page_index']))
$page_index=$_GET['page_index'];
else if(!empty($_POST['page_index']))
$page_index=$_POST['page_index'];
else
$page_index=1;

$count=get_latest_items('');
$page_cnt=50;
$sno=(($page_index-1)*$page_cnt);  
$pages=ceil($count/$page_cnt); 
$lmt=$sno.",".$page_cnt;

 $get_data= get_instructor_documents('','','','');

 ?>


 
  <div class="register-shell container-fluid w-100" >
    <div class="row g-0 register-card w-100 bg-light">
   
        

        <div class="container m-3 my-5">
          <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"  id="instructorRegisterForm" class="needs-validation" novalidate onsubmit="validate_documentation();">
		
            
           	 <div class="row g-3 m-3 p-2">
             
            	
                
         
                
                 <div class="col-12 col-md-6">
                  <label class="form-label col-md-3">  Image </label>
                  <?php if($mid!="") { ?>
                  <img src="doc_uploads/<?php echo $row['image']?>" width="100px" height="100px" alt="image"  />
                  <?php }?>
                   <input type="file" name="image" class="form-control" id="image" accept=".png,.jpg,.jpeg,.pdf" value="<?php echo $row['image'] ?? "";?>"  required />
                    <div class="err"></div>
                  </div>
             
                
                 <div class="col-12 col-md-6">
                  <label class="form-label col-md-3"> ID Proof</label>
                        <?php if($mid!="") { ?>
                  <img src="doc_uploads/<?php echo $row['id_proof'] ?? "";?>" width="100px" height="100px" alt="image"  />
                  <?php } ?>
               <input type="file" name="id_proof" id="id_proof" class="form-control" accept=".png,.jpg,.jpeg,.pdf" value="<?php echo $row['id_proof'] ?? ""; ?>" required  />
                    <div class="err"></div>
                  </div>
              
                 <div class="col-12 col-md-6">
                       <?php if($mid!="") {?>
                  <img src="doc_uploads/<?php echo $row['grad_proof'] ?? "";?>" width="100px" height="100px" alt="image"  />
                  <?php } ?>
                  <label class="form-label col-md-3"> Graduation  Certificate</label>
               <input type="file" name="grad_proof" id="grad_proof" class="form-control" accept=".png,.jpg,.jpeg,.pdf" value="<?php echo $row['grad_proof'] ?? ""; ?>" required  />
                    <div class="err"></div>
                  </div>
                  
                 <div class="col-12 col-md-6">
                       <?php if($mid!="") {?>
                  <img src="doc_uploads/<?php echo $row['exp_cert'] ?? "";?>" width="100px" height="100px" alt="image"  />
                  <?php } ?>
                  <label class="form-label col-md-3"> Experience Certificate</label>
               <input type="file" name="exp_cert" id="exp_cert" class="form-control" accept=".png,.jpg,.jpeg,.pdf" value="<?php echo $row['exp_cert'] ?? ""; ?>" required  />
                    <div class="err"></div>
                  </div>

              </div>

  

              <div class="col-1 d-grid mt-2">
              <input type="hidden" name="mid" value="<?php echo $mid; ?>">
                <button type="submit" name="save" class="btn btn-primary btn-register">Submit</button>
              </div>
            </div>
          </form>

        
    
 <div class="container m-3 my-5">
 <table class="table table-border">
 	<thead>
    	<th>#</th>
        <th>Image</th>
        <th>ID Proof</th>
        <th>Graduation  Certificate</th>
        <th>Experience Certificate</th>
        <th>Status</th>
        <th colspan="3">Action</th>
    
    </thead>
    <tbody>
      <?php
				  $sno=1;
				  for($i=0;$i<count($get_data);$i++)

				  {
				  		if($get_data[$i]['status']==0)
						$clr="red";
						else
						$clr="blue";
				  ?>
                    <tr>
                      <td><?php echo $sno; ?></td>
                    
                     <td><img src="doc_uploads/<?php echo $get_data[$i]['image']; ?>" alt="" width="150px" height="150px" /></td>
                      <td> <img src="doc_uploads/<?php echo $get_data[$i]['id_proof']; ?>" alt="" width="150px" height="150px" /></td>
                      <td><img src="doc_uploads/<?php echo $get_data[$i]['grad_proof']; ?>" alt=""  width="150px" height="150px"/></td>
                        <td><img src="doc_uploads/<?php echo $get_data[$i]['exp_cert']; ?>" alt="" width="150px" height="150px"/> </td>
                    
                      <td style="color:<?php echo $clr; ?>; font-weight:600"><?php echo $get_data[$i]['st']; ?></td>
                 <td>
                <div class="d-flex gap-3">
                <button class="btn btn-sm <?php echo ($get_data[$i]['st'] == 'Active') ? 'btn-success' : 'btn-secondary'; ?>" title="Change Status" onclick="validate_status('<?php echo $get_data[$i]['id']; ?>','<?php echo $get_data[$i]['st1']; ?>','documentation.php');">  <i class="bi <?php echo ($get_data[$i]['st1'] == 'Active') ? 'bi-toggle-on' : 'bi-toggle-off'; ?>"></i> <?php echo $get_data[$i]['st1']; ?> </button>
                <button class="btn btn-sm btn-outline-primary" title="Edit Course" onclick="validate_update('<?php echo $get_data[$i]['id']; ?>','documentation.php');"><i class="bi bi-pencil-square"></i> </button>
                <button class="btn btn-sm btn-outline-danger" title="Delete Course" onclick="validate_delete('<?php echo $get_data[$i]['id']; ?>','documentation.php');"> <i class="bi bi-trash"></i></button>
                
                </div>
                </td>
                      
                    </tr>
                     <?php
				   		$sno++;
				   }
				   ?>
                    <tr>
                      <td colspan="8">
                      <?php
					  if($pages>1)
					  {
					  	for($i=1;$i<=$pages;$i++)
						{
						?>
							| <a style="cursor:pointer; color:#000033; font-size:16px;" onclick="pageindex('<?php echo $i; ?>','documentation.php')"><?php echo $i; ?></a>
                        <?php
						}
					  }
					  ?>
                    
                      </td>
                    </tr>
    </tbody>
 </table>
 </div>
 
 
 
 
 </div>
 </div>
 </div>
 
 
 
 
 
 
 <?php include("footer.php");?>