getID(); $item_type = $item->getType(); if (self::getCaseFromItemTypeAndItemId($item_type, $item_id )) { return array( 'processmakercases' => $LANG['processmaker']['item']['tab']." ".$this->fields['case_status']."" ); } else { return array( 'processmakercases' => $LANG['processmaker']['item']['tab'] ); } } /** * Summary of getCaseIdFromItemTypeAndItemId * @param mixed $itemType is the item type * @param mixed $itemId is the item id * @return mixed case id */ static function getCaseIdFromItemTypeAndItemId( $itemType, $itemId) { global $DB; $query = "SELECT * FROM glpi_plugin_processmaker_cases WHERE items_id=$itemId and itemtype='$itemType';"; if (($res = $DB->query($query) ) && $DB->numrows($res) > 0) { $row = $DB->fetch_array($res); return $row['id']; } return false; } /** * Summary of getCaseFromItemTypeAndItemId * @param mixed $itemType is the item type * @param mixed $itemId is the item id * @return mixed: returns false when there is no case associated with the item, else fills in the item fields from DB, and returns true */ function getCaseFromItemTypeAndItemId($itemType, $itemId) { if ($caseId = self::getCaseIdFromItemTypeAndItemId( $itemType, $itemId)) { return $this->getFromDB( $caseId ); } return false; } /** * Summary of getFromDB * @param mixed $ID id of needed object * @return mixed object if found, else false */ function getFromDB($ID) { global $DB; // Search for object in database and fills 'fields' // != 0 because 0 is consider as empty if (strlen($ID)==0) { return false; } $query = "SELECT * FROM `".$this->getTable()."` WHERE `".$this->getIndexName()."` = '".$ID."'"; if (($result = $DB->query($query)) && $DB->numrows($result)==1) { $this->fields = $DB->fetch_assoc($result); $this->post_getFromDB(); return true; } return false; } /** * Summary of getVariables * Gets variables from a case. * @param array $vars an array of variable name that will be read from the case as case variables * @return array an associative array (variable_name => value). The returned array can be empty if requested variables are not found. */ function getVariables( $vars = array() ) { global $PM_DB; $locVars = array( ); $app_data = array(); // by default $caseId = $this->getID(); $query = "SELECT APP_DATA FROM APPLICATION WHERE APP_UID='$caseId';"; if (($res = $PM_DB->query($query)) && $PM_DB->numrows($res) > 0) { $row = $PM_DB->fetch_assoc($res); $app_data = unserialize($row['APP_DATA'] ); $locVars = array_intersect_key( $app_data, array_flip($vars) ); } return $locVars; } /** * Summary of sendVariables * Sends variables to a case. * BEWARE that this will not work correctly for values containning special chars like \ * instead use the web service function from PluginProcessmakerProcessmaker class * @param array $vars an array of associative variables (name => value) that will be injected into the case as case variables * @return true if variables have been saved to the case, false otherwise */ function sendVariables( $vars = array() ) { global $PM_DB; $variablesSent = false; // be default $app_data = array(); // by default $caseId = $this->getID(); $query = "SELECT APP_DATA FROM APPLICATION WHERE APP_UID='$caseId';"; if (($res = $PM_DB->query($query)) && $PM_DB->numrows($res) > 0) { $row = $PM_DB->fetch_assoc($res); $app_data = unserialize($row['APP_DATA'] ); } $app_data = array_replace( $app_data, $vars ); $serialized = serialize( $app_data ); $query = "UPDATE APPLICATION SET APP_DATA='$serialized' WHERE APP_UID='$caseId';"; $res = $PM_DB->query( $query ); if ($PM_DB->affected_rows() == 1) { $variablesSent = true; } return $variablesSent; } /** * Summary of displayTabContentForItem * @param CommonGLPI $item is the item * @param mixed $tabnum is the tab num * @param mixed $withtemplate has template * @return mixed */ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { global $LANG, $DB, $CFG_GLPI; $config = PluginProcessmakerConfig::getInstance(); if ($config->fields['maintenance'] == 0) { $item_id = $item->getID(); $item_type = $item->getType(); ////retrieve container for current tab //$container = new self; //$found_c = $container->find("`itemtype` = '$item_type' AND `items_id` = $item_id "); //echo "Show the frame"; $rand = rand(); echo "
"; echo "
"; echo Html::scriptBlock("$('#processmakercasemenu').css('max-width', 'none');"); echo ""; $pmCaseUser = false; // initial value: no user // first search for the case if (self::getCaseIdFromItemTypeAndItemId($item_type, $item_id )) { $myProcessMaker = new PluginProcessmakerProcessmaker( ); $myProcessMaker->login(); $caseInfo = $myProcessMaker->getCaseFromItem( $item_type, $item_id ); if ($caseInfo->caseStatus != 'CANCELLED' && $caseInfo->caseStatus != 'COMPLETED') { // need to get info on the thread of the GLPI current user // we must retreive currentGLPI user from this array $GLPICurrentPMUserId = PluginProcessmakerUser::getPMUserId( Session::getLoginUserID() ); $pmCaseUser = $caseInfo->currentUsers[0]; // by default currently manage only one task at a time, must define tab management for several tasks foreach ($caseInfo->currentUsers as $caseUser) { if ($caseUser->userId == $GLPICurrentPMUserId) { $pmCaseUser = $caseUser; break; } } } $locDelIndex = 1; // by default switch ($caseInfo->caseStatus) { case "CANCELLED" : echo ""; $paramsURL = "DEL_INDEX=1"; // echo "" ; break; case "DRAFT" : case "TO_DO" : $paramsURL = "DEL_INDEX=".$pmCaseUser->delIndex."&action=".$caseInfo->caseStatus; $locDelIndex = $pmCaseUser->delIndex; if ($pmCaseUser->userId != '') { echo ""; if ($GLPICurrentPMUserId == $pmCaseUser->userId) { // then propose a button to cancel case only when assigned user is == to glpi current user echo ""; } if ($caseInfo->caseStatus == "DRAFT" || (plugin_processmaker_haveRight("deletecase", DELETE) && $_SESSION['glpiactiveprofile']['interface'] == 'central')) { // then propose a button to delete case echo ""; } echo ""; echo ""; } break; case "COMPLETED" : echo ""; $paramsURL = "DEL_INDEX="; // DEL_INDEX is not set to tell PM to show the current task i.e.: the last one break; } $proj = new PluginProcessmakerProcess; $proj->getFromDBbyExternalID( $caseInfo->processId ); $project_type = $proj->fields['project_type']; // then propose a button to view case history //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; echo "
".$LANG['processmaker']['item']['tab']."
".$LANG['processmaker']['item']['cancelledcase']."
"; echo $LANG['processmaker']['item']['cancelcase']; echo ""; echo ""; echo ""; //echo ""; //echo ""; echo ""; echo ""; echo $LANG['processmaker']['item']['deletecase']; echo ""; echo ""; echo ""; echo ""; echo "
".$LANG['processmaker']['item']['completedcase']."
"; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo "
"; echo ""; //?rand=$rand' // processmakertabpaneltable is used to align the tabs echo ""; echo Html::scriptBlock("$('#processmakertabpaneltable').css('max-width', 'none');"); echo ""; echo ""; } else { //******************************** // no running case for this ticket // propose to start one //******************************** echo ""; echo ""; } else { echo ""; } } echo "
"; ////////////////////////// // Processmaker tab panels // need to have a global variable which contains tab id // used only one time for activated panel ////////////////////////// $arrayProcessmakerTabPanel = array(); echo "
"; ////////////// // Define tabs ////////////// echo "
    "; //echo "
  • Nunc tincidunt
  • "; //$arrayProcessmakerTabPanel[] = "tabs-1"; $arrayProcessmakerTabPanel = []; if ($pmCaseUser) { foreach ($caseInfo->currentUsers as $caseUser) { $title = $LANG['processmaker']['item']['task']['task'].$caseUser->taskName; echo "
  • ". ($caseUser->userId != $GLPICurrentPMUserId ? "$title" : $title) ."
  • "; $arrayProcessmakerTabPanel[] = "task-".$caseUser->delIndex; } } else { // no user means CANCELLED or COMPLETED // then create artificial panel to host case infos echo "
  • ".$LANG['processmaker']['item']['case']['caseinfo']."
  • "; $arrayProcessmakerTabPanel[] = "caseInfo"; } // add default panels: map, history, log and dynaforms $defaultTabs = ['caseMap' => 'viewcasemap', 'caseHistory' => 'viewcasehistory', 'caseChangeLogHistory' => 'viewcasechangeloghistory', 'historyDynaformPage' => 'viewdynaforms' ]; foreach ($defaultTabs as $tab => $tabText) { echo "
  • ".$LANG['processmaker']['item']['case'][$tabText]."
  • "; } echo "
"; //////////////// // Define panels //////////////// if ($pmCaseUser) { $csrf = Session::getNewCSRFToken(); foreach ($caseInfo->currentUsers as $caseUser) { // for each task, if task is to be claimed, we need to verify that current user can claim it by checking if he/she is in the group assigned to the task $hide_claim_button=false; // by default if (!$caseUser->userId) { // current task is to claimed // get task user list $query = "SELECT items_id, itemtype FROM glpi_plugin_processmaker_tasks WHERE case_id = '".$caseInfo->caseId."' AND del_index =".$caseUser->delIndex; foreach ($DB->request($query) as $row) { // normally there is only one task $task = getItemForItemtype( $row['itemtype'] ); $task->getFromDB( $row['items_id'] ); // check if this group can be found in the current user's groups if (!isset($_SESSION['glpigroups']) || !in_array( $task->fields['groups_id_tech'], $_SESSION['glpigroups'] )) { $hide_claim_button=true; } } } echo "
"; // to load users for task re-assign only when task is not to be 'claimed' if ($caseUser->userId) { echo "
Loading...
"; echo ""; } echo "
"; } } else { // no user means CANCELLED or COMPLETED // then create artificial panel to host case infos echo "
"; $url = $myProcessMaker->serverURL."/cases/cases_Open?sid=".$_SESSION["pluginprocessmaker"]["session"]["id"]."&APP_UID=".$caseInfo->caseId."&".$paramsURL."&action=TO_DO"; echo "
"; } // default panels // map, history, log and dynaforms // will be added dynamically by the addTabPanel function echo "
"; // end of tabs/panels echo "
"; if ($pmCaseUser) { $activePanel = 'task-'.$pmCaseUser->delIndex; } else { $activePanel = 'caseInfo'; } $caseMapUrl = $myProcessMaker->serverURL.($project_type=='bpmn' ? "/designer?prj_uid=".$caseInfo->processId."&prj_readonly=true&app_uid=".$caseInfo->caseId : "/cases/ajaxListener?action=processMap&rand=$rand")."&glpi_domain={$config->fields['domain']}"; echo ""; echo "
".$LANG['processmaker']['item']['nocase']; // check if item is not solved nor closed if ($item->fields['status'] != 'solved' && $item->fields['status'] != 'closed' && $_SESSION['glpiactiveprofile']['interface'] != 'helpdesk') { // propose case start echo " - ".$LANG['processmaker']['item']['startone']; echo "
"; echo $LANG['processmaker']['item']['selectprocess']." "; echo ""; echo ""; echo ""; // Dropdown::show('PluginProcessmakerProcessmaker', array( 'entity' => $item->fields['entities_id'], 'name' => 'plugin_processmaker_process_id', 'condition' => "is_active=1")); // condition is used to prevent start of none-active cases PluginProcessmakerProcess::dropdown(array( 'value' => 0, 'entity' => $item->fields['entities_id'], 'name' => 'plugin_processmaker_process_id', 'condition' => "is_active=1")); echo ""; echo ""; echo "
"; Html::closeForm(true ); //echo ""; } else { // under maintenance echo $LANG['processmaker']['config']['undermaintenance']; } return true; } /** * Summary of deleteTasks * will delete all tasks associated with this case from the item * @return true if tasks have been deleted from associated item and from case table */ private function deleteTasks( ) { global $DB; $ret = false; $query = "DELETE from glpi_".strtolower($this->fields['itemtype'])."tasks where id in (select items_id from glpi_plugin_processmaker_tasks where case_id='".$this->fields['id']."')"; if ($DB->query( $query )) { $query = "DELETE from glpi_plugin_processmaker_tasks where case_id='".$this->fields['id']."'"; if ($DB->query( $query )) { $ret = true; } } return $ret; } /** * Summary of deleteCase * will delete case and all tasks associated with this case from the item * @return true if case and tasks have been deleted from associated item and from case table */ function deleteCase( ) { global $DB; $ret = false; if ($this->deleteTasks()) { if ($this->deleteFromDB( )) { $ret = true; } } return $ret; } /** * Summary of cancelTasks * will mark as information all to_do tasks * BEWARE that this will only be done when case is in TO_DO status * @return true if tasks have been deleted from associated item and from case table */ private function cancelTasks( ) { global $DB; $ret = false; if (isset($this->fields['case_status']) && $this->fields['case_status'] == "TO_DO") { $query = "UPDATE glpi_".$this->fields['itemtype']."tasks SET state=0,users_id_tech=0,begin=NULL,end=NULL WHERE state=1 AND id in (select items_id from glpi_plugin_processmaker_tasks where case_id='".$this->fields['id']."')"; if ($DB->query( $query )) { $ret = true; } } return $ret; } /** * Summary of cancelCase * will cancel case and mark 'to_do' tasks associated with this case from the item as information * BEWARE that this will only be done when case is in TO_DO status * @return true if case and tasks have been cancelled or marked from associated item and from case table */ function cancelCase( ) { global $DB; $ret = false; if (isset($this->fields['case_status']) && $this->fields['case_status'] == "TO_DO") { if ($this->cancelTasks()) { if ($this->update( array( 'id' => $this->getID(), 'case_status' => 'CANCELLED' ) )) { $ret=true; } } } return $ret; } /** * Summary of canSolve * To know if a Ticket (Problem or Change) can be solved * i.e. the case permits solving of item * @param mixed $item is the item * @return bool true to permit solve, false otherwise */ public static function canSolve ($item) { $myCase = new self; if ($myCase->getCaseFromItemTypeAndItemId( $item['item']->getType(), $item['item']->getID() )) { $pmVar = $myCase->getVariables( array( 'GLPI_ITEM_CAN_BE_SOLVED' ) ); if ($myCase->fields['case_status'] != 'COMPLETED' && $myCase->fields['case_status'] != 'CANCELLED' && (!isset($pmVar['GLPI_ITEM_CAN_BE_SOLVED']) || $pmVar['GLPI_ITEM_CAN_BE_SOLVED'] != 1)) { // then item can't be solved return false; } } return true; } /** * Summary of getToDoTasks * @param mixed $parm is a Ticket, a Problem or a Change * @return array list of tasks with status 'to do' for case associated with item */ public static function getToDoTasks($parm) { $myCase = new self; if ($myCase->getCaseFromItemTypeAndItemId( $parm->getType(), $parm->getID() )) { return PluginProcessmakerTask::getToDoTasks( $myCase->getID(), $parm->getType()."Task" ); } return array(); } }