!c99Shell v. 1.0 pre-release build #16!

Software: Apache/2.2.3 (CentOS). PHP/5.1.6 

uname -a: Linux mx-ll-110-164-51-230.static.3bb.co.th 2.6.18-194.el5PAE #1 SMP Fri Apr 2 15:37:44
EDT 2010 i686
 

uid=48(apache) gid=48(apache) groups=48(apache) 

Safe-mode: OFF (not secure)

/var/www/html/mis/application/controllers/eregis/   drwxr-xr-x
Free 50.99 GB of 127.8 GB (39.9%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     bdcollege.php (100.13 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include('rg_controller.php');
class 
Bdcollege extends Rg_controller {

//    function __construct() {
//        parent::__construct();
//    }

    // ##### start tmc
    
function tmc_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
        
        
$acY $this->input->post('tmcAcY');
        
$tmId $this->input->post('tmcTmId');
        
$edit $this->input->post('edit');

        
$this->tmc->tmcAcY $acY;
        
$this->tmc->tmcTmId $tmId;
        
$qu_tmc $this->tmc->get_by_key();
        if (
$qu_tmc->num_rows() && $edit!="") {
            
$this->contents['qu_tmc'] = $qu_tmc;
        }

        
$this->contents['rs_tm'] = $this->tm->get_options();
        
$this->contents['rs_tmc'] = $this->tmc->qryTmcJoinTm();

        if ( 
file_exists(dirname(__FILE__).'/bdpbri.php') ) {
            
$this->contents['action'] = 'bdpbri/tmc_insert_update';
            
$this->contents['pbri'] = 1;
        } else {
            
$this->contents['action'] = 'bdcollege/tmc_update';
            
$this->contents['pbri'] = 0;
        }

        
$this->output($this->config->item("rg_folder")."v_addTermConfig"$this->session->flashdata('msg'));
    }

    function 
tmc_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');

        
$data['UsName'] = $this->session->userdata('UsName');

        
$data['rs_tmc'] = $this->tmc->qryTmcJoinTm();

        
$this->load->view($this->config->item("rg_folder")."v_printTermConfig"$data);
    }

    function 
tmc_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('tmcAcY',' ','trim|integer|callback_checkAdY|xss_clean');
        
$this->form_validation->set_rules('tmcTmId',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('tmcFrDate',' ','trim|callback_checkTmcFrDate[tmcToDate]|xss_clean');
        
$this->form_validation->set_rules('tmcToDate',' ','trim|callback_checkTmcToDate[tmcFrDate]|xss_clean');

        if (
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
            
$this->tmc->db->trans_begin();

            
$tmcAcY $this->input->post('tmcAcY');
            
$tmcTmId $this->input->post('tmcTmId');
            
$tmcFrDate splitDateForm2($this->input->post('tmcFrDate'), "-");
            
$tmcToDate splitDateForm2($this->input->post('tmcToDate'), "-");
            
            
$this->tmc->tmcAcY $tmcAcY;
            
$this->tmc->tmcTmId $tmcTmId;
            
$qu_tmc $this->tmc->get_by_key();
            if (
$qu_tmc->num_rows()) {
                
$date_tmc $this->tmc->qryBetWeenDateNotAcYTmId($tmcAcY$tmcTmId$tmcFrDate,$tmcToDate);
                if (!
$date_tmc->num_rows()) {
                    
$this->tmc->get_by_key(TRUE);
                    if (
class_exists('Ver_query')) {
                        
Ver_query::setOldVal($this->tmc$this->config->item('rg_dbname').'.rg_TermConfig');
                    }

                    
$this->tmc->tmcFrDate $tmcFrDate;
                    
$this->tmc->tmcToDate $tmcToDate;
                    
$this->tmc->update();
                    if (
class_exists('Ver_query')) {
                        
Ver_query::saveQuery($this->tmc$this->tmc->db->last_query());
                    }

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if (
$this->tmc->db->trans_status() === false) {
                
$this->tmc->db->trans_rollback();
            } else {
                
$this->tmc->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);
            
redirect($this->config->item("rg_folder")."bdcollege/tmc_input");
        } else {
            
$this->tmc_input();
        }
    }

    function 
checkTmcFrDate($str$field) {
        
$start_date splitDateForm2($str); 
        
$end_date splitDateForm2($this->input->post($field));
        
$tmcAcY $this->input->post('tmcAcY');
        
$tmcTmId $this->input->post('tmcTmId');

        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');

        
$date_tmc $this->tmc->qryBetWeenDateNotAcYTmId($tmcAcY$tmcTmId$start_date,$end_date);
        if(!
$date_tmc->num_rows()) {
            if (
$start_date $end_date) { 
                
$this->form_validation->set_message('checkTmcFrDate''%s ต้องน้อยกว่าหรือเท่ากับ วันที่สิ้นสุด');
                return 
false;
            } else { 
                return 
true;
            }
        } else {
            if(
$tmcAcY!="" && $tmcTmId!="") {
                
$this->form_validation->set_message('checkTmcFrDate''%s คาบเกี่ยวกับปี/ภาคการศึกษาอื่น');
                return 
false;
            } else {
                return 
true;
            }
        }
    }

    function 
checkTmcToDate($str$field) {
        
$end_date splitDateForm2($str); 
        
$start_date splitDateForm2($this->input->post($field));
        
$tmcAcY $this->input->post('tmcAcY');
        
$tmcTmId $this->input->post('tmcTmId');

        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');

        
$date_tmc $this->tmc->qryBetWeenDateNotAcYTmId($tmcAcY$tmcTmId$start_date,$end_date);
        if(!
$date_tmc->num_rows()) {
            return 
true;
        } else {
            if(
$tmcAcY!="" && $tmcTmId!="") {
                
$this->form_validation->set_message('checkTmcToDate''%s คาบเกี่ยวกับปี/ภาคการศึกษาอื่น');
                return 
false;
            } else {
                return 
true;
            }
        }
    }
    
// ##### end tmc

    // ##### start bd
    
function bd_input() {
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','bd');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_config','cfg');

        
$plHwId $this->input->post('plHwId');

        
$this->bd->plHwId $plHwId;
        
$qu_bd $this->bd->get_by_key();
        if (
$qu_bd->num_rows()) {
            
$this->contents['qu_bd'] = $qu_bd;
        }

        
$this->cfg->get_by_key(TRUE);
        
$this->contents['cfgCheckSP'] = $this->cfg->cfgCheckSP;
        
$this->contents['rs_bd'] = $this->bd->getBd();

        
$this->output($this->config->item("rg_folder")."v_addBuilding"$this->session->flashdata('msg'));
    }

    function 
bd_print() {
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','bd');

        
$this->contents['UsName'] = $this->session->userdata('UsName');

        
$this->contents['rs_bd'] = $this->bd->getBd();

        
$this->output_detail($this->config->item("rg_folder")."v_printBuilding");
    }

    function 
bd_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('plHwId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('plIsDom',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('hwName',' ','trim|required|xss_clean');

        if (
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','bd');

            
$plHwId $this->input->post('plHwId');
            
$hwName $this->input->post('hwName');
            
$plIsDom $this->input->post('plIsDom');

            
$this->bd->plHwId $plHwId;
            
$qu_bd $this->bd->get_by_key();

            if (
$qu_bd->num_rows()) {
                
$rs_bd $this->bd->qryPlByNameAndNotId($hwName$plHwId);
                if (!
$rs_bd->num_rows()) {
                    
$this->bd->get_by_key(TRUE);

                    
$this->bd->hwName $hwName;
                    
$this->bd->plIsDom $plIsDom;
                    
$this->bd->update();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            } else {
                
$rs_bd $this->bd->qryPlByName($hwName);
                if (!
$rs_bd->num_rows()) {
                    
$this->bd->plHwId $this->bd->getNextId();
                    
$this->bd->plRmNo '';
                    
$this->bd->plFloor '';
                    
$this->bd->plBuilding NULL;
                    
$this->bd->plRtId NULL;
                    
$this->bd->plIsRoom 'N';
                    
$this->bd->plIsDom $plIsDom;
                    
$this->bd->plNumFloor '';
                    
$this->bd->plCapacity '';
                    
$this->bd->hwName $hwName;
                    
$this->bd->insert();
                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if (
$this->bd->db->trans_status() === false) {
                
$this->bd->db->trans_rollback();
            } else {
                
$this->bd->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);
            
redirect($this->config->item("rg_folder")."bdcollege/bd_input");
        } else {
            
$this->bd_input();
        }
    }

    function 
bd_delete() {
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','bd');

        
$plHwId $this->input->post('plHwId');

        
$flgmsg 41;
        
$rs_bd $this->bd->qryPlByBuilding($plHwId);
        if (
$rs_bd->num_rows() == 0) {
            
$this->bd->plHwId $plHwId;
            
$this->bd->delete();

            if (
$this->bd->db->trans_status() === false) {
                
$this->bd->db->trans_rollback();
                
$flgmsg 41;
            } else {
                
$this->bd->db->trans_commit();
                
$flgmsg 30;
            }
        }

        
$this->session->set_flashdata('msg'$flgmsg);
        
redirect($this->config->item("rg_folder")."bdcollege/bd_input");
    }
    
// ##### end bd

    // ##### start rm
    
function rm_input() {
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','rm');
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','bd');
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_roomtype','rt');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_config','cfg');

        
$plHwId $this->input->post('plHwId');

        
$this->rm->plHwId $plHwId;
        
$qu_rm $this->rm->get_by_key();
        if (
$qu_rm->num_rows()) {
            
$this->contents['qu_rm'] = $qu_rm;

            
$this->bd->plHwId $qu_rm->row()->plBuilding;
            
$this->contents['qu_bd'] = $this->bd->get_by_key();
        }

        
$ord_rs_rt = array('rtName'    => '');
        
$this->contents['rs_rt'] = $this->rt->get_optionsRt('',$ord_rs_rt);
        
$this->contents['rs_rm'] = $this->rm->getRm();
        
$this->contents['rs_bd'] = $this->bd->get_optionsBd();

        
$this->cfg->get_by_key(TRUE);
        
$this->contents['cfgCheckSP'] = $this->cfg->cfgCheckSP;

        
$this->output($this->config->item("rg_folder")."v_addRoom"$this->session->flashdata('msg'));
    }

    function 
rm_print() {
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','rm');

        
$this->contents['UsName'] = $this->session->userdata('UsName');

        
$this->contents['rs_rm'] = $this->rm->getRm();

        
$this->output_detail($this->config->item("rg_folder")."v_printRoom");
    }

    function 
rm_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('plHwId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('plRmNo',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('plBuilding',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('plCapacity',' ','trim|required|is_natural_no_zero|xss_clean');
        
$this->form_validation->set_rules('plRtId',' ','trim|required|xss_clean');

        if (
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','rm');

            
$plHwId $this->input->post('plHwId');
            
$plRmNo $this->input->post('plRmNo');
            
$plCapacity $this->input->post('plCapacity');
            
$plBuilding $this->input->post('plBuilding');
            
$plRtId $this->input->post('plRtId');

            
$this->rm->plHwId $plHwId;
            
$qu_rm $this->rm->get_by_key();

            
// หาอาคารที่มีห้องดังกล่าว ว่าป็นหอพักหรือป่าว
            
$building $this->rm->qryPlByPlHwId($plBuilding);
            if(
$building->num_rows()) {
                
$plIsDom $building->row()->plIsDom;
            }
            
// จบหาอาคารที่มีห้องดังกล่าว

            
if($qu_rm->num_rows()) {
                
$rs_rm $this->rm->qryPlByNameAndBuildingAndNotId($plRmNo$plBuilding$plHwId);

                
//$rs_rm = $this->rm->qryPlByNameAndNotId($plRmNo, $plHwId);
                
if (!$rs_rm->num_rows()) {
                    
$this->rm->get_by_key(TRUE);

                    
$this->rm->plRmNo $plRmNo;
                    
$this->rm->plBuilding $plBuilding;
                    
$this->rm->plCapacity $plCapacity;
                    
$this->rm->hwName $plRmNo;
                    
$this->rm->plIsDom = (isset($plIsDom)) ? $plIsDom "N";
                    
$this->rm->plRtId $plRtId;
                    
$this->rm->update();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            } else {
                
$rs_rm $this->rm->qryPlByNameAndBuilding($plRmNo$plBuilding);
                
//$rs_rm = $this->rm->qryPlByName($plRmNo);
                
if (!$rs_rm->num_rows()) {
                    
$this->rm->plHwId $this->rm->getNextId();
                    
$this->rm->plRmNo $plRmNo;
                    
$this->rm->plFloor '';
                    
$this->rm->plBuilding $plBuilding;
                    
$this->rm->plRtId $plRtId;
                    
$this->rm->plIsRoom 'Y';
                    
$this->rm->plIsDom = (isset($plIsDom)) ? $plIsDom "N";
                    
$this->rm->plNumFloor '';
                    
$this->rm->plCapacity $plCapacity;
                    
$this->rm->hwName $plRmNo;
                    
$this->rm->insert();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if (
$this->rm->db->trans_status() === false) {
                
$this->rm->db->trans_rollback();
            } else {
                
$this->rm->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);
            
redirect($this->config->item("rg_folder")."bdcollege/rm_input");
        } else {
            
$this->rm_input();
        }
    }

    function 
rm_delete() {
        
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','rm');

        
$plHwId $this->input->post('plHwId');

        
$this->rm->plHwId $plHwId;
        
$this->rm->delete();

        if (
$this->rm->db->trans_status() === false) {
            
$this->rm->db->trans_rollback();
            
$flgmsg 41;
        } else {
            
$this->rm->db->trans_commit();
            
$flgmsg 30;
        }

        
$this->session->set_flashdata('msg'$flgmsg);
        
redirect($this->config->item("rg_folder")."bdcollege/rm_input");
    }
    
// ##### end rm

    // ##### start dm
//    function dm_input() {
//        $this->load->model($this->config->item("rg_folder").'mo_rg_domitory','dm');
//
//        $dmId = $this->input->post('dmId');
//
//        $this->dm->dmId = $dmId;
//        $this->contents['qu_dm'] = $this->dm->get_by_key();
//
//        $ord_rs_dm = array('dmName' => '');
//        $this->contents['rs_dm'] = $this->dm->qryDm('',$ord_rs_dm,'');
//
//        $this->output($this->config->item("rg_folder")."v_addDomitory", $this->session->flashdata('msg'));
//    }
//
//    function dm_print() {
//        $this->load->model($this->config->item("rg_folder").'mo_rg_domitory','dm');
//
//        $ord_rs_dm = array('dmName'    => '');
//        $data['rs_dm'] = $this->dm->qryDm('',$ord_rs_dm,'');
//
//        $data['UsName'] = $this->session->userdata('UsName');
//
//        $this->load->view($this->config->item("rg_folder")."v_printDomitory", $data);
//    }
//
//    function dm_insert_update() {
//        $this->load->library('form_validation');
//        $this->form_validation->set_error_delimiters('<div class="error">','</div>');
//        $this->form_validation->set_rules('dmId',' ','trim|xss_clean');
//        $this->form_validation->set_rules('dmName',' ','trim|required|xss_clean');
//
//        if($this->form_validation->run() == true) {
//            $flgmsg = 0;
//            $this->db->trans_begin();
//            $this->load->model($this->config->item("rg_folder").'mo_rg_domitory','dm');
//
//            $dmId = $this->input->post('dmId');
//            $dmName = $this->input->post('dmName');
//
//            $this->dm->dmId = $dmId;
//            $qu_dm = $this->dm->get_by_key();
//            $con_rs_dm = array('dmName'    => $dmName);
//            if($qu_dm->num_rows()) {
//                $rs_dm = $this->dm->qryDmNotId($con_rs_dm,$dmId);
//                if(!$rs_dm->num_rows()) {
//                    $this->dm->get_by_key(TRUE);
//                    $this->dm->dmName = $dmName;
//                    $this->dm->update();
//                    $flgmsg = 1;
//                }
//            } else {
//                $rs_dm = $this->dm->qryDm($con_rs_dm);
//                if(!$rs_dm->num_rows()) {
//                    $this->dm->dmId = '';
//                    $this->dm->dmName = $dmName;
//                    $this->dm->insert();
//                    $flgmsg = 1;
//                }
//            }
//
//            $this->session->set_flashdata('msg', 2);
//
//            if($this->db->trans_status() === false) {
//                $this->db->trans_rollback();
//                if($flgmsg)
//                    $this->session->set_flashdata('msg', 2);
//                } else {
//                $this->db->trans_commit();
//                if($flgmsg)
//                    $this->session->set_flashdata('msg', 1);
//            }
//            
//            redirect($this->config->item("rg_folder")."bdcollege/dm_input");
//        }
//        else
//            $this->dm_input();
//    }
//    function dm_delete() {
//        $this->load->model($this->config->item("rg_folder").'mo_rg_domitory','dm');
//
//        $dmId = $this->input->post('dmId');
//        $this->dm->dmId = $dmId;
//        $this->dm->delete();
//
//        if($this->db->trans_status() === false) {
//            $this->db->trans_rollback();
//            $this->session->set_flashdata('msg', 4);
//        } else {
//            $this->db->trans_commit();
//            $this->session->set_flashdata('msg', 3);
//        }
//        
//        redirect($this->config->item("rg_folder")."bdcollege/dm_input");
//    }
    // ##### end dm

    // ##### start org
    
function org_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_organization','org');

        
$orgId $this->input->post('orgId');

        
$this->org->orgId $orgId;
        
$qu_org $this->org->get_by_key();
        if (
$qu_org->num_rows()) {
            
$this->contents['qu_org'] = $qu_org;
        }

        
$ord_rs_org = array('orgName' => 'ASC');
        
$this->contents['rs_org'] = $this->org->qryOrg(''$ord_rs_org);

        
$this->output($this->config->item("rg_folder")."v_addOrganization"$this->session->flashdata('msg'));
    }

    function 
org_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_organization','org');

        
$this->contents['UsName'] = $this->session->userdata('UsName');

        
$ord_rs_org = array('orgName'    => 'ASC');
        
$this->contents['rs_org'] = $this->org->qryOrg(''$ord_rs_org);

        
$this->output_detail($this->config->item("rg_folder")."v_printOrganization");
    }

    function 
org_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('orgId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('orgName',' ','trim|required|xss_clean');

        if (
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("rg_folder").'mo_rg_organization','org');

            
$orgId $this->input->post('orgId');
            
$orgName $this->input->post('orgName');

            
$this->org->orgId $orgId;
            
$qu_org $this->org->get_by_key();

            
$con_rs_org = array('orgName'    => $orgName);
            if (
$qu_org->num_rows()) {
                
$rs_org $this->org->qryOrgNotId($con_rs_org$orgId);
                if(!
$rs_org->num_rows()) {
                    
$this->org->get_by_key(TRUE);

                    
$this->org->orgName $orgName;
                    
$this->org->update();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            } else {
                
$rs_org $this->org->qryOrg($con_rs_org);
                if (!
$rs_org->num_rows()) {
                    
$ths->org->orgId '';
                    
$this->org->orgName $orgName;
                    
$this->org->insert();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if (
$this->org->db->trans_status() === false) {
                
$this->org->db->trans_rollback();
            } else {
                
$this->org->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);
            
redirect($this->config->item("rg_folder")."bdcollege/org_input");
        } else {
            
$this->org_input();
        }
    }

    function 
org_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_organization','org');

        
$orgId $this->input->post('orgId');

        
$this->org->orgId $orgId;
        
$this->org->delete();

        if (
$this->org->db->trans_status() === false) {
            
$this->org->db->trans_rollback();
            
$this->session->set_flashdata('msg'41);
        } else {
            
$this->org->db->trans_commit();
            
$this->session->set_flashdata('msg'30);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/org_input");
    }
    
// ##### end org

    // ##### start dpt
    
function dpt_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_department','dpt');

        
$dptId $this->input->post('dptId');

        
$this->dpt->dptId $dptId;
        
$qu_dpt $this->dpt->get_by_key();
        if (
$qu_dpt->num_rows()) {
            
$this->contents['qu_dpt'] = $qu_dpt;
        }

        
$ord_rs_dpt = array('dptName'    => 'ASC');
        
$this->contents['rs_dpt'] = $this->dpt->qryDpt(''$ord_rs_dpt);

        
$this->output($this->config->item("rg_folder")."v_addDepartment"$this->session->flashdata('msg'));
    }

    function 
dpt_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_department','dpt');

        
$this->contents['UsName'] = $this->session->userdata('UsName');

        
$ord_rs_dpt = array('dptName'    => 'ASC');
        
$this->contents['rs_dpt'] = $this->dpt->qryDpt(''$ord_rs_dpt);

        
$this->output_detail($this->config->item("rg_folder")."v_printDepartment");
    }

    function 
dpt_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('dptId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('dptName',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('dptStatus',' ','trim|xss_clean');

        if(
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();

            
$this->load->model($this->config->item("rg_folder").'mo_rg_department','dpt');

            
$dptId $this->input->post('dptId');
            
$dptName $this->input->post('dptName');
            
$dptStatus = ($this->input->post('dptStatus') == 'N') ? 'N' 'Y';

            
$this->dpt->dptId $dptId;
            
$qu_dpt $this->dpt->get_by_key();

            
$con_rs_dpt = array('dptName'    => $dptName);
            if (
$qu_dpt->num_rows()) {
                
$rs_dpt $this->dpt->qryDptNotId($con_rs_dpt,$dptId);
                if(!
$rs_dpt->num_rows()) {
                    
$this->dpt->get_by_key(TRUE);

                    
$this->dpt->dptName $dptName;
                    
$this->dpt->dptStatus $dptStatus;
                    
$this->dpt->update();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            } else {
                
$rs_dpt $this->dpt->qryDpt($con_rs_dpt);
                if (!
$rs_dpt->num_rows()) {
                    
$this->dpt->dptId '';
                    
$this->dpt->dptName $dptName;
                    
$this->dpt->dptStatus $dptStatus;
                    
$this->dpt->insert();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if (
$this->dpt->db->trans_status() === false) {
                
$this->dpt->db->trans_rollback();
            } else {
                
$this->dpt->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);
            
redirect($this->config->item("rg_folder")."bdcollege/dpt_input");
        } else {
            
$this->dpt_input();
        }
    }

    function 
dpt_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_department','dpt');

        
$dptId $this->input->post('dptId');

        
$this->dpt->dptId $dptId;
        
$this->dpt->delete();

        if (
$this->dpt->db->trans_status() === false) {
            
$this->dpt->db->trans_rollback();
            
$this->session->set_flashdata('msg'41);
        } else {
            
$this->dpt->db->trans_commit();
            
$this->session->set_flashdata('msg'30);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/dpt_input");
    }
    
// ##### end dpt

    // ##### start cfg
    
function cfg_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_config','cfg');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_acadconfig','ac');

        
$this->contents['qu_cfg'] = $this->cfg->qryCfg("","","","");
        
$this->contents['qu_ac'] = $this->ac->qryAcPrsIdRegistrarJoinPrs();

        
$this->output($this->config->item("rg_folder")."v_config");
    }
    function 
cfg_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">''</div>');
        
$this->form_validation->set_rules('cfgSiteName''ชื่อระบบ''');
        
$this->form_validation->set_rules('clgCode''รหัสวิทยาลัย''trim|required|xss_clean');
        
$this->form_validation->set_rules('clgName''ชื่อวิทยาลัย (ไทย)''trim|required|xss_clean');
        
$this->form_validation->set_rules('clgNameE''ชื่อวิทยาลัย (อังกฤษ)''trim|required|xss_clean');
        
$this->form_validation->set_rules('clgAddr''ที่อยู่วิทยาลัย''trim|required|xss_clean');
        
$this->form_validation->set_rules('clgPhoneNo''หมายเลขโทรศัพท์วิทยาลัย''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgClgBankName''cfgClgBankName''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgClgBankAccountName''cfgClgBankAccountName''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgClgBankNo''cfgClgBankNo''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgClgBankFee''cfgClgBankFee''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgInstitute''ชื่อสถาบันที่สังกัด (ไทย)''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgInstituteE''ชื่อสถาบันที่สังกัด (อังกฤษ)''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgMinistry''ชื่อกระทรวงที่สังกัด (ไทย)''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgMinistryE''ชื่อกระทรวงที่สังกัด (อังกฤษ)''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgBgClTrAndTd''สีพื้นหลังของแถวและคอลัมน์หลัก''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgBgClSwapTr''สีพื้นหลังของแถวที่แสดงข้อมูล''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgFnClHeadTb''สีของตัวอักษรหัวตารางและคอลัมน์''trim|required|xss_clean');
        
$this->form_validation->set_rules('cfgFnClErrSpec''สีของตัวอักษรที่แสดงข้อผิดพลาด''trim|required|xss_clean');

        
$this->form_validation->set_rules('prsIdRC''ผู้อำนวยการของวิทยาลัย''trim|required|xss_clean');
        
$this->form_validation->set_rules('prsIdRC2''นายทะเบียนของวิทยาลัย''trim|required|xss_clean');
        
$this->form_validation->set_rules('acNoLockT''สถานะการส่งเกรดของอาจารย์''trim|xss_clean');
        
$this->form_validation->set_rules('acCardExpiryDay''วันที่หมดอายุบัตรของทุกชั้นปี''trim|required|xss_clean');
        
$this->form_validation->set_rules('acCardExpiryMonth''เดือนที่หมดอายุบัตรของทุกชั้นปี''trim|required|xss_clean');
        
$this->form_validation->set_rules('acForceAssess''สถานะของการประเมิน''trim|xss_clean');

        
$config['upload_path'] = $this->config->item('rg_upload_logo');
        
$this->load->library('upload');
        foreach(
$_FILES as $key => $value) {
            if(
$_FILES['uploadSiteBanner']['name']!="" && $key=="uploadSiteBanner") {
                if(
file_exists($this->config->item('rg_upload_picture').$this->config->item('SiteBanner').".jpg")) {
                    
rename ($this->config->item('rg_upload_logo').$this->config->item('SiteBanner').".jpg"$this->config->item('rg_upload_logo').$this->config->item('SiteBanner')."_old.jpg");
                }

                
$config['allowed_types'] = 'jpg';
                
$config['max_width'] = $this->config->item('rg_allowed_widthCfg');
                
$config['max_height'] = $this->config->item('rg_allowed_heightCfg');
                
$config['max_size']    = $this->config->item('rg_upload_size');
                
$config['file_name'] = $this->config->item('SiteBanner');
                
$this->upload->initialize($config);
                if (
$this->upload->do_upload("uploadSiteBanner")){
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('SiteBanner')."_old.jpg")) {
                        
unlink($this->config->item('rg_upload_logo').$this->config->item('SiteBanner')."_old.jpg");
                    }

                    
$data = array('upload_data' => $this->upload->data());
                    
$pathBanner $data['upload_data']['file_name'];
                } else {
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('SiteBanner')."_old.jpg")) {
                        
rename ($this->config->item('rg_upload_logo').$this->config->item('SiteBanner')."_old.jpg"$this->config->item('rg_upload_logo').$this->config->item('SiteBanner').".jpg");
                    }

                    
$error = array('error' => $this->upload->display_errors());
                    
$this->form_validation->set_rules('uploadSiteBanner'trim($error['error']), 'callback_checkupload');
                }
            }

            if(
$_FILES['uploadSiteLogo']['name']!="" && $key=="uploadSiteLogo") {
                if(
file_exists($this->config->item('rg_upload_picture').$this->config->item('SiteLogo').".jpg")) {
                    
rename ($this->config->item('rg_upload_logo').$this->config->item('SiteLogo').".jpg"$this->config->item('rg_upload_logo').$this->config->item('SiteLogo')."_old.jpg");
                }

                
$config['allowed_types'] = 'jpg';
                
$config['max_width'] = $this->config->item('rg_allowed_widthLg');
                
$config['max_height'] = $this->config->item('rg_allowed_heightLg');
                
$config['max_size']    = $this->config->item('rg_upload_size');
                
$config['file_name'] = $this->config->item('SiteLogo');
                
$this->upload->initialize($config);
                if (
$this->upload->do_upload("uploadSiteLogo")){
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('SiteLogo')."_old.jpg")) {
                        
unlink($this->config->item('rg_upload_logo').$this->config->item('SiteLogo')."_old.jpg");
                    }

                    
$data = array('upload_data' => $this->upload->data());
                    
$pathLogo $data['upload_data']['file_name'];
                } else {
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('SiteLogo')."_old.jpg")) {
                        
rename ($this->config->item('rg_upload_logo').$this->config->item('SiteLogo')."_old.jpg"$this->config->item('rg_upload_logo').$this->config->item('SiteLogo').".jpg");
                    }

                    
$error = array('error' => $this->upload->display_errors());
                    
$this->form_validation->set_rules('uploadSiteLogo'trim($error['error']), 'callback_checkupload');
                }
            }


            if(
$_FILES['uploadInstituteLogo']['name']!="" && $key=="uploadInstituteLogo") {
                if(
file_exists($this->config->item('rg_upload_picture').$this->config->item('logo_institute').".jpg")) {
                    
rename ($this->config->item('rg_upload_logo').$this->config->item('logo_institute').".jpg"$this->config->item('rg_upload_logo').$this->config->item('logo_institute')."_old.jpg");
                }

                
$config['allowed_types'] = 'jpg';
                
$config['max_width'] = $this->config->item('rg_allowed_widthIn');
                
$config['max_height'] = $this->config->item('rg_allowed_heightIn');
                
$config['max_size']    = $this->config->item('rg_upload_size');
                
$config['file_name'] = $this->config->item('logo_institute');
                
$this->upload->initialize($config);
                if (
$this->upload->do_upload("uploadInstituteLogo")){
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('logo_institute')."_old.jpg")) {
                        
unlink($this->config->item('rg_upload_logo').$this->config->item('logo_institute')."_old.jpg");
                    }

                    
$data = array('upload_data' => $this->upload->data());
                    
$pathIn $data['upload_data']['file_name'];
                } else {
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('logo_institute')."_old.jpg")) {
                        
rename ($this->config->item('rg_upload_logo').$this->config->item('logo_institute')."_old.jpg"$this->config->item('rg_upload_logo').$this->config->item('logo_institute').".jpg");
                    }

                    
$error = array('error' => $this->upload->display_errors());
                    
$this->form_validation->set_rules('uploadInstituteLogo'trim($error['error']), 'callback_checkupload');
                }
            }

            if(
$_FILES['uploadCollegeBankLogo']['name']!="" && $key=="uploadCollegeBankLogo") {
                if(
file_exists($this->config->item('rg_upload_picture').$this->config->item('logo_bank').".jpg")) {
                    
rename ($this->config->item('rg_upload_logo').$this->config->item('logo_bank').".jpg"$this->config->item('rg_upload_logo').$this->config->item('logo_bank')."_old.jpg");
                }

                
$config['allowed_types'] = 'jpg';
                
$config['max_width'] = $this->config->item('rg_allowed_widthBank');
                
$config['max_height'] = $this->config->item('rg_allowed_heightBank');
                
$config['max_size']    = $this->config->item('rg_upload_size');
                
$config['file_name'] = $this->config->item('logo_bank');
                
$this->upload->initialize($config);
                if (
$this->upload->do_upload("uploadCollegeBankLogo")){
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('logo_bank')."_old.jpg")) {
                        
unlink($this->config->item('rg_upload_logo').$this->config->item('logo_bank')."_old.jpg");
                    }

                    
$data = array('upload_data' => $this->upload->data());
                    
$pathBank $data['upload_data']['file_name'];
                } else {
                    if(
file_exists($this->config->item('rg_upload_logo').$this->config->item('logo_bank')."_old.jpg")) {
                        
rename ($this->config->item('rg_upload_logo').$this->config->item('logo_bank')."_old.jpg"$this->config->item('rg_upload_logo').$this->config->item('logo_bank').".jpg");
                    }

                    
$error = array('error' => $this->upload->display_errors());
                    
$this->form_validation->set_rules('uploadCollegeBankLogo'trim($error['error']), 'callback_checkupload');
                }
            }
        }

        if (
$this->form_validation->run() == FALSE) {
            
$this->cfg_input();
        } else {
            
$this->db->trans_begin();
    
            
$this->load->model($this->config->item("rg_folder").'mo_rg_Config','cfg');
            
$cfg $this->cfg;

            
$cfg->get_by_key(TRUE);
            
$cfg->cfgSiteBanner = (isset($pathBanner)) ? $pathBanner $cfg->cfgSiteBanner;
            
$cfg->cfgClgLogo = (isset($pathLogo)) ? $pathLogo $cfg->cfgClgLogo;
            
$cfg->cfgInstituteLogo = (isset($pathIn)) ? $pathIn $cfg->cfgInstituteLogo;
            
$cfg->cfgClgBankLogo = (isset($pathBank)) ? $pathBank $cfg->cfgClgBankLogo;
            
$cfg->cfgSiteName trim($this->input->post('cfgSiteName'));
            
$cfg->cfgClgCode trim($this->input->post('clgCode'));
            
$cfg->cfgClgName trim($this->input->post('clgName'));
            
$cfg->cfgClgNameE trim($this->input->post('clgNameE'));
            
$cfg->cfgClgAddr trim($this->input->post('clgAddr'));
            
$cfg->cfgClgPhoneNo trim($this->input->post('clgPhoneNo'));
            
$cfg->cfgClgBankName trim($this->input->post('cfgClgBankName'));
            
$cfg->cfgClgBankAccountName trim($this->input->post('cfgClgBankAccountName'));
            
$cfg->cfgClgBankNo trim($this->input->post('cfgClgBankNo'));
            
$cfg->cfgClgBankFee trim($this->input->post('cfgClgBankFee'));
            
$cfg->cfgInstitute trim($this->input->post('cfgInstitute'));
            
$cfg->cfgInstituteE trim($this->input->post('cfgInstituteE'));
            
$cfg->cfgMinistry trim($this->input->post('cfgMinistry'));
            
$cfg->cfgMinistryE trim($this->input->post('cfgMinistryE'));
            
$cfg->cfgBgClTrAndTd trim($this->input->post('cfgBgClTrAndTd'));
            
$cfg->cfgBgClSwapTr trim($this->input->post('cfgBgClSwapTr'));
            
$cfg->cfgFnClHeadTb trim($this->input->post('cfgFnClHeadTb'));
            
$cfg->cfgFnClErrSpec trim($this->input->post('cfgFnClErrSpec'));
            
$cfg->update();    
            
            
$this->load->model($this->config->item("rg_folder").'mo_rg_AcadConfig','ac');
            
$ac $this->ac;

            
$ac->get_by_key(TRUE);
            
$ac->acNoLockT $this->input->post('acNoLockT') ? $this->input->post('acNoLockT') : 'T';
            
$ac->acCardExpiryDay trim($this->input->post('acCardExpiryDay'));
            
$ac->acCardExpiryMonth trim($this->input->post('acCardExpiryMonth'));
            
$ac->acForceAssess trim($this->input->post('acForceAssess'));
            
$ac->acPrsIdTSRegistrar trim($this->input->post('prsIdRC2'));
            
$ac->acPrsIdDirector trim($this->input->post('prsIdRC'));
            
$ac->update();

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
            } else {
                
$this->db->trans_commit();
            }
        
            
redirect($this->config->item("rg_folder")."bdcollege/cfg_input"); 
        }
    }
    
// ##### end cfg

    // ##### start rc
    
function rc_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_receiptconfig','rc');

        
$this->contents['rs_rc'] = $this->rc->qryRc();

        
$this->output($this->config->item("rg_folder")."v_editReceiptConfig"$this->session->flashdata('msg'));
    }
    function 
rc_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('rcWPaper',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcHPaper',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcSpace',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYClgName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXClgName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYDate',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXDay',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXMonth',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXYear',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYStdName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXStdName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYCurName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXCurName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYTerm',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXStdCode',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXAcY',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXTerm',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYItem',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXItem',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXAmt',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYTotal',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYStr',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXStr',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYPrsName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXPrsName',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcYPrsPosition',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcXPrsPosition',' ','trim|integer|xss_clean');
        
$this->form_validation->set_rules('rcPerPage',' ','trim|integer|xss_clean');

        if(
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("rg_folder").'mo_rg_receiptconfig','rc');

            
$this->rc->rcWPaper $this->input->post('rcWPaper');
            
$this->rc->rcHPaper $this->input->post('rcHPaper');
            
$this->rc->rcSpace $this->input->post('rcSpace');
            
$this->rc->rcYClgName $this->input->post('rcYClgName');
            
$this->rc->rcXClgName $this->input->post('rcXClgName');
            
$this->rc->rcYDate $this->input->post('rcYDate');
            
$this->rc->rcXDay $this->input->post('rcXDay');
            
$this->rc->rcXMonth $this->input->post('rcXMonth');
            
$this->rc->rcXYear $this->input->post('rcXYear');
            
$this->rc->rcYStdName $this->input->post('rcYStdName');
            
$this->rc->rcXStdName $this->input->post('rcXStdName');
            
$this->rc->rcYCurName $this->input->post('rcYCurName');
            
$this->rc->rcXCurName $this->input->post('rcXCurName');
            
$this->rc->rcYTerm $this->input->post('rcYTerm');
            
$this->rc->rcXStdCode $this->input->post('rcXStdCode');
            
$this->rc->rcXAcY $this->input->post('rcXAcY');
            
$this->rc->rcXTerm $this->input->post('rcXTerm');
            
$this->rc->rcYItem $this->input->post('rcYItem');
            
$this->rc->rcXItem $this->input->post('rcXItem');
            
$this->rc->rcXAmt $this->input->post('rcXAmt');
            
$this->rc->rcYTotal $this->input->post('rcYTotal');
            
$this->rc->rcYStr $this->input->post('rcYStr');
            
$this->rc->rcXStr $this->input->post('rcXStr');
            
$this->rc->rcYPrsName $this->input->post('rcYPrsName');
            
$this->rc->rcXPrsName $this->input->post('rcXPrsName');
            
$this->rc->rcYPrsPosition $this->input->post('rcYPrsPosition');
            
$this->rc->rcXPrsPosition $this->input->post('rcXPrsPosition');
            
$this->rc->rcPerPage $this->input->post('rcPerPage');
            
$this->rc->update();
            
$flgmsg 1;

            
$this->session->set_flashdata('msg'2);
            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/rc_input");

        } else {
            
$this->rc_input();
        }
    }
    
// ##### end rc

    // ##### start pp
    
function pp_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_personpermission','pp');

        
$curId $this->input->post('curId') ? $this->input->post('curId') : '0';
        
$acY $this->input->post('acY') ? $this->input->post('acY') : $this->session->userdata('acY');
        
$tmId $this->input->post('tm') ? $this->input->post('tm') : $this->session->userdata('tmId');

        
$con_rs_cur = array('curStatus'    => 'Y');
        
$ord_rs_cur = array('curName'    => '');
        
$this->contents['rs_cur'] = $this->cur->get_options_3($con_rs_cur,$ord_rs_cur,'','เรียนรวมหลายหลักสูตร');

        
$this->contents['rs_tm'] = $this->tm->get_options('','','','n');
        
$this->contents['rs_co'] = $this->co->get_optionsGrpCoAcY('n');

        
$this->contents['curId'] = $curId;
        
$this->contents['tmId'] = $tmId;
        
$this->contents['acY'] = $acY;

        
$i 0;
        
$arr = array();
        
$con_rs_prs = array('prsPsId'    => 1);
        
$ord_rs_prs = array('fName'    => '',
                            
'lName'    => '');
        
$rs_prs $this->prs->qryPrsJoinPPC($con_rs_prs,$ord_rs_prs);
        if(
$rs_prs->num_rows()) {
            foreach(
$rs_prs->result() as $row_prs) {
                
$arr[$i]['pp'] = $row_prs;

                
$con_rs_pp = array('ppAcY'        => $acY,
                                   
'ppTmId'        => $tmId,
                                   
'ppPrsId'    => $row_prs->prsId,
                                   
'ppCurId'    => $curId);
                
$qu_pp $this->pp->qryPp($con_rs_pp);
                if(
$qu_pp->num_rows()) {
                    
$arr[$i]['ppTT'] = $qu_pp->row()->ppTT=='Y' 'checked' '';
                    
$arr[$i]['ppWL'] = $qu_pp->row()->ppWL=='Y' 'checked' '';
                } else {
                    
$arr[$i]['ppTT'] = '';
                    
$arr[$i]['ppWL'] = '';
                }

                
$i++;
            }
        }
        
$this->contents['arr'] = $arr;

        
//$this->output($this->config->item("rg_folder")."v_addPersonPermission", $this->session->flashdata('msg'));
        
$this->output($this->config->item("rg_folder")."v_addPersonPermission");
    }
    function 
pp_insert_update() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_personpermission','pp');

        
$acY $this->input->post('acY');
        
$tmId $this->input->post('tmId');
        
$curId $this->input->post('curId');

        
$con_rs_pp = array('ppAcY'        => $acY,
                           
'ppTmId'        => $tmId,
                           
'ppCurId'    => $curId);
        
$rs_pp $this->pp->qryPp($con_rs_pp);

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$rs_pp->num_rows()) {
            foreach(
$rs_pp->result() as $row_pp) {
                
$this->pp->ppPrsId $row_pp->ppPrsId;
                
$this->pp->ppAcY $acY;
                
$this->pp->ppTmId $tmId;
                
$this->pp->ppCurId $curId;
                
$this->pp->delete();
                
$flgmsg 1;
            }
        }

        
$cnt $this->input->post('cnt');
        for(
$i=0$i<$cnt$i++) {
            if(
$this->input->post('ppTT'.$i)=='Y' || $this->input->post('ppWL'.$i)=='Y') {
                
$this->pp->ppPrsId $this->input->post('prsId'.$i);
                
$this->pp->ppTmId $tmId;
                
$this->pp->ppCurId $curId;
                
$this->pp->ppAcY $acY;
                
$this->pp->ppTT $this->input->post('ppTT'.$i)=='Y' 'Y' 'N';
                
$this->pp->ppWL $this->input->post('ppWL'.$i)=='Y' 'Y' 'N';
                
$this->pp->insert();
                
$flgmsg 1;
            }
        }

        
//$this->session->set_flashdata('msg', 2);
        
if($this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            if(
$flgmsg){
                
//$this->session->set_flashdata('msg', 2);
                
}
            } else {
            
$this->db->trans_commit();
            if(
$flgmsg){
                
//$this->session->set_flashdata('msg', 1);
            
}
        }

        
redirect($this->config->item("rg_folder")."bdcollege/pp_input");
    }
    
// ##### end pp

    // ##### start sd
    
function sd_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');

        
$ord_rs_tmc = array('tmcAcY'    => 'DESC');
        
$this->contents['rs_tmc'] = $this->tmc->get_optionsGroupAcY('n',$ord_rs_tmc);
        
$this->contents['rs_tm'] = $this->tm->get_options('','','','n');

        
$acY $this->input->post('acY') ? $this->input->post('acY') : $this->session->userdata('acY');
        
$tmId $this->input->post('tmId') ? $this->input->post('tmId') : $this->session->userdata('tmId');

        
$this->contents['acY'] = $acY;
        
$this->contents['tmId'] = $tmId;


        if(isset(
$this->edit) && $this->edit) {
            
$this->contents['edit'] = 1;
        }
        
$this->sd->sdAcY $acY;
        
$this->sd->sdTmId $tmId;
        
$this->contents['qu_sd'] = $this->sd->get_by_key();
        
        
$this->tmc->tmcAcY $acY;
        
$this->tmc->tmcTmId $tmId;
        
$this->contents['qu_tmc'] = $this->tmc->get_by_key();

        
$this->output($this->config->item("rg_folder")."v_addSchedule"$this->session->flashdata('msg'));
    }
    function 
sd_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');

        
$data['rs_sd'] = $this->sd->qrySdJoinTmc();
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printSchedule"$data);
    }
    function 
checkLimitDate($str) {
        
$frDate splitDateForm2($this->input->post('tmcFrDate'),'-');
        
$toDate splitDateForm2($this->input->post('tmcToDate'),'-');
        
$nstr splitDateForm2($str,'-');

        if(
$nstr >= $frDate && $nstr <= $toDate) {
            return 
true;
        } else {
            
//$this->form_validation->set_message('checkLimitDate','%sต้องอยู่ในช่วงวันเปิด-ปิดภาคการศึกษา สบช');
            
$this->form_validation->set_message('checkLimitDate','วันที่ไม่อยู่ในช่วงที่ สบช. กำหนด');
            return 
false;
        }
    }
    function 
checkBeforeDate($str$field) {
        
$nstr splitDateForm2($str,'-');
        
$nfield splitDateForm2($this->input->post($field),'-');
        
        if(
$nstr $nfield) {
            
//$this->form_validation->set_message('checkBeforeDate','%sต้องไม่เกินวันที่เริ่มต้น');
            
$this->form_validation->set_message('checkBeforeDate','วันที่สิ้นสุดน้อยกว่าวันที่เริ่มต้น');
            return 
false;
        } else {
            return 
true;
        }
    }
    function 
checkAfterDate($str$field) {
        
$nstr splitDateForm2($str,'-');
        
$nfield splitDateForm2($this->input->post($field),'-');

        if(
$nstr $nfield) {
            return 
true;
        } else {
            
$this->form_validation->set_message('checkAfterDate','%sต้องมากกว่าวันที่สิ้นสุดของรายการก่อนหน้า');
            return 
false;
        }
    }
    function 
sd_insert_update_nokk() {
        
$add $this->input->post('add');

        if(
$add) {
            
$this->load->library('form_validation');
            
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
            
$this->form_validation->set_rules('sdSDate','วันเปิดภาคการศึกษา','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdRegSDate','วันที่เริ่มลงทะเบียนเรียน','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdRegEDate','วันที่สิ้นสุดลงทะเบียนเรียน','trim|callback_checkLimitDate|callback_checkBeforeDate[sdRegSDate]|xss_clean');
            
$this->form_validation->set_rules('sdAddWithdrawSDate','วันที่เริ่มเพิ่ม-ถอนรายวิชา','trim|callback_checkLimitDate|callback_checkAfterDate[sdRegEDate]|xss_clean');
            
$this->form_validation->set_rules('sdAddWithdrawEDate','วันที่สิ้นสุด    เพิ่ม-ถอนรายวิชา','trim|callback_checkLimitDate|callback_checkBeforeDate[sdAddWithdrawSDate]|xss_clean');
            
$this->form_validation->set_rules('sdPaySDate','วันที่เริ่มช่วงสอบกลางภาค','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdPayEDate','วันที่สิ้นสุดช่วงสอบกลางภาค','trim|callback_checkLimitDate|callback_checkBeforeDate[sdPaySDate]|xss_clean');
            
$this->form_validation->set_rules('sdMidExamSDate','วันที่เริ่มต้นช่วงสอบกลางภาค','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdMidExamEDate','วันที่สิ้นสุดช่วงสอบกลางภาค','trim|callback_checkLimitDate|callback_checkBeforeDate[sdMidExamSDate]|xss_clean');
            
$this->form_validation->set_rules('sdFinalExamSDate','วันที่เริ่มต้นช่วงสอบปลายภาค','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdFinalExamEDate','วันที่สิ้นสุดช่วงสอบปลายภาค','trim|callback_checkLimitDate|callback_checkBeforeDate[sdFinalExamSDate]|xss_clean');
            
$this->form_validation->set_rules('sdSendGradeEDate','วันที่สิ้นสุดช่วงส่งเกรดนักศึกษา','trim|callback_checkLimitDate|callback_checkBeforeDate[sdFinalExamSDate]|xss_clean');
            
$this->form_validation->set_rules('sdEDate','วันที่เริ่มต้นวันปิดภาคการศึกษา','trim|callback_checkLimitDate|callback_checkBeforeDate[sdSDate]|xss_clean');

            if(
$this->form_validation->run() == true) {
                
$flgmsg 0;
                
$this->db->trans_begin();
                
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');

                
$acY $this->input->post('acY');
                
$tmId $this->input->post('tmId');

                
$this->sd->sdAcY $acY;
                
$this->sd->sdTmId $tmId;
                
$qu_sd $this->sd->get_by_key();

                
$this->sd->sdAcY $acY;
                
$this->sd->sdTmId $tmId;
                
$this->sd->sdSDate splitDateDb2($this->input->post('sdSDate'),'-');
                
$this->sd->sdEDate splitDateDb2($this->input->post('sdEDate'),'-');
                
$this->sd->sdRegSDate splitDateDb2($this->input->post('sdRegSDate','-'));
                
$this->sd->sdRegEDate splitDateDb2($this->input->post('sdRegEDate','-'));
                
$this->sd->sdAddWithdrawSDate splitDateDb2($this->input->post('sdAddWithdrawSDate','-'));
                
$this->sd->sdAddWithdrawEDate splitDateDb2($this->input->post('sdAddWithdrawEDate','-'));
                
$this->sd->sdPaySDate splitDateDb2($this->input->post('sdPaySDate','-'));
                
$this->sd->sdPayEDate splitDateDb2($this->input->post('sdPayEDate','-'));
                
$this->sd->sdMidExamSDate splitDateDb2($this->input->post('sdMidExamSDate','-'));
                
$this->sd->sdMidExamEDate splitDateDb2($this->input->post('sdMidExamEDate','-'));
                
$this->sd->sdFinalExamSDate splitDateDb2($this->input->post('sdFinalExamSDate','-'));
                
$this->sd->sdFinalExamEDate splitDateDb2($this->input->post('sdFinalExamEDate','-'));
                
$this->sd->sdSendGradeEDate splitDateDb2($this->input->post('sdSendGradeEDate','-'));

                if(!
$qu_sd->num_rows()) {
                    
$this->sd->insert();
                    
$flgmsg 1;
                } else {
                    
$this->sd->update();
                    
$flgmsg 1;
                }

                
$this->session->set_flashdata('msg'2);
                if(
$this->db->trans_status() === false) {
                    
$this->db->trans_rollback();
                    if(
$flgmsg)
                        
$this->session->set_flashdata('msg'2);
                    } else {
                    
$this->db->trans_commit();
                    if(
$flgmsg)
                        
$this->session->set_flashdata('msg'1);
                }

                
redirect($this->config->item("rg_folder")."bdcollege/sd_input");
            } else {
                
$this->edit 1;
                
$this->sd_input();
            }
        } else {
            
$this->edit 1;
            
$this->sd_input();
        }
    }

    
// edit function for kk college
    
function sd_insert_update() {
        
$add $this->input->post('add');

        if(
$add) {
            
$this->load->library('form_validation');
            
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
            
$this->form_validation->set_rules('sdSDate','วันเปิดภาคการศึกษา','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdRegSDate','วันที่เริ่มลงทะเบียนเรียน','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdRegEDate','วันที่สิ้นสุดลงทะเบียนเรียน','trim|callback_checkLimitDate|callback_checkBeforeDate[sdRegSDate]|xss_clean');
            
$this->form_validation->set_rules('sdAddWithdrawSDate','วันที่เริ่มเพิ่ม-ถอนรายวิชา','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdAddWithdrawEDate','วันที่สิ้นสุด    เพิ่ม-ถอนรายวิชา','trim|callback_checkLimitDate|callback_checkBeforeDate[sdAddWithdrawSDate]|xss_clean');
            
$this->form_validation->set_rules('sdPaySDate','วันที่เริ่มช่วงสอบกลางภาค','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdPayEDate','วันที่สิ้นสุดช่วงสอบกลางภาค','trim|callback_checkLimitDate|callback_checkBeforeDate[sdPaySDate]|xss_clean');
            
$this->form_validation->set_rules('sdMidExamSDate','วันที่เริ่มต้นช่วงสอบกลางภาค','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdMidExamEDate','วันที่สิ้นสุดช่วงสอบกลางภาค','trim|callback_checkLimitDate|callback_checkBeforeDate[sdMidExamSDate]|xss_clean');
            
$this->form_validation->set_rules('sdFinalExamSDate','วันที่เริ่มต้นช่วงสอบปลายภาค','trim|callback_checkLimitDate|xss_clean');
            
$this->form_validation->set_rules('sdFinalExamEDate','วันที่สิ้นสุดช่วงสอบปลายภาค','trim|callback_checkLimitDate|callback_checkBeforeDate[sdFinalExamSDate]|xss_clean');
            
$this->form_validation->set_rules('sdSendGradeEDate','วันที่สิ้นสุดช่วงส่งเกรดนักศึกษา','trim|callback_checkLimitDate|callback_checkBeforeDate[sdFinalExamSDate]|xss_clean');
            
$this->form_validation->set_rules('sdEDate','วันที่เริ่มต้นวันปิดภาคการศึกษา','trim|callback_checkLimitDate|callback_checkBeforeDate[sdSDate]|xss_clean');

            if(
$this->form_validation->run() == true) {
                
$flgmsg 0;
                
$this->db->trans_begin();
                
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');

                
$acY $this->input->post('acY');
                
$tmId $this->input->post('tmId');

                
$this->sd->sdAcY $acY;
                
$this->sd->sdTmId $tmId;
                
$qu_sd $this->sd->get_by_key();

                
$this->sd->sdAcY $acY;
                
$this->sd->sdTmId $tmId;
                
$this->sd->sdSDate splitDateDb2($this->input->post('sdSDate'),'-');
                
$this->sd->sdEDate splitDateDb2($this->input->post('sdEDate'),'-');
                
$this->sd->sdRegSDate splitDateDb2($this->input->post('sdRegSDate','-'));
                
$this->sd->sdRegEDate splitDateDb2($this->input->post('sdRegEDate','-'));
                
$this->sd->sdAddWithdrawSDate splitDateDb2($this->input->post('sdAddWithdrawSDate','-'));
                
$this->sd->sdAddWithdrawEDate splitDateDb2($this->input->post('sdAddWithdrawEDate','-'));
                
$this->sd->sdPaySDate splitDateDb2($this->input->post('sdPaySDate','-'));
                
$this->sd->sdPayEDate splitDateDb2($this->input->post('sdPayEDate','-'));
                
$this->sd->sdMidExamSDate splitDateDb2($this->input->post('sdMidExamSDate','-'));
                
$this->sd->sdMidExamEDate splitDateDb2($this->input->post('sdMidExamEDate','-'));
                
$this->sd->sdFinalExamSDate splitDateDb2($this->input->post('sdFinalExamSDate','-'));
                
$this->sd->sdFinalExamEDate splitDateDb2($this->input->post('sdFinalExamEDate','-'));
                
$this->sd->sdSendGradeEDate splitDateDb2($this->input->post('sdSendGradeEDate','-'));

                if(!
$qu_sd->num_rows()) {
                    
$this->sd->insert();
                    
$flgmsg 1;
                } else {
                    
$this->sd->update();
                    
$flgmsg 1;
                }

                
$this->session->set_flashdata('msg'2);
                if(
$this->db->trans_status() === false) {
                    
$this->db->trans_rollback();
                    if(
$flgmsg)
                        
$this->session->set_flashdata('msg'2);
                    } else {
                    
$this->db->trans_commit();
                    if(
$flgmsg)
                        
$this->session->set_flashdata('msg'1);
                }

                
redirect($this->config->item("rg_folder")."bdcollege/sd_input");
            } else {
                
$this->edit 1;
                
$this->sd_input();
            }
        } else {
            
$this->edit 1;
            
$this->sd_input();
        }
    }
    
// ##### end sd

    // ##### start gen
    
function gen_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_generation','gen');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');

        
$genId $this->input->post('genId');
        
$this->gen->genId $genId;
        
$this->contents['qu_gen'] = $this->gen->get_by_key();
        
        
// *********** start check disble
        
$con_qu_gen = array('stdGenId'    => $genId);
        
$grp_qu_gen = array('stdCurId'    => 'stdCurId',
                            
'stdGenId'    => 'stdGenId');
        
$dsb $this->gen->qryGenJoinStd($con_qu_gen,'',$grp_qu_gen);
        
$this->contents['dsb'] = ($dsb->num_rows());
        if(
$this->contents['dsb']==1) {
            
$this->cur->curId $dsb->row()->stdCurId;
            
$this->contents['qu_cur'] = $this->cur->get_by_key();

            
$this->tm->tmId $this->contents['qu_gen']->row()->genTmId;
            
$this->contents['qu_tm'] = $this->tm->get_by_key();
        }
        
// *********** end check disble

        
$ord_rs_gen = array('curName'    => '',
                            
'genAcY'    => '');
        
$this->contents['rs_gen'] = $this->gen->qryGenJoinCurTm('',$ord_rs_gen,'');

        
$con_rs_cur = array('curStatus' => 'Y');
        
$ord_rs_cur = array('curName'    => '');
        
$this->contents['rs_cur'] = $this->cur->get_options($con_rs_cur,$ord_rs_cur,'','y');
        
$this->contents['rs_tm'] = $this->tm->get_options('','','','y');
        
$this->contents['tmId'] = $this->session->userdata('tmId');

        
$this->output($this->config->item("rg_folder")."v_addGeneration"$this->session->flashdata('msg'));
    }
    function 
gen_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_generation','gen');

        
$ord_rs_gen = array('curName'    => '',
                            
'genAcY'    => '');
        
$data['rs_gen'] = $this->gen->qryGenJoinCurTm('',$ord_rs_gen,'');
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printGeneration"$data);
    }
    function 
gen_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('genId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('genAcY',' ','trim|integer|callback_checkAdY|xss_clean');
        
$this->form_validation->set_rules('genNo',' ','trim|integer|is_natural_no_zero|required|xss_clean');
        
$this->form_validation->set_rules('genCurId',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('tmId',' ','trim|required|xss_clean');

        if(
$this->form_validation->run() == true) {
            
$this->load->model($this->config->item("rg_folder").'mo_rg_generation','gen');

            
$genId $this->input->post('genId');
            
$genAcY $this->input->post('genAcY');
            
$genNo $this->input->post('genNo');
            
$curId $this->input->post('genCurId');
            
$tmId $this->input->post('tmId');

            
$this->gen->genId $genId;
            
$qu_gen $this->gen->get_by_key();

            
$con_rs_gen = array('genNo'        => $genNo,
                                
'genAcY'    => $genAcY,
                                
'genCurId'    => $curId,
                                
'genTmId'    => $tmId);

            
$this->db->trans_begin();
            if(
$qu_gen->num_rows()) {
                
$rs_gen $this->gen->qryGenNotId($con_rs_gen,$genId);
                if(!
$rs_gen->num_rows()) {
                    
$this->gen->get_by_key(TRUE);
                    
$this->gen->genAcY $genAcY;
                    
$this->gen->genCurId $curId;
                    
$this->gen->genTmId $tmId;
                    
$this->gen->genNo $genNo;
                    
$this->gen->update();
                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            } else {
                
$rs_gen $this->gen->qryGen($con_rs_gen,'','');
                if(!
$rs_gen->num_rows()) {
                    
$this->gen->genId '';
                    
$this->gen->genAcY $genAcY;
                    
$this->gen->genCurId $curId;
                    
$this->gen->genTmId $tmId;
                    
$this->gen->genNo $genNo;
                    
$this->gen->insert();
                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if (
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                
$flgmsg 20;
            } else {
                
$this->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);
            
redirect($this->config->item("rg_folder")."bdcollege/gen_input");
        }
        else
            
$this->gen_input();
    }
    function 
gen_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_generation','gen');

        
$genId $this->input->post('genId');
        
$this->db->trans_begin();
        
$this->gen->genId $genId;
        
$this->gen->delete();

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'41);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'30);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/gen_input");
    }
    
// ##### end gen

    // ##### start prd
    
function checkTimeH($str) {
        if(
$str=='') {
            
$this->form_validation->set_message('checkTimeH','กรุณาป้อน%s');
            return 
false;
        } else if(
$str 24) {
            
$this->form_validation->set_message('checkTimeH','%sไม่ถูกต้อง');
            return 
false;
        } else if(
$str 0) {
            
$this->form_validation->set_message('checkTimeH','%sไม่ถูกต้อง');
            return 
false;
        } else {
            return 
true;
        }
    }
    function 
checkTimeM($str) {
        if(
$str=='') {
            
$this->form_validation->set_message('checkTimeM','กรุณาป้อน%s');
            return 
false;
        } else if(
$str 60) {
            
$this->form_validation->set_message('checkTimeM','%sไม่ถูกต้อง');
            return 
false;
        } else if(
$str 0) {
            
$this->form_validation->set_message('checkTimeM','%sไม่ถูกต้อง');
            return 
false;
        } else {
            return 
true;
        }
    }
    function 
checkTime($str$field) {
        
$toTime =  $this->input->post($field);

        if(
$str=='') {
            
$this->form_validation->set_message('checkTime','กรุณาป้อน%s');
            return 
false;
        } else if(
$str 60) {
            
$this->form_validation->set_message('checkTime','%sไม่ถูกต้อง');
            return 
false;
        } else if(
$str 0) {
            
$this->form_validation->set_message('checkTime','%sไม่ถูกต้อง');
            return 
false;
        } else if(
$str $toTime) {
            
$this->form_validation->set_message('checkTime','%s ต้องน้อยกว่าหรือเท่ากับ ชั่วโมงเริ่มต้น');
            return 
false;
        } else {
            return 
true;
        }
    }
    function 
prd_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');

        
$prdId $this->input->post('prdId');
        
$this->prd->prdId $prdId;
        
$this->contents['qu_prd'] = $this->prd->get_by_key();

        
$this->contents['rs_prd'] = $this->prd->qryPrd();

        
$this->output($this->config->item("rg_folder")."v_addPeriod"$this->session->flashdata('msg'));
    }
    function 
prd_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');

        
$data['rs_prd'] = $this->prd->qryPrd();
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printPeriod"$data);
    }
    function 
prd_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">''</div>');
        
$this->form_validation->set_rules('prdId''prdId''trim|xss_clean');
        
$this->form_validation->set_rules('HH1'' ''trim|numeric|callback_checkTimeH|xss_clean');
        
$this->form_validation->set_rules('ii1'' ''trim|numeric|callback_checkTimeM|xss_clean');
        
$this->form_validation->set_rules('HH2'' ''trim|numeric|callback_checkTime[HH1]|xss_clean');
        
$this->form_validation->set_rules('ii2'' ''trim|numeric|callback_checkTimeM|xss_clean');
        
        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$this->form_validation->run() == true) {
            
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');

            
$prdId $this->input->post('prdId');
            
$prdFrTime trim($this->input->post('HH1')).":".trim($this->input->post('ii1'));
            
$prdToTime trim($this->input->post('HH2')).":".trim($this->input->post('ii2'));

            
$this->prd->prdId $prdId;
            
$qu_prd $this->prd->get_by_key();

            
$con_rs_prd = array('prdFrTime'    => $prdFrTime,
                                
'prdToTime'    => $prdToTime);
            if(
$qu_prd->num_rows()) {
                
$rs_prd $this->prd->qryPrdNotId($con_rs_prd,$prdId);
                if(!
$rs_prd->num_rows()) {
                    
$this->prd->get_by_key(TRUE);
                    
$this->prd->prdFrTime $prdFrTime;
                    
$this->prd->prdToTime $prdToTime;
                    
$this->prd->update();
                    
$flgmsg 1;
                }
            } else {
                
$rs_prd $this->prd->qryPrd($con_rs_prd);
                if(!
$rs_prd->num_rows()) {
                    
$this->prd->prdId '';
                    
$this->prd->prdFrTime $prdFrTime;
                    
$this->prd->prdToTime $prdToTime;
                    
$this->prd->insert();
                    
$flgmsg 1;
                }
            }

            
$this->session->set_flashdata('msg'2);

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/prd_input");
        } else {
            
$this->prd_input();
        }
    }
    function 
prd_delete () {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');
        
        
$prdId $this->input->post('prdId');

        
$this->prd->prdId $prdId;
        
$this->prd->delete();

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'4);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'3);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/prd_input");
    }
    
// ##### end prd

    // ##### start wd
    
function checkMonday($str$field) {
        
$strNew =  splitDateForm2($str,'-');
        
$fieldNew $this->input->post($field);

        if(
$strNew $fieldNew) {
            
$this->form_validation->set_message('checkMonday','%sต้องน้อยกว่าหรือเท่ากับวันที่เริ่มต้นภาคการศึกษา');
            return 
false;
        }
        
        if(
checkWeekDay($str1)) {
            return 
true;
        } else {
            
$this->form_validation->set_message('checkMonday','%sต้องเลือกวันจันทร์เท่านั้น');
            return 
false;
        }
    }
    function 
wd_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_timetable','tt');

        
$acY $this->input->post('acY');
        
$this->contents['acY'] = ($acY) ? $acY $this->session->userdata('acY');
        
$this->contents['rs_tmc'] = $this->tmc->get_optionsGroupAcY('');

        
$this->tmc->tmcAcY $this->contents['acY'];
        
$this->tmc->tmcTmId 1;
        
$this->contents['qu_tmc'] = $this->tmc->get_by_key();

        
$rs_wd $this->wd->qryWdGroupWdAcY();

        
$i 0;
        
$arr = array();
        if(
$rs_wd->num_rows()) {
            foreach(
$rs_wd->result() as $row_wd) {
                
$con_qu_tt = array('coAcY'    => $row_wd->wdAcY);
                
$qu_tt $this->tt->qryTtJoinCo($con_qu_tt);
                
$flgdel = ($qu_tt->num_rows()) ? $qu_tt->num_rows() : 0;
                
$arr[$i]['wd'] = $row_wd;
                
$arr[$i]['del'] = $flgdel;

                
$i++;
            }
        }

        
$this->contents['arr'] = $arr;

        
$this->output($this->config->item("rg_folder")."v_addWeekDate"$this->session->flashdata('msg'));
    }
    function 
wd_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');

        
$data['rs_wd'] = $this->wd->qryWdJoinTm();
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printWeekDate"$data);
    }
    function 
wd_insert_update() {
        
$wdFrDate $this->input->post('wdFrDate');
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('tmcFrDate',' ','trim|xss_clean');
        
$this->form_validation->set_rules('wdFrDate',' ','trim|callback_checkMonday[tmcFrDate]|xss_clean');
        
$this->form_validation->set_rules('wdNum',' ','trim|numeric|required|xss_clean');

        if(
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');
            
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');

            
$acY $this->input->post('acY');
            
$tmId $this->input->post('tmId');
            
$wdNum $this->input->post('wdNum');
            
            
$this->wd->wdAcY $acY;
            
$this->wd->wdAcYWeekNo 1;
            
$qu_wd $this->wd->get_by_key();
            if(!
$qu_wd->num_rows()) {
                
$wdTmId 1;
                
$wdTmWeekNo 1;
                for(
$wdAcYWeekNo=1$wdAcYWeekNo<=$wdNum$wdAcYWeekNo++) {
                    if(
$wdAcYWeekNo==1) {
                        
$wdFrDate splitDateForm2($wdFrDate);
                    } else {
                        
$wdFrDate futureDay(($wdFrDate), 7);
                    }

                    
$qu_tmc $this->tmc->getBetweenDateByNowDate(splitDateForm2(splitDateDb2($wdFrDate)));
                    if(
$qu_tmc->num_rows() && $qu_tmc->row()->tmcTmId!=$wdTmId) {
                        
$wdTmId $qu_tmc->row()->tmcTmId;
                        
$wdTmWeekNo 1;
                    }

                    
$this->wd->wdAcY $acY;
                    
$this->wd->wdAcYWeekNo $wdAcYWeekNo;
                    
$this->wd->wdTmWeekNo $wdTmWeekNo;
                    
$this->wd->wdFrDate $wdFrDate;
                    
$this->wd->wdToDate futureDay($wdFrDate6);
                    
$this->wd->wdTmId $wdTmId;
                    
$this->wd->insert();
                    
$flgmsg 1;

                    
$wdTmWeekNo++;
                }
            }

            
$this->session->set_flashdata('msg'2);
            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/wd_input");
        } else {
            
$this->wd_input();
        }
    }
    function 
wd_edit() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');

        
$wdAcY $this->input->post('wdAcY');
        
$this->contents['acY'] = $wdAcY;
        
$this->contents['rs_tmc'] = $this->tmc->get_optionsGroupAcY('');

        
$con_rs_wd = array('wdAcY'    => $wdAcY);
        
$this->contents['rs_wd'] = $this->wd->qryWd($con_rs_wd,'','');

        
$this->output($this->config->item("rg_folder")."v_editWeekDate");

    }
    function 
wd_edit_update() {
        
$cnt =  $this->input->post('cnt');
        
$wdAcY $this->input->post('wdAcY');

        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');

        for(
$i=0$i<$cnt$i++) {
            
$this->form_validation->set_rules('wdTmId'.$i,' ','trim|numeric|required|callback_checkTmId|xss_clean');
            
$this->form_validation->set_rules('wdTmWeekNo'.$i,' ','trim|required|xss_clean');
        }

        if(
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');

            
$con_rs_wd = array('wdAcY'    => $wdAcY);
            
$rs_wd $this->wd->qryWd($con_rs_wd);
            if(
$rs_wd->num_rows()) {
                foreach(
$rs_wd->result() as $row_wd) {
                    
$this->wd->wdAcY $row_wd->wdAcY;
                    
$this->wd->wdAcYWeekNo $row_wd->wdAcYWeekNo;
                    
$this->wd->delete();
                }
            }

            
$tmId 0;
            for(
$k=0$k<$cnt$k++) {
                
$wdTmId $this->input->post('wdTmId'.$k);
                if(
$wdTmId $tmId) {
                    
$tmId = ($wdTmId==$tmId+1) ? $wdTmId 1;
                    
$wdTmWeekNo $this->input->post('wdTmWeekNo'.$k);
                }

                
$this->wd->wdAcY $wdAcY;
                
$this->wd->wdAcYWeekNo $this->input->post('wdAcYWeekNo'.$k);
                
$this->wd->wdTmId $tmId;
                
$this->wd->wdTmWeekNo $wdTmWeekNo;
                
$this->wd->wdFrDate $this->input->post('wdFrDate'.$k);
                
$this->wd->wdToDate $this->input->post('wdToDate'.$k);
                
$this->wd->insert();
                
$flgmsg 1;

                
$wdTmWeekNo++;
            }

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/wd_input");
        } else {
            
$this->wd_edit();
        }
    }
    function 
wd_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');

        
$wdAcY $this->input->post('wdAcY');

        
$con_rs_wd = array('wdAcY'    => $wdAcY);
        
$rs_wd $this->wd->qryWd($con_rs_wd);

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$rs_wd->num_rows()) {
            foreach(
$rs_wd->result() as $row_wd) {
                
$this->wd->wdAcY $wdAcY;
                
$this->wd->wdAcYWeekNo $row_wd->wdAcYWeekNo;
                
$this->wd->delete();
                
$flgmsg 1;
            }
        }

        
$this->session->set_flashdata('msg'4);
        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'4);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'3);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/wd_input");
    }
    
// ##### end wd

    // ##### start nsd
    
function checkDateNsd($str$field) {
        
$frDate splitDateForm2($str,'-');
        
$toDate splitDateForm2($this->input->post($field),'-');

        if(
$frDate $toDate) {
            
$this->form_validation->set_message('checkDateNsd''%s ต้องน้อยกว่าหรือเท่ากับถึงวันที่');
            return 
false;
        } else {
            return 
true;
        }
    }
    function 
checkTimeNsd($str$field) {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');

        
$this->prd->prdId $str;
        
$this->prd->get_by_key(TRUE);
        
$frTime $this->prd->prdFrTime;

        
$this->prd->prdId $this->input->post($field);
        
$this->prd->get_by_key(TRUE);
        
$toTime $this->prd->prdFrTime;

        if(
$frTime $toTime) {
            
$this->form_validation->set_message('checkTimeNsd''%s ต้องน้อยกว่าหรือเท่ากับถึงเวลา');
            return 
false;
        } else {
            return 
true;
        }
    }
    function 
nsd_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_nostudydate','nsd');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');

        
// edit
        
$nsdId $this->input->post('nsdId');
        
$this->nsd->nsdId $nsdId;
        
$qu_nsd $this->nsd->get_by_key();
        if(
$qu_nsd->num_rows()) {
            
$con_toDate = array('nsdNsdIdParent' => $nsdId);
            
$toDate = ($this->nsd->getMaxDateByParent($con_toDate)) ? $this->nsd->getMaxDateByParent($con_toDate) : $qu_nsd->row()->nsdDate;
            
$this->contents['frDate'] = splitDateDb2($qu_nsd->row()->nsdDate,'/');
            
$this->contents['toDate'] = splitDateDb2($toDate,'/');
        }
        
// end edit

        
$this->contents['qu_nsd'] = $qu_nsd;

        
$con_rs_nsd = array('nsdNsdIdParent'    => 'NULL');
        
$ord_rs_nsd = array('nsdDate'    => 'DESC');
        
$rs_nsd $this->nsd->qryNsd($con_rs_nsd,$ord_rs_nsd,'');

        
$i 0;
        
$arr = array();
        if(
$rs_nsd->num_rows()) {
            foreach(
$rs_nsd->result() as $row_nsd) {
                
$con_max_nsd = array('nsdNsdIdParent'    => $row_nsd->nsdId);
                
$maxNsd $this->nsd->getMaxDateByParent($con_max_nsd);
                
$str abbreDate2($row_nsd->nsdDate). (($maxNsd==NULL) ? '' ' - '.abbreDate2($maxNsd));
                
$arr[$i]['nsd'] = $row_nsd;
                
$arr[$i]['nsdDate'] = $str;

                
$this->prd->prdId $row_nsd->nsdPrdFrTime;
                
$frPrd $this->prd->get_by_key(TRUE);
                
$arr[$i]['frPrd'] = $this->prd->prdFrTime;

                
$this->prd->prdId $row_nsd->nsdPrdToTime;
                
$toPrd $this->prd->get_by_key(TRUE);
                
$arr[$i]['toPrd'] = $this->prd->prdToTime;

                
$i++;
            }
        }

        
$this->contents['arr'] = $arr;
        
$this->contents['rs_prd'] = $this->prd->get_options('','','','');
        
        
$this->output($this->config->item("rg_folder")."v_addNoStudyDate"$this->session->flashdata('msg'));
    }
    function 
nsd_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_nostudydate','nsd');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');

        
$con_rs_nsd = array('nsdNsdIdParent'    => 'NULL');
        
$ord_rs_nsd = array('nsdDate'    => 'DESC');
        
$rs_nsd $this->nsd->qryNsd($con_rs_nsd,$ord_rs_nsd,'');

        
$i 0;
        
$arr = array();
        if(
$rs_nsd->num_rows()) {
            foreach(
$rs_nsd->result() as $row_nsd) {
                
$con_max_nsd = array('nsdNsdIdParent'    => $row_nsd->nsdId);
                
$maxNsd $this->nsd->getMaxDateByParent($con_max_nsd);
                
$str abbreDate2($row_nsd->nsdDate). (($maxNsd==NULL) ? '' ' - '.abbreDate2($maxNsd));
                
$arr[$i]['nsd'] = $row_nsd;
                
$arr[$i]['nsdDate'] = $str;

                
$this->prd->prdId $row_nsd->nsdPrdFrTime;
                
$frPrd $this->prd->get_by_key(TRUE);
                
$arr[$i]['frPrd'] = $this->prd->prdFrTime;

                
$this->prd->prdId $row_nsd->nsdPrdToTime;
                
$toPrd $this->prd->get_by_key(TRUE);
                
$arr[$i]['toPrd'] = $this->prd->prdToTime;

                
$i++;
            }
        }

        
$data['arr'] = $arr;
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printNoStudyDate"$data);
    }
    function 
nsd_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('nsdId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('nsdName',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('frDate',' ','trim|callback_checkDateNsd[toDate]|xss_clean');
        
$this->form_validation->set_rules('toDate',' ','trim|xss_clean');
        
$this->form_validation->set_rules('nsdPrdFrTime',' ','trim|callback_checkTimeNsd[nsdPrdToTime]|xss_clean');
        
$this->form_validation->set_rules('nsdPrdToTime',' ','trim|xss_clean');
        
$this->form_validation->set_rules('nsdRemark',' ','trim|xss_clean');

        if(
$this->form_validation->run() == true) {
            
$flgmsg 0;
            
$this->db->trans_begin();
            
$this->load->model($this->config->item("rg_folder").'mo_rg_nostudydate','nsd');
            
$this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');
            
$this->load->model($this->config->item("rg_folder").'mo_rg_day','dy');
            
$this->load->model($this->config->item("rg_folder").'mo_rg_timetable','tt');

            
$nsdId $this->input->post('nsdId');
            
$nsdName $this->input->post('nsdName');
            
$frDate splitDateForm2($this->input->post('frDate'),'-');
            
$toDate splitDateForm2($this->input->post('toDate'),'-');
            
$frTime $this->input->post('nsdPrdFrTime');
            
$toTime $this->input->post('nsdPrdToTime');
            
$nsdRemark $this->input->post('nsdRemark');

            
// edit
            
if($nsdId) {
                
$con_rs_nsd = array('nsdNsdIdParent'    => $nsdId);
                
$rs_nsd $this->nsd->qryNsd($con_rs_nsd);
                if(
$rs_nsd->num_rows()) {
                    foreach(
$rs_nsd->result() as $row_nsd) {
                        
$this->nsd->nsdId $row_nsd->nsdId;
                        
$this->nsd->delete();
                    }
                }
                
$this->nsd->nsdId $nsdId;
                
$this->nsd->delete();
            }
            
// end edit

            
for($i=0$i<numDay($frDate,$toDate)+1$i++) {
                
$nsdDate futureDay($frDate$i);
                
$nsd $this->nsd->qryNsdByDateAndFrTimeAndToTime($nsdDate,$frTime,$toTime);

                
$wd $this->wd->qryWdBetweenFrDateAndToDate($nsdDate);
                if(
$wd->num_rows()) {
                    
$wdAcY $wd->row()->wdAcY;
                    
$wdAcYWeekNo $wd->row()->wdAcYWeekNo;
                } else {
                    
$wdAcY 0;
                    
$wdAcYWeekNo 0;
                }

                
$dyId getWeekDay(splitDateDb2($nsdDate,'-')) ? getWeekDay(splitDateDb2($nsdDate,'-')) : 7;

                
$con_tt = array('coAcY'            => $wdAcY,
                                
'ttWdAcYWeekNo'    => $wdAcYWeekNo,
                                
'ttDyId'        => $dyId);
                
$tt $this->tt->qryTtBetweenFrTimeAndToTime($con_tt,$frTime,$toTime);

                if(
$nsd->num_rows() || $tt->num_rows()) {
                    
$flgmsg 21;
                } else {
                    
$this->nsd->nsdId '';
                    
$this->nsd->nsdName $nsdName;
                    
$this->nsd->nsdDate $nsdDate;
                    
$this->nsd->nsdRemark $nsdRemark;
                    
$this->nsd->nsdNsdIdParent = ($i==0) ? NULL $nsdNsdIdParent;
                    
$this->nsd->nsdPrdFrTime $frTime;
                    
$this->nsd->nsdPrdToTime $toTime;
                    
$this->nsd->insert();
                    
$flgmsg 10;

                    if(
$i==0) {
                        
$nsdNsdIdParent $this->nsd->last_insert_id();
                    }
                }
            }
            
            
$this->session->set_flashdata('msg'$flgmsg);
            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'$flgmsg);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'$flgmsg);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/nsd_input");
        } else {
            
$this->nsd_input();
        }
    }
    function 
nsd_copy() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_nostudydate','nsd');

        
$acY $this->session->userdata('acY');
        
$frDate $this->tmc->getMinToDateByAcY($acY);
        
$toDate $this->tmc->getMaxToDateByAcY($acY);

        
// ณ ปีการศึกษาปัจจุบันยังไม่มีการกำหนดวันที่ไม่ให้จัดการเรียนการสอน
        
$rs_nsd $this->nsd->qryNsdBetweenDateOrdNsdDateAndNsdPrdFrTime($frDate$toDate);

        
// ให้บันทึกได้กรณีที่ยังไม่มีการกำหนด rg_NoStudyDate
        
$flgmsg 0;
        
$this->db->trans_begin();
        if(!
$rs_nsd->num_rows()) {
            
$frDate $this->tmc->getMinToDateByAcY($acY-1);
            
$toDate $this->tmc->getMaxToDateByAcY($acY-1);

            
$nsdNsdIdParent NULL;
            
$rs_nsd $this->nsd->qryNsdBetweenDateOrdNsdDateAndNsdPrdFrTime($frDate$toDate);
            if(
$rs_nsd->num_rows()) {
                foreach(
$rs_nsd->result() as $row_nsd) {
                    list(
$yy$mm$dd) =  preg_split("[/|-]"$row_nsd->nsdDate);

                    
$this->nsd->nsdId '';
                    
$this->nsd->nsdName $row_nsd->nsdName;
                    
$this->nsd->nsdDate = ($yy+1).'-'.$mm.'-'.$dd;
                    
$this->nsd->nsdRemark $row_nsd->nsdRemark;
                    
$this->nsd->nsdNsdIdParent = (is_null($row_nsd->nsdNsdIdParent)) ? NULL $nsdNsdIdParent;
                    
$this->nsd->nsdPrdFrTime $row_nsd->nsdPrdFrTime;
                    
$this->nsd->nsdPrdToTime $row_nsd->nsdPrdToTime;
                    
$this->nsd->insert();
                    
$flgmsg 1;

                    
$nsdNsdIdParent = (is_null($row_nsd->nsdNsdIdParent)) ? $this->nsd->last_insert_id() : $nsdNsdIdParent;
                }
            }
        }

        
$this->session->set_flashdata('msg'2);

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            if(
$flgmsg)
                
$this->session->set_flashdata('msg'2);
            } else {
            
$this->db->trans_commit();
            if(
$flgmsg)
                
$this->session->set_flashdata('msg'1);
        }
        
redirect($this->config->item("rg_folder")."bdcollege/nsd_input");
    }
    function 
nsd_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_nostudydate','nsd');

        
$nsdId $this->input->post('nsdId');

        
// หยุดมากกว่า 1 วัน
        
$con_rs_nsd = array('nsdNsdIdParent'    => $nsdId);
        
$rs_nsd $this->nsd->qryNsd($con_rs_nsd);

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$rs_nsd->num_rows()) {
            foreach(
$rs_nsd->result() as $row_nsd) {
                
$this->nsd->nsdId $row_nsd->nsdId;
                
$this->nsd->delete();
                
$flgmsg 1;
            }
        }

        
// หยุด 1 วัน
        
$this->nsd->nsdId $nsdId;
        
$this->nsd->delete();
        
$flgmsg 1;

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'4);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'3);
        }
        
redirect($this->config->item("rg_folder")."bdcollege/nsd_input");
    }
    
// ##### end nsd

    // ##### start mep
    
function mep_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_province','prv');

        
$this->mep->mepId $this->input->post('mepId');
        
$this->contents['qu_mep'] = $this->mep->get_by_key();

        
$ord_rs_prv = array('provinceName' => '');
        
$this->contents['rs_prv'] = $this->prv->get_options(''$ord_rs_prv'''y');
        

        
$ord_rs_mep = array('mepName'    => '',
                            
'provinceName'    => '');
        
$this->contents['rs_mep'] = $this->mep->qryMepJoinPrv(''$ord_rs_mep'');

        
$this->output($this->config->item("rg_folder")."v_addMainExternalPlace"$this->session->flashdata('msg'));
    }
    function 
mep_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');

        
$ord_rs_mep = array('mepName'    => '',
                            
'provinceName'    => '');
        
$data['rs_mep'] = $this->mep->qryMepJoinPrv(''$ord_rs_mep'');
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printMainExternalPlace"$data);
    }
    function 
mep_search() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_province','prv');
    
        
$ord_rs_prv = array('provinceName' => '');
        
$this->contents['rs_prv'] = $this->prv->get_options(''$ord_rs_prv'''y');

        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('mepSearch','คำค้น','trim|required|xss_clean');

        if(
$this->form_validation->run() == true) {
            
$ord_rs_mep = array('mepName'    => '',
                                
'provinceName'    => '');
            
$this->contents['rs_mep'] = $this->mep->qryMepLikeNameJoinPrv($this->input->post('mepSearch'));
        }
    
        
$this->output($this->config->item("rg_folder")."v_addMainExternalPlace");
    }
    function 
mep_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('mepId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('mepName',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('mepPrvId',' ','trim|required|xss_clean');

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$this->form_validation->run() == true) {
            
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');

            
$mepId $this->input->post('mepId');
            
$mepName $this->input->post('mepName');
            
$mepPrvId $this->input->post('mepPrvId');

            
$this->mep->mepId $mepId;
            
$qu_mep $this->mep->get_by_key();

            
$con_rs_mep = array('mepName'    => $mepName,
                                
'mepPrvId'    => $mepPrvId);
            if(
$qu_mep->num_rows()) {
                
$rs_mep $this->mep->qryMepNotId($con_rs_mep,$mepId);
                if(!
$rs_mep->num_rows()) {
                    
$this->mep->get_by_key(TRUE);
                    
$this->mep->mepName $mepName;
                    
$this->mep->mepPrvId $mepPrvId;
                    
$this->mep->update();
                    
$flgmsg 1;
                }
            } else {
                
$rs_mep $this->mep->qryMep($con_rs_mep);
                if(!
$rs_mep->num_rows()) {
                    
$this->mep->mepId '';
                    
$this->mep->mepName $mepName;
                    
$this->mep->mepPrvId $mepPrvId;
                    
$this->mep->insert();
                    
$flgmsg 1;
                }
            }
            
            
$this->session->set_flashdata('msg'2);

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
            } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/mep_input");
        }
        else
            
$this->mep_input();
    }
    function 
mep_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');

        
$mepId $this->input->post('mepId');
        
$this->mep->mepId $mepId;
        
$this->mep->delete();

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'4);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'3);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/mep_input");
    }
    
// ##### end mep

    // ##### start sep
    
function sep_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_subexternalplace','sep');

        
$sepId $this->input->post('sepId');
        
$this->sep->sepId $sepId;
        
$this->contents['qu_sep'] = $this->sep->get_by_key();

        
$ord_rs_sep = array('sepName'    => '');
        
$this->contents['rs_sep'] = $this->sep->qrySep('',$ord_rs_sep,'');

        
$this->output($this->config->item("rg_folder")."v_addSubExternalPlace"$this->session->flashdata('msg'));
    }
    function 
sep_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_subexternalplace','sep');

        
$ord_rs_sep = array('sepName'    => '');
        
$data['rs_sep'] = $this->sep->qrySep('',$ord_rs_sep,'');
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printSubExternalPlace"$data);
    }
    function 
sep_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('sepId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('sepName',' ','trim|required|xss_clean');

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$this->form_validation->run() == true) {
            
$this->load->model($this->config->item("rg_folder").'mo_rg_subexternalplace','sep');


            
$sepId $this->input->post('sepId');
            
$sepName $this->input->post('sepName');

            
$this->sep->sepId $sepId;
            
$qu_sep $this->sep->get_by_key();

            
$con_rs_sep = array('sepName'    => $sepName);
            if(
$qu_sep->num_rows()) {
                
$rs_sep $this->sep->qrySepNotId($con_rs_sep,$sepId);
                if(!
$rs_sep->num_rows()) {
                    
$this->sep->get_by_key(TRUE);
                    
$this->sep->sepName $sepName;
                    
$this->sep->update();
                    
$flgmsg 1;
                }
            } else {
                
$rs_sep $this->sep->qrySep($con_rs_sep);
                if(!
$rs_sep->num_rows()) {
                    
$this->sep->sepId '';
                    
$this->sep->sepName $sepName;
                    
$this->sep->insert();
                    
$flgmsg 1;
                }
            }

            
$this->session->set_flashdata('msg'2);

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }
            
            
redirect($this->config->item("rg_folder")."bdcollege/sep_input");
        }
        else
            
$this->sep_input();
    }
    function 
sep_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_subexternalplace','sep');

        
$sepId $this->input->post('sepId');
        
$this->sep->sepId $sepId;
        
$this->sep->delete();

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'4);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'3);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/sep_input");
    }
    
// ##### end sep

    // ##### start etp
    
function etp_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_externalplace','etp');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_subexternalplace','sep');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');

        
$mepId $this->input->post('mepIdSearch');
        
$sepId $this->input->post('sepIdSearch');    
        
$this->contents['mepId'] = $mepId;
        
$this->contents['sepId'] = $sepId;

        
$ord_rs_sep = array('sepName' => '');
        
$this->contents['rs_sep'] = $this->sep->get_options(''$ord_rs_sep'''y');
        
        
$ord_rs_etp = array('mepName'    => '',
                            
'sepName'    => '');
        
$this->contents['rs_etp'] = $this->etp->qryEtpJoinMepSep(''$ord_rs_etp'');

        
$ord_rs_mepSearch = array('mepName' => '');
        
$this->contents['rs_mepSearch'] = $this->mep->get_options(''$ord_rs_mepSearch'''y');
        
$this->contents['rs_sepSearch'] = $this->contents['rs_sep'];

        
$this->output($this->config->item("rg_folder")."v_addExternalPlace"$this->session->flashdata('msg'));
    }
    function 
etp_search() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_externalplace','etp');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_subexternalplace','sep');
        
$this->load->model($this->config->item("rg_folder").'mo_rg_mainexternalplace','mep');

        
$mepId $this->input->post('mepIdSearch');
        
$sepId $this->input->post('sepIdSearch');
        
        
$this->contents['mepId'] = $mepId;
        
$this->contents['sepId'] = $sepId;

        if(
$mepId!='' && $sepId!='') {
            
$con_rs_etp = array('etpMepId'    => $mepId,
                                
'etpSepId'    => $sepId);
            
$ord_rs_etp = array('mepName'    => '',
                                
'sepName'    => '');
            
$this->contents['rs_etp'] = $this->etp->qryEtpJoinMepSep($con_rs_etp$ord_rs_etp);
        } else {
            
$this->contents['rs_etp'] = $this->etp->qryEtpByMepIdOrSepIdJoinMepSep($mepId$sepId);
        }
        
        
$ord_rs_sep = array('sepName' => '');
        
$this->contents['rs_sep'] = $this->sep->get_options(''$ord_rs_sep'''y');

        
$ord_rs_mepSearch = array('mepName' => '');
        
$this->contents['rs_mepSearch'] = $this->mep->get_options(''$ord_rs_mepSearch'''y');
        
$this->contents['rs_sepSearch'] = $this->contents['rs_sep'];

        
$this->output($this->config->item("rg_folder")."v_addExternalPlace"$this->session->flashdata('msg'));
    }
    function 
etp_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_externalplace','etp');

        
$ord_rs_etp = array('mepName'    => '',
                            
'sepName'    => '');
        
$data['rs_etp'] = $this->etp->qryEtpJoinMepSep(''$ord_rs_etp'');
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printExternalPlace"$data);
    }
    function 
etp_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('mepName',' ','trim|xss_clean');
        
$this->form_validation->set_rules('mepId',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('prvName',' ','trim|xss_clean');
        
$this->form_validation->set_rules('prvId',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('sepId',' ','trim|required|xss_clean');

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$this->form_validation->run() == true) {
            
$this->load->model($this->config->item("rg_folder").'mo_rg_externalplace','etp');

            
$etpMepId $this->input->post('mepId');
            
$etpSepId $this->input->post('sepId');
            
            
$this->etp->etpMepId $etpMepId;
            
$this->etp->etpSepId $etpSepId;
            
$qu_etp $this->etp->get_by_key();
            if(!
$qu_etp->num_rows()) {
                
$this->etp->etpMepId $etpMepId;
                
$this->etp->etpSepId $etpSepId;
                
$this->etp->insert();
                
$flgmsg 1;
            }

            
$this->session->set_flashdata('msg'2);

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'2);
                } else {
                
$this->db->trans_commit();
                if(
$flgmsg)
                    
$this->session->set_flashdata('msg'1);
            }

            
redirect($this->config->item("rg_folder")."bdcollege/etp_input");
        }
        else
            
$this->etp_input();
    }
    function 
etp_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_externalplace','etp');

        
$etpMepId $this->input->post('etpMepId');
        
$etpSepId $this->input->post('etpSepId');

        
$this->etp->etpMepId $etpMepId;
        
$this->etp->etpSepId $etpSepId;
        
$this->etp->delete();

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'4);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'3);
        }

        
redirect($this->config->item("rg_folder")."bdcollege/etp_input");
    }
    function 
etp_addExternalPlaceRow($mepId$sepId) {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_config','cfg');
        
$this->load->model($this->config->item('rg_folder').'mo_rg_externalplace','etp');

        if(
$mepId==0)
            
$con_rs_etp = array('etpSepId' => $sepId);
        else if(
$sepId==0)
            
$con_rs_etp = array('etpMepId' => $mepId);
        else
            
$con_rs_etp = array('etpMepId' => $mepId,
                                
'etpSepId' => $sepId);

        
$data['qu_cfg'] = $this->cfg->qryCfg("","","",FALSE);
        
$data['rs_etp'] = $this->etp->qryEtpJoinMepSep($con_rs_etp,"","");

        echo 
$this->load->view("eregis/v_addExternalPlaceRow",$data,TRUE);
    }
    
// ##### end etp

    // ##### start tcm
    
function tcm_input() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_teachingmethod','tcm');

        
$tcmId $this->input->post('tcmId');
        
$this->tcm->tcmId $tcmId;
        
$this->contents['qu_tcm'] = $this->tcm->get_by_key();

        
$ord_rs_tmc = array('tcmName'    => '',
                            
'tcmNameE'    => '');
        
$this->contents['rs_tcm'] = $this->tcm->qryTcm('',$ord_rs_tmc,'');

        
$this->output($this->config->item("rg_folder")."v_addTeachingMethod"$this->session->flashdata('msg'));
    }
    function 
tcm_print() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_teachingmethod','tcm');

        
$ord_rs_tmc = array('tcmName'    => '',
                            
'tcmNameE'    => '');
        
$data['rs_tcm'] = $this->tcm->qryTcm('',$ord_rs_tmc,'');
        
$data['UsName'] = $this->session->userdata('UsName');

        
$this->load->view($this->config->item("rg_folder")."v_printTeachingMethod"$data);
    }
    function 
tcm_insert_update() {
        
$this->load->library('form_validation');
        
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
$this->form_validation->set_rules('tcmId',' ','trim|xss_clean');
        
$this->form_validation->set_rules('tcmName',' ','trim|required|xss_clean');
        
$this->form_validation->set_rules('tcmNameE',' ','trim|required|xss_clean');

        
$flgmsg 0;
        
$this->db->trans_begin();
        if(
$this->form_validation->run() == true) {
            
$this->load->model($this->config->item("rg_folder").'mo_rg_teachingmethod','tcm');

            
$tcmId $this->input->post('tcmId');
            
$tcmName $this->input->post('tcmName');
            
$tcmNameE $this->input->post('tcmNameE');

            
$this->tcm->tcmId $tcmId;
            
$qu_tcm $this->tcm->get_by_key();

            
$con_rs_tcm = array('tcmName'    => $tcmName,
                                
'tcmNameE'    => $tcmNameE);
            if(
$qu_tcm->num_rows()) {
                
$rs_tcm $this->tcm->qryTcmNotId($con_rs_tcm,$tcmId);
                if(!
$rs_tcm->num_rows()) {
                    
$this->tcm->get_by_key(TRUE);
                    
$this->tcm->tcmName $tcmName;
                    
$this->tcm->tcmNameE $tcmNameE;
                    
$this->tcm->update();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            } else {
                
$rs_tcm $this->tcm->qryTcm($con_rs_tcm);
                if(!
$rs_tcm->num_rows()) {
                    
$this->tcm->tcmId '';
                    
$this->tcm->tcmName $tcmName;
                    
$this->tcm->tcmNameE $tcmNameE;
                    
$this->tcm->insert();

                    
$flgmsg 10;
                } else {
                    
$flgmsg 21;
                }
            }

            if(
$this->db->trans_status() === false) {
                
$this->db->trans_rollback();
                
$flgmsg 21;
            } else {
                
$this->db->trans_commit();
            }

            
$this->session->set_flashdata('msg'$flgmsg);

            
redirect($this->config->item("rg_folder")."bdcollege/tcm_input");
        }
        else
            
$this->tcm_input();
    }
    function 
tcm_delete() {
        
$this->load->model($this->config->item("rg_folder").'mo_rg_teachingmethod','tcm');

        
$tcmId $this->input->post('tcmId');
        
$this->tcm->tcmId $tcmId;
        
$this->tcm->delete();

        if(
$this->db->trans_status() === false) {
            
$this->db->trans_rollback();
            
$this->session->set_flashdata('msg'41);
        } else {
            
$this->db->trans_commit();
            
$this->session->set_flashdata('msg'30);
        }
        
        
redirect($this->config->item("rg_folder")."bdcollege/tcm_input");
    }
    
// ##### end tcm
}
?>

:: Command execute ::

Enter:
 
Select:
 

:: Shadow's tricks :D ::

Useful Commands
 
Warning. Kernel may be alerted using higher levels
Kernel Info:

:: Preddy's tricks :D ::

Php Safe-Mode Bypass (Read Files)

File:

eg: /etc/passwd

Php Safe-Mode Bypass (List Directories):

Dir:

eg: /etc/

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c999shell v. 1.0 pre-release build #16 Modded by Shadow & Preddy | RootShell Security Group | r57 c99 shell | Generation time: 0.0353 ]--