<?php 
/**
 * User_profile_values Page Controller
 * @category  Controller
 */
class User_profile_valuesController extends SecureController{
	function __construct(){
		parent::__construct();
		$this->tablename = "user_profile_values";
	}
	/**
     * 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("user_profile_values.id", 
			"user_profile_values.user_id", 
			"user_info.user_full_name AS user_info_user_full_name", 
			"user_profile_values.basic_pay", 
			"user_profile_values.da", 
			"user_profile_values.hra", 
			"user_profile_values.ta_vahtuk_bhatta", 
			"user_profile_values.washing", 
			"user_profile_values.incentive_allowance", 
			"user_profile_values.festive_advance", 
			"user_profile_values.quarter_rent", 
			"user_profile_values.petrol_allowance", 
			"user_profile_values.dcps", 
			"user_profile_values.epf", 
			"user_profile_values.allowance_others", 
			"user_profile_values.pt", 
			"user_profile_values.dcps_14_mc", 
			"user_profile_values.dcps_10_own", 
			"user_profile_values.epf_12_mc", 
			"user_profile_values.eps_12_own", 
			"user_profile_values.gpf_b_n_n_vargani", 
			"user_profile_values.gpf_b_n_n_hafta", 
			"user_profile_values.lic", 
			"user_profile_values.mediclaim", 
			"user_profile_values.accidental_insurance", 
			"user_profile_values.group_insurance", 
			"user_profile_values.income_tax", 
			"user_profile_values.festival_adv_installment", 
			"user_profile_values.court_fee", 
			"user_profile_values.soc_1", 
			"user_profile_values.soc_2", 
			"user_profile_values.soc_3", 
			"user_profile_values.bank_1", 
			"user_profile_values.bank_2", 
			"user_profile_values.bank_3", 
			"user_profile_values.deductions_other", 
			"user_profile_values.timestamp");
		$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 = "(
				user_profile_values.id LIKE ? OR 
				user_profile_values.user_id LIKE ? OR 
				user_info.user_full_name LIKE ? OR 
				user_profile_values.name_of_emp LIKE ? OR 
				user_profile_values.basic_pay LIKE ? OR 
				user_profile_values.da LIKE ? OR 
				user_profile_values.hra LIKE ? OR 
				user_profile_values.ta_vahtuk_bhatta LIKE ? OR 
				user_profile_values.washing LIKE ? OR 
				user_profile_values.incentive_allowance LIKE ? OR 
				user_profile_values.festive_advance LIKE ? OR 
				user_profile_values.quarter_rent LIKE ? OR 
				user_profile_values.petrol_allowance LIKE ? OR 
				user_profile_values.dcps LIKE ? OR 
				user_profile_values.epf LIKE ? OR 
				user_profile_values.allowance_others LIKE ? OR 
				user_profile_values.pt LIKE ? OR 
				user_profile_values.dcps_14_mc LIKE ? OR 
				user_profile_values.dcps_10_own LIKE ? OR 
				user_profile_values.epf_12_mc LIKE ? OR 
				user_profile_values.eps_12_own LIKE ? OR 
				user_profile_values.gpf_b_n_n_vargani LIKE ? OR 
				user_profile_values.gpf_b_n_n_hafta LIKE ? OR 
				user_profile_values.lic LIKE ? OR 
				user_profile_values.mediclaim LIKE ? OR 
				user_profile_values.accidental_insurance LIKE ? OR 
				user_profile_values.group_insurance LIKE ? OR 
				user_profile_values.income_tax LIKE ? OR 
				user_profile_values.festival_adv_installment LIKE ? OR 
				user_profile_values.court_fee LIKE ? OR 
				user_profile_values.soc_1 LIKE ? OR 
				user_profile_values.soc_2 LIKE ? OR 
				user_profile_values.soc_3 LIKE ? OR 
				user_profile_values.bank_1 LIKE ? OR 
				user_profile_values.bank_2 LIKE ? OR 
				user_profile_values.bank_3 LIKE ? OR 
				user_profile_values.deductions_other LIKE ? OR 
				user_profile_values.timestamp LIKE ? OR 
				user_profile_values.admin_id LIKE ? OR 
				user_info.id LIKE ? OR 
				user_info.username LIKE ? OR 
				user_info.password LIKE ? OR 
				user_info.email LIKE ? OR 
				user_info.user_profile_values LIKE ? OR 
				user_info.user_role_id 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%","%$text%","%$text%","%$text%","%$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 = "user_profile_values/search.php";
		}
		$db->join("user_info", "user_profile_values.user_id = user_info.id", "INNER");
		if(!empty($request->orderby)){
			$orderby = $request->orderby;
			$ordertype = (!empty($request->ordertype) ? $request->ordertype : ORDER_TYPE);
			$db->orderBy($orderby, $ordertype);
		}
		else{
			$db->orderBy("user_profile_values.id", 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 = "User Profile Values";
		$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("user_profile_values/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("user_profile_values.id", 
			"user_profile_values.user_id", 
			"user_profile_values.name_of_emp", 
			"user_profile_values.basic_pay", 
			"user_profile_values.da", 
			"user_profile_values.hra", 
			"user_profile_values.ta_vahtuk_bhatta", 
			"user_profile_values.washing", 
			"user_profile_values.incentive_allowance", 
			"user_profile_values.festive_advance", 
			"user_profile_values.quarter_rent", 
			"user_profile_values.petrol_allowance", 
			"user_profile_values.dcps", 
			"user_profile_values.epf", 
			"user_profile_values.allowance_others", 
			"user_profile_values.pt", 
			"user_profile_values.dcps_14_mc", 
			"user_profile_values.dcps_10_own", 
			"user_profile_values.epf_12_mc", 
			"user_profile_values.eps_12_own", 
			"user_profile_values.gpf_b_n_n_vargani", 
			"user_profile_values.gpf_b_n_n_hafta", 
			"user_profile_values.lic", 
			"user_profile_values.mediclaim", 
			"user_profile_values.accidental_insurance", 
			"user_profile_values.group_insurance", 
			"user_profile_values.income_tax", 
			"user_profile_values.festival_adv_installment", 
			"user_profile_values.court_fee", 
			"user_profile_values.soc_1", 
			"user_profile_values.soc_2", 
			"user_profile_values.soc_3", 
			"user_profile_values.bank_1", 
			"user_profile_values.bank_2", 
			"user_profile_values.bank_3", 
			"user_profile_values.deductions_other", 
			"user_profile_values.timestamp", 
			"user_profile_values.admin_id", 
			"user_info.id AS user_info_id", 
			"user_info.username AS user_info_username", 
			"user_info.password AS user_info_password", 
			"user_info.email AS user_info_email", 
			"user_info.user_full_name AS user_info_user_full_name", 
			"user_info.user_profile_values AS user_info_user_profile_values", 
			"user_info.user_role_id AS user_info_user_role_id");
		if($value){
			$db->where($rec_id, urldecode($value)); //select record based on field name
		}
		else{
			$db->where("user_profile_values.id", $rec_id);; //select record based on primary key
		}
		$db->join("user_info", "user_profile_values.user_id = user_info.id", "INNER ");  
		$record = $db->getOne($tablename, $fields );
		if($record){
			$page_title = $this->view->page_title = "View  User Profile Values";
		$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("user_profile_values/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("user_id","basic_pay","da","hra","ta_vahtuk_bhatta","washing","incentive_allowance","festive_advance","quarter_rent","petrol_allowance","dcps","epf","allowance_others","pt","dcps_14_mc","dcps_10_own","epf_12_mc","eps_12_own","gpf_b_n_n_vargani","gpf_b_n_n_hafta","lic","mediclaim","accidental_insurance","group_insurance","income_tax","festival_adv_installment","court_fee","soc_1","soc_2","soc_3","bank_1","bank_2","bank_3","deductions_other","admin_id");
			$postdata = $this->format_request_data($formdata);
			$this->rules_array = array(
				'user_id' => 'required',
				'basic_pay' => 'required|numeric',
				'da' => 'required|numeric',
				'hra' => 'required|numeric',
				'ta_vahtuk_bhatta' => 'required|numeric',
				'washing' => 'required|numeric',
				'incentive_allowance' => 'required|numeric',
				'festive_advance' => 'required|numeric',
				'quarter_rent' => 'required|numeric',
				'petrol_allowance' => 'required|numeric',
				'dcps' => 'required|numeric',
				'epf' => 'required|numeric',
				'allowance_others' => 'required|numeric',
				'pt' => 'required|numeric',
				'dcps_14_mc' => 'required|numeric',
				'dcps_10_own' => 'required|numeric',
				'epf_12_mc' => 'required|numeric',
				'eps_12_own' => 'required|numeric',
				'gpf_b_n_n_vargani' => 'required|numeric',
				'gpf_b_n_n_hafta' => 'required|numeric',
				'lic' => 'required|numeric',
				'mediclaim' => 'required|numeric',
				'accidental_insurance' => 'required|numeric',
				'group_insurance' => 'required|numeric',
				'income_tax' => 'required|numeric',
				'festival_adv_installment' => 'required|numeric',
				'court_fee' => 'required|numeric',
				'soc_1' => 'required|numeric',
				'soc_2' => 'required|numeric',
				'soc_3' => 'required|numeric',
				'bank_1' => 'required|numeric',
				'bank_2' => 'required|numeric',
				'bank_3' => 'required|numeric',
				'deductions_other' => 'required|numeric',
			);
			$this->sanitize_array = array(
				'user_id' => 'sanitize_string',
				'basic_pay' => 'sanitize_string',
				'da' => 'sanitize_string',
				'hra' => 'sanitize_string',
				'ta_vahtuk_bhatta' => 'sanitize_string',
				'washing' => 'sanitize_string',
				'incentive_allowance' => 'sanitize_string',
				'festive_advance' => 'sanitize_string',
				'quarter_rent' => 'sanitize_string',
				'petrol_allowance' => 'sanitize_string',
				'dcps' => 'sanitize_string',
				'epf' => 'sanitize_string',
				'allowance_others' => 'sanitize_string',
				'pt' => 'sanitize_string',
				'dcps_14_mc' => 'sanitize_string',
				'dcps_10_own' => 'sanitize_string',
				'epf_12_mc' => 'sanitize_string',
				'eps_12_own' => 'sanitize_string',
				'gpf_b_n_n_vargani' => 'sanitize_string',
				'gpf_b_n_n_hafta' => 'sanitize_string',
				'lic' => 'sanitize_string',
				'mediclaim' => 'sanitize_string',
				'accidental_insurance' => 'sanitize_string',
				'group_insurance' => 'sanitize_string',
				'income_tax' => 'sanitize_string',
				'festival_adv_installment' => 'sanitize_string',
				'court_fee' => 'sanitize_string',
				'soc_1' => 'sanitize_string',
				'soc_2' => 'sanitize_string',
				'soc_3' => 'sanitize_string',
				'bank_1' => 'sanitize_string',
				'bank_2' => 'sanitize_string',
				'bank_3' => 'sanitize_string',
				'deductions_other' => 'sanitize_string',
			);
			$this->filter_vals = true; //set whether to remove empty fields
			$modeldata = $this->modeldata = $this->validate_form($postdata);
			$modeldata['admin_id'] = USER_ID;
			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("user_profile_values");
				}
				else{
					$this->set_page_error();
				}
			}
		}
		$page_title = $this->view->page_title = "Add New User Profile Values";
		$this->render_view("user_profile_values/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","user_id","basic_pay","da","hra","ta_vahtuk_bhatta","washing","incentive_allowance","festive_advance","quarter_rent","petrol_allowance","dcps","epf","allowance_others","pt","dcps_14_mc","dcps_10_own","epf_12_mc","eps_12_own","gpf_b_n_n_vargani","gpf_b_n_n_hafta","lic","mediclaim","accidental_insurance","group_insurance","income_tax","festival_adv_installment","court_fee","soc_1","soc_2","soc_3","bank_1","bank_2","bank_3","deductions_other","admin_id");
		if($formdata){
			$postdata = $this->format_request_data($formdata);
			$this->rules_array = array(
				'user_id' => 'required',
				'basic_pay' => 'required|numeric',
				'da' => 'required|numeric',
				'hra' => 'required|numeric',
				'ta_vahtuk_bhatta' => 'required|numeric',
				'washing' => 'required|numeric',
				'incentive_allowance' => 'required|numeric',
				'festive_advance' => 'required|numeric',
				'quarter_rent' => 'required|numeric',
				'petrol_allowance' => 'required|numeric',
				'dcps' => 'required|numeric',
				'epf' => 'required|numeric',
				'allowance_others' => 'required|numeric',
				'pt' => 'required|numeric',
				'dcps_14_mc' => 'required|numeric',
				'dcps_10_own' => 'required|numeric',
				'epf_12_mc' => 'required|numeric',
				'eps_12_own' => 'required|numeric',
				'gpf_b_n_n_vargani' => 'required|numeric',
				'gpf_b_n_n_hafta' => 'required|numeric',
				'lic' => 'required|numeric',
				'mediclaim' => 'required|numeric',
				'accidental_insurance' => 'required|numeric',
				'group_insurance' => 'required|numeric',
				'income_tax' => 'required|numeric',
				'festival_adv_installment' => 'required|numeric',
				'court_fee' => 'required|numeric',
				'soc_1' => 'required|numeric',
				'soc_2' => 'required|numeric',
				'soc_3' => 'required|numeric',
				'bank_1' => 'required|numeric',
				'bank_2' => 'required|numeric',
				'bank_3' => 'required|numeric',
				'deductions_other' => 'required|numeric',
			);
			$this->sanitize_array = array(
				'user_id' => 'sanitize_string',
				'basic_pay' => 'sanitize_string',
				'da' => 'sanitize_string',
				'hra' => 'sanitize_string',
				'ta_vahtuk_bhatta' => 'sanitize_string',
				'washing' => 'sanitize_string',
				'incentive_allowance' => 'sanitize_string',
				'festive_advance' => 'sanitize_string',
				'quarter_rent' => 'sanitize_string',
				'petrol_allowance' => 'sanitize_string',
				'dcps' => 'sanitize_string',
				'epf' => 'sanitize_string',
				'allowance_others' => 'sanitize_string',
				'pt' => 'sanitize_string',
				'dcps_14_mc' => 'sanitize_string',
				'dcps_10_own' => 'sanitize_string',
				'epf_12_mc' => 'sanitize_string',
				'eps_12_own' => 'sanitize_string',
				'gpf_b_n_n_vargani' => 'sanitize_string',
				'gpf_b_n_n_hafta' => 'sanitize_string',
				'lic' => 'sanitize_string',
				'mediclaim' => 'sanitize_string',
				'accidental_insurance' => 'sanitize_string',
				'group_insurance' => 'sanitize_string',
				'income_tax' => 'sanitize_string',
				'festival_adv_installment' => 'sanitize_string',
				'court_fee' => 'sanitize_string',
				'soc_1' => 'sanitize_string',
				'soc_2' => 'sanitize_string',
				'soc_3' => 'sanitize_string',
				'bank_1' => 'sanitize_string',
				'bank_2' => 'sanitize_string',
				'bank_3' => 'sanitize_string',
				'deductions_other' => 'sanitize_string',
			);
			$modeldata = $this->modeldata = $this->validate_form($postdata);
			$modeldata['admin_id'] = USER_ID;
			if($this->validated()){
				$db->where("user_profile_values.id", $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("user_profile_values");
				}
				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("user_profile_values");
					}
				}
			}
		}
		$db->where("user_profile_values.id", $rec_id);;
		$data = $db->getOne($tablename, $fields);
		$page_title = $this->view->page_title = "Edit  User Profile Values";
		if(!$data){
			$this->set_page_error();
		}
		return $this->render_view("user_profile_values/edit.php", $data);
	}
	/**
     * Update single field
	 * @param $rec_id (select record by table primary key)
	 * @param $formdata array() from $_POST
     * @return array
     */
	function editfield($rec_id = null, $formdata = null){
		$db = $this->GetModel();
		$this->rec_id = $rec_id;
		$tablename = $this->tablename;
		//editable fields
		$fields = $this->fields = array("id","user_id","basic_pay","da","hra","ta_vahtuk_bhatta","washing","incentive_allowance","festive_advance","quarter_rent","petrol_allowance","dcps","epf","allowance_others","pt","dcps_14_mc","dcps_10_own","epf_12_mc","eps_12_own","gpf_b_n_n_vargani","gpf_b_n_n_hafta","lic","mediclaim","accidental_insurance","group_insurance","income_tax","festival_adv_installment","court_fee","soc_1","soc_2","soc_3","bank_1","bank_2","bank_3","deductions_other","admin_id");
		$page_error = null;
		if($formdata){
			$postdata = array();
			$fieldname = $formdata['name'];
			$fieldvalue = $formdata['value'];
			$postdata[$fieldname] = $fieldvalue;
			$postdata = $this->format_request_data($postdata);
			$this->rules_array = array(
				'user_id' => 'required',
				'basic_pay' => 'required|numeric',
				'da' => 'required|numeric',
				'hra' => 'required|numeric',
				'ta_vahtuk_bhatta' => 'required|numeric',
				'washing' => 'required|numeric',
				'incentive_allowance' => 'required|numeric',
				'festive_advance' => 'required|numeric',
				'quarter_rent' => 'required|numeric',
				'petrol_allowance' => 'required|numeric',
				'dcps' => 'required|numeric',
				'epf' => 'required|numeric',
				'allowance_others' => 'required|numeric',
				'pt' => 'required|numeric',
				'dcps_14_mc' => 'required|numeric',
				'dcps_10_own' => 'required|numeric',
				'epf_12_mc' => 'required|numeric',
				'eps_12_own' => 'required|numeric',
				'gpf_b_n_n_vargani' => 'required|numeric',
				'gpf_b_n_n_hafta' => 'required|numeric',
				'lic' => 'required|numeric',
				'mediclaim' => 'required|numeric',
				'accidental_insurance' => 'required|numeric',
				'group_insurance' => 'required|numeric',
				'income_tax' => 'required|numeric',
				'festival_adv_installment' => 'required|numeric',
				'court_fee' => 'required|numeric',
				'soc_1' => 'required|numeric',
				'soc_2' => 'required|numeric',
				'soc_3' => 'required|numeric',
				'bank_1' => 'required|numeric',
				'bank_2' => 'required|numeric',
				'bank_3' => 'required|numeric',
				'deductions_other' => 'required|numeric',
			);
			$this->sanitize_array = array(
				'user_id' => 'sanitize_string',
				'basic_pay' => 'sanitize_string',
				'da' => 'sanitize_string',
				'hra' => 'sanitize_string',
				'ta_vahtuk_bhatta' => 'sanitize_string',
				'washing' => 'sanitize_string',
				'incentive_allowance' => 'sanitize_string',
				'festive_advance' => 'sanitize_string',
				'quarter_rent' => 'sanitize_string',
				'petrol_allowance' => 'sanitize_string',
				'dcps' => 'sanitize_string',
				'epf' => 'sanitize_string',
				'allowance_others' => 'sanitize_string',
				'pt' => 'sanitize_string',
				'dcps_14_mc' => 'sanitize_string',
				'dcps_10_own' => 'sanitize_string',
				'epf_12_mc' => 'sanitize_string',
				'eps_12_own' => 'sanitize_string',
				'gpf_b_n_n_vargani' => 'sanitize_string',
				'gpf_b_n_n_hafta' => 'sanitize_string',
				'lic' => 'sanitize_string',
				'mediclaim' => 'sanitize_string',
				'accidental_insurance' => 'sanitize_string',
				'group_insurance' => 'sanitize_string',
				'income_tax' => 'sanitize_string',
				'festival_adv_installment' => 'sanitize_string',
				'court_fee' => 'sanitize_string',
				'soc_1' => 'sanitize_string',
				'soc_2' => 'sanitize_string',
				'soc_3' => 'sanitize_string',
				'bank_1' => 'sanitize_string',
				'bank_2' => 'sanitize_string',
				'bank_3' => 'sanitize_string',
				'deductions_other' => 'sanitize_string',
			);
			$this->filter_rules = true; //filter validation rules by excluding fields not in the formdata
			$modeldata = $this->modeldata = $this->validate_form($postdata);
			if($this->validated()){
				$db->where("user_profile_values.id", $rec_id);;
				$bool = $db->update($tablename, $modeldata);
				$numRows = $db->getRowCount();
				if($bool && $numRows){
					return render_json(
						array(
							'num_rows' =>$numRows,
							'rec_id' =>$rec_id,
						)
					);
				}
				else{
					if($db->getLastError()){
						$page_error = $db->getLastError();
					}
					elseif(!$numRows){
						$page_error = "No record updated";
					}
					render_error($page_error);
				}
			}
			else{
				render_error($this->view->page_error);
			}
		}
		return null;
	}
	/**
     * 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("user_profile_values.id", $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("user_profile_values");
	}
}
