Viewing file:      attend.php (19.67 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php include('sa_controller.php'); class Attend extends Sa_controller {     // Start Ajax     function get_acp ($mpj_id="") {         $this->load->model($this->config->item("sa_folder").'sa_detail_project_model', 'dpj');
          $options = array();         $options[''] = "";         if ($mpj_id) {             $this->dpj->dpj_mpj_id = $mpj_id;             $rs_dpj = $this->dpj->get_detail();             foreach ($rs_dpj->result() as $row) {                 $options[$row->dpj_id] = $row->dpj_sub_name;             }         }         $js = "id=\"mb_acp_id\" class=\"req-4\" onChange=\"acp_change_cur()\"";         echo form_dropdown('mb_acp_id', $options, '',$js);         echo " <span class=\"error\">*</span>";     }
      function get_cur ($dpj_id="") {         $this->load->model($this->config->item("sa_folder").'sa_target_group_model', 'tg');         $this->load->model($this->config->item("rg_folder").'mo_rg_curriculum', 'cur');
          $options = array();         $options[''] = "";         if ($dpj_id) {             $this->tg->tg_type = 1;             $this->tg->tg_dpj_id = $dpj_id;             $rs_tg = $this->tg->get_by_dpj_type();             foreach ($rs_tg->result() as $row) {                 $this->cur->curId = $row->tg_cur_id;                 $qu_cur = $this->cur->get_by_key();                 if ($qu_cur->num_rows()) {                     $options[$row->tg_cur_id] = $qu_cur->row()->curName;                 }             }         } else {             $con_rs_cur = array('curStatus' => 'Y');             $options = $this->cur->get_options($con_rs_cur);         }         $js = "id=\"cur_id\"";         echo form_dropdown('cur_id', $options, '',$js);     }
      function get_smo ($dpj_id="") {         $this->load->model($this->config->item("sa_folder").'sa_smo_club_model', 'smo');
          $options = array();         $options[''] = "";         if ($dpj_id) {             $rs_tg = $this->smo->get_by_dpj($dpj_id);                          foreach ($rs_tg->result() as $row) {                 $options[$row->sc_id] = $row->sc_name;             }         }         $js = "id=\"tg_sc_id\""; //class=\"req-5\"         echo form_dropdown('tg_sc_id', $options, '',$js);         echo " <span class=\"error\">*</span>";     }
      function get_sy ($dpj_id="") {         $this->load->model($this->config->item("sa_folder").'sa_target_group_model', 'tg');         $this->load->model($this->config->item("rg_folder").'mo_rg_studyyear', 'sy');
          $options = array();         $options[''] = "";         if ($dpj_id) {             $this->tg->tg_type = 1;             $this->tg->tg_dpj_id = $dpj_id;             $rs_tg = $this->tg->get_by_dpj_type();             foreach ($rs_tg->result() as $row) {                 $this->sy->syId = $row->tg_tm_id;                 $qu_sy = $this->sy->get_by_key();                 if ($qu_sy->num_rows()) {                     $options[$row->tg_tm_id] = $qu_sy->row()->syName;                 } else {                     $options['NULL'] = "ทุกชั้นปี";                     //$options = $this->sy->get_options();                 }             }         } else {             $options = $this->sy->get_options();         }         $js = "id=\"sy_id\"";         echo form_dropdown('sy_id', $options, '',$js);     }     // End Ajax
      function mb_input() {         $this->load->model($this->config->item('sa_folder').'sa_member_model','mb');         $this->load->model($this->config->item('sa_folder').'sa_smo_club_model','sc');         $this->load->model($this->config->item('sa_folder').'sa_detail_project_model','dpj');         $this->load->model($this->config->item('rg_folder').'mo_rg_term','tm');         $this->load->model($this->config->item('rg_folder').'mo_rg_studyyear','sy');         $this->load->model($this->config->item('rg_folder').'mo_rg_curriculum','cur');
          $mb_id = $this->input->post('mb_id');         $type = $this->input->post('type');         $rs = explode("###", $this->input->post('wk11_co'));         $mb_smo_id = $this->input->post('mb_smo_id');         $mb_cl_id = $this->input->post('mb_cl_id');         $mb_mpj_id = $this->input->post('mb_mpj_id');         $mb_acp_id = $this->input->post('mb_acp_id');         $mb_year = $this->input->post('mb_year');         $mb_fr_date = $this->input->post('mb_fr_date') ? splitDateForm2($this->input->post('mb_fr_date'), '-') : getNowDate();         $mb_to_date = $this->input->post('mb_to_date') ? splitDateForm2($this->input->post('mb_to_date'), '-') : getNowDate();
          $this->mb->mb_id = $mb_id;         $qu_mb = $this->mb->get_by_key_2();         if ($qu_mb->num_rows()) {             $data['qu_mb'] = $qu_mb;             $row_mb = $qu_mb->row();
              if ($row_mb->mb_smo_id) {                 $type = 1;             } else if ($row_mb->mb_cl_id) {                 $type = 2;             } else if ($row_mb->mb_mpj_id && is_null($row_mb->mb_acp_id)) {                 $type = 3;             } else if ($row_mb->mb_acp_id) {                 $type = 4;
                  $this->dpj->dpj_mpj_id = $row_mb->mb_mpj_id;                 $data['rs_acp'] = $this->dpj->get_detail();             }         }         $data['type'] = $type;
          $data['rs_type'] = array("", "สโมสร", "ชมรม", "โครงการ", "กิจกรรม");
          $this->sc->sc_type = 1;         $data['rs_smo'] = $this->sc->get_by_type();
          $this->sc->sc_type = 2;         $data['rs_cl'] = $this->sc->get_by_type();
          $this->dpj->dpj_mpj_id = 0;         $data['rs_mpj'] = $this->dpj->get_detail();
          $data['rs_tm'] = $this->tm->get_options();         $data['rs_sy'] = $this->sy->get_options();         $data['rs_sy'] = $this->sy->get_options();         $this->sc->sc_type = 0;         $data['rs_opsmo'] = $this->sc->get_optionsByType('n');         $con_rs_cur = array('curStatus' => 'Y');         $data['rs_cur'] = $this->cur->get_options($con_rs_cur);
          $data['rs_mb'] = $this->mb->get_by_cond($mb_fr_date, $mb_to_date, $mb_year);         if ($rs) {             foreach ($rs as $value) {                 $std = explode(":", $value);                 $data['rs_mb'] = $this->mb->get_by_cond($mb_fr_date, $mb_to_date, $mb_year, $std[0]);
                  if ($type == 1) {                     if ($mb_smo_id) {                         $data['rs_mb'] = $this->mb->get_by_cond($mb_fr_date, $mb_to_date, $mb_year, $std[0], $mb_smo_id);                     }                 } else if ($type == 2) {                     if ($mb_cl_id) {                         $data['rs_mb'] = $this->mb->get_by_cond($mb_fr_date, $mb_to_date, $mb_year, $std[0], '', $mb_cl_id);                     }                 } else if ($type == 3) {                     if ($mb_mpj_id) {                         $data['rs_mb'] = $this->mb->get_by_cond($mb_fr_date, $mb_to_date, $mb_year, $std[0], '', '', $mb_mpj_id);                     }                 } else if ($type == 4) {                     if ($mb_mpj_id) {                         $data['rs_mb'] = $this->mb->get_by_cond($mb_fr_date, $mb_to_date, $mb_year, $std[0], '', '', '', $mb_acp_id);                     }                 }             }         }
          $this->output("v_attend",$data);     }
      function mb_insert_update() {         $this->load->library('form_validation');         $this->form_validation->set_error_delimiters('<div class="error">', '</div>');         $this->form_validation->set_rules('mb_id', ' ', 'trim|xss_clean');         $this->form_validation->set_rules('type', ' ', 'trim|required|is_natural_no_zero|xss_clean');
          $mb_id = $this->input->post('mb_id');         $type = $this->input->post('type');         $choice = $this->input->post('choice');         $std_id = $this->input->post('std_id');
          if ($choice == 1) {             if ($mb_id) {                 $this->form_validation->set_rules('std', ' ', 'trim|required|xss_clean');             } else {                 $this->form_validation->set_rules('wk11_co', ' ', 'trim|required|xss_clean');             }         } else if ($choice == 2) {             if (($type == 3) || ($type == 4)) {                 $this->form_validation->set_rules('cur_id', ' ', 'trim|required|xss_clean');                 $this->form_validation->set_rules('sy_id', ' ', 'trim|required|xss_clean');             } else {                 $this->form_validation->set_rules('cur_id', ' ', 'trim|xss_clean');                 $this->form_validation->set_rules('sy_id', ' ', 'trim|xss_clean');             }         } else if ($choice == 3) {             if (($type == 3) || ($type == 4)) {                 $this->form_validation->set_rules('tg_sc_id', ' ', 'trim|required|xss_clean');             } else {                 $this->form_validation->set_rules('tg_sc_id', ' ', 'trim|xss_clean');             }         }
          if ($type == 1) {             $this->form_validation->set_rules('mb_smo_id', ' ', 'trim|required|xss_clean');         } else if ($type == 2) {             $this->form_validation->set_rules('mb_cl_id', ' ', 'trim|required|xss_clean');         } else if ($type == 3) {             $this->form_validation->set_rules('mb_mpj_id', ' ', 'trim|required|xss_clean');         } else if ($type == 4) {             $this->form_validation->set_rules('mb_mpj_id', ' ', 'trim|required|xss_clean');             $this->form_validation->set_rules('mb_acp_id', ' ', 'trim|required|xss_clean');         }
          $this->form_validation->set_rules('mb_year', ' ', 'trim|required|xss_clean');         $this->form_validation->set_rules('mb_tmId', ' ', 'trim|required|xss_clean');         $this->form_validation->set_rules('mb_syId', ' ', 'trim|required|xss_clean');         $this->form_validation->set_rules('mb_fr_date', ' ', 'trim|required|xss_clean|callback_checkFrDate[mb_to_date]');         $this->form_validation->set_rules('mb_to_date', ' ', 'trim|required|xss_clean');
          if ($this->form_validation->run() == FALSE) {             $this->mb_input();         } else {             $this->db->trans_begin();
              $this->load->model($this->config->item('rg_folder').'mo_rg_student','std');             $this->load->model($this->config->item('sa_folder').'sa_member_model','mb');             $this->load->model($this->config->item('sa_folder').'sa_target_group_model','tg');
              if ($choice == 1) {                 $rs = explode("###", ($this->input->post('std') ? $this->input->post('std') : $this->input->post('wk11_co')));                 foreach ($rs as $value) {                     $std = explode(":", $value);
                      $con_qu_std = array('stdCode' => $std[0]);                     $qu_std = $this->std->qryStd($con_qu_std);                     if ($qu_std->num_rows()) {                         $row_std = $qu_std->row();
                          $this->tg->tg_dpj_id = ($type == 3) ? $this->input->post('mb_mpj_id') : (($type == 4) ? $this->input->post('mb_acp_id') : '');                         $this->tg->tg_type = 1;                         //$this->tg->tg_cur_id = $row_std->stdCurId;                         $tg_num = $this->tg->get_by_dpj_type_cur_tm();
                          $insert_flg = 0;                         if (($type == 1) || ($type == 2)) {                             $insert_flg = 1;                         } else if ($type == 3) {                             $this->mb->mb_mpj_id = $this->input->post('mb_mpj_id');                             $rs_mb = $this->mb->get_by_mpj();                             if (($rs_mb->num_rows() + 1) <= $tg_num) {                                 $insert_flg = 1;                             }                         } else if ($type == 4) {                             $this->mb->mb_acp_id = $this->input->post('mb_acp_id');                             $rs_mb = $this->mb->get_by_acp();                             if (($rs_mb->num_rows() + 1) <= $tg_num) {                                 $insert_flg = 1;                             }                         }
                          $this->mb->mb_id = $mb_id;                         $this->mb->get_by_key(TRUE);
                          $this->mb->mb_std_id = $row_std->stdId;                         $this->mb->mb_smo_id = ($type == 1) ? $this->input->post('mb_smo_id') : NULL;                         $this->mb->mb_cl_id = ($type == 2) ? $this->input->post('mb_cl_id') : NULL;                         $this->mb->mb_mpj_id = (($type == 3) || ($type == 4)) ? $this->input->post('mb_mpj_id') : NULL;                         $this->mb->mb_acp_id = ($type == 4) ? $this->input->post('mb_acp_id') : NULL;                         $this->mb->mb_year = $this->input->post('mb_year');                         $this->mb->mb_tmId = $this->input->post('mb_tmId');                         $this->mb->mb_syId = $this->input->post('mb_syId');                         $this->mb->mb_fr_date = splitDateForm2($this->input->post('mb_fr_date'));                         $this->mb->mb_to_date = splitDateForm2($this->input->post('mb_to_date'));
                          $rs_mb = $this->mb->get_duplicate();                         if (($rs_mb->num_rows() == 0) && $insert_flg) {                             if ($mb_id) {                                 $this->mb->update();                             } else {                                 $this->mb->insert();                             }                         }                     }                 }             } else if ($choice == 2) {                 $cnt = 0;                 $cur_id = $this->input->post('cur_id');                 $sy_id = $this->input->post('sy_id');
                  $this->tg->tg_dpj_id = ($type == 3) ? $this->input->post('mb_mpj_id') : (($type == 4) ? $this->input->post('mb_acp_id') : '');                 $this->tg->tg_type = 1;                 //$this->tg->tg_cur_id = $cur_id;                 $this->tg->tg_tm_id = $sy_id;                 $tg_num = $this->tg->get_by_dpj_type_cur_tm();
                  if ($std_id) {                     for ($i = 0; $i < count($std_id); $i++) {                         $con_rs_std['stdId'] = $std_id[$i];                         $qu_std = $this->std->qryStd($con_rs_std);
                          if ($qu_std->num_rows()) {                             $row_std = $qu_std->row();
                              $this->mb->mb_std_id = $row_std->stdId;                             $this->mb->mb_smo_id = ($type == 1) ? $this->input->post('mb_smo_id') : NULL;                             $this->mb->mb_cl_id = ($type == 2) ? $this->input->post('mb_cl_id') : NULL;                             $this->mb->mb_mpj_id = (($type == 3) || ($type == 4)) ? $this->input->post('mb_mpj_id') : NULL;                             $this->mb->mb_acp_id = ($type == 4) ? $this->input->post('mb_acp_id') : NULL;                             $this->mb->mb_year = $this->input->post('mb_year');                             $this->mb->mb_tmId = $this->input->post('mb_tmId');                             $this->mb->mb_syId = $this->input->post('mb_syId');                             $this->mb->mb_fr_date = splitDateForm2($this->input->post('mb_fr_date'));                             $this->mb->mb_to_date = splitDateForm2($this->input->post('mb_to_date'));
                              $insert_flg = 0;                             if (($type == 1) || ($type == 2)) {                                 $insert_flg = 1;                             } else if ((($type == 3) || ($type == 4)) && ($cnt < $tg_num)) {                                 $insert_flg = 1;                             }
                              $rs_mb = $this->mb->get_duplicate();                             if (($rs_mb->num_rows() == 0) && $insert_flg) {                                 $this->mb->insert();                                 $cnt++;                             }                         }                     }                 } else {                     $con_rs_std = array('stdSstId' => 1);                      if ($cur_id) {                         $con_rs_std['stdCurId'] = $cur_id;                     }                     if ($sy_id) {                         $con_rs_std['stdSyId'] = $sy_id;                     }                     $rs_std = $this->std->qryStd($con_rs_std);//ค้าง                     //echo $this->std->db->last_query();                     foreach ($rs_std->result() as $row_std) {                         $this->mb->mb_std_id = $row_std->stdId;                         $this->mb->mb_smo_id = ($type == 1) ? $this->input->post('mb_smo_id') : NULL;                         $this->mb->mb_cl_id = ($type == 2) ? $this->input->post('mb_cl_id') : NULL;                         $this->mb->mb_mpj_id = (($type == 3) || ($type == 4)) ? $this->input->post('mb_mpj_id') : NULL;                         $this->mb->mb_acp_id = ($type == 4) ? $this->input->post('mb_acp_id') : NULL;                         $this->mb->mb_year = $this->input->post('mb_year');                         $this->mb->mb_tmId = $this->input->post('mb_tmId');                         $this->mb->mb_syId = $this->input->post('mb_syId');                         $this->mb->mb_fr_date = splitDateForm2($this->input->post('mb_fr_date'));                         $this->mb->mb_to_date = splitDateForm2($this->input->post('mb_to_date'));
                          $insert_flg = 0;                         if (($type == 1) || ($type == 2)) {                             $insert_flg = 1;                         } else if ((($type == 3) || ($type == 4)) ) {//&& ($cnt < $tg_num)                             $insert_flg = 1;                         }
                          $rs_mb = $this->mb->get_duplicate();                         if (($rs_mb->num_rows() == 0) && $insert_flg) {                             $this->mb->insert();                             $cnt++;                         }                         //echo $cnt.'<BR>';                     }    // end foreach                 }    // end if std_id                 //die();                 //echo $this->db->last_query();             } else if($choice == 3) {                 $cnt = 0;                 $tg_sc_id = $this->input->post('tg_sc_id');
                  $this->tg->tg_dpj_id = ($type == 3) ? $this->input->post('mb_mpj_id') : (($type == 4) ? $this->input->post('mb_acp_id') : '');                 $this->tg->tg_type = 5;                 $this->tg->tg_sc_id = $tg_sc_id;                 $tg_num = $this->tg->get_by_dpj_type_cur_tm();                 if ($std_id) {                     for ($i = 0; $i < count($std_id); $i++) {                         $con_rs_std['stdId'] = $std_id[$i];                         $qu_std = $this->std->qryStd($con_rs_std);
                          if ($qu_std->num_rows()) {                             $row_std = $qu_std->row();
                              $this->mb->mb_std_id = $row_std->stdId;                             $this->mb->mb_smo_id = ($type == 1) ? $this->input->post('mb_smo_id') : NULL;                             $this->mb->mb_cl_id = ($type == 2) ? $this->input->post('mb_cl_id') : NULL;                             $this->mb->mb_mpj_id = (($type == 3) || ($type == 4)) ? $this->input->post('mb_mpj_id') : NULL;                             $this->mb->mb_acp_id = ($type == 4) ? $this->input->post('mb_acp_id') : NULL;                             $this->mb->mb_year = $this->input->post('mb_year');                             $this->mb->mb_tmId = $this->input->post('mb_tmId');                             $this->mb->mb_syId = $this->input->post('mb_syId');                             $this->mb->mb_fr_date = splitDateForm2($this->input->post('mb_fr_date'));                             $this->mb->mb_to_date = splitDateForm2($this->input->post('mb_to_date'));
                              $insert_flg = 0;                             if (($type == 1) || ($type == 2)) {                                 $insert_flg = 1;                             } else if ((($type == 3) || ($type == 4)) && ($cnt < $tg_num)) {                                 $insert_flg = 1;                             }
                              $rs_mb = $this->mb->get_duplicate();                             if (($rs_mb->num_rows() == 0) && $insert_flg) {                                 $this->mb->insert();                                 $cnt++;                             }                         }                     }                 } else {                     $this->mb->mb_smo_id = $tg_sc_id;                                          $rs_std = $this->mb->get_by_smo();//ค้าง                     foreach ($rs_std->result() as $row_std) {                         $this->mb->mb_std_id = $row_std->mb_std_id;                         $this->mb->mb_smo_id = ($type == 1) ? $this->input->post('mb_smo_id') : NULL;                         $this->mb->mb_cl_id = ($type == 2) ? $this->input->post('mb_cl_id') : NULL;                         $this->mb->mb_mpj_id = (($type == 3) || ($type == 4)) ? $this->input->post('mb_mpj_id') : NULL;                         $this->mb->mb_acp_id = ($type == 4) ? $this->input->post('mb_acp_id') : NULL;                         $this->mb->mb_year = $this->input->post('mb_year');                         $this->mb->mb_tmId = $this->input->post('mb_tmId');                         $this->mb->mb_syId = $this->input->post('mb_syId');                         $this->mb->mb_fr_date = splitDateForm2($this->input->post('mb_fr_date'));                         $this->mb->mb_to_date = splitDateForm2($this->input->post('mb_to_date'));
                          $insert_flg = 0;                         if (($type == 1) || ($type == 2)) {                             $insert_flg = 1;                         } else if ((($type == 3) || ($type == 4)) && ($cnt < $tg_num)) {                             $insert_flg = 1;                         }
                          $rs_mb = $this->mb->get_duplicate();                         if (($rs_mb->num_rows() == 0) && $insert_flg) {                             $this->mb->insert();                             $cnt++;                         }                     }    // end foreach                                      }    // end if std_id                                  }// end if choice
              if ($this->db->trans_status() === false) {                 $this->db->trans_rollback();             } else {                 $this->db->trans_commit();             }
              if ($std_id) {                 redirect($this->config->item('sa_folder').'attend/mb_popup');             } else {                 redirect($this->config->item('sa_folder').'attend/mb_input');             }         }     }
      function mb_delete () {         $this->load->model($this->config->item('sa_folder').'sa_member_model','mb');
          $mb_id = $this->input->post('mb_id');
          $this->mb->mb_id = $mb_id;         $this->mb->delete();
          redirect($this->config->item('sa_folder').'attend/mb_input');     }
      function mb_popup () {         $this->load->model($this->config->item('rg_folder').'mo_rg_student','std');
          $cur_id = $this->input->post('cur_id');         $sy_id = $this->input->post('sy_id');         $data['type'] = $this->input->post('type');         $data['choice'] = $this->input->post('choice');         $data['mb_smo_id'] = $this->input->post('mb_smo_id');         $data['mb_cl_id'] = $this->input->post('mb_cl_id');         $data['mb_mpj_id'] = $this->input->post('mb_mpj_id');         $data['mb_acp_id'] = $this->input->post('mb_acp_id');         $data['mb_year'] = $this->input->post('mb_year');         $data['mb_tmId'] = $this->input->post('mb_tmId');         $data['mb_syId'] = $this->input->post('mb_syId');         $data['mb_fr_date'] = $this->input->post('mb_fr_date');         $data['mb_to_date'] = $this->input->post('mb_to_date');
          $data['cur_id'] = $cur_id;         $data['sy_id'] = $sy_id;
          //$con_rs_std = array('stdSstId' => 1);         if ($cur_id) {             $con_rs_std['stdCurId'] = $cur_id;         }         if ($sy_id && ($sy_id != 'NULL')) {             $con_rs_std['stdSyId'] = $sy_id;         }         $ord_rs_std = array('curName' => 'ASC');         $data['rs_std'] = $this->std->qryStdJoinCur($con_rs_std, $ord_rs_std);//ค้าง
          $this->output_popup("v_pop_mb",$data);     }
      function profile() {         $this->load->model($this->config->item('rg_folder').'mo_rg_student','std');         $this->load->model($this->config->item('sa_folder').'sa_member_model','mb');         $this->load->model($this->config->item('rg_folder').'mo_rg_studentreward','srw');         $this->load->model($this->config->item('rg_folder').'mo_rg_curriculum','cur');         $this->load->model($this->config->item('rg_folder').'mo_rg_config','cfg');
          $std_id = $this->input->post('std_id');
          $con_qu_std = array('stdId' => $std_id);         $qu_std = $this->std->qryStdJoinPf($con_qu_std);         $data['qu_std'] = $qu_std;
          $data['curName'] = '-';         if($data['qu_std']->num_rows()) {             $this->cur->curId = $qu_std->row()->stdCurId;             $this->cur->get_by_key(TRUE);             $data['curName'] = $this->cur->curName;         }
          $this->mb->mb_std_id = $std_id;         $data['rs_smo'] = $this->mb->get_smo();
          $this->mb->mb_std_id = $std_id;         $data['rs_cl'] = $this->mb->get_cl();
          $data['rs_mpj'] = $this->mb->get_mpj();         $data['rs_acp'] = $this->mb->get_acp();
          $con_rs_srw = array('srwStdId' => $std_id);         $ord_rs_srw = array('srwReceiveDate' => 'ASC');         $data['rs_srw'] = $this->srw->qrySrw($con_rs_srw, $ord_rs_srw);
          $data['qu_cfg'] = $this->cfg->get_by_key();
          $this->output_popup("v_profile",$data);         //$this->load->view("esa/v_profile",$data);     } }
  |