diff --git a/inc/notificationtargetcase.class.php b/inc/notificationtargetcase.class.php index 7e74e32..d42fb16 100644 --- a/inc/notificationtargetcase.class.php +++ b/inc/notificationtargetcase.class.php @@ -1,120 +1,137 @@ - __('Send email', 'processmaker')]; - } - - - /** - * Summary of addAdditionalTargets - * @param mixed $event - */ - function addAdditionalTargets($event = '') { - $this->notification_targets = []; - $this->notification_targets_labels = []; - $this->addTarget(self::RECIPIENTS, __('eMail recipients', 'processmaker'), self::EMAIL_RECIPIENTS); - } - - - /** - * Summary of addSpecificTargets - * @param mixed $data - * @param mixed $options - */ - function addSpecificTargets($data, $options) { - - // test if we are in the good notification - // then in this case add the targets from the ['recipients'] - if (isset($options['glpi_send_email'])) { - // 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']; - - foreach($options['glpi_send_email'] as $params) { - if (isset($params['notifications_id']) - && $params['notifications_id'] == $data['notifications_id']) { - //Look for all targets whose type is Notification::ITEM_USER - switch ($data['type']) { - case self::EMAIL_RECIPIENTS: - - switch ($data['items_id']) { - - case self::RECIPIENTS : - $this->addUsers($params); - break; - } - } - } - } - } - - // if no target is added to $this, then the notification will not be sent. - - } - - - /** - * Add users from $options['glpi_send_email']['to'] - * - * @param array $email_param should contain 'recipients' - * - * @return void - */ - function addUsers($email_param = []) { - global $DB, $CFG_GLPI; - - if (isset($email_param['recipients'])) { - $id_list = []; // for users with ids - $email_list = []; // for standalone emails - - // normalize into array the recipient list - $email_param['recipients'] = is_array($email_param['recipients']) ? $email_param['recipients'] : [$email_param['recipients']]; - foreach ($email_param['recipients'] as $user) { - if (is_numeric($user)) { - $id_list[] = intval($user); - } else { - $email_list[] = $user; - } - } - - $query = $this->getDistinctUserSql()." - FROM `glpi_users` ". - $this->getProfileJoinSql()." - WHERE `glpi_users`.`id` IN (".implode(',', $id_list).")"; - - foreach ($DB->request($query) as $data) { - $this->addToRecipientsList($data); - } - - foreach($email_list as $email){ - $this->addToRecipientsList([ - 'email' => $email, - 'language' => $CFG_GLPI["language"], - 'users_id' => -1 - ]); - } - } - } - -} + __('Send email', 'processmaker')]; + } + + + /** + * Summary of addAdditionalTargets + * @param mixed $event + */ + function addAdditionalTargets($event = '') { + $this->notification_targets = []; + $this->notification_targets_labels = []; + $this->addTarget(self::RECIPIENTS, __('eMail recipients', 'processmaker'), self::EMAIL_RECIPIENTS); + } + + + /** + * Summary of addSpecificTargets + * @param mixed $data + * @param mixed $options + */ + function addSpecificTargets($data, $options) { + + // test if we are in the good notification + // then in this case add the targets from the ['recipients'] + if (isset($options['glpi_send_email'])) { + // 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']; + + foreach($options['glpi_send_email'] as $params) { + if (isset($params['notifications_id']) + && $params['notifications_id'] == $data['notifications_id']) { + //Look for all targets whose type is Notification::ITEM_USER + switch ($data['type']) { + case self::EMAIL_RECIPIENTS: + + switch ($data['items_id']) { + + case self::RECIPIENTS : + $this->addUsers($params); + break; + } + } + } + } + } + + // if no target is added to $this, then the notification will not be sent. + + } + + + /** + * Add users from $email_param['recipients'] + * + * @param array $email_param should contain 'recipients' + * + * @return void + */ + function addUsers($email_param = []) { + global $DB, $CFG_GLPI; + + if (isset($email_param['recipients'])) { + $id_list = []; // for users with ids + $email_list = []; // for standalone emails + + // normalize into array the recipient list + $email_param['recipients'] = is_array($email_param['recipients']) ? $email_param['recipients'] : [$email_param['recipients']]; + foreach ($email_param['recipients'] as $user) { + if (is_numeric($user)) { + $id_list[] = intval($user); + } else { + $email_list[] = $user; + } + } + + $user = new User(); + foreach ($id_list as $users_id) { + if ($user->getFromDB($users_id)) { + + $author_email = UserEmail::getDefaultForUser($user->fields['id']); + $author_lang = $user->fields["language"]; + $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); + } + } + + foreach($email_list as $email){ + $this->addToRecipientsList([ + 'email' => $email, + 'language' => $CFG_GLPI["language"], + 'users_id' => -1 + ]); + } + } + } + +} diff --git a/inc/notificationtargetprocessmaker.class.php b/inc/notificationtargetprocessmaker.class.php index cb11f33..fb23e74 100644 --- a/inc/notificationtargetprocessmaker.class.php +++ b/inc/notificationtargetprocessmaker.class.php @@ -1,225 +1,227 @@ - __('Process category', 'processmaker'), - 'process.categoryid' => __('Process category id', 'processmaker'), - 'process.categorycomment' => __('Process category comment', 'processmaker'), - 'case.id' => __('Case id', 'processmaker'), - 'case.title' => __('Case title', 'processmaker'), - 'case.description' => __('Case description', 'processmaker'), - 'case.url' => __('Case URL'), - 'var.XXX' => __('Case variable \'XXX\'', 'processmaker'), - 'array.YYY' => __('List of values in \'YYY\' array', 'processmaker'), - 'array.numberofYYY' => __('Number of rows 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'), - 'item.type' => __('Item type', 'processmaker'), - 'item.id' => __('Item id', 'processmaker'), - 'item.url' => __('Item URL', 'processmaker'), - 'item.title' => __('Item title', 'processmaker') - ]; - - foreach ($tags as $tag => $label) { - $elt= ['tag' => $tag, - 'label' => $label, - 'value' => true]; - if ($tag == 'var.XXX') { - $elt['allowed_values'] = [__('XXX is to be replaced by any case variable names', 'processmaker')]; - } - if ($tag == 'array.YYY') { - $elt['allowed_values'] = [__('YYY is to be replaced by any array variables', 'processmaker')]; - $elt['foreach'] = true; - } - 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')]; - } - $this->addTagToList($elt); - } - - asort($this->tag_descriptions); - } - - - /** - * Get all data needed for template processing - **/ - public function addDataForTemplate($event, $options = []) { - global $CFG_GLPI, $PM_DB; - - $excluded = ['_VAR_CHANGED_', - 'PIN', - 'APPLICATION', - 'PROCESS', - 'TASK', - 'INDEX', - 'USER_LOGGED', - 'USR_USERNAME', - 'APP_NUMBER', - 'GLPI_.*', - 'SYS_.*' - ]; - - $process = new PluginProcessmakerProcess; - - $process->getFromDB($options['case']->fields['plugin_processmaker_processes_id']); - $taskcat_id = $process->fields['taskcategories_id']; - - // get case variable values - $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) { - // get all the case variables from $PM_DB - $caserow = $PM_DB->fetch_assoc($res); - $case_variables = unserialize($caserow['APP_DATA']); - $excluded_re = '/^(' . implode('|', $excluded) . ')$/u'; - foreach ($case_variables as $key => $val) { - if (!preg_match($excluded_re, $key)) { - if (is_array($val)) { - // add numberof for count of rows - $this->data["##array.numberof$key##"] = count($val); - // get the keys/vals of the sub-array - foreach ($val as $attribute => $row) { - if (is_array($row)) { - $index = isset($this->data["array.$key"]) ? count($this->data["array.$key"]) : 0; - foreach ($row as $col_name => $col_val) { - $this->data["array.$key"][$index]["##array.$key.$col_name##"] = $col_val; - $this->data["##lang.array.$key.$col_name##"] = $col_name; - } - } else { - $this->data["1darray.$key"]["##array.$key.$attribute##"] = $row; - $this->data["##lang.1darray.$key.$attribute##"] = $attribute; - } - } - } else { - $this->data["##var.$key##"] = $val; - $this->data["##lang.var.$key##"] = $key; - } - } - } - $this->data['##case.title##'] = $caserow['APP_TITLE']; - $this->data['##case.description##'] = $caserow['APP_DESCRIPTION']; - } - - // case id - $this->data['##case.id##'] = $options['case']->fields['id']; - - // case URL - $this->data['##case.url##'] = $this->formatURL($options['additionnaloption']['usertype'], - urlencode(urlencode($CFG_GLPI["url_base"] . - PluginProcessmakerCase::getFormURLWithID($options['case']->fields['id'], false)))); - // parent task information: meta data on process - // will get parent of task which is the process task category - $tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name'); - $tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment'); - // process title - $this->data['##process.categoryid##'] = $taskcat_id; - $this->data['##process.category##'] = $tmp_taskcatinfo['name']; - $this->data['##process.categorycomment##'] = $tmp_taskcatinfo['comment']; - - // add information about item that hosts the case - $item = new $options['case']->fields['itemtype']; - $item->getFromDB($options['case']->fields['items_id']); - $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.url##'] = $this->formatURL($options['additionnaloption']['usertype'], - urlencode(urlencode($CFG_GLPI["url_base"] . - $item::getFormURLWithID($options['case']->fields['items_id'], false)))); - $this->data['##item.title##'] = HTML::entities_deep($item->fields['name']); - - // add labels to tags that are not set - $this->getTags(); - foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { - if (!isset($this->data[$tag])) { - $this->data[$tag] = $values['label']; - } - } - } - - - /** - * Get header to add to content - **/ - function getContentHeader() { - - if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL - && MailCollector::getNumberOfActiveMailCollectors() - ) { - return NotificationTargetTicket::HEADERTAG.' '.__('To answer by email, write above this line').' '. - NotificationTargetTicket::HEADERTAG; - } - - return ''; - } - - - /** - * Get footer to add to content - **/ - function getContentFooter() { - - if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL - && MailCollector::getNumberOfActiveMailCollectors() - ) { - return NotificationTargetTicket::FOOTERTAG.' '.__('To answer by email, write under this line').' '. - NotificationTargetTicket::FOOTERTAG; - } - - return ''; - } - + __('Process category', 'processmaker'), + 'process.categoryid' => __('Process category id', 'processmaker'), + 'process.categorycomment' => __('Process category comment', 'processmaker'), + 'case.id' => __('Case id', 'processmaker'), + 'case.title' => __('Case title', 'processmaker'), + 'case.description' => __('Case description', 'processmaker'), + 'case.url' => __('Case URL'), + 'var.XXX' => __('Case variable \'XXX\'', 'processmaker'), + 'array.YYY' => __('List of values in \'YYY\' array', 'processmaker'), + 'array.numberofYYY' => __('Number of rows 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'), + 'item.type' => __('Item type', 'processmaker'), + 'item.id' => __('Item id', 'processmaker'), + 'item.url' => __('Item URL', 'processmaker'), + 'item.title' => __('Item title', 'processmaker') + ]; + + foreach ($tags as $tag => $label) { + $elt= ['tag' => $tag, + 'label' => $label, + 'value' => true]; + if ($tag == 'var.XXX') { + $elt['allowed_values'] = [__('XXX is to be replaced by any case variable names', 'processmaker')]; + } + if ($tag == 'array.YYY') { + $elt['allowed_values'] = [__('YYY is to be replaced by any array variables', 'processmaker')]; + $elt['foreach'] = true; + } + 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')]; + } + $this->addTagToList($elt); + } + + asort($this->tag_descriptions); + } + + + /** + * Get all data needed for template processing + **/ + public function addDataForTemplate($event, $options = []) { + global $CFG_GLPI, $PM_DB; + + $excluded = ['_VAR_CHANGED_', + 'PIN', + 'APPLICATION', + 'PROCESS', + 'TASK', + 'INDEX', + 'USER_LOGGED', + 'USR_USERNAME', + 'APP_NUMBER', + 'GLPI_.*', + 'SYS_.*' + ]; + + $process = new PluginProcessmakerProcess; + + $process->getFromDB($options['case']->fields['plugin_processmaker_processes_id']); + $taskcat_id = $process->fields['taskcategories_id']; + + // get case variable values + $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) { + // get all the case variables from $PM_DB + $caserow = $PM_DB->fetchAssoc($res); + $case_variables = unserialize($caserow['APP_DATA']); + $excluded_re = '/^(' . implode('|', $excluded) . ')$/u'; + foreach ($case_variables as $key => $val) { + if (!preg_match($excluded_re, $key)) { + if (is_array($val)) { + // add numberof for count of rows + $this->data["##array.numberof$key##"] = count($val); + // get the keys/vals of the sub-array + foreach ($val as $attribute => $row) { + if (is_array($row)) { + $index = isset($this->data["array.$key"]) ? count($this->data["array.$key"]) : 0; + foreach ($row as $col_name => $col_val) { + $this->data["array.$key"][$index]["##array.$key.$col_name##"] = $col_val; + $this->data["##lang.array.$key.$col_name##"] = $col_name; + } + } else { + $this->data["1darray.$key"]["##array.$key.$attribute##"] = $row; + $this->data["##lang.1darray.$key.$attribute##"] = $attribute; + } + } + } else { + $this->data["##var.$key##"] = $val; + $this->data["##lang.var.$key##"] = $key; + } + } + } + $this->data['##case.title##'] = $caserow['APP_TITLE']; + $this->data['##case.description##'] = $caserow['APP_DESCRIPTION']; + } + + // case id + $this->data['##case.id##'] = $options['case']->fields['id']; + + // case URL + $this->data['##case.url##'] = $this->formatURL($options['additionnaloption']['usertype'], + urlencode(urlencode($CFG_GLPI["url_base"] . + PluginProcessmakerCase::getFormURLWithID($options['case']->fields['id'], false)))); + // parent task information: meta data on process + // will get parent of task which is the process task category + $tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name'); + $tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment'); + // process title + $this->data['##process.categoryid##'] = $taskcat_id; + $this->data['##process.category##'] = $tmp_taskcatinfo['name']; + $this->data['##process.categorycomment##'] = $tmp_taskcatinfo['comment']; + + // add information about item that hosts the case + $item = new $options['case']->fields['itemtype']; + $item->getFromDB($options['case']->fields['items_id']); + $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.url##'] = $this->formatURL($options['additionnaloption']['usertype'], + urlencode(urlencode($CFG_GLPI["url_base"] . + $item::getFormURLWithID($options['case']->fields['items_id'], false)))); + $this->data['##item.title##'] = HTML::entities_deep($item->fields['name']); + + // add labels to tags that are not set + $this->getTags(); + foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { + if (!isset($this->data[$tag])) { + $this->data[$tag] = $values['label']; + } + } + } + + + /** + * Get header to add to content + **/ + function getContentHeader() { + + if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL + && MailCollector::countActiveCollectors() + && $this->allowResponse() + ) { + return NotificationTargetTicket::HEADERTAG.' '.__('To answer by email, write above this line').' '. + NotificationTargetTicket::HEADERTAG; + } + + return ''; + } + + + /** + * Get footer to add to content + **/ + function getContentFooter() { + + if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL + && MailCollector::countActiveCollectors() + && $this->allowResponse() + ) { + return NotificationTargetTicket::FOOTERTAG.' '.__('To answer by email, write under this line').' '. + NotificationTargetTicket::FOOTERTAG; + } + + return ''; + } + } \ No newline at end of file diff --git a/inc/notificationtargettask.class.php b/inc/notificationtargettask.class.php index 1deff80..1e34dda 100644 --- a/inc/notificationtargettask.class.php +++ b/inc/notificationtargettask.class.php @@ -1,327 +1,343 @@ - ['event' => 'task_add_', 'label' => __('Task add'), 'glpi' => 'add_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_done' => ['event' => 'task_done_', 'label' => __('Task done'), 'glpi' => 'update_task'], - 'task_reminder' => ['event' => 'task_reminder_', 'label' => __('Task reminder'), 'glpi' => 'update_task'] - ]; - } - - - /** - * Summary of getDefaultGLPIEvents - * Will return the GLPI default task event matching a self type - * @param string $type - * @return string - */ - static function getDefaultGLPIEvents($type) { - $events = self::getDefaultEvents(); - return $events[$type]['glpi']; - } - - - /** - * Summary of getNotification - * @param mixed $evt - * @param mixed $taskcat - * @param mixed $entity - * @return array - */ - 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'] - $defaultEvents = self::getDefaultEvents(); - $event = $defaultEvents[$evt]['event'].$taskcat; - $dbu = new DbUtils; - $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])]; - } - - - /** - * Summary of getEvents - * @return string[] - */ - public function getEvents() { - global $DB; - $actions = []; - - $defaultEvents = self::getDefaultEvents(); - - $table = PluginProcessmakerTaskCategory::getTable(); - $ptable = PluginProcessmakerProcess::getTable(); - $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"; - - $ptaskcats = []; - $temp = new TaskCategory; - foreach ($DB->request($query) as $row) { - if (!isset($ptaskcats[$row['ptaskcat']])) { - $temp->getFromDB($row['ptaskcat']); - $ptaskcats[$row['ptaskcat']] = $temp->fields['name']; - } - $temp->getFromDB($row['taskcat']); - - foreach($defaultEvents as $events) { - $actions[$events['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $events['label']; - } - } - - return $actions; - } - - - /** - * Get all data needed for template processing - **/ - public function addDataForTemplate($event, $options = []) { - global $PM_DB, $CFG_GLPI; - - if (!isset($options['case']) || $options['case'] == null) { - $mycase = new PluginProcessmakerCase; - $mycase->getFromDB($options['plugin_processmaker_cases_id']); - $options['case'] = $mycase; - } - parent::addDataForTemplate($event, $options); - - $events = self::getDefaultEvents(); - $locevent = explode('_', $event); - $baseevent = $locevent[0].'_'.$locevent[1]; - $taskcat_id = $locevent[2]; - - // task action: add, update or done - $this->data['##task.action##'] = $events[$baseevent]['label']; - - // task category information: meta data on task - $tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name'); - $tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment'); - $this->data['##task.categoryid##'] = $taskcat_id; - $this->data['##task.category##'] = $tmp_taskcatinfo['name']; - $this->data['##task.categorycomment##'] = $tmp_taskcatinfo['comment']; - - // task information - $taskobj = $this->obj; - - // del index - $this->data['##task.delindex##'] = $taskobj->fields['del_index']; - - // is private? - $this->data['##task.isprivate##'] = Dropdown::getYesNo(false); - if ($taskobj->maybePrivate()) { - $this->data['##task.isprivate##'] = Dropdown::getYesNo($taskobj->fields['is_private']); - } - // status - $this->data['##task.status##'] = Planning::getState($taskobj->fields['state']); - // creation date - $this->data['##task.date##'] = Html::convDateTime($taskobj->fields['date_creation']); - // update date - $this->data['##task.update##'] = Html::convDateTime($taskobj->fields['date_mod']); - // content: don't know if this could be interesting - $this->data['##task.description##'] = $taskobj->fields['content']; - - // task creator - // should always be Process Maker user - $dbu = new DbUtils(); - $this->data['##task.author##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id'])); - - // task editor - $this->data['##task.lastupdater##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_editor'])); - - // task technician - $this->data['##task.user##'] = ''; - $this->data['##task.user.login##'] = ''; // by default - $tech = new User; - if ($taskobj->fields['users_id_tech'] > 0 - && $tech->getFromDB($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']; - } - $oldtech = new User; - if (isset($options['old_users_id_tech']) - && $options['old_users_id_tech'] > 0 - && $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.login##'] = $oldtech->fields['name']; - } - - // 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); - - // task planning - $this->data['##task.begin##'] = ''; - $this->data['##task.end##'] = ''; - if (!is_null($taskobj->fields['begin'])) { - $this->data['##task.begin##'] = Html::convDateTime($taskobj->fields['begin']); - $this->data['##task.end##'] = Html::convDateTime($taskobj->fields['end']); - } - // task duration - $this->data['##task.time##'] = Html::timestampToString($taskobj->fields['actiontime'], false); - - // add labels to tags that are not set - $this->getTags(); - foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { - if (!isset($this->data[$tag])) { - $this->data[$tag] = $values['label']; - } - } - } - - - /** - * Summary of getTags - */ - public function getTags() { - - parent::getTags(); - - $tags = ['task.action' => __('Task action', 'processmaker'), - 'task.author' => __('Writer'), - 'task.isprivate' => __('Private'), - 'task.date' => __('Opening date'), - 'task.description' => __('Description'), - 'task.categoryid' => __('Category id'), - 'task.category' => __('Category'), - 'task.categorycomment' => __('Category comment'), - 'task.time' => __('Total duration'), - 'task.user' => __('User assigned to task'), - 'task.user.login' => __('User login assigned to task'), - 'task.former.user' => __('Former user assigned to task'), - 'task.former.user.login' => __('Former user login assigned to task'), - 'task.group' => __('Group assigned to task'), - 'task.begin' => __('Start date'), - 'task.end' => __('End date'), - 'task.status' => __('Status'), - 'task.lastupdater' => __('Last updater'), - 'task.update' => __('Last update'), - 'task.delindex' => __('Delegation index') - ]; - foreach ($tags as $tag => $label) { - $elt= ['tag' => $tag, - 'label' => $label, - 'value' => true]; - - $this->addTagToList($elt); - } - asort($this->tag_descriptions); - } - - - /** - * Summary of addAdditionalTargets - * @param mixed $event - */ - function addAdditionalTargets($event = '') { - - $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::OBSERVER_GROUP, __('Watcher group')); - $this->addTarget(Notification::OBSERVER, __('Watcher')); - - $this->addTarget(Notification::AUTHOR, __('Requester'), PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE); - - if (strpos($event, 'task_update_') === 0) { - $this->addTarget(Notification::OLD_TECH_IN_CHARGE, - __('Former technician in charge of the task')); - } - - } - - - /** - * Summary of addSpecificTargets - * @param mixed $data - * @param mixed $options - */ - function addSpecificTargets($data, $options) { - - $obj = $this->obj; - $this->obj = $options['obj']; - - switch ($data['type']) { - case PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE : - - switch ($data['items_id']) { - - //Send to the requester of the ITIL object - case Notification::AUTHOR : - $this->addItemAuthor(); - break; - } - break; - - case Notification::USER_TYPE : - - switch ($data['items_id']) { - - //Notification to the ITIL object's observer group - case Notification::OBSERVER_GROUP : - $this->addLinkedGroupByType(CommonITILActor::OBSERVER); - break; - - //Notification to the ITIL object's observer user - case Notification::OBSERVER : - $this->addLinkedUserByType(CommonITILActor::OBSERVER); - break; - - //Send to the ITIL object followup author - case Notification::TASK_ASSIGN_TECH : - $this->addTaskAssignUser($options); - break; - - //Send to the ITIL object task group assigned - case Notification::TASK_ASSIGN_GROUP : - $this->addTaskAssignGroup($options); - break; - - //Send to the technician previously in charge of the task (before re-assignment) - case Notification::OLD_TECH_IN_CHARGE : - $this->addOldAssignTechnician($options); - break; - - } - } - - $this->obj = $obj; - } - - - /** - * Summary of addOldAssignTechnician - * @param $options - */ - function addOldAssignTechnician($options = []) { - global $DB; - - // In case of delete task pass user id - if (isset($options['old_users_id_tech'])) { - $query = $this->getDistinctUserSql()." - FROM `glpi_users` ". - $this->getProfileJoinSql()." - WHERE `glpi_users`.`id` = '".$options['old_users_id_tech']."'"; - - foreach ($DB->request($query) as $data) { - $this->addToRecipientsList($data); - } - } - } - -} + ['event' => 'task_add_', 'label' => __('Task add'), 'glpi' => 'add_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_done' => ['event' => 'task_done_', 'label' => __('Task done'), 'glpi' => 'update_task'], + 'task_reminder' => ['event' => 'task_reminder_', 'label' => __('Task reminder'), 'glpi' => 'update_task'] + ]; + } + + + /** + * Summary of getDefaultGLPIEvents + * Will return the GLPI default task event matching a self type + * @param string $type + * @return string + */ + static function getDefaultGLPIEvents($type) { + $events = self::getDefaultEvents(); + return $events[$type]['glpi']; + } + + + /** + * Summary of getNotification + * @param mixed $evt + * @param mixed $taskcat + * @param mixed $entity + * @return array + */ + 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'] + $defaultEvents = self::getDefaultEvents(); + $event = $defaultEvents[$evt]['event'].$taskcat; + $dbu = new DbUtils; + $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])]; + } + + + /** + * Summary of getEvents + * @return string[] + */ + public function getEvents() { + global $DB; + $actions = []; + + $defaultEvents = self::getDefaultEvents(); + + $table = PluginProcessmakerTaskCategory::getTable(); + $ptable = PluginProcessmakerProcess::getTable(); + $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"; + + $ptaskcats = []; + $temp = new TaskCategory; + foreach ($DB->request($query) as $row) { + if (!isset($ptaskcats[$row['ptaskcat']])) { + $temp->getFromDB($row['ptaskcat']); + $ptaskcats[$row['ptaskcat']] = $temp->fields['name']; + } + $temp->getFromDB($row['taskcat']); + + foreach($defaultEvents as $events) { + $actions[$events['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $events['label']; + } + } + + return $actions; + } + + + /** + * Get all data needed for template processing + **/ + public function addDataForTemplate($event, $options = []) { + global $PM_DB, $CFG_GLPI; + + if (!isset($options['case']) || $options['case'] == null) { + $mycase = new PluginProcessmakerCase; + $mycase->getFromDB($options['plugin_processmaker_cases_id']); + $options['case'] = $mycase; + } + parent::addDataForTemplate($event, $options); + + $events = self::getDefaultEvents(); + $locevent = explode('_', $event); + $baseevent = $locevent[0].'_'.$locevent[1]; + $taskcat_id = $locevent[2]; + + // task action: add, update or done + $this->data['##task.action##'] = $events[$baseevent]['label']; + + // task category information: meta data on task + $tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name'); + $tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment'); + $this->data['##task.categoryid##'] = $taskcat_id; + $this->data['##task.category##'] = $tmp_taskcatinfo['name']; + $this->data['##task.categorycomment##'] = $tmp_taskcatinfo['comment']; + + // task information + $taskobj = $this->obj; + + // del index + $this->data['##task.delindex##'] = $taskobj->fields['del_index']; + + // is private? + $this->data['##task.isprivate##'] = Dropdown::getYesNo(false); + if ($taskobj->maybePrivate()) { + $this->data['##task.isprivate##'] = Dropdown::getYesNo($taskobj->fields['is_private']); + } + // status + $this->data['##task.status##'] = Planning::getState($taskobj->fields['state']); + // creation date + $this->data['##task.date##'] = Html::convDateTime($taskobj->fields['date_creation']); + // update date + $this->data['##task.update##'] = Html::convDateTime($taskobj->fields['date_mod']); + // content: don't know if this could be interesting + $this->data['##task.description##'] = $taskobj->fields['content']; + + // task creator + // should always be Process Maker user + $dbu = new DbUtils(); + $this->data['##task.author##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id'])); + + // task editor + $this->data['##task.lastupdater##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_editor'])); + + // task technician + $this->data['##task.user##'] = ''; + $this->data['##task.user.login##'] = ''; // by default + $tech = new User; + if ($taskobj->fields['users_id_tech'] > 0 + && $tech->getFromDB($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']; + } + $oldtech = new User; + if (isset($options['old_users_id_tech']) + && $options['old_users_id_tech'] > 0 + && $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.login##'] = $oldtech->fields['name']; + } + + // 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); + + // task planning + $this->data['##task.begin##'] = ''; + $this->data['##task.end##'] = ''; + if (!is_null($taskobj->fields['begin'])) { + $this->data['##task.begin##'] = Html::convDateTime($taskobj->fields['begin']); + $this->data['##task.end##'] = Html::convDateTime($taskobj->fields['end']); + } + // task duration + $this->data['##task.time##'] = Html::timestampToString($taskobj->fields['actiontime'], false); + + // add labels to tags that are not set + $this->getTags(); + foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { + if (!isset($this->data[$tag])) { + $this->data[$tag] = $values['label']; + } + } + } + + + /** + * Summary of getTags + */ + public function getTags() { + + parent::getTags(); + + $tags = ['task.action' => __('Task action', 'processmaker'), + 'task.author' => __('Writer'), + 'task.isprivate' => __('Private'), + 'task.date' => __('Opening date'), + 'task.description' => __('Description'), + 'task.categoryid' => __('Category id'), + 'task.category' => __('Category'), + 'task.categorycomment' => __('Category comment'), + 'task.time' => __('Total duration'), + 'task.user' => __('User assigned to task'), + 'task.user.login' => __('User login assigned to task'), + 'task.former.user' => __('Former user assigned to task'), + 'task.former.user.login' => __('Former user login assigned to task'), + 'task.group' => __('Group assigned to task'), + 'task.begin' => __('Start date'), + 'task.end' => __('End date'), + 'task.status' => __('Status'), + 'task.lastupdater' => __('Last updater'), + 'task.update' => __('Last update'), + 'task.delindex' => __('Delegation index') + ]; + foreach ($tags as $tag => $label) { + $elt= ['tag' => $tag, + 'label' => $label, + 'value' => true]; + + $this->addTagToList($elt); + } + asort($this->tag_descriptions); + } + + + /** + * Summary of addAdditionalTargets + * @param mixed $event + */ + function addAdditionalTargets($event = '') { + + $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::OBSERVER_GROUP, __('Watcher group')); + $this->addTarget(Notification::OBSERVER, __('Watcher')); + + $this->addTarget(Notification::AUTHOR, __('Requester'), PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE); + + if (strpos($event, 'task_reassign_') === 0) { + $this->addTarget(Notification::OLD_TECH_IN_CHARGE, + __('Former technician in charge of the task')); + } + + } + + + /** + * Summary of addSpecificTargets + * @param mixed $data + * @param mixed $options + */ + function addSpecificTargets($data, $options) { + + $obj = $this->obj; + $this->obj = $options['obj']; + + switch ($data['type']) { + case PluginProcessmakerNotificationTargetProcessmaker::PM_USER_TYPE : + + switch ($data['items_id']) { + + //Send to the requester of the ITIL object + case Notification::AUTHOR : + $this->addItemAuthor(); + break; + } + break; + + case Notification::USER_TYPE : + + switch ($data['items_id']) { + + //Notification to the ITIL object's observer group + case Notification::OBSERVER_GROUP : + $this->addLinkedGroupByType(CommonITILActor::OBSERVER); + break; + + //Notification to the ITIL object's observer user + case Notification::OBSERVER : + $this->addLinkedUserByType(CommonITILActor::OBSERVER); + break; + + //Send to the ITIL object followup author + case Notification::TASK_ASSIGN_TECH : + $this->addTaskAssignUser($options); + break; + + //Send to the ITIL object task group assigned + case Notification::TASK_ASSIGN_GROUP : + $this->addTaskAssignGroup($options); + break; + + //Send to the technician previously in charge of the task (before re-assignment) + case Notification::OLD_TECH_IN_CHARGE : + $this->addOldAssignTechnician($options); + break; + + } + } + + $this->obj = $obj; + } + + + /** + * Summary of addOldAssignTechnician + * @param $options + */ + function addOldAssignTechnician($options = []) { + //global $DB; + global $CFG_GLPI; + + if (isset($options['old_users_id_tech'])) { + + $user = new User(); + if ($user->getFromDB($options['old_users_id_tech'])) { + + $author_email = UserEmail::getDefaultForUser($user->fields['id']); + $author_lang = $user->fields["language"]; + $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); + } + } + } + +} diff --git a/inc/task.class.php b/inc/task.class.php index e7e38f6..04daec3 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -121,7 +121,7 @@ static function populatePlanning($params = []) :array { $events = []; 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') { $params['who_group'] = $params['who']; $params['whogroup'] = $params['who']; diff --git a/processmaker.xml b/processmaker.xml index 8ed5d68..165ff59 100644 --- a/processmaker.xml +++ b/processmaker.xml @@ -41,7 +41,7 @@ 9.4 - 4.0.5 + 4.0.8 9.5 diff --git a/setup.php b/setup.php index b902a8d..f562752 100644 --- a/setup.php +++ b/setup.php @@ -1,6 +1,6 @@