<?php
session_start();
include 'dbc.php';

$userid=$_SESSION["userid"];

date_default_timezone_set("Asia/Karachi");
$ttime=date("h:i:sa");
$std_rollno=$_POST["std_rollno"];
$barcode=$_POST["barcode"];
$today=$_POST["today"];
$status=$_POST["status"];
$mnth=date("m");

$month_num =$mnth; 
  $month_name = date("F", mktime(0, 0, 0, $month_num, 10)); 
$yr=date("Y");
$my=$month_name . $yr;
$a=0;
$sql1 = "select * from atten where camp='$barcode' and date='$today' and user_id='$userid'";
$admission1=mysql_query($sql1) or die("Error : " . mysql_error());
    while($ppp1=mysql_fetch_array($admission1))
	 
{

$a=$a + 1;
}

if ($a >=1)
{
header("location:attendance_form.php");
	
	}
	
else
{



$sql = "select * from admission where barcode='$barcode' and user_id='$userid'";
$std_ledger=mysql_query($sql) or die("Error : " . mysql_error());
     $ppp=mysql_fetch_array($std_ledger);

$rollno=$ppp["std_rollno"];
$stdname=$ppp["std_name"];
$fname=$ppp["father_name"];
$class_name=$ppp["class_name"];
$cell_1=$ppp["cell_1"];

if ($barcode =="")
{
header("location:attendance_form.php");
	
	}
	
else
{
$sql3 = "Insert into atten (id,date,class_name,std_rollno,std_name,father_name,cell_1,pass_mark,total_mark,obt_mark,user_id,status,sess1,camp,ttime) values (null,'$today','$class_name','$rollno','$stdname','$fname','$cell_1','$month_name','$yr','P','$userid','In','$my','$barcode','$ttime')";
mysql_query($sql3) or die("Error : " . mysql_error());
}
$type = "xml"; 
$id = "rchhrdgphs"; 
$pass = "hajiroshandin786"; 
$lang = "English"; 
$mask = "HRDG-School";
// Data for text message 
$to = $cell_1; 
$message =  "Student Name:" . $sdtname . ": Rollno:" . $rollno . ":Class:" . $class_name .  ":Reported in School at::" . $ttime . ":" . $today;
$remarks =  "Student Name:" . $sdtname . ": Rollno:" . $rollno . ":Class:" . $class_name .  ":Reported in School at::" . $ttime . ":" . $today; 
$message = urlencode($message);   
// Prepare data for POST request 
$data = "id=".$id."&pass=".$pass."&msg=".$message."&to=".$to."&lang=".$lang."&mask=".$mask."&type=".$type;   
// Send the POST request with cURL 
$ch = curl_init('http://www.outreach.pk/api/sendsms.php/sendsms/url'); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); 
//This is the result from Outreach 

curl_close($ch); 
	
$sql4 = "Insert into smstbl (id,date,stdname,disc) values (null,'$today','$sdtname','$remarks')";
mysql_query($sql4) or die("Error : " . mysql_error());
	
	
header("location:attendance_form.php");
}
?>
