<?php 
class home extends CI_Controller {
function home()	 
{  
parent::__construct();	
$this->load->library('session');
$this->load->Model('functions', 'fun');  //function in model 
$this->load->library('pagination');
$this->load->library('form_validation');
} 







	public function index($lang='',$result='')

	{   
	$data['result']=$result;     
	    if($lang=='ar')
	   {
	   $this->session->set_userdata('lang','ar');
	   }
	   if($lang=='en')
	   {
	   $this->session->set_userdata('lang','en');
	   }
 
	
	    if($this->session->userdata('lang')=='ar')
	    {

                $this->load->view('header_ar');
				$this->load->view('home_ar');
				$this->load->view('footer_ar');
	   }else
	   {
	           

                $this->load->view('header');
				$this->load->view('home',$data);
				$this->load->view('footer');
	   }
	

	}
	
	
	public function services($lang='')

	{         
	    if($lang=='ar')
	   {
	   $this->session->set_userdata('lang','ar');
	   }
	   if($lang=='en')
	   {
	   $this->session->set_userdata('lang','en');
	   }
 
	
	    if($this->session->userdata('lang')=='ar')
	    {
 $this->load->view('header_ar');
				$this->load->view('services_ar');
				$this->load->view('footer_ar');
               
	   }else
	   {
	           
 $this->load->view('header');
				$this->load->view('services');
				$this->load->view('footer');

	   }
	

	}


	public function download($id)

	{

	   $dt=array();

	   $menu_q= $this->fun->getone('posts',$id);

	   $dt=$menu_q;

	   foreach($dt->result() as $rr):

	   $file=$rr->up1;

	   endforeach;

		$ex=explode('.',$file);

		$ext=$ex[1];

		header('Content-disposition: attachment; filename='.$file);

		header('Content-type: application/'.$ext);

		readfile('./uploads/models/'.$file);

	}

	public function download2()

	{

	   $dt=array();

	   $menu_q= $this->fun->get_setting();;

	   $dt=$menu_q;

	   foreach($dt->result() as $rr):

	   $file=$rr->profile;

	   endforeach;

		$ex=explode('.',$file);

		$ext=$ex[1];

		header('Content-disposition: attachment; filename=Programs_agenda');

		header('Content-type: application/'.$ext);

		readfile('./uploads/'.$file);

	}





	
		public function team()

	{

	            $this->load->view('header');

				$this->load->view('team');

				$this->load->view('footer');

	

	}

		public function search_result()

	{
	$key=$this->input->post('key');
	$q=$this->fun->search_result($key);
	 $hd['posts']=$q;

	            $this->load->view('header_ar');

				$this->load->view('search_result_ar',$hd);

				$this->load->view('footer_ar');

	

	}



public function details($id)
	{
	 $hd['id']=$id;
	 

 
	
	    if($this->session->userdata('lang')=='ar')
	    {
            $this->load->view('header_ar');

				$this->load->view('details_ar',$hd);

				$this->load->view('footer_ar');               
	   }else
	   {
	           
             $this->load->view('header');

				$this->load->view('details',$hd);

				$this->load->view('footer');
	   }



	         

	

	}


	public function areas()
	{
	            $this->load->view('header_ar');

				$this->load->view('areas_ar');

				$this->load->view('footer_ar');

	

	}
	
	public function comons()
	{
	            $this->load->view('header_ar');

				$this->load->view('comons_ar');

				$this->load->view('footer_ar');

	

	}


	

	
	




public function news()

	{

		$config['base_url'] = base_url().'index.php/home/news/';

		$config['total_rows'] = $this->fun->get_num('news');

		$config['per_page'] = 5;

		$config['num_links'] = 3; 

		$config['uri_segment'] = 3;	

		$config['full_tag_open']='<div class="paginations"><ul id="pagin">';

		$config['full_tag_close'] = '</ul></div>';

		$config['next_link'] = 'Next';

		$config['prev_link'] = 'Prev';

		$config['next_tag_open'] = '<li class="latest_img">';

		$config['next_tag_close'] = '</li>';

		$config['prev_tag_open'] = '<li class="latest_img">';

		$config['prev_tag_close'] = '</li>';

		$config['num_tag_open'] = '<li class="latest_img">';

		$config['num_tag_close'] = '</li>';

		$config['cur_tag_open'] = '<li class="current latest_img"><a href="#" class="current">';

		$config['cur_tag_close'] = '</a></li>';		

		$offset = $this->uri->segment(3,0);

		$this->session->set_userdata('offset',$offset);

		$this->pagination->initialize($config);

		$q= $this->fun->getall_pag('posts','news',$config['per_page']);

		$data['posts']=$q;



 
       if($this->session->userdata('lang')=='en')
	    {

                $this->load->view('header');
				$this->load->view('news',$data);
				$this->load->view('footer');
	   }else
	   {

	            $this->load->view('header_ar');
				$this->load->view('news_ar',$data);
				$this->load->view('footer_ar');
	  }

	

	}

	

	public function downloads()

	{

		$config['base_url'] = base_url().'index.php/home/downloads/';

		$config['total_rows'] = $this->fun->get_num('downloads');

		$config['per_page'] = 12;

		$config['num_links'] = 3; 

		$config['uri_segment'] = 3;	

		$config['full_tag_open']='<div class="paginations"><ul id="pagin">';

		$config['full_tag_close'] = '</ul></div>';

		$config['next_link'] = 'Next';

		$config['prev_link'] = 'Prev';

		$config['next_tag_open'] = '<li class="latest_img">';

		$config['next_tag_close'] = '</li>';

		$config['prev_tag_open'] = '<li class="latest_img">';

		$config['prev_tag_close'] = '</li>';

		$config['num_tag_open'] = '<li class="latest_img">';

		$config['num_tag_close'] = '</li>';

		$config['cur_tag_open'] = '<li class="current latest_img"><a href="#" class="current">';

		$config['cur_tag_close'] = '</a></li>';		

		$offset = $this->uri->segment(3,0);

		$this->session->set_userdata('offset',$offset);

		$this->pagination->initialize($config);

		$q= $this->fun->getall_pag('posts','downloads',$config['per_page']);

		$data['posts']=$q;



 

	            $this->load->view('header');

				$this->load->view('downloads',$data);

				$this->load->view('footer');

	

	}








function contacts()
{
  $this->fun->contactmails();
}

	public function list_topics($module)

	{

		$config['base_url'] = base_url().'index.php/home/list_topics/'.$module.'/';

		$config['total_rows'] = $this->fun->get_num($module);

		$config['per_page'] = 10;

		$config['num_links'] = 3; 

		$config['uri_segment'] = 4;	

		$config['full_tag_open']='<div class="paginations"><ul id="pagin">';

		$config['full_tag_close'] = '</ul></div>';

		$config['next_link'] = 'Next';

		$config['prev_link'] = 'Prev';

		$config['next_tag_open'] = '<li class="latest_img">';

		$config['next_tag_close'] = '</li>';

		$config['prev_tag_open'] = '<li class="latest_img">';

		$config['prev_tag_close'] = '</li>';

		$config['num_tag_open'] = '<li class="latest_img">';

		$config['num_tag_close'] = '</li>';

		$config['cur_tag_open'] = '<li class="current latest_img"><a href="#" class="current">';

		$config['cur_tag_close'] = '</a></li>';		

		$offset = $this->uri->segment(3,0);

		$this->session->set_userdata('offset',$offset);

		$this->pagination->initialize($config);

		$q= $this->fun->getall_pag('posts',$module,$config['per_page']);

		$data['posts']=$q;

		$data['module']=$module;



 

	            $this->load->view('header');

				$this->load->view('list',$data);

				$this->load->view('footer');

	

	}



		public function gallery($cat)
	{
		        $data['cat']=$cat;
				$this->load->view('header');
				$this->load->view('gallery',$data);
				$this->load->view('footer');
	
	}
	public function albums()
	{
		
				$this->load->view('header');
				$this->load->view('albums');
				$this->load->view('footer');
	
	}

	

	function career_apply($jobid)

	{

	$data['jobid']=$jobid;

	 //$this->load->view('header',$hd);

	$this->load->view('career_apply',$data);

	//$this->load->view('footer');



	}





















		function send_apply()



	{



	 //$pic=$this->input->post('pic');



	 //echo $pic;



	    $file_name='';



	  



        



        if($_FILES['ppic']['name'])



				{



						$this->load->library('upload');



						$config['upload_path'] = "./uploads/cvs/";



						$config['allowed_types'] = '*';



						$config['overwrite'] = false;



						$config['encrypt_name'] =true;	



						$this->upload->set_max_filesize(201);



						$this->upload->initialize($config);



						$url = basename($_FILES['ppic']['name']);



						if(!empty($url)) // select img //



						{



							if (!$this->upload->do_upload('ppic'))



							{



							$error = $this->upload->display_errors();



							echo $error;



							//echo "<script type=\"text/javascript\">



							//alert(\" Image not uploaded please try again \");



							//window.location = \"addnew\";



							//</script>"; 



							} 



							else 



							{



							$upname = $this->upload->data();



							$file_name = $upname['file_name'];



							}



						 }



		        }











	



	     $jobid=$this->input->post('jobid');



	    $jobname=$this->input->post('jobname');



	    $fname=$this->input->post('fname');



	    $lname=$this->input->post('lname');



	    $mname=$this->input->post('mname');



	    $email=$this->input->post('email');



	    $phone=$this->input->post('phone');



	    $country=$this->input->post('country');



	    $city=$this->input->post('city');



	    $messag=$this->input->post('msg');



	    $skills=$this->input->post('skills');



	    $to= $this->fun->get_email();



	    $sub="new application in ".$jobname;



	    



	      $this->load->helper('email');



	      



    if($fname=='' or $mname=='' or $messag=='')



    {  // echo $email;



        	echo "<font color=cc0000>Enter Required Fields</font>";







    }



     elseif (!valid_email($email))



			{



				echo "<font color=cc0000>Enter Valid E-mail</font>";



			}







			else







			{







    



	      



       



	     $msg="Dear sir,\r\n name: ".$fname." ".$mname." \r\n Email: ".$email. "\r\n Phone: ".$phone. "\r\n\r\n".$messag."\r\nthanks" ;



          



          $msg=$msg.'... to download cv click '.base_url().'/uploads/cvs/'.$file_name;



	    



           $this->load->library('email');



$this->email->set_mailtype('html');



			$this->email->from($email);



			$this->email->to($to);



						



			$this->email->subject($sub);



			$this->email->message($msg);



			



			$this->email->send();



			



			//echo $this->email->print_debugger();



	    



	   



	       // echo "<script type=\"text/javascript\"> alert(\" Successfuly sent \") ;window.location.href= \"".base_url()."index.php/career/career_apply/".$jobid."\";</script>";



         echo "<font color=cc0000>Successfuly sent</font>";







		 



		//$this->load->view('career_apply',$data);



		//$this->load->view('footer');



		//$this->career_apply($jobid);



		



		}







	}

	

	






		function send_msg()
	{
	     $username=$this->input->post('username'); 
	     $pass=$this->input->post('pass');	
            $this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('username', 'Name ', 'trim|required|xss_clean');
					    $this->form_validation->set_rules('pass', 'Message', 'trim|required|xss_clean');
        if ($this->form_validation->run() == FALSE)
		 {
		       
		       	            $result= "<font color=red><b>Enter Username and password</b></font>";
	           		         $this->index("l",$result);
		 }
		 else
			 { 
			 
			    $chk=$this->fun->check_user_login($this->input->post('username'),md5($this->input->post('pass')));
			      if($chk==FALSE)
                   {
                        
                          $result= "<font color=red><b>Wronge Username and password </b></font>";
        		         $this->index("l",$result);
                   }
                   else
                   {
                   $this->session->set_userdata('username',$this->input->post('username'));
                   $this->session->set_userdata('userid',$chk);

                    redirect('home');
                   }
 	       // echo "<script type=\"text/javascript\"> alert(\" Successfuly sent \") ;window.location.href= \"".base_url()."index.php/contact/form\";</script>";
		}
	}
function logout()
{
$this->session->set_userdata('username',$username);
redirect('home');
}





}















/* End of file welcome.php */







/* Location: ./application/controllers/welcome.php */