Fixed issues with notifications

This commit is contained in:
Tomolimo
2021-07-30 10:09:50 +02:00
parent 2d29fa5aa1
commit 14e7e612c9
6 changed files with 709 additions and 674 deletions

View File

@@ -1,120 +1,137 @@
<?php <?php
/* /*
* @version $Id: notificationtargettaskcategory.class.php tomolimo $ * @version $Id: notificationtargettaskcategory.class.php tomolimo $
------------------------------------------------------------------------- -------------------------------------------------------------------------
*/ */
if (!defined('GLPI_ROOT')) { if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file"); die("Sorry. You can't access directly to this file");
} }
// Class NotificationTarget // Class NotificationTarget
class PluginProcessmakerNotificationTargetCase extends PluginProcessmakerNotificationTargetProcessmaker { class PluginProcessmakerNotificationTargetCase extends PluginProcessmakerNotificationTargetProcessmaker {
// type // type
const EMAIL_RECIPIENTS = 200; const EMAIL_RECIPIENTS = 200;
// user type // user type
const RECIPIENTS = 1; const RECIPIENTS = 1;
/** /**
* Summary of getEvents * Summary of getEvents
* @return string[] * @return string[]
*/ */
public function getEvents() { public function getEvents() {
return ['send_email' => __('Send email', 'processmaker')]; return ['send_email' => __('Send email', 'processmaker')];
} }
/** /**
* Summary of addAdditionalTargets * Summary of addAdditionalTargets
* @param mixed $event * @param mixed $event
*/ */
function addAdditionalTargets($event = '') { function addAdditionalTargets($event = '') {
$this->notification_targets = []; $this->notification_targets = [];
$this->notification_targets_labels = []; $this->notification_targets_labels = [];
$this->addTarget(self::RECIPIENTS, __('eMail recipients', 'processmaker'), self::EMAIL_RECIPIENTS); $this->addTarget(self::RECIPIENTS, __('eMail recipients', 'processmaker'), self::EMAIL_RECIPIENTS);
} }
/** /**
* Summary of addSpecificTargets * Summary of addSpecificTargets
* @param mixed $data * @param mixed $data
* @param mixed $options * @param mixed $options
*/ */
function addSpecificTargets($data, $options) { function addSpecificTargets($data, $options) {
// test if we are in the good notification // test if we are in the good notification
// then in this case add the targets from the ['recipients'] // then in this case add the targets from the ['recipients']
if (isset($options['glpi_send_email'])) { if (isset($options['glpi_send_email'])) {
// normalize $options['glpi_send_email'] to an array of email parameters // normalize $options['glpi_send_email'] to an array of email parameters
$options['glpi_send_email'] = isset($options['glpi_send_email']['notifications_id']) ? [$options['glpi_send_email']] : $options['glpi_send_email']; $options['glpi_send_email'] = isset($options['glpi_send_email']['notifications_id']) ? [$options['glpi_send_email']] : $options['glpi_send_email'];
foreach($options['glpi_send_email'] as $params) { foreach($options['glpi_send_email'] as $params) {
if (isset($params['notifications_id']) if (isset($params['notifications_id'])
&& $params['notifications_id'] == $data['notifications_id']) { && $params['notifications_id'] == $data['notifications_id']) {
//Look for all targets whose type is Notification::ITEM_USER //Look for all targets whose type is Notification::ITEM_USER
switch ($data['type']) { switch ($data['type']) {
case self::EMAIL_RECIPIENTS: case self::EMAIL_RECIPIENTS:
switch ($data['items_id']) { switch ($data['items_id']) {
case self::RECIPIENTS : case self::RECIPIENTS :
$this->addUsers($params); $this->addUsers($params);
break; break;
} }
} }
} }
} }
} }
// if no target is added to $this, then the notification will not be sent. // if no target is added to $this, then the notification will not be sent.
} }
/** /**
* Add users from $options['glpi_send_email']['to'] * Add users from $email_param['recipients']
* *
* @param array $email_param should contain 'recipients' * @param array $email_param should contain 'recipients'
* *
* @return void * @return void
*/ */
function addUsers($email_param = []) { function addUsers($email_param = []) {
global $DB, $CFG_GLPI; global $DB, $CFG_GLPI;
if (isset($email_param['recipients'])) { if (isset($email_param['recipients'])) {
$id_list = []; // for users with ids $id_list = []; // for users with ids
$email_list = []; // for standalone emails $email_list = []; // for standalone emails
// normalize into array the recipient list // normalize into array the recipient list
$email_param['recipients'] = is_array($email_param['recipients']) ? $email_param['recipients'] : [$email_param['recipients']]; $email_param['recipients'] = is_array($email_param['recipients']) ? $email_param['recipients'] : [$email_param['recipients']];
foreach ($email_param['recipients'] as $user) { foreach ($email_param['recipients'] as $user) {
if (is_numeric($user)) { if (is_numeric($user)) {
$id_list[] = intval($user); $id_list[] = intval($user);
} else { } else {
$email_list[] = $user; $email_list[] = $user;
} }
} }
$query = $this->getDistinctUserSql()." $user = new User();
FROM `glpi_users` ". foreach ($id_list as $users_id) {
$this->getProfileJoinSql()." if ($user->getFromDB($users_id)) {
WHERE `glpi_users`.`id` IN (".implode(',', $id_list).")";
$author_email = UserEmail::getDefaultForUser($user->fields['id']);
foreach ($DB->request($query) as $data) { $author_lang = $user->fields["language"];
$this->addToRecipientsList($data); $author_id = $user->fields['id'];
}
if (empty($author_lang)) {
foreach($email_list as $email){ $author_lang = $CFG_GLPI["language"];
$this->addToRecipientsList([ }
'email' => $email, if (empty($author_id)) {
'language' => $CFG_GLPI["language"], $author_id = -1;
'users_id' => -1 }
]);
} $user = [
} 'language' => $author_lang,
} 'users_id' => $author_id
];
} if ($this->isMailMode()) {
$user['email'] = $author_email;
}
$this->addToRecipientsList($user);
}
}
foreach($email_list as $email){
$this->addToRecipientsList([
'email' => $email,
'language' => $CFG_GLPI["language"],
'users_id' => -1
]);
}
}
}
}

View File

@@ -1,225 +1,227 @@
<?php <?php
/** /**
* PluginProcessmakerNotificationTargetProcessmaker short summary. * PluginProcessmakerNotificationTargetProcessmaker short summary.
* *
* PluginProcessmakerNotificationTargetProcessmaker description. * PluginProcessmakerNotificationTargetProcessmaker description.
* *
* Common notificationtarget class for cases and tasks * Common notificationtarget class for cases and tasks
* *
* @version 1.0 * @version 1.0
* @author MoronO * @author MoronO
*/ */
class PluginProcessmakerNotificationTargetProcessmaker extends NotificationTargetCommonITILObject { class PluginProcessmakerNotificationTargetProcessmaker extends NotificationTargetCommonITILObject {
const PM_USER_TYPE = 1000; const PM_USER_TYPE = 1000;
const OLD_TASK_TECH_IN_CHARGE = 1; const OLD_TASK_TECH_IN_CHARGE = 1;
/** /**
* Summary of saveNotificationState * Summary of saveNotificationState
* @param mixed $donotif * @param mixed $donotif
* @return mixed * @return mixed
*/ */
static function saveNotificationState($donotif) { static function saveNotificationState($donotif) {
global $CFG_GLPI; global $CFG_GLPI;
$savenotif = $CFG_GLPI["use_notifications"]; $savenotif = $CFG_GLPI["use_notifications"];
if (!$donotif) { if (!$donotif) {
$CFG_GLPI["use_notifications"] = false; $CFG_GLPI["use_notifications"] = false;
} }
return $savenotif; return $savenotif;
} }
/** /**
* Summary of restoreNotificationState * Summary of restoreNotificationState
* @param mixed $savenotif * @param mixed $savenotif
*/ */
static function restoreNotificationState($savenotif) { static function restoreNotificationState($savenotif) {
global $CFG_GLPI; global $CFG_GLPI;
$CFG_GLPI["use_notifications"] = $savenotif; $CFG_GLPI["use_notifications"] = $savenotif;
} }
/** /**
* Summary of getSubjectPrefix * Summary of getSubjectPrefix
* @param mixed $event * @param mixed $event
* @return string * @return string
*/ */
function getSubjectPrefix($event = '') { function getSubjectPrefix($event = '') {
return ''; return '';
} }
/** /**
* Summary of getTags * Summary of getTags
*/ */
public function getTags() { public function getTags() {
$tags = ['process.category' => __('Process category', 'processmaker'), $tags = ['process.category' => __('Process category', 'processmaker'),
'process.categoryid' => __('Process category id', 'processmaker'), 'process.categoryid' => __('Process category id', 'processmaker'),
'process.categorycomment' => __('Process category comment', 'processmaker'), 'process.categorycomment' => __('Process category comment', 'processmaker'),
'case.id' => __('Case id', 'processmaker'), 'case.id' => __('Case id', 'processmaker'),
'case.title' => __('Case title', 'processmaker'), 'case.title' => __('Case title', 'processmaker'),
'case.description' => __('Case description', 'processmaker'), 'case.description' => __('Case description', 'processmaker'),
'case.url' => __('Case URL'), 'case.url' => __('Case URL'),
'var.XXX' => __('Case variable \'XXX\'', 'processmaker'), 'var.XXX' => __('Case variable \'XXX\'', 'processmaker'),
'array.YYY' => __('List of values in \'YYY\' array', 'processmaker'), 'array.YYY' => __('List of values in \'YYY\' array', 'processmaker'),
'array.numberofYYY' => __('Number of rows in \'YYY\' array', 'processmaker'), 'array.numberofYYY' => __('Number of rows in \'YYY\' array', 'processmaker'),
'array.YYY.colname' => __('Value for colname in \'YYY\' array', 'processmaker'), 'array.YYY.colname' => __('Value for colname in \'YYY\' array', 'processmaker'),
'1darray.ZZZ.key' => __('Value for key in \'ZZZ\' assoc array (1-dimension array)', 'processmaker'), '1darray.ZZZ.key' => __('Value for key in \'ZZZ\' assoc array (1-dimension array)', 'processmaker'),
'item.type' => __('Item type', 'processmaker'), 'item.type' => __('Item type', 'processmaker'),
'item.id' => __('Item id', 'processmaker'), 'item.id' => __('Item id', 'processmaker'),
'item.url' => __('Item URL', 'processmaker'), 'item.url' => __('Item URL', 'processmaker'),
'item.title' => __('Item title', 'processmaker') 'item.title' => __('Item title', 'processmaker')
]; ];
foreach ($tags as $tag => $label) { foreach ($tags as $tag => $label) {
$elt= ['tag' => $tag, $elt= ['tag' => $tag,
'label' => $label, 'label' => $label,
'value' => true]; 'value' => true];
if ($tag == 'var.XXX') { if ($tag == 'var.XXX') {
$elt['allowed_values'] = [__('XXX is to be replaced by any case variable names', 'processmaker')]; $elt['allowed_values'] = [__('XXX is to be replaced by any case variable names', 'processmaker')];
} }
if ($tag == 'array.YYY') { if ($tag == 'array.YYY') {
$elt['allowed_values'] = [__('YYY is to be replaced by any array variables', 'processmaker')]; $elt['allowed_values'] = [__('YYY is to be replaced by any array variables', 'processmaker')];
$elt['foreach'] = true; $elt['foreach'] = true;
} }
if ($tag == '1darray.ZZZ.key') { if ($tag == '1darray.ZZZ.key') {
$elt['allowed_values'] = [__('ZZZ is to be replaced by any assoc array variables (1-dimension array with key/value pairs)', 'processmaker')]; $elt['allowed_values'] = [__('ZZZ is to be replaced by any assoc array variables (1-dimension array with key/value pairs)', 'processmaker')];
} }
$this->addTagToList($elt); $this->addTagToList($elt);
} }
asort($this->tag_descriptions); asort($this->tag_descriptions);
} }
/** /**
* Get all data needed for template processing * Get all data needed for template processing
**/ **/
public function addDataForTemplate($event, $options = []) { public function addDataForTemplate($event, $options = []) {
global $CFG_GLPI, $PM_DB; global $CFG_GLPI, $PM_DB;
$excluded = ['_VAR_CHANGED_', $excluded = ['_VAR_CHANGED_',
'PIN', 'PIN',
'APPLICATION', 'APPLICATION',
'PROCESS', 'PROCESS',
'TASK', 'TASK',
'INDEX', 'INDEX',
'USER_LOGGED', 'USER_LOGGED',
'USR_USERNAME', 'USR_USERNAME',
'APP_NUMBER', 'APP_NUMBER',
'GLPI_.*', 'GLPI_.*',
'SYS_.*' 'SYS_.*'
]; ];
$process = new PluginProcessmakerProcess; $process = new PluginProcessmakerProcess;
$process->getFromDB($options['case']->fields['plugin_processmaker_processes_id']); $process->getFromDB($options['case']->fields['plugin_processmaker_processes_id']);
$taskcat_id = $process->fields['taskcategories_id']; $taskcat_id = $process->fields['taskcategories_id'];
// get case variable values // get case variable values
$res = $PM_DB->query("SELECT APP_DATA, APP_TITLE, APP_DESCRIPTION FROM APPLICATION WHERE APP_NUMBER = ".$options['case']->fields['id']); $res = $PM_DB->query("SELECT APP_DATA, APP_TITLE, APP_DESCRIPTION FROM APPLICATION WHERE APP_NUMBER = ".$options['case']->fields['id']);
if ($res && $PM_DB->numrows($res) == 1) { if ($res && $PM_DB->numrows($res) == 1) {
// get all the case variables from $PM_DB // get all the case variables from $PM_DB
$caserow = $PM_DB->fetch_assoc($res); $caserow = $PM_DB->fetchAssoc($res);
$case_variables = unserialize($caserow['APP_DATA']); $case_variables = unserialize($caserow['APP_DATA']);
$excluded_re = '/^(' . implode('|', $excluded) . ')$/u'; $excluded_re = '/^(' . implode('|', $excluded) . ')$/u';
foreach ($case_variables as $key => $val) { foreach ($case_variables as $key => $val) {
if (!preg_match($excluded_re, $key)) { if (!preg_match($excluded_re, $key)) {
if (is_array($val)) { if (is_array($val)) {
// add numberof for count of rows // add numberof for count of rows
$this->data["##array.numberof$key##"] = count($val); $this->data["##array.numberof$key##"] = count($val);
// get the keys/vals of the sub-array // get the keys/vals of the sub-array
foreach ($val as $attribute => $row) { foreach ($val as $attribute => $row) {
if (is_array($row)) { if (is_array($row)) {
$index = isset($this->data["array.$key"]) ? count($this->data["array.$key"]) : 0; $index = isset($this->data["array.$key"]) ? count($this->data["array.$key"]) : 0;
foreach ($row as $col_name => $col_val) { foreach ($row as $col_name => $col_val) {
$this->data["array.$key"][$index]["##array.$key.$col_name##"] = $col_val; $this->data["array.$key"][$index]["##array.$key.$col_name##"] = $col_val;
$this->data["##lang.array.$key.$col_name##"] = $col_name; $this->data["##lang.array.$key.$col_name##"] = $col_name;
} }
} else { } else {
$this->data["1darray.$key"]["##array.$key.$attribute##"] = $row; $this->data["1darray.$key"]["##array.$key.$attribute##"] = $row;
$this->data["##lang.1darray.$key.$attribute##"] = $attribute; $this->data["##lang.1darray.$key.$attribute##"] = $attribute;
} }
} }
} else { } else {
$this->data["##var.$key##"] = $val; $this->data["##var.$key##"] = $val;
$this->data["##lang.var.$key##"] = $key; $this->data["##lang.var.$key##"] = $key;
} }
} }
} }
$this->data['##case.title##'] = $caserow['APP_TITLE']; $this->data['##case.title##'] = $caserow['APP_TITLE'];
$this->data['##case.description##'] = $caserow['APP_DESCRIPTION']; $this->data['##case.description##'] = $caserow['APP_DESCRIPTION'];
} }
// case id // case id
$this->data['##case.id##'] = $options['case']->fields['id']; $this->data['##case.id##'] = $options['case']->fields['id'];
// case URL // case URL
$this->data['##case.url##'] = $this->formatURL($options['additionnaloption']['usertype'], $this->data['##case.url##'] = $this->formatURL($options['additionnaloption']['usertype'],
urlencode(urlencode($CFG_GLPI["url_base"] . urlencode(urlencode($CFG_GLPI["url_base"] .
PluginProcessmakerCase::getFormURLWithID($options['case']->fields['id'], false)))); PluginProcessmakerCase::getFormURLWithID($options['case']->fields['id'], false))));
// parent task information: meta data on process // parent task information: meta data on process
// will get parent of task which is the process task category // will get parent of task which is the process task category
$tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name'); $tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name');
$tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment'); $tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment');
// process title // process title
$this->data['##process.categoryid##'] = $taskcat_id; $this->data['##process.categoryid##'] = $taskcat_id;
$this->data['##process.category##'] = $tmp_taskcatinfo['name']; $this->data['##process.category##'] = $tmp_taskcatinfo['name'];
$this->data['##process.categorycomment##'] = $tmp_taskcatinfo['comment']; $this->data['##process.categorycomment##'] = $tmp_taskcatinfo['comment'];
// add information about item that hosts the case // add information about item that hosts the case
$item = new $options['case']->fields['itemtype']; $item = new $options['case']->fields['itemtype'];
$item->getFromDB($options['case']->fields['items_id']); $item->getFromDB($options['case']->fields['items_id']);
$this->data['##item.type##'] = $item->getTypeName(1); $this->data['##item.type##'] = $item->getTypeName(1);
$this->data['##item.id##'] = sprintf("%07d", $options['case']->fields['items_id']); // to have items_id with 7 digits with leading 0 $this->data['##item.id##'] = sprintf("%07d", $options['case']->fields['items_id']); // to have items_id with 7 digits with leading 0
$this->data['##item.url##'] = $this->formatURL($options['additionnaloption']['usertype'], $this->data['##item.url##'] = $this->formatURL($options['additionnaloption']['usertype'],
urlencode(urlencode($CFG_GLPI["url_base"] . urlencode(urlencode($CFG_GLPI["url_base"] .
$item::getFormURLWithID($options['case']->fields['items_id'], false)))); $item::getFormURLWithID($options['case']->fields['items_id'], false))));
$this->data['##item.title##'] = HTML::entities_deep($item->fields['name']); $this->data['##item.title##'] = HTML::entities_deep($item->fields['name']);
// add labels to tags that are not set // add labels to tags that are not set
$this->getTags(); $this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->data[$tag])) { if (!isset($this->data[$tag])) {
$this->data[$tag] = $values['label']; $this->data[$tag] = $values['label'];
} }
} }
} }
/** /**
* Get header to add to content * Get header to add to content
**/ **/
function getContentHeader() { function getContentHeader() {
if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL
&& MailCollector::getNumberOfActiveMailCollectors() && MailCollector::countActiveCollectors()
) { && $this->allowResponse()
return NotificationTargetTicket::HEADERTAG.' '.__('To answer by email, write above this line').' '. ) {
NotificationTargetTicket::HEADERTAG; return NotificationTargetTicket::HEADERTAG.' '.__('To answer by email, write above this line').' '.
} NotificationTargetTicket::HEADERTAG;
}
return '';
} return '';
}
/**
* Get footer to add to content /**
**/ * Get footer to add to content
function getContentFooter() { **/
function getContentFooter() {
if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL
&& MailCollector::getNumberOfActiveMailCollectors() if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL
) { && MailCollector::countActiveCollectors()
return NotificationTargetTicket::FOOTERTAG.' '.__('To answer by email, write under this line').' '. && $this->allowResponse()
NotificationTargetTicket::FOOTERTAG; ) {
} return NotificationTargetTicket::FOOTERTAG.' '.__('To answer by email, write under this line').' '.
NotificationTargetTicket::FOOTERTAG;
return ''; }
}
return '';
}
} }

View File

@@ -1,327 +1,343 @@
<?php <?php
/* /*
* @version $Id: notificationtargettaskcategory.class.php tomolimo $ * @version $Id: notificationtargettaskcategory.class.php tomolimo $
------------------------------------------------------------------------- -------------------------------------------------------------------------
*/ */
if (!defined('GLPI_ROOT')) { if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file"); die("Sorry. You can't access directly to this file");
} }
// Class NotificationTarget // Class NotificationTarget
class PluginProcessmakerNotificationTargetTask extends PluginProcessmakerNotificationTargetProcessmaker { class PluginProcessmakerNotificationTargetTask extends PluginProcessmakerNotificationTargetProcessmaker {
/** /**
* Summary of getDefaultEvents * Summary of getDefaultEvents
* @return array[] * @return array[]
*/ */
private static function getDefaultEvents() { private static function getDefaultEvents() {
return ['task_add' => ['event' => 'task_add_', 'label' => __('Task add'), 'glpi' => 'add_task'], return ['task_add' => ['event' => 'task_add_', 'label' => __('Task add'), 'glpi' => 'add_task'],
'task_reassign' => ['event' => 'task_reassign_', 'label' => __('Task re-assign'), 'glpi' => 'update_task'], 'task_reassign' => ['event' => 'task_reassign_', 'label' => __('Task re-assign'), 'glpi' => 'update_task'],
'task_unclaim' => ['event' => 'task_unclaim_', 'label' => __('Task un-claim'), 'glpi' => 'update_task'], 'task_unclaim' => ['event' => 'task_unclaim_', 'label' => __('Task un-claim'), 'glpi' => 'update_task'],
'task_done' => ['event' => 'task_done_', 'label' => __('Task done'), 'glpi' => 'update_task'], 'task_done' => ['event' => 'task_done_', 'label' => __('Task done'), 'glpi' => 'update_task'],
'task_reminder' => ['event' => 'task_reminder_', 'label' => __('Task reminder'), 'glpi' => 'update_task'] 'task_reminder' => ['event' => 'task_reminder_', 'label' => __('Task reminder'), 'glpi' => 'update_task']
]; ];
} }
/** /**
* Summary of getDefaultGLPIEvents * Summary of getDefaultGLPIEvents
* Will return the GLPI default task event matching a self type * Will return the GLPI default task event matching a self type
* @param string $type * @param string $type
* @return string * @return string
*/ */
static function getDefaultGLPIEvents($type) { static function getDefaultGLPIEvents($type) {
$events = self::getDefaultEvents(); $events = self::getDefaultEvents();
return $events[$type]['glpi']; return $events[$type]['glpi'];
} }
/** /**
* Summary of getNotification * Summary of getNotification
* @param mixed $evt * @param mixed $evt
* @param mixed $taskcat * @param mixed $taskcat
* @param mixed $entity * @param mixed $entity
* @return array * @return array
*/ */
static function getNotifications($evt, $taskcat, $entity) { static function getNotifications($evt, $taskcat, $entity) {
// search if at least one active notification is existing for that pm task with that event 'task_update_'.$glpi_task->fields['taskcategories_id'] // search if at least one active notification is existing for that pm task with that event 'task_update_'.$glpi_task->fields['taskcategories_id']
$defaultEvents = self::getDefaultEvents(); $defaultEvents = self::getDefaultEvents();
$event = $defaultEvents[$evt]['event'].$taskcat; $event = $defaultEvents[$evt]['event'].$taskcat;
$dbu = new DbUtils; $dbu = new DbUtils;
$crit = $dbu->getEntitiesRestrictCriteria(Notification::getTable(), 'entities_id', $entity, true); $crit = $dbu->getEntitiesRestrictCriteria(Notification::getTable(), 'entities_id', $entity, true);
return ['event' => $event, 'notifications' => $dbu->getAllDataFromTable(Notification::getTable(), ['itemtype' => 'PluginProcessmakerTask', 'event' => $event, 'is_active' => 1, $crit])]; return ['event' => $event, 'notifications' => $dbu->getAllDataFromTable(Notification::getTable(), ['itemtype' => 'PluginProcessmakerTask', 'event' => $event, 'is_active' => 1, $crit])];
} }
/** /**
* Summary of getEvents * Summary of getEvents
* @return string[] * @return string[]
*/ */
public function getEvents() { public function getEvents() {
global $DB; global $DB;
$actions = []; $actions = [];
$defaultEvents = self::getDefaultEvents(); $defaultEvents = self::getDefaultEvents();
$table = PluginProcessmakerTaskCategory::getTable(); $table = PluginProcessmakerTaskCategory::getTable();
$ptable = PluginProcessmakerProcess::getTable(); $ptable = PluginProcessmakerProcess::getTable();
$query = "SELECT $table.taskcategories_id AS taskcat, $ptable.taskcategories_id AS ptaskcat FROM $table $query = "SELECT $table.taskcategories_id AS taskcat, $ptable.taskcategories_id AS ptaskcat FROM $table
LEFT JOIN $ptable ON $ptable.id=$table.plugin_processmaker_processes_id"; LEFT JOIN $ptable ON $ptable.id=$table.plugin_processmaker_processes_id";
$ptaskcats = []; $ptaskcats = [];
$temp = new TaskCategory; $temp = new TaskCategory;
foreach ($DB->request($query) as $row) { foreach ($DB->request($query) as $row) {
if (!isset($ptaskcats[$row['ptaskcat']])) { if (!isset($ptaskcats[$row['ptaskcat']])) {
$temp->getFromDB($row['ptaskcat']); $temp->getFromDB($row['ptaskcat']);
$ptaskcats[$row['ptaskcat']] = $temp->fields['name']; $ptaskcats[$row['ptaskcat']] = $temp->fields['name'];
} }
$temp->getFromDB($row['taskcat']); $temp->getFromDB($row['taskcat']);
foreach($defaultEvents as $events) { foreach($defaultEvents as $events) {
$actions[$events['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $events['label']; $actions[$events['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $events['label'];
} }
} }
return $actions; return $actions;
} }
/** /**
* Get all data needed for template processing * Get all data needed for template processing
**/ **/
public function addDataForTemplate($event, $options = []) { public function addDataForTemplate($event, $options = []) {
global $PM_DB, $CFG_GLPI; global $PM_DB, $CFG_GLPI;
if (!isset($options['case']) || $options['case'] == null) { if (!isset($options['case']) || $options['case'] == null) {
$mycase = new PluginProcessmakerCase; $mycase = new PluginProcessmakerCase;
$mycase->getFromDB($options['plugin_processmaker_cases_id']); $mycase->getFromDB($options['plugin_processmaker_cases_id']);
$options['case'] = $mycase; $options['case'] = $mycase;
} }
parent::addDataForTemplate($event, $options); parent::addDataForTemplate($event, $options);
$events = self::getDefaultEvents(); $events = self::getDefaultEvents();
$locevent = explode('_', $event); $locevent = explode('_', $event);
$baseevent = $locevent[0].'_'.$locevent[1]; $baseevent = $locevent[0].'_'.$locevent[1];
$taskcat_id = $locevent[2]; $taskcat_id = $locevent[2];
// task action: add, update or done // task action: add, update or done
$this->data['##task.action##'] = $events[$baseevent]['label']; $this->data['##task.action##'] = $events[$baseevent]['label'];
// task category information: meta data on task // task category information: meta data on task
$tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name'); $tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name');
$tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment'); $tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment');
$this->data['##task.categoryid##'] = $taskcat_id; $this->data['##task.categoryid##'] = $taskcat_id;
$this->data['##task.category##'] = $tmp_taskcatinfo['name']; $this->data['##task.category##'] = $tmp_taskcatinfo['name'];
$this->data['##task.categorycomment##'] = $tmp_taskcatinfo['comment']; $this->data['##task.categorycomment##'] = $tmp_taskcatinfo['comment'];
// task information // task information
$taskobj = $this->obj; $taskobj = $this->obj;
// del index // del index
$this->data['##task.delindex##'] = $taskobj->fields['del_index']; $this->data['##task.delindex##'] = $taskobj->fields['del_index'];
// is private? // is private?
$this->data['##task.isprivate##'] = Dropdown::getYesNo(false); $this->data['##task.isprivate##'] = Dropdown::getYesNo(false);
if ($taskobj->maybePrivate()) { if ($taskobj->maybePrivate()) {
$this->data['##task.isprivate##'] = Dropdown::getYesNo($taskobj->fields['is_private']); $this->data['##task.isprivate##'] = Dropdown::getYesNo($taskobj->fields['is_private']);
} }
// status // status
$this->data['##task.status##'] = Planning::getState($taskobj->fields['state']); $this->data['##task.status##'] = Planning::getState($taskobj->fields['state']);
// creation date // creation date
$this->data['##task.date##'] = Html::convDateTime($taskobj->fields['date_creation']); $this->data['##task.date##'] = Html::convDateTime($taskobj->fields['date_creation']);
// update date // update date
$this->data['##task.update##'] = Html::convDateTime($taskobj->fields['date_mod']); $this->data['##task.update##'] = Html::convDateTime($taskobj->fields['date_mod']);
// content: don't know if this could be interesting // content: don't know if this could be interesting
$this->data['##task.description##'] = $taskobj->fields['content']; $this->data['##task.description##'] = $taskobj->fields['content'];
// task creator // task creator
// should always be Process Maker user // should always be Process Maker user
$dbu = new DbUtils(); $dbu = new DbUtils();
$this->data['##task.author##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id'])); $this->data['##task.author##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id']));
// task editor // task editor
$this->data['##task.lastupdater##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_editor'])); $this->data['##task.lastupdater##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_editor']));
// task technician // task technician
$this->data['##task.user##'] = ''; $this->data['##task.user##'] = '';
$this->data['##task.user.login##'] = ''; // by default $this->data['##task.user.login##'] = ''; // by default
$tech = new User; $tech = new User;
if ($taskobj->fields['users_id_tech'] > 0 if ($taskobj->fields['users_id_tech'] > 0
&& $tech->getFromDB($taskobj->fields['users_id_tech'])) { && $tech->getFromDB($taskobj->fields['users_id_tech'])) {
$this->data['##task.user##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_tech'])); $this->data['##task.user##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_tech']));
$this->data['##task.user.login##'] = $tech->fields['name']; $this->data['##task.user.login##'] = $tech->fields['name'];
} }
$oldtech = new User; $oldtech = new User;
if (isset($options['old_users_id_tech']) if (isset($options['old_users_id_tech'])
&& $options['old_users_id_tech'] > 0 && $options['old_users_id_tech'] > 0
&& $oldtech->getFromDB($options['old_users_id_tech'])) { && $oldtech->getFromDB($options['old_users_id_tech'])) {
$this->data['##task.former.user##'] = Html::clean($dbu->getUserName($options['old_users_id_tech'])); $this->data['##task.former.user##'] = Html::clean($dbu->getUserName($options['old_users_id_tech']));
$this->data['##task.former.user.login##'] = $oldtech->fields['name']; $this->data['##task.former.user.login##'] = $oldtech->fields['name'];
} }
// task group technician // task group technician
$this->data['##task.group##'] = Html::clean(Toolbox::clean_cross_side_scripting_deep(Dropdown::getDropdownName("glpi_groups", $taskobj->fields['groups_id_tech'])), true, 2, false); $this->data['##task.group##'] = Html::clean(Toolbox::clean_cross_side_scripting_deep(Dropdown::getDropdownName("glpi_groups", $taskobj->fields['groups_id_tech'])), true, 2, false);
// task planning // task planning
$this->data['##task.begin##'] = ''; $this->data['##task.begin##'] = '';
$this->data['##task.end##'] = ''; $this->data['##task.end##'] = '';
if (!is_null($taskobj->fields['begin'])) { if (!is_null($taskobj->fields['begin'])) {
$this->data['##task.begin##'] = Html::convDateTime($taskobj->fields['begin']); $this->data['##task.begin##'] = Html::convDateTime($taskobj->fields['begin']);
$this->data['##task.end##'] = Html::convDateTime($taskobj->fields['end']); $this->data['##task.end##'] = Html::convDateTime($taskobj->fields['end']);
} }
// task duration // task duration
$this->data['##task.time##'] = Html::timestampToString($taskobj->fields['actiontime'], false); $this->data['##task.time##'] = Html::timestampToString($taskobj->fields['actiontime'], false);
// add labels to tags that are not set // add labels to tags that are not set
$this->getTags(); $this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->data[$tag])) { if (!isset($this->data[$tag])) {
$this->data[$tag] = $values['label']; $this->data[$tag] = $values['label'];
} }
} }
} }
/** /**
* Summary of getTags * Summary of getTags
*/ */
public function getTags() { public function getTags() {
parent::getTags(); parent::getTags();
$tags = ['task.action' => __('Task action', 'processmaker'), $tags = ['task.action' => __('Task action', 'processmaker'),
'task.author' => __('Writer'), 'task.author' => __('Writer'),
'task.isprivate' => __('Private'), 'task.isprivate' => __('Private'),
'task.date' => __('Opening date'), 'task.date' => __('Opening date'),
'task.description' => __('Description'), 'task.description' => __('Description'),
'task.categoryid' => __('Category id'), 'task.categoryid' => __('Category id'),
'task.category' => __('Category'), 'task.category' => __('Category'),
'task.categorycomment' => __('Category comment'), 'task.categorycomment' => __('Category comment'),
'task.time' => __('Total duration'), 'task.time' => __('Total duration'),
'task.user' => __('User assigned to task'), 'task.user' => __('User assigned to task'),
'task.user.login' => __('User login assigned to task'), 'task.user.login' => __('User login assigned to task'),
'task.former.user' => __('Former user assigned to task'), 'task.former.user' => __('Former user assigned to task'),
'task.former.user.login' => __('Former user login assigned to task'), 'task.former.user.login' => __('Former user login assigned to task'),
'task.group' => __('Group assigned to task'), 'task.group' => __('Group assigned to task'),
'task.begin' => __('Start date'), 'task.begin' => __('Start date'),
'task.end' => __('End date'), 'task.end' => __('End date'),
'task.status' => __('Status'), 'task.status' => __('Status'),
'task.lastupdater' => __('Last updater'), 'task.lastupdater' => __('Last updater'),
'task.update' => __('Last update'), 'task.update' => __('Last update'),
'task.delindex' => __('Delegation index') 'task.delindex' => __('Delegation index')
]; ];
foreach ($tags as $tag => $label) { foreach ($tags as $tag => $label) {
$elt= ['tag' => $tag, $elt= ['tag' => $tag,
'label' => $label, 'label' => $label,
'value' => true]; 'value' => true];
$this->addTagToList($elt); $this->addTagToList($elt);
} }
asort($this->tag_descriptions); asort($this->tag_descriptions);
} }
/** /**
* Summary of addAdditionalTargets * Summary of addAdditionalTargets
* @param mixed $event * @param mixed $event
*/ */
function addAdditionalTargets($event = '') { function addAdditionalTargets($event = '') {
$this->addTarget(Notification::TASK_ASSIGN_TECH, __('Technician in charge of the task')); $this->addTarget(Notification::TASK_ASSIGN_TECH, __('Technician in charge of the task'));
$this->addTarget(Notification::TASK_ASSIGN_GROUP, __('Group in charge of the task')); $this->addTarget(Notification::TASK_ASSIGN_GROUP, __('Group in charge of the task'));
$this->addTarget(Notification::OBSERVER_GROUP, __('Watcher group')); $this->addTarget(Notification::OBSERVER_GROUP, __('Watcher group'));
$this->addTarget(Notification::OBSERVER, __('Watcher')); $this->addTarget(Notification::OBSERVER, __('Watcher'));
$this->addTarget(Notification::AUTHOR, __('Requester'), PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE); $this->addTarget(Notification::AUTHOR, __('Requester'), PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE);
if (strpos($event, 'task_update_') === 0) { if (strpos($event, 'task_reassign_') === 0) {
$this->addTarget(Notification::OLD_TECH_IN_CHARGE, $this->addTarget(Notification::OLD_TECH_IN_CHARGE,
__('Former technician in charge of the task')); __('Former technician in charge of the task'));
} }
} }
/** /**
* Summary of addSpecificTargets * Summary of addSpecificTargets
* @param mixed $data * @param mixed $data
* @param mixed $options * @param mixed $options
*/ */
function addSpecificTargets($data, $options) { function addSpecificTargets($data, $options) {
$obj = $this->obj; $obj = $this->obj;
$this->obj = $options['obj']; $this->obj = $options['obj'];
switch ($data['type']) { switch ($data['type']) {
case PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE : case PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE :
switch ($data['items_id']) { switch ($data['items_id']) {
//Send to the requester of the ITIL object //Send to the requester of the ITIL object
case Notification::AUTHOR : case Notification::AUTHOR :
$this->addItemAuthor(); $this->addItemAuthor();
break; break;
} }
break; break;
case Notification::USER_TYPE : case Notification::USER_TYPE :
switch ($data['items_id']) { switch ($data['items_id']) {
//Notification to the ITIL object's observer group //Notification to the ITIL object's observer group
case Notification::OBSERVER_GROUP : case Notification::OBSERVER_GROUP :
$this->addLinkedGroupByType(CommonITILActor::OBSERVER); $this->addLinkedGroupByType(CommonITILActor::OBSERVER);
break; break;
//Notification to the ITIL object's observer user //Notification to the ITIL object's observer user
case Notification::OBSERVER : case Notification::OBSERVER :
$this->addLinkedUserByType(CommonITILActor::OBSERVER); $this->addLinkedUserByType(CommonITILActor::OBSERVER);
break; break;
//Send to the ITIL object followup author //Send to the ITIL object followup author
case Notification::TASK_ASSIGN_TECH : case Notification::TASK_ASSIGN_TECH :
$this->addTaskAssignUser($options); $this->addTaskAssignUser($options);
break; break;
//Send to the ITIL object task group assigned //Send to the ITIL object task group assigned
case Notification::TASK_ASSIGN_GROUP : case Notification::TASK_ASSIGN_GROUP :
$this->addTaskAssignGroup($options); $this->addTaskAssignGroup($options);
break; break;
//Send to the technician previously in charge of the task (before re-assignment) //Send to the technician previously in charge of the task (before re-assignment)
case Notification::OLD_TECH_IN_CHARGE : case Notification::OLD_TECH_IN_CHARGE :
$this->addOldAssignTechnician($options); $this->addOldAssignTechnician($options);
break; break;
} }
} }
$this->obj = $obj; $this->obj = $obj;
} }
/** /**
* Summary of addOldAssignTechnician * Summary of addOldAssignTechnician
* @param $options * @param $options
*/ */
function addOldAssignTechnician($options = []) { function addOldAssignTechnician($options = []) {
global $DB; //global $DB;
global $CFG_GLPI;
// In case of delete task pass user id
if (isset($options['old_users_id_tech'])) { if (isset($options['old_users_id_tech'])) {
$query = $this->getDistinctUserSql()."
FROM `glpi_users` ". $user = new User();
$this->getProfileJoinSql()." if ($user->getFromDB($options['old_users_id_tech'])) {
WHERE `glpi_users`.`id` = '".$options['old_users_id_tech']."'";
$author_email = UserEmail::getDefaultForUser($user->fields['id']);
foreach ($DB->request($query) as $data) { $author_lang = $user->fields["language"];
$this->addToRecipientsList($data); $author_id = $user->fields['id'];
}
} if (empty($author_lang)) {
} $author_lang = $CFG_GLPI["language"];
}
} if (empty($author_id)) {
$author_id = -1;
}
$user = [
'language' => $author_lang,
'users_id' => $author_id
];
if ($this->isMailMode()) {
$user['email'] = $author_email;
}
$this->addToRecipientsList($user);
}
}
}
}

View File

@@ -121,7 +121,7 @@ class PluginProcessmakerTask extends CommonITILTask
$events = []; $events = [];
if (isset($params['start'])) { if (isset($params['start'])) {
$params['begin'] = '2000-01-01 00:00:00'; $params['begin'] = $params['start']; //'2000-01-01 00:00:00';
if ($params['type'] == 'group') { if ($params['type'] == 'group') {
$params['who_group'] = $params['who']; $params['who_group'] = $params['who'];
$params['whogroup'] = $params['who']; $params['whogroup'] = $params['who'];

View File

@@ -41,7 +41,7 @@
<compatibility>9.4</compatibility> <compatibility>9.4</compatibility>
</version> </version>
<version> <version>
<num>4.0.5</num> <num>4.0.8</num>
<compatibility>9.5</compatibility> <compatibility>9.5</compatibility>
</version> </version>
</versions> </versions>

View File

@@ -1,6 +1,6 @@
<?php <?php
define('PROCESSMAKER_VERSION', '4.0.5'); define('PROCESSMAKER_VERSION', '4.0.8');
// used for case cancellation // used for case cancellation
define("CANCEL", 256); define("CANCEL", 256);