1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
<?php
/**
* Kalkun
* An open source web based SMS Management
*
* @package Kalkun
* @author Kalkun Dev Team
* @license https://spdx.org/licenses/GPL-2.0-or-later.html
* @link https://kalkun.sourceforge.io/
*/
// ------------------------------------------------------------------------
/**
* Users Class
*
* @package Kalkun
* @subpackage Users
* @category Controllers
*/
class Users extends MY_Controller {
/**
* Constructor
*
* @access public
*/
function __construct()
{
parent::__construct();
// check level
if ($this->session->userdata('level') !== 'admin')
{
$this->session->set_flashdata('notif', tr_raw('Access denied.'));
redirect('/');
}
$this->load->model('User_model');
}
// --------------------------------------------------------------------
/**
* Index
*
* Display list of all users
*
* @access public
*/
function index()
{
$data['title'] = tr_raw('User', 'default');
$this->load->library('pagination');
$config['base_url'] = site_url().'/users/index/';
$config['total_rows'] = $this->User_model->getUsers(array('option' => 'all'))->num_rows();
$config['per_page'] = $this->Kalkun_model->get_setting()->row('paging');
$config['cur_tag_open'] = '<span id="current">';
$config['cur_tag_close'] = '</span>';
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['pagination_links'] = $this->pagination->create_links();
$param = array('option' => 'paginate', 'limit' => $config['per_page'], 'offset' => $this->uri->segment(3, 0));
$data['main'] = 'main/users/index';
if ($_POST)
{
$data['users'] = $this->User_model->getUsers(array('option' => 'search'));
}
else
{
$data['users'] = $this->User_model->getUsers($param);
}
$this->load->helper('kalkun');
if (is_ajax())
{
$this->load->view('main/users/users_list', $data);
}
else
{
$this->load->view('main/layout', $data);
}
}
// --------------------------------------------------------------------
/**
* Add user
*
* Display Add/Update an user form
*
* @access public
*/
function add_user()
{
$this->load->helper('form');
$type = $this->input->get('type');
$data['tmp'] = '';
if ($type === 'edit')
{
$id_user = $this->input->get('param1');
$data['users'] = $this->User_model->getUsers(array('option' => 'by_iduser', 'id_user' => $id_user));
}
$this->load->view('main/users/add_user', $data);
}
// --------------------------------------------------------------------
/**
* Add user process
*
* Process the add/update user
*
* @access public
*/
function add_user_process()
{
$this->load->helper('kalkun');
$this->User_model->adduser();
if ($this->input->post('id_user'))
{
if ($this->config->item('demo_mode')
&& intval($this->input->post('id_user')) === 1)
{
if ($this->input->post('username') !== 'kalkun')
{
$return_msg = [
'type' => 'error',
'msg' => tr_raw('Modification of username of "kalkun" user forbidden in demo mode. Username was restored.'),
];
}
if ($this->input->post('level') !== 'admin')
{
$return_msg = [
'type' => 'error',
'msg' => tr_raw('Changing role of "kalkun" user forbidden in demo mode. Role was restored.'),
];
}
}
if ( ! isset($return_msg))
{
$return_msg = [
'type' => 'info',
'msg' => tr_raw('User updated successfully.'),
];
}
}
else
{
$return_msg = [
'type' => 'info',
'msg' => tr_raw('User added successfully.'),
];
}
// Return status
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($return_msg));
}
// --------------------------------------------------------------------
/**
* Delete user
*
* Delete an user
* All data related to deleted user (sms, phonebook, preference, etc) also deleted
*
* @access public
*/
function delete_user()
{
$uid = $this->input->post('id_user');
// get and delete all user_outbox
$res = $this->Message_model->get_messages(array('uid' => $uid, 'type' => 'outbox'));
foreach ($res->result() as $tmp)
{
$param = array('type' => 'single', 'option' => 'outbox', 'id_message' => $tmp->id_outbox);
$this->Message_model->delMessages($param);
}
// get and delete all user_inbox
$res = $this->Message_model->get_messages(array('uid' => $uid, 'type' => 'inbox'));
foreach ($res->result() as $tmp)
{
$param = array('type' => 'single', 'option' => 'permanent', 'source' => 'inbox', 'id_message' => $tmp->id_inbox);
$this->Message_model->delete_messages($param);
}
// get and delete all user_sentitems
$res = $this->Message_model->get_messages(array('uid' => $uid, 'type' => 'sentitems'));
foreach ($res->result() as $tmp)
{
$param = array('type' => 'single', 'option' => 'permanent', 'source' => 'sentitems', 'id_message' => $tmp->id_sentitems);
$this->Message_model->delete_messages($param);
}
// delete the rest (user, user_settings, pbk, pbk_groups, user_folders, sms_used)
$this->User_model->delUsers($this->input->post('id_user'));
}
}
|