<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Site_admin extends CI_Controller {
	
	private $id				=	''		; 
	private $filename		=	''		;
	private $order			=	''		; 
	private $title			=	''		; 
	private $text			=	''		; 
	private $img			=	''		;
	private $type			=	''		; 
	private $active			=	''		;
	private $error			=	'' 		;
	private $error_count	=	0		;
	private $upload_arr		=	array() ; 

	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->library('loginfunctions');
		
		//logged out
		if($this->loginfunctions->checkloggedin()===FALSE)
		{
			redirect('admin/') ;
		}
		else
		{
			$this->load->model('Db_model') ;
			
			$this->load->library(array('form_validation'));
		}
		
	}
	
	public function index()
	{
		$this->view();
	}


	private function _page( $data=array()  )
	{
		
		$this->load->view('admin/about_header',$data);
		$this->load->view('admin/menu');
		//$this->load->view('admin/top_links',$data);
		$this->load->view('admin/site_content',$data);
		$this->load->view('admin/footer');
		
	}
	
	
	
	
	/**
	*
	*   About Us modification
	*
	*/
	
	public function edit()
	{

		
		
		//retrieve details from database matching to the id
		$details = $this->Db_model->get_all('site',array());
		
		if($details!==FALSE)
		{
		
		//$this->aid = $details[0]['aid'] ;
		$this->phone1 = $details[0]['phone1'] ;
		$this->phone2 = $details[0]['phone2'] ;
		$this->emailo = $details[0]['emailo'] ;
		$this->dvt1 = $details[0]['dvt1'] ;
		$this->dvt2 = $details[0]['dvt2'] ;
		$this->dvtcharge = $details[0]['dvtcharge'] ;

		}
		
		$data = array(
				'page_name' => 'Site Identity' ,
				'heading' => 'Site Identity - Edit' ,
				'top_link_name' => 'View' ,
				'top_link' => site_url('Admin_home/') ,
		        'phone1' => $this->phone1,
				'phone2' => $this->phone2,
				'emailo' => $this->emailo,
				'dvt1' => $this->dvt1,
				'dvt2' => $this->dvt2,
				'dvtcharge' => $this->dvtcharge,
		        'str' => ''
				);
		
		
		//check if submit button clicked
		if($this->input->post('submit'))
		{
			
			$this->form_validation->set_rules('phone1', 'Phone Number One', 'trim|required|numeric');
			$this->form_validation->set_rules('phone2', 'Phone Number Two', 'trim|required|numeric');
            $this->form_validation->set_rules('dvtcharge', 'Fixed Delivery charge', 'trim|required|numeric');


			//if validation errors
			if ($this->form_validation->run() === FALSE)
			{
				
				$data = array(
							'page_name' => 'Site Identity' ,
			             	'heading' => 'Site Identity - Edit' ,
							
							'top_link' => site_url('Admin_home/') ,
						
						
							'phone1' => $this->input->post('phone1'),
							'phone2' => $this->input->post('phone2'),
							'emailo' => $this->input->post('emailo'),
							'dvt1' => $this->input->post('dvt1'),
							'dvt2' => $this->input->post('dvt2'),
							'dvtcharge' => $this->input->post('dvtcharge'),
		
							'str' => ''
							);
				
			
				$this->_page($data);
				
			}
			else
			{
				
				$data = array(
				
				
				            'phone1' => $this->input->post('phone1',TRUE),
							'phone2' => $this->input->post('phone2',TRUE),
							'emailo' => $this->input->post('emailo',TRUE),
							'dvt1' => $this->input->post('dvt1',TRUE),
							'dvt2' => $this->input->post('dvt2',TRUE),
							'dvtcharge' => $this->input->post('dvtcharge',TRUE),
				
					
							  );
				
			
				
				//update data
				$this->Db_model->update('site',$data,array()) ;
				
				redirect('Admin_home/');
			}
		
		}//if($this->input->post('submit'))
		
		else
		{
			/**
			*
			*	show form at first time page loads,
			*	ie, before clicking submit button
			*
			*/
			
			$this->_page($data);
		}
		
			
	

	}
	

	
	
	
	


	

	
}//end class About_admin

