seeddms-code/op/op.GroupMgr.php

243 lines
7.8 KiB
PHP
Raw Normal View History

2013-04-10 19:48:16 +00:00
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010 Matteo Lucarelli
2016-08-09 05:34:30 +00:00
// Copyright (C) 2010-2016 Uwe Steinmann
2013-04-10 19:48:16 +00:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include("../inc/inc.Settings.php");
2022-11-09 05:40:50 +00:00
include("../inc/inc.Utils.php");
2013-04-10 19:48:16 +00:00
include("../inc/inc.LogInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.Init.php");
include("../inc/inc.Extension.php");
include("../inc/inc.DBInit.php");
2013-04-10 19:48:16 +00:00
include("../inc/inc.ClassUI.php");
include("../inc/inc.Authentication.php");
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
2010-10-29 13:19:51 +00:00
}
if (isset($_POST["action"])) $action = $_POST["action"];
else $action = null;
2013-04-10 19:48:16 +00:00
// Create new group --------------------------------------------------------
if ($action == "addgroup") {
2016-10-05 14:23:22 +00:00
/* Check if the form data comes from a trusted request */
if(!checkFormKey('addgroup')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
2013-04-10 19:48:16 +00:00
$name = $_POST["name"];
2021-05-27 17:52:13 +00:00
if(!$name) {
UI::exitError(getMLText("admin_tools"),getMLText("group_name_missing"));
}
2013-04-10 19:48:16 +00:00
$comment = $_POST["comment"];
2021-05-27 17:52:13 +00:00
if ($settings->_strictFormCheck && !$comment) {
UI::exitError(getMLText("admin_tools"),getMLText("group_comment_missing"));
}
2013-04-10 19:48:16 +00:00
if (is_object($dms->getGroupByName($name))) {
2013-04-10 19:48:16 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("group_exists"));
}
$newGroup = $dms->addGroup($name, $comment);
if (!$newGroup) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
2010-10-29 13:19:51 +00:00
}
$groupid=$newGroup->getID();
2013-04-10 19:48:16 +00:00
2013-06-14 08:27:17 +00:00
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_add_group')));
add_log_line("&action=addgroup&name=".$name);
2013-04-10 19:48:16 +00:00
}
// Delete group -------------------------------------------------------------
else if ($action == "removegroup") {
2016-10-05 14:23:22 +00:00
/* Check if the form data comes from a trusted request */
if(!checkFormKey('removegroup')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
2010-10-29 13:19:51 +00:00
if (!isset($_POST["groupid"]) || !is_numeric($_POST["groupid"]) || intval($_POST["groupid"])<1) {
2013-04-10 19:48:16 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
$group = $dms->getGroup($_POST["groupid"]);
if (!is_object($group)) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
if (!$group->remove($user)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$groupid = '';
2013-06-14 08:27:17 +00:00
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_rm_group')));
add_log_line("?groupid=".$_POST["groupid"]."&action=removegroup");
2013-04-10 19:48:16 +00:00
}
// Modifiy group ------------------------------------------------------------
else if ($action == "editgroup") {
2016-10-05 14:23:22 +00:00
/* Check if the form data comes from a trusted request */
if(!checkFormKey('editgroup')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
2013-04-10 19:48:16 +00:00
if (!isset($_POST["groupid"]) || !is_numeric($_POST["groupid"]) || intval($_POST["groupid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
2010-10-29 13:19:51 +00:00
}
2013-04-10 19:48:16 +00:00
$groupid=$_POST["groupid"];
$group = $dms->getGroup($groupid);
2013-04-10 19:48:16 +00:00
if (!is_object($group)) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
$name = $_POST["name"];
$comment = $_POST["comment"];
if ($group->getName() != $name)
$group->setName($name);
if ($group->getComment() != $comment)
2010-10-29 13:19:51 +00:00
$group->setComment($comment);
2013-04-10 19:48:16 +00:00
2013-06-14 08:27:17 +00:00
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_edit_group')));
add_log_line("?groupid=".$_POST["groupid"]."&action=editgroup");
2013-04-10 19:48:16 +00:00
}
// Add user to group --------------------------------------------------------
2010-10-29 13:19:51 +00:00
else if ($action == "addmember") {
2013-04-10 19:48:16 +00:00
2016-10-05 14:23:22 +00:00
/* Check if the form data comes from a trusted request */
if(!checkFormKey('addmember')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
2013-04-10 19:48:16 +00:00
if (!isset($_POST["groupid"]) || !is_numeric($_POST["groupid"]) || intval($_POST["groupid"])<1) {
2010-10-29 13:19:51 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
2013-04-10 19:48:16 +00:00
$groupid=$_POST["groupid"];
$group = $dms->getGroup($groupid);
2013-04-10 19:48:16 +00:00
if (!is_object($group)) {
2010-10-29 13:19:51 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
2013-04-10 19:48:16 +00:00
}
2010-10-29 13:19:51 +00:00
if (!isset($_POST["userid"]) || !is_numeric($_POST["userid"]) || intval($_POST["userid"])<1) {
2013-04-10 19:48:16 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_user_id"));
}
$newMember = $dms->getUser($_POST["userid"]);
if (!is_object($newMember)) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_user_id"));
2010-10-29 13:19:51 +00:00
}
if (!$group->isMember($newMember)){
$group->addUser($newMember);
if (isset($_POST["manager"])) $group->toggleManager($newMember);
}
2013-06-14 08:27:17 +00:00
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_add_group_member')));
add_log_line("?groupid=".$groupid."&userid=".$_POST["userid"]."&action=addmember");
2013-04-10 19:48:16 +00:00
}
// Remove user from group --------------------------------------------------
else if ($action == "rmmember") {
2016-10-05 14:23:22 +00:00
/* Check if the form data comes from a trusted request */
if(!checkFormKey('rmmember')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
2013-04-10 19:48:16 +00:00
if (!isset($_POST["groupid"]) || !is_numeric($_POST["groupid"]) || intval($_POST["groupid"])<1) {
2010-10-29 13:19:51 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
2013-04-10 19:48:16 +00:00
$groupid=$_POST["groupid"];
$group = $dms->getGroup($groupid);
2013-04-10 19:48:16 +00:00
if (!is_object($group)) {
2010-10-29 13:19:51 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
2013-04-10 19:48:16 +00:00
if (!isset($_POST["userid"]) || !is_numeric($_POST["userid"]) || intval($_POST["userid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_user_id"));
}
$oldMember = $dms->getUser($_POST["userid"]);
if (!is_object($oldMember)) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_user_id"));
}
2010-10-29 13:19:51 +00:00
$group->removeUser($oldMember);
2013-06-14 08:27:17 +00:00
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_rm_group_member')));
add_log_line("?groupid=".$groupid."&userid=".$_POST["userid"]."&action=rmmember");
2010-10-29 13:19:51 +00:00
}
// toggle manager flag
2013-04-10 19:48:16 +00:00
else if ($action == "tmanager") {
2010-10-29 13:19:51 +00:00
2016-10-05 14:23:22 +00:00
/* Check if the form data comes from a trusted request */
if(!checkFormKey('tmanager')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
2013-04-10 19:48:16 +00:00
if (!isset($_POST["groupid"]) || !is_numeric($_POST["groupid"]) || intval($_POST["groupid"])<1) {
2010-10-29 13:19:51 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
2013-04-10 19:48:16 +00:00
$groupid=$_POST["groupid"];
$group = $dms->getGroup($groupid);
2010-10-29 13:19:51 +00:00
2013-04-10 19:48:16 +00:00
if (!is_object($group)) {
2010-10-29 13:19:51 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("invalid_group_id"));
}
2013-04-10 19:48:16 +00:00
if (!isset($_POST["userid"]) || !is_numeric($_POST["userid"]) || intval($_POST["userid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_user_id"));
}
$usertoedit = $dms->getUser($_POST["userid"]);
if (!is_object($usertoedit)) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_user_id"));
}
2010-10-29 13:19:51 +00:00
$group->toggleManager($usertoedit);
2013-06-14 08:27:17 +00:00
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_toogle_group_manager')));
add_log_line("?groupid=".$groupid."&userid=".$_POST["userid"]."&action=tmanager");
2010-10-29 13:19:51 +00:00
}
2013-04-10 19:48:16 +00:00
2010-10-29 13:19:51 +00:00
header("Location:../out/out.GroupMgr.php?groupid=".$groupid);
2013-04-10 19:48:16 +00:00
?>