diff --git a/utils/adddoc.php b/utils/adddoc.php index c0a2912b5..763da6cee 100644 --- a/utils/adddoc.php +++ b/utils/adddoc.php @@ -63,6 +63,8 @@ if(isset($options['v']) || isset($options['verѕion'])) { /* Set alternative config file */ if(isset($options['config'])) { define('SEEDDMS_CONFIG_FILE', $options['config']); +} elseif(isset($_SERVER['SEEDDMS_CONFIG_FILE'])) { + define('SEEDDMS_CONFIG_FILE', $_SERVER['SEEDDMS_CONFIG_FILE']); } /* Set parent folder or document */ @@ -368,4 +370,3 @@ if($folder) { exit(1); } } -?> diff --git a/utils/createfolder.php b/utils/createfolder.php index d5233e602..7d629ace9 100644 --- a/utils/createfolder.php +++ b/utils/createfolder.php @@ -1,5 +1,11 @@ : login name of user\n"; echo " -F : id of parent folder\n"; echo " -c : set comment for file\n"; echo " -n : set name of the folder\n"; @@ -19,7 +26,7 @@ function usage() { /* {{{ */ } /* }}} */ $version = "0.0.1"; -$shortoptions = "F:c:s:n:hv"; +$shortoptions = "F:u:c:s:n:hv"; $longoptions = array('help', 'version', 'config:'); if(false === ($options = getopt($shortoptions, $longoptions))) { usage(); @@ -40,16 +47,11 @@ if(isset($options['v']) || isset($options['verѕion'])) { /* Set alternative config file */ if(isset($options['config'])) { - $settings = new Settings($options['config']); -} else { - $settings = new Settings(); + define('SEEDDMS_CONFIG_FILE', $options['config']); +} elseif(isset($_SERVER['SEEDDMS_CONFIG_FILE'])) { + define('SEEDDMS_CONFIG_FILE', $_SERVER['SEEDDMS_CONFIG_FILE']); } -if(isset($settings->_extraPath)) - ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path')); - -require_once("SeedDMS/Core.php"); - if(isset($options['F'])) { $folderid = (int) $options['F']; } else { @@ -58,6 +60,11 @@ if(isset($options['F'])) { exit(1); } +$username = ''; +if(isset($options['u'])) { + $username = $options['u']; +} + $comment = ''; if(isset($options['c'])) { $comment = $options['c']; @@ -73,23 +80,49 @@ if(isset($options['n'])) { $name = $options['n']; } -$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase); -$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\""); -//$db->_conn->debug = 1; +include($myincpath."/inc/inc.Settings.php"); +include($myincpath."/inc/inc.Init.php"); +include($myincpath."/inc/inc.Extension.php"); +include($myincpath."/inc/inc.DBInit.php"); +include($myincpath."/inc/inc.ClassNotificationService.php"); +include($myincpath."/inc/inc.ClassEmailNotify.php"); +include($myincpath."/inc/inc.ClassController.php"); -$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir); -if(!$settings->_doNotCheckDBVersion && !$dms->checkVersion()) { - echo "Database update needed."; - exit; +/* Create a global user object {{{ */ +if($username) { + if(!($user = $dms->getUserByLogin($username))) { + echo "No such user '".$username."'."; + exit; + } +} else + $user = $dms->getUser(1); + +$dms->setUser($user); +/* }}} */ + +/* Create a global notifier object {{{ */ +$notifier = new SeedDMS_NotificationService(); + +if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) { + foreach($GLOBALS['SEEDDMS_HOOKS']['notification'] as $notificationObj) { + if(method_exists($notificationObj, 'preAddService')) { + $notificationObj->preAddService($dms, $notifier); + } + } } -$dms->setRootFolderID($settings->_rootFolderID); -$dms->setMaxDirID($settings->_maxDirID); -$dms->setEnableConverting($settings->_enableConverting); -$dms->setViewOnlineFileTypes($settings->_viewOnlineFileTypes); +if($settings->_enableEmail) { + $notifier->addService(new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword)); +} -/* Create a global user object */ -$user = $dms->getUser(1); +if(isset($GLOBALS['SEEDDMS_HOOKS']['notification'])) { + foreach($GLOBALS['SEEDDMS_HOOKS']['notification'] as $notificationObj) { + if(method_exists($notificationObj, 'postAddService')) { + $notificationObj->postAddService($dms, $notifier); + } + } +} +/* }}} */ $folder = $dms->getFolder($folderid); @@ -108,11 +141,41 @@ if (!is_numeric($sequence)) { exit(1); } -$res = $folder->addSubFolder($name, $comment, $user, $sequence); +$controller = Controller::factory('AddSubFolder', array('dms'=>$dms, 'user'=>$user)); +$controller->setParam('folder', $folder); +$controller->setParam('name', $name); +$controller->setParam('comment', $comment); +$controller->setParam('sequence', $sequence); +$controller->setParam('attributes', array()); +$controller->setParam('notificationgroups', array()); +$controller->setParam('notificationusers', array()); +if(!$subFolder = $controller->run()) { + echo "Could not add subfolder to folder\n"; +} else { + // Send notification to subscribers. + if($notifier) { + $fnl = $folder->getNotifyList(); + $snl = $subFolder->getNotifyList(); + $nl = array( + 'users'=>array_unique(array_merge($snl['users'], $fnl['users']), SORT_REGULAR), + 'groups'=>array_unique(array_merge($snl['groups'], $fnl['groups']), SORT_REGULAR) + ); -if (is_bool($res) && !$res) { - echo "Could not add folder\n"; - exit(1); + $subject = "new_subfolder_email_subject"; + $message = "new_subfolder_email_body"; + $params = array(); + $params['name'] = $subFolder->getName(); + $params['folder_name'] = $folder->getName(); + $params['folder_path'] = $folder->getFolderPathPlain(); + $params['username'] = $user->getFullName(); + $params['comment'] = $comment; + $params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$subFolder->getID(); + $params['sitename'] = $settings->_siteName; + $params['http_root'] = $settings->_httpRoot; + $notifier->toList($user, $nl["users"], $subject, $message, $params); + foreach ($nl["groups"] as $grp) { + $notifier->toGroup($user, $grp, $subject, $message, $params); + } + } } -?> diff --git a/utils/indexer.php b/utils/indexer.php index f8eae2010..d0b911ba9 100644 --- a/utils/indexer.php +++ b/utils/indexer.php @@ -1,8 +1,10 @@ _extraPath)) - ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path')); -//ini_set('include_path', $settings->_rootDir. PATH_SEPARATOR .ini_get('include_path')); - -require_once("inc/inc.Init.php"); -require_once("inc/inc.Extension.php"); -require_once("inc/inc.DBInit.php"); -require "vendor/autoload.php"; +include($myincpath."/inc/inc.Settings.php"); +include($myincpath."/inc/inc.Init.php"); +include($myincpath."/inc/inc.Extension.php"); +include($myincpath."/inc/inc.DBInit.php"); if($settings->_fullSearchEngine == 'sqlitefts') { $indexconf = array( @@ -164,4 +162,3 @@ tree($dms, $index, $indexconf, $folder); $index->commit(); $index->optimize(); -?> diff --git a/utils/xmldump.php b/utils/xmldump.php index 192c85cae..f02282f98 100644 --- a/utils/xmldump.php +++ b/utils/xmldump.php @@ -1,8 +1,10 @@ _extraPath)) - ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path')); - -require_once("SeedDMS/Core.php"); - if(isset($options['folder'])) { $folderid = intval($options['folder']); } else { @@ -462,16 +459,10 @@ function tree($folder, $parent=null, $indent='', $skipcurrent=false) { /* {{{ */ } } /* }}} */ -$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase); -$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\""); - -$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir); -if(!$settings->_doNotCheckDBVersion && !$dms->checkVersion()) { - echo "Database update needed."; - exit; -} - -$dms->setRootFolderID($settings->_rootFolderID); +include($myincpath."/inc/inc.Settings.php"); +include($myincpath."/inc/inc.Init.php"); +include($myincpath."/inc/inc.Extension.php"); +include($myincpath."/inc/inc.DBInit.php"); echo "\n"; echo "getDBVersion(), 1, 3))."\" date=\"".date('Y-m-d H:i:s')."\">\n"; diff --git a/utils/xmlimport.php b/utils/xmlimport.php index f429dfd80..5e4392f26 100644 --- a/utils/xmlimport.php +++ b/utils/xmlimport.php @@ -1,10 +1,11 @@ err("Could not open mapping file '".$exportmapping."'"); } } -?>