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 * @param mixed $itemId * @return mixed */ 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 * @param mixed $itemId * @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 * @return mixed */ 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 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 * @param mixed $tabnum * @param mixed $withtemplate * @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 "