mails listing expired documents can be send for each owner

This commit is contained in:
Uwe Steinmann 2021-06-16 08:02:32 +02:00
parent fbc3be64a2
commit e425120d7d

View File

@ -24,27 +24,52 @@ class SeedDMS_ExpiredDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
$settings = $this->settings;
$logger = $this->logger;
$taskparams = $task->getParameter();
$docs = $dms->getDocumentsExpired(intval($taskparams['days']));
$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>";
$body = '';
$bodyhtml = '';
if (count($docs)>0) {
$bodyhtml .= "<table>".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("expiration_date", array(), ""), "ID", getMLText("name", array(), ""));
$body .= sprintf($tableformathead."\n", getMLText("expiration_date", array(), ""), "ID", getMLText("name", array(), ""));
$body .= "---------------------------------------------------------------------------------\n";
foreach($docs as $doc) {
$body .= sprintf($tableformat."\n", getReadableDate($doc->getExpires()), $doc->getId(), $doc->getName());
$bodyhtml .= sprintf($tableformathtml."\n", getReadableDate($doc->getExpires()), $doc->getId(), $doc->getName());
}
$bodyhtml .= "</table>".PHP_EOL;
if($taskparams['email'])
require_once('inc/inc.ClassEmailNotify.php');
$email = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword);
require_once('inc/inc.ClassEmailNotify.php');
$email = new SeedDMS_EmailNotify($dms, $settings->_smtpSendFrom, $settings->_smtpServer, $settings->_smtpPort, $settings->_smtpUser, $settings->_smtpPassword);
if(!empty($taskparams['peruser'])) {
$users = $dms->getAllUsers();
foreach($users as $u) {
$docs = $dms->getDocumentsExpired(intval($taskparams['days']), $u);
if (count($docs)>0) {
$bodyhtml .= "<table>".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("expires", array(), ""), "ID", getMLText("name", array(), ""));
$body .= sprintf($tableformathead."\n", getMLText("expires", array(), ""), "ID", getMLText("name", array(), ""));
$body .= "---------------------------------------------------------------------------------\n";
foreach($docs as $doc) {
$body .= sprintf($tableformat."\n", getReadableDate($doc->getExpires()), $doc->getId(), $doc->getName());
$bodyhtml .= sprintf($tableformathtml."\n", getReadableDate($doc->getExpires()), $doc->getId(), $doc->getName());
}
$bodyhtml .= "</table>".PHP_EOL;
$params = array();
$params['count'] = count($docs);
$params['__body__'] = $body;
$params['__body_html__'] = $bodyhtml;
$params['sitename'] = $settings->_siteName;
$email->toIndividual('', $u, 'expired_docs_mail_subject', '', $params);
$logger->log('Task \'expired_docs\': Sending reminder \'expired_docs_mail_subject\' to user \''.$u->getLogin().'\'', PEAR_LOG_INFO);
}
}
} elseif($taskparams['email']) {
$docs = $dms->getDocumentsExpired(intval($taskparams['days']));
if (count($docs)>0) {
$bodyhtml .= "<table>".PHP_EOL;
$bodyhtml .= sprintf($tableformatheadhtml."\n", getMLText("expiration_date", array(), ""), "ID", getMLText("name", array(), ""));
$body .= sprintf($tableformathead."\n", getMLText("expiration_date", array(), ""), "ID", getMLText("name", array(), ""));
$body .= "---------------------------------------------------------------------------------\n";
foreach($docs as $doc) {
$body .= sprintf($tableformat."\n", getReadableDate($doc->getExpires()), $doc->getId(), $doc->getName());
$bodyhtml .= sprintf($tableformathtml."\n", getReadableDate($doc->getExpires()), $doc->getId(), $doc->getName());
}
$bodyhtml .= "</table>".PHP_EOL;
$params = array();
$params['count'] = count($docs);
$params['__body__'] = $body;
@ -53,7 +78,9 @@ class SeedDMS_ExpiredDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
$email->toIndividual('', $taskparams['email'], 'expired_docs_mail_subject', '', $params);
$logger->log('Task \'expired_docs\': Sending reminder \'expired_docs_mail_subject\' to user \''.$taskparams['email'].'\'', PEAR_LOG_INFO);
// mail($taskparams['email'], getMLText('expired_docs_mail_subject',array('sitename'=>$settings->_siteName, 'count'=>count($docs))), $body);
}
} else {
$logger->log('Task \'expired_docs\': neither peruser nor email is set', PEAR_LOG_WARNING);
}
return true;
}
@ -73,6 +100,11 @@ class SeedDMS_ExpiredDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
'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'=>'peruser',
'type'=>'boolean',
'description'=> 'Send mail to each user. If set, a list of all expired documents will be send to the owner of the documents.',
)
);
}