mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-06-18 02:59:27 +00:00
put controller code into controller/class.EditFolder.php
This commit is contained in:
parent
4483fb52cc
commit
1be9052c85
106
controllers/class.EditFolder.php
Normal file
106
controllers/class.EditFolder.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of EditFolder 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 editing a folder
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class SeedDMS_Controller_EditFolder extends SeedDMS_Controller_Common {
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$user = $this->params['user'];
|
||||||
|
$settings = $this->params['settings'];
|
||||||
|
$folder = $this->params['folder'];
|
||||||
|
$name = $this->params['name'];
|
||||||
|
$comment = $this->params['comment'];
|
||||||
|
$sequence = $this->params['sequence'];
|
||||||
|
$attributes = $this->params['attributes'];
|
||||||
|
$index = $this->params['index'];
|
||||||
|
|
||||||
|
/* Get the document id and name before removing the document */
|
||||||
|
$foldername = $folder->getName();
|
||||||
|
$folderid = $folder->getID();
|
||||||
|
|
||||||
|
if(!$this->callHook('preEditFolder')) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->callHook('editFolder', $folder);
|
||||||
|
if($result === null) {
|
||||||
|
if(($oldname = $folder->getName()) != $name)
|
||||||
|
if(!$folder->setName($name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(($oldcomment = $folder->getComment()) != $comment)
|
||||||
|
if(!$folder->setComment($comment))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$oldattributes = $folder->getAttributes();
|
||||||
|
if($attributes) {
|
||||||
|
foreach($attributes as $attrdefid=>$attribute) {
|
||||||
|
$attrdef = $dms->getAttributeDefinition($attrdefid);
|
||||||
|
if($attribute) {
|
||||||
|
if($attrdef->getRegex()) {
|
||||||
|
if(!preg_match($attrdef->getRegex(), $attribute)) {
|
||||||
|
$this->error = 1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_array($attribute)) {
|
||||||
|
if($attrdef->getMinValues() > count($attribute)) {
|
||||||
|
$this->error = 2;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($attrdef->getMaxValues() && $attrdef->getMaxValues() < count($attribute)) {
|
||||||
|
$this->error = 3;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
||||||
|
if(!$folder->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif(isset($oldattributes[$attrdefid])) {
|
||||||
|
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($oldattributes as $attrdefid=>$oldattribute) {
|
||||||
|
if(!isset($attributes[$attrdefid])) {
|
||||||
|
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcasecmp($sequence, "keep")) {
|
||||||
|
if($folder->setSequence($sequence)) {
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->callHook('postEditFolder')) {
|
||||||
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,12 +20,18 @@
|
||||||
include("../inc/inc.Settings.php");
|
include("../inc/inc.Settings.php");
|
||||||
include("../inc/inc.LogInit.php");
|
include("../inc/inc.LogInit.php");
|
||||||
include("../inc/inc.Utils.php");
|
include("../inc/inc.Utils.php");
|
||||||
include("../inc/inc.DBInit.php");
|
|
||||||
include("../inc/inc.Language.php");
|
include("../inc/inc.Language.php");
|
||||||
|
include("../inc/inc.Init.php");
|
||||||
|
include("../inc/inc.Extension.php");
|
||||||
|
include("../inc/inc.DBInit.php");
|
||||||
include("../inc/inc.ClassUI.php");
|
include("../inc/inc.ClassUI.php");
|
||||||
|
include("../inc/inc.ClassController.php");
|
||||||
include("../inc/inc.ClassEmail.php");
|
include("../inc/inc.ClassEmail.php");
|
||||||
include("../inc/inc.Authentication.php");
|
include("../inc/inc.Authentication.php");
|
||||||
|
|
||||||
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
|
$controller = Controller::factory($tmp[1]);
|
||||||
|
|
||||||
if (!isset($_POST["folderid"]) || !is_numeric($_POST["folderid"]) || intval($_POST["folderid"])<1) {
|
if (!isset($_POST["folderid"]) || !is_numeric($_POST["folderid"]) || intval($_POST["folderid"])<1) {
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => getMLText("invalid_folder_id"))),getMLText("invalid_folder_id"));
|
UI::exitError(getMLText("folder_title", array("foldername" => getMLText("invalid_folder_id"))),getMLText("invalid_folder_id"));
|
||||||
}
|
}
|
||||||
|
@ -58,141 +64,82 @@ if(isset($_POST["attributes"]))
|
||||||
else
|
else
|
||||||
$attributes = array();
|
$attributes = array();
|
||||||
|
|
||||||
$wasupdated = false;
|
$oldname = $folder->getName();
|
||||||
if(($oldname = $folder->getName()) != $name) {
|
$oldcomment = $folder->getComment();
|
||||||
if($folder->setName($name)) {
|
|
||||||
// Send notification to subscribers.
|
|
||||||
if($notifier) {
|
|
||||||
$notifyList = $folder->getNotifyList();
|
|
||||||
/*
|
|
||||||
$subject = "###SITENAME###: ".$folder->getName()." - ".getMLText("folder_renamed_email");
|
|
||||||
$message = getMLText("folder_renamed_email")."\r\n";
|
|
||||||
$message .=
|
|
||||||
getMLText("old").": ".$oldname."\r\n".
|
|
||||||
getMLText("new").": ".$folder->getName()."\r\n".
|
|
||||||
getMLText("folder").": ".$folder->getFolderPathPlain()."\r\n".
|
|
||||||
getMLText("comment").": ".$comment."\r\n".
|
|
||||||
"URL: ###URL_PREFIX###out/out.ViewFolder.php?folderid=".$folder->getID()."\r\n";
|
|
||||||
|
|
||||||
// $subject=mydmsDecodeString($subject);
|
|
||||||
// $message=mydmsDecodeString($message);
|
|
||||||
|
|
||||||
$notifier->toList($user, $folder->_notifyList["users"], $subject, $message);
|
|
||||||
foreach ($folder->_notifyList["groups"] as $grp) {
|
|
||||||
$notifier->toGroup($user, $grp, $subject, $message);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
$subject = "folder_renamed_email_subject";
|
|
||||||
$message = "folder_renamed_email_body";
|
|
||||||
$params = array();
|
|
||||||
$params['name'] = $folder->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.ViewFolder.php?folderid=".$folder->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);
|
|
||||||
}
|
|
||||||
// if user is not owner send notification to owner
|
|
||||||
if ($user->getID() != $folder->getOwner()->getID())
|
|
||||||
$notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(($oldcomment = $folder->getComment()) != $comment) {
|
|
||||||
if($folder->setComment($comment)) {
|
|
||||||
// Send notification to subscribers.
|
|
||||||
if($notifier) {
|
|
||||||
$notifyList = $folder->getNotifyList();
|
|
||||||
/*
|
|
||||||
$subject = "###SITENAME###: ".$folder->getName()." - ".getMLText("comment_changed_email");
|
|
||||||
$message = getMLText("folder_comment_changed_email")."\r\n";
|
|
||||||
$message .=
|
|
||||||
getMLText("name").": ".$folder->getName()."\r\n".
|
|
||||||
getMLText("folder").": ".$folder->getFolderPathPlain()."\r\n".
|
|
||||||
getMLText("comment").": ".$comment."\r\n".
|
|
||||||
"URL: ###URL_PREFIX###out/out.ViewFolder.php?folderid=".$folder->getID()."\r\n";
|
|
||||||
|
|
||||||
// $subject=mydmsDecodeString($subject);
|
|
||||||
// $message=mydmsDecodeString($message);
|
|
||||||
|
|
||||||
$notifier->toList($user, $folder->_notifyList["users"], $subject, $message);
|
|
||||||
foreach ($folder->_notifyList["groups"] as $grp) {
|
|
||||||
$notifier->toGroup($user, $grp, $subject, $message);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
$subject = "folder_comment_changed_email_subject";
|
|
||||||
$message = "folder_comment_changed_email_body";
|
|
||||||
$params = array();
|
|
||||||
$params['name'] = $folder->getName();
|
|
||||||
$params['folder_path'] = $folder->getFolderPathPlain();
|
|
||||||
$params['old_comment'] = $oldcomment;
|
|
||||||
$params['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.ViewFolder.php?folderid=".$folder->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);
|
|
||||||
}
|
|
||||||
// if user is not owner send notification to owner
|
|
||||||
if ($user->getID() != $folder->getOwner()->getID())
|
|
||||||
$notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params);
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$oldattributes = $folder->getAttributes();
|
$oldattributes = $folder->getAttributes();
|
||||||
if($attributes) {
|
|
||||||
foreach($attributes as $attrdefid=>$attribute) {
|
$controller->setParam('folder', $folder);
|
||||||
$attrdef = $dms->getAttributeDefinition($attrdefid);
|
$controller->setParam('index', $index);
|
||||||
if($attribute) {
|
$controller->setParam('name', $name);
|
||||||
if($attrdef->getRegex()) {
|
$controller->setParam('comment', $comment);
|
||||||
if(!preg_match($attrdef->getRegex(), $attribute)) {
|
$controller->setParam('sequence', $sequence);
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("attr_no_regex_match"));
|
$controller->setParam('attributes', $attributes);
|
||||||
}
|
if(!$controller->run()) {
|
||||||
}
|
switch($controller->getErrorNo()) {
|
||||||
if(is_array($attribute)) {
|
case 1:
|
||||||
if($attrdef->getMinValues() > count($attribute)) {
|
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("attr_no_regex_match"));
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("attr_min_values", array("attrname"=>$attrdef->getName())));
|
break;
|
||||||
}
|
case 2:
|
||||||
if($attrdef->getMaxValues() && $attrdef->getMaxValues() < count($attribute)) {
|
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("attr_min_values", array("attrname"=>$attrdef->getName())));
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("attr_max_values", array("attrname"=>$attrdef->getName())));
|
break;
|
||||||
}
|
case 3:
|
||||||
}
|
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("attr_max_values", array("attrname"=>$attrdef->getName())));
|
||||||
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
break;
|
||||||
if(!$folder->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
default:
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
||||||
}
|
break;
|
||||||
} elseif(isset($oldattributes[$attrdefid])) {
|
|
||||||
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach($oldattributes as $attrdefid=>$oldattribute) {
|
|
||||||
if(!isset($attributes[$attrdefid])) {
|
|
||||||
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strcasecmp($sequence, "keep")) {
|
if($oldname != $name) {
|
||||||
if($folder->setSequence($sequence)) {
|
// Send notification to subscribers.
|
||||||
} else {
|
if($notifier) {
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
$notifyList = $folder->getNotifyList();
|
||||||
|
|
||||||
|
$subject = "folder_renamed_email_subject";
|
||||||
|
$message = "folder_renamed_email_body";
|
||||||
|
$params = array();
|
||||||
|
$params['name'] = $folder->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.ViewFolder.php?folderid=".$folder->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);
|
||||||
|
}
|
||||||
|
// if user is not owner send notification to owner
|
||||||
|
if ($user->getID() != $folder->getOwner()->getID())
|
||||||
|
$notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($oldcomment != $comment) {
|
||||||
|
// Send notification to subscribers.
|
||||||
|
if($notifier) {
|
||||||
|
$notifyList = $folder->getNotifyList();
|
||||||
|
|
||||||
|
$subject = "folder_comment_changed_email_subject";
|
||||||
|
$message = "folder_comment_changed_email_body";
|
||||||
|
$params = array();
|
||||||
|
$params['name'] = $folder->getName();
|
||||||
|
$params['folder_path'] = $folder->getFolderPathPlain();
|
||||||
|
$params['old_comment'] = $oldcomment;
|
||||||
|
$params['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.ViewFolder.php?folderid=".$folder->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);
|
||||||
|
}
|
||||||
|
// if user is not owner send notification to owner
|
||||||
|
if ($user->getID() != $folder->getOwner()->getID())
|
||||||
|
$notifier->toIndividual($user, $folder->getOwner(), $subject, $message, $params);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user