send mail if attributes are changed, fix setting comment in email

This commit is contained in:
Uwe Steinmann 2018-03-19 12:13:18 +01:00
parent 0563636b7d
commit 150b9975d3

View File

@ -66,7 +66,12 @@ else
$oldname = $folder->getName();
$oldcomment = $folder->getComment();
$oldattributes = $folder->getAttributes();
/* Make a real copy of each attribute because setting a new attribute value
* will just update the old attribute object in array attributes[] and hence
* also update the old value
*/
foreach($folder->getAttributes() as $ai=>$aa)
$oldattributes[$ai] = clone $aa;
$controller->setParam('folder', $folder);
$controller->setParam('name', $name);
@ -115,7 +120,7 @@ if($oldcomment != $comment) {
$params['name'] = $folder->getName();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['old_comment'] = $oldcomment;
$params['comment'] = $comment;
$params['new_comment'] = $comment;
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
@ -131,6 +136,61 @@ if($oldcomment != $comment) {
}
}
$newattributes = $folder->getAttributes();
if($oldattributes) {
foreach($oldattributes as $attrdefid=>$attribute) {
if(!isset($newattributes[$attrdefid]) || $newattributes[$attrdefid]->getValueAsArray() !== $oldattributes[$attrdefid]->getValueAsArray()) {
if($notifier) {
$notifyList = $folder->getNotifyList();
$subject = "folder_attribute_changed_email_subject";
$message = "folder_attribute_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['attribute_name'] = $attribute->getAttributeDefinition()->getName();
$params['attribute_old_value'] = $oldattributes[$attrdefid]->getValue();
$params['attribute_new_value'] = isset($newattributes[$attrdefid]) ? $newattributes[$attrdefid]->getValue() : '';
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
}
}
/* Check for new attributes which didn't have a value before */
if($newattributes) {
foreach($newattributes as $attrdefid=>$attribute) {
if(!isset($oldattributes[$attrdefid]) && $attribute) {
if($notifier) {
$notifyList = $folder->getNotifyList();
$subject = "folder_attribute_changed_email_subject";
$message = "folder_attribute_changed_email_body";
$params = array();
$params['name'] = $folder->getName();
$params['attribute_name'] = $dms->getAttributeDefinition($attrdefid)->getName();
$params['attribute_old_value'] = '';
$params['attribute_new_value'] = $attribute->getValue();
$params['folder_path'] = $folder->getFolderPathPlain();
$params['username'] = $user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID();
$params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot;
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
foreach ($notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
}
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_folder_edited')));
add_log_line("?folderid=".$folderid);