File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/class_group/controllers/Class_group.php
Back
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Class_group extends MY_Controller { function __construct() { parent::__construct(); $this->load->model('Class_group_model'); $this->load->model('Academic_year/Academic_year_model'); $this->load->model('core/User_model'); $this->load->model('venue/Venue_model'); } function listing($ay_id=0) { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_CLASS_GROUP')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "class_group"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "class_group"; $data['sub_menu'] = "cg_tea_arrangement"; $data['pagetitle'] = ts('teacher class',1); if($ay_id==0) $ay_id = $this->Academic_year_model->getCurrentAcademicYear()['id']; $data['classes'] = $this->Class_group_model->getClassesOnlyWithUser($ay_id,true); $data['venues'] = $this->Class_group_model->getVenues(); $data['ac_years'] = $this->Academic_year_model->getAcademicYears(); $data['users'] = $this->User_model->getAllUsers(); $data['ay_id']=$ay_id; $this->load->view('basetemplate', $data); } else { redirect("login"); } } function add() { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_CLASS_GROUP')) show_error($this->lang->line('no_permission_error')); $this->form_validation->set_rules('title', 'Class Name', 'required'); $this->form_validation->set_rules('ac_year_id', 'Academic Year', 'required'); if ($this->form_validation->run()==false){ $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } else { if($this->Class_group_model->addClass($this->input->post())) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } redirect($_SERVER['HTTP_REFERER']); } else { redirect("login"); } } function edit($id) { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_CLASS_GROUP')) show_error($this->lang->line('no_permission_error')); $this->form_validation->set_rules('title', 'Class Name', 'required'); $this->form_validation->set_rules('ac_year_id', 'Academic Year', 'required'); $data = $this->Class_group_model->getClass($id); if(empty($data)) show_error('No record found'); if ($this->form_validation->run()==false){ $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } else { if($this->Class_group_model->editClass($this->input->post(),$id)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } redirect($_SERVER['HTTP_REFERER']); } else { redirect("login"); } } function delete($id=0){ if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_CLASS_GROUP')) show_error($this->lang->line('no_permission_error')); $data = $this->Class_group_model->getClass($id); if(empty($data)) show_error('No record found'); if($this->Class_group_model->deleteClass($id)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); redirect($_SERVER['HTTP_REFERER']); } else { redirect("login"); } } function import($ay_id) { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_CLASS_GROUP')) show_error($this->lang->line('no_permission_error')); $import = import_xls('class','./files/tmp_upload'); //print_r($import);exit; if(empty($import['error'])) { if($this->Class_group_model->importclass($import['data'],$ay_id)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); } else { $err_msg = ''; if(!empty($import['error']['upload'])) { $err_msg .= $import['error']['upload'] . PHP_EOL; } $empty = ''; if(!empty($import['error']['empty'])) { foreach($import['error']['empty'] as $e_row => $e_column) { $empty .= 'row ' . $e_row . ' of column ' . $e_column . ' cannot be empty. ' . PHP_EOL; } } $err_msg .= $empty; $this->session->set_flashdata('error', $err_msg); } redirect($_SERVER['HTTP_REFERER']); }else { redirect("login"); } } function preview() { $import = import_xls('class','./files/tmp_upload',array(1,1,1,1)); //print_r($import);exit; if(empty($import)) echo '<input id="duplicate" name="duplicate" type="hidden" value="0" />'; else { $err_msg = ''; if(!empty($import['error']['upload'])) { echo '<h3 style="color:red">' . $import['error']['upload'] . '</h3>'; } echo '<table class="table table-striped table-bordered table-hover" id="data_table" data-always-visible="1">'; echo '<tr>'; foreach($import['header'] as $h_row) { echo '<th>' . $h_row . '</th>'; } echo '</tr>'; foreach($import['data'] as $n_row=>$row) { echo '<tr>'; foreach($row as $n_col=>$col) { if(!empty($import['error']['empty'][$n_row+1]) && $import['error']['empty'][$n_row+1]==$n_col+1) { echo '<td style="color:red">EMPTY</td>'; } else { /* if($n_col==0){ $class_info=$this->Class_group_model->checkUnique(array('field'=>'title','title'=>$col)); if($class_info){ echo '<td><span style="color:red">[重复]</span>'.$col.'</td>'; $import['error']['repeat'][]='0'; }else{ echo '<td>'.$col.'</td>'; } }else */ if($n_col===1){ $venue_info=$this->Venue_model->checkUnique(array('field'=>'title','title'=>$col)); if(!$venue_info){ echo '<td><span style="color:red">[不存在]</span>'.$col.'</td>'; $import['error']['repeat'][]='1'; }else{ echo '<td>'.$col.'</td>'; } }else if($n_col==2 && $col!=''){ $users=explode(",",$col); $user_return = []; foreach($users as $key1 =>$value1) { if(is_numeric($value1)) $userinfo=$this->User_model->checkUnique(array('field'=>'id','id'=>$value1)); else $userinfo=$this->User_model->checkUnique(array('field'=>'username','username'=>$value1)); if(empty($userinfo)) { $user_return[] = '<span style="color:red">[不存在]</span>'.$value1.' '; $import['error']['repeat'][]='2'; } else { $user_return[] = $value1; } } echo '<td>'.implode(',',$user_return).'</td>'; }else if($n_col==2 && $col[2]==''){ echo '<td style="color:red">EMPTY</td>'; }else{ if($col==NULL){ echo '<td style="color:red">EMPTY</td>'; }else{ echo '<td>'.$col.'</td>'; } } } } echo '</tr>'; } echo '</table>'; if(!empty($import['error'])) echo '<input id="duplicate" name="duplicate" type="hidden" value="1" />'; } } function export($ay_id) { if($this->session->userdata("user_id")) { $subjects = $this->Class_group_model->getClassesOnlyWithUser($ay_id); $venues = $this->Class_group_model->getVenues(); $academic_years = $this->Academic_year_model->getAcademicYears(); $year_name = $academic_years[array_search($ay_id,array_column($academic_years,'id'))]['year_label']; $filename= $year_name . "_class_export.xls"; $keys = array("title"=>"Class","description"=>"Home Venue","budget_amount"=>"Teachers","budget_allowance"=>"Level"); $data = array(); for($i=0;$i<count($subjects);$i++) { $newarray=$subjects[$i]; $class=$subjects[$i]; unset($class['id']); $venue=($class['venue_id']!=0)?$venues[array_search($class['venue_id'],array_column($venues,'id'))]['title']:"-"; $year=($class['ac_year_id']!=0)?$academic_years[array_search($class['ac_year_id'],array_column($academic_years,'id'))]['year_label']:"-"; $rowarr=array('title'=>$class['title'],'venue_id'=>$venue,'user'=>$class['teachers'],'level'=>$class['level']); $data[]=$rowarr; } export_xls($keys,$data,'class_export'); } else { redirect("login"); } } function get($id=0) { if($this->session->userdata("user_id")) { $data = $this->Class_group_model->getClass($id); echo json_encode($data); } else { redirect("login"); } } function getClass($id=0) { if($this->session->userdata("user_id")) { $class = $this->Class_group_model->getClass($id); $users = $this->Class_group_model->getClassUser($id); $data = array('class'=>$class,'users'=>$users) ; echo json_encode($data); } else { redirect("login"); } } function getUserGroup($uid, $ay_id,$subject) { $groups = $this->Class_group_model->getUserGroup($uid, $ay_id,$subject); echo json_encode($groups); } function getUserGroupTerm($uid, $term_id,$subject) { $groups = $this->Class_group_model->getUserGroupTerm($uid, $term_id,$subject); echo json_encode($groups); } function getClasses($ay_id) { $classes = $this->Class_group_model->getClassesOnly($ay_id); echo json_encode($classes); } function getClassStudent($class) { $stu = $this->Class_group_model->getClassStudent($class); echo json_encode($stu); } function getGroupStudent($group) { $stu = $this->Class_group_model->getGroupStudent($group); echo json_encode($stu); } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.16 |
proxy
|
phpinfo
|
Settings