Viewing file: preregis.php (38.79 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include("rg_controller.php");
class preregis extends Rg_controller {
// function __construct() {
// parent::__construct();
// }
// ##### start คัดลอกรายวิชาที่เปิดสอน
function pr_beforeCopyCo() {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->contents['acY'] = $this->session->userdata('acY');
$this->contents['tmId'] = $this->session->userdata('tmId');
$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);
$this->contents['rs_sy'] = $this->sy->get_options();
$this->contents['rs_tm'] = $this->tm->get_options();
$this->output($this->config->item("rg_folder")."v_beforeCopyCourseOpen");
}
function pr_copyCo() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
$this->form_validation->set_rules('curId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('syId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('tmId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('acY', ' ', 'trim|callback_checkAcY|xss_clean');
if($this->form_validation->run() == true) {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyplan','sp');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$this->load->model($this->config->item("rg_folder").'mo_rg_course','crs');
$acY = $this->input->post('acY');
$curId = $this->input->post('curId');
$tmId = $this->input->post('tmId');
$syId = $this->input->post('syId');
$this->tm->tmId = $tmId;
$this->cur->curId = $curId;
$this->sy->syId = $syId;
$this->contents['qu_tm'] = $this->tm->get_by_key(TRUE);
$this->contents['qu_cur'] = $this->cur->get_by_key(TRUE);
$this->contents['qu_sy'] = $this->sy->get_by_key(TRUE);
$this->contents['acY'] = $acY;
$i = 0;
$arr = array();
$flagExit = 0;
$sumCreditTotal = 0;
$con_rs_sp = array('spCurId' => $curId,
'spSyId' => $syId,
'spTmId' => $tmId);
$rs_sp = $this->sp->qrySp($con_rs_sp);
if($rs_sp->num_rows()) {
foreach($rs_sp->result() as $row_sp) {
$con_rs_co = array('coCurId' => 'NULL',
'coAcY' => $acY,
'coSyId' => $syId,
'coTmId' => $tmId,
'coCrsId' => $row_sp->spCrsId);
// หารายวิชาที่เปิดสอน ของเรียนรวมหลายหลักสูตร
$rs_co = $this->co->qryCo($con_rs_co);
if($rs_co->num_rows()) {
$flagExit = 1;
} else {
$con_qu_crs = array('crsId' => $row_sp->spCrsId);
$qu_crs = $this->crs->qryCrs($con_qu_crs);
$arr[$i]['crs'] = $qu_crs->num_rows() ? $qu_crs->row() : NULL;
$sumCreditTotal += $qu_crs->row()->crsCreditTotal;
}
$i++;
}
}
// คัดลอกรายวิชาที่เปิดสอนแล้ว
$con_rs_co = array('coCurId' => $curId,
'coSyId' => $syId,
'coTmId' => $tmId,
'coAcY' => $acY);
$rs_co = $this->co->qryCo($con_rs_co);
if($rs_co->num_rows()) {
$flagExit = 1;
}
$this->contents['flagExit'] = $flagExit;
$this->contents['sumCreditTotal'] = $sumCreditTotal;
$this->contents['arr'] = $arr;
$this->output($this->config->item("rg_folder")."v_copyCourseOpen");
} else {
$this->contents['add'] = 1;
$this->pr_beforeCopyCo();
}
}
function pr_processAddCo() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyplan','sp');
$acY = $this->input->post('acY');
$curId = $this->input->post('curId');
$syId = $this->input->post('syId');
$tmId = $this->input->post('tmId');
$con_rs_sp = array('spCurId' => $curId,
'spSyId' => $syId,
'spTmId' => $tmId);
$rs_sp = $this->sp->qrySp($con_rs_sp);
$this->db->trans_begin();
if($rs_sp->num_rows()) {
foreach($rs_sp->result() as $row_sp) {
$this->co->coAcY = $acY;
$this->co->coSectionClass = 1;
$this->co->coSection = 1;
$this->co->coNumSeatOpen = 50;
$this->co->coNumSeatReg = 0;
$this->co->coSendGradeStatus = 'N';
$this->co->coDeclareStatus = 'N';
$this->co->coCurId = $curId;
$this->co->coSyId = $syId;
$this->co->coTmId = $tmId;
$this->co->coCrsId = $row_sp->spCrsId;
$this->co->coRspId = NULL;
$this->co->coCdId1 = $row_sp->spCdId1;
$this->co->coCdId2 = $row_sp->spCdId2;
$this->co->coPrsId = NULL;
$this->co->insert();
}
}
if($this->db->trans_status() === false) {
$this->db->trans_rollback();
} else {
$this->db->trans_commit();
}
redirect($this->config->item("rg_folder")."preregis/pr_beforeCopyCo");
}
// ##### end คัดลอกรายวิชาที่เปิดสอน
// ##### start กำหนดรายวิชาที่เปิดสอน
function co_search() {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->contents['acY'] = $this->session->userdata('acY');
$this->contents['tmId'] = $this->session->userdata('tmId');
$con_rs_cur = array('curStatus' => 'Y');
$ord_rs_cur = array('curName' => 'ASC');
$this->contents['rs_cur'] = $this->cur->get_options($con_rs_cur, $ord_rs_cur, '', '---เรียนรวมหลายหลักสูตร---');
$this->contents['rs_sy'] = $this->sy->get_options();
$this->contents['rs_tm'] = $this->tm->get_options('','','','n');
$this->output($this->config->item("rg_folder")."v_searchCourseOpen");
}
function co_input() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
$this->form_validation->set_rules('curId', ' ', 'trim|xss_clean');
$this->form_validation->set_rules('syId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('tmId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('acY', ' ', 'callback_checkAcY');
if ($this->form_validation->run() == FALSE) {
$this->co_search();
} else {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$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_courseopenstudent','costd');
$this->load->model($this->config->item("rg_folder").'mo_rg_student','std');
$this->load->model($this->config->item("rg_folder").'mo_rg_timetable','tt');
$this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');
$curId = $this->input->post('curId');
$syId = $this->input->post('syId');
$tmId = $this->input->post('tmId');
$acY = $this->input->post('acY');
$coId = $this->input->post('coId');
$this->cur->curId = $curId;
$qu_cur = $this->cur->get_by_key();
if ($qu_cur->num_rows()) {
$this->contents['qu_cur'] = $qu_cur;
}
$this->sy->syId = $syId;
$this->contents['qu_sy'] = $this->sy->get_by_key();
$this->tm->tmId = $tmId;
$this->contents['qu_tm'] = $this->tm->get_by_key();
$this->contents['acY'] = $acY;
$i = 0;
$arr = array();
$con_rs_co = array('coCurId' => $curId,
'coSyId' => $syId,
'coTmId' => $tmId,
'coAcY' => $acY
);
if (!$curId) { // วิชาที่เปิดสอนนอกหลักสูตร
$con_rs_co = array('coCurId' => 'NULL',
'coSyId' => $syId,
'coTmId' => $tmId,
'coAcY' => $acY
);
}
$rs_co = $this->co->qryCoJoinCrs($con_rs_co);
foreach ($rs_co->result() as $row_co) {
$con_qu_co = array('coId' => $row_co->coId);
$arr[$i]['qu_co'] = $this->co->qryCoJoinCrs($con_qu_co);
$con_qu_co = array('coCurId' => $row_co->coCurId,
'coCrsId' => $row_co->coCrsId,
'coSyId' => $row_co->coSyId,
'coTmId' => $row_co->coTmId,
'coAcY' => $row_co->coAcY
);
if (is_null($row_co->coCurId)) {
$con_qu_co = array('coCurId' => 'NULL',
'coCrsId' => $row_co->coCrsId,
'coSyId' => $row_co->coSyId,
'coTmId' => $row_co->coTmId,
'coAcY' => $row_co->coAcY
);
}
$arr[$i]['maxSec'] = $this->co->getMaxSection($con_qu_co);
$con_qu_cos = array('cosCoId' => $row_co->coId);
$arr[$i]['cntStd'] = $this->costd->getCountStdId($con_qu_cos);
$con_qu_co = array('coCurId' => $row_co->coCurId,
'coCrsId' => $row_co->coCrsId,
'coSyId' => $row_co->coSyId,
'coTmId' => $row_co->coTmId,
'coAcY' => $row_co->coAcY
);
if (is_null($row_co->coCurId)) {
$con_qu_co = array('coCurId' => 'NULL',
'coCrsId' => $row_co->coCrsId,
'coSyId' => $row_co->coSyId,
'coTmId' => $row_co->coTmId,
'coAcY' => $row_co->coAcY
);
}
$arr[$i]['sumNumSeatOpen'] = $this->co->getSumNumSeatOpen($con_qu_co);
$i++;
}
$this->contents['rs'] = $arr;
$con_qu_std = array('stdCurId' => $curId,
'stdSyId' => $syId,
'stdSstId' => 1,
'stdGenStatus' => 'Y'
);
$this->contents['numStd'] = $this->std->getCountStdId($con_qu_std);
$con_rs_co = array('coCurId' => 'NULL',
'coAcY' => $acY,
'coSyId' => $syId,
'coTmId' => $tmId,
'cofCurId' => $curId
);
$this->contents['rs_co'] = $this->co->qryCoJoinCofCrs($con_rs_co);
// อาจารย์ผู้รับผิดชอบส่งเกรด
$con_qu_co = array('coId' => $coId);
$qu_co = $this->co->qryCoJoinCrs($con_qu_co);
if ($qu_co->num_rows()) {
$this->contents['qu_co'] = $qu_co;
$row_co = $qu_co->row();
$this->contents['rs_tt'] = $this->tt->qryTeacher2($coId);
$con_qu_tt = array('ttPrsId' => $row_co->coPrsId,
'ttCoId' => $coId
);
$this->contents['sumHr'] = $this->tt->getSumHr($con_qu_tt);
$con_rs_prs = array('prsPsId' => 1);
$ord_rs_prs = array('fName' => 'ASC',
'lName' => 'ASC'
);
$this->contents['rs_prs'] = $this->prs->get_options($con_rs_prs, $ord_rs_prs);
}
$this->output($this->config->item("rg_folder")."v_addCourseOpen");
}
}
function co_insert() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$curId = $this->input->post('curId');
$acY = $this->input->post('acY');
$syId = $this->input->post('syId');
$tmId = $this->input->post('tmId');
$crsId = $this->input->post('crsId');
$cdId1 = $this->input->post('cdId1');
$cdId2 = $this->input->post('cdId2');
$coNumSeatOpen = $this->input->post('coNumSeatOpen');
$coSectionClass = count($coNumSeatOpen);
for ($i = 0; $i < $coSectionClass; $i++) {
$con_rs_co = array('coCurId' => (($curId == 'NULL') ? NULL : $curId),
'coAcY' => $acY,
'coSyId' => $syId,
'coTmId' => $tmId,
'coCrsId' => $crsId,
'coSection' => $i + 1
);
$rs_co = $this->co->qryCo($con_rs_co);
if ($rs_co->num_rows() == 0) {
$this->co->coCurId = ($curId == 'NULL') ? NULL : $curId;
$this->co->coAcY = $acY;
$this->co->coSyId = $syId;
$this->co->coTmId = $tmId;
$this->co->coCrsId = $crsId;
$this->co->coSectionClass = $coSectionClass;
$this->co->coSection = $i + 1;
$this->co->coNumSeatOpen = $coNumSeatOpen[$i];
$this->co->coNumSeatReg = 0;
$this->co->coSendGradeStatus = 'N';
$this->co->coRspId = NULL;
$this->co->coCdId1 = $cdId1;
$this->co->coCdId2 = $cdId2;
$this->co->coDeclareStatus = 'N';
$this->co->coPrsId = NULL;
$this->co->insert();
}
}
$this->co_input();
}
function co_update() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopenstudent','costd');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$coId = $this->input->post('coId');
$coNumSeatOpen = $this->input->post('coNumSeatOpen');
$con_qu_cos = array('cosCoId' => $coId);
$res = $this->costd->getCountStdId($con_qu_cos);
$this->co->coId = $coId;
$this->co->get_by_key(TRUE);
$this->co->coNumSeatOpen = ($res > $coNumSeatOpen) ? $res : $coNumSeatOpen;
$this->co->update();
$this->co_input();
}
function co_updateRCIS() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$coId = $this->input->post('coId');
$responsibility = $this->input->post('responsibility');
$prsIdRC = $this->input->post('prsIdRC');
$this->co->coId = $coId;
$this->co->get_by_key(TRUE);
$this->co->coPrsId = ($responsibility == 'RC') ? $prsIdRC : $responsibility;
$this->co->update();
$this->co_input();
}
function co_delete() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$coId = $this->input->post('coId');
$this->co->coId = $coId;
$qu_co = $this->co->get_by_key();
if ($qu_co->num_rows()) {
$this->db->trans_begin();
$row_co = $qu_co->row();
$this->co->delete();
// Find sectionClass
$con_rs_co = array('coCurId' => $row_co->coCurId,
'coAcY' => $row_co->coAcY,
'coSyId' => $row_co->coSyId,
'coTmId' => $row_co->coTmId,
'coCrsId' => $row_co->coCrsId
);
if (is_null($row_co->coCurId)) {
$con_rs_co = array('coCurId' => 'NULL',
'coAcY' => $row_co->coAcY,
'coSyId' => $row_co->coSyId,
'coTmId' => $row_co->coTmId,
'coCrsId' => $row_co->coCrsId
);
}
$rs_co = $this->co->qryCo($con_rs_co);
$numRecord = $rs_co->num_rows();
// Update sectionClass
foreach ($rs_co->result() as $row_co) {
$this->co->coId = $row_co->coId;
$this->co->get_by_key(TRUE);
$this->co->coSectionClass = $numRecord;
$this->co->update();
}
if ($this->db->trans_status() === false) {
$this->db->trans_rollback();
} else {
$this->db->trans_commit();
}
}
$this->co_input();
}
function cof_show() {
$this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
$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_courseopenfor','cof');
$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;
$this->contents['rs_tmc'] = $this->tmc->get_optionsGroupAcY();
$ord_rs_tm = array('tmCode' => 'ASC');
$this->contents['rs_tm'] = $this->tm->get_options("", $ord_rs_tm);
$i = 0;
$arr = array();
$con_rs_co = array('coCurId' => 'NULL',
'coAcY' => $acY,
'coTmId' => $tmId
);
$rs_co = $this->co->qryCo($con_rs_co);
foreach ($rs_co->result() as $row_co) {
$con_qu_co = array('coId' => $row_co->coId);
$arr[$i]['qu_co'] = $this->co->qryCoJoinCrs($con_qu_co);
$con_rs_cof = array('cofCoId' => $row_co->coId);
$arr[$i]['rs_cof'] = $this->cof->qryCof($con_rs_cof);
$i++;
}
$this->contents['rs'] = $arr;
$this->output($this->config->item("rg_folder")."v_showCourseOpenFor");
}
function cof_input() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$this->load->model($this->config->item("rg_folder").'mo_rg_timetable','tt');
$this->load->model($this->config->item("rg_folder").'mo_rg_programcourses','pcr');
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopenfor','cof');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopenstudent','costd');
$coId = $this->input->post('coId');
$this->contents['coId'] = $coId;
$con_qu_co = array('coId' => $coId);
$qu_co = $this->co->qryCoJoinCrs($con_qu_co);
$this->contents['qu_co'] = $qu_co;
$row_co = $qu_co->row();
$qu_tt = $this->tt->qryTeacher($coId);
$this->contents['prsNames'] = $qu_tt->row()->prsName;
$i = 0;
$arr = array();
$con_rs_pcr = array('pcrCsCdId1' => $row_co->coCdId1,
'pcrCsCdId2' => $row_co->coCdId2,
'pcrCrsId' => $row_co->coCrsId,
'curStatus' => 'Y'
);
$rs_pcr = $this->pcr->qryPcrJoinCur($con_rs_pcr);
foreach ($rs_pcr->result() as $row_pcr) {
$this->cur->curId = $row_pcr->pcrCsCurId;
$arr[$i]['qu_cur'] = $this->cur->get_by_key();
$this->cof->cofCoId = $coId;
$this->cof->cofCurId = $row_pcr->pcrCsCurId;
$qu_cof = $this->cof->get_by_key();
$arr[$i]['qu_cof'] = $qu_cof;
$con_qu_cos = array('cosCoId' => $coId,
'stdCurId' => $row_pcr->pcrCsCurId
);
$arr[$i]['cntStd'] = $this->costd->getCountStdIdJoinStd($con_qu_cos);
$i++;
}
$this->contents['rs'] = $arr;
$this->output($this->config->item("rg_folder")."v_addCourseOpenFor");
}
function cof_insert() {
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopenstudent','costd');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopenfor','cof');
$this->load->model($this->config->item("rg_folder").'mo_rg_realstudyplan','rsp');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$cnt = $this->input->post('cnt');
$order = $this->input->post('order');
$coId = $this->input->post('coId');
$curId = $this->input->post('curId');
$cofSeats = $this->input->post('cofSeats');
for ($i = 0; $i < $cnt; $i++) {
$con_qu_cos = array('cosCoId' => $coId,
'stdCurId' => $curId[$i]
);
$res = $this->costd->getCountStdIdJoinStd($con_qu_cos);
if (isset($order[$i]) && ($order[$i] == 'Y') && $cofSeats[$i]) {
$this->cof->cofCoId = $coId;
$this->cof->cofCurId = $curId[$i];
$qu_cof = $this->cof->get_by_key();
if ($qu_cof->num_rows()) {
$this->cof->get_by_key(TRUE);
$this->cof->cofSeats = ($res > $cofSeats[$i]) ? $res : $cofSeats[$i];
$this->cof->update();
} else {
$this->cof->cofNumEnroll = 0;
$this->cof->cofSeats = ($res > $cofSeats[$i]) ? $res : $cofSeats[$i];
$this->cof->insert();
}
} else {
$con_rs_rsp = array('rspCoId' => $coId,
'rspCurId' => $curId[$i]
);
$rs_rsp = $this->rsp->qryRsp($con_rs_rsp);
$this->cof->cofCoId = $coId;
$this->cof->cofCurId = $curId[$i];
$qu_cof = $this->cof->get_by_key();
if (!$res && !$rs_rsp->num_rows() && $qu_cof->num_rows()) {
$this->cof->delete();
}
}
}
$con_qu_cof = array('cofCoId' => $coId);
$this->co->coId = $coId;
$this->co->get_by_key(TRUE);
$this->co->coNumSeatOpen = $this->cof->getSumSeats($con_qu_cof);
$this->co->update();
$this->cof_input();
}
// ##### start กำหนดชั่วโมงฝึกปฏิบัติ
function showPracticeHour() {
$this->output($this->config->item("rg_folder")."v_showPracticeHours");
}
function addPracticeHour() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
$this->form_validation->set_rules('curName',' ','trim|xss_clean');
$this->form_validation->set_rules('curId',' ','trim|required|xss_clean');
$this->form_validation->set_rules('stdTmIdAdmit',' ','trim|xss_clean');
$this->form_validation->set_rules('adY',' ','trim|required|xss_clean');
if($this->form_validation->run() == true) {
$this->ph_input();
} else {
$this->showPracticeHour();
}
}
function ph_input() {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_clinicalpractice','cp');
$curId = $this->input->post('curId');
$adY = $this->input->post('adY');
$this->contents['adY'] = $adY;
$this->cur->curId = $curId;
$this->contents['qu_cur'] = $this->cur->get_by_key();
$cond_cp = array('phCurId' => $curId, 'phAdY' => $adY);
$ord_rs_cp = array('cpSeq' => 'ASC');
$this->contents['rs_cp'] = $this->cp->qryCpJoinPh($cond_cp, $ord_rs_cp);
$this->output($this->config->item("rg_folder")."v_addPracticeHours");
}
function ph_insert_update() {
$this->load->model($this->config->item("rg_folder").'mo_rg_practicehours','ph');
$cnt = $this->input->post('cnt');
$curId = $this->input->post('curId');
$adY = $this->input->post('adY');
for($i=0; $i<$cnt; $i++) {
if($this->input->post('chk'.$i)=='Y') {
$this->ph->phCurId = $curId;
$this->ph->phCpId = $this->input->post('cpId'.$i);
$this->ph->phAdY = $adY;
$qu_ph = $this->ph->get_by_key();
if($qu_ph->num_rows()) {
$this->ph->get_by_key(TRUE);
$this->ph->phLabHr = $this->input->post('phLabHr'.$i);
$this->ph->update();
} else {
$this->ph->phCurId = $curId;
$this->ph->phCpId = $this->input->post('cpId'.$i);
$this->ph->phAdY = $adY;
$this->ph->phLabHr = $this->input->post('phLabHr'.$i);
$this->ph->insert();
}
} else {
$this->ph->phCurId = $curId;
$this->ph->phCpId = $this->input->post('cpId'.$i);
$this->ph->phAdY = $adY;
$this->ph->delete();
}
}
$this->ph_input();
}
// ##### end กำหนดชั่วโมงฝึกปฏิบัติ
function es_search() {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->load->model($this->config->item("rg_folder").'mo_rg_examtype','ex');
$acY = $this->session->userdata('acY');
$tmId = $this->session->userdata('tmId');
$this->contents['acY'] = $acY;
$this->contents['tmId'] = $tmId;
$con_rs_cur = array('curStatus' => 'Y');
$ord_rs_cur = array('curName' => 'ASC');
$this->contents['rs_cur'] = $this->cur->get_options($con_rs_cur, $ord_rs_cur, '', 'เรียนรวมหลายหลักสูตร');
$ord_rs_sy = array('syCode' => 'ASC');
$this->contents['rs_sy'] = $this->sy->get_options('', $ord_rs_sy);
$ord_rs_tm = array('tmCode' => 'ASC');
$this->contents['rs_tm'] = $this->tm->get_options('', $ord_rs_tm);
$this->contents['rs_ex'] = $this->ex->get_options('','','n');
$this->output($this->config->item("rg_folder")."v_searchExamSchedule");
}
function es_input() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
$this->form_validation->set_rules('curId',' ','trim|xss_clean');
$this->form_validation->set_rules('syId',' ','trim|required|xss_clean');
$this->form_validation->set_rules('acY',' ','trim|required|exact_length[4]|xss_clean');
$this->form_validation->set_rules('tmId',' ','trim|required|xss_clean');
$this->form_validation->set_rules('exType',' ','trim|required|xss_clean');
if ($this->form_validation->run() == false) {
$this->es_search();
} else {
$this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');
$this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->load->model($this->config->item("rg_folder").'mo_rg_examtype','ex');
$this->load->model($this->config->item("rg_folder").'mo_rg_examschedule','es');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
$this->load->model($this->config->item("rg_folder").'mo_rg_schedule','sd');
$this->load->model($this->config->item("rg_folder").'mo_rg_studytype','st');
$this->load->model($this->config->item("ppc_folder").'mo_spc_place','rm');
$this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');
$this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');
$this->load->model($this->config->item("rg_folder").'mo_rg_courseopenfor','cof');
$curId = $this->input->post('curId') ? $this->input->post('curId') : NULL;
$syId = $this->input->post('syId');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$coId = $this->input->post('coId');
$exType = $this->input->post('exType');
$this->contents['acY'] = $acY;
if ($curId) {
$this->cur->curId = $curId;
$this->contents['qu_cur'] = $this->cur->get_by_key();
}
$this->sy->syId = $syId;
$this->contents['qu_sy'] = $this->sy->get_by_key();
$this->tm->tmId = $tmId;
$this->contents['qu_tm'] = $this->tm->get_by_key();
$con_qu_ex = array('exType' => $exType);
$this->contents['qu_ex'] = $this->ex->qryEx($con_qu_ex);
$this->contents['coId'] = $coId;
if ($coId) {
$con_rs_es = array('esCoId' => $coId,
'esExamType' => $exType
);
$rs_es = $this->es->qryEs($con_rs_es);
if ($rs_es->num_rows()) {
$this->contents['rs_es'] = $rs_es;
}
$con_qu_co = array('coId' => $coId);
$this->contents['qu_co'] = $this->co->qryCoJoinCrs($con_qu_co);
$this->sd->sdAcY = $acY;
$this->sd->sdTmId = $tmId;
$this->contents['qu_sd'] = $this->sd->get_by_key();
$this->contents['rs_st'] = $this->st->get_options();
$this->contents['rs_rm'] = $this->rm->get_optionsRm();
$this->contents['rs_prd'] = $this->prd->get_options();
$con_rs_prs = array('prsPsId' => 1);
$this->contents['rs_prs'] = $this->prs->get_options($con_rs_prs);
}
$i = 0;
$arr = array();
$con_rs_co = array('coCurId' => $curId,
'coSyId' => $syId,
'coTmId' => $tmId,
'coAcY' => $acY
);
if (is_null($curId)) {
$con_rs_co = array('coCurId' => 'NULL',
'coSyId' => $syId,
'coTmId' => $tmId,
'coAcY' => $acY
);
}
$rs_co = $this->co->qryCo($con_rs_co);
foreach ($rs_co->result() as $row_co) {
$j = 0;
$prsNames = '';
$con_rs_es = array('esCoId' => $row_co->coId,
'esExamType' => $exType
);
$rs_es = $this->es->qryEs($con_rs_es);
foreach ($rs_es->result() as $row_es) {
$con_qu_prs = array('prsId' => $row_es->esPrsId);
$qu_prs = $this->prs->qryPrsJoinPPC($con_qu_prs);
//echo $this->db->last_query();
//$arr[$i]['esDate'] = '';
if ($qu_prs->num_rows()) {
if ($j == 0) {
$arr[$i]['esDate'] = $row_es->esDate;
$this->st->stId = $row_es->esStId;
$arr[$i]['qu_st'] = $this->st->get_by_key();
$this->rm->plHwId = $row_es->esRmId;
$arr[$i]['qu_rm'] = $this->rm->get_by_key();
$this->prd->prdId = $row_es->esPrdFrTime;
$arr[$i]['qu_prd1'] = $this->prd->get_by_key();
$this->prd->prdId = $row_es->esPrdToTime;
$arr[$i]['qu_prd2'] = $this->prd->get_by_key();
$prsNames = $qu_prs->row()->name;
} else {
$prsNames .= '<br />'.$qu_prs->row()->name;
}
}
$j++;
}
$arr[$i]['mtd'] = $j;
$arr[$i]['prsNames'] = $prsNames;
$pgNames = '';
if (is_null($row_co->coCurId)) {
$k = 0;
$con_rs_cof = array('cofCoId' => $row_co->coId);
$rs_cof = $this->cof->qryCofJoinCur($con_rs_cof);
foreach ($rs_cof->result() as $row_cof) {
if ($k == 0) {
$pgNames = $row_cof->curName;
} else {
$pgNames .= '<br /> '.$row_cof->curName;
}
$k++;
}
} else {
$this->cur->curId = $row_co->coCurId;
$qu_cur = $this->cur->get_by_key();
$pgNames = $qu_cur->row()->curName;
}
$arr[$i]['pgNames'] = $pgNames;
$con_qu_co = array('coId' => $row_co->coId);
$arr[$i]['qu_co'] = $this->co->qryCoJoinCrs($con_qu_co);
$i++;
} // end foreach
$con_rs_co = array('coCurId' => 'NULL',
'coAcY' => $acY,
'coSyId' => $syId,
'coTmId' => $tmId,
'cofCurId' => $curId
);
$rs_co = $this->co->qryCoJoinCofCrs($con_rs_co);
foreach ($rs_co->result() as $row_co) {
$j = 0;
$prsNames = '';
$con_rs_es = array('esCoId' => $row_co->coId,
'esExamType' => $exType
);
$rs_es = $this->es->qryEs($con_rs_es);
foreach ($rs_es->result() as $row_es) {
$con_qu_prs = array('prsId' => $row_es->esPrsId);
$qu_prs = $this->prs->qryPrsJoinPPC($con_qu_prs);
if ($qu_prs->num_rows()) {
if ($j == 0) {
$arr[$i]['esDate'] = $row_es->esDate;
$this->st->stId = $row_es->esStId;
$arr[$i]['qu_st'] = $this->st->get_by_key();
$this->rm->plHwId = $row_es->esRmId;
$arr[$i]['qu_rm'] = $this->rm->get_by_key();
$this->prd->prdId = $row_es->esPrdFrTime;
$arr[$i]['qu_prd1'] = $this->prd->get_by_key();
$this->prd->prdId = $row_es->esPrdToTime;
$arr[$i]['qu_prd2'] = $this->prd->get_by_key();
$prsNames = $qu_prs->row()->name;
} else {
$prsNames .= '<br />'.$qu_prs->row()->name;
}
}
$j++;
}
$arr[$i]['mtd'] = $j;
$arr[$i]['prsNames'] = $prsNames;
$pgNames = '';
if (is_null($row_co->coCurId)) {
$k = 0;
$con_rs_cof = array('cofCoId' => $row_co->coId);
$rs_cof = $this->cof->qryCofJoinCur($con_rs_cof);
foreach ($rs_cof->result() as $row_cof) {
if ($k == 0) {
$pgNames = $row_cof->curName;
} else {
$pgNames .= '<br /> '.$row_cof->curName;
}
$k++;
}
}
$arr[$i]['pgNames'] = $pgNames;
$con_qu_co = array('coId' => $row_co->coId);
$arr[$i]['qu_co'] = $this->co->qryCoJoinCrs($con_qu_co);
$i++;
}
$this->contents['rs'] = $arr;
$this->contents['rs_st2'] = $this->st->qrySt();
$this->output($this->config->item("rg_folder")."v_addExamSchedule");
}
}
function es_insert() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
$this->form_validation->set_rules('esStId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('esRmId', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('esPrdFrTime', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('esPrdToTime', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('esDate', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('prsId[]', ' ', 'trim|xss_clean');
if($this->form_validation->run() == true) {
$this->load->model($this->config->item("rg_folder").'mo_rg_examschedule','es');
$esDate = splitDateForm2($this->input->post('esDate'), '-');
$curId = $this->input->post('curId');
$syId = $this->input->post('syId');
$acY = $this->input->post('acY');
$tmId = $this->input->post('tmId');
$coId = $this->input->post('coId');
$exType = $this->input->post('exType');
$prsId = $this->input->post('prsId');
$esRmId = $this->input->post('esRmId');
$esStId = $this->input->post('esStId');
$esPrdFrTime = $this->input->post('esPrdFrTime');
$esPrdToTime = $this->input->post('esPrdToTime');
$msg = '';
// Delete All
$con_rs_es = array('esCoId' => $coId,
'esExamType' => $exType
);
$rs_es = $this->es->qryEs($con_rs_es);
foreach ($rs_es->result() as $row_es) {
$this->es->esCoId = $row_es->esCoId;
$this->es->esRmId = $row_es->esRmId;
$this->es->esExamType = $row_es->esExamType;
$this->es->esDate = $row_es->esDate;
$this->es->esPrdFrTime = $row_es->esPrdFrTime;
$this->es->esStId = $row_es->esStId;
$this->es->esPrsId = $row_es->esPrsId;
$this->es->delete();
}
$this->db->trans_begin();
// Insert All
for ($i = 0; $i < count($prsId); $i++) {
if ($prsId[$i]) {
$flag1 = $this->es->getCountByExTypeDateRmIdTime($exType, $esDate, $esRmId, $esPrdFrTime, $esPrdToTime);
// หา วันที่ เวลาในการใช้ห้องว่ามีหรือไม่
$flag2 = $this->es->getCountByDateTimePrsId($esDate, $esPrdFrTime, $esPrdToTime, $prsId[$i]);
// หาวันที่ และเวลาคุมสอบของอาจารย์
// หารายวิชาว่ามีการจัดตารางสอบแล้วหรือยัง
$con_rs_es = array( 'esCoId' => $coId,
'esExamType' => $exType
);
$cntCo = $this->es->getCountCoId($con_rs_es);
if ($cntCo) {
if ($flag2 == 0) {
$this->es->esCoId = $coId;
$this->es->esRmId = $esRmId;
$this->es->esExamType = $exType;
$this->es->esDate = $esDate;
$this->es->esPrdFrTime = $esPrdFrTime;
$this->es->esStId = $esStId;
$this->es->esPrdToTime = $esPrdToTime;
$this->es->esPrsId = $prsId[$i];
$this->es->insert();
} else {
$msg = "ไม่สามารถบันทึกข้อมูล วัน เวลาและห้องสอบซ้ำซ้อนกันได้<br />กรุณาตรวจสอบข้อมูลอีกครั้ง";
//$msg .= "<span class=\"hand\" onClick=\"sendPost('hidform', {'curId':".$curId.",'syId':".$syId.",'acY':".$acY.",'tmId':".$tmId.",'exType':'".$exType."'}, '".site_url($this->config->item("rg_folder")."preregis/es_input")."')\">คลิกที่นี่</span>"; //ค้าง
// $this->db->trans_rollback();
// $this->session->set_flashdata('msg', $msg);
// redirect($this->config->item("rg_folder")."msg/err_msg");
}
} else {
if (($flag1 == 0) && ($flag2 == 0)) {
$this->es->esCoId = $coId;
$this->es->esRmId = $esRmId;
$this->es->esExamType = $exType;
$this->es->esDate = $esDate;
$this->es->esPrdFrTime = $esPrdFrTime;
$this->es->esStId = $esStId;
$this->es->esPrdToTime = $esPrdToTime;
$this->es->esPrsId = $prsId[$i];
$this->es->insert();
} else {
$msg = "ไม่สามารถบันทึกข้อมูล วัน เวลาและห้องสอบซ้ำซ้อนกันได้<br />กรุณาตรวจสอบข้อมูลอีกครั้ง ";
//$msg .= "<span class=\"hand\" onClick=\"sendPost('hidform', {'curId':".$curId.",'syId':".$syId.",'acY':".$acY.",'tmId':".$tmId.",'exType':'".$exType."'}, '".site_url($this->config->item("rg_folder")."preregis/es_input")."')\">คลิกที่นี่</span>"; //ค้าง
// $this->db->trans_rollback();
// $this->session->set_flashdata('msg', $msg);
// redirect($this->config->item("rg_folder")."msg/err_msg");
}
} // end if
} // end if
} // end for
$this->db->trans_commit();
if ($msg) {
$this->session->set_flashdata('msg', $msg);
redirect($this->config->item("rg_folder")."msg/err_msg");
}
}
$this->es_input();
}
function checkOVLCourse(){
$this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');
$this->contents['acY'] = ($this->input->post('acY')) ? $this->input->post('acY') : $this->session->userdata('acY');
$this->contents['tmId'] = ($this->input->post('tmId')) ? $this->input->post('tmId') : $this->session->userdata('tmId');
if($this->input->post('btnSearth')){
$this->load->model($this->config->item("rg_folder").'mo_rg_timetable','tt');
$cond = array('coAcY' => $this->contents['acY'], 'coTmId' => $this->contents['tmId']);
$gpd = array('coAcY' => 'coAcY', 'coTmId' => 'coTmId', 'ttDyId' => 'ttDyId', 'ttRmId' => 'ttRmId', 'ttPrdFrTime' => 'ttPrdFrTime', 'ttPrdToTime' => 'ttPrdToTime');
$this->contents['rs_tt'] = $this->tt->qryTtJoinCo($cond,'',$gpd);
$this->contents['tt'] = $this->tt;
}
$this->contents['rs_tm'] = $this->tm->get_options('','','',FALSE);
$this->output($this->config->item("rg_folder")."v_searchCheckOVLCourse");
}
/*
เพิ่ม : สำหรับฟังก์ชั่นด้านล่างเป็นฟังก์ชั่น callback สำหรับตรวจสอบ validation
*/
// function checkAdY($str) {
// if($str=='') {
// $this->form_validation->set_message('checkAdY','กรุณาป้อน%s');
// return false;
// } else if(strlen($str)!=4) {
// $this->form_validation->set_message('checkAdY','%sจะต้องเท่ากับ 4 หลัก');
// return false;
// } else if($str==0) {
// $this->form_validation->set_message('checkAdY','%sจะต้องมากกว่า 0');
// return false;
// } else {
// return true;
// }
// }
// function checkAcY($str) {
// if($str=='') {
// $this->form_validation->set_message('checkAcY','กรุณาป้อน%s');
// return false;
// } else if(strlen($str)!=4) {
// $this->form_validation->set_message('checkAcY','%sจะต้องเท่ากับ 4 หลัก');
// return false;
// } else if($str==0) {
// $this->form_validation->set_message('checkAcY','%sจะต้องมากกว่า 0');
// return false;
// }
//
// if($str >= $this->input->post('adY')) {
// return true;
// } else {
// $this->form_validation->set_message('checkAcY','%sจะต้องมากกว่าหรือเท่ากับปีการศึกษาที่เข้า');
// return false;
// }
// }
// function checkAcYInTmc($str) {
// if($str=="") {
// $this->form_validation->set_message('checkAcYInTmc','กรุณาป้อนปีการศึกษา');
// return false;
// } else if(strlen($str)!=4) {
// $this->form_validation->set_message('checkAcYInTmc','ปีการศึกษาจะต้องมากกว่า 4 หลัก');
// return false;
// } else {
// $this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');
//
// $con_rs_tmc = array('tmcAcY' => $str);
// $grp_rs_tmc = array('tmcAcY' => 'tmcAcY');
// $rs_tmc = $this->tmc->qryTmc($con_rs_tmc,'',$grp_rs_tmc);
//
// if($rs_tmc->num_rows())
// return true;
// else
// $this->form_validation->set_message('checkAcYInTmc','ปีการศึกษาไม่ถูกต้อง');
// return false;
// }
// }
}
?>
|