Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/kamariallee.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User extends Admin_Controller { function __construct() { parent::__construct(); $this->load->helper('form'); } //this index is to list all users public function index() { //fetch all users $this->data['users'] = $this->user_m->get(); //load view $this->data['subview'] = 'admin/user/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to edit current user or add new user in admin public function edit($id=NULL) { if($id) { $this->data['user'] = $this->user_m->get($id); count($this->data['user']) || $this->data['errors'][] = 'User could not be found'; } else { $this->data['user'] = $this->user_m->get_new(); } //validation in action $rules = $this->user_m->rules_admin; $id || $rules['password']['rules'] .= '|required'; //for new user password is required $id || $rules['password_confirm']['rules'] .= '|required'; //for new user password is required $this->form_validation->set_rules($rules); if($this->form_validation->run($this) == TRUE) { //if validation correct, then check whether user did update password or not. If no update password, then just change the username or email, and else.. if($this->input->post('password')) { $data = $this->user_m->array_from_post(array( 'name', 'email', 'password')); $data['password'] = $this->user_m->hash($data['password']); } else { $data = $this->user_m->array_from_post(array( 'name', 'email')); } $this->user_m->save($data, $id); redirect('admin/user'); } $this->data['subview'] = 'admin/user/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to delete a user public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->user_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->user_m->delete($id); redirect('admin/user'); } function login() { //validation in action $rules = $this->user_m->_rules; $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled $this->form_validation->set_rules($rules); if($this->form_validation->run($this) == TRUE) { //we can login and redirect $this->user_m->login(); if($this->user_m->loggedin() == TRUE) { redirect('admin/dashboard'); } else { $this->session->set_flashdata('error', 'Sorry Invalid Login'); redirect('admin/user/login'); } } $this->data['subview'] = 'admin/user/login'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } function logout() { $this->user_m->logout(); redirect('admin/user/login', 'refresh'); } //custom callback validation for unique email, used for edit user public function _unique_email($str) { $id = $this->uri->segment(4); //to fetch current id $this->db->where('email', $this->input->post('email')); !$id || $this->db->where('id !=', $id);//dont choose current email $user = $this->user_m->get(); if(count($user)) { $this->form_validation->set_message('_unique_email', '%s should be unique'); return FALSE; } return TRUE; } }