mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-16 06:31:21 +00:00
split AddDocument into stub and controller
This commit is contained in:
parent
6678928301
commit
5b931afefb
99
controllers/class.AddDocument.php
Normal file
99
controllers/class.AddDocument.php
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of AddDocument 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 downloading a document
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common {
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
/* Call preAddDocument early, because it might need to modify some
|
||||||
|
* of the parameters.
|
||||||
|
*/
|
||||||
|
if(false === $this->callHook('preAddDocument')) {
|
||||||
|
$this->errormsg = 'hook_preAddDocument_failed';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$user = $this->params['user'];
|
||||||
|
$settings = $this->params['settings'];
|
||||||
|
$documentsource = $this->params['documentsource'];
|
||||||
|
$index = $this->params['index'];
|
||||||
|
$folder = $this->params['folder'];
|
||||||
|
$name = $this->getParam('name');
|
||||||
|
$comment = $this->getParam('comment');
|
||||||
|
$expires = $this->getParam('expires');
|
||||||
|
$keywords = $this->getParam('keywords');
|
||||||
|
$cats = $this->getParam('categories');
|
||||||
|
$userfiletmp = $this->getParam('userfiletmp');
|
||||||
|
$userfilename = $this->getParam('userfilename');
|
||||||
|
$filetype = $this->getParam('filetype');
|
||||||
|
$userfiletype = $this->getParam('userfiletype');
|
||||||
|
$sequence = $this->getParam('sequence');
|
||||||
|
$reviewers = $this->getParam('reviewers');
|
||||||
|
$approvers = $this->getParam('approvers');
|
||||||
|
$reqversion = $this->getParam('reqversion');
|
||||||
|
$version_comment = $this->getParam('versioncomment');
|
||||||
|
$attributes = $this->getParam('attributes');
|
||||||
|
$attributes_version = $this->getParam('attributesversion');
|
||||||
|
$workflow = $this->getParam('workflow');
|
||||||
|
$notificationgroups = $this->getParam('notificationgroups');
|
||||||
|
$notificationusers = $this->getParam('notificationusers');
|
||||||
|
|
||||||
|
$result = $this->callHook('addDocument');
|
||||||
|
if($result === null) {
|
||||||
|
$res = $folder->addDocument($name, $comment, $expires, $user, $keywords,
|
||||||
|
$cats, $userfiletmp, basename($userfilename),
|
||||||
|
$filetype, $userfiletype, $sequence,
|
||||||
|
$reviewers, $approvers, $reqversion,
|
||||||
|
$version_comment, $attributes, $attributes_version, $workflow);
|
||||||
|
|
||||||
|
if (is_bool($res) && !$res) {
|
||||||
|
$this->errormsg = "error_occured";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$document = $res[0];
|
||||||
|
|
||||||
|
if($index) {
|
||||||
|
$index->addDocument(new SeedDMS_Lucene_IndexedDocument($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add a default notification for the owner of the document */
|
||||||
|
if($settings->_enableOwnerNotification) {
|
||||||
|
$res = $document->addNotify($user->getID(), true);
|
||||||
|
}
|
||||||
|
/* Check if additional notification shall be added */
|
||||||
|
foreach($notificationusers as $notuser) {
|
||||||
|
$res = $document->addNotify($notuser->getID(), true);
|
||||||
|
}
|
||||||
|
foreach($notificationgroups as $notgroup) {
|
||||||
|
$res = $document->addNotify($notgroup->getID(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->callHook('postAddDocument', $document)) {
|
||||||
|
}
|
||||||
|
$result = $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ include("../inc/inc.ClassEmail.php");
|
||||||
include("../inc/inc.DBInit.php");
|
include("../inc/inc.DBInit.php");
|
||||||
include("../inc/inc.Authentication.php");
|
include("../inc/inc.Authentication.php");
|
||||||
include("../inc/inc.ClassUI.php");
|
include("../inc/inc.ClassUI.php");
|
||||||
|
include("../inc/inc.ClassController.php");
|
||||||
|
|
||||||
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
|
$controller = Controller::factory($tmp[1]);
|
||||||
|
|
||||||
/* Check if the form data comes for a trusted request */
|
/* Check if the form data comes for a trusted request */
|
||||||
if(!checkFormKey('adddocument')) {
|
if(!checkFormKey('adddocument')) {
|
||||||
|
@ -65,6 +69,13 @@ if($version_comment == "" && isset($_POST["use_comment"]))
|
||||||
|
|
||||||
$keywords = $_POST["keywords"];
|
$keywords = $_POST["keywords"];
|
||||||
$categories = isset($_POST["categories"]) ? $_POST["categories"] : null;
|
$categories = isset($_POST["categories"]) ? $_POST["categories"] : null;
|
||||||
|
$cats = array();
|
||||||
|
if($categories) {
|
||||||
|
foreach($categories as $catid) {
|
||||||
|
$cats[] = $dms->getDocumentCategory($catid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($_POST["attributes"]))
|
if(isset($_POST["attributes"]))
|
||||||
$attributes = $_POST["attributes"];
|
$attributes = $_POST["attributes"];
|
||||||
else
|
else
|
||||||
|
@ -217,10 +228,13 @@ if($settings->_workflowMode == 'traditional' || $settings->_workflowMode == 'tra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$docsource = 'upload';
|
||||||
|
|
||||||
if($settings->_dropFolderDir) {
|
if($settings->_dropFolderDir) {
|
||||||
if(isset($_POST["dropfolderfileform1"]) && $_POST["dropfolderfileform1"]) {
|
if(isset($_POST["dropfolderfileform1"]) && $_POST["dropfolderfileform1"]) {
|
||||||
$fullfile = $settings->_dropFolderDir.'/'.$user->getLogin().'/'.$_POST["dropfolderfileform1"];
|
$fullfile = $settings->_dropFolderDir.'/'.$user->getLogin().'/'.$_POST["dropfolderfileform1"];
|
||||||
if(file_exists($fullfile)) {
|
if(file_exists($fullfile)) {
|
||||||
|
$docsource = 'dropfolder';
|
||||||
/* Check if a local file is uploaded as well */
|
/* Check if a local file is uploaded as well */
|
||||||
if(isset($_FILES["userfile"]['error'][0])) {
|
if(isset($_FILES["userfile"]['error'][0])) {
|
||||||
if($_FILES["userfile"]['error'][0] != 0)
|
if($_FILES["userfile"]['error'][0] != 0)
|
||||||
|
@ -237,6 +251,64 @@ if($settings->_dropFolderDir) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($settings->_libraryFolder) {
|
||||||
|
if(isset($_POST["librarydoc"]) && $_POST["librarydoc"]) {
|
||||||
|
if($clonedoc = $dms->getDocument($_POST["librarydoc"])) {
|
||||||
|
if($content = $clonedoc->getLatestContent()) {
|
||||||
|
$docsource = 'library';
|
||||||
|
$fullfile = tempnam('', '');
|
||||||
|
if(SeedDMS_Core_File::copyFile($dms->contentDir . $content->getPath(), $fullfile)) {
|
||||||
|
/* Check if a local file is uploaded as well */
|
||||||
|
if(isset($_FILES["userfile"]['error'][0])) {
|
||||||
|
if($_FILES["userfile"]['error'][0] != 0)
|
||||||
|
$_FILES["userfile"] = array();
|
||||||
|
}
|
||||||
|
$_FILES["userfile"]['tmp_name'][] = $fullfile;
|
||||||
|
$_FILES["userfile"]['type'][] = $content->getMimeType();
|
||||||
|
$_FILES["userfile"]['name'][] = $content->getOriginalFileName();
|
||||||
|
$_FILES["userfile"]['size'][] = $content->getFileSize();
|
||||||
|
$_FILES["userfile"]['error'][] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$index = null;
|
||||||
|
if($settings->_enableFullSearch) {
|
||||||
|
if(!empty($settings->_luceneClassDir))
|
||||||
|
require_once($settings->_luceneClassDir.'/Lucene.php');
|
||||||
|
else
|
||||||
|
require_once('SeedDMS/Lucene.php');
|
||||||
|
|
||||||
|
$index = SeedDMS_Lucene_Indexer::open($settings->_luceneDir);
|
||||||
|
if($index) {
|
||||||
|
SeedDMS_Lucene_Indexer::init($settings->_stopWordsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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) {
|
||||||
|
if($document->getAccessMode($user) >= M_READ)
|
||||||
|
$notusers[] = $notuser;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$notgroups = array();
|
||||||
|
if(!empty($_POST['notification_groups'])) {
|
||||||
|
foreach($_POST['notification_groups'] as $notgroupid) {
|
||||||
|
$notgroup = $dms->getGroup($notgroupid);
|
||||||
|
if($notgroup) {
|
||||||
|
if($document->getGroupAccessMode($notgroup) >= M_READ)
|
||||||
|
$notgroups[] = $notgroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Check files for Errors first */
|
/* Check files for Errors first */
|
||||||
for ($file_num=0;$file_num<count($_FILES["userfile"]["tmp_name"]);$file_num++){
|
for ($file_num=0;$file_num<count($_FILES["userfile"]["tmp_name"]);$file_num++){
|
||||||
if ($_FILES["userfile"]["size"][$file_num]==0) {
|
if ($_FILES["userfile"]["size"][$file_num]==0) {
|
||||||
|
@ -265,75 +337,32 @@ for ($file_num=0;$file_num<count($_FILES["userfile"]["tmp_name"]);$file_num++){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cats = array();
|
$controller->setParam('documentsource', $docsource);
|
||||||
if($categories) {
|
$controller->setParam('folder', $folder);
|
||||||
foreach($categories as $catid) {
|
$controller->setParam('index', $index);
|
||||||
$cats[] = $dms->getDocumentCategory($catid);
|
$controller->setParam('name', $name);
|
||||||
}
|
$controller->setParam('comment', $comment);
|
||||||
}
|
$controller->setParam('expires', $expires);
|
||||||
|
$controller->setParam('keywords', $keywords);
|
||||||
|
$controller->setParam('categories', $cats);
|
||||||
|
$controller->setParam('userfiletmp', $userfiletmp);
|
||||||
|
$controller->setParam('userfilename', $userfilename);
|
||||||
|
$controller->setParam('filetype', $fileType);
|
||||||
|
$controller->setParam('userfiletype', $userfiletype);
|
||||||
|
$controller->setParam('sequence', $sequence);
|
||||||
|
$controller->setParam('reviewers', $reviewers);
|
||||||
|
$controller->setParam('approvers', $approvers);
|
||||||
|
$controller->setParam('reqversion', $reqversion);
|
||||||
|
$controller->setParam('versioncomment', $version_comment);
|
||||||
|
$controller->setParam('attributes', $attributes);
|
||||||
|
$controller->setParam('attributesversion', $attributes_version);
|
||||||
|
$controller->setParam('workflow', $workflow);
|
||||||
|
$controller->setParam('notificationgroups', $notgroups);
|
||||||
|
$controller->setParam('notificationusers', $notusers);
|
||||||
|
|
||||||
if(isset($GLOBALS['SEEDDMS_HOOKS']['addDocument'])) {
|
if(!$document = $controller->run()) {
|
||||||
foreach($GLOBALS['SEEDDMS_HOOKS']['addDocument'] as $hookObj) {
|
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText($controller->getErrorMsg()));
|
||||||
if (method_exists($hookObj, 'pretAddDocument')) {
|
|
||||||
$hookObj->preAddDocument(array('name'=>&$name, 'comment'=>&$comment));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = $folder->addDocument($name, $comment, $expires, $user, $keywords,
|
|
||||||
$cats, $userfiletmp, basename($userfilename),
|
|
||||||
$fileType, $userfiletype, $sequence,
|
|
||||||
$reviewers, $approvers, $reqversion,
|
|
||||||
$version_comment, $attributes, $attributes_version, $workflow);
|
|
||||||
|
|
||||||
if (is_bool($res) && !$res) {
|
|
||||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
|
||||||
} else {
|
} else {
|
||||||
$document = $res[0];
|
|
||||||
if(isset($GLOBALS['SEEDDMS_HOOKS']['addDocument'])) {
|
|
||||||
foreach($GLOBALS['SEEDDMS_HOOKS']['addDocument'] as $hookObj) {
|
|
||||||
if (method_exists($hookObj, 'postAddDocument')) {
|
|
||||||
$hookObj->postAddDocument($document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($settings->_enableFullSearch) {
|
|
||||||
if(!empty($settings->_luceneClassDir))
|
|
||||||
require_once($settings->_luceneClassDir.'/Lucene.php');
|
|
||||||
else
|
|
||||||
require_once('SeedDMS/Lucene.php');
|
|
||||||
|
|
||||||
$index = SeedDMS_Lucene_Indexer::open($settings->_luceneDir);
|
|
||||||
if($index) {
|
|
||||||
SeedDMS_Lucene_Indexer::init($settings->_stopWordsFile);
|
|
||||||
$index->addDocument(new SeedDMS_Lucene_IndexedDocument($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add a default notification for the owner of the document */
|
|
||||||
if($settings->_enableOwnerNotification) {
|
|
||||||
$res = $document->addNotify($user->getID(), true);
|
|
||||||
}
|
|
||||||
/* Check if additional notification shall be added */
|
|
||||||
if(!empty($_POST['notification_users'])) {
|
|
||||||
foreach($_POST['notification_users'] as $notuserid) {
|
|
||||||
$notuser = $dms->getUser($notuserid);
|
|
||||||
if($notuser) {
|
|
||||||
if($document->getAccessMode($user) >= M_READ)
|
|
||||||
$res = $document->addNotify($notuserid, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!empty($_POST['notification_groups'])) {
|
|
||||||
foreach($_POST['notification_groups'] as $notgroupid) {
|
|
||||||
$notgroup = $dms->getGroup($notgroupid);
|
|
||||||
if($notgroup) {
|
|
||||||
if($document->getGroupAccessMode($notgroup) >= M_READ)
|
|
||||||
$res = $document->addNotify($notgroupid, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send notification to subscribers of folder.
|
// Send notification to subscribers of folder.
|
||||||
if($notifier) {
|
if($notifier) {
|
||||||
$notifyList = $folder->getNotifyList();
|
$notifyList = $folder->getNotifyList();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user