diff --git a/controllers/class.AddSubFolder.php b/controllers/class.AddSubFolder.php new file mode 100644 index 000000000..0d6582855 --- /dev/null +++ b/controllers/class.AddSubFolder.php @@ -0,0 +1,71 @@ + + * @copyright Copyright (C) 2010-2013 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class which does the busines logic for downloading a document + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2010-2013 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_Controller_AddSubFolder extends SeedDMS_Controller_Common { + + public function run() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $folder = $this->params['folder']; + + /* Call preAddSubFolder early, because it might need to modify some + * of the parameters. + */ + if(false === $this->callHook('preAddSubFolder')) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preAddSubFolder_failed'; + return null; + } + + $name = $this->getParam('name'); + $comment = $this->getParam('comment'); + $sequence = $this->getParam('sequence'); + $attributes = $this->getParam('attributes'); + $notificationgroups = $this->getParam('notificationgroups'); + $notificationusers = $this->getParam('notificationusers'); + + $result = $this->callHook('addSubFolder'); + if($result === null) { + $subFolder = $folder->addSubFolder($name, $comment, $user, $sequence, $attributes); + if (!is_object($subFolder)) { + $this->errormsg = "error_occured"; + return false; + } + /* Check if additional notification shall be added */ + foreach($notificationusers as $notuser) { + if($subFolder->getAccessMode($user) >= M_READ) + $res = $subFolder->addNotify($notuser->getID(), true); + } + foreach($notificationgroups as $notgroup) { + if($subFolder->getGroupAccessMode($notgroup) >= M_READ) + $res = $subFolder->addNotify($notgroup->getID(), false); + } + + if(!$this->callHook('postAddSubFolder', $subFolder)) { + } + $result = $subFolder; + } + + return $result; + } /* }}} */ +} + diff --git a/op/op.AddSubFolder.php b/op/op.AddSubFolder.php index 8d6e74f26..83a83de6f 100644 --- a/op/op.AddSubFolder.php +++ b/op/op.AddSubFolder.php @@ -27,8 +27,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]); + /* Check if the form data comes from a trusted request */ if(!checkFormKey('addsubfolder')) { UI::exitError(getMLText("folder_title", array("foldername" => getMLText("invalid_request_token"))),getMLText("invalid_request_token")); @@ -75,29 +79,40 @@ foreach($attributes as $attrdefid=>$attribute) { } } -$subFolder = $folder->addSubFolder($name, $comment, $user, $sequence, $attributes); +/* Check if additional notification shall be added */ +$notusers = array(); +if(!empty($_POST['notification_users'])) { + foreach($_POST['notification_users'] as $notuserid) { + $notuser = $dms->getUser($notuserid); + if($notuser) { + $notusers[] = $notuser; + } + } +} +$notgroups = array(); +if(!empty($_POST['notification_groups'])) { + foreach($_POST['notification_groups'] as $notgroupid) { + $notgroup = $dms->getGroup($notgroupid); + if($notgroup) { + $notgroups[] = $notgroup; + } + } +} -if (is_object($subFolder)) { +$controller->setParam('folder', $folder); +$controller->setParam('name', $name); +$controller->setParam('comment', $comment); +$controller->setParam('sequence', $sequence); +$controller->setParam('attributes', $attributes); +$controller->setParam('notificationgroups', $notgroups); +$controller->setParam('notificationusers', $notusers); +if(!$subFolder = $controller->run()) { + UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText($controller->getErrorMsg())); +} else { // Send notification to subscribers. if($notifier) { $notifyList = $folder->getNotifyList(); -/* - $subject = "###SITENAME###: ".$folder->getName()." - ".getMLText("new_subfolder_email"); - $message = getMLText("new_subfolder_email")."\r\n"; - $message .= - getMLText("name").": ".$name."\r\n". - getMLText("folder").": ".$subFolder->getFolderPathPlain()."\r\n". - getMLText("comment").": ".$comment."\r\n". - getMLText("user").": ".$user->getFullName()."\r\n". - "URL: ###URL_PREFIX###out/out.ViewFolder.php?folderid=".$subFolder->getID()."\r\n"; - - $notifier->toList($user, $folder->_notifyList["users"], $subject, $message); - foreach ($folder->_notifyList["groups"] as $grp) { - $notifier->toGroup($user, $grp, $subject, $message); - } -*/ - $subject = "new_subfolder_email_subject"; $message = "new_subfolder_email_body"; $params = array(); @@ -114,9 +129,6 @@ if (is_object($subFolder)) { $notifier->toGroup($user, $grp, $subject, $message, $params); } } - -} else { - UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured")); } add_log_line("?name=".$name."&folderid=".$folderid);