2010-10-30 18:38:07 +00:00
|
|
|
|
<?php
|
2013-02-14 10:27:51 +00:00
|
|
|
|
include("../inc/inc.ClassSettings.php");
|
2010-10-30 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
function usage() { /* {{{ */
|
|
|
|
|
echo "Usage:\n";
|
2016-01-31 10:22:40 +00:00
|
|
|
|
echo " seeddms-adddoc [--config <file>] [-c <comment>] [-k <keywords>] [-s <number>] [-n <name>] [-V <version>] [-s <sequence>] [-t <mimetype>] [-a <attribute=value>] [-h] [-v] -F <folder id> -f <filename>\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Description:\n";
|
2013-02-14 11:10:53 +00:00
|
|
|
|
echo " This program uploads a file into a folder of SeedDMS.\n";
|
2010-10-30 18:38:07 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Options:\n";
|
2011-07-21 07:12:33 +00:00
|
|
|
|
echo " -h, --help: print usage information and exit.\n";
|
|
|
|
|
echo " -v, --version: print version and exit.\n";
|
|
|
|
|
echo " --config: set alternative config file.\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
echo " -F <folder id>: id of folder the file is uploaded to\n";
|
2011-07-20 16:47:58 +00:00
|
|
|
|
echo " -c <comment>: set comment for document\n";
|
|
|
|
|
echo " -C <comment>: set comment for version\n";
|
2010-10-30 18:38:07 +00:00
|
|
|
|
echo " -k <keywords>: set keywords for file\n";
|
2011-07-20 16:47:58 +00:00
|
|
|
|
echo " -K <categories>: set categories for file\n";
|
2010-10-30 18:38:07 +00:00
|
|
|
|
echo " -s <number>: set sequence for file (used for ordering files within a folder\n";
|
|
|
|
|
echo " -n <name>: set name of file\n";
|
|
|
|
|
echo " -V <version>: set version of file (defaults to 1).\n";
|
2015-05-15 05:16:46 +00:00
|
|
|
|
echo " -u <user>: login name of user\n";
|
2010-10-30 18:38:07 +00:00
|
|
|
|
echo " -f <filename>: upload this file\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
echo " -s <sequence>: set sequence of file\n";
|
2010-10-30 18:38:07 +00:00
|
|
|
|
echo " -t <mimetype> set mimetype of file manually. Do not do that unless you know\n";
|
|
|
|
|
echo " what you do. If not set, the mimetype will be determined automatically.\n";
|
2016-01-31 10:22:40 +00:00
|
|
|
|
echo " -a <attribute=value>: Set a document attribute; can occur multiple times.\n";
|
|
|
|
|
echo " -A <attribute=value>: Set a version attribute; can occur multiple times.\n";
|
2010-10-30 18:38:07 +00:00
|
|
|
|
} /* }}} */
|
|
|
|
|
|
2011-07-21 06:56:35 +00:00
|
|
|
|
$version = "0.0.1";
|
2016-01-31 10:22:40 +00:00
|
|
|
|
$shortoptions = "F:c:C:k:K:s:V:u:f:n:t:a:A:hv";
|
2011-07-21 06:56:35 +00:00
|
|
|
|
$longoptions = array('help', 'version', 'config:');
|
|
|
|
|
if(false === ($options = getopt($shortoptions, $longoptions))) {
|
2010-10-30 18:38:07 +00:00
|
|
|
|
usage();
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(0);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print help and exit */
|
2011-07-21 06:56:35 +00:00
|
|
|
|
if(isset($options['h']) || isset($options['help'])) {
|
2010-10-30 18:38:07 +00:00
|
|
|
|
usage();
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(0);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print version and exit */
|
2011-07-21 06:56:35 +00:00
|
|
|
|
if(isset($options['v']) || isset($options['verѕion'])) {
|
2010-10-30 18:38:07 +00:00
|
|
|
|
echo $version."\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(0);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 06:56:35 +00:00
|
|
|
|
/* Set alternative config file */
|
|
|
|
|
if(isset($options['config'])) {
|
|
|
|
|
$settings = new Settings($options['config']);
|
|
|
|
|
} else {
|
|
|
|
|
$settings = new Settings();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 10:27:51 +00:00
|
|
|
|
if(isset($settings->_extraPath))
|
|
|
|
|
ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path'));
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
require_once("SeedDMS/Core.php");
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2010-10-30 18:38:07 +00:00
|
|
|
|
if(isset($options['F'])) {
|
|
|
|
|
$folderid = (int) $options['F'];
|
|
|
|
|
} else {
|
|
|
|
|
echo "Missing folder ID\n";
|
|
|
|
|
usage();
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 13:38:45 +00:00
|
|
|
|
$comment = '';
|
2010-10-30 18:38:07 +00:00
|
|
|
|
if(isset($options['c'])) {
|
|
|
|
|
$comment = $options['c'];
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-20 16:47:58 +00:00
|
|
|
|
$version_comment = '';
|
|
|
|
|
if(isset($options['C'])) {
|
|
|
|
|
$version_comment = $options['C'];
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 13:38:45 +00:00
|
|
|
|
$keywords = '';
|
2010-10-30 18:38:07 +00:00
|
|
|
|
if(isset($options['k'])) {
|
|
|
|
|
$keywords = $options['k'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sequence = 0;
|
|
|
|
|
if(isset($options['s'])) {
|
|
|
|
|
$sequence = $options['s'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = '';
|
|
|
|
|
if(isset($options['n'])) {
|
|
|
|
|
$name = $options['n'];
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 05:16:46 +00:00
|
|
|
|
$username = '';
|
|
|
|
|
if(isset($options['u'])) {
|
|
|
|
|
$username = $options['u'];
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-30 18:38:07 +00:00
|
|
|
|
$filename = '';
|
|
|
|
|
if(isset($options['f'])) {
|
|
|
|
|
$filename = $options['f'];
|
|
|
|
|
} else {
|
|
|
|
|
usage();
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 14:54:36 +00:00
|
|
|
|
$mimetype = '';
|
2010-10-30 18:38:07 +00:00
|
|
|
|
if(isset($options['t'])) {
|
2013-06-25 14:54:36 +00:00
|
|
|
|
$mimetype = $options['t'];
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$reqversion = 0;
|
|
|
|
|
if(isset($options['V'])) {
|
|
|
|
|
$reqversion = $options['V'];
|
|
|
|
|
}
|
|
|
|
|
if($reqversion<1)
|
|
|
|
|
$reqversion=1;
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
|
2010-12-01 13:38:45 +00:00
|
|
|
|
$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
|
2011-07-22 20:47:31 +00:00
|
|
|
|
//$db->_conn->debug = 1;
|
2010-12-01 13:38:45 +00:00
|
|
|
|
|
2010-10-30 18:38:07 +00:00
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
|
2013-06-06 12:34:44 +00:00
|
|
|
|
if(!$dms->checkVersion()) {
|
|
|
|
|
echo "Database update needed.";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 05:17:44 +00:00
|
|
|
|
/* Parse categories */
|
|
|
|
|
$categories = array();
|
|
|
|
|
if(isset($options['K'])) {
|
|
|
|
|
$categorynames = explode(',', $options['K']);
|
|
|
|
|
foreach($categorynames as $categoryname) {
|
|
|
|
|
$cat = $dms->getDocumentCategoryByName($categoryname);
|
|
|
|
|
if($cat) {
|
2018-02-20 05:35:16 +00:00
|
|
|
|
$categories[] = $cat;
|
2018-02-20 05:17:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
echo "Category '".$categoryname."' not found\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-31 10:22:40 +00:00
|
|
|
|
/* Parse document attributes. */
|
|
|
|
|
$document_attributes = array();
|
|
|
|
|
if (isset($options['a'])) {
|
|
|
|
|
$docattr = array();
|
|
|
|
|
if (is_array($options['a'])) {
|
|
|
|
|
$docattr = $options['a'];
|
|
|
|
|
} else {
|
|
|
|
|
$docattr = array($options['a']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($docattr as $thisAttribute) {
|
|
|
|
|
$attrKey = strstr($thisAttribute, '=', true);
|
|
|
|
|
$attrVal = substr(strstr($thisAttribute, '='), 1);
|
|
|
|
|
if (empty($attrKey) || empty($attrVal)) {
|
|
|
|
|
echo "Document attribute $thisAttribute not understood\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
$attrdef = $dms->getAttributeDefinitionByName($attrKey);
|
|
|
|
|
if (!$attrdef) {
|
|
|
|
|
echo "Document attribute $attrKey unknown\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
$document_attributes[$attrdef->getID()] = $attrVal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parse version attributes. */
|
|
|
|
|
$version_attributes = array();
|
|
|
|
|
if (isset($options['A'])) {
|
|
|
|
|
$verattr = array();
|
|
|
|
|
if (is_array($options['A'])) {
|
|
|
|
|
$verattr = $options['A'];
|
|
|
|
|
} else {
|
|
|
|
|
$verattr = array($options['A']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($verattr as $thisAttribute) {
|
|
|
|
|
$attrKey = strstr($thisAttribute, '=', true);
|
|
|
|
|
$attrVal = substr(strstr($thisAttribute, '='), 1);
|
|
|
|
|
if (empty($attrKey) || empty($attrVal)) {
|
|
|
|
|
echo "Version attribute $thisAttribute not understood\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
$attrdef = $dms->getAttributeDefinitionByName($attrKey);
|
|
|
|
|
if (!$attrdef) {
|
|
|
|
|
echo "Version attribute $attrKey unknown\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
$version_attributes[$attrdef->getID()] = $attrVal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-12-01 13:38:45 +00:00
|
|
|
|
$dms->setRootFolderID($settings->_rootFolderID);
|
2013-06-06 12:34:44 +00:00
|
|
|
|
$dms->setMaxDirID($settings->_maxDirID);
|
2010-12-01 13:38:45 +00:00
|
|
|
|
$dms->setEnableConverting($settings->_enableConverting);
|
|
|
|
|
$dms->setViewOnlineFileTypes($settings->_viewOnlineFileTypes);
|
|
|
|
|
|
|
|
|
|
/* Create a global user object */
|
2015-06-26 14:41:36 +00:00
|
|
|
|
if($username) {
|
|
|
|
|
if(!($user = $dms->getUserByLogin($username))) {
|
|
|
|
|
echo "No such user '".$username."'.";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
} else
|
2015-05-15 05:16:46 +00:00
|
|
|
|
$user = $dms->getUser(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
if(is_readable($filename)) {
|
|
|
|
|
if(filesize($filename)) {
|
2015-05-02 06:34:28 +00:00
|
|
|
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
2013-06-25 14:54:36 +00:00
|
|
|
|
if(!$mimetype) {
|
|
|
|
|
$mimetype = $finfo->file($filename);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
2014-06-16 12:30:13 +00:00
|
|
|
|
$filetype = "." . pathinfo($filename, PATHINFO_EXTENSION);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
} else {
|
2010-12-01 13:38:45 +00:00
|
|
|
|
echo "File has zero size\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-12-01 13:38:45 +00:00
|
|
|
|
echo "File is not readable\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 13:38:45 +00:00
|
|
|
|
$folder = $dms->getFolder($folderid);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
if (!is_object($folder)) {
|
2010-12-01 13:38:45 +00:00
|
|
|
|
echo "Could not find specified folder\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($folder->getAccessMode($user) < M_READWRITE) {
|
2010-12-01 13:38:45 +00:00
|
|
|
|
echo "Not sufficient access rights\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($sequence)) {
|
2010-12-01 13:38:45 +00:00
|
|
|
|
echo "Sequence must be numeric\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//$expires = ($_POST["expires"] == "true") ? mktime(0,0,0, sanitizeString($_POST["expmonth"]), sanitizeString($_POST["expday"]), sanitizeString($_POST["expyear"])) : false;
|
|
|
|
|
$expires = false;
|
|
|
|
|
|
|
|
|
|
if(!$name)
|
|
|
|
|
$name = basename($filename);
|
|
|
|
|
$filetmp = $filename;
|
|
|
|
|
|
|
|
|
|
$reviewers = array();
|
|
|
|
|
$approvers = array();
|
|
|
|
|
|
|
|
|
|
$res = $folder->addDocument($name, $comment, $expires, $user, $keywords,
|
2011-07-20 16:47:58 +00:00
|
|
|
|
$categories, $filetmp, basename($filename),
|
2013-06-25 14:54:36 +00:00
|
|
|
|
$filetype, $mimetype, $sequence, $reviewers,
|
2016-01-31 10:22:40 +00:00
|
|
|
|
$approvers, $reqversion, $version_comment,
|
|
|
|
|
$document_attributes, $version_attributes);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
if (is_bool($res) && !$res) {
|
2010-12-01 13:38:45 +00:00
|
|
|
|
echo "Could not add document to folder\n";
|
2011-07-05 12:04:56 +00:00
|
|
|
|
exit(1);
|
2010-10-30 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
?>
|