<?php
class Temp extends CI_Controller{
function temp()
{
parent::__construct();	
$this->load->library('session');
      $this->load->Model('functions', 'fun');
      $this->load->library('form_validation');

      $this->load->helper('date');
    }
    function index($result=''){
            
          if($this->session->userdata('lang')=='ar')
		  {
	      $data['result']=$result;
          $this->load->view('ar/header');
          $this->load->view('ar/temp',$data);
          $this->load->view('ar/footer');
		  }
          else
          {
          $data['result']=$result;
          $this->load->view('header');
          $this->load->view('temp',$data);
          $this->load->view('footer');
        }
    }
    
    function add_checkout(){
        
        $this->load->model('checkout_model');
        
        $rec = $this->checkout_model->get_session_id();
         $rs=mysql_fetch_array($rec);
       
        //$num = mysql_num_rows($rec);
        
        $res= mysql_fetch_assoc($rec);
        $datestring = "%Y/%m/%d";
		$time = time();
		$add_date=mdate($datestring, $time);
		
 		$res['session_id'] = $rs['session_id'];
        $res['ip_address'] =  $rs['ip_address'];
        $res['user_data']  =  $rs['user_data'];


        $res['name'] = $this->input->post('name');
        $res['email'] = $this->input->post('email');
        $res['phone'] = $this->input->post('phone');
        $res['address1'] = $this->input->post('address1');
        $res['address2'] = $this->input->post('address2');
        $res['city'] = $this->input->post('city');
        $res['state'] = $this->input->post('state');
        $res['zip'] = $this->input->post('zip');
        $res['country'] = $this->input->post('country');
        $res['add_date'] = $add_date;
        
         $this->load->model('checkout_model'); 
            $this->checkout_model->add_checkout($res);
           
            if($this->session->userdata('lang')=='ar')
		      {
		           $result='تم ارسال طلبك بنجاح';
		      }
              else
              {
                
		          $result='Your order successfully sent';
              }
             // echo '<script>alert("'.$result.'")</script>';
		    $this->index($result);

/*
        
           $this->form_validation->set_error_delimiters('<font color="#ff0000" style="font-size:11px" >', '</font>');
		   $this->form_validation->set_rules('name', 'name ', 'trim|required|xss_clean');
		   $this->form_validation->set_rules('email', 'E-mail ', 'trim|required|valid_email|xss_clean');
		   $this->form_validation->set_rules('phone', 'phone', 'trim|required|xss_clean');
		   $this->form_validation->set_rules('address1', 'Address1 ', 'trim|required|xss_clean');


           if ($this->form_validation->run() == FALSE)
		   { 
		      if($this->session->userdata('lang')=='ar')
		      {
		          $result='(*) من فضلك ادخل الحقول المطلوبه';
		      }
              else
              {
                
		         $result='(*) Please Enter Required Fields';
              }
		   $this->index($result);
	 
		   }
		   else
		   {
          
            $this->load->model('checkout_model'); 
            $this->checkout_model->add_checkout($res);
           
            if($this->session->userdata('lang')=='ar')
		      {
		           $result='تم ارسال طلبك بنجاح';
		      }
              else
              {
                
		          $result='Your order successfully sent';
              }
             // echo '<script>alert("'.$result.'")</script>';
		    $this->index($result);

        
           }*/
    }
    
    function remove($rowid){
        
        $this->cart->update(array(
                            'rowid' => $rowid,
                            'qty' => 0
                            ));
                            
        redirect('temp');
    }
    
    function update(){
        
        $this->cart->update(array(
                            'rowid' => $this->input->post('rowid'),
                            'qty'   => $this->input->post('qty')
                            ));
                            
        redirect('temp');
    }
}