<?php
class database{
	private $con;
	private $lq;
	public function __construct(){
	//$this->do_connect();
	}	
	private function do_connect(){
		$this->con=mysql_connect(SERVER,USER,PASS);
		if($this->con){
			$db=mysql_select_db(DB);
		}else{
			return false;
		}
	}
	public function close_db(){
		mysql_close($this->con);	
	}
	public function query($sql){
		$this->lq=$sql;
		if($result= mysql_query($sql)){
		return $result;
		}else{
		echo "ERROR LAST QUERY WAS: <em style='color:red;'>".$this->lq."</em><br />";
		echo "<center><div style='border:1px solid black; height:40px; padding:10px; margin-top:15px; width:800px; color:white; background-color:black;'>".mysql_error()."</div></center>";
		return false;
		}
	}
	public function fetch($result,$multi=false){
		if($multi==true){
		return mysql_fetch_object($result);
		}else{
		return mysql_fetch_array($result);
		}
	}
	public function num_rows($result){
		return mysql_num_rows($result);	
	}
	public function insert_id(){	
		return mysql_insert_id();
	}
	public function escape($value){
		return mysql_escape_string($value);
	}
	public function affect(){
		return mysql_affected_rows();	
	}
	public function selectSR($arr,$tbl,$cond=""){
		$ret_arr=array();		
			$sql="SELECT ".implode(",",$arr)." FROM ".$tbl." WHERE ".$cond;			
			$result=$this->query($sql);
			return $this->fetch($result);
		}
	public function select($arr,$tbl,$cond=""){
		$ret_arr=array();				
			$sql="SELECT ".implode(",",$arr)." FROM ".$tbl;
			if($cond !=""){
			$sql="SELECT ".implode(",",$arr)." FROM ".$tbl." WHERE ".$cond;
			}			
			$result=$this->query($sql);
			while($ob=$this->fetch($result,true)){
				$ret_arr[]=$ob;
				}
				return $ret_arr;			
		}
	public function insert($arr,$tbl){
		$SafeArr=array();
		foreach($arr as $v){
			$SafeArr[]=strip_tags($this->escape($v));
		}
		$sql="INSERT INTO ".$tbl." (".implode(",",array_keys($arr)).") values('".implode("','",array_values($SafeArr))."')";
		$result=$this->query($sql);
		return ($this->affect()==1)? true : false ;
		}
	public function delete($cond,$table){
		$sql="DELETE FROM ".$table." WHERE ".$cond;
		$result=$this->query($sql);
		return ($this->affect()>-1)? true : false ;
		}
	public function update($uparr,$tbl,$cond){
		$update=array();
		foreach($uparr as $k=>$v){
			$v=strip_tags($this->escape($v));
			$update[]="$k='$v'";
			}
		$sql="UPDATE ".$tbl." SET ".implode(", ",$update)." WHERE ".$cond;
//		echo $sql;
//		exit;
		$result=$this->query($sql);
		return true;
		}
	public function deleteAll($arr,$tbl){
		foreach($arr as $a){
			$this->delete("id=".$a,$tbl);
			return ($this->affect()>0)? true : false;
			}
		}
	public function file_upload($fileFieldName){
		
		$uploaded=0;
		$ext="";

		//generate unique file name using time:
		$newfilename= md5(rand() * time());
		
		//do we have a file?
		if((!empty($_FILES[$fileFieldName])) && ($_FILES[$fileFieldName]['error'] == 0))
		{
		   $filename =strtolower(basename($_FILES[$fileFieldName]['name']));
		
		   $ext = substr($filename, strrpos($filename, '.') + 1);
		
		   if ((($ext == "jpg")||($ext == "JPG")||($ext == "docx")||($ext == "doc")||($ext == "pdf")||($ext == "csv")||($ext == "xls")||($ext == "ppt")||($ext == "exe")||($ext == "gif")||($ext == "png")||($ext == "jpeg")||($ext == "mp3")||($ext == "wav")||($ext == "mpeg")||($ext == "mpg")) && ($_FILES[$fileFieldName]["size"] < 500000) || (($_FILES[$fileFieldName]["type"] == "image/jpeg")||($_FILES[$fileFieldName]["type"] == "image/pjpeg")))
		   {
		   //Determine the path to which we want to save this file
		   $extension = $ext;
		   $ext=".".$ext;
		   $file_upload	= $newfilename.$ext;
		   $newname = 'admin/uploads/'.$newfilename.$ext;
		
			   if ((move_uploaded_file($_FILES[$fileFieldName]['tmp_name'],$newname)))
			   {
				   //echo "File uploaded successfully!";
				   $uploaded=1;
				   return $newfilename.$ext;
			   }
			   else
			   {
					return false;
			   }
			 }
   		}
	}// end of func
	public function print_array($arr){
		echo "<pre>";
		print_r($arr);
		echo "</pre>";
		exit;
	}
	public function redirect($fileName,$msg=""){
		if($msg!=""){
		unset($_SESSION['msgg']);
		$_SESSION['msgg']=$msg;
		}
		?>
		<script type="text/javascript">
            window.location="<?php echo $fileName ?>";
        </script>
        <?php
		exit;
	}
	public function msg(){
		echo '<p>'.$_SESSION['msgg'].'</p>';
		unset($_SESSION['msgg']);
	}
	public	function Get_Gender($gender)
	{
		if($gender == 1)
		{
			return "Male";	
		}
	
		if($gender == 2)
		{
			return "FeMale";	
		}
	
		if($gender == 3)
		{
			return "Both";	
		}	
	}
	public	function Get_Job_Type($gender)
	{
		if($gender == 1)
		{
			return "Monthly";	
		}
	
		if($gender == 2)
		{
			return "Annual";	
		}
	}
	public	function Get_Education($gender)
	{
		if($gender == 8)
		{
			return "Less Than Higher School Graduate";	
		}
	
		if($gender == 10)
		{
			return "Higher School Graduate";	
		}
		if($gender == 12)
		{
			return "Associate Degree";	
		}
		if($gender == 14)
		{
			return "Bechalor's Degree";	
		}
		if($gender == 16)
		{
			return "Mastess Degree";	
		}
		if($gender == 18)
		{
			return "Doctoral Degree";	
		}
	}	
	public	function Get_Skill($gender)
	{
		if($gender == 1)
		{
			return "Beginner";	
		}
	
		if($gender == 2)
		{
			return "Intermediate";	
		}
		if($gender == 3)
		{
			return "Expert";	
		}
	}

	public function Get_Experence($year,$month)
	{
			$Experience_Dec	=	"";
			if($month == "0" && $row['Experece_Month'] == "0")
			{
				$Experience_Dec	=	"Fresh";	
			}
			if($row['experence'] == "0" && $row['Experece_Month'] != "0")
			{
				$Experience_Dec	=	$row['Experece_Month']." Months";
			}
			if($row['experence'] != "0" && $row['Experece_Month'] == "0")
			{
				$Experience_Dec	=	$row['experence']." Years";
			}
			if($row['experence'] != "0" && $row['Experece_Month'] != "0")
			{
				$Experience_Dec	=	$row['experence']." Years &nbsp;and ".$row['Experece_Month']." Months";
			}
			return $Experience_Dec;		
	}
}
$db= new database();
?>