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

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

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


if(!empty($_POST['mid']))
$mid=$_POST['mid'];
else if(!empty($_GET['mid']))
$mid=$_GET['mid'];
else
$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_inst_course('','','','');
$course_master = get_course_master('','','','');
  $gradeings = get_grade('','','','');
  
 ?>


 
  <div class="container-fluid w-100">
    <div class="row g-0 register-card w-100 bg-light">
		
       
        
				 <div class="bg-white p-4 mt-3 mx-2 shadow-sm rounded d-flex justify-content-between align-items-center">
    
    <h4 class="fw-bold mb-0">
        <i class="bi bi-journal-text me-2 text-primary"></i>
        My Courses
    </h4>

    <a href="my_courses.php" class="btn btn-primary btn-sm p-2 fw-bold">
        <i class="bi bi-plus-lg me-1"></i> New Course
    </a>

</div>
  
      
        
    
 <div class="container my-3 mr-5 p-4">
<div class="table-responsive">
 <table class="table table-bordered table-hover p-0">
 	<thead >
    	<th>#</th>
      <!--  <th>Category</th>-->
        <th>Course</th>
        <th>Course Type</th>
        <th>Course Image</th>
        <th>No.Of Classes</th>
        <th>Duration</th>
        <th>Course Price</th>
        <th>Course Discount(%)</th>
        <th>Curriculum Vitae </th>
        <th>View More</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><?php  echo $get_data[$i]['course_title'] ?? "";?></td>
                         <td><?php  echo $get_data[$i]['course_type'] ?? "";?></td>
                     <td><img src="courses_upload/<?php echo $get_data[$i]['course_img']; ?>" style="width:100px;height:100px;"  alt="img"  /> </td>
                     <td><?php  echo $get_data[$i]['no_of_class'] ?? "";?></td>
                        <td><?php  echo $get_data[$i]['duration'] ?? "";?></td>
                      <td>$.<?php echo $get_data[$i]['course_price']; ?></td>
                       <td><?php echo $get_data[$i]['course_discount']; ?></td>
                         <td><a href="curriculum.php?view_id=<?php echo $get_data[$i]['id']?>" class="btn btn-warning"><i class="bi bi-eye"></i> View cv</a></td>
                       <td><a href="course_card.php?view_id=<?php echo $get_data[$i]['id']?>" class="btn btn-info"><i class="bi bi-eye"></i> View Details</a></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']; ?>','course_report.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']; ?>','my_courses.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']; ?>','course_report.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; ?>','course_report.php')"><?php echo $i; ?></a>
                        <?php
						}
					  }
					  ?>
                    
                      </td>
                    </tr>
    </tbody>
 </table>
 </div>
 </div>
 
 
 

 </div>
 </div>
 
 
 
 
 
 
 <?php include("footer.php");?>