You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.8 KiB
96 lines
2.8 KiB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
use app\core\utils\Response;
|
|
|
|
class UserRoleController extends MY_Controller {
|
|
public function __construct()
|
|
{
|
|
$this->my_parent_controller();
|
|
Response::handleSessionTimeout("bo");
|
|
//load language files
|
|
$this->load_language_backoffice();
|
|
$this->lang->load('backoffice/system_config', 'fr');
|
|
//load models
|
|
$this->load->model("UserRole");
|
|
}
|
|
|
|
public function fetch()
|
|
{
|
|
$data = $this->UserRole->all("datatables");
|
|
output_to_json($this, $data);
|
|
}
|
|
|
|
public function saveRole()
|
|
{
|
|
if (!$this->input->post('role') || !$this->input->post('privs')) {
|
|
output_to_json($this, [
|
|
"mtype" => "error",
|
|
"message" => "Please enter a role name"
|
|
]);
|
|
}
|
|
/* Save new role */
|
|
$role = new UserRole();
|
|
$role->name = $this->input->post('role');
|
|
$role->privs = $this->input->post('privs');
|
|
$save = $role->save();
|
|
if ($save === true) {
|
|
output_to_json($this, [
|
|
"mtype" => "success",
|
|
"message" => "User role added"
|
|
]);
|
|
}
|
|
output_to_json($this, $save);
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
if (!$this->input->post('role') || !$this->input->post('privs') || !$this->input->post('role_id')) {
|
|
output_to_json($this, [
|
|
"mtype" => "error",
|
|
"message" => "Please enter a role name"
|
|
]);
|
|
}
|
|
/* Save new role */
|
|
$role = new UserRole();
|
|
$role->role_id = $this->input->post('role_id');
|
|
$role->name = $this->input->post('role');
|
|
$role->privs = $this->input->post('privs');
|
|
$save = $role->update();
|
|
if ($save === true) {
|
|
output_to_json($this, [
|
|
"mtype" => "success",
|
|
"message" => "User role updated"
|
|
]);
|
|
}
|
|
output_to_json($this, $save);
|
|
}
|
|
|
|
public function delete()
|
|
{
|
|
if (!$this->input->post('roleId')) {
|
|
output_to_json($this, [
|
|
"mtype" => "error",
|
|
"message" => "Role id is required"
|
|
]);
|
|
}
|
|
/* Initialize role */
|
|
$role = new UserRole();
|
|
$role->role_id = $this->input->post('roleId');
|
|
|
|
if ($role->hasUserDependency()){
|
|
output_to_json($this, [
|
|
"mtype" => "error",
|
|
"message" => "User role is currently assigned to user"
|
|
]);
|
|
}
|
|
|
|
$delete = $role->delete();
|
|
if ($delete === true) {
|
|
output_to_json($this, [
|
|
"mtype" => "success",
|
|
"message" => "User role delete"
|
|
]);
|
|
}
|
|
output_to_json($this, $delete);
|
|
}
|
|
}
|