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


// inserting signl student

if(($_POST['action']=='SendMessages'))
{

  $class=$_POST['class'];   
  $numbers=$_POST['numbers'];   
  
  //adding a space in the bottom
  $message=$_POST['text_fld'];    

  $branch=$_SESSION['branch'];
  $limit=$_POST['limit'];
  $brand_limit=$_POST['brand_limit'];
  $date=date('Y-m-d');
  

  $msgcount=ceil(strlen($message)/160);
  $cell_no="";

 $numbers2=explode(",",$numbers);
 
  foreach($numbers2 as $numb){
    
  // adding prefix country code


      if(substr($numb,0,1)=="3"){
      $number1 = "92".$numb;
      }else if(substr($numb,0,1)=="0"){
      $number1 =  "92".substr($numb,1);
      }
      else if(substr($numb,0,2)=="92"){
      $sendmsg1 =  $numb;
      }
      else{
       $number1 = "00";
      }

      $cell_no.=$number1.",";
  }

    if ($_POST['GroupChange']=='AbsentStds') {      
    

	    $sql1 = "SELECT att.date, att.attendance, att.branch_Id, att.student_id, std.student_id, std.cell_no, std.first_name  FROM  eduportal_attendance_detail as att, edu_student_details as std  WHERE att.date='$date' and att.attendance='A' and att.branch_Id='$branch' and att.student_id=std.student_id "; 

	    $sms=0;
	    $absentsms = $m->query($sql1);

	    foreach ($absentsms as $absentdata) {
	     

	      $number=$absentdata['cell_no'];
	      $message ="Respected Parents, ". $absentdata['first_name']." is absent from school today.... From:".$_SESSION['branch_name'];


	      sendSMSFuction($number,$message,$_SESSION['brand']);


	      $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'result_msg' => 1);

	     $m->insert ('edu_messages_details', $data);

	     $sms++;

      
    } // end foreach

  } else { 
    



	  $username = SMSAPI_USER;
	  $password = SMSAPI_PASS;
	  $to = $cell_no;
	  

	if($_POST['from']!="" || $_POST['from']!=NULL ){
	  $from = $_POST['from'];   
	}else {      
	  $from=$_SESSION['brand'];  
	}
	 
    $from = $_SESSION['brand'];  

  //$message=str_replace("'","||",$message);

$curl = curl_init();

$url='https://bsms.ufone.com/bsms_v8_api/sendapi-0.3.jsp?id=03348960296&message='.urlencode($message).'&shortcode=EduPortal&lang=English&mobilenum='.$cell_no.'&password=Ufone@APi@321&groupname&messagetype=Nontransactional';

echo $url."<br><br><br><br>";

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 5000,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Cookie: cookiesession1=678B2881QRSTUVXYZABCDEFGHIMN88F6'
  ),
));

$response = curl_exec($curl);

curl_close($curl);

print_r($response);

 // inserting log detials into db
 $sms=0;
  $count=0;
  $qty=count($numbers2);
  
  $query="insert into edu_messages_details(msg_sender,msg_from,msg_details,msg_status,branch_id,other_msg,msg_count) values";
  foreach($numbers2 as $numb){

   $br=$_SESSION['branch'];
   $query .= " ('$from','$numb','$message','$status','$br','1','$msgcount')";

   if($count < ($qty -1 )){
     $query .=",";
   }
    $count++;
    $sms++;
  } // ending the for loop 

  // inserting all  the queries at once
  $result = $m->query($query);
  

} // ending else



  // updating credit limit of sms
  
  $val=intVal($brid[0]['sms_limit'])-($sms*$msgcount);

  $query="update edu_branch_config set sms_limit='$val' where branch_id=".$_SESSION['branch'];
  $m->query($query);

  // adding the record in audit log
  $username=$_SESSION['username'];
  $action="User: ".$username." ,Action: Messages, New Eng SMS";

  date_default_timezone_set("Asia/Karachi");
	$data = array(
	'user_id' => $_SESSION['user_id'],
	'action' => $action,
	'date' => date("Y-m-d"),
	'month_id' => date('m'),
	'time' => date("h:i:sa"),
	);
  $m->insert('eduportal_users_auditlog_detail',$data);


 //echo "<script>window.location='sent_message.php'</script>";

}  // main 
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title>New Messages | EduPortal</title>
     <?php include('RootMe/css_links.php');?>
   
 <script src="js/ajax_functions.js"></script> 
<script>

function msg_check() {
// alert("786");
var numbers = document.getElementById('numbers').value;
var msgcount = document.getElementById('msgcount1').value;
var smsleft = document.getElementById('sms_left').value;
const arr = numbers.split(',');
var totalnumber=arr.filter(word => word !== ',').length;

var totalNumberOfMessages = msgcount * totalnumber;

if (totalNumberOfMessages > smsleft) {
alert("Can't Send. Because your SMS Limit has been Exceed. Remaning SMS: "+smsleft) ;
return false;
} else {
return true;
}


}

window.onload = myOnload;

function myOnload(evt){

  MakeTextBoxUrduEnabled(message);//enable Urdu in html text area
}

</script>


<style>
.fborder{border: 1px solid #cccccc;}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
   color: #b7b7b7;
}

::-ms-input-placeholder { /* Microsoft Edge */
   color: #b7b7b7;
}
.styletext{line-height: 1.5em; font-family: Arial, Helvetica, sans-serif; font-size: 14px;}

       input.larger { 
      transform: scale(3); 
      margin: 4px 19px 0px 23px;
      } 
   
</style>

  </head>
  
<!-- load counter functions -->
<script type="text/javascript" src="js/counter_funcs.js"></script>
<!-- set the maximum character length value for the field -->

<script type="text/javascript">

  var MAX = 20;
  function check_char_length(elem_id, max_len)
  {
      if(check_content_length(elem_id, max_len)) {
    return true;
      } else {
    // too many chars
    alert("Maximum input length is " + max_len + " characters");
    return false;
      }
  }
    /*]]>*/
    </script>



<script>

function getValue() {
    var checks = document.getElementsByClassName('checks');
    var str = '';

    for ( i = 0; i < 1; i++) {
        if ( checks[i].checked === true ) {
            str += checks[i].value + " ";
        }
    }
    alert(str);
}


function getEmployees(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_emp_numbers.php?b="+b);
  ajx.send(); 

}



function getInquiryNumber(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_inquiry_numbers.php?b="+b);
  ajx.send(); 

}

function getOldEmployees(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_oldemp_numbers.php?b="+b);
  ajx.send(); 

}



function getPresentStds(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_present_std.php?b="+b);
  ajx.send(); 

}




function getAbsentStds(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_absent_std.php?b="+b);
  ajx.send(); 

}


function getLateStds(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_late_std.php?b="+b);
  ajx.send(); 

}



function getOldStudents(b)
{
   // alert(b);
  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
          //alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_oldstd_numbers.php?b="+b);
  ajx.send(); 

}

function getMbileApp(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText);
            total=total.length;
            document.getElementById("text").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("text").value= ajx.responseText;
    }
  }
  ajx.open("GET", "get_app_link.php");
  ajx.send(); 

}

function getParentLink(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText);
            total=total.length;
            document.getElementById("text").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("text").value= ajx.responseText;
    }
  }
  ajx.open("GET", "get_parent_link.php");
  ajx.send(); 

}


function getAbsentSMS(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText);
            total=total.length;
            document.getElementById("text").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("text").value= ajx.responseText;
    }
  }
  ajx.open("GET", "get_absent_sms.php");
  ajx.send(); 

}

function getTeacherLink(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText);
            total=total.length;
            document.getElementById("text").innerHTML=total;
          }
         // alert(ajx.responseText);
          document.getElementById("text").value= ajx.responseText;
    }
  }
  ajx.open("GET", "get_parent_link.php");
  ajx.send(); 

}

function getContacts(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
          // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_contacts.php?b="+b);
  ajx.send(); 

}


function getCategory(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
          // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_cat_contacts.php?cat_id="+b);
  ajx.send(); 

}



function getAllStudentsNumber(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
          // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_all_students_number.php?b="+b);
  ajx.send(); 

}

function getFeeDefaulters(b)
{

  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
          // alert(ajx.responseText);
          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_feedefaulters.php?b="+b);
  ajx.send(); 

}


function FatherMotherNumbers(FM,b)
{

var grp = document.getElementById("group").value;
var cls = document.getElementById("classes").value;
var oldnmbr = document.getElementById("numbers").value;
//alert(oldnmbr);
//alert(FM+" "+b+" "+grp+" "+cls);
  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }
           //alert(ajx.responseText);
          document.getElementById("numbers").value=oldnmbr+","+ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_father_mother_numbers.php?b="+b+"&FM="+FM+"&grp="+grp+"&cls="+cls+"&oldnmbr="+oldnmbr);  
  ajx.send(); 

}




function getGroup(str,b)
{
//alert(str);
  var g;
//var g = document.getElementById("gardian").value;
//alert(g);
  if(str=="Contacts"){
    //alert("Contacts");
    document.getElementById("classes").style.display="none";
    getContacts(b);
    document.getElementById("category").style.display="block";
  }

  else if(str=="inquiry"){
    //alert("Emp");
    document.getElementById("classes").style.display="none";
    document.getElementById("category").style.display="none";
    getInquiryNumber(b);
  }

  else if(str=="Employees"){
    //alert("Emp");
    document.getElementById("classes").style.display="none";
    document.getElementById("category").style.display="none";
    getEmployees(b);
  }
    else if(str=="OldEmployees"){
    //alert("Emp");
    getOldEmployees(b);
  }

     else if(str=="OldStudents"){
    //alert("Emp");
    getOldStudents(b);
  }
 
    else if(str=="OldEmployees"){
    //alert("Emp");
    getOldEmployees(b);
  }

   else if(str=="AbsentStds"){
    //alert("Emp");
    
    getAbsentStds(b);
    getAbsentSMS(b);
    
  }

   else if(str=="PresentStds"){
    //alert("Emp");
    getPresentStds(b);
  }

 else if(str=="LateStds"){
    //alert("Emp");
    getLateStds(b);
  }

   else if(str=="MobileAppLink"){
    //alert("Emp");
    getMbileApp(b);
  }
  else if(str=="ParentPortalLink"){
    //alert("Emp");
    getParentLink(b);
  }
  
  else if(str=="TeacherPortalLink"){
    //alert("Emp");
    getTeacherLink(b);
  }
  else if(str=="Fee"){
    //alert("Emp");
    document.getElementById("classes").style.display="none";
    document.getElementById("category").style.display="none";
    getFeeDefaulters(b);
  }

  else if(str=="Allstd"){
    //alert("Emp");
    
    getAllStudentsNumber(b);
  }
  else {

     if(str!="All"){
    
    document.getElementById("txt_section").style.display="block";
 
    getMsgsec(str);
    
  }

  document.getElementById("classes").style.display="block";
  var ajx;  // The variable that makes Ajax possible!
  
  if(window.XMLHttpRequest)
  ajx=new XMLHttpRequest();
  ajx.onreadystatechange = function()
  {

    if(ajx.readyState == 4)
    {
          // alert(ajx.responseText);  
          
          if(ajx.responseText!=null){
            var total=(ajx.responseText).split(",");
            total=total.length;
            document.getElementById("recipient").innerHTML=total;
          }

          document.getElementById("numbers").value= ajx.responseText.trim();
    }
  }
  ajx.open("GET", "get_numbers.php?class_id="+str+"&b="+b+"&gardian="+g);
  ajx.send(); 

  //FatherMotherNumbers(FM,b);

} // ending else

}

function myFunction() {
    var x = document.getElementById("myDIV");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
}


function apply(str) {
 // alert(str);  
    if (str != null || str != "" ) {
      var x = document.getElementById("text").value=str;
    } else {
      var x = document.getElementById("text").value="";
    }
}






function getMsgsec(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_msg_sect.php?class_id="+id,true);

            xmlhttp.send();




          }






function getClassSectionNumber(id){

//alert(id+"786");
   //var secID = document.getElementById("txt_section").value;
   var clsID = document.getElementById("classes").value;
//alert(clsID);
          
        var ajx;  // The variable that makes Ajax possible!
  
              if(window.XMLHttpRequest)
              ajx=new XMLHttpRequest();
              ajx.onreadystatechange = function()
              {

                if(ajx.readyState == 4)
                {
                      // alert(ajx.responseText);  
                      
                      if(ajx.responseText!=null){
                        var total=(ajx.responseText).split(",");
                        total=total.length;
                        document.getElementById("recipient").innerHTML=total;
                      }
                      //alert(ajx.responseText);
                      document.getElementById("numbers").value= ajx.responseText.trim();
                }
              }

            ajx.open("GET","get_numbers.php?class_id="+clsID+"&secID="+id);

            ajx.send();


}


</script>
  <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="">
           

             <a href="dashboard.php">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
             <a href="new_sms.php">New SMS </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp;  

              New English SMS   

             <a href="sent_message.php" class="btn btn-round btn-info quiklink pull-right"> View Sent SMS </a>

             <a href="newurdusms.php" class="btn btn-round btn-danger quiklink pull-right" >New Urdu SMS </a>
         
  
            <div class="clearfix"></div>


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

<form class="form-style-7" id="add_student" action="testing.php" method="post" onSubmit="return msg_check();" enctype="multipart/form-data" accept-charset='ISO-8859-15'>


  <input type="hidden" name="action"  value="SendMessages">
  <input type="hidden" value="" class="form-control"  id="validate_status" />
  <input type="hidden" name="limit"  value="<?php echo $brid[0]['sms_limit']; ?>" >
 <!--  <input type="text" name="brand_limit"  value="<?php echo $brid[0]['brand_sms_usage']; ?>" > -->


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

   
     </div>

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


          

        <div class="row">

              
               <div class="col-md-12" >
                  <div class="alert alert-danger alert-dismissible fade in">
                    <a href="#" style="color:white;" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong> New Policy By Telecom !</strong> All the messages from this page considered as the non-transaction SMS that will not be delivered between 8:00 PM to 8:00 AM. In between if you will send SMS, it will be received after 8:00 AM.
                  </div>

              </div>
                       
                         
            <?php if($sms_credit<=0){?>
              
               <div class="col-md-12" >
                  <div class="alert alert-danger alert-dismissible fade in">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong>Sorry !</strong> Your SMS Limit is exceeded, Please contact administrator !!!
                  </div>

              </div>
            <?php } ?>  
           


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


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Message is sent successfully...
            </div>


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

                       
                      <div class="col-md-12 col-xs-12" >
                          <div class="form-group" >

                        <div style="float:right;"> 
                              
               
                              <input type="button" onClick="myFunction()" id="button" class="btn btn-primary" style="padding:4px 10px 4px 10px;" value="Add Template" />   
                        </div>
                            
<!--                       <div class="col-md-12 col-xs-12" >
                          <div class="form-group" >
                            
                            <label>  Select Gardian Number : * </label>
                              
                              <select name="gardian" id="gardian" onChange="getGroup(this.value,<?php echo $_SESSION['branch'];?>)" class="select_add" style="height:40px;width: 100%;">
                                <option value="NO"> NO </option>
                                <option value="YES"> YES  </option>
                          </select>
                          </div>
                     </div> -->
                              <div style="float:left;">  <label > Choose Group  </label> 

                              </div>

                            

                              <br/> <br/>

                          
                                <select name="GroupChange" id="group" class="select_add" style="height:40px;width: 100%;" onChange="getGroup(this.value,<?php echo $_SESSION['branch'];?>)"  >
                                <option value="">Select Group </option>

                                <option value="Allstd"> All Students </option>
                                <option value="All"> All Families </option>
                                <option value="Employees"> All Employees </option>
                                <option value="Fee"> Fee Defaulters </option>
                                <option value="Contacts"> Contacts </option>
                                <option value="OldStudents"> All Old Students </option>
                                <option value="OldEmployees"> All Old Employees </option>
                                <option value="PresentStds"> Today Present Students </option>
                                <option value="AbsentStds"> Today Absent Students </option>
                                <option value="LateStds"> Today Late Students </option>
                                <option value="MobileAppLink"> Mobile App Link </option>
                                <option value="ParentPortalLink"> Parents Portal Link </option>
                                <option value="TeacherPortalLink"> Teachers Portal Link </option>
                                <option value="inquiry"> inquiry </option>

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


                  


                       
                      <div class="col-md-12 col-xs-12" >
                          <div class="form-group" >


                                <select name="class" id="classes" class="select_add" style="height:40px;display:none;width: 100%;" onChange="getGroup(this.value,<?php echo $_SESSION['branch'];?>)"  >
                                <option value=""> Select Class  </option>
                                <option value="All"> All Classes  </option>

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

                                   <option <?php if($student[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="col-md-12 col-xs-12" >
                          <div class="form-group" >


                                <select name="section" id="txt_section" onChange="getClassSectionNumber(this.value)" class="" style="height:40px;display:none;width: 100%;"  >                             
                                
                         
                             </select>
                          </div>
                      </div>

                     
                      <div class="col-md-12 col-xs-12" >
                          <div class="form-group" >
                         
                                <select name="category" id="category" class="select_add" style="height:55px;display:none;width: 100%;" onChange="getCategory(this.value,<?php echo $_SESSION['branch'];?>)">
                                <option value="category"> Select Categories </option>
                              

                               <?php
                                $m->where("branch_id", $_SESSION['branch']);
                                 $query="select * from eduportal_contacts_category";
                                 $WorkAssignList = $m->query($query);
                                foreach($WorkAssignList as $WorkAssignListVal)
                               { ?>

                                   <option <?php if($contact[0]['cat_id']==$WorkAssignListVal['cat_id']){echo "selected";} ?>  value="<?php echo $WorkAssignListVal['cat_id']; ?>"><?php echo $WorkAssignListVal['cat_name']; ?></option>


                              <?php  } ?>

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


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

                        <label class="container1 accessFontSize" style="font-size: 15px;float: right;">
                        <input type="checkbox" name="motherNo" onclick="FatherMotherNumbers(this.value,<?php echo $_SESSION['branch'];?>)" value="mother" />
                        Add Mother Number<span class="checkmark"></span>                    
                        </label>

                      

                       

                        <label class="container1 accessFontSize" style="font-size: 15px;float: right;">
                        <input type="checkbox" name="fatherNo" onclick="FatherMotherNumbers(this.value,<?php echo $_SESSION['branch'];?>)" value="father" />
                        Add Father Number&nbsp;&nbsp;<span class="checkmark"></span>                    
                        </label>
                        
                          <div class="form-group" >
                            
                            <label>  Cell Numbers : * </label>
                              
                              <textarea placeholder="03016138728,03016138662..." class="form-control message1 form-textarea" required rows="7" id="numbers" name="numbers" style="line-height: 1.5em; font-family: Arial, Helvetica, sans-serif; font-size: 14px;"><?php echo ltrim($_GET['students'], 'undefined,');?></textarea>
                          </div>
                      </div>


                    <div class="col-md-12 col-xs-12" style="display:none;" id="myDIV" >

                          <div class="form-group" >


                            
                              <div style="float:left;">  <label >  Select Template </label> 

                              </div>

                           
                                <select name="class" id="template" class="select_add" style="width: 100%;height: 44px;" onChange="apply(this.value)"  >
                                <option value="">Choose Template </option>

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

                                   <option <?php if($student[0]['template_title']==$WorkAssignListVal['template_title']){echo "selected";} ?> value="<?php echo $WorkAssignListVal['template_detail']; ?>"><?php echo $WorkAssignListVal['template_title']; ?></option>


                              <?php  } ?>

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


    
                       
                      <div class="col-md-12 col-xs-12" >
                          <div class="form-group" >


                             <label> From  </label> 

                               <select name="from" id="from" class="select_add" style="height:40px;width: 100%;"  >
                                

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

                   <option value="<?php echo $WorkAssignListVal['mask_name']; ?>"><?php echo $WorkAssignListVal['mask_name']; ?></option>


                              <?php  }*/ ?>
                              <option value="EduPortal">EduPortal</option>

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

                      

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

                         
                          <div class="form-group" >
                              
                              <label>  Message : * </label>
                    
                              
                                 <textarea class="form-control message1 form-textarea styletext" required maxlength="612"  rows="7" id="text" name="text_fld" ><?php echo $_GET['msg'];?></textarea>
                                                 
     
                            </div>
                   </div>   


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


                          <div class="msg-count">

                            <div class="col-md-4 col-sm-4" >
                              <strong><span>Total:<span id="char">0</span></span></strong>

                            </div>

                           <div class="col-md-4 col-sm-4" >
                              <strong>Contacts:<span id="recipient">0</span></strong>
                            </div>
                            
                            
                            <div class="col-md-4 col-sm-4" style="text-align:right;">
                              <strong class="text-right" ><span>Left:<span id="leavechar">160</span></span></strong>                            
                            </div>
                            
                            
                            <div class="col-md-4 col-sm-4" style="text-align:right;">
                              <strong class="text-right" ><span class="text-right">MAX:<span id="maxcount">612</span></span></strong>
                            
                            </div>
                            
                            <div class="col-md-4 col-sm-4" style="text-align:right;">
                              <strong class="text-right" ><span class="text-right">Count:<span onChange="msg_count();" id="msgcount">0 
                              </span></span></strong>
                             <input type="hidden" name="msgcount1" id="msgcount1" value="0" />
                            </div>


                              <input type="hidden" name="id" id="id" value="">
                         
                          </div>



                   </div>   


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

                        <br> <br>
            

     
        
                        <?php if($sms_credit<=0){?>

                          <div class="alert alert-danger alert-dismissible fade in">
                            <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                            <strong>Sorry !</strong> Your SMS Limit is exceeded, Please contact administrator !!!
                          </div>
                             <input disabled type="submit" value=" Send Message " class="pull-right btn btn-primary" >
                       

                        <?php } elseif($brid[0]['sms_service']=="0") { ?>  

                           <input type="submit" value=" Send Message " class="pull-right btn btn-primary" >    
                       
                        <?php } elseif($brid[0]['sms_service']=="1") { ?>

                        <input disabled type="submit" value=" Send Message " class="pull-right btn btn-primary" >

                         <?php } ?>


                     </div>                    


    
                   </div>  <!-- ending row-->


    </div>   <!--  ending 10 column-->



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

    

     </div>

    </form>

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


     </div>   <!--  main row -->

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

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

 <?php include('RootMe/js_linksscript.php');?>
 
  <script type="text/javascript">
$(document).ready(function() {

        
        document.getElementById("text").value = '';
        $("#text").removeAttr('dir');
        $('.unicode-show').hide();
        $("#text").attr('maxlength', '612');
        document.getElementById('char').innerHTML = "0";
        document.getElementById('leavechar').innerHTML = "160";
        document.getElementById('maxcount').innerHTML = "612";
        document.getElementById('msgcount').innerHTML = "0";
        


    function show(ch, leave, messagecount, total, maxLen) {
        $('#char').html(ch);
        $('#leavechar').html(leave);
        $('#maxcount').html(maxLen);
        $('#msgcount').html(messagecount);
        $("#message").attr('maxlength', maxhtml);
    };




$("[name='text_fld']").keyup(function() {
        var len = this.value.length;
        
        
        if (len!= "") {
           
            var chars = 1;
            var msgs = 1;
            var maxLen = 612;
            var level1 = 160;
            var level2 = 146;
            var level3 = 153;
            var level4 = 153;

            maxhtml = 612;
          

            if (len == 0) {
                show(0, level1, 0, 0, maxLen);
            } else if (len > 0 && len <= level1) {
                var tot;
                tot = "";
                show(len, level1 - len, 1, len, maxLen - len);
                document.getElementById("msgcount1").value=1;
            } else if (len > level1 && len <= (level2 + level1)) {
                var tot;
                tot = len - level1;
                show(tot, level2 - tot, 2, len, maxLen - len);
                document.getElementById("msgcount1").value=2;
            } else if (len > (level2 + level1) && len <= (level3 + level1 + level2)) {
                var tot;
                tot = len - (level1 + level2);
                show(tot, level3 - tot, 3, len, maxLen - len);
                document.getElementById("msgcount1").value=3;
            } else if (len > (level3 + level1 + level2) < len <= maxLen) {
                var tot;
                tot = len - (level1 + level2 + level3);
                show(tot, level4 - tot, 4, len, maxLen - len);
                document.getElementById("msgcount1").value=4;
                
                 if (maxLen - len<0){
                    msg = $('#message').val(); 
                    str = msg.slice(0, maxLen - len);
                    document.getElementById("message").value = str;
                    return;   
                    }
                 
                 
           
                
                
            } else {


            }
        }
    });

});
</script>

 <script>

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

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


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