<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php

  $branch=$_SESSION['branch'];
$WorkAssignListings = $m->query("SELECT * FROM edu_user_config where branch_id='$branch' and status='0'");

$m->where("status", 0);
$m->where("branch_id", $_SESSION['branch']);
$total_students=$m->get("edu_student_details");
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Teacher Subjects | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
  
<script>
$(document).ready(function(){
 $('#framework').multiselect({
  nonSelectedText: 'Choose Subjects',
  enableFiltering: true,
  enableCaseInsensitiveFiltering: true,
  buttonWidth:'310px'
  
 });
 
 $('#framework_form').on('submit', function(event){
  event.preventDefault();
  var form_data = $(this).serialize();
  $.ajax({
   url:"insert.php",
   method:"POST",
   data:form_data,
   success:function(data)
   {
    $('#framework option:selected').each(function(){
     $(this).prop('selected', false);
    });
    $('#framework').multiselect('refresh');
    alert(data);
   }
  });
 });
 
 
});
</script>



  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
          <div class="row" style="background-color: white;">
     
         <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
         <a href="academic_settings.php">Academic Settings </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
         Assign Subjects to Teachers



      
<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">




    <br>

     
          
          <?php  if(isset($_SESSION['Upsuccess'])){?>


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> One record is updated successfully...
            </div>


          <?php  unset($_SESSION['Upsuccess']); }?>

  

          
    
          <?php  if(isset($_SESSION['error_msg'])){?>

          <div class="col-md-10">

             <div id="error"  class="alert alert-warning alert-dismissible">
                      <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                       <strong>Warning !</strong> You have already saved the challan of this month !!!
              </div>

           </div>

         <?php  unset($_SESSION['error_msg']); }?>

        





<div style="float:left;" class="col-md-12">

 <h3 >  <strong> Subjects Allocation To Each Teacher:</strong><small> (<?php echo count($WorkAssignListings);?> records found)</small> </h3>


<table  class="table table-striped table-bordered" style="width:100%">
        <thead>
            <tr>

                <th width="5%" style="text-align:center;"> S.No </th>
                <th width="15%"> Teacher </th>
                <th width="50%" style="text-align:center;"> Subjects </th>
                <th width="12%" style="text-align:center;">Manage Subjects </th>
                
            </tr>
        </thead>
        <tbody>

   
     <?php 

   
     $count=1;
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

          
        $cls=$WorkAssignListVal['class_id'];
        $section=$WorkAssignListVal['section_id'];
        
         // getting strength of students 
         
        $m->where("section_id", $section);
        $m->where("class_id", $cls);
        $m->where("status", 0);
        $m->where("branch_id", $_SESSION['branch']);
        $total=$m->get("edu_student_details");
   
      ?>

        <tr>
              <td style="text-align:center;"> <?php echo $count; $count++;?> </td>
              <td> <?php echo  $WorkAssignListVal['user_fname']; ?> </td>
               <td  style="text-align:center;"> 
                  
                  
                  
              <?php 

           
              $m->where("branch_id", $_SESSION['branch']);
              $m->where("user_id", $WorkAssignListVal['user_id']);
             // $m->where("section_id", $WorkAssignListVal['section_id']);
              $teacher_sbj = $m->get("eduportal_assign_subject_to_teachers");

              foreach($teacher_sbj as $teacher_sb) {

                      
                $m->where("subject_id", $teacher_sb['subject_id']);
                $subjects = $m->get("eduportal_subject_config");

                  echo " ".$subjects[0]['subject'].",";
                  
              }
              ?> 

                  
                  
              </td>
        

              <td>


                <a style="padding: 0px 5px; font-size:14px;" data-toggle="modal" data-target="#Modal<?php echo $WorkAssignListVal['user_id'];?>"  href="#" style="cursor:pointer;"  class="btn btn-success">
                  Manage <i class="fa fa-pencil" aria-hidden="true"></i>
                </a>


            <!-- Modal -->
            <div id="Modal<?php echo $WorkAssignListVal['user_id'];?>" class="modal fade" role="dialog">
              <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">

                   
               <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">

                  <input type="hidden" name="action" value="UpdateAssignTeacherSubjects">
             
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title"> <?php echo  $WorkAssignListVal['user_fname']." - ".$WorkAssignListVal['user_lname'] ; ?> </h4>
                  </div>
                  <div class="modal-body">

                  <label for=""> Session </label>
          
                   <select name="session" class="form-control" >
                    

                    <?php
                    $match;
                  if(!isset($_REQUEST['session'])){
                    $match=$_SESSION['current_session'];
                  }else { $match=$_REQUEST['session']; }

                    $WorkAssignList = $m->get("edu_session_config");
                    foreach($WorkAssignList as $WorkAssignVal)
                    { ?>

                       <option <?php if($match==$WorkAssignVal['session_id']){echo 'selected';}?> value="<?php echo $WorkAssignVal['session_id']; ?>"><?php echo $WorkAssignVal['session_year']; ?></option>


                            <?php
                    } ?>

                </select>
                <br><br>
                
                  <input type="hidden" name="user_id" value="<?php echo $WorkAssignListVal['user_id'];?>" />
                  <input type="hidden" name="section_id" value="<?php echo $WorkAssignListVal['section_id'];?>" />
                  
                  <?php 

                       
                  $m->where("branch_id", $_SESSION['branch']);
                  $teacher_sbj = $m->get("eduportal_subject_config");

                  foreach($teacher_sbj as $teacher_sb) {

                    $m->where("user_id", $WorkAssignListVal['user_id']);
                   // $m->where("section_id", $WorkAssignListVal['section_id']);
                    $m->where("subject_id", $teacher_sb['subject_id']);
                    $m->where("branch_id", $_SESSION['branch']);
                     $values = $m->get("eduportal_assign_subject_to_teachers");

                    if(count($values)>0){
                      
                      ?>
                  <label class="container1">
                    <input type="checkbox" name="subjects[]" checked value="<?php echo $teacher_sb['subject_id'];?>" />
                    <?php echo " ".$teacher_sb['subject']." ";?><span class="checkmark"></span>
                  </label>
                    <?php  }  else { ?>
                    
                    <label class="container1">
                    <input type="checkbox" name="subjects[]"  value="<?php echo $teacher_sb['subject_id'];?>" />
                    <?php echo " ".$teacher_sb['subject']." ";?><span class="checkmark"></span>
                    </label> 
                    <?php 
                      } // ending else
                      
                    }
                  ?> 

             
                  </div>
                  <div class="modal-footer">
                    <input type="submit" class="btn btn-primary" value="Save" />
                  </div>


                   </form>
                </div>

              </div>
            </div>
            <!-- Modal -->

           
              </td>




              </tr>





              <?php
      } ?>



           
            
           
        </tbody>
        
    </table>


</div>





  </div>
  <div class="clearfix"></div>
</section>            
    

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
