<?php
	require "../commonincludefiles.php";
	require "sendingsms_studentpresant.php";
   	//$objStudent = new StudentMgmt();
	$gtuno = trim(Escape($_POST['gturegno']));
	$birthdate = DateConversion(Escape($_POST['birthdate']),"Y-m-d","Y-m-d");
	$student_mobile = Escape($_POST['student_mobile']);
	
	//$rs = $objStudent->getGturegnoRecord($gtuno);
	$qry = "select 
				sm.student_id,
				sd.cur_branchid,
				sd.cur_semesterid,
				sd.year_id,
				sd.cur_branchyearid,
				CONCAT(sm.student_surname , ' ' , sm.student_firstname , ' ' ,sm.student_lastname) AS studentname
				from 
					cms_studentmaster sm,
					cms_studentdetail sd
				where
				sm.college_id  = 1
				AND sm.student_id=sd.student_id
				AND sm.student_active=1	
				AND sd.year_id =  (select max(year_id) from cms_studentdetail t1,cms_studentmaster t2 where t1.student_id = t2.student_id
				                    and t2.student_gturegno = '$gtuno')
				AND sm.student_gturegno='$gtuno'
				AND sm.student_birthdate = '$birthdate'		";			
				
    $rs = dbQuery($qry);
	$flag="";
	if(dbRows($rs) > 0)
	{
		$row = dbArray($rs);
		//$qry1 = " select * from feedback_que_result where student_id = ".trim($row["student_id"])." ";
		//$rs1 = dbQuery($qry1);
		
		/*if(dbRows($rs1) > 0)
		  {
			  echo'{"success":"false","msg":"Sorry! you have already given feedback. !"}'; 
		  }
		else
		 {  
		 */
	$qry2 = "select branch_name from cms_branchmaster where  branch_id = ".trim($row["cur_branchid"])." ";	
	$rs2 = dbQuery($qry2);
	extract(dbArray($rs2));
	$qry3 = "select semester_name from cms_semestermaster where  semester_id = ".trim($row["cur_semesterid"])." ";	
	$rs3 = dbQuery($qry3);
	extract(dbArray($rs3));
	$qry4 = "select year_name from cms_yearmaster where  year_id = ".trim($row["year_id"])." ";	
	$rs4 = dbQuery($qry4);
	extract(dbArray($rs4));
	$qry3 = "select branchyear_name from cms_branchyear where  branchyear_id = ".trim($row["cur_branchyearid"])." ";	
	$rs3 = dbQuery($qry3);
	extract(dbArray($rs3));
// set require session------------------------------------------------------		 
		$_SESSION['f_student_id']  = trim($row["student_id"]);		
		$_SESSION['f_studentname'] = trim($row["studentname"]);
		$_SESSION['f_cur_branchid'] = trim($row["cur_branchid"]);
		$_SESSION['f_cur_semesterid'] = trim($row["cur_semesterid"]);
		$_SESSION['f_year_id'] = trim($row["year_id"]);
		$_SESSION['f_cur_branchyearid'] = trim($row["cur_branchyearid"]);
		$_SESSION['f_student_mobile'] = trim($student_mobile);
		$_SESSION['f_branch_name'] = trim($branch_name);
		$_SESSION['f_year_name'] = trim($year_name);
		$_SESSION['f_branchyear_name'] = trim($branchyear_name);
		$_SESSION['f_semester_name'] = trim($semester_name);
		$_SESSION['f_code'] = trim(str_rand('5','numeric'));
		$_SESSION["VedantnrCollegeId"] = '1';
		
		//$cur_divison = $row["cur_divison"];
		sendCode(trim($student_mobile),$_SESSION['f_code'],$_SESSION['f_studentname']);
		echo'{"success":"true"}'; 
		/* }*/
	}
	else 
	  {
		echo'{"success":"false","msg":"Sorry! you have entered wrong information kindly enter valid information. !"}'; 
	  }
	

function str_rand($length = 8, $seeds = 'alphanum')
	{
    // Possible seeds
    $seedings['alpha'] = 'abcdefghijklmnopqrstuvwqyz';
    $seedings['numeric'] = '0123456789';
    $seedings['alphanum'] = 'abcdefghijklmnopqrstuvwqyz0123456789';
    $seedings['hexidec'] = '0123456789abcdef';
    
    // Choose seed
    if (isset($seedings[$seeds]))
    {
        $seeds = $seedings[$seeds];
    }
    
    // Seed generator
    list($usec, $sec) = explode(' ', microtime());
    $seed = (float) $sec + ((float) $usec * 100000);
    mt_srand($seed);
    
    // Generate
    $str = '';
    $seeds_count = strlen($seeds);
    
    for ($i = 0; $length > $i; $i++)
    {
        $str .= $seeds{mt_rand(0, $seeds_count - 1)};
    }
    
    return $str;
	}
function sendCode($mobile_number,$f_code)
{
	    //$mobile_number = $student_mobile; 	
		$msg_body = trim("Your secure password for giving online feedback is : ".$f_code.""); 
		$msg_prefix = "Dear Parents, "; 
		$msg_suffix = " From Image ETI."; 
		
		if($msg_prefix != ""){
			$msg_body = $msg_prefix.$msg_body;
		}
		if($msg_suffix != ""){
			$msg_body = $msg_body.$msg_suffix;
		}
$objSiteConfigMgmt = new SiteConfigMgmt();
$SmsUserName 		= $objSiteConfigMgmt->getSiteConfigValue('smsusername');
$SmsPassword 		= $objSiteConfigMgmt->getSiteConfigValue('smspassword');
$SmsSendapi 		= $objSiteConfigMgmt->getSiteConfigValue('smssendapi');		

//$response = sendSms($SmsUserName,$SmsPassword,$SmsSendapi,$mobile_number,$msg_body);

/*	$status=split(" | ",$response);
					if(trim($status[0]) == "success")
						{
							echo'{"success":"true","msg":"'.$status[0].'"}'; 
						}
					else
					  		echo'{"success":"false","msg":"'.$status[0].'"}';*/
	
			
}

?>