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

  $branch=$_SESSION['branch'];
$WorkAssignListings = $m->query("SELECT sec.*, cls.* FROM edu_adm_section_detail as sec LEFT JOIN edu_class_config as cls ON sec.class_id = cls.class_id where cls.class_id!='' and cls.branch_id='$branch' ORDER BY cls.class_id asc");

     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Class Subjects | EduPortal</title>
    <?php include('RootMe/css_links.php');?>



    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  #sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
  #sortable li span { position: absolute; margin-left: -1.3em; }
  </style>
 <!--  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> -->
  <script>
  $( function() {
    $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();
  } );
  </script>
   
  </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 Classes


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


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

 <h3 >  <strong> Subjects Allocation To Each Class:</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%"> Class </th>
                <th width="44%" style="text-align:center;"> Subjects </th>
                <th width="18%" 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'];
 
   
      ?>

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

           
              $m->where("branch_id", $_SESSION['branch']);
              $m->where("class_id", $WorkAssignListVal['class_id']);
              $m->where("section_id", $WorkAssignListVal['section_id']);
              $m->where("session_id", $_SESSION['current_session']);
              $teacher_sbj = $m->get("eduportal_class_subjects");

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

                <a style="padding: 3px 5px; font-size:14px;" href="subject_drag.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&section_id=<?php echo $WorkAssignListVal['section_id'];?>&class_id=<?php echo $WorkAssignListVal['class_id'];?>" style="cursor:pointer;" target="_blank"  class="btn btn-success">
                  Subject Order <i class="fa fa-sort" aria-hidden="true"></i>
                </a>


            <!-- Modal -->
            <div id="Modal<?php echo $WorkAssignListVal['section_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="UpdateClassSubjects">
             
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title"> <?php echo  $WorkAssignListVal['Class_Name']." - ".$WorkAssignListVal['section_name'] ; ?> </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="class_id" value="<?php echo $WorkAssignListVal['class_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("class_id", $WorkAssignListVal['class_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_class_subjects");

                    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'].$teacher_sb['subject_id']." ";?><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'].$teacher_sb['subject_id']." ";?><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>
