248 lines
7.3 KiB
PHP
248 lines
7.3 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
/**
|
|
* AMS
|
|
*
|
|
* @package HMVC
|
|
* @author Venba
|
|
* @copyright 2022 Venba
|
|
* @license https://venbainfotech.com/licenses/MIT MIT License
|
|
* @link <URI> (description)
|
|
* @version GIT: $Id$
|
|
* @since Version 0.0.1
|
|
* @filesource
|
|
*
|
|
*/
|
|
|
|
class User extends Admin_Controller
|
|
{
|
|
/**
|
|
* [__construct description]
|
|
*
|
|
* @method __construct
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// To inherit directly the attributes of the parent class.
|
|
parent::__construct();
|
|
$this->load->model('MY_Model');
|
|
$this->load->model('user_model');
|
|
$this->load->model('audit_model');
|
|
// $this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
$this->layout->set('users', "abc");
|
|
$this->layout->buffer('main_content', 'User/index');
|
|
$this->layout->render('default_layout');
|
|
|
|
|
|
}
|
|
|
|
public function userList()
|
|
{
|
|
if (is_superadmin()) {
|
|
$user_list = $this->user_model->get_admin();
|
|
}
|
|
else if(is_admin() || is_user()) {
|
|
$user_list = $this->user_model->get_user( md5(user()->id) , user()->business_id);
|
|
}
|
|
$this->layout->set('tableData', $user_list);
|
|
$this->layout->buffer('main_content', 'User/user_list');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
public function addUser($businessId = 0)
|
|
{
|
|
$business = $this->user_model->business();
|
|
if($businessId != 0){
|
|
$businessData = $this->MY_Model->get_by_id($businessId,'business');
|
|
$this->layout->set('businessData', $businessData);
|
|
}
|
|
$this->layout->set('data', user());
|
|
$this->layout->set('business_dropdown', $business);
|
|
$this->layout->buffer('main_content', 'User/add_user');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
public function createUser()
|
|
{
|
|
$data=$this->input->post();
|
|
// $data['business_id'] = user()->business_id;
|
|
// $data['created_by'] = user()->id;
|
|
// $data['role'] = "user";
|
|
unset($data['confirm_password']);
|
|
$data['password'] = hash_password($this->input->post('password'));
|
|
$table="users";
|
|
$create_user = $this->MY_Model->insert($data,$table);
|
|
//audit
|
|
if($create_user)
|
|
{
|
|
//set id $ table name for audit history
|
|
$this->audit->set('id',$create_user);
|
|
$this->audit->set('table',$table);
|
|
//fetch new_data after post data insert
|
|
$this->audit->fetch('new_data');
|
|
//audit history generation for insert
|
|
$test = $this->audit->create_history('insert');
|
|
}
|
|
redirect('user/userList');
|
|
|
|
}
|
|
|
|
|
|
public function editUser($id)
|
|
{
|
|
$usertData = $this->user_model->get_user_by_md5_id($id,user()->business_id);
|
|
$this->layout->set('editData', $usertData);
|
|
$this->layout->buffer('main_content', 'User/edit_user');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
|
|
public function editUsers()
|
|
{
|
|
|
|
$table="users";
|
|
$action = $this->input->post();
|
|
|
|
$id = $this->input->post('id');
|
|
//set id $ table name for audit history
|
|
$this->audit->set('id',$this->input->post('id'));
|
|
$this->audit->set('table','users');
|
|
//fetch old_data before new_data update
|
|
$this->audit->fetch('old_data');
|
|
//update new data
|
|
$userData = $this->MY_Model->edit_option($action, $id, $table);
|
|
if($userData)
|
|
{
|
|
//fetch new_data after post data update
|
|
$this->audit->fetch('new_data');
|
|
//audit history generation for update
|
|
$test = $this->audit->create_history('update');
|
|
}
|
|
redirect('user/userList');
|
|
|
|
}
|
|
|
|
public function deleteUser($id)
|
|
{
|
|
$Data = $this->user_model->delete_user_by_md5_id($id,user()->business_id);
|
|
redirect('user/userList');
|
|
}
|
|
|
|
public function activateUser($id)
|
|
{
|
|
$Data = $this->user_model->activate_inactive_users($id,user()->business_id);
|
|
redirect('user/userList');
|
|
}
|
|
|
|
public function profile()
|
|
{
|
|
$user_list = $this->MY_Model->get_by_id( user()->id , 'users');
|
|
$this->layout->set('userData', $user_list);
|
|
$this->layout->buffer('main_content', 'User/profile');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
public function editprofile($id)
|
|
{
|
|
$usertData = $this->user_model->get_user_by_md5_id($id,user()->business_id);
|
|
$this->layout->set('editData', $usertData);
|
|
$this->layout->buffer('main_content', 'User/edit_profile');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
public function editprofiles()
|
|
{
|
|
$table="users";
|
|
$action = $this->input->post();
|
|
|
|
$id = $this->input->post('id');
|
|
//file upload confic
|
|
$user_image['upload_path'] = APPPATH. '../assets/uploads/profile_picture';
|
|
$user_image['allowed_types'] = 'jpg|png';
|
|
$user_image['max_size'] = 80000;
|
|
//upload
|
|
$this->load->library('upload', $user_image);
|
|
$this->upload->initialize($user_image);
|
|
if ( ! $this->upload->do_upload('profile_image'))
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
|
|
unset($action['profile_image']);
|
|
} else{
|
|
$upload_user_image = $this->upload->data();
|
|
$action['profile_image'] = $upload_user_image['file_name'];
|
|
|
|
}
|
|
|
|
$userData = $this->MY_Model->edit_option($action, $id, $table);
|
|
redirect('user/profile');
|
|
}
|
|
|
|
|
|
public function changepassword()
|
|
{
|
|
// $password = md5(user()->password);
|
|
// $this->layout->set('pass', $password);
|
|
$this->layout->buffer('main_content', 'user/change_password');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
|
|
public function check_password()
|
|
{
|
|
$old_password = $this->input->post('old_password');
|
|
if (password_verify($old_password, user()->password)) {
|
|
$data['password'] = hash_password($this->input->post('password'));
|
|
$table="users";
|
|
$userData = $this->MY_Model->edit_option($data, user()->id, $table);
|
|
// $this->session->sess_destroy();
|
|
$data1['status'] = 'success';
|
|
$data1['csrf_hash'] = $this->security->get_csrf_hash();
|
|
echo json_encode($data1);
|
|
}
|
|
else{
|
|
$data['status'] = 'failed';
|
|
$data['csrf_hash'] = $this->security->get_csrf_hash();
|
|
echo json_encode($data);
|
|
}
|
|
}
|
|
|
|
|
|
public function businessProfile($business_id)
|
|
{
|
|
$business_list = $this->user_model->get_business_by_md5_id($business_id);
|
|
$this->layout->set('businessData', $business_list);
|
|
$this->layout->buffer('main_content', 'User/business');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
|
|
public function view_user_history($id)
|
|
{
|
|
$table = 'users';
|
|
$user_history = $this->audit_model->get_history( $id , $table , user()->business_id);
|
|
$data = array('title'=> "User History" , 'user_history'=> $user_history );
|
|
$htmlPage = $this->load->view('view_history.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
|
|
public function view_business_history($id)
|
|
{
|
|
$table = 'business';
|
|
$user_history = $this->audit_model->get_history( $id , $table , user()->business_id);
|
|
$data = array('title'=> "Business History" , 'user_history'=> $user_history );
|
|
$htmlPage = $this->load->view('view_history.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
}
|