<?php
date_default_timezone_set("Asia/Dhaka");
    $checkbox = $_POST['selectedcheckbox'];
    $student_id=$_POST['student_id'];
    $cell_number=$_POST['cell_number'];
    $add_absent=$_POST['data_update'];
    //$moble_number[]= $checkbox;
    //$checkbox='['.$checkbox.']';
    $st_id=json_decode($student_id,true);
    $st_cell_number=json_decode($cell_number,true);

   //print_r($st_cell_number) ;
   include "config.php";
   $sql = '';
   $to_day= date("Y-m-d");
   $id_cell='';
   if($add_absent==1){

    for($i=0;$i<count($st_id);$i++){
      $stu_id=$st_id[$i];
      $st_cell=$st_cell_number[$i];
      $id_cell.="'".$stu_id."'"."-".$st_cell."\r\n"; 
    
      $query="UPDATE 
      student_list_ju SET absent_per_month=IFNULL(absent_per_month, 0) + 1  WHERE  st_id='$stu_id'"
      ;
      $result=mysqli_query($link,$query);
      $sql .= "INSERT INTO absent_list (st_id,abs_date) 
      VALUES(
          '$stu_id',
          '$to_day'
             ); ";
    
    }
    $id_cell="Id-Mobile Number \r\n".$id_cell;
    
    
     if($sql != ''){
      mysqli_multi_query($link, $sql);
     }
    


   }else{

    for($i=0;$i<count($st_id);$i++){
      $stu_id=$st_id[$i];
      $st_cell=$st_cell_number[$i];
      $id_cell.="'".$stu_id."'"."-".$st_cell."\r\n"; 
  
    }
    $id_cell="Id-Mobile Number \r\n".$id_cell;
   }
  





$to=$checkbox ;

	$smstxt=$_POST['smstext'];
	

// আমরা $to তে সব নাম্বার কমা সেপারেট করা অবস্থায় পেয়েছি এবার এসএমএস প্রেরন করুন
$token = "d28c64966d30bb80787a063d678a85bc";//bpatcsc
//$token = "598f22ad0144f07eb1f000cc76af2dd8";
$message = "$smstxt";
//http://api.greenweb.com.bd/api.php
$url = "http://api.greenweb.com.bd/api.php";//bpatcsc
//$url = "http://api.smscpanel.net/api.php?";

$data= array(
'to'=>"$to",
'message'=>"$message",
'token'=>"$token"
); // Add parameters in key value
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$smsresult = curl_exec($ch);

//echo $smsresult;
//echo curl_error($ch);


//স্যাম্পল কোর্ডে নিচের অংশ আছে:
//$smsresult = curl_exec($ch);

//অর্থাৎ Curl এক্সিকিউশনের পর $smsresult স্ট্রিং পেয়েছেন । এবার এটাকে array তে কনভার্ট  করবো :

$smsresultarray = preg_split('/\r\n|\r|\n/', $smsresult);

//এবার array কে ল্যুপে নিবো

foreach($smsresultarray as $result) {
  $status = mb_substr($result, 0, 2);

  if ($status == 'Ok') {
	  //sms successfully sent do whatever you want
	  //echo $result;
    echo $id_cell;
  } else {
	//failed to sent do whatever you want
	echo $result;
  }
}


//Result
/*echo '<div class="txt-msg">';
//echo $smsresult;
//Error Display
echo curl_error($ch);
echo '</div>';*/

// echo "<script>";
// echo 'var x = ' . json_encode($smsresult) . ';';   
// //echo 'alert(x);';
//   echo "document.getElementById('show').innerHTML = x;";
// echo "</script>";



/* $number = $linkzoom;

    echo '<script>';
    echo 'var x = ' . json_encode($number) . ';';
    //echo 'alert(x);';
		echo 'window.location= x;';
    echo '</script>';*/

?>