File: //var/www/html/qcr24/app/application/controllers/admin/My_account.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class My_account extends MY_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('admin/maccount');
$this->load->model('admin/muser');
}
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$data['user_details'] = $this->maccount->get_user_details($this->admin_session_data['user_id']);
$data['user'] = $this->muser->edit_user($this->admin_session_data['user_id']);
$data['roles'] = $this->muser->get_role();
$data['content'] = 'admin/my-account';
$this->load->view('admin/layouts/index', $data);
}
public function updateaccount()
{
$user_id=$this->input->post('user_id');
$where = array(
'ma.email' => $this->input->post('email'),
'ma.user_id <>' => $user_id
);
$has_useremail = $this->muser->get_user($where);
if(!empty($has_useremail)){
echo json_encode(array('status'=>false,'msg'=>'Email is already used'));
}
else {
$data = array(
'full_name' => $this->input->post('full_name'),
'email' => $this->input->post('email'),
'gender' => $this->input->post('gender'),
'mobile_no' => $this->input->post('mobile_no'),
'address' => $this->input->post('address'),
'abn' => $this->input->post('abn'),
'tfn' => $this->input->post('tfn'),
'updated_by' => $this->admin_session_data['user_id'],
'updated_ts' => date('Y-m-d H:i:s')
);
if(!empty($_FILES['user_image']['name'])){
// Upload folder location***
$config['upload_path'] = './public/admin_images/user_images';
// Allowed file type***
$config['allowed_types'] = '*';
$config['encrypt_name'] = TRUE;
// load upload library***
$this->load->library('upload', $config);
$profile_pic_old = $this->input->post('profile_pic_old');
if ($this->upload->do_upload('user_image')) {
$data['user_image'] = $this->upload->data()['file_name'];
@unlink('./public/admin_images/user_images/' . $profile_pic_old);
} else {
$data['user_image'] = $profile_pic_old;
}
}
$condition = array('user_id' => $user_id);
$result = $this->muser->update_user($condition, $data);
if ($result) {
if(isset($data['user_image']) && !empty($data['user_image'])){
$user_data_set = $this->session->userdata('admin_data');
$user_data_set['user_image'] = $data['user_image'];
$this->session->set_userdata('admin_data', $user_data_set);
}
echo json_encode(array('status'=>true,'msg'=>'User Updated Successfully'));
}
}
}
}