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

<?php

$m->where("user_id", $_SESSION['user_id']);
$m->where ("branch_id", $_SESSION['branch']);
$m->where("page_id", $_REQUEST['page']);
$access = $m->get("users_privilege_detail");


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



$sql = " select * from  eduportal_exam_terms where branch_id=".$_SESSION['branch']." and session_id=".$match." order by term_id desc";
//echo $sql;

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

if(isset($_GET['id'])){
  
  $sql = "select * from  eduportal_exam_terms where term_id=".$_GET['id'];
  $terms = $m->query($sql);

}
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Terms | 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="" 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; 
              
          Manage Tests/ Terms (<?php echo count($WorkAssignListings);?> records)
 
          
<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">


          
          <?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']); }?>

  

          
    

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

     <form  action="terms.php" enctype="multipart/form-data" method="get">
 
               <input type="hidden" name="sess" value="<?php echo session_id().session_id().session_id().session_id();?>"   />           
              <div class="col-md-10" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Filter Terms with Sessions</label>
                    <select name="session" id="session" class="form-control"  style="height:50px;">

                              <option value="">Select Session</option>
                        

                        <?php
 
 

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

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


                                <?php
                        } ?>

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



           <div class="col-md-2 pull-right" style="padding:2px;" >
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 38px;float: right;">Search</button>
                </div>
          </div>

  </form>


    <table  class="table table-striped table-bordered" style="width:100%;font-size:12px;">
          
          <thead>
            <tr>
                <th width="5%"   style="text-align:center;">S.No</th>
                <th width="30%"> Title </th>
                <th width="20%" style="text-align:center;"> Start Date </th>
                <th width="20%" style="text-align:center;"> End Date </th>
                <th width="10%" style="text-align:center;"> Session </th>
                <th width="10%">Action </th>

            </tr>
        </thead>
        <tbody>


   
     
     <?php 

     $count=1;

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

        $m->where("session_id", $WorkAssignListVal['session_id']);
        $session=$m->get("edu_session_config");
        
      ?>

        <tr>
              <td  style="text-align:center;">
                 <?php echo $count;  $count++;?>

               </td>

              <td> <?php echo $WorkAssignListVal['term_title'];?> </td>
              <td> <?php echo date("d-M-Y",strtotime($WorkAssignListVal['starting_date']));?> </td>
              <td> <?php echo date("d-M-Y",strtotime($WorkAssignListVal['ending_date']));?> </td>
              <td> <?php echo $session[0]['session_year'];?> </td>
             
              <td>

                <?php if ($access[0]['edit_access']!=NULL) { ?>

                <a style="padding: 0px 5px; font-size:14px;"  href="terms.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&id=<?php echo $WorkAssignListVal['term_id'];?>" style="cursor:pointer;"  class="btn btn-success">
                  <i class="fa fa-pencil" aria-hidden="true"></i>
                </a>

                <?php } ?>

                <?php if ($access[0]['delete_access']!=NULL) { ?>

                <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?terms=<?php echo $WorkAssignListVal['term_id'];?>&action=DeleteTerms" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

               <?php } ?>
    
                </td>




              </tr>





              <?php
      } ?>



           
            
           
        </tbody>
        
    </table>


</div>




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


  <h3> Add New Term/Test </h3>
  <br/>

  <table style="width:100%">
          
         <tr>
          <td width="100%" style="padding-left:2%; padding-right:2%;" >

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

        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">
              
              <input type="hidden" name="action" value="AddTerm1">



                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" class="form-control inputfield" >

                           <?php
 
 
 
                      $match;
                      if(!isset($_REQUEST['session'])){
                        $match=$_SESSION['current_session'];
                      }else { $match=$_REQUEST['session']; }
                     
   
                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

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


                                <?php
                        } ?>

                    </select>
                </div>


                <div class="form-group ">
                  <label class="required">Display On Mobile App</label>
                    <select name="Live_Mobile_App"  id="Live_Mobile_App" class="form-control" >              
                              <option <?php if($terms[0]['Live_Mobile_App']==0){echo "selected";} ?> value="0">YES</option>
                              <option <?php if($terms[0]['Live_Mobile_App']==1){echo "selected";} ?> value="1">NO</option>
                                   
                          </select>
                </div>
              

              <div class="form-group">

                  <label for=""> Starting Date </label>
                  <input type="date" class="inputfield"  name="starting" value="<?php echo date("Y-m-d");?>"  required>
               
                  <label for=""> Ending Date </label>
                  <input type="date" class="inputfield" name="ending" value="<?php echo date("Y-m-d");?>"    required>
                   
                
                  <label for=""> Paper/Exam Title </label>
                  <input type="text" class="inputfield" name="name" placeholder="Weekly Test etc..."    autocomplete="off"  maxlength="100" autofocus="autofocus" required>
                   
                  <br><br>
                  
                  <div class="clearfix"></div>
              
                  <input type="submit" value="Save Record" class="btn btn-primary" >
              
              </div>

        </form>

<?php } else {?>


        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">
              
              <input type="hidden" name="action" value="UpdateTerm">

              <input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />





              <div class="form-group">


                <label class="required">Display at Mobile App</label>
                    <select name="Live_Mobile_App"  id="Live_Mobile_App" class="form-control" >              
                              <option <?php if($terms[0]['Live_Mobile_App']==0){echo "selected";} ?> value="0">YES</option>
                              <option <?php if($terms[0]['Live_Mobile_App']==1){echo "selected";} ?> value="1">NO</option>
                                   
                          </select>


                  <label for=""> Starting Date </label>
                  <input type="date" class="inputfield"  name="starting" value="<?php echo $terms[0]['starting_date']; ?>"  required>
               
                  <label for=""> Ending Date </label>
                  <input type="date" class="inputfield"  name="ending" value="<?php echo $terms[0]['ending_date']; ?>"   required>
                   


                  <label for=""> Update Term </label>
                  <input type="text" class="inputfield"  name="name"  value="<?php echo $terms[0]['term_title']; ?>" required maxlength="100" autofocus="autofocus" required>
                   
                  <br><br>
                  
                  <div class="clearfix"></div>
              
                  <input type="submit" value="Update Record" class="btn btn-primary" >
              
              </div>

        </form>



<?php }?>





                </td>
                
          </tr>
        
  </table>


</div>



    <br><br>


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

           
          </div>
        </div>

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

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