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

<?php  include("sessioncheck.php"); ?>

<?php



$pageName = basename($_SERVER['PHP_SELF']);

 $m->where("page_name", $pageName);
 $pageNameAccess=$m->get("eduportal_modules_pages_detail");


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


 

     ?>





<!DOCTYPE html>

<html lang="en">

  <head>

    

    <title>Add Chapters | EduPortal</title>

    <?php include('RootMe/css_links.php');?>

  

<script type="text/javascript">



function getSubCat(id){

  //alert(id);



    if (window.XMLHttpRequest) {

      // code for IE7+, Firefox, Chrome, Opera, Safari

      xmlhttp=new XMLHttpRequest();

    } else { // code for IE6, IE5

      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

    }

    xmlhttp.onreadystatechange=function() {

      if (xmlhttp.readyState==4 && xmlhttp.status==200) {



        document.getElementById("subcatgory").innerHTML=xmlhttp.responseText;

       //alert(xmlhttp.responseText);



      }



    }

    xmlhttp.open("GET","get_exp_subcategory.php?id="+id,true);

    xmlhttp.send();

  }

</script> 

  </head>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>

function getClassSubject(id){

//alert(id);

    if (window.XMLHttpRequest) {



      // code for IE7+, Firefox, Chrome, Opera, Safari



      xmlhttp=new XMLHttpRequest();



    } else { // code for IE6, IE5



      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");



    }



    xmlhttp.onreadystatechange=function() {



      if (xmlhttp.readyState==4 && xmlhttp.status==200) {



        document.getElementById("subject_id").innerHTML=xmlhttp.responseText;

        // alert(xmlhttp.responseText);



      }



    }



    xmlhttp.open("GET","get_class_subject.php?class_id="+id,true);



    xmlhttp.send();

  }

</script>

  <style>

#snackbar {

  visibility: hidden;

  min-width: 250px;

  margin-left: -125px;

  background-color: #1E90FF;

  color: #fff;

  text-align: right;

  border-radius: 2px;

  padding: 16px;

  position: fixed;

  z-index: 1;

  left: 80%;

  bottom: 30px;

  font-size: 17px;

}



#snackbar.show {

  visibility: visible;

  -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;

  animation: fadein 0.5s, fadeout 0.5s 2.5s;

}



@-webkit-keyframes fadein {

  from {bottom: 0; opacity: 0;} 

  to {bottom: 30px; opacity: 1;}

}



@keyframes fadein {

  from {bottom: 0; opacity: 0;}

  to {bottom: 30px; opacity: 1;}

}



@-webkit-keyframes fadeout {

  from {bottom: 30px; opacity: 1;} 

  to {bottom: 0; opacity: 0;}

}



@keyframes fadeout {

  from {bottom: 30px; opacity: 1;}

  to {bottom: 0; opacity: 0;}

}

</style>

  <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">

            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
             Chapter Managements
          <br><br>

          <div class="row" style="background-color: white;">

           

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

  <div class="container">



 <div class="" style="margin-top:10px;">

   


          <div class="">


      <h3 style="margin-left: 15px;">Add Subject Chapters</h3>

      <h5 style="margin-left: 15px;color:#ff5c5c;">Before adding chapters, please make sure you have assigned subjects to classes.</h5>

            <div class="row">

          

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

                <div class="x_panel">

            

                  <div class="x_content">

          

     

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

  <?php

  

  $month;

   if(!isset($_GET['chpup'])){?>

    <!-- <input type="hidden" name="subject_id"  value="<?php echo $_GET['subject_id'];?>"> -->

        <input type="hidden" name="action" value="Create_Chapter" />



  <?php $month=date("m");} else {



          $query="select * from edu_create_subject_chapters where chapter_id =".$_GET['chpup'];

          $chapterdata = $m->query($query);



          $month=$chapterdata[0]['month_id'];

?>

              <input type="hidden" name="action" value="update_chapter" />

              <input type="hidden" name="chapter_id"  value="<?php echo $_GET['chpup'];?>">



  <?php } ?>        

          

       



        <div class="item form-group">

                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email"> Class <span class="required">*</span>

                        </label>

                        

                        <div class="col-md-6 col-sm-6 col-xs-12">

                          <select  name="class_id" class="form-control" onChange="getClassSubject(this.value)" required>

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



                  <?php

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

                    $WorkAssignList = $m->get("edu_class_config");

                    foreach($WorkAssignList as $WorkAssignListVal)

                    { ?>



                        <option <?php if($chapterdata[0]['class_id']==$WorkAssignListVal['class_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['class_id']; ?>"><?php echo $WorkAssignListVal['Class_Name']; ?></option>





                            <?php

                    } ?>



                            </select>

                        </div>



                      </div>







        <div class="item form-group">

                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email"> Subject <span class="required">*</span>

                        </label>

                        

                        <div class="col-md-6 col-sm-6 col-xs-12">

                    <select name="subject_id" id="subject_id" class="form-control"  style="padding-left:2px;" required>



                      <option value="">All</option>

                   <?php

                              if(isset($_REQUEST['chpup']))

                              { 



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

                              $WorkAssignList = $m->get("eduportal_subject_config");

                              

                              foreach($WorkAssignList as $WorkAssignListVal)

                        { ?>



                           <option <?php if($chapterdata[0]['subject_id']==$WorkAssignListVal['subject_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['subject_id']; ?>"><?php echo $WorkAssignListVal['subject']; ?></option>



                              <?php }   ?>

                                

                          <?php } ?>

                     



                    </select>

                        </div>



                      </div>



                           

                   



           <div class="item form-group">

                        

                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Chapter Name <span class="required"></span>

                        </label>

                        <div class="col-md-6 col-sm-6 col-xs-12">

                         

                           <input class="form-control col-md-7 col-xs-12"  name="chapter_Name" placeholder="eg Introduction To Computer! " value="<?php echo $chapterdata[0]['chapter_Name']; ?>">

                        </div>

                    </div>





                      <div class="ln_solid" style="border-top:none;"></div>

                      <div class="form-group">

                        <div class="col-md-6 col-md-offset-3">

                          

                          <button id="send" type="submit" class="btn btn-primary" >Submit Record</button>  &nbsp;&nbsp;&nbsp;

                          <a href="subjects.php" > <button type="button" class="btn btn-success" >Add New Subjects</button> </a>



                        </div>

                      </div>



                    </form>

              

          </div>

                </div>

              </div>

            </div>

          </div>

       

        



        <!-- /page content -->







  </div>

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

</section>           



<?php



$branch=$_SESSION['branch'];

$sql = "SELECT * FROM edu_create_subject_chapters where branch_id='$branch' order by chapter_id desc";



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



 

     ?>









     <div class="t col-md-12 col-sm-12 col-xs-12">

                <h3>Chapter List<small> (<?php echo count($chapters);?> records)</small></h3>

              </div>



              

          

          

    

<!-- <form action="add_expenses.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&from=<?php echo $_GET['from'];?>&to=<?php echo $_GET['to'];?>">



                

                

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

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

                 <div class="form-group ">



                 <label class="required"> From Date</label>

                 <input name="from"  id="from" value="<?php echo $from;?>" type="date" class="form-control"  >

                       

                  </div>

                  </div>                      

             



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



                       <div class="form-group ">



                          <label class="required"> To Date</label>

                              <input name="to" id="to" value="<?php echo $to;?>" type="date" class="form-control"  >

                       

                          </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 class="col-md-3 " style="padding:8px;">

                <div class="form-group ">

                <a href="print_expense_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&from=<?php echo $_GET['from'];?>&to=<?php echo $_GET['to'];?>&customer=<?php echo $_GET['customer'];?>" target="_blank" class=" btn btn-primary" style="margin-top: 24px;"> Print Report </a>

                </div>

              </div> 

        </div>            

 </form> -->

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



<div id="snackbar"><script> toastFunction();</script> Your Recored is Sucessfully Added</div>



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

          ?>





          

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





            <div class="alert alert-success" id="msg">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Success!</strong> Record is updated successfully...

            </div>





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

          ?>



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





            <div class="alert alert-danger" id="msg">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Danger!</strong> Record is deleted successfully...

            </div>





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

          ?>



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

                      <thead>

                        <tr>

                          <th width="">S.No</th>

                          <th width="">Class Name</th>

                          <th width="">Subject Name</th>

                          <th width="">Chapter Name</th>

                          <th width="">Action</th>

                         



                        </tr>

                      </thead>

                      <tbody>



                        

<?php  $count=1;

$date= date("Y-m-d");



foreach($chapters as $chapter){



  $m->where("subject_id", $chapter['subject_id']);

  $subject=$m->get("eduportal_subject_config");



  $m->where("class_id", $chapter['class_id']);

  $class=$m->get("edu_class_config");



  $m->where("Month_Id", $category['month_id']);

  $months=$m->get("eduportal_month_config");





?>

                        <tr>

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

                         



                          <td><?php echo $class[0]['Class_Name'];?></td>

                          <td><?php echo $subject[0]['subject'];?></td>

                          <td><?php echo $chapter['chapter_Name'];?></td>

                          

                       <!--    <td><?php //echo $category['customer_phone'];?></td> -->

                                                  



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

          <a style="padding: 0px 5px; font-size:14px;"  href="create_subject_chapters.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&chpup=<?php echo $chapter['chapter_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?chapter_id=<?php echo $chapter['chapter_id'];?>&action=DeleteChapter" 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>



            </div>

          </div>

        </div>

        <!-- /page content -->

  



    

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

</script>

  </body>

</html>

<script>

function toastFunction() {

  var x = document.getElementById("snackbar");

  x.className = "show";

  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

}

</script>