From 128b704403bfd43c5e380e6876ad6a978ab565d5 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Mon, 19 Mar 2018 16:56:18 +0100 Subject: [PATCH] Added more info in config format Added possibility to rename PM DB (default to wf_workflow) Fixes #53 Fixes #50 + other fixes Changed version to 3.2.8 --- front/processmaker.helpdesk.form.php | 15 ++++++++++- front/tracking.injector.php | 7 ++++++ hook.php | 8 ++++++ inc/config.class.php | 27 +++++++++++++++++++- inc/db.class.php | 2 +- inc/processmaker.class.php | 37 ++++++++++++++++++++++++++-- processmaker.xml | 4 +-- setup.php | 2 +- 8 files changed, 94 insertions(+), 8 deletions(-) diff --git a/front/processmaker.helpdesk.form.php b/front/processmaker.helpdesk.form.php index 4a0e9d0..9f88c29 100644 --- a/front/processmaker.helpdesk.form.php +++ b/front/processmaker.helpdesk.form.php @@ -588,7 +588,9 @@ function processMakerShowCase( $ID, $from_helpdesk ) { $buffer = htmlspecialchars($buffer, ENT_NOQUOTES); // will restore '<' to '<' and '>' to '>' // so that only the already escaped entites will get the double encoding - $buffer = str_replace(['<', '>'], ['<', '>'], $buffer); + // will also change end of bold into a local identifier + $endOfBold = 'end_of_bold'.rand(); + $buffer = str_replace(['<', '>', ''], ['<', '>', $endOfBold], $buffer); // will convert any UTF-8 char that can't be expressed in ASCII into an HTML entity $buffer = mb_convert_encoding($buffer, 'HTML-ENTITIES'); @@ -604,6 +606,14 @@ function processMakerShowCase( $ID, $from_helpdesk ) { $elt->setAttribute( 'style', 'display:none;'); } + // add an input for processId in the form + // echo ""; + $res = $xpath->query('//form[@name="helpdeskform"]'); + $input = $res->item(0)->appendChild(new DOMElement('input')); + $input->setAttribute('name', 'processId'); + $input->setAttribute('type', 'hidden'); + $input->setAttribute('value', $caseInfo->processId); + // special case for content textarea which is in the same tr than the file upload $res = $xpath->query('//*[@name="content"]/ancestor::div[1] | //*[@name="content"]/ancestor::tr[1]/td[1]'); foreach($res as $elt) { @@ -644,6 +654,9 @@ function processMakerShowCase( $ID, $from_helpdesk ) { $buffer = $dom->saveHTML(); + // revert back + $buffer = str_replace($endOfBold, '', $buffer); + // will revert back any char converted above $buffer = mb_convert_encoding($buffer, 'UTF-8', 'HTML-ENTITIES'); echo $buffer; diff --git a/front/tracking.injector.php b/front/tracking.injector.php index 0161fbf..9534fb8 100644 --- a/front/tracking.injector.php +++ b/front/tracking.injector.php @@ -7,6 +7,9 @@ if( isset( $_REQUEST['_glpi_csrf_token'] ) ) { define('GLPI_KEEP_CSRF_TOKEN', true) ; } +$PM_POST = $_POST; +$PM_REQUEST = $_REQUEST; +$PM_GET = $_GET; include( "../../../inc/includes.php" ); if (empty($_POST["_type"]) @@ -58,4 +61,8 @@ if( isset($_POST["_from_helpdesk"]) && $_POST["_from_helpdesk"] == 1 // prepare environment for std tracking.injector.php // switch to front dir chdir(GLPI_ROOT."/front"); +// revert back $_POST, $_GET and $_REQUEST +$_GET = $PM_GET; +$_POST = $PM_POST; +$_REQUEST = $PM_REQUEST; include (GLPI_ROOT . "/front/tracking.injector.php"); diff --git a/hook.php b/hook.php index ac0c469..d25a5ec 100644 --- a/hook.php +++ b/hook.php @@ -123,6 +123,7 @@ function plugin_processmaker_install() { `pm_group_guid` VARCHAR(32) NULL DEFAULT NULL, `comment` TEXT NULL, `pm_dbserver_name` VARCHAR(255) NULL DEFAULT 'localhost', + `pm_dbname` VARCHAR(50) NULL DEFAULT 'wf_workflow', `pm_dbserver_user` VARCHAR(255) NULL DEFAULT NULL, `pm_dbserver_passwd` VARCHAR(255) NULL DEFAULT NULL, `domain` VARCHAR(50) NULL DEFAULT '', @@ -164,6 +165,13 @@ function plugin_processmaker_install() { $DB->query($query) or die("error adding fields maintenance to glpi_plugin_processmaker_configs" . $DB->error()); } + if (!arFieldExists("glpi_plugin_processmaker_configs", "pm_dbname" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_configs` + ADD COLUMN `pm_dbname` VARCHAR(50) NULL DEFAULT 'wf_workflow' AFTER `pm_dbserver_name`; + ;"; + $DB->query($query) or die("error adding field pm_dbname to glpi_plugin_processmaker_configs" . $DB->error()); + } + if (arTableExists("glpi_plugin_processmaker_profiles")) { $query = "DROP TABLE `glpi_plugin_processmaker_profiles` ;"; $DB->query($query) or die("error dropping glpi_plugin_processmaker_profiles" . $DB->error()); diff --git a/inc/config.class.php b/inc/config.class.php index daf7c7c..d701dff 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -143,6 +143,8 @@ class PluginProcessmakerConfig extends CommonDBTM { static function showConfigForm($item) { global $LANG, $PM_DB, $CFG_GLPI; + $setup_ok = false; + $ui_theme = array( 'glpi_classic' => 'glpi_classic', 'glpi_neoclassic' => 'glpi_neoclassic' @@ -150,7 +152,7 @@ class PluginProcessmakerConfig extends CommonDBTM { $config = self::getInstance(); - $config->showFormHeader(); + $config->showFormHeader(['colspan' => 4]); echo ""; echo "".$LANG['processmaker']['config']['URL'].""; @@ -220,6 +222,7 @@ class PluginProcessmakerConfig extends CommonDBTM { && $config->fields["pm_admin_user"] != '' && ($pm->login(true))) { echo "".__('Test successful'); + $setup_ok = true; } else { echo "".__('Test failed')."
".print_r($pm->lasterror, true); } @@ -232,6 +235,11 @@ class PluginProcessmakerConfig extends CommonDBTM { echo ""; echo "\n"; + echo ""; + echo "" . __('Database name') . ""; + echo ""; + echo "\n"; + echo ""; echo "" . __('SQL user') . ""; echo ""; @@ -310,6 +318,23 @@ class PluginProcessmakerConfig extends CommonDBTM { Dropdown::showYesNo("maintenance", $config->fields['maintenance']); echo ""; + echo ""; + + echo "".__('Processmaker system information').""; + if ($setup_ok) { + $info = $pm->systemInformation( ); + echo ''._('Version').''.$info->version.''; + echo ''._('Web server').''.$info->webServer.''; + echo ''._('Server name').''.$info->serverName.''; + echo ''._('PHP version').''.$info->phpVersion.''; + echo ''._('DB version').''.$info->databaseVersion.''; + echo ''._('DB server IP').''.$info->databaseServerIp.''; + echo ''._('DB name').''.$info->databaseName.''; + echo ''._('User browser').''.$info->userBrowser.''; + echo ''._('User IP').''.$info->userIp.''; + } else { + echo ''._('Version').''.__('Not yet!').''; + } $config->showFormButtons(array('candel'=>false)); return false; diff --git a/inc/db.class.php b/inc/db.class.php index 83504ac..6b03342 100644 --- a/inc/db.class.php +++ b/inc/db.class.php @@ -18,7 +18,7 @@ class PluginProcessmakerDB extends DBmysql { $this->dbhost = $config->fields['pm_dbserver_name']; $this->dbuser = $config->fields['pm_dbserver_user']; $this->dbpassword = Toolbox::decrypt($config->fields['pm_dbserver_passwd'], GLPIKEY); - $this->dbdefault = "wf_".$config->fields['pm_workspace']; + $this->dbdefault = $config->fields['pm_dbname']; parent::__construct(); } } diff --git a/inc/processmaker.class.php b/inc/processmaker.class.php index 06cf8c6..eb3dfbb 100644 --- a/inc/processmaker.class.php +++ b/inc/processmaker.class.php @@ -451,6 +451,24 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { } } + /** + * Summary of systemInformation + * returns information about the PM system + * Embedded systemInformation() PM web service call (definition: http://wiki.processmaker.com/index.php/ProcessMaker_WSDL_Web_Services#systemInformation.28.29) + * A session must be open before with login() + * @return an object containing information, or false when exception occured + */ + function systemInformation( ) { + try { + $pmSystemInfo = $this->pmSoapClient->systemInformation( array( 'sessionId' => $_SESSION["pluginprocessmaker"]["session"]["id"]) ); + return $pmSystemInfo; + } + catch (Exception $e) { + Toolbox::logDebug( $e ); + return false; + } + } + /** * Summary of reassignCase * reassigns a case to a different user. Note that the logged-in user needs to have the PM_REASSIGNCASE permission in his/her role in order to be able to reassign the case. @@ -1380,7 +1398,10 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { if (property_exists( $pmRouteCaseResponse, 'routing' )) { // now tries to get some variables to setup content for new task and to append text to solved task $txtForTasks = $myProcessMaker->getVariables( $myCase->getID(), array( "GLPI_ITEM_APPEND_TO_TASK", - "GLPI_ITEM_SET_STATUS" ) ); + "GLPI_ITEM_SET_STATUS", + "GLPI_TICKET_FOLLOWUP_CONTENT", + "GLPI_TICKET_FOLLOWUP_IS_PRIVATE", + "GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID" ) ); $itemSetStatus = ''; if (array_key_exists( 'GLPI_ITEM_SET_STATUS', $txtForTasks )) { $itemSetStatus = $txtForTasks[ 'GLPI_ITEM_SET_STATUS' ]; @@ -1390,14 +1411,26 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { } else { $txtToAppendToTask = ''; } + $createFollowup = false; // by default + if (array_key_exists( 'GLPI_TICKET_FOLLOWUP_CONTENT', $txtForTasks ) && $txtForTasks[ 'GLPI_TICKET_FOLLOWUP_CONTENT' ] != '') { + $createFollowup = true; + } // reset those variables $resultSave = $myProcessMaker->sendVariables( $myCase->getID(), array( "GLPI_ITEM_APPEND_TO_TASK" => '', - "GLPI_ITEM_SET_STATUS" => '' ) ); + "GLPI_ITEM_SET_STATUS" => '', + "GLPI_TICKET_FOLLOWUP_CONTENT" => '', + "GLPI_TICKET_FOLLOWUP_IS_PRIVATE" => '', + "GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID" => '' ) ); // routing has been done, then solve 1st task $myProcessMaker->solveTask( $myCase->getID(), $parm->input['processmaker_delindex'], array( 'txtToAppend' => $txtToAppendToTask, 'notif' => false) ); + // create a followup if requested + if ($createFollowup && $itemType == 'Ticket') { + $myProcessMaker->addTicketFollowup( $itemId, $txtForTasks ); + } + // and create GLPI tasks for the newly created PM tasks. foreach ($pmRouteCaseResponse->routing as $route) { $myProcessMaker->addTask( $myCase->fields['itemtype'], diff --git a/processmaker.xml b/processmaker.xml index c53af59..0289792 100644 --- a/processmaker.xml +++ b/processmaker.xml @@ -23,11 +23,11 @@ - 3.2.5 + 3.2.8 9.2 - 3.2.5 + 3.2.8 9.1 diff --git a/setup.php b/setup.php index 79c52b2..0f2a64e 100644 --- a/setup.php +++ b/setup.php @@ -119,7 +119,7 @@ function plugin_version_processmaker() { global $LANG; return array ('name' => 'Process Maker', - 'version' => '3.2.5', + 'version' => '3.2.8', 'author' => 'Olivier Moron', 'homepage' => 'https://github.com/tomolimo/processmaker', 'minGlpiVersion' => '9.1');