Viewing file: base_data.php (35.66 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php include('sa_controller.php'); class Base_data extends Sa_controller {
/** คำอธิบายฟังก์ชั่น: มีไว้กำหนดข้อมูลพื้นฐาน คุณลักษณะโครงการ **/ function attribute($add='TRUE') {
$this->load->model($this->config->item('sa_folder').'sa_attribute_model','atb'); $atb = $this->atb; $atb->atb_id = ($this->input->post('atb_parentId')!=0 && $this->input->post('add')!='แก้ไข')?$this->input->post('atb_parentId'):$this->input->post('atb_id'); $data['qu_atb'] = $atb->qu_joinparent(); $data['add'] = ($this->input->post('add'))?$this->input->post('add'):'TRUE'; $data['rs_atb'] = $atb->qu_all(); $this->output("v_add_attribute", $data); }
function add_attribute() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('atb_id', 'atb_id', 'trim|xss_clean'); $this->form_validation->set_rules('atb_name', 'คุณลักษณะโครงการ ', 'trim|required|xss_clean'); $this->form_validation->set_rules('atb_parentId', 'atb_parentId', 'trim|xss_clean'); if ($this->form_validation->run() == FALSE) { $this->attribute(TRUE); } else { $this->load->model($this->config->item('sa_folder').'sa_attribute_model','sa_attribute_model'); $atb = $this->sa_attribute_model;
$atb->atb_id = trim($this->input->post('atb_id')); $atb->atb_name = trim($this->input->post('atb_name')); $atb->atb_parentId = trim($this->input->post('atb_parentId'));
$qu = $atb->qry_attr(); if($qu->num_rows() == 0){ $atb->atb_id = trim($this->input->post('atb_id')); $atb->atb_name = trim($this->input->post('atb_name')); $atb->atb_parentId = trim($this->input->post('atb_parentId'));
if ($this->input->post('atb_id')) { $atb->update(); } else { $atb->insert(); } redirect($this->config->item('sa_folder').'base_data/attribute'); } else { $this->load->vars(array('error_name' => "<font color='red'><br />ข้อมูลนี้มีอยู่แล้ว</font>")); $this->attribute(TRUE); } } }
function del_attribute () {
$this->load->model($this->config->item('sa_folder').'sa_attribute_model','atb'); $atb = $this->atb; $atb->atb_id = $this->input->post('atb_id'); $atb->delete_parent(); $atb->delete();
redirect($this->config->item('sa_folder').'base_data/attribute'); }
/** คำอธิบายฟังก์ชั่น: มีไว้กำหนดข้อมูลพื้นฐาน คุณลักษณะโครงการ **/ function integration($add='TRUE') {
$this->load->model($this->config->item('sa_folder').'sa_integration_model','itg'); $itg = $this->itg; $itg->itg_id = ($this->input->post('itg_parentId')!=0 && $this->input->post('add')!='แก้ไข')?$this->input->post('itg_parentId'):$this->input->post('itg_id'); $data['qu_itg'] = $itg->qu_joinparent(); $data['add'] = ($this->input->post('add'))?$this->input->post('add'):'TRUE'; $data['rs_itg'] = $itg->qu_all(); $this->output("v_add_integration", $data); }
function add_integration() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('itg_id', 'itg_id', 'trim|xss_clean'); $this->form_validation->set_rules('itg_name', 'บูรณาการกับฝ่ายอื่นๆ ', 'trim|required|xss_clean'); $this->form_validation->set_rules('itg_parentId', 'itg_parentId', 'trim|xss_clean'); if ($this->form_validation->run() == FALSE) { $this->integration(TRUE); } else { $this->load->model($this->config->item('sa_folder').'sa_integration_model','sa_integration_model'); $itg = $this->sa_integration_model;
$itg->itg_id = trim($this->input->post('itg_id')); $itg->itg_name = trim($this->input->post('itg_name')); $itg->itg_parentId = trim($this->input->post('itg_parentId'));
$qu = $itg->qry_attr(); if($qu->num_rows() == 0){ $itg->itg_id = trim($this->input->post('itg_id')); $itg->itg_name = trim($this->input->post('itg_name')); $itg->itg_parentId = trim($this->input->post('itg_parentId'));
if ($this->input->post('itg_id')) { $itg->update(); } else { $itg->insert(); } redirect($this->config->item('sa_folder').'base_data/integration'); } else { $this->load->vars(array('error_name' => "<font color='red'><br />ข้อมูลนี้มีอยู่แล้ว</font>")); $this->integration(TRUE); } } }
function del_integration () {
$this->load->model($this->config->item('sa_folder').'sa_integration_model','itg'); $itg = $this->itg; $itg->itg_id = $this->input->post('itg_id'); $itg->delete_parent(); $itg->delete();
redirect($this->config->item('sa_folder').'base_data/integration'); }
/** คำอธิบายฟังก์ชั่น: มีไว้กำหนดข้อมูลพื้นฐาน แหล่งเงินงบประมาณ **/ function sourcebudget($add='TRUE') {
$this->load->model($this->config->item('sa_folder').'sa_sourcebudget_model','sb'); $sb = $this->sb; $sb->sb_id = ($this->input->post('sb_pid')!=0 && $this->input->post('add')!='แก้ไข')?$this->input->post('sb_pid'):$this->input->post('sb_id'); $data['qu_sb'] = $sb->qu_joinparent(); $data['add'] = ($this->input->post('add'))?$this->input->post('add'):'TRUE'; $data['rs_sb'] = $sb->qu_all(); $this->output("v_add_sourcebudget", $data);
}
function add_sourcebudget() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('sb_id', 'sb_id', 'trim|xss_clean'); $this->form_validation->set_rules('sb_name', 'แหล่งเงินงบประมาณ', 'trim|required|xss_clean'); $this->form_validation->set_rules('sb_pid', 'sb_pid', 'trim|xss_clean'); if ($this->form_validation->run() == FALSE) { $this->sourcebudget(TRUE); } else { $this->load->model($this->config->item('sa_folder').'sa_sourcebudget_model','sb'); $sb = $this->sb; $sb->sb_id = trim($this->input->post('sb_id')); $sb->sb_name = trim($this->input->post('sb_name')); $sb->sb_pid = trim($this->input->post('sb_pid'));
$qu = $sb->check_rep_name();
if ($qu->num_rows() == 0) { if ($this->input->post('sb_id')) { $sb->update(); } else { $sb->insert(); }
redirect($this->config->item('sa_folder').'base_data/sourcebudget'); } else { $this->load->vars(array('error_name' => "<font color='red'>ชื่อแหล่งเงินงบประมาณนี้มีอยู่แล้ว</font>")); $this->sourcebudget(); } } }
function del_sourcebudget() {
$this->load->model($this->config->item('sa_folder').'sa_sourcebudget_model','sb'); $sb = $this->sb; $sb->sb_id = $this->input->post('sb_id'); $sb->delete_parent(); $sb->delete();
redirect($this->config->item('sa_folder').'base_data/sourcebudget'); }
/** คำอธิบายฟังก์ชั่น: มีไว้กำหนดข้อมูลพื้นฐาน คณะกรรมการบริหาร */ function smo_pos() { $this->load->model($this->config->item('sa_folder').'sa_position_model','sa_pos'); $pos = $this->sa_pos; $pos->pos_id = $this->input->post('pos_id'); $pos->get_by_key(true); $data['pos'] = $pos; $pos->pos_type = 1; // เป็นประเภทสโมสร $data['rs_pos'] = $pos->get_by_type();
$this->output("v_add_smo_position", $data); }
function add_smo_pos() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>');
$this->form_validation->set_rules('pos_id', '', 'trim|xss_clean'); $this->form_validation->set_rules('pos_name', ' ชื่อตำแหน่ง ', 'trim|required|xss_clean'); $this->form_validation->set_rules('pos_status', ' ', 'trim|required|xss_clean'); $this->form_validation->set_rules('pos_seq', ' ลำดับ ', 'trim|required|is_natural_no_zero|xss_clean'); $this->form_validation->set_rules('pos_num', ' ', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) { $this->smo_pos(); } else { $this->load->model($this->config->item('sa_folder').'sa_position_model'); $pos = $this->sa_position_model;
$pos->pos_id = trim($this->input->post('pos_id')); $pos->pos_name = trim($this->input->post('pos_name')); $pos->pos_type = trim($this->input->post('pos_type')); $pos->pos_seq = trim($this->input->post('pos_seq')); $chk = $pos->check_rep_name(); if ( $chk == 0 ) { $pos->pos_status = trim($this->input->post('pos_status')); $pos->pos_num = trim($this->input->post('pos_num')); if ($this->input->post('pos_id')) { $pos->update(); } else { $pos->insert(); } redirect($this->config->item('sa_folder').'base_data/smo_pos'); } else { if ($chk == 1) { $this->load->vars(array('error_name' => "<font color='red'><br />ชื่อตำแหน่งนี้มีอยู่แล้ว</font>")); } else { $this->load->vars(array('error_seq' => "<font color='red'><br />เลขลำดับนี้มีอยู่แล้ว</font>")); } $this->smo_pos(); } } }
function club_pos() { $this->load->model($this->config->item('sa_folder').'sa_position_model','sa_pos'); $pos = $this->sa_pos; $pos->pos_id = $this->input->post('pos_id'); $pos->get_by_key(TRUE);
$data['pos'] = $pos;
$pos->pos_type = 2; // เป็นประเภทชมรม $data['rs_pos'] = $pos->get_by_type(); $this->output("v_add_club_position", $data); }
function add_club_pos() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>');
$this->form_validation->set_rules('pos_id', '', 'trim|xss_clean'); $this->form_validation->set_rules('pos_name', ' ชื่อตำแหน่ง ', 'trim|required|xss_clean'); $this->form_validation->set_rules('pos_status', ' ', 'trim|required|xss_clean'); $this->form_validation->set_rules('pos_seq', ' ลำดับ ', 'trim|required|is_natural_no_zero|xss_clean'); $this->form_validation->set_rules('pos_num', ' ', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) { $this->club_pos(TRUE); } else { $this->load->model($this->config->item('sa_folder').'sa_position_model'); $pos = $this->sa_position_model; $pos->pos_id = trim($this->input->post('pos_id')); $pos->pos_name = trim($this->input->post('pos_name')); $pos->pos_type = trim($this->input->post('pos_type')); $pos->pos_seq = trim($this->input->post('pos_seq')); $chk = $pos->check_rep_name(); if ( $chk == 0 ) { $pos->pos_id = trim($this->input->post('pos_id')); $pos->pos_name = trim($this->input->post('pos_name')); $pos->pos_status = trim($this->input->post('pos_status')); $pos->pos_type = trim($this->input->post('pos_type')); $pos->pos_seq = trim($this->input->post('pos_seq')); $pos->pos_num = trim($this->input->post('pos_num')); if ( $this->input->post('pos_id')) { $pos->update(); } else { $pos->insert(); } redirect($this->config->item('sa_folder').'base_data/club_pos'); } else { if ($chk == 1) { $this->load->vars(array('error_name' => "<font color='red'><br />ชื่อตำแหน่งนี้มีอยู่แล้ว</font>")); } else { $this->load->vars(array('error_seq' => "<font color='red'><br />เลขลำดับนี้มีอยู่แล้ว</font>")); } $this->club_pos(); } } }
function del_pos () { $id = $this->input->post('pos_id'); $type = $this->input->post('pos_type');
$this->load->model($this->config->item('sa_folder').'sa_position_model'); $pos = $this->sa_position_model; $pos->pos_id = $id; $pos->delete(); if ($type == 1) { redirect($this->config->item('sa_folder').'base_data/smo_pos'); } else { redirect($this->config->item('sa_folder').'base_data/club_pos'); } }
function strategic() { $this->load->model($this->config->item('sa_folder').'sa_initialbudget_model','ib'); $data['qu_ib'] = $this->ib->get_options('y'); $this->load->model($this->config->item('sa_folder').'sa_strategic_model','stg'); $stg = $this->stg;
$stg->stg_id = $this->input->post('stg_id'); $stg->get_by_key(true); $data['stg'] = $stg; $data['v_search'] = ($this->input->post('v_search'))? $this->input->post('v_search') : $this->session->flashdata('v_name') ; $stg->stg_ib = $data['v_search']; $data['rs_stg'] = $stg->get_by_year(); $this->output("v_add_strategic", $data); }
function add_strategic() {
$this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('stg_id', '', 'trim|xss_clean'); $this->form_validation->set_rules('stg_seq', 'ลำดับ', 'trim|required|is_natural_no_zero|xss_clean'); $this->form_validation->set_rules('stg_name', 'ประเด็นยุทธศาสตร์', 'trim|required|xss_clean'); $this->form_validation->set_rules('stg_ib', 'ปีงบประมาณ', 'callback_checkselect'); if ($this->form_validation->run() == FALSE) { $this->strategic(); } else { $this->load->model($this->config->item('sa_folder').'sa_strategic_model','stg'); $stg = $this->stg;
$stg->stg_id = trim($this->input->post('stg_id')); $stg->stg_seq = trim($this->input->post('stg_seq')); $stg->stg_name = trim($this->input->post('stg_name')); $stg->stg_ib = trim($this->input->post('stg_ib'));
$chk = $stg->check_rep_name(); if ($chk == 0) { if ( $this->input->post('stg_id')) { $stg->update(); } else { $stg->insert(); } $this->session->set_flashdata('v_name', $stg->stg_ib); redirect($this->config->item('sa_folder').'base_data/strategic'); } else { if ($chk == 1) { $this->load->vars(array('error_name' => "<font color='red'><br />ชื่อตำแหน่งนี้มีอยู่แล้ว</font>")); } else { $this->load->vars(array('error_seq' => "<font color='red'><br />เลขลำดับนี้มีอยู่แล้ว</font>")); } $this->strategic(); } } }
function del_stg () { $this->load->model($this->config->item('sa_folder').'sa_strategic_model','stg'); $stg = $this->stg; $stg->stg_id = $this->input->post('stg_id'); $stg->delete();
redirect($this->config->item('sa_folder').'base_data/strategic'); }
function vehicle() { $this->load->model($this->config->item('sa_folder').'sa_vehicle_model','veh'); $veh = $this->veh; $veh->veh_id = $this->input->post('veh_id'); $veh->get_by_key(true); $data['veh'] = $veh;
$data['rs_veh'] = $veh->get_all(); $this->output("v_add_vehicle", $data); }
function add_vehicle() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>');
$this->form_validation->set_rules('veh_id', '', 'trim|xss_clean'); $this->form_validation->set_rules('veh_name', 'ชื่อตำแหน่ง', 'trim|required|xss_clean'); $this->form_validation->set_rules('veh_status', 'สถานะ', 'callback_checkselect');
if ($this->form_validation->run() == FALSE) { $this->vehicle(); } else { $this->load->model($this->config->item('sa_folder').'sa_vehicle_model','veh'); $veh = $this->veh; $veh->veh_id = trim($this->input->post('veh_id')); $veh->veh_name = $this->input->post('veh_name'); $qu_veh = $veh->check_rep_name(); if ( $qu_veh->num_rows() == 0 ) { $veh->veh_status = trim($this->input->post('veh_status')); if ( $this->input->post('veh_id') != '' ) { $veh->update(); } else { $veh->insert(); } redirect($this->config->item('sa_folder').'base_data/vehicle'); } else { $this->load->vars(array('error_name' => "<font color='red'><br />ชื่อประเภทกิจกรรมนี้มีอยู่แล้ว</font>")); $this->vehicle(); } } }
function del_vehicle () { $this->load->model($this->config->item('sa_folder').'sa_vehicle_model','veh'); $veh = $this->veh; $veh->veh_id = $this->input->post('veh_id'); $veh->delete();
redirect($this->config->item('sa_folder').'base_data/vehicle'); }
function adviser_type () { $this->load->model($this->config->item('sa_folder').'sa_adviser_type_model','avt'); $avt = $this->avt; $avt->avt_id = $this->input->post('avt_id'); $avt->get_by_key(true); $data['avt'] = $avt;
$data['rs_avt'] = $avt->get_all(); $this->output("v_add_type", $data); }
function add_adviser_type() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>');
$this->form_validation->set_rules('avt_id', '', 'trim|xss_clean'); $this->form_validation->set_rules('avt_name', 'ชื่อตำแหน่ง', 'trim|required|xss_clean'); $this->form_validation->set_rules('avt_status', 'สถานะ', 'trim|xss_clean|callback_checkselect');
if ($this->form_validation->run() == FALSE) { $this->adviser_type(); } else { $this->load->model($this->config->item('sa_folder').'sa_adviser_type_model','avt'); $avt = $this->avt; $avt->avt_name = $this->input->post('avt_name'); $avt->avt_id = $this->input->post('avt_id'); $qu_avt = $avt->check_rep_name(); if ( $qu_avt->num_rows() == 0 ) { $avt->avt_id = trim($this->input->post('avt_id')); $avt->avt_name = trim($this->input->post('avt_name')); $avt->avt_status = trim($this->input->post('avt_status')); if ( $this->input->post('avt_id') != '' ) { $avt->update(); } else { $avt->insert(); } redirect($this->config->item('sa_folder').'base_data/adviser_type'); } else { $this->load->vars(array('error_name' => "<font color='red'><br/>ชื่อประเภทนี้มีอยู่แล้ว</font>")); $this->adviser_type(); } } }
function del_adviser_type () { $this->load->model($this->config->item('sa_folder').'sa_adviser_type_model','avt'); $avt = $this->avt; $avt->avt_id = $this->input->post('avt_id'); $avt->delete();
redirect($this->config->item('sa_folder').'base_data/adviser_type'); }
function ib_add() { $this->load->model($this->config->item('sa_folder').'sa_initialbudget_model','ib');
// update $ib_id = $this->input->post('ib_id'); $this->ib->ib_id = $ib_id; $data['qu_ib'] = $this->ib->get_by_key(); // end update
$ord_rs_ib = array('ib_bgY' => 'DESC'); $data['rs_ib'] = $this->ib->get_all($ord_rs_ib);
$this->output("v_add_initialbudget", $data); } function ib_insert_update() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>'); $this->form_validation->set_rules('ib_bgY', 'ปีงบประมาณ ', 'trim|required|is_natural_no_zero|callback_checkEra|xss_clean'); $this->form_validation->set_rules('ib_id', ' ', 'trim|xss_clean');
if ($this->form_validation->run() == FALSE) { $this->ib_add(); } else {
$this->load->model($this->config->item('sa_folder').'sa_initialbudget_model','ib'); $ib = $this->ib;
$ib->ib_bgY = $this->input->post('ib_bgY'); $ib->ib_id = $this->input->post('ib_id'); $qu_ib = $ib->check_rep_name(); if ($qu_ib->num_rows()==0) { if ($this->input->post('ib_id')=='') { $ib->insert(); } else { $ib->update(); } redirect($this->config->item('sa_folder').'base_data/ib_add'); } else { $this->load->vars(array('error_name' => "<font color='red'><br/>ปีงบประมาณนี้มีอยู่แล้ว</font>")); $this->ib_add(); } } }
function ib_delete() { $this->load->model($this->config->item('sa_folder').'sa_initialbudget_model','ib');
$ib_id = $this->input->post('ib_id'); $this->ib->ib_id = $ib_id; $this->ib->delete();
redirect($this->config->item('sa_folder').'base_data/ib_add'); } function checkBmi($str) { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi;
if($str=='') { $this->form_validation->set_message('checkBmi','กรุณาป้อน%s'); return false; } else { $rs_bmi_group = $bmi->getByGroup($str); $tmp_id = ""; if($rs_bmi_group->num_rows()) { foreach($rs_bmi_group->result() as $row_bmi_group) { $tmp_id.= $row_bmi_group->bmi_id.", "; }
$id = substr($tmp_id, 0, -2); $rs_bmi = $bmi->qryByBmi_groupAndNotBmi_id($str, $id); if($rs_bmi->num_rows()==0) { return TRUE; } else { $this->form_validation->set_message('checkBmi','ชื่อกลุ่มดัชนีมวลกายนี้มีในระบบแล้ว'); return false; } } else { return TRUE; }
if($rs->num_rows()>0){ $this->form_validation->set_message('checkBmi','ชื่อกลุ่มดัชนีมวลกายนี้มีในระบบแล้ว'); return false; }else{ return true; } } } function input_bmi(){ $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi; $rs_bmi = $bmi->getGroup(); $data['rs_bmi'] = $rs_bmi; $data['bmi_group'] = $this->input->post('bmi_group'); $data['bmi_fr_date'] = $this->input->post('bmi_fr_date'); $data['bmi_to_date'] = $this->input->post('bmi_to_date'); $data['check_end'] = $this->input->post('check_end'); $data['edit'] = $this->input->post('edit');
// เลือกข้อมูล update $bmi_id = $this->input->post('bmi_id'); $bmi->bmi_id = $bmi_id; $data['qu_bmi'] = $this->bmi->get_by_key(); // end เลือกข้อมูล update
$this->output("v_add_bmi",$data); } function edit_bmi(){ $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>'); $this->form_validation->set_rules('bmi_group', 'ชื่อกลุ่มดัชนีมวลกาย', 'trim|required|xss_clean|callback_checkBmi'); $this->form_validation->set_rules('bmi_fr_date', 'วันที่เริ่มใช้', 'trim|required|xss_clean|callback_checkFrDate[bmi_to_date]'); $this->form_validation->set_rules('bmi_to_date', ' ', 'trim|required|callback_checkDupDate|xss_clean'); $this->form_validation->set_rules('check_end', ' ', 'trim|required|xss_clean'); $this->form_validation->set_rules('bmi_id', ' ', 'trim|xss_clean'); $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi; if ($this->form_validation->run() == TRUE) { $fr = explode("/",$this->input->post('bmi_fr_date')); $to = explode("/",$this->input->post('bmi_to_date')); $bmi->bmi_group = $this->input->post('bmi_group'); $bmi->bmi_fr_date = $fr[2]."-".$fr[1]."-".$fr[0]; $bmi->bmi_to_date = ($this->input->post('check_end')=="now")? "0000-00-00":$to[2]."-".$to[1]."-".$to[0]; if($bmi->updateByGroup($this->input->post('old'))){ redirect($this->config->item('sa_folder').'base_data/input_bmi'); } }else{ $this->input_bmi(); } } function del_bmi(){ $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi; $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>'); $this->form_validation->set_rules('bmi_group', ' ', 'trim|required|xss_clean'); if ($this->form_validation->run() == TRUE) { if($bmi->deleteByGroup($this->input->post('bmi_group'))){ redirect($this->config->item('sa_folder').'base_data/input_bmi'); } } }
function checkDupDate() { // **** check ข้อมูลดัชนีมวลกายที่มีวันที่ซ้อนกัน
$this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi');
$one_date = splitDateDb2($this->input->post('bmi_fr_date')); $define = $this->input->post('check_end'); $bmi_group = $this->input->post('bmi_group');
if($define=="now") { $to_date = '0000-00-00'; } else { $to_date = splitDateDb2($this->input->post('bmi_to_date')); }
if(!$bmi_group) { $check_first = $this->bmi->qryBmiByFrDateOrToDate($one_date); $check_to = $this->bmi->qryBmiByToDate($to_date); } else { $check_first = $this->bmi->qryBmiByFrDateOrToDateNotGroup($one_date, $bmi_group); if($to_date=='0000-00-00') { $check_to = $this->bmi->qryBmiByToDateNotGroup($to_date, $bmi_group); } else { $check_to = $this->bmi->qryBmiByFrDateOrToDateNotGroup($to_date, $bmi_group); } }
//echo $check_first."+++".$check_to;
if($check_first==1 || $check_to==1) { $this->form_validation->set_message('checkDupDate', '%s วันที่ซ้ำซ้อนกับชุดข้อมูลดัชนีมวลกายอื่น'); return FALSE; } else { return TRUE; } } function input_bmi_tb(){ $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>'); $this->form_validation->set_rules('check_end', ' ', 'trim|required|xss_clean'); $this->form_validation->set_rules('bmi_id', ' ', 'trim|xss_clean');
if($this->input->post('mng')==false) { $this->form_validation->set_rules('bmi_group', 'ชื่อกลุ่มดัชนีมวลกาย', 'trim|required|xss_clean|callback_checkBmi');
// เช็คเฉพาะติ๊กเลือกระบุวันที่ if($this->input->post('check_end')=="define") { $this->form_validation->set_rules('bmi_fr_date', 'วันที่เริ่มใช้', 'trim|required|xss_clean|callback_checkFrDate[bmi_to_date]'); $this->form_validation->set_rules('bmi_to_date', ' ', 'trim|required|callback_checkDupDate|xss_clean'); } else { $this->form_validation->set_rules('bmi_fr_date', 'วันที่เริ่มใช้', 'trim|xss_clean'); $this->form_validation->set_rules('bmi_to_date', ' ', 'trim|callback_checkDupDate|xss_clean'); } } else { $this->form_validation->set_rules('bmi_group', ' ', 'trim|required|xss_clean'); }
$this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi; if($this->input->post('bmi_id')){ $bmi->bmi_id = $this->input->post('bmi_id'); $qu_bmi = $bmi->get_by_key(); } if($this->input->post('valid') or $this->session->flashdata('dt')){ if($this->session->flashdata('dt')){ $dt = $this->session->flashdata('dt'); $dt = array( 'bmi_group' => $dt['bmi_group'], 'bmi_fr_date' => $dt['bmi_fr_date'], 'bmi_to_date' => $dt['bmi_to_date'] ); $this->session->set_flashdata('dt',$dt); $data['bmi_to_date'] = $dt['bmi_to_date']; }else{ if($this->input->post('check_end')=="now"){ $data['bmi_to_date'] = "0000-00-00"; }else{ $data['bmi_to_date'] = $this->input->post('bmi_to_date'); } } $data['bmi_group'] = ($this->session->flashdata('dt'))? $dt['bmi_group']:trim($this->input->post('bmi_group')); $data['bmi_fr_date'] = ($this->session->flashdata('dt'))? $dt['bmi_fr_date']:trim($this->input->post('bmi_fr_date')); $data['check_end'] = $this->input->post('check_end'); if($this->input->post('bmi_id')){ $qu_bmi = $bmi->get_by_key(); $data['qu_bmi'] = $qu_bmi; } $rs_bmi = $bmi->getByGroup($data['bmi_group']); $data['rs_bmi'] = $rs_bmi; $this->output("v_add_bmi_tb",$data); }else{ if ($this->form_validation->run() == FALSE) { $this->input_bmi(); }else{ $data['bmi_group'] = trim($this->input->post('bmi_group')); $data['bmi_fr_date'] = splitDateForm2($this->input->post('bmi_fr_date'), '/'); if($this->input->post('check_end')=="now"){ $data['bmi_to_date'] = "0000-00-00"; }else{ $data['bmi_to_date'] = splitDateForm2($this->input->post('bmi_to_date'), '/'); } if($this->input->post('mng')){ $data['bmi_fr_date'] = $this->input->post('bmi_fr_date'); $data['bmi_to_date'] = $this->input->post('bmi_to_date'); } $data['check_end'] = $this->input->post('check_end'); if($this->input->post('bmi_id')){ $qu_bmi = $bmi->get_by_key(); $data['qu_bmi'] = $qu_bmi; } $rs_bmi = $bmi->getByGroup($data['bmi_group']); $data['rs_bmi'] = $rs_bmi; $this->output("v_add_bmi_tb",$data); } } } function bmi_delete(){ $this->load->library('form_validation'); $this->form_validation->set_rules('bmi_id', ' ', 'trim|xss_clean'); $this->form_validation->set_rules('bmi_group', ' ', 'trim|xss_clean'); $this->form_validation->set_rules('bmi_fr_date', ' ', 'trim|xss_clean'); $this->form_validation->set_rules('bmi_to_date', ' ', 'trim|xss_clean'); if ($this->form_validation->run() == TRUE) { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi; $bmi->bmi_id = trim($this->input->post('bmi_id')); $bmi->delete(); $dt = array( 'bmi_group' => trim($this->input->post('bmi_group')), 'bmi_fr_date' => trim($this->input->post('bmi_fr_date')), 'bmi_to_date' => trim($this->input->post('bmi_to_date')) ); $this->session->set_flashdata('dt',$dt); redirect($this->config->item('sa_folder').'base_data/input_bmi_tb'); } }
function checkBmiRate($str, $field) { $min = $str; $max = $this->input->post($field);
if($min <= $max) { return TRUE; } else { $this->form_validation->set_message('checkBmiRate', '%s ต้องน้อยกว่า ค่าดัชนีมวลกายขั้นสูง'); return FALSE; } }
function checkBmiRateMin($str, $field) { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi');
$bmi_group = $this->input->post($field); $bmi_id = $this->input->post('bmi_id');
$rs_bmi = $this->bmi->qryBmiBetweenMinAndMax($str, $bmi_group, $bmi_id); if($rs_bmi->num_rows()==0) { return TRUE; } else { $this->form_validation->set_message('checkBmiRateMin', $str.' เป็นค่าดัชนีมวลกายแล้ว'); return FALSE; } }
function checkBmiRateMax($str, $field) { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi_min = $this->input->post('bmi_min');
$bmi_group = $this->input->post($field); $bmi_id = $this->input->post('bmi_id');
$rs_bmi = $this->bmi->qryBmiBetweenMinAndMax($str, $bmi_group, $bmi_id); if($rs_bmi->num_rows()==0) { $max_bmi_expect = $this->bmi->qryBmi_minByBmi_group($bmi_group, $bmi_min, $bmi_id);
if($str < $max_bmi_expect || $max_bmi_expect==NULL) { return TRUE; } else { $this->form_validation->set_message('checkBmiRateMax', 'ค่าดัชนีมวลกายขั้นสูงไม่ควรเกิน '.number_format($max_bmi_expect,1)); return FALSE; } } else { $this->form_validation->set_message('checkBmiRateMax', $str.' เป็นค่าดัชนีมวลกายแล้ว'); return FALSE; } }
function checkBmiName($str) { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi');
$bmi_name = $str; $bmi_group = $this->input->post('bmi_group');
$rs_bmi = $this->bmi->qryByBmiGroupAndBmiName($bmi_group, $bmi_name); if($rs_bmi->num_rows()) { $this->form_validation->set_message('checkBmiName', 'ชื่อผลการประเมินนี้มีในระบบแล้ว '); return false; } else { return true; } }
function checkBmiName2($str) { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi');
$bmi_name = $str; $bmi_group = $this->input->post('bmi_group'); $bmi_id = $this->input->post('bmi_id');
$rs_bmi = $this->bmi->qryByBmiGroupAndBmiNameNotId($bmi_group, $bmi_name, $bmi_id); if($rs_bmi->num_rows()) { $this->form_validation->set_message('checkBmiName2', 'ชื่อผลการประเมินนี้มีในระบบแล้ว '); return false; } else { return true; } }
function bmi_tb_insert_update(){ $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<br><font color="red">','</font>'); $this->form_validation->set_message('decimal', 'กรุณาป้อนเลขทศนิยมเท่านั้น'); $this->form_validation->set_rules('bmi_group', ' ', 'trim|required|xss_clean'); $this->form_validation->set_rules('bmi_fr_date', '', 'trim|required|xss_clean|'); $this->form_validation->set_rules('bmi_to_date', ' ', 'trim|required|xss_clean');
if($this->input->post('bmi_id')) { $this->form_validation->set_rules('bmi_name', 'ผลการประเมิน', 'trim|required|checkBmiName2|xss_clean'); } else { $this->form_validation->set_rules('bmi_name', 'ผลการประเมิน', 'trim|required|callback_checkBmiName|xss_clean'); }
$this->form_validation->set_rules('bmi_min', 'ค่าดัชนีมวลกายขั้นต่ำ', 'trim|required|numeric|callback_checkBmiRate[bmi_max]|callback_checkBmiRateMin[bmi_group]|checkxss_clean'); $this->form_validation->set_rules('bmi_max', 'ค่าดัชนีมวลกายขั้นสูง', 'trim|required|numeric|callback_checkBmiRateMax[bmi_group]|xss_clean'); $this->form_validation->set_rules('bmi_id', ' ', 'trim|xss_clean');
if ($this->form_validation->run() == FALSE) { $this->input_bmi_tb(); } else { $this->load->model($this->config->item('sa_folder').'sa_bmi_model','bmi'); $bmi = $this->bmi; $bmi->bmi_group = trim($this->input->post('bmi_group')); $bmi->bmi_name = trim($this->input->post('bmi_name')); $bmi->bmi_min = trim($this->input->post('bmi_min')); $bmi->bmi_max = trim($this->input->post('bmi_max')); $bmi->bmi_fr_date = trim($this->input->post('bmi_fr_date')); $bmi->bmi_to_date = trim($this->input->post('bmi_to_date')); if($this->input->post('bmi_id')) { $bmi->bmi_id = trim($this->input->post('bmi_id')); $bmi->update(); } else { $bmi->insert(); } $dt = array( 'bmi_group' => trim($this->input->post('bmi_group')), 'bmi_fr_date' => trim($this->input->post('bmi_fr_date')), 'bmi_to_date' => trim($this->input->post('bmi_to_date'))); $this->session->set_flashdata('dt',$dt); redirect($this->config->item('sa_folder').'base_data/input_bmi_tb'); } } }
|