<?php
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');
session_start();
$iduser=$_SESSION['user_idd'];
$nam=$_SESSION['name'];
include('../include/config.php');

if(isset($_POST['tel']))
{
$claz=addslashes($_POST['claz']);
$eid=$_POST['eid'];

$tit='';
$query=mysqli_query($con,"select * from Exam where id='$eid'");
while($row=mysqli_fetch_array($query))
{
  $tit=$row["Title"].'-'.$row["Year"].' Exam';
}

if($claz=='GRADE 1' || $claz=='GRADE 2' || $claz=='GRADE 3')
{
$tel=addslashes($_POST['tel']);
$nam=addslashes($_POST['nam']);
$sid=addslashes($_POST['pid']);
$mat=addslashes($_POST['mat']);
$kis=addslashes($_POST['kis']);
$eng=addslashes($_POST['eng']);
$cre=addslashes($_POST['cre']);
$cra=addslashes($_POST['cra']);
$env=addslashes($_POST['env']);
$tot=addslashes($_POST['tot']);


$msg="Dear Parent your child ".$nam." attained the following in ".$tit." -> Math:".$mat.", Kis: ".$kis.", Eng: ".$eng.", CRE: ".$cre.", CrA:".$cra.", Env Act: ".$env.", Total: ".$tot."\n For enquiry contact: 0728 966 221. Thank You";
$baseurl = "https://sms.textsms.co.ke/api/services/sendsms/";
$ch = curl_init($baseurl);
$data= array(
"apikey"=>"dd831d08b4bef652dbb8dbafabdab40b",
"response_type"=> "json",
"partnerID"=>"11288",
"message"=>$msg,
"shortcode"=>"BISHOPKAIRO",
"service_id"=>0,
"mobile"=>$tel,
);

$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-Type: application/json','h_api_key:dd831d08b4bef652dbb8dbafabdab40b'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_encode(curl_exec($ch));

$sql=mysqli_query($con,"INSERT INTO exammessages(pid,Phone,Msg,Dat,User,UserName) VALUES('$sid','$tel','$msg','$timenow','$iduser','$nam')");
if($sql)
{
echo 'success';  
echo $result;
curl_close($ch);
}

}else if($claz=='GRADE 4' || $claz=='GRADE 5' || $claz=='GRADE 6')
{
$tel=addslashes($_POST['tel']);
$nam=addslashes($_POST['nam']);
$sid=addslashes($_POST['pid']);
$mat=addslashes($_POST['mat']);
$kis=addslashes($_POST['kis']);
$eng=addslashes($_POST['eng']);
$cre=addslashes($_POST['cre']);
$cra=addslashes($_POST['cra']);
$ss=addslashes($_POST['ss']);
$st=addslashes($_POST['IS']);
$an=addslashes($_POST['an']);
$tot=addslashes($_POST['tot']);

$msg="Dear Parent your child ".$nam." attained the following in ".$tit." -> Math:".$mat.", Kis: ".$kis.", Eng: ".$eng.", CRE: ".$cre.", CrA:".$cra.", SS: ".$ss.", IS: ".$st.", Agri: ".$an.", Total: ".$tot."\n For enquiry contact: 0728 966 221. Thank You";
$baseurl = "https://sms.textsms.co.ke/api/services/sendsms/";
$ch = curl_init($baseurl);
$data= array(
"apikey"=>"dd831d08b4bef652dbb8dbafabdab40b",
"response_type"=> "json",
"partnerID"=>"11288",
"message"=>$msg,
"shortcode"=>"BISHOPKAIRO",
"service_id"=>0,
"mobile"=>$tel,
);

$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-Type: application/json','h_api_key:dd831d08b4bef652dbb8dbafabdab40b'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_encode(curl_exec($ch));

$sql=mysqli_query($con,"INSERT INTO exammessages(pid,Phone,Msg,Dat,User,UserName) VALUES('$sid','$tel','$msg','$timenow','$iduser','$nam')");
if($sql)
{
echo 'success';  
echo $result;
curl_close($ch);
}   
}else if($claz=='GRADE 7' || $claz=='GRADE 8' || $claz=='GRADE 9')
{
$tel=addslashes($_POST['tel']);
$nam=addslashes($_POST['nam']);
$sid=addslashes($_POST['pid']);
$mat=addslashes($_POST['mat']);
$kis=addslashes($_POST['kis']);
$eng=addslashes($_POST['eng']);
$cre=addslashes($_POST['cre']);
$cra=addslashes($_POST['cra']);
$ss=addslashes($_POST['ss']);
$st=addslashes($_POST['st']);
$an=addslashes($_POST['an']);
$pt=addslashes($_POST['pt']);
$tot=addslashes($_POST['tot']);

$msg="Dear Parent your child ".$nam." attained the following in ".$tit." -> Math:".$mat.", Kis: ".$kis.", Eng: ".$eng.", CRE: ".$cre.", CrA:".$cra.", SS: ".$ss.", ST: ".$st.", Agri: ".$an.", Pre-T: ".$pt.", Total: ".$tot."\n For enquiry contact: 0728 966 221. Thank You";
$baseurl = "https://sms.textsms.co.ke/api/services/sendsms/";
$ch = curl_init($baseurl);
$data= array(
"apikey"=>"dd831d08b4bef652dbb8dbafabdab40b",
"response_type"=> "json",
"partnerID"=>"11288",
"message"=>$msg,
"shortcode"=>"BISHOPKAIRO",
"service_id"=>0,
"mobile"=>$tel,
);

$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-Type: application/json','h_api_key:dd831d08b4bef652dbb8dbafabdab40b'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_encode(curl_exec($ch));

$sql=mysqli_query($con,"INSERT INTO exammessages(pid,Phone,Msg,Dat,User,UserName) VALUES('$sid','$tel','$msg','$timenow','$iduser','$nam')");
if($sql)
{
echo 'success';  
echo $result;
curl_close($ch);
} 
}
}
?>
