/** * change user password */ public function change_pass() { $this->layout = 'none'; if ($this->input->is_ajax_request() && $this->input->post()) { $json = array(); $post = $this->input->post(); $id = id_auth_user(); $this->load->model('Admin_model'); $detail = $this->Admin_model->getAdmin($id); if (!$id || !$detail) { $json['location'] = site_url('home'); } if (!$this->validatePassword()) { $json['error'] = $this->error; } if (!$json) { $now = date('Y-m-d H:i:s'); $data = array('userpass' => password_hash($post['new_password'], PASSWORD_DEFAULT), 'modify_date' => $now); $this->Admin_model->UpdateRecord($id, $data); // insert to log $data_log = array('id_user' => id_auth_user(), 'id_group' => id_auth_group(), 'action' => 'Profile', 'desc' => 'Change Password Profile; ID: ' . $id . ';'); insert_to_log($data_log); // end insert to log $json['success'] = alert_box('Your Password has been changed.', 'success'); $this->session->set_flashdata('form_message', $json['success']); $json['redirect'] = site_url('profile'); } header('Content-type: application/json'); exit(json_encode($json)); } redirect('profile'); }
/** * get all authenticated menu * @param int $id_parent * @return array data */ private function MenusData($id_parent = 0) { $i = 0; $id_group = id_auth_group(); $CI =& get_instance(); $CI->load->database(); $data = $CI->db->join('auth_menu', 'auth_menu.id_auth_menu=auth_menu_group.id_auth_menu', 'left')->where('auth_menu_group.id_auth_group', $id_group)->where('auth_menu.parent_auth_menu', $id_parent)->order_by('auth_menu.position', 'asc')->order_by('auth_menu.id_auth_menu', 'asc')->get('auth_menu_group')->result_array(); foreach ($data as $row => $val) { $data[$row]['children'] = $this->MenusData($val['id_auth_menu']); $i++; } return $data; }
/** * delete picture */ public function delete_picture() { $this->layout = 'none'; if ($this->input->post() && $this->input->is_ajax_request()) { $json = array(); $post = $this->input->post(); if (isset($post['id']) && $post['id'] > 0 && ctype_digit($post['id'])) { $detail = $this->Quiz_model->GetQuiz($post['id']); if ($detail && ($detail['image'] != '' && file_exists(UPLOAD_DIR . 'admin/' . $detail['image']))) { $id = $post['id']; unlink(UPLOAD_DIR . 'admin/' . $detail['image']); @unlink(UPLOAD_DIR . 'admin/tmb_' . $detail['image']); @unlink(UPLOAD_DIR . 'admin/sml_' . $detail['image']); $data_update = array('image' => ''); $this->Quiz_model->UpdateRecord($post['id'], $data_update); $json['success'] = alert_box('File hase been deleted.', 'success'); // insert to log $data_log = array('id_user' => id_auth_user(), 'id_group' => id_auth_group(), 'action' => 'User Quiz', 'desc' => 'Delete Picture User Quiz; ID: ' . $id . ';'); insert_to_log($data_log); // end insert to log } else { $json['error'] = alert_box('Failed to remove File. Please try again.', 'danger'); } } header('Content-type: application/json'); exit(json_encode($json)); } redirect($this->class_path_name); }
/** * delete page */ public function delete() { $this->layout = 'none'; if ($this->input->post() && $this->input->is_ajax_request()) { $post = $this->input->post(); $json = array(); if ($post['ids'] != '') { $array_id = array_map('trim', explode(',', $post['ids'])); if (count($array_id) > 0) { foreach ($array_id as $row => $id) { $record = $this->Menu_model->GetMenu($id); if ($record) { if ($record['is_superadmin'] && !is_superadmin()) { $json['error'] = alert_box('You don\'t have permission to delete this record(s). Please contact the Menuistrator.', 'danger'); break; } else { /*if (!$this->Menu_model->checkUserHaveRightsMenu(id_auth_group(),$id)) { $json['error'] = alert_box('You don\'t have permission to delete this record(s). Please contact the Menuistrator.','danger'); break; } else {*/ $this->Menu_model->DeleteRecord($id); // insert to log $data_log = array('id_user' => id_auth_user(), 'id_group' => id_auth_group(), 'action' => 'Delete Admin Menu', 'desc' => 'Delete Admin Menu; ID: ' . $id . ';'); insert_to_log($data_log); // end insert to log $json['success'] = alert_box('Data has been deleted', 'success'); $this->session->set_flashdata('flash_message', $json['success']); //} } } else { $json['error'] = alert_box('Failed. Please refresh the page.', 'danger'); break; } } } } header('Content-type: application/json'); exit(json_encode($json)); } redirect($this->class_path_name); }