Viewing file:      timetable.php (20.29 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php /**  * timetable class  * สำหรับจัดการตารางสอน  * @author Sitthichai  */
  include("rg_controller.php"); class timetable extends Rg_controller {
      var $condition = Array();     var $order = Array();     var $group = Array();     var $option = '';     var $sess_prsItId = "";     var $sess_prsUsId = "";     var $json_data = Array(         'error' => 1,         'html' => 'Ajax Error: Invalid Request',     );     public function __construct()     {         parent::__construct();         $personId = $this->session->userdata('UsPsCode');         $this->sess_prsItId = 1;         $this->sess_prsUsId = $personId;         if(substr($personId, 0, 5)=='psout') {             $this->sess_prsItId = 2;             $this->sess_prsUsId = substr($personId, 5);         }     }     /**      * สำหรับบันทึกตารางสอน หรือจัดตารางสอน      */     function arranged_schedule($mode){     if($mode=="teacher" or $mode=="default" or $mode=="view"){         $this->load->model($this->config->item("rg_folder").'mo_rg_termconfig','tmc');         $this->load->model($this->config->item("rg_folder").'mo_rg_term','tm');                  $group_AcY = array('tmcAcY'=>'tmcAcY');         $rs_tmc= $this->tmc->get_options('',array('tmcAcY'=>'DESC'),$group_AcY);                  $this->contents['tmc'] = $rs_tmc;                  $this->contents['tm'] = $this->tm->get_options('',array('tmName'=>''),'','N');
          $this->contents['mode'] = $mode;                  if($this->session->userdata('UsPsCode')){             $this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');             $con_ps = array('prsUsId'=>$this->sess_prsUsId);             $qu_ps= $this->prs->qryPrsJoinPPC($con_ps);             $prsId = (isset($qu_ps) && $qu_ps!=NULL && $qu_ps->num_rows()>0) ? $qu_ps->row()->prsId : NULL;             $this->contents['per'] = $prsId;         }          //  หาวันทั้งหมด วัน         $this->load->model($this->config->item("rg_folder").'mo_rg_day','dy');         $this->condition = '';         $this->group = '';         $this->option = '';         $this->order = array('dyId'=>'');         $this->contents['dy'] = $this->dy->qryDy($this->condition,$this->order,$this->group,$this->option);
  //  หาคาบเรียน เวลาเริ่มต้นเรียน                     $this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');         $this->condition = '';         $this->group = '';         $this->option = '';         $this->order = array('prdId'=>'');         $this->contents['prdFr'] = $this->prd->get_options_frTime($this->condition,$this->order,$this->group,$this->option);                  $this->load->model($this->config->item("rg_folder").'mo_rg_room','room');         $rm = $this->room->get_Room(array('plIsRoom'=>'Y'),array('plRmNo'=>''),'','');         $this->contents['rm'] = $rm;                  if($this->session->flashdata('dt')){             $this->contents['dt'] = $this->session->flashdata('dt');         }                  /*if($this->session->userdata('dt')){             $this->contents['dt'] = $this->session->userdata('dt');         }*/
          //$this->output($this->config->item("rg_folder")."v_ttArrangedSchedule",$this->session->flashdata('msg'));         $this->output($this->config->item("rg_folder")."v_ttArrangedSchedule", $this->session->flashdata('msg'));         }     }
      function opt_timetable_detail(){         //$rmId = $this->input->post('rmId');     }
      function get_mep(){         $prdFrTime=2;         $prdToTime=3; //  หาคาบเรียน เวลาสิ้นสุดคาบเรียน                         $this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');             $this->condition = array('1'=>'1');             $this->group = '';             $this->option = '';             $this->order = array('prdId'=>'');             $this->prd->prdId = $prdFrTime;
              $qu = $this->prd->get_options_toTime($this->condition,$this->order,$this->group,$this->option);
              $attr = 'id="prdToTime" onChange="get_option();"';             echo form_dropdown('prdToTime',$qu,$prdToTime,$attr);
  echo $this->db->last_query(); print_r($qu);         //print_r($qu);     }
      function get_option(){         if ($this->input->server('REQUEST_METHOD') === 'POST')         {             $tmcAcY = $this->input->post('tmcAcY');             $tmId = $this->input->post('tmId');             $curId = $this->input->post('curId');             $syId = $this->input->post('syId');             $crsId = $this->input->post('crsId');             $coSection = $this->input->post('coSection');             $mepId = $this->input->post('mepId');             $sepId = $this->input->post('sepId');             $wdAcYWeekNo = $this->input->post('wdAcYWeekNo');             $numWeek = $this->input->post('numWeek');             $dyId = $this->input->post('dyId');             $prdFrTime = $this->input->post('prdFrTime');             $prdToTime = $this->input->post('prdToTime');             $prsId = $this->input->post('prsId');             $stId = $this->input->post('stId'); //            $this->json_data['tt'] = "tmcAcY:$tmcAcY / tmId:$tmId";
  //    $this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');
          //หาสิทธิ์         if($curId=="NULL"){             $id = "0";         }else if(!$this->input->post('curId')){             $id = "0";         }else{             $id = $this->input->post('curId');         }         $this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');         $this->load->model($this->config->item("rg_folder").'mo_rg_personpermission','pp');         $prs_con = array('prsUsId'=>$this->sess_prsUsId,'prsItId'=>$this->sess_prsItId);         $qu_prs = $this->prs->qryPrs($prs_con);         
          if ($qu_prs->num_rows() > 0)         {             $row_prs = $qu_prs->row();             $pp_con = array('ppPrsId'=>$row_prs->prsId,'ppAcY'=>$tmcAcY,'ppTmId'=>$tmId,'ppCurId'=>$id);             $qu_pp = $this->pp->qryPp($pp_con);                          if ($qu_pp->num_rows() > 0)             {                 $row = $qu_pp->row();                 $this->json_data['pp'] = $row->ppTT;             } else{                 $this->json_data['pp'] = "N";             }         }else{             $this->json_data['pp'] = "N";         }
  ///   ค้นหา หลักสูตร              $this->load->model($this->config->item("rg_folder").'mo_rg_curriculum','cur');             $this->load->model($this->config->item("rg_folder").'mo_rg_courseopen','co');             $this->condition = array_merge($this->condition, array('coAcY'=>$tmcAcY,'coTmId'=>$tmId));             $this->group = array( 'curId'=>'curName' );             $this->option = '-- เลือกหลักสูตร --';             //$qu = $this->co->qry_optionCo($this->condition,$this->order,$this->group,$this->option);             $con_cur = array('curStatus'=>'Y');             $qu = $this->cur->get_options($con_cur,$this->order,$this->group,$this->option);                          if(count($qu)==1){                 $qu[''] = '-- ไม่พบหลักสูตรที่เปิดใน ภาคการศึกษานี้ --';             }else{                 unset($qu['']);                 $qu['NULL'] = 'เรียนรวมหลายหลักสูตร';                  ksort($qu);             }             $attr = 'id="curId" onChange="Sync(this.id);get_option();checkSubmit();timeTable();"';             $this->json_data['cur'] = form_dropdown('curId',$qu,$curId,$attr);                          //$tb_con = array('coAcY'=>$tmcAcY);             $con_cur = array('curStatus'=>'Y');             $this->group = array( 'curId'=>'curName' );             $this->option = 'เรียนรวมหลายหลักสูตร';             $qu = $this->cur->get_options($con_cur,$this->order,$this->group,$this->option);                                       if(count($qu)==1){                 $qu[''] = '-- ไม่พบหลักสูตรที่เปิดใน ภาคการศึกษานี้ --';             }else{                 unset($qu['']);                 $qu['NULL'] = '-- เรียนรวมหลักสูตร --';                  ksort($qu);             }             $tbcurId = $this->input->post('tbcurId');             $attr = 'id="tbcurId" onChange="get_option();checkSubmit();timeTable();"'; //Sync(this.id);             $this->json_data['tbcur'] = form_dropdown('tbcurId',$qu,$tbcurId,$attr);              //   ค้นหาชั้นปี              if(!$this->input->post('curId')){                 $curId = "NULL";             }             $this->load->model($this->config->item("rg_folder").'mo_rg_studyyear','sy');             $this->condition = array_merge($this->condition, array('curId'=>$curId));             $this->order = array('syCode'=>'');             $this->option = '-- เลือกชั้นปี --';             $qu = $this->sy->get_options2('',$this->order,'','N');             //echo $this->db->last_query();             if(count($qu)==1){                 $qu[''] = '-- ไม่พบชั้นปี --';             }                          $attr = 'id="syId" onChange="Sync(this.id);get_option();checkSubmit();"';             $this->json_data['sy'] = form_dropdown('syId',$qu,$syId,$attr);                          if(!$this->input->post('tbcurId')){                 $tbcurId = "NULL";             }             //$tb_con = array('coAcY'=>$tmcAcY,'curId'=>$tbcurId);                          $this->order = array('syCode'=>'');             $this->option = '-- เลือกชั้นปี --';             $qu = $this->sy->get_options2('',$this->order,'','N');             //echo $this->db->last_query();             if(count($qu)==1){                 $qu[''] = '-- ไม่พบชั้นปี --';             }             $tbsyId = $this->input->post('tbsyId');             $attr = 'id="tbsyId" onChange="checkSubmit();timeTable();"';              $this->json_data['tbsy'] = form_dropdown('tbsyId',$qu,$tbsyId,$attr);              //  ค้นหารายวิชา              $this->condition = array_merge($this->condition, array('syId'=>$syId));             $this->group = array('crsId'=>'crsName');             $this->option = '-- เลือกรายวิชา --';             $qu = $this->co->qry_optionCo($this->condition,$this->order,$this->group,$this->option);
              if(count($qu)==1){                 $qu[''] = '-- ไม่พบรายวิชา --';             }             $attr = 'id="crsId" onChange="get_option();checkSubmit();"';             $this->json_data['crs'] = form_dropdown('crsId',$qu,$crsId,$attr);              //  ค้นหากลุ่ม              $this->condition = array_merge($this->condition, array('crsId'=>$crsId));             $this->order = array('coSection'=>'');             $this->group = array('coSection'=>'coSection');             $this->option = '';             $qu = $this->co->qry_optionCo($this->condition,$this->order,$this->group,$this->option);             if(count($qu)>1){                 $qu['%'] = '-- ทุกกลุ่ม --';                 ksort($qu);             }             if(count($qu)==0){                 $qu[''] = '-- ไม่พบ --';             }             $attr = 'id="coSection" onChange="get_option();checkSubmit();"';             $this->json_data['coSection'] = form_dropdown('coSection',$qu,$coSection,$attr);
  //   ค้นหา สถานที่ฝึกหลัก              $this->load->model($this->config->item("rg_folder").'mo_rg_externalplace','etp');             $this->condition =  '';             $this->group = array('mepId'=>'mepName');             $this->option = '-- เลือกสถานที่ฝึกหลัก --';             $this->order = '';             $qu = $this->etp->mep_optionsJoinMepSep($this->condition,$this->order,$this->group,$this->option);             if(count($qu)>=1){                 $attr = 'id="mepId" onChange="get_option();checkSubmit();"';                 $this->json_data['mep'] = form_dropdown('mepId',$qu,$mepId,$attr).' : ';                                  $attr = 'id="tbmepId" onChange="Sync(this.id);"';                 $this->json_data['tbmep'] = form_dropdown('tbmepId',$qu,$mepId,$attr);             }else{                 $qu[''] = '-- ไม่พบสถานฝึกหลัก --';                 $this->json_data['mep'] = form_dropdown('mepId',$qu,$mepId,$attr).' : ';                 $this->json_data['tbmep'] = form_dropdown('tbmepId',$qu,$mepId,$attr);             }             
              if($mepId!=''){                  $cond = array('mepId'=>$mepId); //   ค้นหา สถานที่ฝึกย่อย                  $this->condition = $cond ;                 $this->group = array('sepId'=>'sepId');                 $this->option = '';                 $this->order = '';                 $qu = $this->etp->sep_optionsJoinMepSep($this->condition,$this->order,$this->group,$this->option);                 /*if(count($qu)>1){                     $qu['%'] = '--เลือกสถานที่ฝึกย่อย --';                     ksort($qu);                 }*/                 if(count($qu)>=1){                    $attr = 'id="sepId" onChange="get_option();checkSubmit();"';                     $this->json_data['sep'] = form_dropdown('sepId',$qu,$sepId,$attr);                                          $attr = 'id="tbsepId" onChange="Sync(this.id);"';                     $this->json_data['tbsep'] = form_dropdown('tbsepId',$qu,$sepId,$attr);                 }else{                     $this->json_data['sep'] = "";                     $this->json_data['tbsep'] = "";                 }                                  //$this->json_data['sep'] = $this->db->last_query();             }else{                 $this->json_data['sep'] = '';                 $this->json_data['tbsep'] = '';             }              //   ค้นหา สัปดาห์              $this->load->model($this->config->item("rg_folder").'mo_rg_weekdate','wd');             $this->condition = array('wdAcY'=>$tmcAcY);             $this->group = '';             $this->option = '';             $this->order = '';//array('wdAcYWeekNo'=>'');             $qu = $this->wd->opt_WeekNoFrToDate($this->condition,$this->order,$this->group,$this->option);
              if(count($qu)==0){                 $qu[0] = '-- ไม่พบหลักสูตรที่เปิดใน ปีศึกษานี้ --';             }             $attr = 'id="wdAcYWeekNo" onChange="get_option();"';             $this->json_data['wd'] = form_dropdown('wdAcYWeekNo',$qu,(setValue('wdAcYWeekNo',$wdAcYWeekNo) == '')? $wdAcYWeekNo : setValue('wdAcYWeekNo',$wdAcYWeekNo),$attr);             $attr = 'id="tbwdAcYWeekNo" onChange="Sync(this.id);"';             $this->json_data['tbwd'] = form_dropdown('tbwdAcYWeekNo',$qu,$wdAcYWeekNo,$attr);                          $attr = 'id="tbwdAcYWeekNo" onChange="timeTable();"';             $this->json_data['tbwd2'] = form_dropdown('tbwdAcYWeekNo',$qu,$wdAcYWeekNo,$attr);              //   gen จำนวนวัน             $opt = Array();             $weekNum = 1;             while($weekNum <= count($qu)-$wdAcYWeekNo+1) {                 $opt[$weekNum] = $weekNum;                 $weekNum++;             }             $attr = 'id="numWeek" onChange="get_option();"';             $this->json_data['numWeek'] = form_dropdown('numWeek',$opt,$numWeek,$attr);
  //  หาวันทั้งหมด วัน             $this->load->model($this->config->item("rg_folder").'mo_rg_day','dy');             $this->condition = '';             $this->group = '';             $this->option = '';             $this->order = array('dyId'=>'');             $qu = $this->dy->qryDy($this->condition,$this->order,$this->group,$this->option);
              $attr = 'id="dyId" onChange="get_option();"';             $this->json_data['dy'] = form_dropdown('dyId',$qu,$dyId,$attr);              //  หาคาบเรียน เวลาสิ้นสุดคาบเรียน                         $this->load->model($this->config->item("rg_folder").'mo_rg_period','prd');             $this->condition = array('1'=>'1');             $this->group = '';             $this->option = '';             $this->order = array('prdId'=>'');             $this->prd->prdId = $prdFrTime;
              $qu = $this->prd->get_options_toTime($this->condition,$this->order,$this->group,$this->option);             $attr = 'id="prdToTime" onChange="get_option();"';             $this->json_data['prdTo'] = form_dropdown('prdToTime',$qu,$prdToTime,$attr);              //  ค้นหาชื่ออาจารย์ผู้สอน             $this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');             $this->condition = array('prsPsId'=> 1);             $this->group = '';             $this->option = '';             $this->order = array('fname'=>'','lname'=>'');
              $qu = $this->prs->get_options($this->condition,$this->order,$this->group,$this->option);                          if(count($qu)>=2){                 $attr = 'id="prsId" onChange="get_option();"';                 $this->json_data['prs'] = form_dropdown('prsId',$qu,$prsId,$attr);                                  $attr = 'id="tbprsId" onChange="Sync(this.id);getExam();"';                 $this->json_data['tbprs'] = form_dropdown('tbprsId',$qu,$prsId,$attr);             }else{                 $this->json_data['tbprs'] = "";                 $this->json_data['prs'] = "";             } //  ค้นหาประเภทการสอน             $this->load->model($this->config->item("rg_folder").'mo_rg_studytype','st');             $this->condition = '';             $this->group = '';             $this->option = '';             $this->order = array('stId'=>'');
              $qu = $this->st->get_options($this->condition,$this->order,$this->group,$this->option);             $attr = 'id="stId" onChange="get_option();checkSubmit();"';             if(count($qu)>=1){                 $this->json_data['st'] = form_dropdown('stId',$qu,$stId,$attr);             }else{                 $this->json_data['st'] = "";             }             /*         $this->json_data['tt'] =$this->db->last_query();//form_dropdown('prdToTime',$qu); */             $this->json_data['error'] = 0;             echo json_encode($this->json_data);             //echo "tmcAcY : $tmcAcY || tmId : $tmId";         }     }
      // ##### start แสดงวิธีการสอน     function tcm_popup() {         $this->load->model($this->config->item("rg_folder").'mo_rg_teachingmethod','tcm');             $condition = '';             $group = '';             $order = array('tcmName'=>'');
          $this->contents['qu'] = $this->tcm->qryTcm_2($condition,$order,$group);         $this->output_detail($this->config->item("rg_folder")."v_checkboxTcm");     }     // ##### end จบแสดงวิธีการสอน
      // ##### start แสดงอาจารย์ผู้สอน     function prs_popup() {         $this->load->model($this->config->item("rg_folder").'mo_rg_person','prs');             $condition = array('prsPsId' => 1);             $order = array('fName' => '',                 'lName' => ''             );
          $this->contents['qu'] = $this->prs->qryPrsJoinPPC($condition, $order);         $this->output_detail($this->config->item("rg_folder")."v_checkboxPrs");
      }     // ##### end จบแสดงอาจารย์ผู้สอน          function search(){         $this->load->model($this->config->item("rg_folder").'m_rg_weekdate','wd');         $wd = $this->wd;         $this->contents['opt_wd'] = $wd->get_options("",array('wdAcY'=>'wdAcY'),array('wdAcY'=>'wdAcY'), false);              }
      function showTimetable(){         $acY = 2554;         $wdAcYWeekNo = 1;         $this->load->model($this->config->item("rg_folder").'m_rg_Day','dy');         $dy = $this->dy;         $this->load->model($this->config->item("rg_folder").'mo_rg_Period','prd');         $prd = $this->prd;         $this->load->model($this->config->item("rg_folder").'mo_rg_timetable','tt');         $tt = $this->tt;         $condition = array('1'=>'1');         $order = array('prdId'=>'');         $qu_prd = $prd->qryPrd($condition,$order);         $qu_dy = $dy->qryOrderId();
          $show_table = array();         $show_table[0][0] = 'วัน\เวลา';         if($qu_prd->num_rows > 0 && $qu_dy->num_rows > 0) {             foreach($qu_prd->result() as $prd_row){                 $show_table[0][$prd_row->prdId] = $prd_row->prdId.'<br>'.substr($prd_row->prdFrTime, 0, 5).'-'.substr($prd_row->prdToTime, 0, 5);             }             foreach($qu_dy->result() as $dy_row){                 $show_table[$dy_row->dyId][0] = $dy_row->dyName;
  //                foreach($qu_prd->result() as $prd_row){                     // ค้นหา ตารางเรียนใน dy & prd
  $show_table[$dy_row->dyId][$prd_row->prdId] = "[ $dy_row->dyId ][ $prd_row->prdId ]"; //$row->prdId.'<br>'.substr($prd_row->prdFrTime, 0, 5).'-'.substr($row->prdToTime, 0, 5); //---------------------------------------------------------                                          $condition = array( 'coAcY' =>$coAcY ,                                     'wdAcYWeekNo'=>$wdAcYWeekNo ,                                     'coCrsId'=>$coCrsId ,                                     'ttDyId'=>$dy_row->dyId ,                                 );                     // tt->searchBy($prd_row->prdFrTime) //                }             }         }         $this->contents['timetable'] = $show_table;         $this->output($this->config->item("rg_folder")."v_showTimeTable");     } }
  |