diff --git a/README.md b/README.md
index 9130842..643387d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
GLPI plugin that provides an interface with a customized ProcessMaker server (https://github.com/tomolimo/processmaker-server).
-version 3.4.x is compatible with GLPI 9.2 and needs ProcessMaker either 3.0.1.8-RE-1.12 (https://github.com/tomolimo/processmaker-server/releases/tag/3.0.1.8-RE-1.12) or 3.3.0-RE-1.0 (https://github.com/tomolimo/processmaker-server/releases/tag/3.3.0-RE-1.0)
+version 3.4.x is compatible with GLPI 9.2 and needs ProcessMaker either 3.0.1.8-RE-1.12 (https://github.com/tomolimo/processmaker-server/releases/tag/3.0.1.8-RE-1.12) or 3.3.0-RE-1.x (https://github.com/tomolimo/processmaker-server/releases/tag/3.3.0-RE-1.5)
version 3.5.x is compatible with GLPI 9.3 and needs ProcessMaker 3.3.0-RE-1.x (https://github.com/tomolimo/processmaker-server/releases/latest)
diff --git a/ajax/dropdownProcesses.php b/ajax/dropdownProcesses.php
index f8c8fc9..c9c585e 100644
--- a/ajax/dropdownProcesses.php
+++ b/ajax/dropdownProcesses.php
@@ -67,7 +67,7 @@
//if ($DB->numrows($result)) {
// while ($data = $DB->fetch_array($result)) {
-if ($result->numrows()) {
+//if ($result->numrows()) {
foreach ($result as $data) {
$process_entities = PluginProcessmakerProcess::getEntitiesForProfileByProcess($data["id"], $_SESSION['glpiactiveprofile']['id'], true);
$can_add = $data['max_cases_per_item'] == 0 || !isset($count_cases_per_item[$data["id"]]) || $count_cases_per_item[$data["id"]] < $data['max_cases_per_item'];
@@ -82,7 +82,7 @@
$count++;
}
}
-}
+//}
$ret['results'] = $processes;
$ret['count'] = $count;
diff --git a/ajax/dropdownUsers.php b/ajax/dropdownUsers.php
index 6015a0b..40de892 100644
--- a/ajax/dropdownUsers.php
+++ b/ajax/dropdownUsers.php
@@ -79,13 +79,13 @@
$count = 0;
//if ($DB->numrows($result)) {
// while ($data = $DB->fetch_assoc($result)) {
-if ($res->numrows()) {
+//if ($res->numrows()) {
foreach ($res as $data) {
$users[$data["id"]] = $dbu->formatUserName($data["id"], $data["name"], $data["realname"],
$data["firstname"]);
$logins[$data["id"]] = $data["name"];
}
-}
+//}
if (!function_exists('dpuser_cmp')) {
function dpuser_cmp($a, $b) {
diff --git a/front/processmaker.form.php b/front/processmaker.form.php
index d70ab35..edd9106 100644
--- a/front/processmaker.form.php
+++ b/front/processmaker.form.php
@@ -14,7 +14,7 @@
$case = new PluginProcessmakerCase;
if ($case->getFromGUID($resultCase->caseId)) {
$link = $case->getLinkURL();
- $task = new PluginProcessmakerTask();
+ $task = new PluginProcessmakerTask($_POST['itemtype'].'Task');
$task->getFromDBByRequest([
'WHERE' => [
diff --git a/inc/case.class.php b/inc/case.class.php
index 44c2d9e..6ba292a 100644
--- a/inc/case.class.php
+++ b/inc/case.class.php
@@ -265,27 +265,50 @@ function reassignCase($delIndex, $taskGuid, $delThread, $users_id_source, $users
*/
public function reassignTask ($delIndex, $newDelIndex, $delThread, $newDelThread, $newTech) {
global $DB;
- $res = $DB->request('glpi_plugin_processmaker_tasks', [
- 'AND' => [
- 'plugin_processmaker_cases_id' => $this->getID(),
- 'del_index' => $delIndex,
- 'del_thead' => $delThread
- ]
- ]);
- //$query = "SELECT * FROM glpi_plugin_processmaker_tasks WHERE plugin_processmaker_cases_id={$this->getID()} AND del_index=$delIndex AND del_thread=$delThread; ";
- //$res = $DB->query($query);
- //if ($DB->numrows($res) > 0) {
- // $row = $DB->fetch_array( $res );
- if ($row = $res->next()) {
- $glpi_task = new $row['itemtype'];
- $glpi_task->getFromDB( $row['items_id'] );
-
- $itilobject_itemtype = $this->fields['itemtype']; //str_replace( 'Task', '', $row['itemtype'] );
+
+ $dbu = new DbUtils;
+ $pm_task_row = $dbu->getAllDataFromTable(PluginProcessmakerTask::getTable(), ['plugin_processmaker_cases_id' => $this->getID(), 'del_index' => $delIndex, 'del_thread' => $delThread]);
+ if ($pm_task_row && count($pm_task_row) == 1) {
+ $pm_task_row = array_shift($pm_task_row);
+ $glpi_task = new $pm_task_row['itemtype'];
+ $glpi_task->getFromDB( $pm_task_row['items_id'] );
+
+ $itilobject_itemtype = $this->fields['itemtype'];
$foreignkey = getForeignKeyFieldForItemType( $itilobject_itemtype );
PluginProcessmakerProcessmaker::addWatcher( $itilobject_itemtype, $glpi_task->fields[ $foreignkey ], $newTech );
- $glpi_task->update( [ 'id' => $row['items_id'], $foreignkey => $glpi_task->fields[ $foreignkey ], 'users_id_tech' => $newTech ]);
+ $donotif = PluginProcessmakerNotificationTargetProcessmaker::saveNotificationState(false); // do not send notification yet
+ $glpi_task->update( ['id' => $glpi_task->getID(), $foreignkey => $glpi_task->fields[$foreignkey], 'users_id_tech' => $newTech, 'update' => true] );
+ PluginProcessmakerNotificationTargetProcessmaker::restoreNotificationState($donotif);
+
+ // 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']);
+ if ($res['notifications'] && count($res['notifications']) > 0) {
+ $pm_task = new PluginProcessmakerTask($pm_task_row['itemtype']);
+ $pm_task->getFromDB($pm_task_row['items_id']);
+ NotificationEvent::raiseEvent($res['event'],
+ $pm_task,
+ ['plugin_processmaker_cases_id' => $this->getID(),
+ 'itemtype' => $pm_task_row['itemtype'],
+ 'task_id' => $glpi_task->getID(),
+ 'old_users_id_tech' => $glpi_task->oldvalues['users_id_tech'],
+ 'is_private' => isset($glpi_task->fields['is_private']) ? $glpi_task->fields['is_private'] : 0,
+ 'entities_id' => $this->fields['entities_id'],
+ 'case' => $this
+ ]);
+ } else {
+ $item = new $itilobject_itemtype;
+ $item->getFromDB($glpi_task->fields[$foreignkey]);
+ NotificationEvent::raiseEvent('update_task',
+ $item,
+ ['plugin_processmaker_cases_id' => $this->getID(),
+ 'itemtype' => $pm_task_row['itemtype'],
+ 'task_id' => $glpi_task->getID(),
+ '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']}; ";
@@ -294,7 +317,7 @@ public function reassignTask ($delIndex, $newDelIndex, $delThread, $newDelThread
'del_index' => $newDelIndex,
'del_thread' => $newDelThread
], [
- 'id' => $row['id']
+ 'id' => $pm_task_row['id']
]
);
}
@@ -694,14 +717,14 @@ static function showForItem(CommonITILObject $item) {
$condition[] = ['is_active' => 1];
if ($itemtype == 'Ticket') {
$condition[] = ['is_incident' => 1];
- $is_itemtype = "AND is_incident=1";
+ //$is_itemtype = "AND is_incident=1";
if ($item->fields['type'] == Ticket::DEMAND_TYPE) {
$condition[] = ['is_request' => 1];
- $is_itemtype = "AND is_request=1";
+ //$is_itemtype = "AND is_request=1";
}
} else {
$condition[] = ['is_'.strtolower($itemtype) => 1];
- $is_itemtype = "AND is_".strtolower($itemtype)."=1";
+ //$is_itemtype = "AND is_".strtolower($itemtype)."=1";
}
PluginProcessmakerProcess::dropdown(['value' => 0,
'entity' => $item->fields['entities_id'],
diff --git a/inc/config.class.php b/inc/config.class.php
index e8c6ed2..0caee15 100644
--- a/inc/config.class.php
+++ b/inc/config.class.php
@@ -326,9 +326,6 @@ function parseUrl( url ) {
foreach ($res as $row) {
$pmGroups[ $row['CON_ID'] ] = $row['CON_VALUE'];
}
- //foreach ($PM_DB->request( $query ) as $row) {
- // $pmGroups[ $row['CON_ID'] ] = $row['CON_VALUE'];
- //}
Dropdown::showFromArray( 'pm_group_guid', $pmGroups, ['value' => $config->fields['pm_group_guid']] );
} else {
echo "".__('Not connected');
diff --git a/inc/notificationtargetcase.class.php b/inc/notificationtargetcase.class.php
new file mode 100644
index 0000000..7e74e32
--- /dev/null
+++ b/inc/notificationtargetcase.class.php
@@ -0,0 +1,120 @@
+ __('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
+ ]);
+ }
+ }
+ }
+
+}
diff --git a/inc/notificationtargetprocessmaker.class.php b/inc/notificationtargetprocessmaker.class.php
new file mode 100644
index 0000000..8179c1a
--- /dev/null
+++ b/inc/notificationtargetprocessmaker.class.php
@@ -0,0 +1,168 @@
+ __('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' => __('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')
+ ];
+
+ 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;
+ }
+ $this->addTagToList($elt);
+ }
+
+ asort($this->tag_descriptions);
+ }
+
+
+ /**
+ * Get all data needed for template processing
+ **/
+ public function addDataForTemplate($event, $options = []) {
+ global $PM_DB, $CFG_GLPI;
+
+ $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'];
+
+ // 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) {
+ // 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 $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;
+ }
+ }
+ } 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##'] = $CFG_GLPI["url_base"]."/index.php?redirect=".urlencode("/plugins/processmaker/front/case.form.php?id=".$options['case']->fields['id']);
+
+ // 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 labels
+ $this->getTags();
+ foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
+ if (!isset($this->data[$tag])) {
+ $this->data[$tag] = $values['label'];
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/inc/notificationtargettask.class.php b/inc/notificationtargettask.class.php
new file mode 100644
index 0000000..948be21
--- /dev/null
+++ b/inc/notificationtargettask.class.php
@@ -0,0 +1,320 @@
+ ['event' => 'task_add_', 'label' => __('New task')],
+ 'task_update' => ['event' => 'task_update_', 'label' => __('Update of a task')]
+ ];
+ }
+
+
+ /**
+ * 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
+ WHERE $table.is_active = 1
+ AND $ptable.is_active = 1";
+
+ $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']);
+
+ $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'];
+ }
+
+ return $actions;
+ }
+
+
+ /**
+ * Get all data needed for template processing
+ **/
+ public function addDataForTemplate($event, $options = []) {
+ global $PM_DB, $CFG_GLPI;
+
+ if (!isset($options['case'])) {
+ $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 or update
+ $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;
+
+ // 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##'] = Html::clean($dbu->getUserName($taskobj->fields['users_id_tech']));
+
+ // 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
+ $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.group' => __('Group assigned to task'),
+ 'task.begin' => __('Start date'),
+ 'task.end' => __('End date'),
+ 'task.status' => __('Status'),
+ 'task.lastupdater' => __('Last updater'),
+ 'task.update' => __('Last update')
+ ];
+ 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'));
+
+ 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) {
+
+ //Look for all targets whose type is Notification::ITEM_USER
+ switch ($data['type']) {
+ case Notification::USER_TYPE :
+
+ switch ($data['items_id']) {
+
+ //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;
+
+ }
+ }
+ }
+
+
+ /**
+ * Add user assigned to task
+ *
+ * @param array $options Options
+ *
+ * @return void
+ */
+ function addTaskAssignUser($options = []) {
+ global $DB;
+
+ // In case of delete task pass user id
+ if (isset($options['task_users_id_tech'])) {
+ $query = $this->getDistinctUserSql()."
+ FROM `glpi_users` ".
+ $this->getProfileJoinSql()."
+ WHERE `glpi_users`.`id` = '".$options['task_users_id_tech']."'";
+
+ foreach ($DB->request($query) as $data) {
+ $this->addToRecipientsList($data);
+ }
+ } else if (isset($options['task_id'])) {
+ $dbu = new DbUtils;
+ $tasktable = $dbu->getTableForItemType($options['itemtype']); //getTableForItemType($this->obj->getType().'Task');
+
+ $query = $this->getDistinctUserSql()."
+ FROM `$tasktable`
+ INNER JOIN `glpi_users`
+ ON (`glpi_users`.`id` = `$tasktable`.`users_id_tech`)".
+ $this->getProfileJoinSql()."
+ WHERE `$tasktable`.`id` = '".$options['task_id']."'";
+
+ foreach ($DB->request($query) as $data) {
+ $this->addToRecipientsList($data);
+ }
+ }
+ }
+
+
+ /**
+ * Add group assigned to the task
+ *
+ * @param array $options Options
+ *
+ * @return void
+ */
+ function addTaskAssignGroup($options = []) {
+ global $DB;
+
+ // In case of delete task pass user id
+ if (isset($options['task_groups_id_tech'])) {
+ $this->addForGroup(0, $options['task_groups_id_tech']);
+
+ } else if (isset($options['task_id'])) {
+ $dbu = new DbUtils;
+ $tasktable = $dbu->getTableForItemType($options['itemtype']); //getTableForItemType($this->obj->getType().'Task');
+ foreach ($DB->request([$tasktable, 'glpi_groups'], "`glpi_groups`.`id` = `$tasktable`.`groups_id_tech`
+ AND `$tasktable`.`id` = '".$options['task_id']."'") as $data) {
+ $this->addForGroup(0, $data['groups_id_tech']);
+ }
+ }
+ }
+
+
+ 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);
+ }
+ }
+ }
+
+}
diff --git a/inc/process.class.php b/inc/process.class.php
index f0816a5..704da48 100644
--- a/inc/process.class.php
+++ b/inc/process.class.php
@@ -190,7 +190,7 @@ function refreshTasks($post) {
] );
}
// here we should take into account translations if any
- if ( isset($taskArray[ $taskGUID ])) {
+ if (isset($taskArray[ $taskGUID ])) {
foreach ($taskArray[ $taskGUID ] as $langTask => $taskL) {
// look for 'name' field
if ($loc_id = DropdownTranslation::getTranslationID( $taskCat->getID(), 'TaskCategory', 'name', $langTask )) {
@@ -318,7 +318,7 @@ function refresh() {
);
//$query = "SELECT * FROM `".PluginProcessmakerCase::getTable()."` WHERE `plugin_processmaker_processes_id` = ".$key;
//$res = $DB->query($query);
- if ($DB->numrows($res) === 0) {
+ if ($res->numrows() === 0) {
// and if no will delete the process
$proc->delete(['id' => $key]);
// delete main taskcat
@@ -815,13 +815,13 @@ function showForm ($ID, $options = ['candel'=>false]) {
* @param $count true if execute an count(*),
* @param $search pattern
*
- * @return mysql result set.
+ * @return DBmysqlIterator.
**/
static function getSqlSearchResult ($count = true, $search = []) {
global $DB, $CFG_GLPI;
$query = [];
- $where = '';
- $orderby = '';
+ //$where = '';
+ //$orderby = '';
if (isset($_REQUEST['condition']) && isset($_SESSION['glpicondition'][$_REQUEST['condition']])) {
//$where = ' WHERE '.$_SESSION['glpicondition'][$_REQUEST['condition']]; //glpi_plugin_processmaker_processes.is_active=1 ';
@@ -838,7 +838,7 @@ static function getSqlSearchResult ($count = true, $search = []) {
//$orderby = " ORDER BY glpi_plugin_processmaker_processes.name ASC";
}
- if (!empty($search) && $search!=$CFG_GLPI["ajax_wildcard"]) {
+ if (!empty($search) && $search != $CFG_GLPI["ajax_wildcard"]) {
$query['WHERE']['AND']['OR']['glpi_plugin_processmaker_processes.name'] = $search;
$query['WHERE']['AND']['OR']['glpi_plugin_processmaker_processes.comment'] = $search;
//$where .= " AND (glpi_plugin_processmaker_processes.name $search
@@ -847,7 +847,7 @@ static function getSqlSearchResult ($count = true, $search = []) {
$query['FROM'] = 'glpi_plugin_processmaker_processes';
//$query = "SELECT $fields FROM glpi_plugin_processmaker_processes ".$where." ".$orderby.";";
//return $DB->query($query);
- $r= $DB->request($query);
+ //$r= $DB->request($query);
return $DB->request($query);
}
@@ -858,7 +858,7 @@ static function getSqlSearchResult ($count = true, $search = []) {
* @return mixed
*/
static function getProcessName($pid, $link = 0) {
- global $DB;
+ global $DB, $CFG_GLPI;
$process='';
if ($link==2) {
$process = ["name" => "",
@@ -872,8 +872,10 @@ static function getProcessName($pid, $link = 0) {
//if ($result && $DB->numrows($result)==1) {
// $data = $DB->fetch_assoc($result);
if ($res && $res->numrows() == 1) {
- $processname = $res['name'];//$data["name"];
- if ($link==2) {
+// $processname = $res['name'];//$data["name"];
+ $data = $res->next();
+ $processname = $data["name"];
+ if ($link == 2) {
$process["name"] = $processname;
$process["link"] = $CFG_GLPI["root_doc"]."/plugins/processmaker/front/process.form.php?id=".$pid;
$process["comment"] = __('Name')." : ".$processname."
".__('Comments').
@@ -908,10 +910,10 @@ static function getEntitiesForProfileByProcess($processes_id, $profiles_id, $chi
]
]
]);
- $query = "SELECT `entities_id`, `is_recursive`
- FROM `glpi_plugin_processmaker_processes_profiles`
- WHERE `plugin_processmaker_processes_id` = '$processes_id'
- AND `profiles_id` = '$profiles_id'";
+ //$query = "SELECT `entities_id`, `is_recursive`
+ // FROM `glpi_plugin_processmaker_processes_profiles`
+ // WHERE `plugin_processmaker_processes_id` = '$processes_id'
+ // AND `profiles_id` = '$profiles_id'";
$entities = [];
//foreach ($DB->request($query) as $data) {
@@ -961,6 +963,5 @@ static function showUnderMaintenance($ptitle, $size = '') {
echo "
".__('Process task', 'processmaker')." | |||||||
---|---|---|---|---|---|---|---|
".__('Process name', 'processmaker')." | "; + echo "".__('Task name', 'processmaker')." | "; + + echo "".__('Complete name')." | " . + "".__('Start', 'processmaker')." | " . + "".__('Task GUID', 'processmaker')." | " . + "".__('Comments')." | " . + "".__('Active')." | " . + "".__('Sub-process', 'processmaker')." | " . + "
" . $taskCat['pname']; + if ($_SESSION["glpiis_ids_visible"]) { + echo " (" . $processes_id . ")"; + } + echo " | "; + echo ""; + echo $taskCat['name']; + + if ($_SESSION["glpiis_ids_visible"]) { + echo " (" . $taskCat['taskcategories_id'] . ")"; + } + echo " | "; + + echo "" . $taskCat['completename'] . " | "; + + echo ""; + if ($taskCat['is_start']) { + echo ""; + } + echo " | "; + + echo "".$taskCat['pm_task_guid']." | "; + + echo "".$taskCat['comment']." | "; + + echo ""; + if ($taskCat['is_active']) { + echo ""; + } + echo " | "; + + echo ""; + if ($taskCat['is_subprocess']) { + echo ""; + } + echo " | "; + + echo "