<?php
$pgMod="sms";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


//error_reporting("555");
//print_r($_REQUEST);print_r($_FILES);exit;
if(isset($_REQUEST["sms"]) && ($_POST["msgHindi"]!="" || $_POST["msgEnglish"]!="")){
    // print_r($_POST);
    // die();
	$status="";$send="";$fail="";
	$mob=array();$alert_err=array();$mmm="";
	
	$template = $db->getRow("select entityid, senderid from template where templateid='$_POST[TemplateID]' ");
	$entityid = $template["entityid"];
	$senderid = $template["senderid"];
	
	
	if(is_array($_POST["cat"]) && count($_POST["cat"])>0){ 
		for($i=0;$i<(count($_POST["cat"]));$i++){
			$idno=$_POST["cat"][$i];
			
        if($_GET['type']=="enquiry"){
    		$phoneNumber = $db->getVal("select mobile from enquiry where idno='$idno'");
        } else {
    		$phoneNumber = $db->getVal("select mobile from student where idno='$idno'");
        }
// die();
			if($phoneNumber != ""){

    // 			if($_POST["changer"]=="hindi")
    // 			$status.=sms($phoneNumber,$_POST["msgHindi"],$_GET["type"]."_sms");
    // 			else
    // 			$status.=sms($phoneNumber,$_POST["msgEnglish"],$_GET["type"]."_sms",$_POST["TemplateID"]);

                if($_GET["type"] == "class" || $_GET["type"]=="hostel"){
			        $type= "class_sms";
			    } else {
			        $type =  $_GET["type"]."_sms";
			    }

    			if($_POST["changer"]=="hindi")
    			$status.=sms($phoneNumber,$_POST["msgHindi"],$type,$_POST["TemplateID"],$entityid,$senderid);
    			else
    			$status.=sms($phoneNumber,$_POST["msgEnglish"],$type,$_POST["TemplateID"],$entityid,$senderid);

			}
		}
	}
	if($status!=""){
		$_SESSION["msg"]="message send successfully"; 
		redirect();
	}
	?><script>
    $(document).ready(function(e) {
        $('#loaders').hide()
    });
    </script><?php
	
}

elseif(isset($_REQUEST["templatesms"]) ){
	$status="";$send="";$fail="";
	$mob=array();$alert_err=array();$mmm="";
	
	$template = $db->getRow("select entityid, senderid from template where templateid='$_POST[TemplateID]' ");
	$entityid = $template["entityid"];
	$senderid = $template["senderid"];

	
	if(is_array($_POST["cat"]) && count($_POST["cat"])>0){
		for($i=0;$i<(count($_POST["cat"]));$i++){
        
        $idno=$_POST["cat"][$i];
			
		$phoneNumber = $db->getVal("select mobile from student where idno='$idno'");


    		if($phoneNumber != ""){

                $ch_name=$db->getRow("select name,admissionno,password,mobile from student where idno='".$idno."' and  session='".$_SESSION["admin"]["session"]."' ");
            
            	$pass = new password();
            	$salt = "CrazyassLongSALTThatMakesYourUsersPasswordVeryLong123!!312567__asdSdas";
            	$pwd = $pass->encrypt_decrypt("decrypt", $ch_name["password"] , $salt, "a1b2c3a1b2c3a1b2");
            
            //   	$SMSdetail="Dear Parents , Download your School App of your child(".$ch_name["name"].") from google play store ".$LinksDetails["website"]." or you can type your school name on play store \n user id-".$ch_name["admissionno"]."  \n password -".$pwd." Regards Principal SCHOOL";
                    
                $msg = "Dear Parents, $LinksDetails[website], Regards Principal userid-$ch_name[admissionno] pwd-$pwd";
                            
                // $_GET["type"]="class";
        // 		$status.=sms($ch_name["mobile"],$SMSdetail,$_GET["type"]."_sms");
                $type= "class_sms";
                $status.=sms($phoneNumber,$msg,$type,$_POST["TemplateID"],$entityid,$senderid);
            }
		}
	}

	if($status!=""){
		$_SESSION["msg"]="message send successfully";
		redirect();
	}
	?><?php
	
}

 /*
elseif(isset($_REQUEST["templatesms"]) ){
	$status="";$send="";$fail="";
	$mob=array();$alert_err=array();$mmm="";
	if(is_array($_POST["cat"]) && count($_POST["cat"])>0){
		for($i=0;$i<(count($_POST["cat"]));$i++){
			$Number=$_POST["cat"][$i];
            $str_arr = explode (",", $Number);  
            print_r($str_arr);
 	for($k=0;$k<(count($str_arr));$k++) { 
    //  print_r($str_arr[$k]);
    //  die();
     $pt = explode ("~", $str_arr[$k]);  

    $pt[0];
    $pt[1];

  $ch_name=$db->getRow("select name,admissionno,password,mobile from student where idno='".$pt[0]."' and  session='".$_SESSION["admin"]["session"]."' ");
		    //echo 	 $ss="select name,admissionno,password from student where mobile='".$pt[0]."' and  idno='".$pt[1]."' and  session='".$_SESSION["admin"]["session"]."' ";
	$ch_name["admissionno"];

	$pass = new password();
	$salt = "CrazyassLongSALTThatMakesYourUsersPasswordVeryLong123!!312567__asdSdas";
	$pwd = $pass->encrypt_decrypt("decrypt", $ch_name["password"] , $salt, "a1b2c3a1b2c3a1b2");
	
	      //echo	$SMSdetail="Dear Parents,   Download your School App from google play store ".$ch_name['admissionno']."      ";
      	$SMSdetail="Dear Parents, Download your School App of your child(".$ch_name["name"].") from google play store ".$LinksDetails["website"]." or you can type your school name on play store \n user id-".$ch_name["admissionno"]."  \n password -".$pwd." Regards Principal SCHOOL";

$_GET["type"]="class";
			$status.=sms($ch_name["mobile"],$SMSdetail,$_GET["type"]."_sms");
		
 }
		}  
	}

	if($status!=""){
		$_SESSION["msg"]="message send successfully";
		redirect();
	}
	?><?php
	
}
*/

elseif(isset($_REQUEST["voice"])){
	
	//echo "voide ";exit;
	if(isset($_FILES["vsms"]["name"]) && !empty($_FILES["vsms"]["name"])){
		$lfilename = basename($_FILES['vsms']['name']);
		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
		if($lext=="wav" || $lext=="mp3"){
			set_time_limit(300);
			$server_path = "/mssinfotech/uploads/vcall/";
			$file_tmp_name = $_FILES["vsms"]["tmp_name"];
			
			$ftp_server = "66.96.147.115";
			$ftp_username = "mssinfotech";
			$ftp_password = "Mragank@123";
			$file_name = $_FILES["vsms"]["name"];
			
			// Create FTP stream, a connection to the FTP server
			$connection = ftp_connect($ftp_server);
			
			// Login to the server
			$ftp_conn = ftp_login($connection, $ftp_username, $ftp_password);
			
			// Login check
			if ((!$connection) || (!$ftp_conn)) {
				//echo "<p>Connection to <b>$ftp_server</b> for user<b>$ftp_username</b> FAILED</p>"; exit;
			} else {
				// Upload file to specified path
				$ftp_upload = ftp_put($connection,
				str_replace("//","/",$server_path."/".$file_name),
				$file_tmp_name, FTP_BINARY);					
				// Close FTP connection
				ftp_close($ftp_conn);
			
				$status="";$send="";$fail="";
				$mob=array();$alert_err=array();$mmm="";
				if(is_array($_POST["cat"]) && count($_POST["cat"])>0){
					for($i=0;$i<(count($_POST["cat"]));$i++){
						$phoneNumber=$_POST["cat"][$i];
						//$_POST["photo"]=$lnewfile;
						$status.=vsms("http://mssinfotech.com/uploads/vcall/".$file_name,$phoneNumber,$_GET["type"]."_sms");
					}
					$_SESSION["msg"]="voice sms send successfully";
					redirect();
				}else{
					$alert_err[]="Please select atleast one student";		
				}
			}
		}else{
			$alert_err[]="invalid file please upload only wav or mp3 file of 30sec.";
		}
	}else{
		$alert_err[]="please select any wav or mp3 file";
	}
	
	?><script>
    $(document).ready(function(e) {
        $('#loaders').hide()
    });
    </script><?php
}

if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
    <embed src='media/sms_voice.mp3' width='180' height='90' loop='false' autostart='true' hidden='true' style="position:absolute; top:-1000px" />
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
?><div id="loaders" style="position:fixed; z-index: 999999999; padding-top: 15%; display:none; top:0; left:0; width:100%; height:100%; opacity:0.7; background-color:#000; vertical-align:central; text-align:center">
    	<img src="assets/img/load.gif" /><br />
		<h1>Loading...</h1>
    </div>
<!-- Forms --> 
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 96.7% !important;overflow: inherit !important;} 
.classList{cursor:pointer;text-decoration:none;display:block;border:1px solid #666;margin: 5px 0;padding: 5px 11px;}
.selected{background-color: #ccc;color: #fff;font-weight: bolder;box-shadow: 5px 5px 16px #000;}
.imgs{float:left;height: 60px;margin-right: 10px;}
.classList span{color:#F00; font-weight:bolder;}
.driverDetail { border: 1px solid #000;padding: 5px 10px;background-color: #ccc;box-shadow: 0 0 10px #2B2929;font-weight: bolder;font-size: 14px;margin: 10px 5px;}
.cat {	display: inline-block;	width: 87%;	border: 1px solid #ccc;	padding: 5px 10px;	box-shadow: 4px 3px 6px #ccc;	cursor: pointer;	margin-right: 6px;}
.subcat {	display: inline-block;	width: 75%;	border: 1px solid #ccc;	padding: 5px 10px;	box-shadow: 4px 3px 6px #ccc;	cursor: pointer;	margin-left: 28px;}
.selected{	box-shadow: inset 0 0 10px #ccc;}
.cat .check, .subcat .check{	float: left;	margin: 5px 5px 5px 0;}
</style>
<script type="text/javascript" src="https://www.google.com/jsapi?key=AIzaSyC1uIsI9XJycYUDq1B7iMjn3jnPDx-5gkY"></script>

<script type="text/javascript">
function checkAll(checkboxa){
    if($('#'+checkboxa).is(':checked')) {
        $('.'+checkboxa).attr('checked', 'checked');
		$('.'+checkboxa).parent('span').addClass('checked');
    } else {
		$('.'+checkboxa).parent('span').removeClass('checked');
        $('.'+checkboxa).removeAttr('checked');
    }
}
$(document).ready(function(){
    $("#filter").keyup(function(){
 
        // Retrieve the input field text and reset the count to zero
        var filter = $(this).val(), count = 0;
 
        // Loop through the comment list
        $(".subcat").each(function(){
 
            // If the list item does not contain the text phrase fade it out
            if ($(this).text().search(new RegExp(filter, "i")) < 0) {
                $(this).fadeOut();
 
            // Show the list item if the phrase matches and increase the count by 1
            } else {
                $(this).show();
                count++;
            }
        });
 
        // Update the count
        var numberItems = count;
        //$("#filter-count").text("Number of Comments = "+count);
    });
});
google.load("elements", "1", {
	packages: "transliteration"
  });

function onLoad() {
	var options = {
		sourceLanguage:
			google.elements.transliteration.LanguageCode.ENGLISH,
		destinationLanguage:
			[google.elements.transliteration.LanguageCode.HINDI],
		shortcutKey: 'ctrl+g',
		transliterationEnabled: true
	};
	
	// Create an instance on TransliterationControl with the required
	// options.
	var control =
		new google.elements.transliteration.TransliterationControl(options);
	
	// Enable transliteration in the textbox with id
	// 'transliterateTextarea'.
	control.makeTransliteratable(['transliterateTextarea']);
}
google.setOnLoadCallback(onLoad);
function checkHindi(){
	// Load the Google Transliterate API
  	var checkID=$(".checkHindiClass").attr("id");
	if(checkID=="transliterateTextarea"){
		$(".checkHindiClass").removeAttr("id");
	}else{
		$(".checkHindiClass").attr("id","transliterateTextarea");
	}
}

	function AppSMS(typs){
        if(typs=='route'){
            
        
		var route = [];

		var msg = $("#englishtext").val();

		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
                // alert($(this).attr("data-route"));
                route.push($(this).attr("data-route"));
			}
		})

        $.post( "sms/ajax.php", { type: "routenotification", route:route, msg: msg } , function( data ) {
	   // 	alert(data);
    	});

	}
	
	if(typs=='student'){
            
        
		var student = [];

		var msg = $("#englishtext").val();

		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
                 //alert($(this).attr("data-faculty"));
               student.push($(this).attr("data-student"));
			}
		})

        $.post( "sms/ajax.php", { type: "studentnotification", student:student, msg: msg } , function( data ) {
	   // 	alert(data);
    	});

	}
	
	if(typs=='class'){
            
        
		var classs = [];

		var msg = $("#englishtext").val();

		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
                 //alert($(this).attr("data-faculty"));
               classs.push($(this).attr("data-classe"));
			}
		})

        $.post( "sms/ajax.php", { type: "classnotification", classs:classs, msg: msg } , function( data ) {
	   // 	alert(data);
    	});

	}
	
}
</script>
<form method="post" action="" enctype="multipart/form-data">
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Send SMS to Selected <?php echo $checkbox=ucfirst($_GET["type"]); ?></h3>
            </div>
            <div class="well">
			<!-- Forms: Box -->
			<div class="span6">
				<!-- Forms: Top Bar -->
				<div class="top-bar">
                    <h3><i class="icon-cog"></i><input type="text" id="filter" style="float:right; margin-left:30px" placeholder="Search Here" />
                    <label style="float:right; margin-left:10px;" for="<?php echo $checkbox; ?>">All  <?php echo ucfirst($_GET["type"]); ?></label>
                        <?php $allclass   = $db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
                              $allsection = $db->getRows("select * from section"); 
                        if($_GET["type"] == "class"){
                             ?>
                        <input  onclick="fetchByClass(<?php echo count($allclass); ?>,<?php echo count($allsection); ?>,'allclass')" class="check" type="checkbox" value="1" id="<?php echo $checkbox; ?>" />
                        <?php }

                        else if($_GET["type"] == "hostel"){
                             ?>
                        <input onclick="fetchByHostel(<?php echo count($allclass); ?>,<?php echo count($allsection); ?>,'allhostel')" class="check" type="checkbox" value="1" id="<?php echo $checkbox; ?>" />
                        <?php }

                        else { ?>
                        <input  onchange="checkAll('<?php echo $checkbox; ?>')" class="check" type="checkbox" name="cat[]" value="1" id="<?php echo $checkbox; ?>" />
                        <?php }?>
					
                    </h3>
                </div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
			<div class="well no-padding" style="">

            <div class="control-group">
                <?php
				if($_GET["type"]=="student"){
					$arr=explode(",",$_REQUEST['chk']);
					$class=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status = 1 order by name");
					if(is_array($class) && count($class)>0){$i=0;
						foreach($class as $cla){
							$id=$cla["idno"];
							 ?>
                        	<div class="subcat">
                            <?php if($arr[$i]==$cla["idno"]) { $i++;?>
                                <input data-student="<?php echo $cla["idno"]; ?>" class="check <?php echo $checkbox; ?> checkboxes" type="checkbox" name="cat[]" value="<?php echo $id;?>" id="cat<?php echo $cla["idno"]; ?>"checked="checked" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?>(<?php echo $cla["class"] ?>)</label>
                                <?php } else { ?>
                                <input  data-student="<?php echo $cla["idno"]; ?>" class="check <?php echo $checkbox; ?> checkboxes" type="checkbox" name="cat[]" value="<?php echo $id;?>" id="cat<?php echo $cla["idno"]; ?>" />				
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?>(<?php echo $cla["class"] ?>)</label>
								 <?php } ?>

                            </div>
                          <?php }		
					}	
				}elseif($_GET["type"]=="faculty"){
					$class=$db->getRows("select * from staff  where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name ");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ ?>
                        	<div class="subcat">
                            
                                <input data-faculty="<?php echo $cla["idno"]; ?>" class="check <?php echo $checkbox; ?> checkboxes" type="checkbox" name="cat[]" value="<?php echo $cla["idno"];?>" id="cat<?php echo $cla["idno"]; ?>" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?></label>
                            </div>
                          <?php }		
					}
				}
				/*elseif($_GET["type"]=="class"){
					$class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ $number=array();
							$mobile=$db->getRows("select mobile from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$cla["class"]."' and  session='".$_SESSION["admin"]["session"]."' and status = 1");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
								}
							}
						?>
                        	<div class="subcat">

                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $cla["id"]; ?>" />
                                <label for="cat<?php echo $cla["id"]; ?>"><?php echo $cla["class"] ?></label>
                            </div>
                          <?php }		
					}
				}*/
				
				elseif($_GET["type"]=="class"){
					$class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($class) && count($class)>0){
						$j = 0;
						foreach($class as $cla){ $number=array(); $j++;

							$mobile=$db->getRows("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$cla["class"]."' and  session='".$_SESSION["admin"]["session"]."' and status = 1");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
								}
							}
							
							$sections = $db->getRows("select * from section");
						?>
                        	<div class="subcat">

                                <input data-classe="<?php echo $cla["id"]; ?>" class="check <?php echo $checkbox; ?> checkboxes" type="checkbox"  value="<?php echo implode(",",$number);?>" id="cat<?php echo $j; ?>" onclick="fetchByClass(<?php echo count($class); ?>, <?php echo count($sections); ?>)" data-class="<?php echo $cla["class"]; ?>" />
                                <label for="cat<?php echo $cla["id"]; ?>">
                                    <span style="width:50px;position:absolute;">
                                        <?php echo $cla["class"] ?>                                        
                                    </span>
                                    <span style="position:relative;margin-left:50px;">
                                        <?php $s=1; foreach($sections as $sec){
                                            $allstudent = $db->getVal("select count(idno) from student where class='".$cla["class"]."' and section='".$sec['name']."' and  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and status = 1");
                                                if($allstudent > 0){
                                                    echo " <input  type='checkbox' class=' <?php echo $checkbox; ?> ' value='$sec[name]' id='sec_$j_$sec[id]' onclick='fetchByClass(".count($class).", ".count($sections).")' /> $sec[name] &nbsp";
                                                }
                                            }
                                        ?>
                                    </span>
                                </label>

                            </div>
                          <?php }
					}
				}
				
				elseif($_GET["type"]=="department"){
					$class=$db->getRows("select * from department where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ $number=array();
							$mobile=$db->getRows("select mobile from staff where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$cla["class"]."' and  session='".$_SESSION["admin"]["session"]."'");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
								}
							}?>
                        	<div class="subcat">
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $cla["id"]; ?>" />
                                <label for="cat<?php echo $cla["id"]; ?>"><?php echo $cla["name"] ?></label>
                            </div>
                          <?php }		
					}
				}
				elseif($_GET["type"]=="transport"){
						$class=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and bus!='' and issue_TC=0 and status = 1 order by name");
					if(is_array($class) && count($class)>0){$i=0;
						foreach($class as $cla){
							$id=$cla["idno"];
							 ?>
                        	<div class="subcat">
                            
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo $cla["idno"];?>" id="cat<?php echo $cla["idno"]; ?>" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?>(<?php echo $cla["class"] ?>)</label>
							</div>
                          <?php		
					}	}
				}
				elseif($_GET["type"]=="bus"){
					$bus=$db->getRows("select * from bus where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($bus) && count($bus)>0){
						foreach($bus as $b){ $number=array();
							$mobile=$db->getRows("select mobile from student where school_id='".$_SESSION["admin"]["school_id"]."' and bus='".$b["id"]."' and  session='".$_SESSION["admin"]["session"]."' and status = 1");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
								}
							}
						?>
                        	<div class="subcat">
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $cla["id"]; ?>" />
                                <label for="cat<?php echo $b["id"]; ?>"><?php echo $b["root"] ?></label>
                            </div>
                          <?php }
					}
				}

				elseif($_GET["type"]=="route"){
					$route=$db->getRows("SELECT * FROM location group by name  ");
					if(is_array($route) && count($route)>0){
						foreach($route as $b){ $number=array();
							$mobile=$db->getRows("select mobile from student where school_id='".$_SESSION["admin"]["school_id"]."' and location='".$b["id"]."' and  session='".$_SESSION["admin"]["session"]."' and status = 1");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
									
									}
								 echo implode(",",$number);
							}
						?>
                        	<div class="subcat">
                                <input data-route="<?php echo $b["id"]; ?>" class="check <?php echo $checkbox; ?> checkboxes" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $b["id"]; ?>" />
                                <label for="cat<?php echo $b["id"]; ?>"><?php echo $b["name"] ?></label>
                                
                                <!--<input class="checkboxes" type="hidden" value="<?php echo $b["id"]; ?>" />-->
                                
                            </div>
                        <?php }
					}
				}

				elseif($_GET["type"]=="all"){
					?><hr>Student<hr><?php
					$class=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 order by name");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ ?>
                        	<div class="subcat">
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo $cla["mobile"];?>" id="cat<?php echo $cla["idno"]; ?>" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?>(<?php echo $class["class"] ?>)</label>
                            </div>
                          <?php }		
					}
					?><hr>Faculty<hr><?php
					$class=$db->getRows("select * from staff where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ $number=array();
							$mobile=$db->getRows("select mobile from staff where idno='".$cla["idno"]."' and school_id='".$_SESSION["admin"]["school_id"]."' ");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
								}
							}  ?>
                        	<div class="subcat">
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $cla["idno"]; ?>" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?></label>
                            </div>
                          <?php }		
					}
				}
				elseif($_GET["type"]=="enquiry"){
					$arr=explode(",",$_REQUEST['chk']);
					$class=$db->getRows("select * from enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status = 1 order by name");
					if(is_array($class) && count($class)>0){$i=0;
						foreach($class as $cla){
							$id=$cla["idno"];
							 ?>
                        	<div class="subcat">
                            <?php if($arr[$i]==$cla["idno"]) { $i++;?>
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo $cla["idno"];?>" id="cat<?php echo $cla["idno"]; ?>"checked="checked" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?>(<?php echo $cla["class"] ?>)</label>
                                <?php } else { ?>
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo $cla["idno"];?>" id="cat<?php echo $cla["idno"]; ?>" />
                                <label for="cat<?php echo $cla["idno"]; ?>"><?php echo $cla["name"] ?>(<?php echo $cla["class"] ?>)</label>
								 <?php } ?>

                            </div>
                          <?php }		
					}	
				}
				
				
				
				elseif($_GET["type"]=="app_data"){
					$class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ $number=array();
							$mobile=$db->getRows("select idno,mobile from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$cla["class"]."' and  session='".$_SESSION["admin"]["session"]."' and status = 1");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"]."~".$mob["idno"];
								
								

								}
							}
						?>
                        	<div class="subcat">

                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $cla["id"]; ?>" />
                                <label for="cat<?php echo $cla["id"]; ?>"><?php echo $cla["class"] ?></label>
                            </div>
                          <?php }		
					}
				}	
				
				
				elseif($_GET["type"]=="enquiry_class"){
					$class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
					if(is_array($class) && count($class)>0){
						foreach($class as $cla){ $number=array();
							$mobile=$db->getRows("select mobile from enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$cla["class"]."' and  session='".$_SESSION["admin"]["session"]."' and status = 1");
							if(is_array($mobile) && count($mobile)>0){
								foreach($mobile as $mob){
									$number[]=$mob["mobile"];
								}
							}
						?>
                        	<div class="subcat">
                                <input class="check <?php echo $checkbox; ?>" type="checkbox" name="cat[]" value="<?php echo implode(",",$number);?>" id="cat<?php echo $cla["id"]; ?>" />
                                <label for="cat<?php echo $cla["id"]; ?>"><?php echo $cla["class"] ?></label>
                            </div>
                          <?php }		
					}
				}?>
						</div>
                          
                        
						
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
			<!-- Forms: Box -->
			<div class="span6">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
				    
                    <h3>Enter SMS </h3>

				    
                    <!--<h3>Enter SMS  <a href="javascript:;" onclick="changelang()" id="switcher">Click Here To Start Typing in English</a>-->
                            
                    <!--</h3>-->
                </div>
				<!-- / Forms: Top Bar -->
          
				<!-- Forms: Content -->
				<div class="well no-padding">

						<div class="control-group">
							<label class="control-label" for="inputInline">Select Template</label>
                            <div class="controls">
                                <select id="templateid" name="TemplateID" onchange="getTemplate(this.value)" required>
                                    <option value="">--Select Template--</option>
                                    <?php $alltemplate = $db->getRows("select * from template ");
                                          foreach($alltemplate as $template){ ?>
                                          <option value="<?php echo $template['templateid']; ?>"><?php echo $template['name']." - ".$template['templateid']; ?></option>
                                    <?php } ?>
                                </select>
							</div>
						</div>


					<!-- Forms: Form -->
                    <!-- Forms: Form Textarea -->
						<div class="control-group">
							<label class="control-label" for="inputInline"><i class="icon-edit"></i> SMS Content
                           <input type="hidden"  name="changer" id="changer" value="english" />
                            </label>
							<!--<div class="controls" id="hindi">-->
							<!--	<textarea maxlength="70" name="msgHindi" rows="3" class="span12 checkHindiClass" id="transliterateTextarea"></textarea>-->
       <!--                     <p id="hindiLeft"></p>-->
							<!--</div>-->
                            <div class="controls" id="english">
							<textarea name="msgEnglish" id="englishtext" maxlength="<?php echo $LinksDetails["perpage"]; ?>" rows="3" class="span12"></textarea>
                            <p id="englishLeft"></p>
							</div>
						</div>
						<!-- / Forms: Form Textarea -->

	 
						<!-- Forms: Form Actions -->
						<div class="form-actions">
							<button type="submit" name="sms" value="sms" onclick="$('#loaders').show()" class="btn btn-primary"> Send</button>
							<button type="reset" class="btn"> Cancel</button>
							    
							<p onclick="AppSMS('<?php echo $_GET["type"] ?>')" class="btn btn-danger" style="float:right;">Send App Notification</p>
							
						</div>

                    <!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

				</div>
				<!-- / Forms: Content -->
		  </div>
          <div class="span6">
          		<div class="top-bar">
                    <h3>Send Voice Call</h3>
                </div>
          		<div class="well no-padding">

					<!-- Forms: Form -->
                    <!-- Forms: Form Textarea -->
						<div class="control-group">
							<label class="control-label" for="inputInline"><i class="icon-edit"></i> File(.wav,mp3) </label>
							<div class="controls">
								<input type="file" name="vsms" />
							</div>
                            
						</div>
						<!-- / Forms: Form Textarea -->

	 
						<!-- Forms: Form Actions -->
						<div class="form-actions">
							<button type="submit" name="voice" onclick="$('#loaders').show()" value="sms" class="btn btn-primary"> Send</button>
							

							<button type="reset" class="btn"> Cancel</button>
						<button type="submit" name="templatesms" onclick="$('#loaders').show()" value="templatesms" class="btn btn-primary"> Send App Template</button>

						</div>

                    <!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

				</div>
			</div>
			<!-- / Forms: Box -->
			
            <div class="span6">
          		<div class="top-bar">
                    <h3>Student List</h3>
                </div>
          		<div class="well no-padding">
          	            <div id="studentList"></div>	    
      		    </div>
  		    </div>
			
			
            </div>
        </div>
        
	</div>
</form>
<!-- / Forms -->
<script>
$(document).ready(function(){
    $('textarea[maxlength]').keyup(function(){
        var max = parseInt($(this).attr('maxlength'));
        if($(this).val().length > max){
            $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
        }
        $(this).parent().find('.charsRemaining').html('You have ' + (max - $(this).val().length) + ' characters remaining');
    });
});


function changelang(){
	var ctype=$("#changer").val();
	if(ctype=="english"){
		$("#changer").val('hindi');
		$("#switcher").html('Click Here To Start Typing in English');
		$("#hindi").show();
		$("#english").hide();
	}else{
		$("#changer").val('english');
		$("#switcher").html('Click Here To Start Typing in Hindi');
		$("#hindi").hide();
		$("#english").show();
	}
}
$('#englishLeft').text('<?php echo $LinksDetails[perpage]; ?> characters left');
$('#englishtext').keyup(function () {
	var max = <?php echo $LinksDetails[perpage]; ?>;
	var len = $(this).val().length;
	if (len >= max) {
		$('#englishLeft').text(' you have reached the limit');
	} else {
		var ch = max - len;
		$('#englishLeft').text(ch + ' characters left');
	}
});
$('#hindiLeft').text('70 characters left');
$('#transliterateTextarea').keyup(function(){
	var max = 70;
	var len = $(this).val().length;
	if (len >= max) {
		$('#hindiLeft').text(' you have reached the limit');
	} else {
		var ch = max - len;
		$('#hindiLeft').text(ch + ' characters left');
	}
});

function getTemplate(id){
    $.post( "sms/ajax.php", { type: "getcontent", templateid: id } , function( data ) {
	  	$("#englishtext").val(data);
	});
}

function fetchByClass(totalclass, totalsection, type){

    var classes = [];
    
    if(type == 'allclass'){
        if($('#Class').is(':checked')) {
            $(".Class").prop("checked", true);
        } else {
            $(".Class").prop("checked", false);
        }
    }

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
        if (document.getElementById("cat"+i).checked) {
            var cls = document.getElementById("cat"+i).getAttribute("data-class");
            var  sectest = [];
            for(var j=1; j<=totalsection; j++){
                if (document.getElementById("sec_"+i+"_"+j)) {
                    if (document.getElementById("sec_"+i+"_"+j).checked) {
                        var sec = document.getElementById("sec_"+i+"_"+j).value;
                        sectest.push(sec);
                    }
                }
            }
            
            classes.push({class:cls, section:sectest});
        }
    }
    }

    $.post("sms/ajax.php", { type: "get_student_list", classAry: classes}, function( data ) {
        // alert(data);
        $('#studentList').html(data);
    });

}

function checkStudents(){
    if (document.getElementById("checkall").checked) {
        $(".check-students").prop("checked", true);
    } else {
        $(".check-students").prop("checked", false);
    }
}

</script>