place code into controller

This commit is contained in:
Uwe Steinmann 2016-04-13 18:31:28 +02:00
parent caf1501c89
commit 7e24402671
2 changed files with 116 additions and 61 deletions

View 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;
}
}

View File

@ -27,51 +27,29 @@ include("../inc/inc.Init.php");
include("../inc/inc.Extension.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassController.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"));
}
if (isset($_POST["action"])) $action=$_POST["action"];
else $action=NULL;
// add new role ---------------------------------------------------------
if ($action == "addrole") {
if(!in_array($action, array('addrole', 'removerole', 'editrole')))
UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
/* Check if the form data comes for a trusted request */
if(!checkFormKey('addrole')) {
/* Check if the form data comes for a trusted request */
if(!checkFormKey($action)) {
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 ------------------------------------------------------------
else if ($action == "removerole") {
/* Check if the form data comes for a trusted request */
if(!checkFormKey('removerole')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
$roleid = 0;
if(in_array($action, array('removerole', 'editrole'))) {
if (isset($_POST["roleid"])) {
$roleid = $_POST["roleid"];
}
@ -80,16 +58,52 @@ else if ($action == "removerole") {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_role_id"));
}
$roleToRemove = $dms->getRole($roleid);
if (!is_object($roleToRemove)) {
$roleobj = $dms->getRole($roleid);
if (!is_object($roleobj)) {
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"));
}
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')));
$roleid=-1;
@ -98,36 +112,21 @@ else if ($action == "removerole") {
// modify role ------------------------------------------------------------
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"];
$role = preg_replace('/[^0-2]+/', '', $_POST["role"]);
$noaccess = isset($_POST['noaccess']) ? $_POST['noaccess'] : null;
if ($editedRole->getName() != $name)
$editedRole->setName($name);
if ($editedRole->getRole() != $role)
$editedRole->setRole($role);
$editedRole->setNoAccess($noaccess);
$controller->setParam('name', $name);
$controller->setParam('role', $role);
$controller->setParam('noaccess', $noaccess);
if (!$controller($_POST)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$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);