Skip to content

Commit

Permalink
Fixed bugs for URL in notifications Set version to 3.6.6
Browse files Browse the repository at this point in the history
Added new tags in notification templates
Fixed bugs on tag data
Added 1 dim assoc array management in notification templates
Fixed issue on the 2 dim arrays
Added missing notification template tags to get info on item hosting the case (Ticket, Change, Problem)
Added quote to be sure that SQL request will not throw an error
Added a test for the return code from routeCase() to prevent closing of current task if routing is not done
  • Loading branch information
tomolimo committed Oct 28, 2019
1 parent eb50535 commit 7a31eef
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 87 deletions.
25 changes: 13 additions & 12 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ function plugin_item_update_processmaker_tasks($parm) {
$locCase->getFromDB($pmTask->fields['plugin_processmaker_cases_id']);
$srccase_guid = $locCase->fields['case_guid'];

$msg = ' $locCase: '.str_replace("\n", "\n ", print_r($locCase, true))."\n";
$msg .= ' $task: '.str_replace("\n", "\n ", print_r($parm, true))."\n";
$msg .= ' $pmTask: '.str_replace("\n", "\n ", print_r($pmTask, true))."\n";
$msg .= "\n";
//$msg = Toolbox::backtrace(false);
//$msg .= ' $locCase: '.str_replace("\n", "\n ", print_r($locCase, true))."\n";
//$msg .= ' $task: '.str_replace("\n", "\n ", print_r($parm, true))."\n";
//$msg .= ' $pmTask: '.str_replace("\n", "\n ", print_r($pmTask, true))."\n";
//$msg .= "\n";

foreach ($DB->request( 'glpi_plugin_processmaker_caselinks', "is_active = 1 AND sourcetask_guid='".$pmTaskCat->fields['pm_task_guid']."'") as $targetTask) {

Expand Down Expand Up @@ -289,17 +290,17 @@ function plugin_item_update_processmaker_tasks($parm) {
unset( $infoForTasks[ $casevar ] );
}

$msg .= " ***********\n";
$msg .= ' $targetTask: '.str_replace("\n", "\n ", print_r($targetTask, true))."\n";
//$msg .= " ***********\n";
//$msg .= ' $targetTask: '.str_replace("\n", "\n ", print_r($targetTask, true))."\n";

$targetTask['sourcecondition'] = str_replace( array_keys($infoForTasks), $infoForTasks, $targetTask['sourcecondition'] );

$eval = eval( "return (".$targetTask['sourcecondition']." ? 1 : 0);" );

$msg .= ' $infoForTasks: '.str_replace("\n", "\n ", print_r($infoForTasks, true))."\n";
$msg .= ' $targetTask[\'sourcecondition\']: '.str_replace("\n", "\n ", print_r($targetTask['sourcecondition'], true))."\n";
$msg .= ' $result: '."$eval\n";
$msg .= "\n";
//$msg .= ' $infoForTasks: '.str_replace("\n", "\n ", print_r($infoForTasks, true))."\n";
//$msg .= ' $targetTask[\'sourcecondition\']: '.str_replace("\n", "\n ", print_r($targetTask['sourcecondition'], true))."\n";
//$msg .= ' $result: '."$eval\n";
//$msg .= "\n";

if ($eval) {
// look at each linked ticket if a case is attached and then if a task like $val is TO_DO
Expand Down Expand Up @@ -429,8 +430,8 @@ function plugin_item_update_processmaker_tasks($parm) {

}

$msg .= "================\n";
Toolbox::logInFile("processmaker", $msg);
//$msg .= "================\n";
//Toolbox::logInFile("processmaker", $msg);

}
}
20 changes: 9 additions & 11 deletions inc/case.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ public function reassignTask ($delIndex, $newDelIndex, $delThread, $newDelThread
'update' => true] );
PluginProcessmakerNotificationTargetProcessmaker::restoreNotificationState($donotif);

// then update the delIndex and delThread
$DB->Update( 'glpi_plugin_processmaker_tasks', [
'del_index' => $newDelIndex,
'del_thread' => $newDelThread
], [
'id' => $pm_task_row['id']
]
);

// Notification management
// search if at least one active notification is existing for that pm task with that event 'task_update_'.$glpi_task->fields['taskcategories_id']
$res = PluginProcessmakerNotificationTargetTask::getNotifications('task_update', $glpi_task->fields['taskcategories_id'], $this->fields['entities_id']);
Expand Down Expand Up @@ -316,17 +325,6 @@ public function reassignTask ($delIndex, $newDelIndex, $delThread, $newDelThread
'is_private' => isset($glpi_task->fields['is_private']) ? $glpi_task->fields['is_private'] : 0
]);
}

// then update the delIndex and delThread
//$query = "UPDATE glpi_plugin_processmaker_tasks SET del_index = $newDelIndex, del_thread = $newDelThread WHERE id={$row['id']}; ";
//$res = $DB->query($query);
$DB->Update( 'glpi_plugin_processmaker_tasks', [
'del_index' => $newDelIndex,
'del_thread' => $newDelThread
], [
'id' => $pm_task_row['id']
]
);
}
}

Expand Down
88 changes: 70 additions & 18 deletions inc/notificationtargetprocessmaker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* PluginProcessmakerNotificationTargetProcessmaker short summary.
*
* PluginProcessmakerNotificationTargetProcessmaker description.
*
*
* Common notificationtarget class for cases and tasks
*
* @version 1.0
Expand Down Expand Up @@ -58,11 +58,16 @@ public function getTags() {
'case.id' => __('Case id', 'processmaker'),
'case.title' => __('Case title', 'processmaker'),
'case.description' => __('Case description', 'processmaker'),
'case.url' => __('URL'),
'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 case array \'YYY\'', 'processamker')
'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) {
Expand All @@ -76,6 +81,9 @@ public function getTags() {
$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);
}

Expand All @@ -87,7 +95,7 @@ public function getTags() {
* Get all data needed for template processing
**/
public function addDataForTemplate($event, $options = []) {
global $PM_DB, $CFG_GLPI;
global $CFG_GLPI, $PM_DB;

$excluded = ['_VAR_CHANGED_',
'PIN',
Expand All @@ -107,11 +115,6 @@ public function addDataForTemplate($event, $options = []) {
$process->getFromDB($options['case']->fields['plugin_processmaker_processes_id']);
$taskcat_id = $process->fields['taskcategories_id'];

// set defaults to all
foreach ($this->tags as $key => $val) {
$this->data["##$key##"] = "-";
}

// 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) {
Expand All @@ -125,10 +128,16 @@ public function addDataForTemplate($event, $options = []) {
// add numberof for count of rows
$this->data["##array.numberof$key##"] = count($val);
// get the keys/vals of the sub-array
foreach ($val as $row) {
foreach ($row as $col_name => $col_val) {
$this->data["array.$key"][]["##array.$key.$col_name##"] = $col_val;
$this->data["##lang.array.$key.$col_name##"] = $col_name;
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 {
Expand All @@ -145,18 +154,29 @@ public function addDataForTemplate($event, $options = []) {
$this->data['##case.id##'] = $options['case']->fields['id'];

// case URL
$this->data['##case.url##'] = $CFG_GLPI["url_base"]."/index.php?redirect=".urlencode("/plugins/processmaker/front/case.form.php?id=".$options['case']->fields['id']);

$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');
$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 labels
// 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])) {
Expand All @@ -165,4 +185,36 @@ public function addDataForTemplate($event, $options = []) {
}
}


/**
* 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 '';
}

}
22 changes: 18 additions & 4 deletions inc/notificationtargettask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class PluginProcessmakerNotificationTargetTask extends PluginProcessmakerNotific
*/
private static function getDefaultEvents() {
return ['task_add' => ['event' => 'task_add_', 'label' => __('New task')],
'task_update' => ['event' => 'task_update_', 'label' => __('Update of a task')]
'task_update' => ['event' => 'task_update_', 'label' => __('Update of a task')],
'task_done' => ['event' => 'task_done_', 'label' => __('Task done')]
];
}

Expand Down Expand Up @@ -66,8 +67,9 @@ public function getEvents() {
}
$temp->getFromDB($row['taskcat']);

$actions[$defaultEvents['task_add']['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $defaultEvents['task_add']['label'];
$actions[$defaultEvents['task_add']['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $defaultEvents['task_add']['label'];
$actions[$defaultEvents['task_update']['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $defaultEvents['task_update']['label'];
$actions[$defaultEvents['task_done']['event'].$row['taskcat']] = $ptaskcats[$row['ptaskcat']]." > ".$temp->fields['name'].": " . $defaultEvents['task_done']['label'];
}

return $actions;
Expand All @@ -92,7 +94,7 @@ public function addDataForTemplate($event, $options = []) {
$baseevent = $locevent[0].'_'.$locevent[1];
$taskcat_id = $locevent[2];

// task action: add or update
// task action: add, update or done
$this->data['##task.action##'] = $events[$baseevent]['label'];

// task category information: meta data on task
Expand Down Expand Up @@ -132,6 +134,15 @@ public function addDataForTemplate($event, $options = []) {

// task technician
$this->data['##task.user##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_tech']));
$tech = new User;
$tech->getFromDB($taskobj->fields['users_id_tech']);
$this->data['##task.user.login##'] = $tech->fields['name'];
if (isset($options['old_users_id_tech'])) {
$oldtech = new User;
$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);
Expand All @@ -146,7 +157,7 @@ public function addDataForTemplate($event, $options = []) {
// task duration
$this->data['##task.time##'] = Html::timestampToString($taskobj->fields['actiontime'], false);

// add labels
// 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])) {
Expand All @@ -173,6 +184,9 @@ public function getTags() {
'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'),
Expand Down
Loading

0 comments on commit 7a31eef

Please sign in to comment.