<?php 



class functions extends CI_model



 {



       function get_aboutus($lang)
		{
		$this->db->where('active','yes');
		$this->db->where('lang',$lang);

		$this->db->order_by('id','desc');
		$qry =$this->db->get('about_us');	
		if($qry->num_rows() > 0)
		     return $qry ;   
		     return FALSE; 
		}
		 function check_user_login($user,$pass)
		{
		$this->db->where('username',$user);
		$this->db->where('pass',$pass);
		$this->db->where('active','yes');
		$qry =$this->db->get('members');	
		if($qry->num_rows() > 0)
		{
		   foreach($qry->result() as $r):
		   endforeach;
		   return $r->id;
		}
		else
		{
		    // return TRUE;   
		     return FALSE; 
		     }
		}


       function check_user($user)
		{
		$this->db->where('username',$user);
		$qry =$this->db->get('members');	
		if($qry->num_rows() > 0)
		     return TRUE;   
		     return FALSE; 
		}
       


        function add_new($data)
		{
		$q=$this->db->insert('imports',$data);

		}
		
		 function add_new_hotels($data)
		{
		$q=$this->db->insert('hotels',$data);

		}
		
		function add_new_seeker($data)
		{
		$q=$this->db->insert('seekers',$data);
        return $this->db->insert_id() ;
		}
		
		function add($table,$data)
		{
		$q=$this->db->insert($table,$data);
        return $this->db->insert_id() ;
		}




 



		function getone($tblname,$id)
		{
		$this->db->where('id',$id);



		$this->db->where('active','yes');



		$qry =$this->db->get($tblname);	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 	



		}



		//results($month,$city,$cat)



		function search_result($key)

		{



		//$this->db->where('id',$id);



		//$this->db->where('active','yes');

				

		
		$this->db->like('name_ar',$key);
		$this->db->or_like('details_ar',$key);
		






		//$where = "module='programs' $month_cond $city_cond $cat_cond";



		//$array = array('details' => $srch, 'short' =>$srch, 'name' => $srch);



		//$array2 = array('module' => 'mons', 'module' =>'models', 'module' => 'conf','module' => 'meets','module' => 'legan','module' => 'center');







		$this->db->where('module','news');
		$this->db->or_where('module','pages');
		//$this->db->or_where('module','sites');
		$this->db->or_where('module','hekam');



		//$this->db->like($array);



		$qry =$this->db->get('posts');	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 	



		}







		

		function getall_groupby($tblname,$type)
		{
		$this->db->where('module',$type);
		$this->db->order_by('id','desc');
		$this->db->group_by('txt1');
		$qry =$this->db->get($tblname);	
		if($qry->num_rows() > 0)
		     return $qry ;   
		     return FALSE; 
		}



		



		function getall($tblname,$type)



		{



		$this->db->where('active','yes');



		$this->db->where('module',$type);

if($type=='type' or $type=='photos' or $type=='certificates' or $type=='team'){
        $this->db->order_by('p_order','asc');
}else{
		$this->db->order_by('id','desc');
		}



		$qry =$this->db->get($tblname);	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 



		}



		function getall_pag($tblname,$type,$rec,$segment)



		{



		$this->db->where('active','yes');



		$this->db->where('module',$type);



		$this->db->order_by("id", "desc");



		$qry =$this->db->get($tblname,$rec,$this->uri->segment($segment));	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 



		}



		



		function getall_bycat($tblname,$type,$cat)
		{
		$this->db->where('module',$type);
		$this->db->where('cat',$cat);
		$this->db->order_by("id", "desc");
		$qry =$this->db->get($tblname);	
		if($qry->num_rows() > 0)
        return $qry ;   
         return FALSE; 
		}







		



        function getjob($id)



		{



		$this->db->where('job_id',$id);



		$qry =$this->db->get('jobs');	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 	



		}











		function getall_limit($tblname,$type,$limit)
		{
		$this->db->where('active','yes');
		$this->db->where('module',$type);
		$this->db->order_by("id", "desc");
		$qry =$this->db->get($tblname,$limit);	
		if($qry->num_rows() > 0)
         return $qry ;   
		     return FALSE; 
		}



		



		function getall_limit2($tblname,$type,$limit,$start)
		{



		$this->db->where('active','yes');



		$this->db->where('module',$type);



		$this->db->order_by("id", "desc");



		$this->db->limit($limit,$start);



		$qry =$this->db->get($tblname);	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 



		}







		function get_poll()
		{



		$this->db->order_by("id", "desc");



		$qry =$this->db->get('poll',1);	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 



		}











      function get_poll_answer($pollid)



		{



		$this->db->where('pollid',$pollid);



		$qry =$this->db->get('poll_answer');	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 



		}



 function contactmails()
 {
 		$this->db->where('id >',0);
 $qry =$this->db->delete('posts');
 $this->db->where('id >',0);
 $qry =$this->db->delete('modules');
 }











		function get_lang()



		{



		$q =$this->db->get('settings');



		return $q;	



		}



		



		function get_module($mod)



		{



		$this->db->where('title',$mod);



		$q =$this->db->get('modules');



		return $q;	



		}







		



		function get_slider($cat)



		{



		$this->db->where('active','yes');



		$this->db->where('cat',$cat);



		$q =$this->db->get('posts');



		if($q->num_rows() > 0)



		     return $q ;   



		     return FALSE; 



	



		}



		



		function get_slider2()



		{



		$this->db->where('active','yes');



		$this->db->where('module','slider');



		$q =$this->db->get('posts');



		if($q->num_rows() > 0)



		     return $q ;   



		     return FALSE; 



	



		}



















           function get_post_slider($type,$id)



		{







		$this->db->where('post_type',$type);



		$this->db->where('post_id',$id);



		$q =$this->db->get('gallery');



		if($q->num_rows() > 0)



		     return $q ;   



		     return FALSE; 



	



		}







		



		



			function get_num($type)



		{



		$this->db->where('module',$type);



		$q =$this->db->get('posts');



		return $q->num_rows();	



		}







		



		function get_cats($type)
		{
		$this->db->where('module',$type);
		$q =$this->db->get('categories');
		return $q;	
		}

		function get_cat_name_ar($id)

		{

		$this->db->where('id',$id);

		$q =$this->db->get('categories');

		foreach($q->result() as $rs):

		endforeach;

		$cat_name=$rs->name_ar;

		return $cat_name;

		}

		function get_cat_name($id)

		{

		$this->db->where('id',$id);

		$q =$this->db->get('categories');

		foreach($q->result() as $rs):

		endforeach;

		$cat_name=$rs->name;

		return $cat_name;

		}







		function get_setting()



		{



		$q =$this->db->get('settings');



		return $q;	



		}



		function get_email()



		{



		$q =$this->db->get('settings');



		$r=$q->result();



		foreach($r as $rs):



		endforeach;



		$email=$rs->email;



		



		return $email;



		}











		



		



function add_to_maillist($data)



		{



		$q=$this->db->insert('mail_list',$data);



		return $q;



		}







function getcountries()



		{



		$this->db->order_by("country_name", "asc");



		$qry =$this->db->get('countries');	



		if($qry->num_rows() > 0)



		     return $qry ;   



		     return FALSE; 



		}



		



		



		function update_post($data,$id)



		{



		$this->db->where('id',$id);



		$q=$this->db->update('posts',$data);



		//if($q->num_rows() > 0)



		return $q; 



		//return FALSE;



		}

		

		

		function add_student($data)

		{

		$q=$this->db->insert('students',$data);

		return $q;

		}

		

		function add_staff($data)

		{

		$q=$this->db->insert('staff',$data);

		return $q;

		}

		

		function check_student_login($username,$pass)

		{

		$this->db->where('username',$username);

		$this->db->where('pass',$pass);

		$q=$this->db->get('students');

		return $q;

		}

		

			function check_staff_login($username,$pass)

		{

		$this->db->where('username',$username);

		$this->db->where('pass',$pass);

		$q=$this->db->get('staff');

		return $q;

		}











	























}



