<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.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>SMS Alerts | 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>
$(document).ready(function(){
  
    $("#div1").fadeOut();
    $("#div2").fadeOut("slow");
    $("#div3").fadeOut(3000);
 
});
</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">
          <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;">
   
      

                                    <!-- page content -->
        
  <div class="">
    
      <h3 style="margin-left: 15px;">Auto SMS Alerts</h3>
            <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['alrtup'])){?>
        <input type="hidden" name="action" value="add_user_alert" />

  <?php } else {

          $query="select * from eduportal_sms_alert where alert_id =".$_GET['alrtup'];
          $alertdata = $m->query($query);

       ?>     <input type="hidden" name="action" value="update_alert" />
              <input type="hidden" name="alert_id"  value="<?php echo $_GET['alrtup'];?>">

  <?php } ?>        
          
                   
              <div class="col-md-12">
            
              <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Module</label>

            
                    <select name="sms_module" class="form-control" >
                     <option <?php if($alertdata[0]['module']=="FeeCollection"){echo "Selected";} ?> value="FeeCollection">Fee Collection</option>
                     <option <?php if($alertdata[0]['module']=="Attendance"){echo "Selected";} ?> value="Attendance">Attendance</option>                    

                    </select>

                  
                </div>
              </div>
              
              
              <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Users</label>

                    <select name="user_id" class="form-control" >
                      
                    <?php

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

                       <option <?php if($alertdata[0]['user_id']==$WorkAssignListVal['user_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['user_id']; ?>"><?php echo $WorkAssignListVal['user_fname']; ?></option>


                            <?php
                    } ?>

                    </select>

                  
                </div>
              </div> 
              
              <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Type</label>

            
                    <select name="type" class="form-control" >
                     <option <?php if($alertdata[0]['type']=="daily"){echo "Selected";} ?> value="daily">Daily</option>
                     <option <?php if($alertdata[0]['type']=="weekly"){echo "Selected";} ?> value="weekly">Weekly</option>
                     <option <?php if($alertdata[0]['type']=="monthly"){echo "Selected";} ?> value="monthly">Monthly</option>                    

                    </select>

                  
                </div>
              </div>


              <!-- <div class="col-md-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Time</label>

            
                    <input type="time" name="time" class="form-control" value="<?php echo $alertdata[0]['type'];?> ">                  
                </div>
              </div> -->

                 


               <div class="col-md-2" style="padding:8px;margin-top:22px;">
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary">Save</button>
                </div>
              </div>

             
            </div>     

           

                      

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

        <!-- /page content -->



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

<?php


$sql = "SELECT * FROM eduportal_sms_alert where branch_id='$branch' order by user_id asc ";

// echo $sql;
$ViewSMSalerts = $m->query($sql);
 //print_r($categories);
 
     ?>




     <div class="t col-md-12 col-sm-12 col-xs-12">
                <h3>SMS Alert List<small> (<?php echo count($ViewSMSalerts);?> records)</small></h3>
              </div>


<?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="datatable" class="table table-striped table-bordered"style="background-color: white;">
                      <thead>
                        <tr>
                          <th width="1%">S.No</th>
                           <th width="10%">Module</th>
                          <th width="10%">User Name</th>
                          <th width="20%">Type</th>
                          <!-- <th width="10%">Time</th> -->
                          <th width="8%">Action</th>
                         

                        </tr>
                      </thead>
                      <tbody>

                        
<?php  $count=1;
$date= date("Y-m-d");

foreach($ViewSMSalerts as $ViewSMSalert){

  $m->where("user_id", $ViewSMSalert['user_id']);
  $userName=$m->get("edu_user_config");



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

                          <td><?php echo $ViewSMSalert['module'];?></td>
                          <td><?php echo $userName[0]['user_fname'];?></td>
                          <td><?php echo $ViewSMSalert['type'];?></td>
                          <!-- <td><?php echo $ViewSMSalert['time'];?></td> -->
                          
                          <td>        
           
            	<a style="padding: 0px 5px; font-size:14px;"  href="alerts.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&alrtup=<?php echo $ViewSMSalert['alert_id'];?>" style="cursor:pointer;"  class="btn btn-success"> <i class="fa fa-pencil" aria-hidden="true"></i></a>

          

        <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?alert=<?php echo $ViewSMSalert['alert_id'];?>&action=DeleteAlert" 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>

      
        
                          </td>

                        </tr>
<?php } ?>
                      

                      </tbody>
                    </table>
           
          </div>
        </div>

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

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
<script>
function toastFunction() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
</script>