Files
tomolino-processmaker/inc/notificationtargetprocessmaker.class.php
Moron, Olivier cc17bd5fe4 * Bugfix Reminders on task cancelled before delete reminders update was not deleted
* Bugfix Uncaught ReferenceError: $ is not defined on ITIL Object creation
* Delete error message after case cancellation successfully
* change minimum version of processmaker server
* delete TODO comment
* Add possibility to cancel case with multiple tasks
* bugfix delete reminder on case's cancel  or delete
* Add behavior on a claimed task or reasign to the current user for show task in timeline
* Fixed issue with default dates settings in reminders for tasks
* Added shortcut to select "Me as sender"
* Added a test to prevent post-only user to set reminder settings
* Updated XML
* Fix issue with screen view
* Adjusted wordings
* Reviewed $new_date computation in cron
* Bugfix creating a case in processcase tab doesn't redirect to the case
* Adjusted visualization for Reminder
* Added an <hr>
* Adjusted values in dropdowns when settings are NULL
* Added a test to prevent sending of remminders to "ProcessMaker" user
* Added view of default and actual reminder settings for a PM task
* cronPMReminder reflects changes and send reminders
* Re-engineered table fields and search options
* Fixed issue with FUP that were no longuer added to timeline.
* Added automatic reminders
* bugfix on filter
* Changed copyrights
* added .gitignore
* add process category search option + input in process form
* Added process categories
* bugfixes on helpdesk process
* bugfixes html_tags and actiontime
* Changed the way the userId of the first task was computed, to be able to have a tobeclaimed task
* Added get/set APP_DATA scripts to be able to read/write the APP_DATA in json files
* Added a followup when a reminder is sent to task user (or group)

Set version 5.2.3
2025-01-14 12:17:17 +01:00

252 lines
10 KiB
PHP

<?php
/*
-------------------------------------------------------------------------
ProcessMaker plugin for GLPI
Copyright (C) 2014-2024 by Raynet SAS a company of A.Raymond Network.
https://www.araymond.com/
-------------------------------------------------------------------------
LICENSE
This file is part of ProcessMaker plugin for GLPI.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this plugin. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/**
* PluginProcessmakerNotificationTargetProcessmaker short summary.
*
* PluginProcessmakerNotificationTargetProcessmaker description.
*
* Common notificationtarget class for cases and tasks
*
* @version 1.0
* @author MoronO
*/
class PluginProcessmakerNotificationTargetProcessmaker extends NotificationTargetCommonITILObject {
const PM_USER_TYPE = 1000;
const OLD_TASK_TECH_IN_CHARGE = 1;
/**
* Summary of saveNotificationState
* @param mixed $donotif
* @return mixed
*/
static function saveNotificationState($donotif) {
global $CFG_GLPI;
$savenotif = $CFG_GLPI["use_notifications"];
if (!$donotif) {
$CFG_GLPI["use_notifications"] = false;
}
return $savenotif;
}
/**
* Summary of restoreNotificationState
* @param mixed $savenotif
*/
static function restoreNotificationState($savenotif) {
global $CFG_GLPI;
$CFG_GLPI["use_notifications"] = $savenotif;
}
/**
* Summary of getSubjectPrefix
* @param mixed $event
* @return string
*/
function getSubjectPrefix($event = '') {
return '';
}
/**
* Summary of getTags
*/
public function getTags() {
$tags = ['process.category' => __('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 '';
}
}