<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php
/*error_reporting(E_ALL);
ini_set('display_errors', '1');*/
$date;
if(isset($_REQUEST['diaryDate'])) {
        $date=date("Y-m-d",strtotime($_REQUEST['diaryDate']));  

      }else {
        $date=date("Y-m-d");  
      }

 if($_REQUEST['class_id']!=NULL){

     
       $m->where("class_id", $_REQUEST['class_id']);  
            
   
      if($_REQUEST['session']!=NULL){

        $m->where("session_id", $_REQUEST['session']);        
      }
      
      if($_REQUEST['section']!=NULL){

        $m->where("section_id", $_REQUEST['section']);
        
      }

      if($_REQUEST['orderBy']=='RollNoWise'){
       $m->where("status", '0');
       $m->where("branch_id", $_SESSION['branch']);
       $m->orderBy("candidate_roll_no", "asc");
       $WorkAssignListings = $m->get("edu_student_details");
       } else {

       $m->where("status", '0');
       $m->where("branch_id", $_SESSION['branch']);
       $m->orderBy("first_name","asc");
       $WorkAssignListings = $m->get("edu_student_details"); 
       }
      }

       $session;
 
  if($_GET["session"]!=NULL ){

      $session= $_GET["session"];
    }
    else{
      $session= $_SESSION['current_session'];
    }
 
     ?>

     <script type="text/javascript">
         function getsecall(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("txt_section").innerHTML=xmlhttp.responseText;
        // alert(xmlhttp.responseText);

      }

    }

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

    xmlhttp.send();




  }
     </script>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Add Diary | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
<style>
  #selectedFiles img {
    max-width: 125px;
    max-height: 125px;
    float: left;
    margin-bottom:15px;
  }
</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'];?>" style="margin-left: 33px;">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;

          <a href="view_student_diaries.php">Diary List View </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;  

          Add Student's Diary

          <div class="" style="background-color: white;">
           
<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
      <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">
<?php 
        if(!isset($_GET['diaryup'])) { ?>
        <input type="hidden" name="action" value="add_diary" />
    <?php  } else {

          $query="select * from eduportal_student_diary where diary_id =".$_GET['diaryup'];
          $diaryup = $m->query($query);

        ?>
              <input type="hidden" name="action" value="update_diary" />
              <input type="hidden" name="diary_id"  value="<?php echo $_GET['diaryup'];?>">

  <?php } ?> 
        <div class="panel panel-default">
         
          <div class="panel-body">
          
       


                <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" id="session" class="form-control" onChange="getterm(this.value)" >

                              <option value="">Select Session</option>
                       
                        <?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>

            
 <div class="col-md-3 col-sm-12 col-xm-12 floatm" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>
                    <select name="class_id" id="class_id"   data-placeholder="Select" class="chosen-multi-select inputfield form-control" onChange="getsecall(this.value)"  >
                    <option value="">Select Class</option>

                    <?php
                    $m->where("branch_id", $_SESSION['branch']);
                    $WorkAssignList = $m->get("edu_class_config");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($_REQUEST['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="col-md-3 col-sm-12 col-xm-12 floatm" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select name="section" id="txt_section" class="form-control" onChange="getSubjects(this.value)">
                      
                   <?php
                              if($_REQUEST['section']!='')
                              { 

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

                              $secondLevel = $m->get("edu_adm_section_detail");
                              
                              foreach($secondLevel as $secondLevel_val)
                              {
                              
                               ?>
                                <option <?php if($_REQUEST['section']==$secondLevel_val['section_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['section_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['section_name'])); ?></option>

                              <?php }   ?>
                                
                          <?php } ?>

                    </select>

                  
                </div>
              </div> 


               <!-- <div class="col-md-2 col-sm-12 col-xm-12 floatm" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Subject</label>
                    <select name="subject_id" id="subject_id" class="form-control"  style="padding-left:2px;" required>
                      <option value="">Select Subject</option>
                              
                        <?php
                        $m->where("branch_id", $_SESSION['branch']);
                        $WorkAssignList = $m->get("eduportal_subject_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

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


                                <?php
                        } ?>

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



             <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"> Date</label>
                 <input name="diaryDate" value="<?php echo $date;?>" type="date" class="form-control"  >
                       
                  </div>
                  </div> 

             

              <div class="item form-group">
                    <h2 style="">Details</h2> 
                        <div class="col-md-12 col-sm-12 col-xs-12">
                          <textarea id="textarea" required="required" name="details" class="ckeditor"> <?php echo $diaryup[0]['diary_details']; ?></textarea>
                        </div>
              </div>

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

                 <label class="required"> Insert Youtube Link</label>
                 <input name="YoutubeLink" placeholder="e.g https://www.youtube.com/" value="<?php echo $diaryup[0]['youtube_link']; ?>" type="text" class="form-control"  >
                       
                  </div>
               </div>

              <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;" >
                 <div class="form-group ">
                 <label> Upload Image</label>
                 <input type="file" class="form-control has-feedback-left" name="img_file" id="img_file" multiple accept="image/*" />
                 <input type="hidden" name="old_img" value="<?php echo $diaryup[0]['image'];?>" />
              </div>
              </div>
             

              <div class="col-md-12" style="float: left;" id="selectedFiles"></div>
             
               <!-- <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
                        <input type="file" class="form-control has-feedback-left" name="img_file" id="img_file" />
                        <span class="form-control-feedback right" aria-hidden="true">Upload Image</span>
              </div> -->

           <div class="col-md-3 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: 24px;float: right;">Save</button>
                </div>
          </div>

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




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


    <!-- searchable dropdown -->
    
    <link href="autosearch_select/select2.css" rel="stylesheet">
    <link href="autosearch_select/select2-default.css" rel="stylesheet">
    <script src="autosearch_select/select2.min.js"></script>
    <script src="https://cdn.ckeditor.com/4.12.1/standard/ckeditor.js"></script>


    <script>
  var selDiv = "";
    
  document.addEventListener("DOMContentLoaded", init, false);
  
  function init() {
    document.querySelector('#img_file').addEventListener('change', handleFileSelect, false);
    selDiv = document.querySelector("#selectedFiles");

  }
    
  function handleFileSelect(e) {
    
    if(!e.target.files || !window.FileReader) return;
    
    selDiv.innerHTML = "";
    
    var files = e.target.files;
    var filesArr = Array.prototype.slice.call(files);
    filesArr.forEach(function(f) {
      if(!f.type.match("image.*")) {
        return;
      }
  
      var reader = new FileReader();
      reader.onload = function (e) {
        var html = "<img src=\"" + e.target.result + "\">" +  "<br clear=\"left\"/>";
        selDiv.innerHTML += html;       
      }
      reader.readAsDataURL(f); 
      
    });
    
    
  }
  </script>


  </body>
</html>
