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

<?php
$branch=$_SESSION['branch'];
$sessionID=$_REQUEST['session'];
$month=$_REQUEST['month'];


if ($_REQUEST['familyGroupBy']=="CellNumber") {
       
$sql = " select student_id, cell_no, family_code, last_name from  edu_student_details where status='0' AND branch_id='$branch' group by cell_no order by last_name asc";

$WorkAssignListings = $m->query($sql);



} elseif ($_REQUEST['familyGroupBy']=="FamilyCode") {

  $sql = " select student_id, cell_no, family_code, last_name from  edu_student_details where status='0' AND branch_id='$branch' group by family_code order by last_name asc";

$WorkAssignListings = $m->query($sql);



} 

//echo $sql;

 ?>

<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title> Create Families  | EduPortal </title>
     <?php include('RootMe/css_links.php');?> 
  </head>
  
  <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'];?>" style="margin-left: 33px;">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;

          <a href="families.php">Families </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;  

          Create Families
  

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

<form action="create_families.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>">

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

                   <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col2">

                       <div class="form-group ">
                        <?php 
                        $Code;                        
                        ?>
                          <label class="required"> Family Group By</label>
                          <select id="religion" required name="familyGroupBy" class="form-control">

                          <option value="">Select</option>
                          <option <?php if($_REQUEST['familyGroupBy']=="CellNumber"){echo "Selected";} ?> value="CellNumber">Cell Number</option>
                          <!-- <option <?php if($_REQUEST['familyGroupBy']=="FamilyCode"){echo "Selected";} ?> value="FamilyCode">Family Code</option>  -->        
                                                              
                                                
                          </select>
                       
                          </div>
                  </div>


                  <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col2">

                       <div class="form-group ">
                        <?php 
                        $Code;                        
                        ?>
                          <label class="required"> Genrate Family Code</label>
                          <select id="religion" required name="GenrateCode" class="form-control">

                          <option value="">Select</option>
                          <option <?php if($_REQUEST['GenrateCode']=="Auto"){echo "Selected";} ?> value="Auto">Auto</option>
                          <option <?php if($_REQUEST['GenrateCode']=="Manual"){echo "Selected";} ?> value="Manual">Manual</option>         
                                                              
                                                
                          </select>
                       
                          </div>
                  </div>
                  
                  
                  <div class="col-md-1 " style="padding:8px;">
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 24px;">Search</button>
                </div>
              </div> 
              
               
        </div>            
 </form>
    <br>

<?php  if(!isset($_GET['familyGroupBy'])){?>


      <div class="alert alert-danger col-md-12" id="msg">
       <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <strong>Caution!</strong> Please select GroupBy / Genrate Code and click search!!!
      </div>

    <?php  } ?>


<div style="">

<h3>Create Family List <span style="font-size: 16px;"> </span>       </h3>

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

<input type="hidden" name="action" value="createFamilies">
<input type="hidden" name="GenrateCode" value="<?php echo $_GET['GenrateCode'];?>">


<button type="submit" class="btn btn-primary" style="float: right;">Create Family</button>

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

              
                <th width="1%">S.No</th>
                <th width="20%">Father Name</th>
                <th width="8%">Cell Number</th>
                <th width="40%">Childrens</th>
                <th width="10%">Family Code</th>               
                
                      
                
                                
            </tr>
        </thead>
        <tbody>


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

  $cell_number=$WorkAssignListVal['cell_no'];
  
 if ($WorkAssignListVal['family_code']!='' AND $WorkAssignListVal['family_code']!='NULL') {
    
    continue;
  } 

     
      ?>

        <tr>

          <td style="text-align:center; padding: 2px;"><?php echo $count++;?></td>
          <td><a href="student_profile.php?student=<?php echo $WorkAssignListVal['student_id'];?>">
            <input type="text" name="fatherName[]" value="<?php echo $WorkAssignListVal['last_name'];?>"></a></td>
          <td><input type="text" name="cell_no[]" value="<?php echo $WorkAssignListVal['cell_no']?>"></td>   

          <td  style="padding: 2px;text-align: left;">
            <?php 
             $query = "SELECT student_id, first_name FROM  edu_student_details  WHERE cell_no='$cell_number' and branch_id='$branch' and status='0'";
                   //print_r($query);
                   $childs = $m->query($query);

             foreach ($childs as $child) { ?>
              <input type="hidden" name="student<?php echo $WorkAssignListVal['cell_no']?>[]" value="<?php echo $child['student_id'];?>">
              <?php 
             echo $child['first_name'].",";

            }
            ?> 
            </td>

          <td><input type="text" name="GenrateFamilyCode[]" value="<?php echo $WorkAssignListVal['family_code'];?>"></td>      
          
                

              </tr>

              <?php
      } ?>
 
        </tbody>
        
    </table>

  </form>

  </div>



    <br><br>


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

        </div> 
        </div>


            </div>
          </div>
        </div>


     
        <!-- /page content -->


 <!-- jQuery -->
  <script src="js/ajax_functions.js"></script>
  <?php include('RootMe/js_linksscript.php');?> 
  <!-- Links for Datatable-->

 <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
 <script>
        
  $(document).ready(function() {
    $('#listofstudents').DataTable({
      "pageLength": 100
    });
    } 
  );

   $("#checkAll").change(function () {

      $("input:checkbox").prop('checked', $(this).prop("checked"));
  });

 </script>
  
  </body>
</html>
