move most of the code into the controller

This commit is contained in:
Uwe Steinmann 2017-10-12 15:39:28 +02:00
parent 0e9179a9e5
commit f6aa3bfc94
2 changed files with 116 additions and 343 deletions

View File

@ -26,8 +26,12 @@ 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");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1]);
if (!isset($_GET["documentid"]) || !is_numeric($_GET["documentid"]) || intval($_GET["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
@ -51,6 +55,7 @@ if(!checkFormKey('documentaccess', 'GET')) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_request_token"));
}
$mode = '';
switch ($_GET["action"]) {
case "setowner":
case "delaccess":
@ -78,6 +83,7 @@ switch ($_GET["action"]) {
break;
}
$userid = '';
if (isset($_GET["userid"])) {
if (!is_numeric($_GET["userid"])) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("unknown_user"));
@ -94,6 +100,7 @@ if (isset($_GET["userid"])) {
}
}
$groupid = '';
if (isset($_GET["groupid"])) {
if (!is_numeric($_GET["groupid"])) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("unknown_group"));
@ -109,37 +116,36 @@ if (isset($_GET["groupid"])) {
}
}
// Change owner -----------------------------------------------------------
if ($action == "setowner") {
$newowner = null;
if($action == 'setowner') {
if (!$user->isAdmin()) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
}
if (!isset($_GET["ownerid"]) || !is_numeric($_GET["ownerid"]) || $_GET["ownerid"]<1) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("unknown_user"));
if (empty($_GET["ownerid"])) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("unknown_group"));
}
if (!($newowner = $dms->getUser($_GET["ownerid"]))) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("unknown_group"));
}
$oldowner = $document->getOwner();
}
$newOwner = $dms->getUser($_GET["ownerid"]);
if (!is_object($newOwner)) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("unknown_user"));
}
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'preSetOwner')) {
$hookObj->preSetOwner(null, array('document'=>$document, 'newowner'=>$newowner));
}
}
}
$oldOwner = $document->getOwner();
if($document->setOwner($newOwner)) {
// Send notification to subscribers.
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'postSetOwner')) {
$hookObj->postSetOwner(null, array('document'=>$document, 'newowner'=>$newowner));
}
}
}
$controller->setParam('document', $document);
$controller->setParam('folder', $folder);
$controller->setParam('settings', $settings);
$controller->setParam('action', $action);
$controller->setParam('mode', $mode);
$controller->setParam('userid', $userid);
$controller->setParam('groupid', $groupid);
$controller->setParam('newowner', $newowner);
if(!$controller->run()) {
UI::exitError(getMLText("folder_title", array("foldername" => htmlspecialchars($foldername))),getMLText("error_change_access"));
}
// Change owner -----------------------------------------------------------
if ($action == "setowner") {
if($oldowner->getID() != $newowner->getID()) {
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
@ -149,8 +155,8 @@ if ($action == "setowner") {
$params['name'] = $document->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['old_owner'] = $oldOwner->getFullName();
$params['new_owner'] = $newOwner->getFullName();
$params['old_owner'] = $oldowner->getFullName();
$params['new_owner'] = $newowner->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
@ -158,8 +164,7 @@ if ($action == "setowner") {
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
// $notifier->toIndividual($user, $oldOwner, $subject, $message, $params);
// $notifier->toIndividual($user, $oldowner, $subject, $message, $params);
}
}
}
@ -167,14 +172,6 @@ if ($action == "setowner") {
// Change to not inherit ---------------------------------------------------
else if ($action == "notinherit") {
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'preSetNotInherit')) {
$hookObj->preSetOwner(null, array('document'=>$document));
}
}
}
if($document->setInheritAccess(false)) {
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
@ -193,64 +190,10 @@ else if ($action == "notinherit") {
}
}
}
$defAccess = $document->getDefaultAccess();
if($document->setDefaultAccess($defAccess)) {
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
$subject = "access_permission_changed_email_subject";
$message = "access_permission_changed_email_body";
$params = array();
$params['name'] = $document->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
//copy ACL of parent folder
if ($mode == "copy") {
$accessList = $folder->getAccessList();
foreach ($accessList["users"] as $userAccess)
$document->addAccess($userAccess->getMode(), $userAccess->getUserID(), true);
foreach ($accessList["groups"] as $groupAccess)
$document->addAccess($groupAccess->getMode(), $groupAccess->getGroupID(), false);
}
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'postSetNotInherit')) {
$hookObj->postSetNotInherit(null, array('document'=>$document));
}
}
}
}
// Change to inherit-----------------------------------------------------
else if ($action == "inherit") {
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'preSetInherit')) {
$hookObj->preSetInherit(null, array('document'=>$document));
}
}
}
if($document->clearAccessList() && $document->setInheritAccess(true)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'postSetInherit')) {
$hookObj->postSetInherit(null, array('document'=>$document));
}
}
}
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
@ -267,28 +210,11 @@ else if ($action == "inherit") {
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
}
// Set default permissions ----------------------------------------------
else if ($action == "setdefault") {
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'preSetDefaultAccess')) {
$hookObj->preSetDefaultAccess(null, array('document'=>$document));
}
}
}
if($document->setDefaultAccess($mode)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['documentAccess'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['documentAccess'] as $hookObj) {
if (method_exists($hookObj, 'postSetDefaultAccess')) {
$hookObj->postSetDefaultAccess(null, array('document'=>$document));
}
}
}
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
@ -305,39 +231,7 @@ else if ($action == "setdefault") {
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
}
// Modify permission ------------------------------------------------------
else if ($action == "editaccess") {
if (isset($userid)) {
$document->changeAccess($mode, $userid, true);
}
else if (isset($groupid)) {
$document->changeAccess($mode, $groupid, false);
}
}
// Delete permission-------------------------------------------------------
else if ($action == "delaccess") {
if (isset($userid)) {
$document->removeAccess($userid, true);
}
else if (isset($groupid)) {
$document->removeAccess($groupid, false);
}
}
// Add new permission -----------------------------------------------------
else if ($action == "addaccess") {
if (isset($userid) && $userid != -1) {
$document->addAccess($mode, $userid, true);
}
if (isset($groupid) && $groupid != -1) {
$document->addAccess($mode, $groupid, false);
}
}
add_log_line("");

View File

@ -26,8 +26,12 @@ 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");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1]);
if (!isset($_POST["documentid"]) || !is_numeric($_POST["documentid"]) || intval($_POST["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
@ -73,74 +77,6 @@ if(isset($_POST["attributes"]))
else
$attributes = array();
if (($oldname = $document->getName()) != $name) {
if($document->setName($name)) {
// Send notification to subscribers.
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
$subject = "document_renamed_email_subject";
$message = "document_renamed_email_body";
$params = array();
$params['name'] = $document->getName();
$params['old_name'] = $oldname;
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
// if user is not owner send notification to owner
if ($user->getID() != $document->getOwner()->getID() &&
false === SeedDMS_Core_DMS::inList($document->getOwner(), $notifyList['users'])) {
$notifyList['users'][] = $document->getOwner();
}
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
}
if (($oldcomment = $document->getComment()) != $comment) {
if($document->setComment($comment)) {
// Send notification to subscribers.
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
$subject = "document_comment_changed_email_subject";
$message = "document_comment_changed_email_body";
$params = array();
$params['name'] = $document->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['old_comment'] = $oldcomment;
$params['new_comment'] = $comment;
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
// if user is not owner send notification to owner
if ($user->getID() != $document->getOwner()->getID() &&
false === SeedDMS_Core_DMS::inList($document->getOwner(), $notifyList['users'])) {
$notifyList['users'][] = $document->getOwner();
}
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
}
switch($_POST["presetexpdate"]) {
case "date":
$tmp = explode('-', $_POST["expdate"]);
@ -168,16 +104,85 @@ default:
break;
}
if ($expires != $document->getExpires()) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'preSetExpires')) {
$hookObj->preSetExpires(null, array('document'=>$document, 'expires'=>&$expires));
$oldname = $document->getName();
$oldcomment = $document->getComment();
$oldcategories = $document->getCategories();
$oldkeywords = $document->getKeywords();
$oldexpires = $document->getExpires();
$oldattributes = $document->getAttributes();
$controller->setParam('document', $document);
$controller->setParam('name', $name);
$controller->setParam('comment', $comment);
$controller->setParam('keywords', $keywords);
$controller->setParam('categories', $categories);
$controller->setParam('expires', $expires);
$controller->setParam('sequence', $sequence);
$controller->setParam('attributes', $attributes);
if(!$controller->run()) {
if($controller->getErrorNo()) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())), $controller->getErrorMsg());
}
}
if ($oldname != $name) {
// Send notification to subscribers.
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
$subject = "document_renamed_email_subject";
$message = "document_renamed_email_body";
$params = array();
$params['name'] = $document->getName();
$params['old_name'] = $oldname;
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
// if user is not owner send notification to owner
if ($user->getID() != $document->getOwner()->getID() &&
false === SeedDMS_Core_DMS::inList($document->getOwner(), $notifyList['users'])) {
$notifyList['users'][] = $document->getOwner();
}
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
}
if($document->setExpires($expires)) {
if ($oldcomment != $comment) {
// Send notification to subscribers.
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
$subject = "document_comment_changed_email_subject";
$message = "document_comment_changed_email_body";
$params = array();
$params['name'] = $document->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['old_comment'] = $oldcomment;
$params['new_comment'] = $comment;
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
// if user is not owner send notification to owner
if ($user->getID() != $document->getOwner()->getID() &&
false === SeedDMS_Core_DMS::inList($document->getOwner(), $notifyList['users'])) {
$notifyList['users'][] = $document->getOwner();
}
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
if ($expires != $oldexpires) {
if($notifier) {
$notifyList = $document->getNotifyList();
$folder = $document->getFolder();
@ -202,135 +207,9 @@ if ($expires != $document->getExpires()) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
} else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
$document->verifyLastestContentExpriry();
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'postSetExpires')) {
$hookObj->postSetExpires(null, array('document'=>$document, 'expires'=>$expires));
}
}
}
}
if (($oldkeywords = $document->getKeywords()) != $keywords) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'preSetKeywords')) {
$hookObj->preSetKeywords(null, array('document'=>$document, 'keywords'=>&$keywords, 'oldkeywords'=>&$oldkeywords));
}
}
}
if($document->setKeywords($keywords)) {
}
else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'postSetKeywords')) {
$hookObj->postSetKeywords(null, array('document'=>$document, 'keywords'=>&$keywords, 'oldkeywords'=>&$oldkeywords));
}
}
}
}
$oldcategories = $document->getCategories();
if($categories) {
$categoriesarr = array();
foreach($categories as $catid) {
if($cat = $dms->getDocumentCategory($catid)) {
$categoriesarr[] = $cat;
}
}
$oldcatsids = array();
foreach($oldcategories as $oldcategory)
$oldcatsids[] = $oldcategory->getID();
if (count($categoriesarr) != count($oldcategories) ||
array_diff($categories, $oldcatsids)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'preSetCategories')) {
$hookObj->preSetCategories(null, array('document'=>$document, 'categories'=>&$categoriesarr, 'oldcategories'=>&$oldcategories));
}
}
}
if($document->setCategories($categoriesarr)) {
} else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'postSetCategories')) {
$hookObj->postSetCategories(null, array('document'=>$document, 'categories'=>&$categoriesarr, 'oldcategories'=>&$oldcategories));
}
}
}
}
} elseif($oldcategories) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'preSetCategories')) {
$hookObj->preSetCategories(null, array('document'=>$document, 'categories'=>array(), 'oldcategories'=>&$oldcategories));
}
}
}
if($document->setCategories(array())) {
} else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
if(isset($GLOBALS['SEEDDMS_HOOKS']['editDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['editDocument'] as $hookObj) {
if (method_exists($hookObj, 'postSetCategories')) {
$hookObj->postSetCategories(null, array('document'=>$document, 'categories'=>array(), 'oldcategories'=>&$oldcategories));
}
}
}
}
$oldattributes = $document->getAttributes();
if($attributes) {
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
if(!$attrdef->validate($attribute)) {
$errmsg = getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute);
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())), $errmsg);
}
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
if(!$document->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
} elseif($attrdef->getMinValues() > 0) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("attr_min_values", array("attrname"=>$attrdef->getName())));
} elseif(isset($oldattributes[$attrdefid])) {
if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
}
}
foreach($oldattributes as $attrdefid=>$oldattribute) {
if(!isset($attributes[$attrdefid])) {
if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
}
if($sequence != "keep") {
if($document->setSequence($sequence)) {
}
else {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
if ($oldkeywords != $keywords) {
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_document_edited')));