mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
add task to send list of recent changes by email
This commit is contained in:
parent
d612220ad5
commit
b71467b8c8
|
@ -639,7 +639,7 @@ class SeedDMS_StatisticTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
|
|||
* @param SeedDMS_SchedulerTask $task task to be executed
|
||||
* @return boolean true if task was executed succesfully, otherwise false
|
||||
*/
|
||||
public function execute(SeedDMS_SchedulerTask $task) {
|
||||
public function execute(SeedDMS_SchedulerTask $task) { /* {{{ */
|
||||
$dms = $this->dms;
|
||||
$user = $this->user;
|
||||
$logger = $this->logger;
|
||||
|
@ -707,13 +707,13 @@ class SeedDMS_StatisticTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription() { /* {{{ */
|
||||
return 'Send statistics by email';
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
public function getAdditionalParams() {
|
||||
public function getAdditionalParams() { /* {{{ */
|
||||
return array(
|
||||
array(
|
||||
'name'=>'users',
|
||||
|
@ -722,7 +722,104 @@ class SeedDMS_StatisticTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
|
|||
'description'=> 'Send statistics report to this users',
|
||||
)
|
||||
);
|
||||
}
|
||||
} /* }}} */
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Class containing methods for running a scheduled task
|
||||
*
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @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 = "<tr><td>%s</td><td>%d</td><td>%s</td></tr>";
|
||||
$tableformatheadhtml = "<tr><th>%s</th><th>%s</th><th>%s</th></tr>";
|
||||
|
||||
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();
|
||||
}
|
||||
$docs = [];
|
||||
foreach(['newdocuments', 'updateddocuments', 'statuschange'] 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(['newdocuments', 'updateddocuments', 'statuschange'] as $dt) {
|
||||
$params = array();
|
||||
$bodyhtml .= "<h2>".getMLText('latest_'.$dt)."</h2>".PHP_EOL;
|
||||
$ds = SeedDMS_Core_DMS::filterAccess($docs[$dt], $u, M_READ);
|
||||
$params['count_'.$dt] = count($ds);
|
||||
if (count($ds)>0) {
|
||||
$bodyhtml .= "<table>".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(), $doc->getName());
|
||||
}
|
||||
$bodyhtml .= "</table>".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 check for. Negative values will look into the past. 0 will just check for documents expiring the current day. Keep in mind that the document is still valid on the expiration date.',
|
||||
),
|
||||
array(
|
||||
'name'=>'users',
|
||||
'type'=>'users',
|
||||
'multiple'=>true,
|
||||
'description'=> 'Send list of recently changed documents to this users',
|
||||
)
|
||||
);
|
||||
} /* }}} */
|
||||
} /* }}} */
|
||||
|
||||
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['expireddocs'] = 'SeedDMS_ExpiredDocumentsTask';
|
||||
|
@ -731,3 +828,4 @@ $GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['checksum'] = 'SeedDMS_CheckSumTa
|
|||
$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']['recentchanges'] = 'SeedDMS_RecentChangesTask';
|
||||
|
|
Loading…
Reference in New Issue
Block a user