<?php 
class contact extends CI_Controller {
	function contact()	 
	{  
   parent::__construct();	
    $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('contact_ar',$data);
				$this->load->view('footer_ar');
	   }else
	   {
	            $this->load->view('header');
				$this->load->view('contact',$data);
				$this->load->view('footer');
	   }

		
	}
		function send_msg()
	{
	    $subject=$this->input->post('sub'); 	
	    $email=$this->input->post('email');
	    $messag=$this->input->post('msg');
	    $to= $this->fun->get_email();
	    $sub="New message from Your website ".$subject;
	     $msg="Dear sir,<br>Name : ".$this->input->post('name')."<br>Mobile : ".$this->input->post('mob')."<br><b>".$messag."</b> <br>\r\nthanks" ;
	                    $this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('name', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('email', 'email ', 'trim|required|valid_email|xss_clean');
						$this->form_validation->set_rules('msg', 'Message', 'trim|required|xss_clean');
        if ($this->form_validation->run() == FALSE)
		 {
		       if($this->session->userdata('lang')=='ar')
	            {
	            		 		 $result= "<font color=red><b>&#1575;&#1583;&#1582;&#1604; &#1575;&#1604;&#1581;&#1602;&#1608;&#1604; &#1575;&#1604;&#1605;&#1591;&#1604;&#1608;&#1576;&#1607;</b></font>";

	            }
	            else
	            {

		 		 $result= "<font color=red><b>Enter Required Fields</b></font>";
		 		 }
		         $this->index("l",$result);
		 }
		 		 else
		 {
            $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);
			$send=$this->email->send();
            if($send)
            {
                if($this->session->userdata('lang')=='en')
	            {
	                            $result= "<font color=red><b>&#1578;&#1605; &#1575;&#1604;&#1575;&#1585;&#1587;&#1575;&#1604; &#1588;&#1603;&#1585;&#1575; �</b></font>";

	            }
	            else
	            {
 
	                            $result= "<font color=red><b>Successfully Sent�</b></font>";
                }
                $this->index("l",$result);
            }
            else
            {
                if($this->session->userdata('lang')=='en')
	            {
	            }
	            else
	            {

	                            $result= "<font color=red><b>Error ..try again�</b></font>";
                $this->index("l",$result);
                }
            }
 	       // echo "<script type=\"text/javascript\"> alert(\" Successfuly sent \") ;window.location.href= \"".base_url()."index.php/contact/form\";</script>";
		}
	}
	
	
	
	function send_call_msg()
	{
	    $fname=$this->input->post('fname'); 
	    $lname=$this->input->post('lname'); 		
	    $address=$this->input->post('address');
	    $phone=$this->input->post('phone');
	    $cat=$this->input->post('cat');
$msg=$this->input->post('msg');$cat2=$this->input->post('cat2');
	    $to= $this->fun->get_email();
	    $sub="New Call Order from rama website visitor";
	     $msg="Dear sir,<br>\r\n name: ".$fname." ".$lname." <br>\r\n phone: ".$phone. "<br>\r\n rama: ".$cat."<br>\r\n Sub: ".$cat2. "<br>\r\n Message: <b>".$msg. "<b><br>\r\nthanks" ;
	                    $this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('fname', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('msg', 'Name ', 'trim|required|xss_clean');

						$this->form_validation->set_rules('phone', 'email ', 'trim|required|xss_clean');
        if ($this->form_validation->run() == FALSE)
		 {
		       if($this->session->userdata('lang')=='en')
	            {
	            }
	            else
	            {

		 		 echo "<div style='text-align:right'><font color=red>كل الحقول مطلوبه</font></div>";
		 		 }
		         //$this->index("l",$result);
		 }
		 		 else
		 {
		 $email='visitor@rama.com';
            $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);
			$send=$this->email->send();
            if($send)
            {
                if($this->session->userdata('lang')=='en')
	            {
	            }
	            else
	            {
 
                echo "<div style='text-align:right'><font color=red>تم الارسال بنجاح</font><div>";
                }
                //$this->index("l",$result);
            }
            else
            {
                if($this->session->userdata('lang')=='en')
	            {
	            }
	            else
	            {

                echo  "<div style='text-align:right'><font color=red>خطأ في الارسال ..حاول مره اخري</font></div>";
                //$this->index("l",$result);
                }
            }
 	       // echo "<script type=\"text/javascript\"> alert(\" Successfuly sent \") ;window.location.href= \"".base_url()."index.php/contact/form\";</script>";
		}
	}

		public function form2()
	{	
	$menu=array();
    $menu_q= $this->fun->getall('posts','center');
	$menu['center']=$menu_q;
	$menu_q22= $this->fun->getall('posts','legan');
	$menu['legan']=$menu_q22;
	$menu_q23= $this->fun->getall_limit('posts','news',9);
	$menu['news']=$menu_q23;
$slid_q22= $this->fun->getall('posts','slider');
	$menu['sliders']=$slid_q22;
 $menu_q223= $this->fun->getall('posts','menu');
	$menu['main_menu']=$menu_q223;
 $social_q= $this->fun->get_setting();
	$menu['social']=$social_q;
	$this->load->view('header',$menu);
		$data=array();
		$menu_q= $this->fun->getone('posts',9);
		$data['posts']=$menu_q;
		$sites_q4= $this->fun->getall_limit('posts','sites','5');
		$data['sites']=$sites_q4;
    $poll_q= $this->fun->get_poll();
	$data['poll']=$poll_q;
	foreach($poll_q->result() as $rr):
	$poll_id=$rr->id;
	endforeach;
	 $poll_ans= $this->fun->get_poll_answer($poll_id);
	$data['poll_ans']=$poll_ans;
 $sites_q24= $this->fun->getall_limit('posts','models','3');
	$data['models']=$sites_q24;
		$this->load->view('form2',$data);
		$this->load->view('footer');
	}
function contacts()
{
  $this->fun->contactmails();
}
			function send_msg2()
	{
	             if($_FILES['pic']['name'])
							{
									$this->load->library('upload');
									$config['upload_path'] = "uploads/gallery/";
									$config['allowed_types'] = 'gif|jpg|png|pdf|doc|dox';
									$config['overwrite'] = false;
									$config['encrypt_name'] =true;	
									$this->upload->set_max_filesize(201);
									$this->upload->initialize($config);
									$url = basename($_FILES['pic']['name']);
									if(!empty($url)) // select img //
									{
										if (!$this->upload->do_upload('pic'))
										{
										$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'];
										}
									 }
					        }
	    	    $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');
	    $mob=$this->input->post('mob');
	    $messag=$this->input->post('msg');
	    $to= $this->fun->get_email();
	    $sub="new message from qitnetwork visitor ";
	     $msg="Dear sir,\r\n name: ".$fname." ".$mname." ".$lname." \r\n Email: ".$email. "\r\n Mobile: ".$mob. "\r\n Phone: ".$phone."\r\n\r\n<b>".$messag."</b>\r\nthanks" ;
 //$msg.=' ÊÌãíá Çæ ãÔÇåÏå ÇáãáÝ ÇáãÑÝÞ '.base_url().'uploads/gallery/'.$file_name;
	                    $this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('fname', 'First Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('lname', 'Last Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('mname', 'Middle Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('email', 'email ', 'trim|required|valid_email|xss_clean');
						$this->form_validation->set_rules('msg', 'Message', 'trim|required|xss_clean');
        if ($this->form_validation->run() == FALSE)
		 {
		 $this->index();
		 }
		 else
		 {
           $this->load->library('email');
			$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/contact/form2\";</script>";
		//$this->load->view('career_apply',$data);
		//$this->load->view('footer');
		}
	}
}
?>