mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
place code into controller
This commit is contained in:
parent
caf1501c89
commit
7e24402671
56
controllers/class.RoleMgr.php
Normal file
56
controllers/class.RoleMgr.php
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of Role manager controller
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @license GPL 2
|
||||||
|
* @version @version@
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class which does the busines logic for role manager
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class SeedDMS_Controller_RoleMgr extends SeedDMS_Controller_Common {
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addrole() {
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$name = $this->params['name'];
|
||||||
|
$role = $this->params['role'];
|
||||||
|
|
||||||
|
return($dms->addRole($name, $role));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removerole() {
|
||||||
|
$roleobj = $this->params['roleobj'];
|
||||||
|
return $roleobj->remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editrole() {
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$name = $this->params['name'];
|
||||||
|
$role = $this->params['role'];
|
||||||
|
$roleobj = $this->params['roleobj'];
|
||||||
|
$noaccess = $this->params['noaccess'];
|
||||||
|
|
||||||
|
if ($roleobj->getName() != $name)
|
||||||
|
$roleobj->setName($name);
|
||||||
|
if ($roleobj->getRole() != $role)
|
||||||
|
$roleobj->setRole($role);
|
||||||
|
$roleobj->setNoAccess($noaccess);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,51 +27,29 @@ include("../inc/inc.Init.php");
|
||||||
include("../inc/inc.Extension.php");
|
include("../inc/inc.Extension.php");
|
||||||
include("../inc/inc.DBInit.php");
|
include("../inc/inc.DBInit.php");
|
||||||
include("../inc/inc.ClassUI.php");
|
include("../inc/inc.ClassUI.php");
|
||||||
|
include("../inc/inc.ClassController.php");
|
||||||
include("../inc/inc.Authentication.php");
|
include("../inc/inc.Authentication.php");
|
||||||
include("../inc/inc.ClassPasswordStrength.php");
|
|
||||||
|
|
||||||
if (!$user->isAdmin()) {
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
|
$controller = Controller::factory($tmp[1]);
|
||||||
|
$accessop = new SeedDMS_AccessOperation($dms, $user, $settings);
|
||||||
|
if (!$accessop->check_controller_access($controller, $_POST)) {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST["action"])) $action=$_POST["action"];
|
if (isset($_POST["action"])) $action=$_POST["action"];
|
||||||
else $action=NULL;
|
else $action=NULL;
|
||||||
|
|
||||||
// add new role ---------------------------------------------------------
|
if(!in_array($action, array('addrole', 'removerole', 'editrole')))
|
||||||
if ($action == "addrole") {
|
UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
|
||||||
|
|
||||||
/* Check if the form data comes for a trusted request */
|
/* Check if the form data comes for a trusted request */
|
||||||
if(!checkFormKey('addrole')) {
|
if(!checkFormKey($action)) {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
|
||||||
}
|
|
||||||
|
|
||||||
$name = $_POST["name"];
|
|
||||||
$role = preg_replace('/[^0-2]+/', '', $_POST["role"]);
|
|
||||||
|
|
||||||
if (is_object($dms->getRoleByName($name))) {
|
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("role_exists"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$newRole = $dms->addRole($name, $role);
|
|
||||||
if ($newRole) {
|
|
||||||
}
|
|
||||||
else UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
|
||||||
|
|
||||||
$roleid=$newRole->getID();
|
|
||||||
|
|
||||||
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_add_role')));
|
|
||||||
|
|
||||||
add_log_line(".php&action=addrole&name=".$name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete role ------------------------------------------------------------
|
$roleid = 0;
|
||||||
else if ($action == "removerole") {
|
if(in_array($action, array('removerole', 'editrole'))) {
|
||||||
|
|
||||||
/* Check if the form data comes for a trusted request */
|
|
||||||
if(!checkFormKey('removerole')) {
|
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST["roleid"])) {
|
if (isset($_POST["roleid"])) {
|
||||||
$roleid = $_POST["roleid"];
|
$roleid = $_POST["roleid"];
|
||||||
}
|
}
|
||||||
|
@ -80,16 +58,52 @@ else if ($action == "removerole") {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
$roleToRemove = $dms->getRole($roleid);
|
$roleobj = $dms->getRole($roleid);
|
||||||
if (!is_object($roleToRemove)) {
|
|
||||||
|
if (!is_object($roleobj)) {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$roleToRemove->remove()) {
|
$controller->setParam('roleobj', $roleobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add new role ---------------------------------------------------------
|
||||||
|
if ($action == "addrole") {
|
||||||
|
|
||||||
|
$name = $_POST["name"];
|
||||||
|
$role = preg_replace('/[^0-2]+/', '', $_POST["role"]);
|
||||||
|
|
||||||
|
if (is_object($dms->getRoleByName($name))) {
|
||||||
|
UI::exitError(getMLText("admin_tools"),getMLText("role_exists"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($role === '') {
|
||||||
|
UI::exitError(getMLText("admin_tools"),getMLText("missing_role_type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$controller->setParam('name', $name);
|
||||||
|
$controller->setParam('role', $role);
|
||||||
|
|
||||||
|
$newRole = $controller($_POST);
|
||||||
|
if ($newRole) {
|
||||||
|
}
|
||||||
|
else UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||||
|
|
||||||
|
$roleid=$newRole->getID();
|
||||||
|
|
||||||
|
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_add_role')));
|
||||||
|
|
||||||
|
add_log_line(".php&action=".$action."&name=".$name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete role ------------------------------------------------------------
|
||||||
|
else if ($action == "removerole") {
|
||||||
|
|
||||||
|
if (!$controller($_POST)) {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||||
}
|
}
|
||||||
|
|
||||||
add_log_line(".php&action=removerole&roleid=".$roleid);
|
add_log_line(".php&action=".$action."&roleid=".$roleid);
|
||||||
|
|
||||||
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_rm_role')));
|
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_rm_role')));
|
||||||
$roleid=-1;
|
$roleid=-1;
|
||||||
|
@ -98,36 +112,21 @@ else if ($action == "removerole") {
|
||||||
// modify role ------------------------------------------------------------
|
// modify role ------------------------------------------------------------
|
||||||
else if ($action == "editrole") {
|
else if ($action == "editrole") {
|
||||||
|
|
||||||
/* Check if the form data comes for a trusted request */
|
|
||||||
if(!checkFormKey('editrole')) {
|
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($_POST["roleid"]) || !is_numeric($_POST["roleid"]) || intval($_POST["roleid"])<1) {
|
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$roleid=$_POST["roleid"];
|
|
||||||
$editedRole = $dms->getRole($roleid);
|
|
||||||
|
|
||||||
if (!is_object($editedRole)) {
|
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$name = $_POST["name"];
|
$name = $_POST["name"];
|
||||||
$role = preg_replace('/[^0-2]+/', '', $_POST["role"]);
|
$role = preg_replace('/[^0-2]+/', '', $_POST["role"]);
|
||||||
$noaccess = isset($_POST['noaccess']) ? $_POST['noaccess'] : null;
|
$noaccess = isset($_POST['noaccess']) ? $_POST['noaccess'] : null;
|
||||||
|
|
||||||
if ($editedRole->getName() != $name)
|
$controller->setParam('name', $name);
|
||||||
$editedRole->setName($name);
|
$controller->setParam('role', $role);
|
||||||
if ($editedRole->getRole() != $role)
|
$controller->setParam('noaccess', $noaccess);
|
||||||
$editedRole->setRole($role);
|
|
||||||
$editedRole->setNoAccess($noaccess);
|
if (!$controller($_POST)) {
|
||||||
|
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||||
|
}
|
||||||
|
|
||||||
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_edit_role')));
|
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_edit_role')));
|
||||||
add_log_line(".php&action=editrole&roleid=".$roleid);
|
add_log_line(".php&action=".$action."&roleid=".$roleid);
|
||||||
}
|
}
|
||||||
else UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
|
|
||||||
|
|
||||||
header("Location:../out/out.RoleMgr.php?roleid=".$roleid);
|
header("Location:../out/out.RoleMgr.php?roleid=".$roleid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user