<?php
require_once("lib/mainClass.php");
class educationDetails extends  mainClass {

	function addDetails($info){
		$this->mysqlConnect();
		if($_SESSION['sap_u_741'] == ""){
			return;
		}
		$user_id = $_SESSION['sap_u_741'];
		//$query = "select count(*) from tbl_education_details where user_id='".mysql_real_escape_string($user_id)."'";
		//$result = $this->mysqlFetchRow($query);
		//$count = $result[0];
		//if(!$count){
		if($info['cource_count'] <= 10){ //maximum 10 cources can be added
			for ($value=1; $value <= $info['cource_count'];$value++){
				$count = 0;
				$cource_id = 'courceid_'.$value;
				if(isset($info[$cource_id])){
					$query = "select count(*) from tbl_education_details where id='".mysql_real_escape_string($info[$cource_id])."'";
					$result = $this->mysqlFetchRow($query);
					$count = $result[0];
				}
				if(!$count){
			
					$cource_name = 'courcename_'.$value;
					$university_name = 'universityname_'.$value;
					$duration_from = 'durationfrom_'.$value;
					$duration_to = 'durationto_'.$value;
					$university_location = 'universitylocation_'.$value;
					$university_city = 'universitycity_'.$value;
					
					$queryDetails = sprintf("insert into tbl_education_details(user_id,cource_name,university_name,duration_from,duration_to,university_location,university_city) values ('%s','%s','%s','%s','%s','%s','%s')",mysql_escape_string($user_id),mysql_escape_string($info[$cource_name]),mysql_escape_string($info[$university_name]),mysql_escape_string($info[$duration_from]),mysql_escape_string($info[$duration_to]),mysql_escape_string($info[$university_location]),mysql_escape_string($info[$university_city]));
					$this->mysqlQuery($queryDetails);
				}
			
			}
		}	
			//$this->fileup_resume($info);  //not working properly we can enable later
			
		//}
	}
	
	function deleteAllEducation(){
		$this->mysqlConnect();
		if($_SESSION['sap_u_741'] == ""){
			return;
		}
		$user_id = $_SESSION['sap_u_741'];
		$queryDetails = "delete from tbl_education_details where user_id='".mysql_escape_string($user_id)."'";
		$this->mysqlQuery($queryDetails);
	}
	
	function getDetails($uid){
		$this->mysqlConnect();

		$query = "select * from tbl_education_details where user_id='".mysql_real_escape_string($uid)."'";	

		//return $this->mysqlAssoc($query);
		$result = $this->mysqlQuery($query);

		$records = array();
		
		while ($row = mysql_fetch_assoc($result)) {
			$records[] = $row;
		}
		return $records;

	}
	
}
?>