|
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/laciasmara.com/public_html/shop/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');
}
public function log_list()
{
//fetch all users
$this->data['users'] = $this->user_m->get();
$this->data['logs'] = $this->user_m->getLogs();
//load view
$this->data['subview'] = 'admin/user/log_list';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
public function filterByUser($userId = NULL)
{
if ($userId === NULL) {
redirect('admin/user/index'); // Redirect ke halaman daftar semua pengguna jika userId tidak ditentukan
}
$this->data['users'] = $this->user_m->get();
// Fetch data log yang sesuai dengan user yang dipilih
$this->data['logs'] = $this->user_m->getLogsByUser($userId);
// Load view dengan data yang sesuai
$this->data['subview'] = 'admin/user/log_list';
$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();
}
if (($this->data['membership_type'] == "starter" || $this->data['membership_type'] == "business") && $this->data['jml_user'] >= 2) {
redirect('admin/user');
}
//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', 'role', 'password', 'warehouse_id'
));
$data['password'] = $this->user_m->hash($data['password']);
} else {
$data = $this->user_m->array_from_post(array(
'name', 'email', 'role', 'warehouse_id'
));
}
$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) {
$recaptcha = $this->input->post('g-recaptcha-response');
if (!empty($recaptcha)) {
$response = $this->recaptcha->verifyResponse($recaptcha);
if (isset($response['success']) and $response['success'] === 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');
}
}
} else {
$this->session->set_flashdata('error', 'Sorry Recpatcha Error');
redirect('admin/user/login');
}
}
$this->data['widget'] = $this->recaptcha->getWidget();
$this->data['script'] = $this->recaptcha->getScriptTag();
$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;
}
}