File: //var/www/html/taxicamera/applicationold/controllers/admin/User.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends MY_Controller {
public function __construct() {
parent::__construct();
//$this->redirect_guest();
$this->load->model('admin/muser');
if($this->session->userdata('admin') != 1)
{
redirect('admin');
}
}
// Default load function for header and footer inculded
private function _load_view($data) {
$this->load->view('admin/layouts/index',$data);
}
/*
author: soumya hazra
purpose: user Listing
date: 9-9-2019
*/
public function index()
{
$result = array();
$result['users'] = $this->muser->get_user();
$result['users_inc'] = $this->muser->get_user_inactive();
// print_r($result['users_inc']);die;
$result['content']='admin/user/list';
$this->_load_view($result);
}
/*
author: soumya hazra
purpose: add Sub admin view
date: 9-9-2019
*/
public function addsubadmin()
{
$result = array();
$result['roles'] = $this->muser->actv_roles();
$result['content']='admin/user/add';
$this->_load_view($result);
}
/*
author: soumya hazra
purpose: add Sub admin
date: 9-9-2019
*/
public function submit_new_user()
{
//PR($_POST);
$data = array();
$result = array();
$data = array(
'first_name' => $this->input->post( 'first_name' ),
'middle_name' => $this->input->post( 'middle_name' ),
'last_name' => $this->input->post( 'last_name' ),
'role_id' => $this->input->post( 'role_id' ),
'email' => $this->input->post( 'email' ),
'mobile' => $this->input->post( 'mobile' ),
'emergency_contact' => $this->input->post( 'emergency_contact' ),
'dob' => date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post( 'dob' )))),
'flat_no' => $this->input->post( 'flat_no' ),
'street_no' => $this->input->post( 'street_no' ),
'street_name' => $this->input->post( 'street_name' ),
'suburb' => $this->input->post( 'suburb' ),
'state' => $this->input->post( 'state' ),
'pin' => $this->input->post( 'pin' ),
'tfn' => $this->input->post( 'tfn' ),
'abn' => $this->input->post( 'abn' ),
'password' => md5($this->input->post( 'password' )),
'org_password' =>$this->input->post( 'password' ),
'bank_name' => $this->input->post( 'bank_name' ),
'bsb' => $this->input->post( 'bsb' ),
'account_no' => $this->input->post( 'account_no' ),
'created_by' => $this->session->userdata('user_data'),
'created_ts' => date('Y-m-d H:i:s')
);
$result = $this->muser->submit_new_user($data);
if($result)
{
$this->session->set_flashdata('success_msg','User added successfully');
redirect('admin/user');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soumya hazra
purpose: Upddate Sub admin
date: 9-9-2019
*/
public function update_user()
{
$data = array();
$result = array();
$data = array(
'first_name' => $this->input->post( 'first_name' ),
'middle_name' => $this->input->post( 'middle_name' ),
'last_name' => $this->input->post( 'last_name' ),
'role_id' => $this->input->post( 'role_id' ),
'email' => $this->input->post( 'email' ),
'mobile' => $this->input->post( 'mobile' ),
'emergency_contact' => $this->input->post( 'emergency_contact' ),
'dob' => date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post( 'dob' )))),
'flat_no' => $this->input->post( 'flat_no' ),
'street_no' => $this->input->post( 'street_no' ),
'street_name' => $this->input->post( 'street_name' ),
'suburb' => $this->input->post( 'suburb' ),
'password' => md5($this->input->post( 'password' )),
'org_password' =>$this->input->post( 'password' ),
'state' => $this->input->post( 'state' ),
'pin' => $this->input->post( 'pin' ),
'tfn' => $this->input->post( 'tfn' ),
'abn' => $this->input->post( 'abn' ),
'bank_name' => $this->input->post( 'bank_name' ),
'bsb' => $this->input->post( 'bsb' ),
'account_no' => $this->input->post( 'account_no' ),
'updated_by' => $this->session->userdata('user_data'),
'updated_ts' => date('Y-m-d H:i:s'),
);
$uid = $this->input->post( 'user_id' );
$result = $this->muser->update_user($data,$uid);
if($result)
{
$this->session->set_flashdata('success_msg','User updated successfully');
redirect('admin/user');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soumya hazra
purpose: Get single user
date: 10-9-2019
*/
public function edituser($uid)
{
$result['roles'] = $this->muser->actv_roles();
$result['singl_user'] = $this->muser->singl_user($uid);
$result['content']='admin/user/add';
$this->_load_view($result);
}
/*
author: soma
purpose: Set a user deactive
date: 18-9-2019
*/
public function set_deactive_user($user_id)
{
$result = array();
$result = $this->muser->set_deactive_user($user_id);
if($result)
{
$this->session->set_flashdata('success_msg','Deactivated successfully');
redirect('admin/user');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soma
purpose: Set a user Active
date: 18-9-2019
*/
public function set_active_user($user_id)
{
$result = array();
$result = $this->muser->set_active_user($user_id);
if($result)
{
$this->session->set_flashdata('success_msg','Activated successfully...');
redirect('admin/user');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soma
purpose: delete a user
date: 18-9-2019
*/
public function delete_user($user_id)
{
$result = array();
$result = $this->muser->delete_user($user_id);
if($result)
{
$this->session->set_flashdata('success_msg','Deleted successfully...');
redirect('admin/user');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soma
purpose: restore user
date: 18-9-2019
*/
public function restore_user($user_id)
{
$result = array();
$result = $this->muser->restore_user($user_id);
if($result)
{
$this->session->set_flashdata('success_msg','Restored successfully...');
redirect('admin/user');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
public function test()
{
echo "okkkkkkkkkkkkk";die;
}
public function check_email_already_exist(){
$user_id =$this->input->post('user_id');
$email =$this->input->post('email');
$condition=array('email'=>$email);
if($user_id){
$condition['user_id !='.$user_id] = NULL;
}
$user_data=$this->mcommon->getRow('master_user',$condition);
//echo $this->db->last_query();die;
if(empty($user_data)){
$return_data=array('status'=>true);
} else {
$return_data=array('status'=>false);
}
echo json_encode($return_data);
}
}