] [-c ] [-n ] [-s ] [-h] [-v] -F ".PHP_EOL; echo PHP_EOL; echo "Description:".PHP_EOL; echo " This program creates a new folder in SeedDMS.".PHP_EOL; echo PHP_EOL; echo "Options:".PHP_EOL; echo " -h, --help: print usage information and exit.".PHP_EOL; echo " -v, --version: print version and exit.".PHP_EOL; echo " --config: set alternative config file.".PHP_EOL; echo " -u : login name of user".PHP_EOL; echo " -F : id of parent folder".PHP_EOL; echo " -c : set comment for file".PHP_EOL; echo " -n : set name of the folder".PHP_EOL; echo " -s : set sequence of folder".PHP_EOL; } /* }}} */ $version = "0.0.1"; $shortoptions = "F:u:c:s:n:hv"; $longoptions = array('help', 'version', 'config:'); if(false === ($options = getopt($shortoptions, $longoptions))) { usage(); exit(0); } /* Print help and exit */ if(isset($options['h']) || isset($options['help'])) { usage(); exit(0); } /* Print version and exit */ if(isset($options['v']) || isset($options['verŅ•ion'])) { echo $version.PHP_EOL; exit(0); } /* 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']); } if(isset($options['F'])) { $folderid = (int) $options['F']; } else { echo "Missing parent folder ID".PHP_EOL; usage(); exit(1); } $username = ''; if(isset($options['u'])) { $username = $options['u']; } $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']; } 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"); /* 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); } } } if($settings->_enableEmail) { $notifier->addService(new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword)); } 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); if (!is_object($folder)) { echo "Could not find specified folder".PHP_EOL; exit(1); } if ($folder->getAccessMode($user) < M_READWRITE) { echo "Not sufficient access rights".PHP_EOL; exit(1); } if (!is_numeric($sequence)) { echo "Sequence must be numeric".PHP_EOL; exit(1); } $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".PHP_EOL; } 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) ); $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); } } }