2011-07-05 12:05:25 +00:00
|
|
|
|
<?php
|
2013-02-14 10:27:51 +00:00
|
|
|
|
include("../inc/inc.ClassSettings.php");
|
2011-07-05 12:05:25 +00:00
|
|
|
|
|
|
|
|
|
function usage() { /* {{{ */
|
|
|
|
|
echo "Usage:\n";
|
2013-02-14 10:27:51 +00:00
|
|
|
|
echo " seeddms-createfolder [--config <file>] [-c <comment>] [-n <name>] [-s <sequence>] [-h] [-v] -F <parent id>\n";
|
2011-07-05 12:05:25 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Description:\n";
|
2013-02-14 11:10:53 +00:00
|
|
|
|
echo " This program creates a new folder in SeedDMS.\n";
|
2011-07-05 12:05:25 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Options:\n";
|
2011-07-21 12:52:28 +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:05:25 +00:00
|
|
|
|
echo " -F <parent id>: id of parent folder\n";
|
|
|
|
|
echo " -c <comment>: set comment for file\n";
|
|
|
|
|
echo " -n <name>: set name of the folder\n";
|
|
|
|
|
echo " -s <sequence>: set sequence of folder\n";
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
2011-07-21 12:52:28 +00:00
|
|
|
|
$version = "0.0.1";
|
2011-07-05 12:05:25 +00:00
|
|
|
|
$shortoptions = "F:c:s:n:hv";
|
2011-07-21 12:52:28 +00:00
|
|
|
|
$longoptions = array('help', 'version', 'config:');
|
|
|
|
|
if(false === ($options = getopt($shortoptions, $longoptions))) {
|
2011-07-05 12:05:25 +00:00
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print help and exit */
|
2011-07-21 12:52:28 +00:00
|
|
|
|
if(isset($options['h']) || isset($options['help'])) {
|
2011-07-05 12:05:25 +00:00
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print version and exit */
|
2011-07-21 12:52:28 +00:00
|
|
|
|
if(isset($options['v']) || isset($options['verѕion'])) {
|
2011-07-05 12:05:25 +00:00
|
|
|
|
echo $version."\n";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 12:52:28 +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
|
|
|
|
|
2011-07-05 12:05:25 +00:00
|
|
|
|
if(isset($options['F'])) {
|
|
|
|
|
$folderid = (int) $options['F'];
|
|
|
|
|
} else {
|
|
|
|
|
echo "Missing parent folder ID\n";
|
|
|
|
|
usage();
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$comment = '';
|
|
|
|
|
if(isset($options['c'])) {
|
|
|
|
|
$comment = $options['c'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sequence = 0;
|
|
|
|
|
if(isset($options['s'])) {
|
|
|
|
|
$sequence = $options['s'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = '';
|
|
|
|
|
if(isset($options['n'])) {
|
|
|
|
|
$name = $options['n'];
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
|
2011-07-05 12:05:25 +00:00
|
|
|
|
$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
|
2013-06-06 12:41:12 +00:00
|
|
|
|
//$db->_conn->debug = 1;
|
2011-07-05 12:05:25 +00:00
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
|
2013-06-06 12:41:12 +00:00
|
|
|
|
if(!$dms->checkVersion()) {
|
|
|
|
|
echo "Database update needed.";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-05 12:05:25 +00:00
|
|
|
|
$dms->setRootFolderID($settings->_rootFolderID);
|
2013-06-06 12:41:12 +00:00
|
|
|
|
$dms->setMaxDirID($settings->_maxDirID);
|
2011-07-05 12:05:25 +00:00
|
|
|
|
$dms->setEnableConverting($settings->_enableConverting);
|
|
|
|
|
$dms->setViewOnlineFileTypes($settings->_viewOnlineFileTypes);
|
|
|
|
|
|
|
|
|
|
/* Create a global user object */
|
|
|
|
|
$user = $dms->getUser(1);
|
|
|
|
|
|
|
|
|
|
$folder = $dms->getFolder($folderid);
|
|
|
|
|
|
|
|
|
|
if (!is_object($folder)) {
|
|
|
|
|
echo "Could not find specified folder\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($folder->getAccessMode($user) < M_READWRITE) {
|
|
|
|
|
echo "Not sufficient access rights\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($sequence)) {
|
|
|
|
|
echo "Sequence must be numeric\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res = $folder->addSubFolder($name, $comment, $user, $sequence);
|
|
|
|
|
|
|
|
|
|
if (is_bool($res) && !$res) {
|
|
|
|
|
echo "Could not add folder\n";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|