<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Services extends Admin_Controller {
	
	   function __construct()
	   {
			parent::__construct();
			$this->load->model("mod_services","services");
	   }		

       public function index($page=1)
       {	
	   		$tab['activeTab'] = "services";
		    $this->load->model("mod_services");
			$data["services"] = $this->mod_services->getservices();
			$data["services"] = $data["services"]->result_array(); 
			
			$this->load->view('admin/header',$tab);
			$this->load->view('admin/services/view',$data);
			$this->load->view('admin/footer');
       }
	
	   public function add()
       {	
	   		$tab['activeTab'] = "services";
		    $this->load->model("mod_services");
			$this->form_validation->set_rules('name', 'Name', 'required');
		    
			if ($this->form_validation->run() == TRUE)
			{
			//Altering Database
				$user_id = $this->session->userdata('userId');
				$data['typename'] = trim($_POST['name']);
				$data['status'] = $_POST['status'];
				$data['remark'] = $_POST['remark'];
				$data['createdate'] = date('y-m-d');
				$data['createby'] = $user_id;
				
				$msg = $this->services->add($data);
				//End Altering Database
				if($msg==1 || $msg==0){
					$this->session->set_flashdata('message',"New Services is Successfully Added");
					redirect('admin/services/add');
					
					}else{
					$this->session->set_flashdata('message',"New Services is Failure Added!");
				    redirect('admin/services/add');
					
				}
				
			}
				
			$this->load->view('admin/header',$tab);
			$this->load->view('admin/services/add');
			$this->load->view('admin/footer');
       }
	
		
	   public function edit()
	   {
			$tab['activeTab'] = "services";
			$id = $this->uri->segment(4);
			$services = $this->services->getById($id);
			if(!$services)
			{
				redirect("admin/services");
			}
	
			if(@$_POST['update_services'])
			{				
			    $user_id = $this->session->userdata('userId');
				$postdata['typename'] = trim($_POST['name']);
				$postdata['remark'] = $_POST['remark'];
				$postdata['status'] = $_POST['status'];
				$postdata['modifydate'] = date('y-m-d');
				$postdata['modifyby'] = $user_id;
				
				$msg = $this->services->update($postdata,$id);
				
				$this->session->set_flashdata('message',"Services is Successfully Update");
				redirect("admin/services");
			}
		
		    $data['services'] = $services;
		    $this->load->view('admin/header',$tab);
			$this->load->view('admin/services/edit',$data);
			$this->load->view('admin/footer');	
	   }
	   
	   
	   function delete()
	   {
			$id = $this->uri->segment(4);
			$this->services->delete($id);
			$this->session->set_flashdata('message',"Services deleted successfully");
			redirect("admin/services");
	   }
	   
		
}