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

class Waqafsetup extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('7', 'setup');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}
		$this->load->library('layouts');
		$this->load->model('menu');
	}
	
// Waqaf Center - Farhana 

	public function WaqafNew()
	{
	  if($this->input->post('mysubmit')){
		  if($this->input->post('ID')==NULL){
		   $newwaqaf = array(
		   		
				'ID'		=> $this->input->post('ID'), 
				'shortName' => $this->input->post('shortName'),
				'name' => $this->input->post('name'),
				'line1' => $this->input->post('line1'),
				'line2' => $this->input->post('line2'),
				'line3' => $this->input->post('line3'),
				'city' => $this->input->post('city'),
				'postCode' => $this->input->post('postCode'),
				'stateID' => $this->input->post('state'),
				'countryID' => $this->input->post('country'),
				'noTel' => $this->input->post('noTel'),
				'noFax' => $this->input->post('noFax'),
				'email' => $this->input->post('email'),
				'website' => $this->input->post('website'),
			  	'updatedBy' => element('role', $this->session->userdata('logged_in')),
			  );
			  $this->load->model('waqaf/waqaf_model');
			  $insert_waqaf = $this->waqaf_model->waqafmaster_insert($newwaqaf);
			if($insert_waqaf){
				echo '<script>alert("Insert Data Success..");
				window.location.replace("waqaflist");
				</script>';
			}else{
				echo '<script>alert("Insert Data Failed.");
				history.go(-1);</script>';
			}
		  }
		  
		  else{
			$ID = $this->input->post('ID');
		  	$newwaqaf = array(
				'ID'		=> $this->input->post('ID'), 
				'shortName' => $this->input->post('shortName'),
				'name' => $this->input->post('name'),
				//'address' => $this->input->post('address'),
				'line1' => $this->input->post('line1'),
				'line2' => $this->input->post('line2'),
				'line3' => $this->input->post('line3'),
				'city' => $this->input->post('city'),
				'postCode' => $this->input->post('postCode'),
				'stateID' => $this->input->post('state'),
				'countryID' => $this->input->post('country'),
				'noTel' => $this->input->post('noTel'),
				'noFax' => $this->input->post('noFax'),
				'email' => $this->input->post('email'),
				'website' => $this->input->post('website'),
			  	'updatedBy' => element('role', $this->session->userdata('logged_in')),
			
		  	); 
		
			$this->load->model('waqaf/waqaf_model');
			$insert_waqaf = $this->waqaf_model->waqafmaster_edit($newwaqaf, $ID);
			if($insert_waqaf){
				echo '<script>alert("Update Success..");
					window.location.replace("waqaflist");
					</script>';
			}else{
				echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
			}
		  }
		   } else {     
		 $ID = $this->uri->segment(3);;
//		echo 'id.'.$ID;
		$this->lang->load("WaqafCenter",$this->session->userdata('language'));
		$this->load->library('layouts');
		$this->load->helper('form');
		$this->load->model('waqaf/waqaf_model');
		$this->load->model('Country');
		$data['country'] = $this->Country->country_all();
		$this->load->model('State');
		$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
			->add_includes('js/validationengine/jquery.validationEngine.js');
			
		if($ID > 0 ){
			$dataum = $this->waqaf_model->WaqafCenter_ID($ID);
//			echo $this->db->last_query();
			$data['waqafdata'] = $dataum[0];
//			var_dump($dataum);
//			echo '<br>next';
//			var_dump($this->State->state_region($dataum[0]->countryID));
			$data['state'] = $this->State->state_region($dataum[0]->countryID);
			$this->layouts->view('waqaf/addwaqaf', array('latest' => 'sidebar/latest'), $data);
		}else{
			$data['state'] = $this->State->state_region('458');
			$data['waqafdata'] = '';
			$this->layouts->view('waqaf/addwaqaf', array('latest' => 'sidebar/latest'), $data);
		}
						
			}
	}
	public function waqafmaster_edit(){
			$this->load->model('waqaf/waqaf_model');
		  	$updateuser = array('is_delete' => '1');
			$ID = $this->input->post('ID');
		  	$updateuser = $this->waqaf_model->waqafmaster_edit($updatewaqaf,$ID);
			if($updateuser){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
	public function WaqafCenter_Delete($ID){
		$this->db->where('ID', $ID);
		$query = $this->db->delete('wakaf_center'); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function waqafList(){
		$this->load->library('layouts');
		$this->load->model('waqaf/waqaf_model');
		$data['datatbls'] = $this->waqaf_model->group_all();
		$this->lang->load("WaqafCenter",$this->session->userdata('language'));
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('waqaf/waqaflist', array('latest' => 'sidebar/latest'), $data);
	}
	
	 public function rptWaqaf($mode = false){
		 
			$this->load->library('layouts');
			$this->load->helper('form');
			$this->load->helper('menu');
            $this->load->model('waqaf/waqaf_model');
			$this->load->model('company/company_info_model');
			$this->load->model('State');
            $this->lang->load("WaqafCenter",$this->session->userdata('language'));
          
            
             $headerData['rightContentHeader'] = "";
             $headerData['rptTitle'] = "Waqaf Center Master List";
             $headerData['rightContent'] = array("As at: ".date("d-m-Y"));
             $headerData['leftContent'] = array("Waqaf Center Master Listing : All");
             
             $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
              
             $bodyData['rptDataDetail'] = $this->waqaf_model->group_all();
             $bodyData['tableHeader'] = array("ShortName", "Name", "Telephone", "Website", "Action"); 
             $bodyData['selectFields'] = array("shortName", "name", "noTel","website","noFax");
          
            
            $this->load->view('layouts/report/header', $headerData);
            $this->load->view('layouts/report/body', $bodyData);
            $this->load->view('layouts/report/footer','');
        }
}
