2015-05-29 18:43:37 +00:00
|
|
|
<?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 {
|
|
|
|
|
2017-04-27 15:20:33 +00:00
|
|
|
public function run() { /* {{{ */
|
2017-10-12 13:40:09 +00:00
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$user = $this->params['user'];
|
|
|
|
$settings = $this->params['settings'];
|
2020-09-09 17:49:15 +00:00
|
|
|
$fulltextservice = $this->params['fulltextservice'];
|
2017-10-12 13:40:09 +00:00
|
|
|
$folder = $this->params['folder'];
|
2017-04-11 04:42:27 +00:00
|
|
|
|
2015-05-29 18:43:37 +00:00
|
|
|
/* Call preAddDocument early, because it might need to modify some
|
|
|
|
* of the parameters.
|
|
|
|
*/
|
2017-10-12 13:40:09 +00:00
|
|
|
if(false === $this->callHook('preAddDocument')) {
|
2017-06-09 10:28:17 +00:00
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_preAddDocument_failed';
|
2015-05-29 18:43:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-06-09 10:28:17 +00:00
|
|
|
$name = $this->getParam('name');
|
|
|
|
$comment = $this->getParam('comment');
|
2015-05-29 18:43:37 +00:00
|
|
|
$documentsource = $this->params['documentsource'];
|
|
|
|
$expires = $this->getParam('expires');
|
|
|
|
$keywords = $this->getParam('keywords');
|
|
|
|
$cats = $this->getParam('categories');
|
2017-01-25 11:24:47 +00:00
|
|
|
$owner = $this->getParam('owner');
|
2015-05-29 18:43:37 +00:00
|
|
|
$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');
|
2018-01-16 17:15:05 +00:00
|
|
|
$recipients = $this->getParam('recipients');
|
2015-05-29 18:43:37 +00:00
|
|
|
$reqversion = $this->getParam('reqversion');
|
|
|
|
$version_comment = $this->getParam('versioncomment');
|
|
|
|
$attributes = $this->getParam('attributes');
|
2024-03-25 13:18:36 +00:00
|
|
|
foreach($attributes as $attrdefid=>&$attribute) {
|
2019-12-13 14:00:04 +00:00
|
|
|
if($attrdef = $dms->getAttributeDefinition($attrdefid)) {
|
2019-12-13 16:39:05 +00:00
|
|
|
if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) {
|
2019-12-13 14:00:04 +00:00
|
|
|
if($attribute) {
|
2020-12-17 12:41:00 +00:00
|
|
|
switch($attrdef->getType()) {
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_date:
|
2024-03-25 13:18:36 +00:00
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): string => date('Y-m-d', makeTsFromDate($value)), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = date('Y-m-d', makeTsFromDate($attribute));
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_folder:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getFolder((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getFolder((int) $attribute);
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_document:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getDocument((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getDocument((int) $attribute);
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_user:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getUser((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getUser((int) $attribute);
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_group:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getGroup((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getGroup((int) $attribute);
|
2020-12-17 12:41:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-07-27 07:24:59 +00:00
|
|
|
if(!$attrdef->validate($attribute, null, true)) {
|
2019-12-13 14:00:04 +00:00
|
|
|
$this->errormsg = getAttributeValidationError($attrdef->getValidationError(), $attrdef->getName(), $attribute);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} elseif($attrdef->getMinValues() > 0) {
|
|
|
|
$this->errormsg = array("attr_min_values", array("attrname"=>$attrdef->getName()));
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-13 16:39:05 +00:00
|
|
|
} else {
|
|
|
|
if($ret === false)
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-13 14:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-24 19:15:33 +00:00
|
|
|
if($attributes_version = $this->getParam('attributesversion')) {
|
2024-03-25 13:18:36 +00:00
|
|
|
foreach($attributes_version as $attrdefid=>&$attribute) {
|
2020-06-24 19:15:33 +00:00
|
|
|
if($attrdef = $dms->getAttributeDefinition($attrdefid)) {
|
|
|
|
if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) {
|
|
|
|
if($attribute) {
|
2020-12-17 12:41:00 +00:00
|
|
|
switch($attrdef->getType()) {
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_date:
|
2024-03-25 13:18:36 +00:00
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): string => date('Y-m-d', makeTsFromDate($value)), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = date('Y-m-d', makeTsFromDate($attribute));
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_folder:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getFolder((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getFolder((int) $attribute);
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_document:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getDocument((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getDocument((int) $attribute);
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_user:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getUser((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getUser((int) $attribute);
|
|
|
|
break;
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_group:
|
|
|
|
if(is_array($attribute))
|
|
|
|
$attribute = array_map(fn($value): object => $dms->getGroup((int) $value), $attribute);
|
|
|
|
else
|
|
|
|
$attribute = $dms->getGroup((int) $attribute);
|
2020-12-17 12:41:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-07-27 07:32:59 +00:00
|
|
|
if(!$attrdef->validate($attribute, null, true)) {
|
2020-06-24 19:15:33 +00:00
|
|
|
$this->errormsg = getAttributeValidationError($attrdef->getValidationError(), $attrdef->getName(), $attribute);
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-20 06:23:52 +00:00
|
|
|
} elseif($attrdef->getMinValues() > 0) {
|
|
|
|
$this->errormsg = array("attr_min_values", array("attrname"=>$attrdef->getName()));
|
|
|
|
return false;
|
2020-06-24 19:15:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if($ret === false)
|
|
|
|
return false;
|
2019-12-13 14:00:04 +00:00
|
|
|
}
|
2019-12-13 16:39:05 +00:00
|
|
|
}
|
2019-12-13 14:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-29 18:43:37 +00:00
|
|
|
$workflow = $this->getParam('workflow');
|
|
|
|
$notificationgroups = $this->getParam('notificationgroups');
|
|
|
|
$notificationusers = $this->getParam('notificationusers');
|
2015-06-02 08:03:09 +00:00
|
|
|
$initialdocumentstatus = $this->getParam('initialdocumentstatus');
|
2016-08-03 07:30:53 +00:00
|
|
|
$maxsizeforfulltext = $this->getParam('maxsizeforfulltext');
|
2017-01-25 14:09:51 +00:00
|
|
|
$defaultaccessdocs = $this->getParam('defaultaccessdocs');
|
2015-05-29 18:43:37 +00:00
|
|
|
|
2019-01-17 17:27:38 +00:00
|
|
|
$document = $this->callHook('addDocument');
|
|
|
|
if($document === null) {
|
2016-08-03 07:30:53 +00:00
|
|
|
$filesize = SeedDMS_Core_File::fileSize($userfiletmp);
|
2017-01-25 11:24:47 +00:00
|
|
|
$res = $folder->addDocument($name, $comment, $expires, $owner, $keywords,
|
2017-03-03 08:43:45 +00:00
|
|
|
$cats, $userfiletmp, utf8_basename($userfilename),
|
2015-05-29 18:43:37 +00:00
|
|
|
$filetype, $userfiletype, $sequence,
|
|
|
|
$reviewers, $approvers, $reqversion,
|
2015-06-02 08:03:09 +00:00
|
|
|
$version_comment, $attributes, $attributes_version, $workflow, $initialdocumentstatus);
|
2015-05-29 18:43:37 +00:00
|
|
|
|
|
|
|
if (is_bool($res) && !$res) {
|
|
|
|
$this->errormsg = "error_occured";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$document = $res[0];
|
|
|
|
|
2017-01-20 14:02:27 +00:00
|
|
|
/* Set access as specified in settings. */
|
|
|
|
if($defaultaccessdocs) {
|
|
|
|
if($defaultaccessdocs > 0 && $defaultaccessdocs < 4) {
|
|
|
|
$document->setInheritAccess(0, true);
|
|
|
|
$document->setDefaultAccess($defaultaccessdocs, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 17:15:05 +00:00
|
|
|
$lc = $document->getLatestContent();
|
2020-06-28 17:23:38 +00:00
|
|
|
if($recipients) {
|
|
|
|
if($recipients['i']) {
|
|
|
|
foreach($recipients['i'] as $uid) {
|
|
|
|
if($u = $dms->getUser($uid)) {
|
|
|
|
$res = $lc->addIndRecipient($u, $user);
|
|
|
|
}
|
2018-01-16 17:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-28 17:23:38 +00:00
|
|
|
if($recipients['g']) {
|
|
|
|
foreach($recipients['g'] as $gid) {
|
|
|
|
if($g = $dms->getGroup($gid)) {
|
|
|
|
$res = $lc->addGrpRecipient($g, $user);
|
|
|
|
}
|
2018-01-16 17:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 18:43:37 +00:00
|
|
|
/* Add a default notification for the owner of the document */
|
|
|
|
if($settings->_enableOwnerNotification) {
|
2020-08-25 13:53:29 +00:00
|
|
|
$res = $document->addNotify($owner->getID(), true);
|
2015-05-29 18:43:37 +00:00
|
|
|
}
|
|
|
|
/* Check if additional notification shall be added */
|
|
|
|
foreach($notificationusers as $notuser) {
|
2020-08-25 13:53:29 +00:00
|
|
|
if($document->getAccessMode($notuser) >= M_READ)
|
2015-05-29 18:43:37 +00:00
|
|
|
$res = $document->addNotify($notuser->getID(), true);
|
|
|
|
}
|
|
|
|
foreach($notificationgroups as $notgroup) {
|
2017-01-10 05:58:07 +00:00
|
|
|
if($document->getGroupAccessMode($notgroup) >= M_READ)
|
|
|
|
$res = $document->addNotify($notgroup->getID(), false);
|
2015-05-29 18:43:37 +00:00
|
|
|
}
|
2020-12-14 06:52:39 +00:00
|
|
|
} elseif($document === false) {
|
2019-01-17 17:27:38 +00:00
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_addDocument_failed';
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-29 18:43:37 +00:00
|
|
|
|
2020-09-09 17:49:15 +00:00
|
|
|
if($fulltextservice && ($index = $fulltextservice->Indexer()) && $document) {
|
|
|
|
$idoc = $fulltextservice->IndexedDocument($document);
|
2019-01-17 17:27:38 +00:00
|
|
|
if(false !== $this->callHook('preIndexDocument', $document, $idoc)) {
|
|
|
|
$index->addDocument($idoc);
|
|
|
|
$index->commit();
|
2015-05-29 18:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-15 09:03:28 +00:00
|
|
|
if(false === $this->callHook('postAddDocument', $document)) {
|
2020-12-14 06:52:39 +00:00
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_postAddDocument_failed';
|
|
|
|
return false;
|
2019-01-17 17:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $document;
|
2017-04-27 15:20:33 +00:00
|
|
|
} /* }}} */
|
2015-05-29 18:43:37 +00:00
|
|
|
}
|
|
|
|
|