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

	function addDetails($info){
		$this->mysqlConnect();
		if($_SESSION['sap_u_741'] == ""){
			return;
		}
		$user_id = $_SESSION['sap_u_741'];
		$query = "select count(*) from tbl_personal_details where user_id='".mysql_real_escape_string($user_id)."'";
		$result = $this->mysqlFetchRow($query);
		$count = $result[0];
		if(!$count){
		
			$resume_file_name = $this->fileup_resume($info);
			
			if($info['qualification'] == "Others"){
				$qualification = $info['qualiOthers'];
			} else {
				$qualification = $info['qualification'];
			}
			
			$queryDetails = sprintf("insert into tbl_personal_details(user_id,title,first_name,last_name,official_email,mobile,personal_email,date_of_birth,city,resume_file,qualification,organisation_1) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",mysql_escape_string($user_id),mysql_escape_string($info['title']),mysql_escape_string($info['first_name']),mysql_escape_string($info['last_name']),mysql_escape_string($info['official_email']),mysql_escape_string($info['mobile']),mysql_escape_string($info['personal_email']),mysql_escape_string($info['date1']),mysql_escape_string($info['city']),mysql_escape_string($resume_file_name),mysql_escape_string($qualification),mysql_escape_string($info['organisation_1']));
			$this->mysqlQuery($queryDetails);
			
			 //not working properly we can enable later
			
		}
	}
	
	function updateDetails($info){
		$this->mysqlConnect();
		if($_SESSION['sap_u_741'] == ""){
			return;
		}
		$user_id = $_SESSION['sap_u_741'];
		
		if(isset($_FILES) && $_FILES["resume_file"]["name"] !=""){
			$resume_file_name = $this->fileup_resume($info); 
		} else {
			$resume_file_name = $info['resume_file_hdn'];
		}
		
		if($info['qualification'] == "Others"){
				$qualification = $info['qualiOthers'];
			} else {
				$qualification = $info['qualification'];
			}
		
		$queryDetails = "update tbl_personal_details SET title='".mysql_real_escape_string($info['title'])."',  first_name='".mysql_real_escape_string($info['first_name'])."', last_name ='".mysql_real_escape_string($info['last_name'])."', official_email ='".mysql_real_escape_string($info['official_email'])."', mobile ='".mysql_real_escape_string($info['mobile'])."', personal_email='".mysql_real_escape_string($info['personal_email'])."', date_of_birth ='".mysql_real_escape_string($info['date1'])."', city ='".mysql_real_escape_string($info['city'])."', resume_file='".mysql_real_escape_string($resume_file_name)."', qualification='".mysql_real_escape_string($qualification)."', organisation_1='".mysql_real_escape_string($info['organisation_1'])."' where id=".mysql_real_escape_string($info['pd']);
		
		$this->mysqlQuery($queryDetails);
		//exit;
	}
	
	function getDetails($uid){
		$this->mysqlConnect();

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

		return $this->mysqlArray($query);
	}
	
	function fileup_resume($info){
		$target_path_home = "";
		$target_path = "resumes/";
		$filename = $_FILES["resume_file"]["name"];
		$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
		$file_ext = substr($filename, strripos($filename, '.')); // strip name		
		
		if(($file_ext == ".doc" || $file_ext == ".docx" || $file_ext == ".pdf")) //can't be larger than 1 MB
		{			
		
			$random_digit=rand(0000,9999);
			
			//$new_file_name = $random_digit."_". strtolower($_FILES['resume_file']['tmp_name']);
			
			$target_path_home = md5($file_basename) . $file_ext;
			//$target_path_home = $target_path . basename( $_FILES['resume_file']['name']); 

			if(move_uploaded_file($_FILES['resume_file']['tmp_name'], "resumes/".$target_path_home)) {
				//return $target_path_home;
			} else{
				//return "";
			}
		}
		
		return $target_path_home;
	}
	
	function validate($info){
					
		if($info['txttitle']=='' || ctype_cntrl($info['txttitle']) || ctype_punct($info['txttitle']) || ctype_space($info['txttitle'])){
			$array[] = "Please Enter Album Name";
		} 
		
		if($info['txtdesc']=='' || ctype_cntrl($info['txtdesc']) || ctype_punct($info['txtdesc']) || ctype_space($info['txtdesc'])){
			$array[] = "Please Enter Album Description";
		}
		
		return $array;
	}
}
?>