File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/core/controllers/User.php
Back
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User extends MY_Controller { function __construct() { parent::__construct(); $this->load->model('Role_model'); $this->load->model('Cpd_model'); } function listing($role_id = 0,$type='') { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('VIEW_ALL_USER')) show_error($this->lang->line('no_permission_error')); $data = $this->data; //pr($data);exit; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "user/listing"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['userType'] = 'user_'.$type; $data['top_menu'] = "user_top"; $data['sub_menu'] = "user"; $data['pagetitle'] = "Users"; $data['allUsers'] = $this->User_model->getUsers($type,$role_id); $data['allRoles'] = $this->Role_model->getRoles($type,$data['siteSettings']['modules']); $sessionUserRoles = $this->User_model->sessionUserRoles(); $rolesArray = array(); foreach($sessionUserRoles as $role){ $rolesArray[] = $role['id']; } if(in_array(1, $rolesArray)) $data['is_admin'] = 1; else $data['is_admin'] = 0; $this->load->view('basetemplate', $data); } else { redirect("login"); } } function getUser($id = 0) { if($this->session->userdata("user_id")) { if($id == 0 && $this->input->post('id')) $id = $this->input->post('id'); $returnArr = $this->User_model->getUser($id); echo json_encode($returnArr); } else { redirect("login"); } } function editUser() { if($this->session->userdata("user_id")) { if($this->acl->hasPermission('EDIT_ALL_USER')){ $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('name_english', 'English Name', 'required'); $this->form_validation->set_rules('name_chinese', 'Chinese Name', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); } if($this->form_validation->run() || $this->acl->hasPermission('ASSIGN_USER_ROLE')) { if($this->User_model->editUser($this->input->post())) $this->session->set_flashdata('success', $this->lang->line('user_data_update_success')); else $this->session->set_flashdata('error', $this->lang->line('user_data_update_error')); redirect($_SERVER['HTTP_REFERER']); } else { $this->session->set_flashdata('error', $this->lang->line('user_data_update_error')); redirect($_SERVER['HTTP_REFERER']); } } else { redirect("login"); } } function editProfile() { if($this->session->userdata("user_id")) { $this->form_validation->set_rules('name_english', 'English Name', 'required'); $this->form_validation->set_rules('name_chinese', 'Chinese Name', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); if($this->form_validation->run()) { if($this->User_model->editProfile($this->input->post())) $this->session->set_flashdata('success', $this->lang->line('user_data_update_success')); else $this->session->set_flashdata('error', $this->lang->line('user_data_update_error')); redirect("core/editProfile"); } else { $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "user/edit_profile"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = ""; $data['pagetitle'] = "Edit Profile"; $data['cpds'] = $this->Cpd_model->getMyCPD(); $data['me'] = $this->User_model->getUser($this->session->userdata('id')); if($data['me']['profile_url']=='') $data['me']['profile_url'] = '/assets/global/plugins/bootstrap-fileinput/img/default_avatar_male.jpg'; $data['allRoles'] = $this->Role_model->getRoles($type='',$data['siteSettings']['modules']); $data['user'] = $this->User_model->getUser($this->session->userdata('id')); $data['allUsers'] = $this->User_model->getUsers(); //pr($data['allUsers']);exit; //pr($data['allUsers']);exit; $this->load->view('basetemplate', $data); } } else { redirect("login"); } } function setEducation() { if($this->session->userdata("user_id")) { if($this->User_model->setEducation($this->input->post('data'))) $this->session->set_flashdata('success', $this->lang->line('user_data_update_success')); else $this->session->set_flashdata('error', $this->lang->line('user_data_update_error')); } } function addUser() { if($this->session->userdata("user_id")) { $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('name_english', 'English Name', 'required'); $this->form_validation->set_rules('name_chinese', 'Chinese Name', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); if($this->form_validation->run()) { if($this->User_model->addUser($this->input->post())) $this->session->set_flashdata('success', $this->lang->line('user_created_success')); else $this->session->set_flashdata('error', $this->lang->line('user_created_error')); redirect($_SERVER['HTTP_REFERER']); } else { $this->session->set_flashdata('error', $this->lang->line('user_created_error')); redirect($_SERVER['HTTP_REFERER']); } } else { redirect("login"); } } function actionOnUser($id = 0, $action) { if($this->session->userdata("user_id")) { $check = $this->getUserArray($id); if(empty($check)) show_error("Data not found"); else { if($this->User_model->actionOnUser($id, $action)) $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 getUserArray($id = 0) { if($this->session->userdata("user_id")) return $this->User_model->getUser($id); else redirect("login"); } function checkUnique() { if($this->session->userdata("user_id")) { $check = $this->User_model->checkUnique($this->input->post()); if(empty($check)) $return = TRUE; else $return = FALSE; echo json_encode($return); } else { redirect("login"); } } function checkUniqueForEdit() { if($this->session->userdata("user_id")) { $check = $this->User_model->checkUniqueForEdit($this->input->post()); if(empty($check)) $return = TRUE; else $return = FALSE; echo json_encode($return); } else { redirect("login"); } } function bulkAction() { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('DELETE_ALL_USER')) show_error($this->lang->line('no_permission_error')); $returnArr = $this->User_model->bulkAction($this->input->post()); echo json_encode($returnArr); } else { redirect("login"); } } function check_email() { /*if(!$this->session->userdata("user_id")) {*/ $result = $this->User_model->check_email($this->input->post()); if(!empty($result)) echo "true"; else redirect("login");/* } else { redirect('user/dashboard'); }*/ } function import() { if($this->session->userdata("user_id")) { $config['upload_path'] = './files/import'; $config['allowed_types'] = 'csv|xlsx|xls'; $config['max_size'] = 10000; $config['max_width'] = 10024; $config['max_height'] = 10008; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('users')) { $error = array('error' => $this->upload->display_errors()); //print_r( $error);die; $this->session->set_flashdata('error', $error); redirect($_SERVER['HTTP_REFERER']); } else { $data = $this->upload->data(); $file = $data['full_path']; //load the excel library $this->load->library('excel'); //read file from path $objPHPExcel = PHPExcel_IOFactory::load($file); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $exceldata=[]; for ($row = 1; $row <= $highestRow; $row++) { // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, TRUE); if($rowData[0][0]=="" && $rowData[0][1]=="" && $rowData[0][2]=="" && $rowData[0][3]=="" && $rowData[0][4]=="" && $rowData[0][5]=="") {}else { $exceldata[]=array("username"=>$rowData[0][0],"name_english"=> $rowData[0][1],"name_chinese" =>$rowData[0][2], "email"=>$rowData[0][3] ,"roles"=>$rowData[0][4],"password"=>$rowData[0][5]); } } if(!empty($exceldata)) { foreach ($exceldata as $key=> $line ) { if($key!=0) { $rolesArray = explode(',', $line['roles']); $roleIds = array(); foreach($rolesArray as $role){ $roleArr = $this->Role_model->getRoleByRoleName($role); if(!empty($roleArr)) $roleIds[] = $roleArr['id']; else $roleIds[] = trim($role); } $line['roles'] = $roleIds; $newArray = $line; //pr($newArray); //$newArray['module'] = $type; if($this->User_model->checkUniqueUsername(trim($newArray['username'])) && $this->User_model->checkUniqueEmail(trim($newArray['email']))) { $newArray['action'] = 'insert'; $mainArray[] = $newArray; } else{ $newArray['action'] = 'update'; $mainArray[] = $newArray; /*$flashMessage = '<br /><br /><strong>'.$this->lang->line('duplicate_entry_found').'</strong><br /><br />'; $flashMessage .= 'Line Number: '.($counter+1).'<br />'; $flashMessage .= 'Username: '.($newArray['username']).'<br />'; $flashMessage .= 'Email: '.($newArray['email']).'<br />'; $flashMessages[] = $flashMessage; */ } } } $action_to_do = $this->input->post('action_to_do'); foreach($mainArray as $array) $this->User_model->importUsers($array,$action_to_do); $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); redirect($_SERVER['HTTP_REFERER']); } else { $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } redirect($_SERVER['HTTP_REFERER']); } }else { redirect("login"); } } public function userdata() { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_USER_DATA')) show_error($this->lang->line('no_permission_error')); $data = $this->data; //pr($data);exit; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "userdata/userdata"; $data['footer'] = TRUE; $data['top_menu'] = "user_top"; $data['sub_menu'] = "userdata"; $data['pageTitle'] = "Users Data"; $data['allUsers'] = $this->User_model->getUsers(); $this->load->view('basetemplate', $data); } else { redirect("login"); } } function userPortfolio() { if($this->session->userdata("user_id")) { if($this->User_model->updatePortfolio($this->input->post())){} $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); redirect($_SERVER['HTTP_REFERER']); } else { redirect("login"); } } function preview() { $config['upload_path'] = './files/tmp_upload'; $config['allowed_types'] = 'csv|xlsx|xls'; $config['max_size'] = 10000; $config['max_width'] = 10024; $config['max_height'] = 10008; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('users')) { echo '<h3 style="color:red">Please select only these file types eg. csv,xls,xlsx etc. </h3>'; echo '<input id="duplicate" name="duplicate" type="hidden" value="1" />'; die; } else { $data = $this->upload->data(); $file = $data['full_path']; //load the excel library $this->load->library('excel'); //read file from path $objPHPExcel = PHPExcel_IOFactory::load($file); //Get worksheet dimensions $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); //Loop through each row of the worksheet in turn $exceldata=[]; for($row = 1; $row <= $highestRow; $row++) { // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, TRUE); if($rowData[0][0]=="" && $rowData[0][1]=="" && $rowData[0][2]=="" && $rowData[0][3]=="" && $rowData[0][4]=="" && $rowData[0][5]=="") {}else $exceldata[]=$rowData[0]; } $orders=$exceldata; $foundIds = array(); // check array duplicates username and email foreach($orders as $index => $order ) { $dup=0; if(isset($foundIds[$order['0']] ) ) { $dup=1; $orders[$foundIds[$order['0']]]['is_dupe'] = true; } else if(isset($foundIds[$order['3']] )) { $dup=1; $orders[$foundIds[$order['3']]]['is_dupe'] = true; } else { $orders[$index]['is_dupe'] = false; } if($dup == 1) $orders[$index]['is_dupe'] = true; $foundIds[$order['0']] = $index; $foundIds[$order['3']] = $index; } $required=0; $unique_username=0; $duplicate_username=""; $unique_emails=0; $duplicate_emails=""; echo '<table class="table table-striped table-bordered table-hover" id="data_table" data-always-visible="1">'; $i = 0; foreach ( $orders as $order ) { // required fileds check if(empty($order[0]) || empty($order[1]) ) { $required++; } if(empty($order[0]) && empty($order[1]) ) { $required--; }else { if ($i == 0) { echo '<tr>'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<th style="font-family:"Open Sans",sans-serif;">'. ucfirst($value) .'</th>'; } echo '</tr>'; }else { //check unique username titles $username = $this->User_model->getUserByUsername($order[0]); $email = $this->User_model->getUserByEmail($order[3]); if(!empty($username)) { $unique_username++; $duplicate_username.= $order[0].','; echo '<tr style="color:red">'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<td>'. $value .'</td>'; } echo '</tr>'; }else if(!empty($email)) { $unique_emails++; $duplicate_emails.= $order[3].','; echo '<tr style="color:red">'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<td>'. $value .'</td>'; } echo '</tr>'; } else { echo '<tr '; if($order['is_dupe']==1 ) { $unique_username ++; $duplicate_username.= $order[0].','; echo " style='color:red'"; } echo '>'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<td>'. $value .'</td>'; } echo '</tr>'; } } } $i++; } echo '</table>'; if($required > 0) echo '<h5 style="color:red">Requireds fields are not empty username,card_number. </h5>'; if($unique_username > 0) echo '<h5 style="color:red">This username is avialable in DB: '.$duplicate_username.' </h5>'; if($unique_emails > 0) echo '<h5 style="color:red">This emails is avialable in DB: '.$duplicate_emails.' </h5>'; if($required == 0 && $unique_username == 0 && $unique_emails == 0) echo '<input id="duplicate" name="duplicate" type="hidden" value="0" />'; else echo '<input id="duplicate" name="duplicate" type="hidden" value="1" />'; // echo '<input name="subjectsarray" type="hidden" value='.htmlspecialchars( serialize( $orders ) ).' />'; } } function downloadFormat() { if($this->session->userdata("user_id")) { $filename="camplus_user.xls"; //load our new PHPExcel library $this->load->library('excel'); //activate worksheet number 1 $this->excel->setActiveSheetIndex(0); //name the worksheet $this->excel->getActiveSheet()->setTitle('User list'); $allUsers = $this->User_model->getUsers(); $outarray = array(); for($i=0;$i<count($allUsers);$i++) { $role=$allUsers[$i]['roles']; if(count($role) > 0) $rolename=$role[0]['role']; else $rolename=""; if($i==0) { $headerarr=array("username"=>"UserName","name_english"=>"English Name","name_chinese"=>"Chinese Name","email"=>"Email" ,"role"=>"User Role","password"=>"Password" ); $outarray[]=$headerarr; $outarray[]=array("username"=>$allUsers[$i]['username'],"name_english"=>$allUsers[$i]['name_english'],"name_chinese"=>$allUsers[$i]['name_chinese'],"email"=>$allUsers[$i]['email'] ,"role"=>$rolename ); } else { $outarray[]=array("username"=>$allUsers[$i]['username'],"name_english"=>$allUsers[$i]['name_english'],"name_chinese"=>$allUsers[$i]['name_chinese'],"email"=>$allUsers[$i]['email'] ,"role"=>$rolename ); } } // read data to active sheet $this->excel->getActiveSheet()->fromArray($outarray); header("Content-type: application/xls"); header("Content-Disposition: attachment; filename=".$filename); $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); $objWriter->save('php://output'); } else { redirect("login"); } } function previewUserData() { $config['upload_path'] = './files/tmp_upload'; $config['allowed_types'] = 'csv|xlsx|xls'; $config['max_size'] = 10000; $config['max_width'] = 10024; $config['max_height'] = 10008; $user_not_exist = 0; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('users')) { echo '<h3 style="color:red">Please select only these file types eg. csv,xls,xlsx etc. </h3>'; echo '<input id="duplicate" name="duplicate" type="hidden" value="1" />'; die; } else { $data = $this->upload->data(); $file = $data['full_path']; //load the excel library $this->load->library('excel'); //read file from path $objPHPExcel = PHPExcel_IOFactory::load($file); //Get worksheet dimensions $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); //Loop through each row of the worksheet in turn $exceldata=[]; for($row = 1; $row <= $highestRow; $row++) { // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, TRUE); if($rowData[0][0]=="") {}else $exceldata[]=$rowData[0]; } $orders=$exceldata; $foundIds = array(); // check array duplicates username and email foreach($orders as $index => $order ) { $dup=0; if(isset($foundIds[$order['0']] ) ) { $dup=1; $orders[$foundIds[$order['0']]]['is_dupe'] = true; } else { $orders[$index]['is_dupe'] = false; } if($dup == 1) $orders[$index]['is_dupe'] = true; $foundIds[$order['0']] = $index; } $required=0; $unique_username=0; $duplicate_username=""; $unique_emails=0; $duplicate_emails=""; echo '<table class="table table-striped table-bordered table-hover" id="data_table" data-always-visible="1">'; $i = 0; foreach ( $orders as $order ) { // required fileds check if(empty($order[0]) ) { $required++; } if(empty($order[0])) { $required--; }else { if ($i == 0) { echo '<tr>'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<th style="font-family:"Open Sans",sans-serif;">'. ucfirst($value) .'</th>'; } echo '</tr>'; }else { //check unique username titles $username = $this->User_model->getUserByUsername($order[0]); if(empty($username)) { $user_not_exist++; $no_username.= $order[0].','; echo '<tr style="color:red">'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<td>'. $value .'</td>'; } echo '</tr>'; } else { echo '<tr '; if($order['is_dupe']==1 ) { $unique_username ++; $duplicate_username.= $order[0].','; echo " style='color:red'"; } echo '>'; $count = count($order); foreach ( $order as $value ) { if (--$count <= 0) { break; } echo '<td>'. $value .'</td>'; } echo '</tr>'; } } } $i++; } echo '</table>'; if($required > 0) echo '<h5 style="color:red">Requireds fields are not empty username</h5>'; if($user_not_exist > 0) echo '<h5 style="color:red">This username do not exist: '.$no_username.' </h5>'; if($required == 0 && $user_not_exist == 0) echo '<input id="duplicate" name="duplicate" type="hidden" value="0" />'; else echo '<input id="duplicate" name="duplicate" type="hidden" value="1" />'; // echo '<input name="subjectsarray" type="hidden" value='.htmlspecialchars( serialize( $orders ) ).' />'; } } function importUserData() { if($this->session->userdata("user_id")) { $config['upload_path'] = './files/import'; $config['allowed_types'] = 'csv|xlsx|xls'; $config['max_size'] = 10000; $config['max_width'] = 10024; $config['max_height'] = 10008; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('users')) { $error = array('error' => $this->upload->display_errors()); //print_r( $error);die; $this->session->set_flashdata('error', $error); redirect($_SERVER['HTTP_REFERER']); } else { $data = $this->upload->data(); $file = $data['full_path']; //load the excel library $this->load->library('excel'); //read file from path $objPHPExcel = PHPExcel_IOFactory::load($file); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $exceldata=[]; for ($row = 1; $row <= $highestRow; $row++) { // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, TRUE); if($rowData[0][0]=="") {}else { $exceldata[]=array("username"=>$rowData[0][0],"type"=>$rowData[0][1],"service_commencement_date"=> $rowData[0][2],"teaching_exp" =>$rowData[0][3], "pay_day"=>$rowData[0][4] ,"model_scale"=>$rowData[0][5],"pay_grade"=>$rowData[0][6],"grant_source"=>$rowData[0][7],); } } //print_r($exceldata); if(!empty($exceldata)) { foreach ($exceldata as $key=> $line ) { if($key!=0) { $username = $this->User_model->getUserByUsername($line['username']); $line['id'] = $username['id']; print_r($this->User_model->updatePortfolio($line)); } } $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); redirect($_SERVER['HTTP_REFERER']); } else { $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } redirect($_SERVER['HTTP_REFERER']); } }else { redirect("login"); } } function uploadProfile() { if($this->session->userdata("user_id")) { $config['upload_path'] = './files/user_picture'; $config['allowed_types'] = 'jpg|jpeg|gif|png'; $config['max_size'] = 10000; $config['max_width'] = 10024; $config['max_height'] = 10008; $this->load->library('upload', $config); if (!$this->upload->do_upload('avatar-2')) { $error = array('error' => $this->upload->display_errors()); $this->session->set_flashdata('error', 'upload failed'); redirect($_SERVER['HTTP_REFERER']); } else { $data = $this->upload->data(); $file = $data['file_name']; $this->User_model->updateProfilePic($this->session->userdata('id'),'/files/user_picture/'.$file); redirect($_SERVER['HTTP_REFERER']); } } } function profilePic($id) { $profile = $this->User_model->getUser($id)['profile_url']; if($profile!='') { $file = FCPATH . $profile; header('Content-Type:'.mime_content_type($file)); header('Content-Length: ' . filesize($file)); readfile($file); } else { header('Content-Type: image/png'); echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='); } } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.41 |
proxy
|
phpinfo
|
Settings