From 094b281fb4cdb9819512de07f180dcbbc11e54a9 Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 25 Oct 2016 11:37:01 +0200 Subject: [PATCH] Version 3.0.0 first version compatible with GLPi 9.1.1 --- README.md | 4 +- ajax/dropdownProcesses.php | 113 +- ajax/dropdownUsers.php | 163 +- ajax/task_resume.php | 81 - ajax/task_users.php | 30 +- front/cases.front.php | 151 +- front/config.form.php | 15 +- front/process.form.php | 11 +- front/process.php | 4 +- front/process_profile.form.php | 8 +- front/processmaker.form.php | 100 +- front/processmaker.helpdesk.form.php | 1795 +++++++++++++---- front/profile.form.php | 15 - front/tracking.injector.php | 81 +- hook.php | 773 +++---- inc/case.class.php | 670 +++++- inc/cases.class.php | 713 ------- inc/config.class.php | 237 ++- inc/db.class.php | 22 + inc/process.class.php | 567 ++---- inc/process_profile.class.php | 159 +- inc/processmaker.class.php | 1375 ++++++++----- inc/processmakerconfig.class.php | 105 +- inc/profile.class.php | 186 +- inc/task.class.php | 127 ++ inc/taskcategory.class.php | 39 +- inc/tasks.class.php | 68 - inc/user.class.php | 219 ++ inc/users.class.php | 409 ---- js/cases.helpdesk.js | 27 +- js/cases.js | 87 +- js/helpdesk.public.js.php | 39 +- locales/en_GB.php | 51 +- locales/fr_FR.php | 42 +- processmaker.xml | 4 +- setup.php | 248 ++- wiki/2015-06-17 15_27_10-GLPI - Setup.png | Bin 18587 -> 0 bytes wiki/2015-06-17 15_43_57-GLPI - Profiles.png | Bin 19560 -> 0 bytes ...9-GLPI - Profiles simplified interface.png | Bin 19527 -> 0 bytes ...15-06-17 15_56_05-GLPI - Process Maker.png | Bin 70226 -> 0 bytes ...I - Process Maker - Process Definition.png | Bin 65693 -> 0 bytes ...Process Maker - Process Authorizations.png | Bin 10745 -> 0 bytes wiki/Ticket sample.png | Bin 65368 -> 0 bytes wiki/processmaker.png | Bin 58545 -> 0 bytes 44 files changed, 4812 insertions(+), 3926 deletions(-) delete mode 100644 ajax/task_resume.php delete mode 100644 front/profile.form.php delete mode 100644 inc/cases.class.php create mode 100644 inc/db.class.php create mode 100644 inc/task.class.php delete mode 100644 inc/tasks.class.php create mode 100644 inc/user.class.php delete mode 100644 inc/users.class.php delete mode 100644 wiki/2015-06-17 15_27_10-GLPI - Setup.png delete mode 100644 wiki/2015-06-17 15_43_57-GLPI - Profiles.png delete mode 100644 wiki/2015-06-17 15_44_39-GLPI - Profiles simplified interface.png delete mode 100644 wiki/2015-06-17 15_56_05-GLPI - Process Maker.png delete mode 100644 wiki/2015-06-17 16_17_51-GLPI - Process Maker - Process Definition.png delete mode 100644 wiki/2015-06-17 16_38_31-GLPI - Process Maker - Process Authorizations.png delete mode 100644 wiki/Ticket sample.png delete mode 100644 wiki/processmaker.png diff --git a/README.md b/README.md index 8b70ecc..94d563e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # processmaker GLPI plugin that provides an interface with ProcessMaker (http://www.processmaker.com/). -Is currently compatible to GLPI 0.83.8 and ProcessMaker 2.5, 2.8 and 3.0 (see note below) -Note: for ProcessMaker 3.0, this plugin can run old (2.x) and new (3.x) processes, but the process map view (for new BMPN process) has a bug. +Is currently compatible to GLPI 9.1 and ProcessMaker 3.0 (see note below) +Note: for ProcessMaker 3.0, this plugin can run old (2.x) and new (3.x) processes diff --git a/ajax/dropdownProcesses.php b/ajax/dropdownProcesses.php index 6f6498a..48cd90e 100644 --- a/ajax/dropdownProcesses.php +++ b/ajax/dropdownProcesses.php @@ -2,14 +2,12 @@ // ---------------------------------------------------------------------- // Original Author of file: Olivier Moron -// Purpose of file: +// Purpose of file: to return list of processes which can be started by end-user // ---------------------------------------------------------------------- // Direct access to file if (strpos($_SERVER['PHP_SELF'],"dropdownProcesses.php")) { - $AJAX_INCLUDE = 1; - define('GLPI_ROOT','../../..'); - include (GLPI_ROOT."/inc/includes.php"); + include ("../../../inc/includes.php"); header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } @@ -18,98 +16,57 @@ if (!defined('GLPI_ROOT')) { die("Can not acces directly to this file"); } -include_once dirname(__FILE__)."/../inc/process.class.php" ; +//include_once dirname(__FILE__)."/../inc/process.class.php" ; Session::checkLoginUser(); -if (!isset($_POST['right'])) { - $_POST['right'] = "all"; +if (isset($_REQUEST["entity_restrict"]) + && !is_array($_REQUEST["entity_restrict"]) + && (substr($_REQUEST["entity_restrict"], 0, 1) === '[') + && (substr($_REQUEST["entity_restrict"], -1) === ']')) { + $_REQUEST["entity_restrict"] = json_decode($_REQUEST["entity_restrict"]); } -// Default view : Nobody -if (!isset($_POST['all'])) { - $_POST['all'] = 0; +// Security +if (!($item = getItemForItemtype($_REQUEST['itemtype']))) { + exit(); } -$used = array(); +// Count real items returned +$count = 0; -if (isset($_POST['used'])) { - if (is_array($_POST['used'])) { - $used = $_POST['used']; - } else { - $used = unserialize(stripslashes($_POST['used'])); - } +if (!isset($_REQUEST['emptylabel']) || ($_REQUEST['emptylabel'] == '')) { + $_REQUEST['emptylabel'] = Dropdown::EMPTY_VALUE; } -if (isset($_POST["entity_restrict"]) - && !is_numeric($_POST["entity_restrict"]) - && !is_array($_POST["entity_restrict"])) { - - $_POST["entity_restrict"] = unserialize(stripslashes($_POST["entity_restrict"])); +if (!empty($_REQUEST['searchText'])) { + $search = Search::makeTextSearch($_REQUEST['searchText']); } -$result = PluginProcessmakerProcess::getSqlSearchResult(false, $_POST['right'], $_POST["entity_restrict"], - $_POST['value'], $used, $_POST['searchText']); - $processes = array(); +// Empty search text : display first +//if (empty($_REQUEST['searchText'])) { + if ($_REQUEST['display_emptychoice']) { + if (($one_item < 0) || ($one_item == 0)) { + array_push($processes, array('id' => 0, + 'text' => $_REQUEST['emptylabel'])); + } + } +//} + +$result = PluginProcessmakerProcess::getSqlSearchResult(false, $search); if ($DB->numrows($result)) { while ($data=$DB->fetch_array($result)) { - if( in_array( $_POST["entity_restrict"], PluginProcessmakerProcess::getEntitiesForProfileByProcess( $data["id"], $_SESSION['glpiactiveprofile']['id'], true) ) ) { - $processes[$data["id"]] = $data["name"]; + if( in_array( $_REQUEST["entity_restrict"], PluginProcessmakerProcess::getEntitiesForProfileByProcess( $data["id"], $_SESSION['glpiactiveprofile']['id'], true) ) ) { + array_push( $processes, array( 'id' => $data["id"], + 'text' => $data["name"] )); + $count++; } } } - -echo ""; - -if (isset($_POST["comment"]) && $_POST["comment"]) { - $paramscomment = array('value' => '__VALUE__', - 'table' => "glpi_plugin_processmaker_processes"); - - if (isset($_POST['update_link'])) { - $paramscomment['withlink'] = "comment_link_".$_POST["myname"].$_POST["rand"]; - } - Ajax::updateItemOnSelectEvent("dropdown_".$_POST["myname"].$_POST["rand"], - "comment_".$_POST["myname"].$_POST["rand"], - $CFG_GLPI["root_doc"]."/ajax/comments.php", $paramscomment); -} - -Ajax::commonDropdownUpdateItem($_POST); -?> \ No newline at end of file +$ret['results'] = $processes; +$ret['count'] = $count; +echo json_encode($ret); diff --git a/ajax/dropdownUsers.php b/ajax/dropdownUsers.php index ade11c2..aafabf7 100644 --- a/ajax/dropdownUsers.php +++ b/ajax/dropdownUsers.php @@ -10,9 +10,7 @@ // Direct access to file if (strpos($_SERVER['PHP_SELF'],"dropdownUsers.php")) { - $AJAX_INCLUDE = 1; - define('GLPI_ROOT','../../..'); - include (GLPI_ROOT."/inc/includes.php"); + include ("../../../inc/includes.php"); header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } @@ -21,114 +19,117 @@ if (!defined('GLPI_ROOT')) { die("Can not acces directly to this file"); } -include_once dirname(__FILE__)."/../inc/users.class.php" ; +//include_once dirname(__FILE__)."/../inc/users.class.php" ; Session::checkLoginUser(); -if (!isset($_POST['right'])) { - $_POST['right'] = "all"; +$PM_DB = new PluginProcessmakerDB ; + +if (!isset($_REQUEST['right'])) { + $_REQUEST['right'] = "all"; } // Default view : Nobody -if (!isset($_POST['all'])) { - $_POST['all'] = 0; +if (!isset($_REQUEST['all'])) { + $_REQUEST['all'] = 0; } + + + + + + + $used = array(); -if (isset($_POST['used'])) { - if (is_array($_POST['used'])) { - $used = $_POST['used']; - } else { - $used = unserialize(stripslashes($_POST['used'])); - } +if (isset($_REQUEST['used'])) { + $used = $_REQUEST['used']; } -if (isset($_POST["entity_restrict"]) - && !is_numeric($_POST["entity_restrict"]) - && !is_array($_POST["entity_restrict"])) { - - $_POST["entity_restrict"] = unserialize(stripslashes($_POST["entity_restrict"])); +if (!isset($_REQUEST['value'])) { + $_REQUEST['value'] = 0; } -$result = PluginProcessmakerUsers::getSqlSearchResult( $_POST['pmTaskId'], false, $_POST['right'], $_POST["entity_restrict"], - $_POST['value'], $used, $_POST['searchText']); +$one_item = -1; +if (isset($_REQUEST['_one_id'])) { + $one_item = $_REQUEST['_one_id']; +} +if (!isset($_REQUEST['page'])) { + $_REQUEST['page'] = 1; + $_REQUEST['page_limit'] = $CFG_GLPI['dropdown_max']; +} + +if ($one_item < 0) { + $start = ($_REQUEST['page']-1)*$_REQUEST['page_limit']; + //$result = User::getSqlSearchResult(false, $_REQUEST['right'], $_REQUEST["entity_restrict"], + // $_REQUEST['value'], $used, $_REQUEST['searchText'], $start, + // $_REQUEST['page_limit']); + $LIMIT = "LIMIT $start,".$_REQUEST['page_limit']; + $result = PluginProcessmakerUser::getSqlSearchResult( $_REQUEST['specific_tags']['pmTaskId'], false, $_REQUEST['right'], $_REQUEST["entity_restrict"], + $_REQUEST['value'], $used, $_REQUEST['searchText'], $LIMIT); +} else { + $query = "SELECT DISTINCT `glpi_users`.* + FROM `glpi_users` + WHERE `glpi_users`.`id` = '$one_item';"; + $result = $DB->query($query); +} $users = array(); -// check if $_POST["myname"] matches _itil_\w+\[users_id\] -if( preg_match( "/^_itil_\\w+\\[users_id\\]/", $_POST["myname"] ) || preg_match( "/^_users_id_\\w+/", $_POST["myname"] )) { - // prevent use of pseudo-groups like *Raynet-Development_Intranet (TASK USE ONLY!) - $raynetPseudoGroupNoUse = true ; -} else $raynetPseudoGroupNoUse = false ; - +// Count real items returned +$count = 0; if ($DB->numrows($result)) { - while ($data=$DB->fetch_array($result)) { - if( !$raynetPseudoGroupNoUse || mb_strpos( $data["name"], "*" ) === false ) { - $users[$data["id"]] = formatUserName($data["id"], $data["name"], $data["realname"], - $data["firstname"]); - $logins[$data["id"]] = $data["name"]; - } - } + while ($data = $DB->fetch_assoc($result)) { + $users[$data["id"]] = formatUserName($data["id"], $data["name"], $data["realname"], + $data["firstname"]); + $logins[$data["id"]] = $data["name"]; + } } if (!function_exists('dpuser_cmp')) { - function dpuser_cmp($a, $b) { - return strcasecmp($a, $b); - } + function dpuser_cmp($a, $b) { + return strcasecmp($a, $b); + } } // Sort non case sensitive -uasort($users, 'dpuser_cmp'); +//uasort($users, 'dpuser_cmp'); -echo ""; + foreach ($users as $ID => $output) { + $title = sprintf(__('%1$s - %2$s'), $output, $logins[$ID]); -if (isset($_POST["comment"]) && $_POST["comment"]) { - $paramscomment = array('value' => '__VALUE__', - 'table' => "glpi_users"); - - if (isset($_POST['update_link'])) { - $paramscomment['withlink'] = "comment_link_".$_POST["myname"].$_POST["rand"]; - } - Ajax::updateItemOnSelectEvent("dropdown_".$_POST["myname"].$_POST["rand"], - "comment_".$_POST["myname"].$_POST["rand"], - $CFG_GLPI["root_doc"]."/ajax/comments.php", $paramscomment); + array_push($datas, array('id' => $ID, + 'text' => $output, + 'title' => $title)); + $count++; + } +} + + +if (($one_item >= 0) + && isset($datas[0])) { + echo json_encode($datas[0]); +} else { + $ret['results'] = $datas; + $ret['count'] = $count; + echo json_encode($ret); } -Ajax::commonDropdownUpdateItem($_POST); -?> \ No newline at end of file diff --git a/ajax/task_resume.php b/ajax/task_resume.php deleted file mode 100644 index bb1ce0c..0000000 --- a/ajax/task_resume.php +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - -
- - - - - -
-
-
 
 
 
-
- - - - -
- - - - - - - - - - - -
Task Properties
".urldecode($_REQUEST['taskname'])."
".urldecode($_REQUEST['username'])."
-
-
-
 
 
 
-
-
- - - -
-
- - - - -" ; - diff --git a/ajax/task_users.php b/ajax/task_users.php index f352316..bb8d2f0 100644 --- a/ajax/task_users.php +++ b/ajax/task_users.php @@ -7,9 +7,7 @@ // Direct access to file if (strpos($_SERVER['PHP_SELF'],"task_users.php")) { - $AJAX_INCLUDE = 1; - define('GLPI_ROOT','../../..'); - include (GLPI_ROOT."/inc/includes.php"); + include ("../../../inc/includes.php"); header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } @@ -18,15 +16,16 @@ if (!defined('GLPI_ROOT')) { die("Can not acces directly to this file"); } -include_once dirname(__FILE__)."/../inc/processmaker.class.php" ; -include_once dirname(__FILE__)."/../inc/users.class.php" ; +//include_once dirname(__FILE__)."/../inc/processmaker.class.php" ; +//include_once dirname(__FILE__)."/../inc/users.class.php" ; Session::checkLoginUser(); +$PM_DB = new PluginProcessmakerDB ; $rand = rand(); echo "
"; - echo $LANG['processmaker']['item']['reassigncase']." "; + echo $LANG['processmaker']['item']['reassigncase']." "; echo ""; echo ""; echo ""; @@ -36,15 +35,16 @@ echo ""; echo ""; - PluginProcessmakerUsers::dropdown( array('name' => 'users_id_recipient', - 'value' => PluginProcessmakerProcessmaker::getGLPIUserId( $_REQUEST['userId'] ), - 'entity' => 0, //$item->fields["entities_id"], - 'entity_sons' => true, - 'right' => 'all', + PluginProcessmakerUser::dropdown( array('name' => 'users_id_recipient', + 'value' => PluginProcessmakerUser::getGLPIUserId( $_REQUEST['userId'] ), + 'entity' => 0, //$item->fields["entities_id"], // not used, as any user can be assigned to any tasks + 'entity_sons' => false, // not used, as any user can be assigned to any tasks + 'right' => 'all', 'rand' => $rand, - 'pmTaskId' => $_REQUEST['taskId'])); + 'width' => '', + 'specific_tags' => array('pmTaskId' => $_REQUEST['taskId']))); echo "  "; echo ""; -echo "
"; - -?> \ No newline at end of file + Html::closeForm(true); +//echo ""; + diff --git a/front/cases.front.php b/front/cases.front.php index bf066c7..8e82daa 100644 --- a/front/cases.front.php +++ b/front/cases.front.php @@ -1,86 +1,153 @@ getFromDB( $_REQUEST['APP_UID'] ) ) { $myProcessMaker = new PluginProcessmakerProcessmaker() ; $myProcessMaker->login( ) ; - + if( isset( $_REQUEST['form'] ) ) { // save the case variables //$resultSave = $myProcessMaker->sendVariables( $myCase->getID() , $_REQUEST['form'] ) ; - $resultSave = $myProcessMaker->saveForm( $_REQUEST, $_SERVER['HTTP_COOKIE'] ) ; + $resultSave = $myProcessMaker->saveForm( $_REQUEST, $_SERVER['HTTP_COOKIE'] ) ; //$myCase->sendVariables( $_REQUEST['form'] ) ; - + // now derivate the case !!! $pmRouteCaseResponse = $myProcessMaker->routeCase( $myCase->getID(), $_REQUEST['DEL_INDEX']) ; - + // 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_TASK_CONTENT", "GLPI_ITEM_APPEND_TO_TASK", "GLPI_NEXT_GROUP_TO_BE_ASSIGNED" ) ); - if( array_key_exists( 'GLPI_ITEM_APPEND_TO_TASK', $txtForTasks ) ) - $txtToAppendToTask = $txtForTasks[ 'GLPI_ITEM_APPEND_TO_TASK' ] ; - else - $txtToAppendToTask = '' ; - if( array_key_exists( 'GLPI_ITEM_TASK_CONTENT', $txtForTasks ) ) - $txtTaskContent = $txtForTasks[ 'GLPI_ITEM_TASK_CONTENT' ] ; - else - $txtTaskContent = '' ; - if( array_key_exists( 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED', $txtForTasks ) ) - $groupId = $txtForTasks[ 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED' ] ; - else - $groupId = 0 ; - + $infoForTasks = $myProcessMaker->getVariables( $myCase->getID(), array( "GLPI_ITEM_TASK_CONTENT", + "GLPI_ITEM_APPEND_TO_TASK", + "GLPI_NEXT_GROUP_TO_BE_ASSIGNED", + "GLPI_ITEM_TITLE", + "GLPI_TICKET_FOLLOWUP_CONTENT", + "GLPI_TICKET_FOLLOWUP_IS_PRIVATE", + "GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID", + "GLPI_ITEM_TASK_ENDDATE", + "GLPI_ITEM_TASK_STARTDATE", + "GLPI_ITEM_SET_STATUS" + ) ); + $itemSetStatus = ''; + if( array_key_exists( 'GLPI_ITEM_SET_STATUS', $infoForTasks ) ) { + $itemSetStatus = $infoForTasks[ 'GLPI_ITEM_SET_STATUS' ] ; + } + + $txtItemTitle = '' ; + if( array_key_exists( 'GLPI_ITEM_TITLE', $infoForTasks ) ) { + $txtItemTitle = $infoForTasks[ 'GLPI_ITEM_TITLE' ] ; + } + + $txtToAppendToTask = '' ; + if( array_key_exists( 'GLPI_ITEM_APPEND_TO_TASK', $infoForTasks ) ) { + $txtToAppendToTask = $infoForTasks[ 'GLPI_ITEM_APPEND_TO_TASK' ] ; + } + + $txtTaskContent = '' ; + if( array_key_exists( 'GLPI_ITEM_TASK_CONTENT', $infoForTasks ) ) { + $txtTaskContent = $infoForTasks[ 'GLPI_ITEM_TASK_CONTENT' ] ; + } + + $groupId = 0 ; + if( array_key_exists( 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED', $infoForTasks ) ) { + $groupId = $infoForTasks[ 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED' ] ; + } + + $taskStartDate = '' ; + $taskEndDate = '' ; + if( array_key_exists( 'GLPI_ITEM_TASK_ENDDATE', $infoForTasks ) ) { + $taskEndDate = $infoForTasks[ 'GLPI_ITEM_TASK_ENDDATE' ] ; + } + if( array_key_exists( 'GLPI_ITEM_TASK_STARTDATE', $infoForTasks ) ) { + $taskStartDate = $infoForTasks[ 'GLPI_ITEM_TASK_STARTDATE' ] ; + if( $taskEndDate == '' ) { + // at least + $taskEndDate = $taskStartDate ; + } + } + + $createFollowup = false ; // by default + if( array_key_exists( 'GLPI_TICKET_FOLLOWUP_CONTENT', $infoForTasks ) && $infoForTasks[ 'GLPI_TICKET_FOLLOWUP_CONTENT' ] != '') { + //&& array_key_exists( 'GLPI_TICKET_FOLLOWUP_IS_PRIVATE', $infoForTasks ) + //&& array_key_exists( 'GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID', $infoForTasks ) + $createFollowup = true ; + } // reset those variables - $resultSave = $myProcessMaker->sendVariables( $myCase->getID() , array( "GLPI_ITEM_APPEND_TO_TASK" => '', 'GLPI_ITEM_TASK_CONTENT' => '', 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED' => '' ) ) ; - + $resultSave = $myProcessMaker->sendVariables( $myCase->getID() , array( "GLPI_ITEM_APPEND_TO_TASK" => '', + "GLPI_ITEM_TASK_CONTENT" => '', + "GLPI_NEXT_GROUP_TO_BE_ASSIGNED" => '', + "GLPI_TICKET_FOLLOWUP_CONTENT" => '', + "GLPI_TICKET_FOLLOWUP_IS_PRIVATE" => '', + "GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID" => '', + "GLPI_ITEM_TASK_ENDDATE" => '', + "GLPI_ITEM_TASK_STARTDATE" => '', + 'GLPI_ITEM_TITLE' => '', + "GLPI_ITEM_SET_STATUS" => '' + ) ) ; + // print_r( $pmRouteCaseResponse ) ; // die() ; - + // now manage tasks associated with item $itemType = $myCase->getField('itemtype'); $itemId = $myCase->getField('items_id'); - + // switch own task to 'done' and create a new one $myProcessMaker->solveTask( $myCase->getID(), $_REQUEST['DEL_INDEX'], $txtToAppendToTask ) ; + + // create a followup if requested + if( $createFollowup && $itemType == 'Ticket' ) { + $myProcessMaker->addTicketFollowup( $itemId, $infoForTasks ) ; + } $caseInfo = $myProcessMaker->getCaseInfo( $myCase->getID(), $_REQUEST['DEL_INDEX']) ; if( property_exists( $pmRouteCaseResponse, 'routing' ) ) { - foreach( $pmRouteCaseResponse->routing as $route ) { - $myProcessMaker->addTask( $itemType, $itemId, $caseInfo, $route->delIndex, PluginProcessmakerProcessmaker::getGLPIUserId( $route->userId ), $groupId, $route->taskId, $txtTaskContent ) ; + foreach( $pmRouteCaseResponse->routing as $route ) { + $myProcessMaker->addTask( $itemType, $itemId, $caseInfo, $route->delIndex, PluginProcessmakerUser::getGLPIUserId( $route->userId ), $groupId, $route->taskId, $txtTaskContent, $taskStartDate, $taskEndDate ) ; + // if end date was specicied, then must change due date of the PM task + if( $taskEndDate != '' ) { + $PM_DB->query( "UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$taskEndDate' WHERE APP_UID='".$caseInfo->caseId."' AND DEL_INDEX=".$route->delIndex); + } } } - + if( $txtItemTitle != '') { + // we are going to change the title of current GLPI Item + $item = new $itemType ; + $item->getFromDB( $itemId ) ; + $item->update( array('id' => $itemId, 'name' => $txtItemTitle) ) ; + } + + if( $itemSetStatus != '' ) { + $myProcessMaker->setItemStatus($itemType, $itemId, $itemSetStatus ) ; + } // evolution of case status: DRAFT, TO_DO, COMPLETED, CANCELLED - $myCase->update( array( 'id' => $myCase->getID(), 'case_status' => $caseInfo->caseStatus ) ) ; - - } - } + $myCase->update( array( 'id' => $myCase->getID(), 'case_status' => $caseInfo->caseStatus ) ) ; + + } + } } // Claim task management elseif( isset( $_REQUEST['form'] ) && isset( $_REQUEST['form']['BTN_CATCH'] ) && isset( $_REQUEST['form']['APP_UID']) ){ // here we are in a Claim request - $myCase = new PluginProcessmakerCases ; + $myCase = new PluginProcessmakerCase ; if( $myCase->getFromDB( $_REQUEST['form']['APP_UID'] ) ) { $myProcessMaker = new PluginProcessmakerProcessmaker() ; $myProcessMaker->login( ) ; - + $pmClaimCase = $myProcessMaker->claimCase( $myCase->getID(), $_REQUEST['DEL_INDEX'] ) ; - + // now manage tasks associated with item - $myProcessMaker->claimTask( $myCase->getID(), $_REQUEST['DEL_INDEX'] ) ; + $myProcessMaker->claimTask( $myCase->getID(), $_REQUEST['DEL_INDEX'] ) ; } - + } // now redirect to item form page //Html::redirect( Toolbox::getItemTypeFormURL($myCase->getField('itemtype'))); -echo "" ; +echo "" ; -?> \ No newline at end of file diff --git a/front/config.form.php b/front/config.form.php index 46f3925..5578a36 100644 --- a/front/config.form.php +++ b/front/config.form.php @@ -2,22 +2,25 @@ /** */ -define('GLPI_ROOT', '../../..'); -include (GLPI_ROOT . "/inc/includes.php"); +include ( "../../../inc/includes.php"); // No autoload when plugin is not activated -require_once('../inc/config.class.php'); +//require_once('../inc/config.class.php'); $config = new PluginProcessmakerConfig(); if (isset($_POST["update"])) { - $config->check($_POST['id'],'w'); - + $config->check($_POST['id'], UPDATE); + + // save $config->update($_POST); + Html::back(); + } elseif (isset($_POST["refresh"])) { $config->refresh($_POST); // used to refresh process list, task category list Html::back(); -} +} + Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=". urlencode('PluginProcessmakerConfig$1')); diff --git a/front/process.form.php b/front/process.form.php index 4e4d7a7..0038c8d 100644 --- a/front/process.form.php +++ b/front/process.form.php @@ -12,21 +12,22 @@ if (!isset($_REQUEST["id"])) { $PluginProcess = new PluginProcessmakerProcess(); if (isset($_REQUEST["update"])) { - $PluginProcess->check($_REQUEST['id'], 'w'); + $PluginProcess->check($_REQUEST['id'], UPDATE); $PluginProcess->update($_REQUEST); Html::back(); } elseif (isset($_REQUEST["refreshtask"])) { - $PluginProcess->check($_REQUEST['id'], 'w'); + $PluginProcess->check($_REQUEST['id'], UPDATE); $PluginProcess->refreshTasks($_REQUEST); Html::back(); } else { - $PluginProcess->checkGlobal('r'); - + // $PluginProcess->checkGlobal(READ); Html::header($LANG['processmaker']['title'][1],$_SERVER["PHP_SELF"],"plugins","processmaker"); - $PluginProcess->showForm($_REQUEST["id"]); + $PluginProcess->display($_REQUEST) ; + + // $PluginProcess->showForm($_REQUEST["id"]); Html::footer(); } diff --git a/front/process.php b/front/process.php index 2f5dccb..66d793d 100644 --- a/front/process.php +++ b/front/process.php @@ -5,10 +5,10 @@ include (GLPI_ROOT."/inc/includes.php"); Html::header($LANG['processmaker']['title'][1], $_SERVER['PHP_SELF'], "plugins", "processmaker"); -if (plugin_processmaker_haveRight("process_config","r") || Session::haveRight("config","w")) { +if (Session::haveRight("plugin_processmaker_config",READ) || Session::haveRight("config", UPDATE)) { $process=new PluginProcessmakerProcess(); - if( isset( $_REQUEST['refresh'] ) && plugin_processmaker_haveRight("process_config","w") ) { + if( isset( $_REQUEST['refresh'] ) && Session::haveRight("plugin_processmaker_config",UPDATE) ) { $process->refresh(); Html::back(); } diff --git a/front/process_profile.form.php b/front/process_profile.form.php index e656e03..fc1da8d 100644 --- a/front/process_profile.form.php +++ b/front/process_profile.form.php @@ -1,7 +1,7 @@ check(-1,'w',$_POST); + $right->check(-1,UPDATE,$_POST); if ($right->add($_POST)) { //Event::log($_POST["processes_id"], "PluginProcessMakerProcess", 4, "setup", // $_SESSION["glpiname"]." ".$LANG['log'][61]); @@ -23,7 +23,7 @@ if (isset($_POST["add"])) { if (isset($_POST["item"]) && count($_POST["item"])) { foreach ($_POST["item"] as $key => $val) { if ($val == 1) { - if ($right->can($key,'w')) { + if ($right->can($key,UPDATE)) { $right->delete(array('id' => $key)); } } diff --git a/front/processmaker.form.php b/front/processmaker.form.php index 55df0a9..755c10d 100644 --- a/front/processmaker.form.php +++ b/front/processmaker.form.php @@ -1,9 +1,7 @@ login() ; //openSession(); - $requesters = PluginProcessmakerProcessmaker::getItemUsers( $_POST['itemtype'], $_POST['id'], 1 ) ; // 1 for requesters - if( !key_exists( 0, $requesters ) ) { - $requesters[0]['glpi_id'] = 0 ; - $requesters[0]['pm_id'] = 0 ; - } - - //$technicians = PluginProcessmakerProcessmaker::getItemUsers( $_POST['itemtype'], $_POST['id'], 2 ) ; // 2 for technicians - //if( !key_exists( 0, $technicians ) ) { - // $technicians[0]['glpi_id'] = Session::getLoginUserID() ; - // $technicians[0]['pm_id'] = PluginProcessmakerProcessmaker::getPMUserId( Session::getLoginUserID() ) ; - //} - - // get item info to retreive title, description and duedate - $locTicket = new $_POST['itemtype'] ; //Ticket(); - $locTicket->getFromDB( $_POST['id'] ) ; - - if($locTicket->countUsers($locTicket::ASSIGN) == 0 - || !$locTicket->isUser($locTicket::ASSIGN, Session::getLoginUserID()) ){ - $locTicket->update( array( 'id' => $_POST['id'], '_itil_assign' => array( '_type' => 'user', 'users_id' => Session::getLoginUserID() ) ) ) ; - } - - //$writer = PluginProcessmakerProcessmaker::getPMUserId( Session::getLoginUserID() ); - if( !isset($locTicket->fields['due_date']) || $locTicket->fields['due_date'] == null ) { - $locTicket->fields['due_date'] = ""; - } - - $resultCase = $myProcessMaker->newCase( $_POST['plugin_processmaker_process_id'], - array( 'GLPI_ITEM_CAN_BE_SOLVED' => 0, - 'GLPI_TICKET_ID' => $_POST['id'], - 'GLPI_ITEM_TYPE' => $_POST['itemtype'], - 'GLPI_TICKET_REQUESTER_GLPI_ID' => $requesters[0]['glpi_id'], - 'GLPI_TICKET_REQUESTER_PM_ID' => $requesters[0]['pm_id'], - 'GLPI_TICKET_TITLE' => $locTicket->fields['name'], - 'GLPI_TICKET_DESCRIPTION' => $locTicket->fields['content'], - 'GLPI_TICKET_DUE_DATE' => $locTicket->fields['due_date'], - 'GLPI_TICKET_URGENCY' => $locTicket->fields['urgency'], - 'GLPI_ITEM_IMPACT' => $locTicket->fields['impact'], - 'GLPI_ITEM_PRIORITY' => $locTicket->fields['priority'], - 'GLPI_TICKET_GLOBAL_VALIDATION' => $locTicket->fields['global_validation'] , - 'GLPI_TICKET_TECHNICIAN_GLPI_ID' => Session::getLoginUserID(), //$technicians[0]['glpi_id'], - 'GLPI_TICKET_TECHNICIAN_PM_ID' => PluginProcessmakerProcessmaker::getPMUserId( Session::getLoginUserID() ) //$technicians[0]['pm_id'] - ) ) ; + $resultCase = $myProcessMaker->startNewCase( $_POST['plugin_processmaker_process_id'], $_POST['itemtype'], $_POST['id'], Session::getLoginUserID() ) ; if ($resultCase->status_code == 0){ - $caseInfo = $myProcessMaker->getCaseInfo( $resultCase->caseId ); - - //$query = "UPDATE APPLICATION SET APP_STATUS='TO_DO' WHERE APP_UID='".$resultCase->caseId."' AND APP_STATUS='DRAFT'" ; - //$res = $DB->query($query) ; - // save info to DB - $query = "INSERT INTO glpi_plugin_processmaker_cases (items_id, itemtype, id, case_num, case_status, processes_id) VALUES (".$_POST['id'].", '".$_POST['itemtype']."', '".$resultCase->caseId."', ".$resultCase->caseNumber.", '".$caseInfo->caseStatus."', '".$caseInfo->processId."');" ; - $res = $DB->query($query) ; - - $myProcessMaker->add1stTask($_POST['itemtype'], $_POST['id'], $caseInfo ) ; - - //echo "New case ID: $result->caseId, Case No: $result->caseNumber \n"; Html::back(); } else - Session::addMessageAfterRedirect($LANG['processmaker']['item']['error'][$resultCase->status_code]."
$resultCase->message ($resultCase->status_code)", true, ERROR); //echo "Error creating case: $resultCase->message \n"; + Session::addMessageAfterRedirect($LANG['processmaker']['item']['error'][$resultCase->status_code]."
".$resultCase->message." (".$resultCase->status_code.")", true, ERROR); } else Html::back(); } - else { // the case is created before the ticket (used for user management before ticket creation) - // list of requesters is needed - // so read ticket - //$requesters = array( ) ; - - - //foreach( $DB->request( $query ) as $dbuser ) { - // $requesters[] = $dbuser['pm_users_id'] ; - //} - //$writer = PluginProcessmakerProcessmaker::getPMUserId( Session::getLoginUserID() ); - //$userGLPI = new User(); - //$userGLPI->getFromDB( Session::getLoginUserID() ) ; - //if( $userGLPI->fields['language'] != null ) - // $lang = substr( $userGLPI->fields['language'], 0, 2) ; - //else - // $lang = "en" ; + else { // the case is created before the ticket (used for post-only case creation before ticket creation) $myProcessMaker = new PluginProcessmakerProcessmaker() ; - $myProcessMaker->login() ; //openSession( $userGLPI->fields['name'], "md5:37d442efb43ebb80ec6f9649b375ab72", $lang) ; + $myProcessMaker->login() ; - //$resultCase = $myProcessMaker->newCaseImpersonate( $_POST['plugin_processmaker_process_id'], $writer) ; - $resultCase = $myProcessMaker->newCase( $_POST['plugin_processmaker_process_id'], array( 'GLPI_ITEM_CAN_BE_SOLVED' => 0 ) ) ; + $resultCase = $myProcessMaker->newCase( $_POST['plugin_processmaker_process_id'], array( 'GLPI_ITEM_CAN_BE_SOLVED' => 0, 'GLPI_SELFSERVICE_CREATED' => '1') ) ; if ($resultCase->status_code == 0){ // case is created // Must show it... @@ -106,11 +36,6 @@ switch( $_POST["action"] ) { Html::redirect($CFG_GLPI['root_doc']."/plugins/processmaker/front/processmaker.helpdesk.form.php?process_id=".$_POST['plugin_processmaker_process_id']."&case_id=".$resultCase->caseId."&rand=$rand&itilcategories_id=".$_POST["itilcategories_id"]."&type=".$_REQUEST["type"]); } else { - //Html::helpHeader($LANG['job'][13], $_SERVER['PHP_SELF'], $_SESSION["glpiname"]); - //// case is not created show error message - //echo "Error : ".$resultCase->status_code."
" ; - //echo $resultCase->message."
" ; - //Html::helpFooter(); Session::addMessageAfterRedirect($LANG['processmaker']['item']['error'][$resultCase->status_code]."
$resultCase->message ($resultCase->status_code)", true, ERROR); //echo "Error creating case: $resultCase->message \n"; Html::redirect($CFG_GLPI["root_doc"]."/front/helpdesk.public.php?create_ticket=1"); } @@ -131,7 +56,7 @@ switch( $_POST["action"] ) { } else if( isset( $_POST['reassign'] ) ) { // here we should re-assign the current task to $_POST['users_id_recipient'] - $GLPINewPMUserId = PluginProcessmakerProcessmaker::getPMUserId( $_POST['users_id_recipient'] ) ; + $GLPINewPMUserId = PluginProcessmakerUser::getPMUserId( $_POST['users_id_recipient'] ) ; if( $_POST['plugin_processmaker_userId'] != $GLPINewPMUserId ) { $locPM = new PluginProcessmakerProcessmaker() ; $locPM->login( ) ; @@ -160,12 +85,12 @@ switch( $_POST["action"] ) { } else if( isset($_POST['delete']) ) { // delete case from case table, this will also delete the tasks - $locCase = new PluginProcessmakerCases ; + $locCase = new PluginProcessmakerCase ; $locCase->getFromDB( $_POST['plugin_processmaker_caseId'] ) ; if( $locCase->deleteCase() ) { // request delete from pm itself $myProcessMaker = new PluginProcessmakerProcessmaker() ; - $myProcessMaker->login() ; + $myProcessMaker->login(true) ; $resultPM = $myProcessMaker->deleteCase( $_POST['plugin_processmaker_caseId'] ) ; if( $resultPM->status_code == 0 ) { @@ -181,7 +106,7 @@ switch( $_POST["action"] ) { $myProcessMaker->login() ; $resultPM = $myProcessMaker->cancelCase( $_POST['plugin_processmaker_caseId'] ) ; //, $_POST['plugin_processmaker_delIndex'], $_POST['plugin_processmaker_userId'] ) ; if( $resultPM->status_code === 0 ) { - $locCase = new PluginProcessmakerCases ; + $locCase = new PluginProcessmakerCase ; $locCase->getFromDB( $_POST['plugin_processmaker_caseId'] ) ; if( $locCase->cancelCase() ) Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['cancelled'], true, INFO); @@ -198,4 +123,3 @@ switch( $_POST["action"] ) { // to return to ticket Html::back(); -?> \ No newline at end of file diff --git a/front/processmaker.helpdesk.form.php b/front/processmaker.helpdesk.form.php index 7c4a5ec..3392ca4 100644 --- a/front/processmaker.helpdesk.form.php +++ b/front/processmaker.helpdesk.form.php @@ -1,13 +1,11 @@ "; echo ""; - + echo ""; @@ -33,458 +31,1484 @@ function processMakerShowProcessList ($ID, $from_helpdesk) { } +///** +//* Print the helpdesk form +//* +//* @param $ID int : ID of the user who want to display the Helpdesk +//* @param $ticket_template int : ID ticket template for preview : false if not used for preview +//* +//* @return nothing (print the helpdesk) +//**/ +//function showFormHelpdeskbak($ID, $pmItem, $caseInfo, $ticket_template=false) { +// global $DB, $CFG_GLPI, $LANG; + +// if (!Session::haveRight("ticket", CREATE)) { +// return false; +// } + +// $query = "SELECT `realname`, `firstname`, `name` +// FROM `glpi_users` +// WHERE `id` = '$ID'"; +// $result = $DB->query($query); + + +// $email = UserEmail::getDefaultForUser($ID); + + +// // Set default values... +// $default_values = array('_users_id_requester_notif' => array('use_notification' => ($email==""?0:1), +// 'alternative_email' => ''), +// 'nodelegate' => 1, +// '_users_id_requester' => 0, +// 'name' => '', +// 'content' => '', +// 'itilcategories_id' => 0, +// 'urgency' => 3, +// 'itemtype' => '', +// 'entities_id' => $_SESSION['glpiactive_entity'], +// 'items_id' => 0, +// 'plan' => array(), +// 'global_validation' => 'none', +// 'due_date' => 'NULL', +// 'slas_id' => 0, +// '_add_validation' => 0, +// 'type' => 1, +// '_right' => "id"); + +// if (!$ticket_template) { +// $options = $_REQUEST; +// } + +// // Restore saved value or override with page parameter +// foreach ($default_values as $name => $value) { +// if (!isset($options[$name])) { +// if (isset($_SESSION["helpdeskSaved"][$name])) { +// $options[$name] = $_SESSION["helpdeskSaved"][$name]; +// } else { +// $options[$name] = $value; +// } +// } +// } +// // Clean text fields +// $options['name'] = stripslashes($options['name']); +// $options['content'] = Html::cleanPostForTextArea($options['content']); + +// if (!$ticket_template) { +// echo ""; +// } + + +// $delegating = User::getDelegateGroupsForUser($options['entities_id']); + +// if (count($delegating)) { +// echo "
".$LANG['processmaker']['item']['tab']."
"; echo $LANG['processmaker']['item']['selectprocess']." "; echo ""; echo ""; echo ""; // Dropdown::show('PluginProcessmakerProcessmaker', array( 'name' => 'plugin_processmaker_process_id', 'condition' => "is_active=1 and is_helpdeskvisible=1")); // condition is used to prevent start of none-active and none-helpdesk-visible cases - PluginProcessmakerProcess::dropdown( array( 'entity' => $_SESSION['glpiactive_entity'], 'name' => 'plugin_processmaker_process_id' )); + PluginProcessmakerProcess::dropdown( array( 'entity' => $_SESSION['glpiactive_entity'], 'name' => 'plugin_processmaker_process_id' )); echo ""; echo ""; echo "
"; +// echo ""; +// echo ""; + +// echo "
".$LANG['job'][69]." : "; + +// $rand = Dropdown::showYesNo("nodelegate", $options['nodelegate']); + +// $params = array ('nodelegate' => '__VALUE__', +// 'rand' => $rand, +// 'right' => "delegate", +// '_users_id_requester' +// => $options['_users_id_requester'], +// '_users_id_requester_notif' +// => $options['_users_id_requester_notif'], +// 'use_notification' +// => $options['_users_id_requester_notif']['use_notification'], +// 'entity_restrict' +// => $_SESSION["glpiactive_entity"]); + +// Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate".$rand, "show_result".$rand, +// $CFG_GLPI["root_doc"]."/ajax/dropdownDelegationUsers.php", +// $params); + +// echo "
"; +// echo "
"; + +// $self = new Ticket(); +// if ($options["_users_id_requester"] == 0) { +// $options['_users_id_requester'] = Session::getLoginUserID(); +// } else { +// $options['_right'] = "delegate"; +// } +// $self->showActorAddFormOnCreate(Ticket::REQUESTER, $options); +// echo "
"; +// echo "
"; +// echo ""; +// } + +// echo ""; +// echo ""; + + +// // Load ticket template if available : +// $tt = new TicketTemplate(); + +// // First load default entity one +// if ($template_id = EntityData::getUsedConfig('tickettemplates_id', $_SESSION["glpiactive_entity"])) { +// // with type and categ +// $tt->getFromDBWithDatas($template_id, true); +// } + +// $field = ''; +// if ($options['type'] && $options['itilcategories_id']) { +// $categ = new ITILCategory(); +// if ($categ->getFromDB($options['itilcategories_id'])) { +// switch ($options['type']) { +// case Ticket::INCIDENT_TYPE : +// $field = 'tickettemplates_id_incident'; +// break; + +// case Ticket::DEMAND_TYPE : +// $field = 'tickettemplates_id_demand'; +// break; +// } + +// if (!empty($field) && $categ->fields[$field]) { +// // without type and categ +// $tt->getFromDBWithDatas($categ->fields[$field], false); +// } +// } +// } +// if ($ticket_template) { +// // with type and categ +// $tt->getFromDBWithDatas($ticket_template, true); +// } + +// // Predefined fields from template : reset them +// if (isset($options['_predefined_fields'])) { +// $options['_predefined_fields'] +// = unserialize(rawurldecode(stripslashes($options['_predefined_fields']))); +// } else { +// $options['_predefined_fields'] = array(); +// } + +// // Store predefined fields to be able not to take into account on change template +// $predefined_fields = array(); + +// if (isset($tt->predefined) && count($tt->predefined)) { +// foreach ($tt->predefined as $predeffield => $predefvalue) { +// if (isset($options[$predeffield]) && isset($default_values[$predeffield])) { +// // Is always default value : not set +// // Set if already predefined field +// // Set if ticket template change +// if ($options[$predeffield] == $default_values[$predeffield] +// || (isset($options['_predefined_fields'][$predeffield]) +// && $options[$predeffield] == $options['_predefined_fields'][$predeffield]) +// || (isset($options['_tickettemplates_id']) +// && $options['_tickettemplates_id'] != $tt->getID())) { +// $options[$predeffield] = $predefvalue; +// $predefined_fields[$predeffield] = $predefvalue; +// } +// } else { // Not defined options set as hidden field +// echo ""; +// } +// } + +// } else { // No template load : reset predefined values +// if (count($options['_predefined_fields'])) { +// foreach ($options['_predefined_fields'] as $predeffield => $predefvalue) { +// if ($options[$predeffield] == $predefvalue) { +// $options[$predeffield] = $default_values[$predeffield]; +// } +// } +// } +// } +// unset($_SESSION["helpdeskSaved"]); + +// if ($CFG_GLPI['urgency_mask']==(1<<3) || $tt->isHiddenField('urgency')) { +// // Dont show dropdown if only 1 value enabled or field is hidden +// echo ""; +// } + +// // Display predefined fields if hidden +// if ($tt->isHiddenField('itemtype')) { +// echo ""; +// echo ""; +// } + +// echo ""; +// echo "
"; + +// echo ""; + +// echo ""; +// echo ""; +// echo ""; + +// echo ""; +// echo ""; + + +// if ($CFG_GLPI['urgency_mask']!=(1<<3)) { +// if (!$tt->isHiddenField('urgency')) { +// echo ""; +// echo ""; +// echo ""; +// } +// } + +// if (empty($delegating) && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) { +// echo ""; +// echo ""; +// echo ""; +// } + +// if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0) { +// if (!$tt->isHiddenField('itemtype')) { +// echo ""; +// echo ""; +// echo ""; +// } +// } + +// if (!$tt->isHiddenField('name') +// || $tt->isPredefinedField('name')) { +// echo ""; +// echo ""; +// echo ""; +// } + +// if (!$tt->isHiddenField('content') +// || $tt->isPredefinedField('content')) { +// echo ""; +// echo ""; +// echo ""; +// } +// echo ""; +// echo ""; + + +// echo ""; +// echo ""; + +// echo ""; + +// echo ""; +// echo ""; +// echo ""; + +// if (!$ticket_template) { +// echo ""; +// echo ""; +// } + +// echo "
".$caseInfo->processName." : "; +// if (Session::isMultiEntitiesMode()) { +// echo " (".Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]).")"; +// } +// echo "
".$LANG['joblist'][29]." :".$tt->getMandatoryMark('urgency').""; +// Ticket::dropdownUrgency("urgency", $options['urgency']); +// echo "
".$LANG['help'][8]." : "; +// if ($options["_users_id_requester"] == 0) { +// $options['_users_id_requester'] = Session::getLoginUserID(); +// } +// $_REQUEST['value'] = $options['_users_id_requester']; +// $_REQUEST['field'] = '_users_id_requester_notif'; +// $_REQUEST['use_notification'] = $options['_users_id_requester_notif']['use_notification']; +// include (GLPI_ROOT."/ajax/uemailUpdate.php"); + +// echo "
 "; +// echo "
"; +// $rand = rand(); +// $pmCaseUser = $caseInfo->currentUsers[0] ; // by default +// $paramsURL = "DEL_INDEX=".$pmCaseUser->delIndex."&action=".$caseInfo->caseStatus ; + +// echo ""; +// echo "
 "; +// echo "
".$LANG['document'][2]." (".Document::getMaxUploadSize().") : "; +// echo "".
+//            $LANG["; + +// echo " "; +// Ticket::showDocumentAddButton(60); + +// echo "
"; + +// echo "
"; +// if (!$ticket_template) { +// Html::closeForm(); +// } +//} + + /** -* Print the helpdesk form -* -* @param $ID int : ID of the user who want to display the Helpdesk -* @param $ticket_template int : ID ticket template for preview : false if not used for preview -* -* @return nothing (print the helpdesk) -**/ + * Print the helpdesk form + * + * @param $ID integer ID of the user who want to display the Helpdesk + * @param $ticket_template boolean ticket template for preview : false if not used for preview + * (false by default) + * + * @return nothing (print the helpdesk) + **/ +//function showFormHelpdesk($ID, $pmItem, $caseInfo, $ticket_template=false) { +// global $DB, $CFG_GLPI; + +// if (!Ticket::canCreate()) { +// return false; +// } + +// if (!$ticket_template +// && Session::haveRightsOr('ticketvalidation', TicketValidation::getValidateRights())) { + +// $opt = array(); +// $opt['reset'] = 'reset'; +// $opt['criteria'][0]['field'] = 55; // validation status +// $opt['criteria'][0]['searchtype'] = 'equals'; +// $opt['criteria'][0]['value'] = CommonITILValidation::WAITING; +// $opt['criteria'][0]['link'] = 'AND'; + +// $opt['criteria'][1]['field'] = 59; // validation aprobator +// $opt['criteria'][1]['searchtype'] = 'equals'; +// $opt['criteria'][1]['value'] = Session::getLoginUserID(); +// $opt['criteria'][1]['link'] = 'AND'; + +// $url_validate = $CFG_GLPI["root_doc"]."/front/ticket.php?".Toolbox::append_params($opt, +// '&'); + +// if (TicketValidation::getNumberToValidate(Session::getLoginUserID()) > 0) { +// echo "". +// __('Tickets awaiting approval')."

"; +// } +// } + +// $query = "SELECT `realname`, `firstname`, `name` +// FROM `glpi_users` +// WHERE `id` = '$ID'"; +// $result = $DB->query($query); + + +// $email = UserEmail::getDefaultForUser($ID); +// $default_use_notif = Entity::getUsedConfig('is_notif_enable_default', $_SESSION['glpiactive_entity'], '', 1); + +// // Set default values... +// $default_values = array('_users_id_requester_notif' +// => array('use_notification' +// => (($email == "")?0:$default_use_notif)), +// 'nodelegate' => 1, +// '_users_id_requester' => 0, +// '_users_id_observer' => 0, +// '_users_id_observer_notif' +// => array('use_notification' => $default_use_notif), +// 'name' => '', +// 'content' => '', +// 'itilcategories_id' => 0, +// 'locations_id' => 0, +// 'urgency' => 3, +// 'itemtype' => '', +// 'items_id' => 0, +// 'entities_id' => $_SESSION['glpiactive_entity'], +// 'plan' => array(), +// 'global_validation' => CommonITILValidation::NONE, +// '_add_validation' => 0, +// 'type' => Entity::getUsedConfig('tickettype', +// $_SESSION['glpiactive_entity'], +// '', Ticket::INCIDENT_TYPE), +// '_right' => "id", +// '_filename' => array(), +// '_tag_filename' => array()); + +// // Get default values from posted values on reload form +// if (!$ticket_template) { +// if (isset($_POST)) { +// $values = Html::cleanPostForTextArea($_POST); +// } +// } + +// $ticket = new Ticket(); +// // Restore saved value or override with page parameter +// if( !function_exists('restoreInput') ) { +// function restoreInput(Array $default=array()) { + +// if (isset($_SESSION['saveInput']['Ticket'])) { +// $saved = Html::cleanPostForTextArea($_SESSION['saveInput']['Ticket']); + +// // clear saved data when restored (only need once) +// unset($_SESSION['saveInput']['Ticket']); + +// return $saved; +// } + +// return $default; +// } +// } + +// $saved = restoreInput(); +// foreach ($default_values as $name => $value) { +// if (!isset($values[$name])) { +// if (isset($saved[$name])) { +// $values[$name] = $saved[$name]; +// } else { +// $values[$name] = $value; +// } +// } +// } + + +// if (!$ticket_template) { +// echo ""; +// } + + +// $delegating = User::getDelegateGroupsForUser($values['entities_id']); + +// if (count($delegating)) { +// echo "
"; +// echo ""; +// echo ""; + +// echo "
".__('This ticket concerns me')." "; + +// $rand = Dropdown::showYesNo("nodelegate", $values['nodelegate']); + +// $params = array('nodelegate' => '__VALUE__', +// 'rand' => $rand, +// 'right' => "delegate", +// '_users_id_requester' +// => $values['_users_id_requester'], +// '_users_id_requester_notif' +// => $values['_users_id_requester_notif'], +// 'use_notification' +// => $values['_users_id_requester_notif']['use_notification'], +// 'entity_restrict' +// => $_SESSION["glpiactive_entity"]); + +// Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate".$rand, "show_result".$rand, +// $CFG_GLPI["root_doc"]."/ajax/dropdownDelegationUsers.php", +// $params); + +// $class = 'right'; +// if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { +// echo "".__('Check your personnal information'); +// $class = 'center'; +// } + +// echo "
"; +// echo "
"; + +// $self = $ticket; +// if ($values["_users_id_requester"] == 0) { +// $values['_users_id_requester'] = Session::getLoginUserID(); +// } else { +// $values['_right'] = "delegate"; +// } +// $self->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $values); +// echo "
"; +// if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { +// echo "
"; +// User::showPersonalInformation(Session::getLoginUserID()); +// } +// echo "
"; +// echo ""; + +// } else { +// // User as requester +// $values['_users_id_requester'] = Session::getLoginUserID(); + +// if ($CFG_GLPI['use_check_pref']) { +// echo "
"; +// echo ""; +// echo ""; +// echo "
".__('Check your personnal information')."
"; +// User::showPersonalInformation(Session::getLoginUserID()); +// echo "
"; +// } +// } + +// echo ""; +// echo ""; + + +// // Load ticket template if available : +// $tt = $ticket->getTicketTemplateToUse($ticket_template, $values['type'], +// $values['itilcategories_id'], +// $_SESSION["glpiactive_entity"]); + +// // Predefined fields from template : reset them +// if (isset($values['_predefined_fields'])) { +// $values['_predefined_fields'] +// = Toolbox::decodeArrayFromInput($values['_predefined_fields']); +// } else { +// $values['_predefined_fields'] = array(); +// } + +// // Store predefined fields to be able not to take into account on change template +// $predefined_fields = array(); + +// if (isset($tt->predefined) && count($tt->predefined)) { +// foreach ($tt->predefined as $predeffield => $predefvalue) { +// if (isset($values[$predeffield]) && isset($default_values[$predeffield])) { +// // Is always default value : not set +// // Set if already predefined field +// // Set if ticket template change +// if (((count($values['_predefined_fields']) == 0) +// && ($values[$predeffield] == $default_values[$predeffield])) +// || (isset($values['_predefined_fields'][$predeffield]) +// && ($values[$predeffield] == $values['_predefined_fields'][$predeffield])) +// || (isset($values['_tickettemplates_id']) +// && ($values['_tickettemplates_id'] != $tt->getID()))) { +// $values[$predeffield] = $predefvalue; +// $predefined_fields[$predeffield] = $predefvalue; +// } +// } else { // Not defined options set as hidden field +// echo ""; +// } +// } +// // All predefined override : add option to say predifined exists +// if (count($predefined_fields) == 0) { +// $predefined_fields['_all_predefined_override'] = 1; +// } +// } else { // No template load : reset predefined values +// if (count($values['_predefined_fields'])) { +// foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) { +// if ($values[$predeffield] == $predefvalue) { +// $values[$predeffield] = $default_values[$predeffield]; +// } +// } +// } +// } + +// if (($CFG_GLPI['urgency_mask'] == (1<<3)) +// || $tt->isHiddenField('urgency')) { +// // Dont show dropdown if only 1 value enabled or field is hidden +// echo ""; +// } + +// // Display predefined fields if hidden +// if ($tt->isHiddenField('itemtype')) { +// echo ""; +// echo ""; +// } +// if ($tt->isHiddenField('locations_id')) { +// echo ""; +// } +// echo ""; +// echo ""; +// echo "
"; + +// echo ""; + +// echo ""; +// echo ""; +// echo ""; + +// echo ""; +// echo ""; +// echo ""; + + +// if ($CFG_GLPI['urgency_mask'] != (1<<3)) { +// if (!$tt->isHiddenField('urgency')) { +// echo ""; +// echo ""; +// echo ""; +// } +// } + +// if (empty($delegating) +// && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) { +// echo ""; +// echo ""; +// echo ""; +// } +// if (($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0) +// && (count($_SESSION["glpiactiveprofile"]["helpdesk_item_type"]))) { +// if (!$tt->isHiddenField('itemtype')) { +// echo ""; +// echo ""; +// echo ""; +// } +// } + +// if (!$tt->isHiddenField('locations_id')) { +// echo ""; +// } + +// if (!$tt->isHiddenField('_users_id_observer') +// || $tt->isPredefinedField('_users_id_observer')) { +// echo ""; +// echo ""; +// } + + +// if (!$tt->isHiddenField('name') +// || $tt->isPredefinedField('name')) { +// echo ""; +// echo ""; +// } + +// if (!$tt->isHiddenField('content') +// || $tt->isPredefinedField('content')) { +// echo ""; +// echo ""; +// } + + +// echo ""; +// echo ""; + + +// // File upload system +// $width = '100%'; +// if ($CFG_GLPI['use_rich_text']) { +// $width = '50%'; +// } +// echo ""; +// echo ""; +// echo ""; +// echo ""; + +// echo ""; +// echo ""; +// echo ""; + + + +// if (!$ticket_template) { +// echo ""; +// echo ""; +// } + +// echo "
".$caseInfo->processName.""; +// //echo "
".__('Describe the incident or request').""; +// if (Session::isMultiEntitiesMode()) { +// echo "(".Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]).")"; +// } +// echo "
".sprintf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')). +// ""; +// Ticket::dropdownUrgency(array('value' => $values["urgency"])); +// echo "
".__('Inform me about the actions taken').""; +// if ($values["_users_id_requester"] == 0) { +// $values['_users_id_requester'] = Session::getLoginUserID(); +// } +// $_POST['value'] = $values['_users_id_requester']; +// $_POST['field'] = '_users_id_requester_notif'; +// $_POST['use_notification'] = $values['_users_id_requester_notif']['use_notification']; +// include (GLPI_ROOT."/ajax/uemailUpdate.php"); + +// echo "
".__('Watcher').""; +// $values['_right'] = "groups"; + +// if (!$tt->isHiddenField('_users_id_observer')) { +// // Observer +// $rand_observer = $ticket->showActorAddFormOnCreate(CommonITILActor::OBSERVER, $values); +// echo '
'; + +// echo ""; +// Ajax::updateItemOnSelectEvent("dropdown__users_id_observer[]$rand_observer", +// "observer_$rand_observer", +// $CFG_GLPI["root_doc"]."/ajax/helpdesk_observer.php", +// $values); + +// } else { // predefined value +// if (isset($values["_users_id_observer"]) && $values["_users_id_observer"]) { +// echo Ticket::getActorIcon('user', CommonITILActor::OBSERVER)." "; +// echo Dropdown::getDropdownName("glpi_users", $values["_users_id_observer"]); +// echo ""; +// echo '
'; +// } +// } +// echo "
".sprintf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')).""; +// if (!$tt->isHiddenField('name')) { +// echo ""; +// } else { +// echo $values['name']; +// echo ""; +// } +// echo "
".sprintf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')). +// ""; +// $rand = mt_rand(); +// $rand_text = mt_rand(); + +// $cols = 90; +// $rows = 6; +// $content_id = "content$rand"; + +// //if ($CFG_GLPI["use_rich_text"]) { +// // $values["content"] = $ticket->setRichTextContent($content_id, $values["content"], $rand); +// // $cols = 100; +// // $rows = 10; +// //} else { +// $values["content"] = $ticket->setSimpleTextContent($values["content"]); +// //} + +// echo "
"; +// echo "
"; +// echo "
"; +// $rand = rand(); +// $pmCaseUser = $caseInfo->currentUsers[0] ; // by default +// $paramsURL = "DEL_INDEX=".$pmCaseUser->delIndex."&action=".$caseInfo->caseStatus ; +// echo ""; +// echo "
".sprintf(__('%1$s (%2$s)'), __('File'), Document::getMaxUploadSize()); +// DocumentType::showAvailableTypesLink(); +// echo ""; +// echo "
"; +// echo "
"; +// echo ""; +// echo ""; +// if ($CFG_GLPI['use_rich_text']) { +// echo ""; +// } +// echo "
"; + +// echo Html::file(array('multiple' => true, +// 'values' => array('filename' => $values['_filename'], +// 'tag' => $values['_tag_filename']) +// )); +// // "
"; +// echo "
"; +// if (!isset($rand)) { +// $rand = mt_rand(); +// } +// echo Html::imagePaste(array('rand' => $rand)); +// echo "
"; + +// echo "
"; +// if (!$ticket_template) { +// Html::closeForm(); +// } +//} + + function showFormHelpdesk($ID, $pmItem, $caseInfo, $ticket_template=false) { - global $DB, $CFG_GLPI, $LANG; + global $DB, $CFG_GLPI; - if (!Session::haveRight("create_ticket","1")) { - return false; - } + if (!Ticket::canCreate()) { + return false; + } - $query = "SELECT `realname`, `firstname`, `name` - FROM `glpi_users` - WHERE `id` = '$ID'"; - $result = $DB->query($query); + if (!$ticket_template + && Session::haveRightsOr('ticketvalidation', TicketValidation::getValidateRights())) { + + $opt = array(); + $opt['reset'] = 'reset'; + $opt['criteria'][0]['field'] = 55; // validation status + $opt['criteria'][0]['searchtype'] = 'equals'; + $opt['criteria'][0]['value'] = CommonITILValidation::WAITING; + $opt['criteria'][0]['link'] = 'AND'; + + $opt['criteria'][1]['field'] = 59; // validation aprobator + $opt['criteria'][1]['searchtype'] = 'equals'; + $opt['criteria'][1]['value'] = Session::getLoginUserID(); + $opt['criteria'][1]['link'] = 'AND'; + + $url_validate = $CFG_GLPI["root_doc"]."/front/ticket.php?".Toolbox::append_params($opt, + '&'); + + if (TicketValidation::getNumberToValidate(Session::getLoginUserID()) > 0) { + echo "". + __('Tickets awaiting approval')."

"; + } + } + + $email = UserEmail::getDefaultForUser($ID); + $default_use_notif = Entity::getUsedConfig('is_notif_enable_default', $_SESSION['glpiactive_entity'], '', 1); + + // Set default values... + $default_values = array('_users_id_requester_notif' + => array('use_notification' + => (($email == "")?0:$default_use_notif)), + 'nodelegate' => 1, + '_users_id_requester' => 0, + '_users_id_observer' => array(0), + '_users_id_observer_notif' + => array('use_notification' => $default_use_notif), + 'name' => '', + 'content' => '', + 'itilcategories_id' => 0, + 'locations_id' => 0, + 'urgency' => 3, + + 'items_id' => 0, + 'entities_id' => $_SESSION['glpiactive_entity'], + 'plan' => array(), + 'global_validation' => CommonITILValidation::NONE, + '_add_validation' => 0, + 'type' => Entity::getUsedConfig('tickettype', + $_SESSION['glpiactive_entity'], + '', Ticket::INCIDENT_TYPE), + '_right' => "id", + '_filename' => array(), + '_tag_filename' => array()); + + // Get default values from posted values on reload form + if (!$ticket_template) { + if (isset($_POST)) { + $values = Html::cleanPostForTextArea($_POST); + } + } + + $ticket = new Ticket(); + // Restore saved value or override with page parameter + if( !function_exists('restoreInput') ) { + function restoreInput(Array $default=array()) { + + if (isset($_SESSION['saveInput']['Ticket'])) { + $saved = Html::cleanPostForTextArea($_SESSION['saveInput']['Ticket']); + + // clear saved data when restored (only need once) + unset($_SESSION['saveInput']['Ticket']); + + return $saved; + } + + return $default; + } + } + $saved = restoreInput(); + foreach ($default_values as $name => $value) { + if (!isset($values[$name])) { + if (isset($saved[$name])) { + $values[$name] = $saved[$name]; + } else { + $values[$name] = $value; + } + } + } + + // Check category / type validity + if ($values['itilcategories_id']) { + $cat = new ITILCategory(); + if ($cat->getFromDB($values['itilcategories_id'])) { + switch ($values['type']) { + case Ticket::INCIDENT_TYPE : + if (!$cat->getField('is_incident')) { + $values['itilcategories_id'] = 0; + } + break; + + case Ticket::DEMAND_TYPE : + if (!$cat->getField('is_request')) { + $values['itilcategories_id'] = 0; + } + break; + + default : + break; + } + } + } + + if (!$ticket_template) { + echo ""; + } - $email = UserEmail::getDefaultForUser($ID); + $delegating = User::getDelegateGroupsForUser($values['entities_id']); + if (count($delegating)) { + echo "
"; + echo ""; + echo ""; - // First load default entity one - if ($template_id = EntityData::getUsedConfig('tickettemplates_id', $_SESSION["glpiactive_entity"])) { - // with type and categ - $tt->getFromDBWithDatas($template_id, true); - } + echo "
".__('This ticket concerns me')." "; - // Set default values... - $default_values = array('_users_id_requester_notif' => array('use_notification' => ($email==""?0:1), - 'alternative_email' => ''), - 'nodelegate' => 1, - '_users_id_requester' => 0, - 'name' => '', - 'content' => '', - 'itilcategories_id' => 0, - 'urgency' => 3, - 'itemtype' => '', - 'entities_id' => $_SESSION['glpiactive_entity'], - 'items_id' => 0, - 'plan' => array(), - 'global_validation' => 'none', - 'due_date' => 'NULL', - 'slas_id' => 0, - '_add_validation' => 0, - 'type' => EntityData::getUsedConfig('tickettype', - $_SESSION['glpiactive_entity'], - '', Ticket::INCIDENT_TYPE), - '_right' => "id"); + $rand = Dropdown::showYesNo("nodelegate", $values['nodelegate']); - if (!$ticket_template) { - $options = $_REQUEST; - } + $params = array('nodelegate' => '__VALUE__', + 'rand' => $rand, + 'right' => "delegate", + '_users_id_requester' + => $values['_users_id_requester'], + '_users_id_requester_notif' + => $values['_users_id_requester_notif'], + 'use_notification' + => $values['_users_id_requester_notif']['use_notification'], + 'entity_restrict' + => $_SESSION["glpiactive_entity"]); - // Restore saved value or override with page parameter - foreach ($default_values as $name => $value) { - if (!isset($options[$name])) { - if (isset($_SESSION["helpdeskSaved"][$name])) { - $options[$name] = $_SESSION["helpdeskSaved"][$name]; - } else { - $options[$name] = $value; - } - } - } - // Clean text fields - $options['name'] = stripslashes($options['name']); - $options['content'] = Html::cleanPostForTextArea($options['content']); - - if (!$ticket_template) { - echo ""; - } - - - $delegating = User::getDelegateGroupsForUser($options['entities_id']); - - if (count($delegating)) { - echo "
"; - echo ""; - echo ""; - - echo "
".$LANG['job'][69]." : "; - - $rand = Dropdown::showYesNo("nodelegate", $options['nodelegate']); - - $params = array ('nodelegate' => '__VALUE__', - 'rand' => $rand, - 'right' => "delegate", - '_users_id_requester' - => $options['_users_id_requester'], - '_users_id_requester_notif' - => $options['_users_id_requester_notif'], - 'use_notification' - => $options['_users_id_requester_notif']['use_notification'], - 'entity_restrict' - => $_SESSION["glpiactive_entity"]); - - Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate".$rand, "show_result".$rand, + Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate".$rand, "show_result".$rand, $CFG_GLPI["root_doc"]."/ajax/dropdownDelegationUsers.php", $params); - echo "
"; - echo "
"; + $class = 'right'; + if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { + echo "
".__('Check your personnal information'); + $class = 'center'; + } - $self = new Ticket(); - if ($options["_users_id_requester"] == 0) { - $options['_users_id_requester'] = Session::getLoginUserID(); - } else { - $options['_right'] = "delegate"; - } - $self->showActorAddFormOnCreate(Ticket::REQUESTER, $options); - echo ""; - echo "
"; - echo ""; - } - - echo ""; - echo ""; + echo "
"; + echo "
"; - // Load ticket template if available : - $tt = new TicketTemplate(); + $self = $ticket; // new self(); + if ($values["_users_id_requester"] == 0) { + $values['_users_id_requester'] = Session::getLoginUserID(); + } else { + $values['_right'] = "delegate"; + } + $self->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $values); + echo "
"; + if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) { + echo "
"; + User::showPersonalInformation(Session::getLoginUserID()); + } + echo "
"; + echo ""; - $field = ''; - if ($options['type'] && $options['itilcategories_id']) { - $categ = new ITILCategory(); - if ($categ->getFromDB($options['itilcategories_id'])) { - switch ($options['type']) { - case Ticket::INCIDENT_TYPE : - $field = 'tickettemplates_id_incident'; - break; + } else { + // User as requester + $values['_users_id_requester'] = Session::getLoginUserID(); - case Ticket::DEMAND_TYPE : - $field = 'tickettemplates_id_demand'; - break; - } + if ($CFG_GLPI['use_check_pref']) { + echo "
"; + echo ""; + echo ""; + echo "
".__('Check your personnal information')."
"; + User::showPersonalInformation(Session::getLoginUserID()); + echo "
"; + } + } - if (!empty($field) && $categ->fields[$field]) { - // without type and categ - $tt->getFromDBWithDatas($categ->fields[$field], false); - } - } - } - if ($ticket_template) { - // with type and categ - $tt->getFromDBWithDatas($ticket_template, true); - } + echo ""; + echo ""; - // Predefined fields from template : reset them - if (isset($options['_predefined_fields'])) { - $options['_predefined_fields'] - = unserialize(rawurldecode(stripslashes($options['_predefined_fields']))); - } else { - $options['_predefined_fields'] = array(); - } - // Store predefined fields to be able not to take into account on change template - $predefined_fields = array(); + // Load ticket template if available : + $tt = $ticket->getTicketTemplateToUse($ticket_template, $values['type'], + $values['itilcategories_id'], + $_SESSION["glpiactive_entity"]); - if (isset($tt->predefined) && count($tt->predefined)) { - foreach ($tt->predefined as $predeffield => $predefvalue) { - if (isset($options[$predeffield]) && isset($default_values[$predeffield])) { + // Predefined fields from template : reset them + if (isset($values['_predefined_fields'])) { + $values['_predefined_fields'] + = Toolbox::decodeArrayFromInput($values['_predefined_fields']); + } else { + $values['_predefined_fields'] = array(); + } + + // Store predefined fields to be able not to take into account on change template + $predefined_fields = array(); + + if (isset($tt->predefined) && count($tt->predefined)) { + foreach ($tt->predefined as $predeffield => $predefvalue) { + if (isset($values[$predeffield]) && isset($default_values[$predeffield])) { // Is always default value : not set // Set if already predefined field // Set if ticket template change - if ($options[$predeffield] == $default_values[$predeffield] - || (isset($options['_predefined_fields'][$predeffield]) - && $options[$predeffield] == $options['_predefined_fields'][$predeffield]) - || (isset($options['_tickettemplates_id']) - && $options['_tickettemplates_id'] != $tt->getID())) { - $options[$predeffield] = $predefvalue; - $predefined_fields[$predeffield] = $predefvalue; + if (((count($values['_predefined_fields']) == 0) + && ($values[$predeffield] == $default_values[$predeffield])) + || (isset($values['_predefined_fields'][$predeffield]) + && ($values[$predeffield] == $values['_predefined_fields'][$predeffield])) + || (isset($values['_tickettemplates_id']) + && ($values['_tickettemplates_id'] != $tt->getID()))) { + $values[$predeffield] = $predefvalue; + $predefined_fields[$predeffield] = $predefvalue; } - } else { // Not defined options set as hidden field + } else { // Not defined options set as hidden field echo ""; - } - } - - } else { // No template load : reset predefined values - if (count($options['_predefined_fields'])) { - foreach ($options['_predefined_fields'] as $predeffield => $predefvalue) { - if ($options[$predeffield] == $predefvalue) { - $options[$predeffield] = $default_values[$predeffield]; + } + } + // All predefined override : add option to say predifined exists + if (count($predefined_fields) == 0) { + $predefined_fields['_all_predefined_override'] = 1; + } + } else { // No template load : reset predefined values + if (count($values['_predefined_fields'])) { + foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) { + if ($values[$predeffield] == $predefvalue) { + $values[$predeffield] = $default_values[$predeffield]; } - } - } - } - unset($_SESSION["helpdeskSaved"]); + } + } + } - if ($CFG_GLPI['urgency_mask']==(1<<3) || $tt->isHiddenField('urgency')) { - // Dont show dropdown if only 1 value enabled or field is hidden - echo ""; - } + if (($CFG_GLPI['urgency_mask'] == (1<<3)) + || $tt->isHiddenField('urgency')) { + // Dont show dropdown if only 1 value enabled or field is hidden + echo ""; + } - // Display predefined fields if hidden - if ($tt->isHiddenField('itemtype')) { - echo ""; - echo ""; - } + // Display predefined fields if hidden + if ($tt->isHiddenField('items_id')) { - echo ""; - echo "
"; - - echo ""; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo ""; + if (!empty($values['items_id'])) { + foreach ($values['items_id'] as $itemtype => $items) { + foreach ($items as $items_id) { + echo ""; + } + } + } + } + if ($tt->isHiddenField('locations_id')) { + echo ""; + } + echo ""; + echo ""; + echo "
".$caseInfo->processName." : "; - if (Session::isMultiEntitiesMode()) { - echo " (".Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]).")"; - } - echo "
"; - if ($CFG_GLPI['urgency_mask']!=(1<<3)) { - if (!$tt->isHiddenField('urgency')) { - echo ""; - echo ""; - echo ""; - } - } + echo ""; - if (empty($delegating) && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) { - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; - echo ""; - } + echo ""; + echo ""; + echo ""; - echo ""; - echo ""; - } - } + default: // Ticket::INCIDENT_TYPE : + $condition .= " AND `is_incident`='1'"; + } + $opt = array('value' => $values['itilcategories_id'], + 'condition' => $condition, + 'entity' => $_SESSION["glpiactive_entity"], + 'on_change' => 'this.form.submit()'); - if (!$tt->isHiddenField('name') - || $tt->isPredefinedField('name')) { - echo ""; - echo ""; - echo ""; - } + if ($values['itilcategories_id'] && $tt->isMandatoryField("itilcategories_id")) { + $opt['display_emptychoice'] = false; + } - if (!$tt->isHiddenField('content') - || $tt->isPredefinedField('content')) { - echo ""; - echo ""; - echo ""; - } - echo ""; - echo ""; - - - echo ""; - echo ""; + ITILCategory::dropdown($opt); + echo ""; - echo ""; - - echo ""; - echo ""; + echo ""; + echo ""; + } + } - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; + } + if (($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0) + && (count($_SESSION["glpiactiveprofile"]["helpdesk_item_type"]))) { + if (!$tt->isHiddenField('itemtype')) { + echo ""; + echo ""; + echo ""; - echo ""; + } + } - if ($tt->isField('id') && $tt->fields['id'] > 0) { - echo ""; - echo ""; - } + if (!$tt->isHiddenField('locations_id')) { + echo ""; + } - echo ""; + if (!$tt->isHiddenField('_users_id_observer') + || $tt->isPredefinedField('_users_id_observer')) { + echo ""; + echo ""; + echo ""; - } + if (!$tt->isHiddenField('_users_id_observer')) { + // Observer - echo "
".$LANG['joblist'][29]." :".$tt->getMandatoryMark('urgency').""; - Ticket::dropdownUrgency("urgency", $options['urgency']); - echo "
".$caseInfo->processName.""; + //echo "
".__('Describe the incident or request').""; + if (Session::isMultiEntitiesMode()) { + echo "(".Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]).")"; + } + echo "
".$LANG['help'][8]." : "; - if ($options["_users_id_requester"] == 0) { - $options['_users_id_requester'] = Session::getLoginUserID(); - } - $_REQUEST['value'] = $options['_users_id_requester']; - $_REQUEST['field'] = '_users_id_requester_notif'; - $_REQUEST['use_notification'] = $options['_users_id_requester_notif']['use_notification']; - include (GLPI_ROOT."/ajax/uemailUpdate.php"); + echo "
 "; - echo "
"; - $rand = rand(); - $pmCaseUser = $caseInfo->currentUsers[0] ; // by default - $paramsURL = "DEL_INDEX=".$pmCaseUser->delIndex."&action=".$caseInfo->caseStatus ; - - echo ""; - echo "
 "; - echo "
".$LANG['document'][2]." (".Document::getMaxUploadSize().") : "; - echo "".
-            $LANG["; - echo " "; - Ticket::showDocumentAddButton(60); + if ($CFG_GLPI['urgency_mask'] != (1<<3)) { + if (!$tt->isHiddenField('urgency')) { + echo "
".sprintf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')). + ""; + Ticket::dropdownUrgency(array('value' => $values["urgency"])); + echo "
"; + if (empty($delegating) + && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) { + echo "
".__('Inform me about the actions taken').""; + if ($values["_users_id_requester"] == 0) { + $values['_users_id_requester'] = Session::getLoginUserID(); + } + $_POST['value'] = $values['_users_id_requester']; + $_POST['field'] = '_users_id_requester_notif'; + $_POST['use_notification'] = $values['_users_id_requester_notif']['use_notification']; + include (GLPI_ROOT."/ajax/uemailUpdate.php"); - echo "
".sprintf(__('%1$s%2$s'), _n('Watcher', 'Watchers', 2), + $tt->getMandatoryMark('_users_id_observer')).""; + $values['_right'] = "groups"; - echo "
"; - if (!$ticket_template) { - Html::closeForm(); - } + if($tt->isPredefinedField('_users_id_observer') + && !is_array($values['_users_id_observer'])) { + + //convert predefined value to array + $values['_users_id_observer'] = array($values['_users_id_observer']); + $values['_users_id_observer_notif']['use_notification'] = + array($values['_users_id_observer_notif']['use_notification']); + + // add new line to permit adding more observers + $values['_users_id_observer'][1] = 0; + $values['_users_id_observer_notif']['use_notification'][1] = 1; + } + + + echo "
"; + if (isset($values['_users_id_observer'])) { + $observers = $values['_users_id_observer']; + foreach($observers as $index_observer => $observer) { + $options = array_merge($values, array('_user_index' => $index_observer)); + Ticket::showFormHelpdeskObserver($options); + } + } + echo "
"; + + } else { // predefined value + if (isset($values["_users_id_observer"]) && $values["_users_id_observer"]) { + echo Ticket::getActorIcon('user', CommonITILActor::OBSERVER)." "; + echo Dropdown::getDropdownName("glpi_users", $values["_users_id_observer"]); + echo ""; + + } + } + echo ""; + } + + + if (!$tt->isHiddenField('name') + || $tt->isPredefinedField('name')) { + echo ""; + echo "".sprintf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')).""; + if (!$tt->isHiddenField('name')) { + echo ""; + } else { + echo $values['name']; + echo ""; + } + echo ""; + } + + if (!$tt->isHiddenField('content') + || $tt->isPredefinedField('content')) { + echo ""; + echo "".sprintf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')). + ""; + $rand = mt_rand(); + $rand_text = mt_rand(); + + $cols = 90; + $rows = 6; + $content_id = "content$rand"; + + //if ($CFG_GLPI["use_rich_text"]) { + // $values["content"] = $ticket->setRichTextContent($content_id, $values["content"], $rand); + + + + // $cols = 100; + // $rows = 10; + //} else { + $values["content"] = $ticket->setSimpleTextContent($values["content"]); + + //} + + echo "
"; + echo "
"; + echo ""; + } + + + echo ""; + echo ""; + $rand = rand(); + $pmCaseUser = $caseInfo->currentUsers[0] ; // by default + $paramsURL = "DEL_INDEX=".$pmCaseUser->delIndex."&action=".$caseInfo->caseStatus ; + echo ""; + echo ""; + + // File upload system + $width = '100%'; + if ($CFG_GLPI['use_rich_text']) { + $width = '50%'; + } + echo ""; + echo "".sprintf(__('%1$s (%2$s)'), __('File'), Document::getMaxUploadSize()); + DocumentType::showAvailableTypesLink(); + echo ""; + echo ""; + echo "
"; + echo ""; + echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + if ($CFG_GLPI['use_rich_text']) { + echo ""; + } + echo "
"; + + echo Html::file(array('multiple' => true, + 'values' => array('filename' => $values['_filename'], + 'tag' => $values['_tag_filename']) + )); + // "
"; + echo "
"; + if (!isset($rand)) { + $rand = mt_rand(); + } + + echo Html::initImagePasteSystem($content_id, $rand); + echo "
"; + + echo ""; + echo ""; + + + + if (!$ticket_template) { + echo ""; + echo ""; + + if ($tt->isField('id') && ($tt->fields['id'] > 0)) { + echo ""; + echo ""; + } + echo ""; + echo ""; + } + + echo ""; + if (!$ticket_template) { + Html::closeForm(); + } } + function processMakerShowCase( $ID, $from_helpdesk ) { - global $LANG ; - - Html::helpHeader($LANG['job'][13], $_SERVER['PHP_SELF'], $_SESSION["glpiname"]); - - //$userGLPI = new User(); - //$userGLPI->getFromDB( $ID ) ; - //if( $userGLPI->fields['language'] != null ) - // $lang = substr( $userGLPI->fields['language'], 0, 2) ; - //else - // $lang = "en" ; - - $pmItem = new PluginProcessmakerProcessmaker( ) ; + global $CFG_GLPI ; + + //Html::helpHeader($LANG['job'][13], $_SERVER['PHP_SELF'], $_SESSION["glpiname"]); + + $pmItem = new PluginProcessmakerProcessmaker( ) ; $pmItem->login( ) ; - - //if( isset( $_REQUEST['sid'] )) { - // $pmItem->useSession( $_REQUEST['sid'], $lang ) ; - //} - //else { - // $pmItem->openSession( $userGLPI->fields['name'], "md5:37d442efb43ebb80ec6f9649b375ab72", $lang ) ; - //} - + $caseInfo = $pmItem->getCaseInfo( $_REQUEST['case_id'] ) ; if ($caseInfo->status_code == 0){ - // case is created + // case is created // Must show it... - // we may input this case into a temporary case table with session id for key - // we need some more info, del_index... -// $pmCaseUser = $caseInfo->currentUsers[0] ; // by default - + $rand = rand(); -// echo "