<?php
require "commonincludefiles.php";

    $student_gturegno				 = Escape($_POST['student_gturegno']); 
	$password				= Escape($_POST['password']);

	$_SESSION['c_pass']  = $password;
	$_SESSION['c_student_gturegno']  = $student_gturegno;

	//$student_birthdate				= Escape($_POST['student_birthdate']);
	//$_SESSION['c_student_birthdate'] = $student_birthdate;
	


if ($_SESSION['c_student_gturegno'] && $_SESSION['c_pass']){

   $sql="select CONCAT(sm.student_surname , ' ' , sm.student_firstname , ' ' ,sm.student_lastname) AS studentname, sm.student_surname,sm.student_firstname,sm.student_lastname,sm.student_gender,sd.*,cc.*,um.* 
   from cms_studentmaster sm left join cms_studentdetail sd on sm.student_id=sd.student_id 
   left join cms_collegemaster cc on cc.college_id=sm.college_id  
   left join cms_usermaster um on um.student_id=sm.student_id  
   where user_name='{$_SESSION['c_student_gturegno']}' AND  user_password='{$_SESSION['c_pass']}' and student_active = 1 order by  sd.year_id DESC ";	
  
//  echo $sql; exit;
  $out=dbQuery($sql);
    	
	if (dbRows($out)>0){
        $admins		= dbObject($out);	 	 	 	 	 	 
		$qry2 = "select branch_name from cms_branchmaster where  branch_id = ".trim($admins->cur_branchid)." ";	
		$rs2 = dbQuery($qry2);
		extract(dbArray($rs2));
		$qry3 = "select semester_name from cms_semestermaster where  semester_id = ".trim($admins->cur_semesterid)." ";	
		$rs3 = dbQuery($qry3);
		extract(dbArray($rs3));
		
		$qry4 = "select year_name from cms_yearmaster where  year_id = ".trim($admins->year_id)." ";	
		$rs4 = dbQuery($qry4);
		extract(dbArray($rs4));
		
        $_SESSION['_err']				= 'pass_ok';
		$_SESSION['student_id']         = $admins->student_id;
		$_SESSION['student_surname']    = $admins->student_surname;
		$_SESSION['student_firstname']  = $admins->student_firstname;
		$_SESSION['student_lastname']   = $admins->student_lastname;
		$_SESSION['student_gender']     = $admins->student_gender;
		$_SESSION['cur_branchid']       = $admins->cur_branchid;
		$_SESSION['batch_id']           = $admins->batch_id;
		$_SESSION['cur_semesterid']     = $admins->cur_semesterid;
		$_SESSION['cur_divison']        = $admins->cur_divison;
		$_SESSION['current_active']     = $admins->current_active;
		$_SESSION['year_id']            = $admins->year_id;
		$_SESSION["aCollegeId"]			= $admins->college_id;       
		$_SESSION["aCollegeLogo"]		= ($admins->college_logo!="") ? $admins->college_logo : "default.gif";       
		$_SESSION["aCollegeName"]		= $admins->college_name;       
		$_SESSION["aCollegeAddress"]	= $admins->college_address;       
		$_SESSION["aCollegePhone"]		= $admins->college_phone;       				
		$_SESSION["aCollegeEmail"]		= $admins->college_email; 	
		$_SESSION["aCollegeUrl"]		= $admins->college_url;
		$_SESSION['f_student_id']  = trim($admins->student_id);		
		$_SESSION['f_studentname'] = trim($admins->studentname);
		$_SESSION['f_cur_branchid'] = trim($admins->cur_branchid);
		$_SESSION['f_cur_semesterid'] = trim($admins->cur_semesterid);
		$_SESSION['f_branch_name'] = trim($branch_name);
		$_SESSION['f_semester_name'] = trim($semester_name);
		$_SESSION['f_year_name'] = trim($year_name);
        $redfile = "loginhome.php";
	
    } else {
        $_SESSION['_err']='pass_bad';
        unset($root);
        $redfile = "index.php?verr=Invalid";
    }
} else {
    unset($root);
    $redfile = "index.php?verr=Invalid";
}	

?>
<script language="javascript">
    location.href= '<?php echo $redfile;?>';
</script>