* @package SeedDMS
* @subpackage core
*/
class SeedDMS_CalendarTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
/**
* Run the task
*
* @param SeedDMS_SchedulerTask $task task to be executed
* @return boolean true if task was executed succesfully, otherwise false
*/
public function execute(SeedDMS_SchedulerTask $task) {
$dms = $this->dms;
$user = $this->user;
$logger = $this->logger;
$settings = $this->settings;
$taskparams = $task->getParameter();
$tableformat = " %-10s %-60s";
$tableformathead = " %-10s %-60s";
$tableformathtml = "%s | %s |
";
$tableformatheadhtml = "%s | %s |
";
require_once('inc/inc.ClassEmailNotify.php');
require_once('inc/inc.ClassCalendar.php');
$email = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword);
$calendar = new SeedDMS_Calendar($dms->getDB(), null);
$allusers = $dms->getAllUsers();
foreach($allusers as $auser) {
if(!$auser->isAdmin() && !$auser->isGuest() && !$auser->isDisabled() && $auser->getEmail()) {
$body = ''.$auser->getLogin()." <".$auser->getEmail().">\n\n";
$bodyhtml = ''.$auser->getLogin()." <".$auser->getEmail().">
";
$calendar->setUser($auser);
if(isset($taskparams['days']))
$days = intval($taskparams['days']);
else
$days = 7;
if($days < 0) {
$end = mktime(0,0,0, date('m'), date('d'), date('Y'))-1;
$start = $end+$days*86400+1;
} elseif($days > 0) {
$start = mktime(0,0,0, date('m'), date('d'), date('Y'));
$end = $start+$days*86400-1;
} else {
$start = mktime(0,0,0, date('m'), date('d'), date('Y'));
$end = $start+86400-1;
}
$events = $calendar->getEventsInInterval($start, $end);
if($events && count($events)>0) {
$body .= getMLText('startdate', [], null, $auser->getLanguage()).': '.getLongReadableDate($start)."\n";
$body .= getMLText('enddate', [], null, $auser->getLanguage()).': '.getLongReadableDate($end)."\n\n";
$bodyhtml .= ''.getMLText('startdate', [], null, $auser->getLanguage()).': '.getLongReadableDate($start)."
";
$bodyhtml .= ''.getMLText('enddate', [], null, $auser->getLanguage()).': '.getLongReadableDate($end)."
";
$bodyhtml .= "".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("date", array(), null, $auser->getLanguage()), getMLText("name", array(), null, $auser->getLanguage()));
$body .= sprintf($tableformathead."\n", getMLText("date", array(), null, $auser->getLanguage()), getMLText("name", array(), null, $auser->getLanguage()));
$body .= "---------------------------------------------------------------------------------\n";
foreach($events as $event) {
$body .= sprintf($tableformat."\n", getReadableDate($event['start']), $event['name']);
$bodyhtml .= sprintf($tableformathtml."\n", getReadableDate($event['start']), $event['name']);
}
$bodyhtml .= "
".PHP_EOL;
$params = array();
$params['count'] = count($events);
$params['__body__'] = $body;
$params['__body_html__'] = $bodyhtml;
$params['sitename'] = $settings->_siteName;
$email->toIndividual('', $auser, 'calendar_events_mail_subject', '', $params);
$logger->log('Task \'calendar_events\': Sending reminder \'calender_events_mail_subject\' to user \''.$auser->getLogin().'\'', PEAR_LOG_INFO);
}
}
}
return true;
}
public function getDescription() {
return 'Check calendar for upcoming events';
}
public function getAdditionalParams() {
return array(
array(
'name'=>'days',
'type'=>'integer',
'description'=> 'Number of days to look ahead starting from today. Negative values will look into the past ending today. 0 will just check for events of the current day.',
),
);
}
} /* }}} */
/**
* Class containing methods for running a scheduled task
*
* @author Uwe Steinmann
* @package SeedDMS
* @subpackage core
*/
class SeedDMS_StatisticTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
/**
* Run the task
*
* @param SeedDMS_SchedulerTask $task task to be executed
* @return boolean true if task was executed succesfully, otherwise false
*/
public function execute(SeedDMS_SchedulerTask $task) { /* {{{ */
$dms = $this->dms;
$user = $this->user;
$logger = $this->logger;
$settings = $this->settings;
$taskparams = $task->getParameter();
$tableformat = " %-30s %5d";
$tableformathead = " %-30s %5s";
$tableformathtml = "%s | %d |
";
$tableformatheadhtml = "%s | %s |
";
require_once('inc/inc.ClassEmailNotify.php');
$email = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword);
$userstotal = $dms->getStatisticalData('userstotal');
$docstotal = $dms->getStatisticalData('docstotal');
$folderstotal = $dms->getStatisticalData('folderstotal');
$docsaccumulated = $dms->getStatisticalData('docsaccumulated');
$userids = $taskparams['users'];
foreach($userids as $userid) {
if(($auser = $dms->getUser((int) $userid)) && $auser->isAdmin() && !$auser->isDisabled() && $auser->getEmail()) {
/* Create individual mails, because the users may have different
* languages.
*/
$body = ''.$auser->getLogin()." <".$auser->getEmail().">\n\n";
$bodyhtml = ''.$auser->getLogin()." <".$auser->getEmail().">
";
$bodyhtml .= "".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("name", array(), null, $auser->getLanguage()), getMLText("number_count", array(), ""));
$body .= sprintf($tableformathead."\n", getMLText("name", array(), ""), getMLText("number_count", array(), null, $auser->getLanguage()));
$body .= "---------------------------------------------------------------------------------\n";
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("users", array(), null, $auser->getLanguage()), $userstotal);
$body .= sprintf($tableformat."\n", getMLText("users", array(), null, $auser->getLanguage()), $userstotal);
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("documents", array(), null, $auser->getLanguage()), $docstotal);
$body .= sprintf($tableformat."\n", getMLText("documents", array(), null, $auser->getLanguage()), $docstotal);
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("folders", array(), null, $auser->getLanguage()), $folderstotal);
$body .= sprintf($tableformat."\n", getMLText("folders", array(), null, $auser->getLanguage()), $folderstotal);
$today = date('Y-m-d');
$yesterday = date('Y-m-d', time()-86400);
if(isset($docsaccumulated[$today])) {
$docstoday = $docsaccumulated[$today];
} else {
$docstoday = 0;
}
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("new_documents_today", array(), null, $auser->getLanguage()), $docstoday);
$body .= sprintf($tableformat."\n", getMLText("new_documents_today", array(), null, $auser->getLanguage()), $docstoday);
if(isset($docsaccumulated[$yesterday])) {
$docsyesterday = $docsaccumulated[$yesterday];
} else {
$docsyesterday = 0;
}
$bodyhtml .= sprintf($tableformathtml."\n", getMLText("new_documents_yesterday", array(), null, $auser->getLanguage()), $docsyesterday);
$body .= sprintf($tableformat."\n", getMLText("new_documents_yesterday", array(), null, $auser->getLanguage()), $docsyesterday);
$bodyhtml .= "
".PHP_EOL;
$params = array();
$params['__body__'] = $body;
$params['__body_html__'] = $bodyhtml;
$params['sitename'] = $settings->_siteName;
$email->toIndividual('', $auser, 'statistics_mail_subject', '', $params);
$logger->log('Task \'statistics\': Sending statistics \'statistics_mail_subject\' to user \''.$auser->getLogin().'\'', PEAR_LOG_INFO);
}
}
return true;
} /* }}} */
public function getDescription() { /* {{{ */
return 'Send statistics by email';
} /* }}} */
public function getAdditionalParams() { /* {{{ */
return array(
array(
'name'=>'users',
'type'=>'users',
'multiple'=>true,
'description'=> 'Send statistics report to this users',
)
);
} /* }}} */
} /* }}} */
/**
* Class containing methods for running a scheduled task
*
* @author Uwe Steinmann
* @package SeedDMS
* @subpackage core
*/
class SeedDMS_RecentChangesTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
/**
* Run the task
*
* @param SeedDMS_SchedulerTask $task task to be executed
* @return boolean true if task was executed succesfully, otherwise false
*/
public function execute(SeedDMS_SchedulerTask $task) { /* {{{ */
$dms = $this->dms;
$user = $this->user;
$settings = $this->settings;
$logger = $this->logger;
$taskparams = $task->getParameter();
$tableformat = " %-10s %5d %-60s";
$tableformathead = " %-10s %5s %-60s";
$tableformathtml = "%s | %d | %s |
";
$tableformatheadhtml = "%s | %s | %s |
";
require_once('inc/inc.ClassEmailNotify.php');
$email = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword);
if(!empty($taskparams['users'])) {
$userids = $taskparams['users'];
$users = [];
foreach($userids as $userid)
if($u = $dms->getUser($userid))
$users[] = $u;
} else {
$users = $dms->getAllUsers();
}
if(!empty($taskparams['lists'])) {
$lists = $taskparams['lists'];
} else {
$lists = ['newdocuments', 'updateddocuments', 'statuschange'];
}
$docs = [];
foreach($lists as $dt) {
$docs[$dt] = $dms->getLatestChanges($dt, mktime(0, 0, 0)-intval($taskparams['days'])*86400, time());
}
foreach($users as $u) {
if(!$u->isGuest() && !$u->isDisabled()) {
$body = '';
$bodyhtml = '';
foreach($lists as $dt) {
$params = array();
$bodyhtml .= "".getMLText('latest_'.$dt)."
".PHP_EOL;
$body .= getMLText('latest_'.$dt).PHP_EOL.PHP_EOL;
$ds = SeedDMS_Core_DMS::filterAccess($docs[$dt], $u, M_READ);
$params['count_'.$dt] = count($ds);
if (count($ds)>0) {
$bodyhtml .= "".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("date", array(), ""), "ID", getMLText("name", array(), ""));
$body .= sprintf($tableformathead."\n", getMLText("date", array(), ""), "ID", getMLText("name", array(), ""));
$body .= "---------------------------------------------------------------------------------\n";
foreach($ds as $doc) {
$body .= sprintf($tableformat."\n", getReadableDate($doc->getDate()), $doc->getId(), $doc->getName());
$bodyhtml .= sprintf($tableformathtml."\n", getReadableDate($doc->getDate()), $doc->getId(), ''.htmlspecialchars($doc->getName()).'');
}
$bodyhtml .= "
".PHP_EOL;
$body .= PHP_EOL;
}
}
$params['__body__'] = $body;
$params['__body_html__'] = $bodyhtml;
$params['sitename'] = $settings->_siteName;
$email->toIndividual('', $u, 'recentchanges_mail_subject', '', $params);
$logger->log('Task \'recentchanges\': Sending reminder \'recentchanges_mail_subject\' to user \''.$u->getLogin().'\'', PEAR_LOG_INFO);
}
}
return true;
} /* }}} */
public function getDescription() { /* {{{ */
return 'Report new and updated documents and those with a changed status';
} /* }}} */
public function getAdditionalParams() { /* {{{ */
return array(
array(
'name'=>'days',
'type'=>'integer',
'description'=> 'Number of days to look back.',
),
array(
'name'=>'lists',
'type'=>'select',
'description'=>'Document lists to be included.',
'multiple'=>true,
'options'=>[['newdocuments', getMLText('latest_newdocuments')], ['updateddocuments', getMLText('latest_updateddocuments')], ['statuschange', getMLText('latest_statuschange')]],
),
array(
'name'=>'users',
'type'=>'users',
'multiple'=>true,
'description'=> 'Send list of recently changed or added documents to this users',
)
);
} /* }}} */
} /* }}} */
/**
* Class containing methods for running a scheduled task
*
* @author Uwe Steinmann
* @package SeedDMS
* @subpackage core
*/
class SeedDMS_ImportDropFolderTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
private static function getFiles($path, $recursive=false) {
if($recursive)
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
else
$rii = new DirectoryIterator($path);
$files = array();
try {
foreach ($rii as $file)
if (!$file->isDir())
$files[] = [substr($file->getPath(), strlen($path)+1), $file->getFilename()];
} catch(Exception $e) {
}
return $files;
}
/**
* Run the task
*
* @param SeedDMS_SchedulerTask $task task to be executed
* @return boolean true if task was executed succesfully, otherwise false
*/
public function execute(SeedDMS_SchedulerTask $task) { /* {{{ */
$dms = $this->dms;
$user = $this->user;
$logger = $this->logger;
$settings = $this->settings;
$fulltextservice = $this->fulltextservice;
$notifier = $this->notifier;
$taskparams = $task->getParameter();
$dropfolderdir = addDirSep($settings->_dropFolderDir);
if(!empty($taskparams['targetfolder'])) {
if(!($folder = $dms->getFolder($taskparams['targetfolder']))) {
$logger->log('Task \'import_dropfolder\': target folder with id '.$taskparams['targetfolder'].' does not exist', PEAR_LOG_ERR);
return false;
}
} else {
$logger->log('Task \'import_dropfolder\': target folder not set', PEAR_LOG_ERR);
return false;
}
if(!empty($taskparams['users'])) {
$userids = $taskparams['users'];
$users = [];
foreach($userids as $userid)
if($u = $dms->getUser($userid))
$users[] = $u;
} else {
$users = $dms->getAllUsers();
}
foreach($users as $user) {
$dir = $dropfolderdir.$user->getLogin();
$logger->log('Task \'import_dropfolder\': import from \''.$dir.'\' for user \''.$user->getLogin().'\' into \''.$folder->getName().'\'', PEAR_LOG_INFO);
/* Check if we are still looking in the configured directory and
* not somewhere else, e.g. if the login was '../test'
*/
if(dirname($dir).DIRECTORY_SEPARATOR == $dropfolderdir) {
if(is_dir($dir)) {
$files = self::getFiles($dir, !empty($taskparams['recursive']));
foreach($files as $file) {
$logger->log('Task \'import_dropfolder\': import \''.($file[0] ? $file[0].DIRECTORY_SEPARATOR : '').$file[1].'\' for user \''.$user->getLogin().'\'', PEAR_LOG_INFO);
if(empty($taskparams['dryrun'])) {
$mimetype = SeedDMS_Core_File::mimetype($dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
$lastDotIndex = strrpos($file[1], ".");
if (is_bool($lastDotIndex) && !$lastDotIndex) $filetype = ".";
else $filetype = substr($file[1], $lastDotIndex);
$expires = false;
if($settings->_presetExpirationDate) {
$expires = strtotime($settings->_presetExpirationDate);
}
$controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user));
$controller->setParam('documentsource', 'importdropfolder');
$controller->setParam('folder', $folder);
$controller->setParam('fulltextservice', $fulltextservice);
$controller->setParam('name', $file[1]);
$controller->setParam('comment', '');
$controller->setParam('expires', $expires);
$controller->setParam('keywords', '');
$controller->setParam('categories', []);
$controller->setParam('owner', $user);
$controller->setParam('userfiletmp', $dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
$controller->setParam('userfilename', $file[1]);
$controller->setParam('filetype', $filetype);
$controller->setParam('userfiletype', $mimetype);
$minmax = $folder->getDocumentsMinMax();
$deviation = rand(10, 1000)/10;
if($settings->_defaultDocPosition == 'start')
$controller->setParam('sequence', $minmax['min'] - $deviation);
else
$controller->setParam('sequence', $minmax['max'] + $deviation);
$controller->setParam('reviewers', []);
$controller->setParam('approvers', []);
$controller->setParam('reqversion', 1);
$controller->setParam('versioncomment', '');
$controller->setParam('attributes', []);
$controller->setParam('attributesversion', array());
$controller->setParam('workflow', null);
$controller->setParam('notificationgroups', array());
$controller->setParam('notificationusers', array());
$controller->setParam('initialdocumentstatus', $settings->_initialDocumentStatus);
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $settings->_defaultAccessDocs);
if(!$document = $controller()) {
$err = $controller->getErrorMsg();
if(is_string($err))
$errmsg = getMLText($err);
elseif(is_array($err)) {
$errmsg = getMLText($err[0], $err[1]);
} else {
$errmsg = $err;
}
$logger->log('Task \'import_dropfolder\': import of \''.($file[0] ? $file[0].DIRECTORY_SEPARATOR : '').$file[1].'\' for user \''.$user->getLogin().'\' failed', PEAR_LOG_ERR);
} else {
// Send notification to subscribers of folder.
if($notifier) {
$notifier->sendNewDocumentMail($document, $user);
}
/* Remove the file, unless it shall stay in the drop folder */
if(empty($taskparams['keepfile'])) {
if(file_exists($dir.DIRECTORY_SEPARATOR.$file[0].$file[1])) {
unlink($dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
}
}
}
}
}
}
}
}
return true;
} /* }}} */
public function getDescription() { /* {{{ */
return 'Import all files from drop folder';
} /* }}} */
public function getAdditionalParams() { /* {{{ */
return array(
array(
'name'=>'users',
'type'=>'users',
'multiple'=>true,
'description'=> 'Use this user for the import',
),
array(
'name'=>'recursive',
'type'=>'boolean',
'description'=> 'If set, import documents from sub folders in drop folder directory.',
),
array(
'name'=>'targetfolder',
'type'=>'folder',
'description'=> getMLText('task_core_importdropfolder_targetfolder_desc'),
),
array(
'name'=>'keepfile',
'type'=>'boolean',
'description'=> getMLText('task_core_importdropfolder_keepfile_desc'),
),
array(
'name'=>'dryrun',
'type'=>'boolean',
'description'=> getMLText('task_core_importdropfolder_dryrun_desc'),
),
);
} /* }}} */
} /* }}} */
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['expireddocs'] = 'SeedDMS_ExpiredDocumentsTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['indexingdocs'] = 'SeedDMS_IndexingDocumentsTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['checksum'] = 'SeedDMS_CheckSumTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['preview'] = 'SeedDMS_PreviewTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['calendar'] = 'SeedDMS_CalendarTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['statistic'] = 'SeedDMS_StatisticTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['importdropfolder'] = 'SeedDMS_ImportDropFolderTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['recentchanges'] = 'SeedDMS_RecentChangesTask';