Viewing file:      eregis2esa.php (7.44 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php
 include('sa_controller.php');
 class Eregis2esa extends Sa_controller {
 
     function index() {
         $this->load->model($this->config->item('rg_folder').'mo_rg_student','std');
 
         //$data['rs_std'] = $this->std->qryStdJoinPf();
         // ตั้งใจจะให้โชว์ข้อมูลที่ browse file
         $data = "";
 
         $this->output("v_import_std",$data);
     }
 
     function cur_insert() {
         $this->load->model($this->config->item('rg_folder').'mo_rg_curriculum','cur');
         $this->load->model($this->config->item('rg_folder').'mo_rg_generation','gen');
 
         $config['upload_path'] = './uploads/esa/';
         $config['allowed_types'] = 'csv';
         $config['encrypt_name'] = true;
 
         $this->load->library('upload', $config);
 
         if (!$this->upload->do_upload('uploadfile_cur')) {
             $this->session->set_flashdata('msg_submit', $this->upload->display_errors());
         } else {
             $data = $this->upload->data();
             $str = read_file($config['upload_path'].$data['file_name']);
             $lines = explode("\r\n", $str);
 
             $this->db->trans_begin();
             for ($i = 0; $i < count($lines); $i++) {
                 if ($lines[$i]) {
                     list($curName, $genAcY) = preg_split("/,/", $lines[$i]);
 
                     if ($curName && $genAcY) {
                         $genCurId = "";
                         $con_qu_cur = array('curName' => iconv('TIS-620', 'UTF-8', $curName));
                         $qu_cur = $this->cur->qryCur($con_qu_cur);
                         if ($qu_cur->num_rows() == 0) {
                             $this->cur->curImproveY = 0;
                             $this->cur->curName = iconv('TIS-620', 'UTF-8', $curName);
                             $this->cur->curNameE = "";
                             $this->cur->curAbbr = "";
                             $this->cur->curAbbrE = "";
                             $this->cur->curDescription = "";
                             $this->cur->curDescriptionE = "";
                             $this->cur->curMinCredit = 0;
                             $this->cur->curMinGPAX = 0;
                             $this->cur->curNumStudyY = 0;
                             $this->cur->curMaxStudyY = 0;
                             $this->cur->curNumTmPerY = 0;
                             $this->cur->curStatus = 'Y';
                             $this->cur->curCcId = 1;    // 1 fix ไว้เฉพาะกิจการของ คณะวิทย์&se
                             $this->cur->curEdgId = 1;    // 1
                             $this->cur->curElvId = 11;    // fix ปริญญาตรี
                             $this->cur->curGtpId = 1;    // 1
                             $this->cur->curCreateDate = date('Y-m-d H:i:s');
                             $this->cur->curCreateUserId = $this->session->userdata('UsLogin');
                             $this->cur->curUpdateDate = date('Y-m-d H:i:s');
                             $this->cur->curUpdateUsLogin = $this->session->userdata('UsLogin');
                             $this->cur->insert();
 
                             $genCurId = $this->cur->last_insert_id;
                         } else {
                             $genCurId = $qu_cur->row()->curId;
                         }    // end cur
 
                         $con_qu_gen = array('genAcY' => $genAcY,
                             'genCurId' => $genCurId,
                             'genTmId' => 1
                         );
                         $qu_gen = $this->gen->qryGen($con_qu_gen);
                         if ($qu_gen->num_rows() == 0) {
                             $this->gen->genAcY = $genAcY;
                             $this->gen->genNo = "";
                             $this->gen->genCurId = $genCurId;
                             $this->gen->genTmId = 1;
                             $this->gen->insert();
                         }    // end gen
                     }    // end if curName, genAcY
                 }    // end if lines
             }    // end for
             if($this->db->trans_status() === false) {
                 $this->db->trans_rollback();
                 $this->session->set_flashdata('msg_submit', "<font color=\"red\">นำเข้าข้อมูลหลักสูตรล้มเหลว</font>");
             } else {
                 $this->db->trans_commit();
                 $this->session->set_flashdata('msg_submit', "<font color=\"green\">นำเข้าข้อมูลหลักสูตรเรียบร้อย</font>");
             }
         }
 
         unlink($config['upload_path'].$data['file_name']);
         redirect($this->config->item("sa_folder").'eregis2esa');
     }
 
     function std_insert() {
         $this->load->model($this->config->item('rg_folder').'mo_rg_curriculum','cur');
         $this->load->model($this->config->item('rg_folder').'mo_rg_prefix','pf');
         $this->load->model($this->config->item('rg_folder').'mo_rg_student','std');
 
         $config['upload_path'] = './uploads/esa/';
         $config['allowed_types'] = 'csv';
         $config['encrypt_name'] = true;
 
         $this->load->library('upload', $config);
 
         if (!$this->upload->do_upload('uploadfile_std')) {
             $this->session->set_flashdata('msg_submit', $this->upload->display_errors());
         } else {
             $data = $this->upload->data();
             $str = read_file($config['upload_path'].$data['file_name']);
             $lines = explode("\r\n", $str);
 
             $this->db->trans_begin();
             $chk_cur = 0;
             for ($i = 0; $i < count($lines); $i++) {
                 if ($lines[$i]) {
                     list($stdCode, $pfName, $stdName, $stdNameE, $stdSurname, $stdSurnameE, $curName, $stdAdY) = preg_split("/,/", $lines[$i]);
 
                     $con_qu_cur = array('curName' => iconv('TIS-620', 'UTF-8', $curName));
                     $qu_cur = $this->cur->qryCur($con_qu_cur);
 
                     if($qu_cur->num_rows() == 0) {
                         if($curName=="") {
                             continue;
                         }
                         $chk_cur = 1;
                         break;
                     }
 
                     $con_qu_std = array('stdCode' => $stdCode);
                     $qu_std = $this->std->qryStd($con_qu_std);
                     if ($qu_std->num_rows()) {
                         if($stdCode=="") {
                             continue;
                         }
                     }
 
                     $con_qu_pf = array('prefixName' => iconv('TIS-620', 'UTF-8', $pfName));
                     $qu_pf = $this->pf->qryPf($con_qu_pf);
                     if ($qu_pf->num_rows() == 0) {
                         if($pfName=="") {
                             continue;
                         }
                     }
 
                     if ($stdCode!="" && $pfName!="" && $stdName!="" && $stdNameE!="" && $stdSurname!="" && $stdSurnameE!="" && $curName!="" && $stdAdY!="") {
                         $this->std->stdCode = $stdCode;
                         $this->std->stdName = iconv('TIS-620', 'UTF-8', $stdName);
                         $this->std->stdNameE = $stdNameE;
                         $this->std->stdSurname = iconv('TIS-620', 'UTF-8', $stdSurname);
                         $this->std->stdSurnameE = $stdSurnameE;
                         $this->std->stdCreditAttempt = 0;
                         $this->std->stdCreditSatisfy = 0;
                         $this->std->stdGPA = 0;
                         $this->std->stdAdY = $stdAdY;
                         $this->std->stdAdmitDate = "";
                         $this->std->stdGraduateY = 0;
                         $this->std->stdGraduateDate = "";
                         $this->std->stdTotalPoint = "";
                         $this->std->stdExitExam = "";
                         $this->std->stdGenStatus = 'Y';
                         $this->std->stdPfId = $qu_pf->row()->prefixId;
                         $this->std->stdCurId = $qu_cur->row()->curId;
                         $this->std->stdTmIdAdmit = 1;    // fix
                         $this->std->stdSyId = 1;        // fix
                         $this->std->stdSstId = 1;        // fix
                         $this->std->stdGenId = 1;        // fix
                         $this->std->stdEtId = 1;        // fix
                         $this->std->stdEt2Id = 1;        // fix
                         $this->std->stdSoId = 1;        // fix
                         $this->std->stdFsId = 1;        // fix
                         $this->std->stdGtpId = 1;        // fix
                         $this->std->stdSstIdTmp = 1;
                         $this->std->stdUpdateUsLogin = $this->session->userdata('UsLogin');
 
                         if($qu_std->num_rows()==0) {
                             $this->std->insert();
                         }
                     }
                 }
             }
 
             if($this->db->trans_status() === false) {
                 $this->db->trans_rollback();
                 $this->session->set_flashdata('msg_submit', "<font color=\"red\">นำเข้าข้อมูลนักศึกษาล้มเหลว</font>");
             } else if($chk_cur==1) {
                 $this->db->trans_rollback();
                 $this->session->set_flashdata('msg_submit', "<font color=\"red\">ยังไม่ได้เพิ่มหลักสูตร</font>");
             } else {
                 $this->db->trans_commit();
                 $this->session->set_flashdata('msg_submit', "<font color=\"green\">นำเข้าข้อมูลนักศึกษาเรียบร้อย</font>");
             }
         }
 
         unlink($config['upload_path'].$data['file_name']);
         redirect($this->config->item("sa_folder").'eregis2esa');
     }
 }
  |