<?php 
/**
 * Sppg Page Controller
 * @category  Controller
 */
class SppgController extends SecureController{
	function __construct(){
		parent::__construct();
		$this->tablename = "sppg";
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function index($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Pendataan SPPG Prov.Bengkulu";
		$this->view->report_filename = date('d-m-Y') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/list.php", $data); //render the full page
	}
	/**
     * View record detail 
	 * @param $rec_id (select record by table primary key) 
     * @param $value value (select record by value of field name(rec_id))
     * @return BaseView
     */
	function view($rec_id = null, $value = null){
		$request = $this->request;
		$db = $this->GetModel();
		$rec_id = $this->rec_id = urldecode($rec_id);
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		if($value){
			$db->where($rec_id, urldecode($value)); //select record based on field name
		}
		else{
			$db->where("sppg.id_sppg", $rec_id);; //select record based on primary key
		}
		$record = $db->getOne($tablename, $fields );
		if($record){
			$page_title = $this->view->page_title = "View  Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		}
		else{
			if($db->getLastError()){
				$this->set_page_error();
			}
			else{
				$this->set_page_error("No record found");
			}
		}
		return $this->render_view("sppg/view.php", $record);
	}
	/**
     * Insert new record to the database table
	 * @param $formdata array() from $_POST
     * @return BaseView
     */
	function add($formdata = null){
		if($formdata){
			$db = $this->GetModel();
			$tablename = $this->tablename;
			$request = $this->request;
			//fillable fields
			$fields = $this->fields = array("nama_sppg","identitas_sppg","yayasan","asal_kabupaten","tanggal_ops","sertifikat_slhs","sertifikat_halal","sertifikat_kelayakan_air","sertifikat_chef","ipal","pm_bumil","pm_busui","pm_balita","pm_sekolah","jumlah_relawan","link_gmaps","link_slhs","link_halal","link_air");
			$postdata = $this->format_request_data($formdata);
			$this->rules_array = array(
				'nama_sppg' => 'required',
				'identitas_sppg' => 'required',
				'yayasan' => 'required',
				'asal_kabupaten' => 'required',
				'tanggal_ops' => 'required',
				'sertifikat_slhs' => 'required',
				'sertifikat_halal' => 'required',
				'sertifikat_kelayakan_air' => 'required',
				'sertifikat_chef' => 'required',
				'ipal' => 'required',
				'pm_bumil' => 'required',
				'pm_busui' => 'required',
				'pm_balita' => 'required',
				'pm_sekolah' => 'required',
				'jumlah_relawan' => 'required',
				'link_gmaps' => 'required',
				'link_slhs' => 'required',
				'link_halal' => 'required',
				'link_air' => 'required',
			);
			$this->sanitize_array = array(
				'nama_sppg' => 'sanitize_string',
				'identitas_sppg' => 'sanitize_string',
				'yayasan' => 'sanitize_string',
				'asal_kabupaten' => 'sanitize_string',
				'tanggal_ops' => 'sanitize_string',
				'sertifikat_slhs' => 'sanitize_string',
				'sertifikat_halal' => 'sanitize_string',
				'sertifikat_kelayakan_air' => 'sanitize_string',
				'sertifikat_chef' => 'sanitize_string',
				'ipal' => 'sanitize_string',
				'pm_bumil' => 'sanitize_string',
				'pm_busui' => 'sanitize_string',
				'pm_balita' => 'sanitize_string',
				'pm_sekolah' => 'sanitize_string',
				'jumlah_relawan' => 'sanitize_string',
				'link_gmaps' => 'sanitize_string',
				'link_slhs' => 'sanitize_string',
				'link_halal' => 'sanitize_string',
				'link_air' => 'sanitize_string',
			);
			$this->filter_vals = true; //set whether to remove empty fields
			$modeldata = $this->modeldata = $this->validate_form($postdata);
			if($this->validated()){
				$rec_id = $this->rec_id = $db->insert($tablename, $modeldata);
				if($rec_id){
					$this->set_flash_msg("Record added successfully", "success");
					return	$this->redirect("sppg");
				}
				else{
					$this->set_page_error();
				}
			}
		}
		$page_title = $this->view->page_title = "Add New Sppg";
		$this->render_view("sppg/add.php");
	}
	/**
     * Update table record with formdata
	 * @param $rec_id (select record by table primary key)
	 * @param $formdata array() from $_POST
     * @return array
     */
	function edit($rec_id = null, $formdata = null){
		$request = $this->request;
		$db = $this->GetModel();
		$this->rec_id = $rec_id;
		$tablename = $this->tablename;
		 //editable fields
		$fields = $this->fields = array("id_sppg","nama_sppg","identitas_sppg","yayasan","asal_kabupaten","tanggal_ops","sertifikat_slhs","sertifikat_halal","sertifikat_kelayakan_air","sertifikat_chef","ipal","pm_bumil","pm_busui","pm_balita","pm_sekolah","jumlah_relawan","link_gmaps","link_slhs","link_halal","link_air");
		if($formdata){
			$postdata = $this->format_request_data($formdata);
			$this->rules_array = array(
				'nama_sppg' => 'required',
				'identitas_sppg' => 'required',
				'yayasan' => 'required',
				'asal_kabupaten' => 'required',
				'tanggal_ops' => 'required',
				'sertifikat_slhs' => 'required',
				'sertifikat_halal' => 'required',
				'sertifikat_kelayakan_air' => 'required',
				'sertifikat_chef' => 'required',
				'ipal' => 'required',
				'pm_bumil' => 'required',
				'pm_busui' => 'required',
				'pm_balita' => 'required',
				'pm_sekolah' => 'required',
				'jumlah_relawan' => 'required',
				'link_gmaps' => 'required',
				'link_slhs' => 'required',
				'link_halal' => 'required',
				'link_air' => 'required',
			);
			$this->sanitize_array = array(
				'nama_sppg' => 'sanitize_string',
				'identitas_sppg' => 'sanitize_string',
				'yayasan' => 'sanitize_string',
				'asal_kabupaten' => 'sanitize_string',
				'tanggal_ops' => 'sanitize_string',
				'sertifikat_slhs' => 'sanitize_string',
				'sertifikat_halal' => 'sanitize_string',
				'sertifikat_kelayakan_air' => 'sanitize_string',
				'sertifikat_chef' => 'sanitize_string',
				'ipal' => 'sanitize_string',
				'pm_bumil' => 'sanitize_string',
				'pm_busui' => 'sanitize_string',
				'pm_balita' => 'sanitize_string',
				'pm_sekolah' => 'sanitize_string',
				'jumlah_relawan' => 'sanitize_string',
				'link_gmaps' => 'sanitize_string',
				'link_slhs' => 'sanitize_string',
				'link_halal' => 'sanitize_string',
				'link_air' => 'sanitize_string',
			);
			$modeldata = $this->modeldata = $this->validate_form($postdata);
			if($this->validated()){
				$db->where("sppg.id_sppg", $rec_id);;
				$bool = $db->update($tablename, $modeldata);
				$numRows = $db->getRowCount(); //number of affected rows. 0 = no record field updated
				if($bool && $numRows){
					$this->set_flash_msg("Record updated successfully", "success");
					return $this->redirect("sppg");
				}
				else{
					if($db->getLastError()){
						$this->set_page_error();
					}
					elseif(!$numRows){
						//not an error, but no record was updated
						$page_error = "No record updated";
						$this->set_page_error($page_error);
						$this->set_flash_msg($page_error, "warning");
						return	$this->redirect("sppg");
					}
				}
			}
		}
		$db->where("sppg.id_sppg", $rec_id);;
		$data = $db->getOne($tablename, $fields);
		$page_title = $this->view->page_title = "Edit  Sppg";
		if(!$data){
			$this->set_page_error();
		}
		return $this->render_view("sppg/edit.php", $data);
	}
	/**
     * Delete record from the database
	 * Support multi delete by separating record id by comma.
     * @return BaseView
     */
	function delete($rec_id = null){
		Csrf::cross_check();
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$this->rec_id = $rec_id;
		//form multiple delete, split record id separated by comma into array
		$arr_rec_id = array_map('trim', explode(",", $rec_id));
		$db->where("sppg.id_sppg", $arr_rec_id, "in");
		$bool = $db->delete($tablename);
		if($bool){
			$this->set_flash_msg("Record deleted successfully", "success");
		}
		elseif($db->getLastError()){
			$page_error = $db->getLastError();
			$this->set_flash_msg($page_error, "danger");
		}
		return	$this->redirect("sppg");
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function bengkulu_tengah($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/bengkulu_tengah.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function kota_bengkulu($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/kota_bengkulu.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function bengkulu_utara($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/bengkulu_utara.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function bengkulu_selatan($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/bengkulu_selatan.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function rejang_lebong($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/rejang_lebong.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function lebong($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/lebong.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function kaur($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"
pm_balita + pm_busui + pm_bumil + pm_sekolah
 AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
pm_balita + pm_busui + pm_bumil + pm_sekolah
 LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/kaur.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function kepahiang($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/kepahiang.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function mukomuko($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"
pm_balita + pm_busui + pm_bumil + pm_sekolah AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
pm_balita + pm_busui + pm_bumil + pm_sekolah LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/mukomuko.php", $data); //render the full page
	}
	/**
     * List page records
     * @param $fieldname (filter record by a field) 
     * @param $fieldvalue (filter field value)
     * @return BaseView
     */
	function seluma($fieldname = null , $fieldvalue = null){
		$request = $this->request;
		$db = $this->GetModel();
		$tablename = $this->tablename;
		$fields = array("id_sppg", 
			"nama_sppg", 
			"identitas_sppg", 
			"yayasan", 
			"asal_kabupaten", 
			"tanggal_ops", 
			"sertifikat_slhs", 
			"sertifikat_halal", 
			"sertifikat_kelayakan_air", 
			"sertifikat_chef", 
			"ipal", 
			"pm_bumil", 
			"pm_busui", 
			"pm_balita", 
			"pm_sekolah", 
			"pm_balita + pm_busui + pm_bumil + pm_sekolah
 AS Total_PM", 
			"jumlah_relawan", 
			"link_gmaps", 
			"link_slhs", 
			"link_halal", 
			"link_air");
		$pagination = $this->get_pagination(MAX_RECORD_COUNT); // get current pagination e.g array(page_number, page_limit)
		//search table record
		if(!empty($request->search)){
			$text = trim($request->search); 
			$search_condition = "(
				sppg.id_sppg LIKE ? OR 
				sppg.nama_sppg LIKE ? OR 
				sppg.identitas_sppg LIKE ? OR 
				sppg.yayasan LIKE ? OR 
				sppg.asal_kabupaten LIKE ? OR 
				sppg.tanggal_ops LIKE ? OR 
				sppg.sertifikat_slhs LIKE ? OR 
				sppg.sertifikat_halal LIKE ? OR 
				sppg.sertifikat_kelayakan_air LIKE ? OR 
				sppg.sertifikat_chef LIKE ? OR 
				sppg.ipal LIKE ? OR 
				sppg.pm_bumil LIKE ? OR 
				sppg.pm_busui LIKE ? OR 
				sppg.pm_balita LIKE ? OR 
				sppg.pm_sekolah LIKE ? OR 
				pm_balita + pm_busui + pm_bumil + pm_sekolah
 LIKE ? OR 
				sppg.jumlah_relawan LIKE ? OR 
				sppg.link_gmaps LIKE ? OR 
				sppg.link_slhs LIKE ? OR 
				sppg.link_halal LIKE ? OR 
				sppg.link_air LIKE ?
			)";
			$search_params = array(
				"%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%","%$text%"
			);
			//setting search conditions
			$db->where($search_condition, $search_params);
			 //template to use when ajax search
			$this->view->search_template = "sppg/search.php";
		}
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("sppg.id_sppg", ORDER_TYPE);
		}
		if($fieldname){
			$db->where($fieldname , $fieldvalue); //filter by a single field name
		}
		$tc = $db->withTotalCount();
		$records = $db->get($tablename, $pagination, $fields);
		$records_count = count($records);
		$total_records = intval($tc->totalCount);
		$page_limit = $pagination[1];
		$total_pages = ceil($total_records / $page_limit);
		$data = new stdClass;
		$data->records = $records;
		$data->record_count = $records_count;
		$data->total_records = $total_records;
		$data->total_page = $total_pages;
		if($db->getLastError()){
			$this->set_page_error();
		}
		$page_title = $this->view->page_title = "Sppg";
		$this->view->report_filename = date('Y-m-d') . '-' . $page_title;
		$this->view->report_title = $page_title;
		$this->view->report_layout = "report_layout.php";
		$this->view->report_paper_size = "A4";
		$this->view->report_orientation = "portrait";
		$this->render_view("sppg/seluma.php", $data); //render the full page
	}
}
