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

	function deleteAllEducation(){
		$this->mysqlConnect();
		if($_SESSION['sap_u_741'] == ""){
			return;
		}
		$user_id = $_SESSION['sap_u_741'];
		$queryDetails = "delete from tbl_sapexperience_details where user_id='".mysql_escape_string($user_id)."'";
		$this->mysqlQuery($queryDetails);
	}

	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_sapexperience_details where id='".mysql_real_escape_string($info[$cource_id])."'";
					$result = $this->mysqlFetchRow($query);
					$count = $result[0];
				}
				if(!$count){
			
					$projectname = 'projectname_'.$value;
					$projectnature = 'projectnature_'.$value;
					$projectnatureother = 'projectnatureother_'.$value;
					$client = 'client_'.$value;
					$duration_from = 'durationfrom_'.$value;
					$duration_to = 'durationto_'.$value;
					//$modules = 'modules_'.$value;
					$solution = 'sel1_'.$value;
					$modules = 'sel2_'.$value;
					$roles = 'roles_'.$value;
					$projectversion = 'projectversion_'.$value;
					$versionexperience = 'versionexperience_'.$value;
					$employer_id = 'employer_'.$value;
					$versionexperience_months = 'versionexperience_months_'.$value;
					
					$project_nature = isset($info[$projectnatureother]) ? $info[$projectnatureother] : $info[$projectnature];
					
					$queryDetails = sprintf("insert into tbl_sapexperience_details(user_id,project_name,project_nature,client,duration_from,duration_to,sap_solution,sap_modules,roles, 	project_version,version_experience,employer_id,version_months) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",mysql_escape_string($user_id),mysql_escape_string($info[$projectname]),mysql_escape_string($project_nature),mysql_escape_string($info[$client]),mysql_escape_string($info[$duration_from]),mysql_escape_string($info[$duration_to]),mysql_escape_string($info[$solution]),mysql_escape_string($info[$modules]),mysql_escape_string($info[$roles]),mysql_escape_string($info[$projectversion]),mysql_escape_string($info[$versionexperience]),mysql_escape_string($info[$employer_id]),'0');
					//echo $queryDetails;exit;
					$this->mysqlQuery($queryDetails);
				}
			
			}
		}	
			//$this->fileup_resume($info);  //not working properly we can enable later
			
		//}
	}
	
	function getDetails($uid){
		$this->mysqlConnect();

		$query = "select * from tbl_sapexperience_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;

	}
	
	function getEmployerDetails($uid){
		$this->mysqlConnect();

		$query = "SELECT count(distinct `employer_id`) as emp_count FROM tbl_sapexperience_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;

	}
	
}
?>