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


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


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


$course_master = get_course_master('','','','');
 ?>


 
  <div class="register-shell container-fluid w-100"  style="margin-top:-80px;">
    <div class="row g-0 register-card w-100 bg-light">
   
                 

        <div class="container m-3 my-5">
        				<div class="mx-5">
        			      <?php 
                                if (!empty($_GET['upd'])) {
                                ?>
                                  <div class="alert alert-success text-center" style="font-size:13px; font-weight:bold;">
                                    Module Details updated successfully.
                                  </div>
                                <?php 
                                } elseif (!empty($_GET['succ'])) {
                                ?>
                                  <div class="alert alert-success text-center" style="font-size:13px; font-weight:bold;">
                                   Record Stored Successfully .
                                  </div>
                                <?php 
                                } elseif (!empty($_GET['fail'])) {
                                ?>
                                  <div class="alert alert-warning text-center" style="font-size:13px; font-weight:bold;">
                                  Failed to update Module details.
                                  </div>
                                <?php 
                                } 
                                ?>
                          </div>
        
          <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"  id="instructorRegisterForm" class="needs-validation" novalidate onsubmit="validate_module();">
		
            
           	 <div class="row g-3 m-3 p-2">
             		 <div class="col-12 col-md-6">
                  <label class="form-label col-md-3">Course Title</label>
                   <select name="course_id" class="form-select" id="course_id" required >
                   	<option value="">Select:</option>
                    <?php  foreach($course_master as $course){?>
                    <option value="<?php echo $course['id']; ?>"><?php echo $course['title'] ?? "";?></option>
                    <?php } ?>
                   </select>
                   
                   <input type="hidden" name="course_title" value="<?php echo $row['title'] ?? "";?>" id="course_title"  />
                    <div class="err"></div>
                  </div>
             
             <?php 
			 	if($mid ==""){
			 for ($i = 1; $i < 6; $i++ ){?>
               <div class="col-12 col-md-6">
                  <label class="form-label col-md-3">  Module Title<?php echo $i; ?> </label>
                   <input type="text" name="module_title[]" class="form-control" id="module_title<?php echo $i;?>" />
                    <div class="err"></div>
                  </div>
                  <?php } }else{ ?>
                  
                    <div class="col-12 col-md-6">
                  <label class="form-label col-md-3">  Module Title </label>
                   <input type="text" name="module_title" class="form-control" id="module_title"  value="<?php echo $row['module_title'] ?? "";?>"   />
                    <div class="err"></div>
                  </div>
                  <?php } ?>
                  
                
              <!--    <div class="col-12 col-md-6">
                  <label class="form-label col-md-3"> No.Of Lessons </label>
                   <input type="text" name="no_of_lessons" class="form-control" id="no_of_lessons"  value="<?php echo $row['no_of_lessons'] ?? "";?>"  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>
 </div>
 </div>
 
 
 
<script>

  $("#course_id").on("change",function(){
 	let course_id = $("#course_id").val();
	
	$.ajax({
		url: "include/ajax.php",
		method:"POST",
		data: {course_id : course_id},
		success:function(data){
			var parts = data.trim().split("~");
			//alert(parts);
			
			if(parts[0] == "get_course_master"){
				$("#course_title").val(parts[1]);
				$("#course_type").val(parts[2]);
				$("#course_image").val(parts[3]);
			}else{
				alert("Data Not Found!");
			}
		},
		error:function(error){
			alert(error);
		}
	}); 
 });
 </script>
 
 
 
 <?php include("footer.php");?>