function executeActions($output, $params) { if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "assign": $output[$action->fields["field"]] = $action->fields["value"]; break; case "regex_result": //Regex result : assign value from the regex $res = ""; if (isset($this->regex_results[0])) { $res .= RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]); } else { $res .= $action->fields["value"]; } if ($res != '' && ($action->fields["field"] != 'user' && $action->fields["field"] != 'otherserial' && $action->fields["field"] != 'software' && $action->fields["field"] != 'softwareversion')) { $res = Dropdown::importExternal(getItemTypeForTable(getTableNameForForeignKeyField($action->fields['field'])), $res); } $output[$action->fields["field"]] = $res; break; default: //plugins actions $executeaction = clone $this; $ouput = $executeaction->executePluginsActions($action, $output, $params); break; } } } return $output; }
/** * @param $report * @param $name * @param $tableortype (default '') * @param $label (default '') * @param $condition (default '') **/ function __construct($report, $name, $tableortype = '', $label = '', $condition = '') { parent::__construct($report, $name, $name, $label); $this->condition = $condition; if (empty($tableortype)) { $this->table = getTableNameForForeignKeyField($name); } else { if (preg_match("/^glpi_/", $tableortype)) { $this->table = $tableortype; } else { if ($tableortype == NOT_AVAILABLE) { $this->table = NOT_AVAILABLE; } else { $this->table = getTableForItemType($tableortype); } } } }
function selectValues($field = '') { global $DB, $CFG_GLPI; if ($field == '') { $field = $this->fields['field']; } echo "<span id='span_values' name='span_values'>"; if ($this->fields['itemtype'] != '') { $item = new $this->fields['itemtype'](); $searchOption = $item->getSearchOptionByField('field', $field); if (isset($searchOption['linkfield'])) { $linkfield = $searchOption['linkfield']; } else { $linkfield = $searchOption['field']; } if ($linkfield == $this->fields['field']) { $value = $this->fields['value']; } else { $value = ''; } //If field is a foreign key on another table or not $table = getTableNameForForeignKeyField($linkfield); if ($table == '') { if (isset($searchOption['datatype'])) { $datatype = $searchOption['datatype']; } else { $datatype = 'text'; } switch ($datatype) { case 'text': case 'string': default: autocompletionTextField($this, 'value', array('value' => $value)); break; case 'bool': Dropdown::showYesNo('value', $value); break; } } else { $itemtype = getItemTypeForTable($table); Dropdown::show($itemtype, array('name' => 'value', 'value' => $value)); } } echo "</span>"; }
/** * @param $networkPortID **/ static function showFormForNetworkPort($networkPortID) { global $DB, $CFG_GLPI; $name = new self(); $number_names = 0; if ($networkPortID > 0) { $query = "SELECT `id`\n FROM `" . $name->getTable() . "`\n WHERE `itemtype` = 'NetworkPort'\n AND `items_id` = '{$networkPortID}'\n AND `is_deleted` = '0'"; $result = $DB->query($query); if ($DB->numrows($result) > 1) { echo "<tr class='tab_bg_1'><th colspan='4'>" . __("Several network names available! Go to the tab 'Network Name' to manage them.") . "</th></tr>\n"; return; } switch ($DB->numrows($result)) { case 1: $nameID = $DB->fetch_assoc($result); $name->getFromDB($nameID['id']); break; case 0: $name->getEmpty(); break; } } else { $name->getEmpty(); } echo "<tr class='tab_bg_1'><th colspan='4'>"; // If the networkname is defined, we must be able to edit it. So we make a link if ($name->getID() > 0) { echo "<a href='" . $name->getLinkURL() . "'>" . self::getTypeName(1) . "</a>"; echo "<input type='hidden' name='NetworkName_id' value='" . $name->getID() . "'> \n"; Html::showSimpleForm($name->getFormURL(), 'unaffect', _sx('button', 'Dissociate'), array('id' => $name->getID()), $CFG_GLPI["root_doc"] . '/pics/sub_dropdown.png'); } else { echo self::getTypeName(1); } echo "</th>\n"; echo "</tr><tr class='tab_bg_1'>"; echo "<td>" . self::getTypeName(1) . "</td><td>\n"; Html::autocompletionTextField($name, "name", array('name' => 'NetworkName_name')); echo "</td>\n"; echo "<td>" . FQDN::getTypeName(1) . "</td><td>"; Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField("fqdns_id")), array('value' => $name->fields["fqdns_id"], 'name' => 'NetworkName_fqdns_id', 'entity' => $name->getEntityID(), 'displaywith' => array('view'))); echo "</td>\n"; echo "</tr><tr class='tab_bg_1'>\n"; echo "<td>" . IPAddress::getTypeName(Session::getPluralNumber()); IPAddress::showAddChildButtonForItemForm($name, 'NetworkName__ipaddresses'); echo "</td>"; echo "<td>"; IPAddress::showChildsForItemForm($name, 'NetworkName__ipaddresses'); echo "</td>"; // MoYo : really need to display it here ? // make confure because not updatable // echo "<td>".IPNetwork::getTypeName(Session::getPluralNumber())." "; // Html::showToolTip(__('IP network is not included in the database. However, you can see current available networks.')); // echo "</td><td>"; // IPNetwork::showIPNetworkProperties($name->getEntityID()); // echo "</td>\n"; echo "<td colspan='2'> </td>"; echo "</tr>\n"; }
if ($tmpitem->getFromDB($data['items_id'])) { $outputval = sprintf(__('%1$s - %2$s'), $tmpitem->getTypeName(), $tmpitem->getName()); } else { $outputval = $tmpitem->getTypeName(); } } else { $outputval = $data[$field]; } } $outputval = Toolbox::unclean_cross_side_scripting_deep($outputval); if ($displaywith) { foreach ($_POST['displaywith'] as $key) { if (isset($data[$key])) { $withoutput = $data[$key]; if (isForeignKeyField($key)) { $withoutput = Dropdown::getDropdownName(getTableNameForForeignKeyField($key), $data[$key]); } if (strlen($withoutput) > 0 && $withoutput != ' ') { $outputval = sprintf(__('%1$s - %2$s'), $outputval, $withoutput); } } } } $ID = $data['id']; $addcomment = ""; $title = $outputval; if (isset($data["comment"])) { if (isset($data['transcomment']) && !empty($data['transcomment'])) { $addcomment .= $data['transcomment']; } else { $addcomment .= $data["comment"];
/** * Try to match a definied rule * * @param &$criterion RuleCriteria object * @param $field the field to match * @param &$criterias_results * @param &$regex_result * * @return true if the field match the rule, false if it doesn't match **/ static function match(RuleCriteria &$criterion, $field, &$criterias_results, &$regex_result) { $condition = $criterion->fields['condition']; $pattern = $criterion->fields['pattern']; $criteria = $criterion->fields['criteria']; //If pattern is wildcard, don't check the rule and return true //or if the condition is "already present in GLPI" : will be processed later if ($pattern == Rule::RULE_WILDCARD || $condition == Rule::PATTERN_FIND) { return true; } $pattern = trim($pattern); switch ($condition) { case Rule::PATTERN_EXISTS: return !empty($field); case Rule::PATTERN_DOES_NOT_EXISTS: return empty($field); case Rule::PATTERN_IS: if (is_array($field)) { // Special case (used only by UNIQUE_PROFILE, for now) // $pattern is an ID if (in_array($pattern, $field)) { $criterias_results[$criteria] = $pattern; return true; } } else { //Perform comparison with fields in lower case $field = Toolbox::strtolower($field); $pattern = Toolbox::strtolower($pattern); if ($field == $pattern) { $criterias_results[$criteria] = $pattern; return true; } } return false; case Rule::PATTERN_IS_NOT: //Perform comparison with fields in lower case $field = Toolbox::strtolower($field); $pattern = Toolbox::strtolower($pattern); if ($field != $pattern) { $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::PATTERN_UNDER: $table = getTableNameForForeignKeyField($criteria); $values = getSonsOf($table, $pattern); if (isset($values[$field])) { return true; } return false; case Rule::PATTERN_NOT_UNDER: $table = getTableNameForForeignKeyField($criteria); $values = getSonsOf($table, $pattern); if (isset($values[$field])) { return false; } return true; case Rule::PATTERN_END: $value = "/" . $pattern . "\$/i"; if (preg_match($value, $field) > 0) { $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::PATTERN_BEGIN: if (empty($pattern)) { return false; } $value = mb_stripos($field, $pattern, 0, 'UTF-8'); if ($value !== false && $value == 0) { $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::PATTERN_CONTAIN: if (empty($pattern)) { return false; } $value = mb_stripos($field, $pattern, 0, 'UTF-8'); if ($value !== false && $value >= 0) { $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::PATTERN_NOT_CONTAIN: if (empty($pattern)) { return false; } $value = mb_stripos($field, $pattern, 0, 'UTF-8'); if ($value === false) { $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::REGEX_MATCH: $results = array(); // Permit use < and > $pattern = Toolbox::unclean_cross_side_scripting_deep($pattern); if (preg_match_all($pattern . "i", $field, $results) > 0) { // Drop $result[0] : complete match result array_shift($results); // And add to $regex_result array $regex_result[] = $results[1]; $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::REGEX_NOT_MATCH: // Permit use < and > $pattern = Toolbox::unclean_cross_side_scripting_deep($pattern); if (preg_match($pattern . "i", $field) == 0) { $criterias_results[$criteria] = $pattern; return true; } return false; case Rule::PATTERN_FIND: case Rule::PATTERN_IS_EMPTY: // Global criteria will be evaluated later return true; } return false; }
/** * @see CommonDropdown::displaySpecificTypeField() */ function displaySpecificTypeField($ID, $field = array()) { switch ($field['type']) { case "plugin_customfields_dropdowns_id": // We have a dropdown. if (isset($_REQUEST['plugin_customfields_dropdowns_id'])) { $ID = $_REQUEST['plugin_customfields_dropdowns_id']; } elseif (isset($this->fields[$field['name']])) { $ID = $this->fields[$field['name']]; } else { $ID = -1; } Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField($field['name'])), array('value' => $ID, 'name' => $field['name'], 'entity' => $this->getEntityID(), 'auto_submit' => true)); break; case "plugin_customfields_dropdownsitems_id": // We have a dropdown item $condition = "plugin_customfields_dropdowns_id = -1"; if (isset($_REQUEST['plugin_customfields_dropdowns_id'])) { $condition = "plugin_customfields_dropdowns_id = '" . $_REQUEST['plugin_customfields_dropdowns_id'] . "'"; } if ($field['name'] == 'entities_id') { $restrict = -1; } else { $restrict = $this->getEntityID(); } Dropdown::show(getItemTypeForTable($this->getTable()), array('value' => $this->fields[$field['name']], 'name' => $field['name'], 'comments' => false, 'entity' => $restrict, 'used' => $ID > 0 ? getSonsOf($this->getTable(), $ID) : array(), 'condition' => $condition)); break; } }
/** * transform array of fields passed in parameter : * change value from integer id to string name of foreign key * You can pass an array of array, this method is recursive. * * @param $fields array to check and transform * @param $expand bool array of option to enable, could be : * - expand_dropdowns (default false) * - get_hateoas (default true) * * @return array altered $fields **/ protected static function parseDropdowns($fields, $params = array()) { // default params $default = array('expand_dropdowns' => false, 'get_hateoas' => true); $params = array_merge($default, $params); // parse fields recursively foreach ($fields as $key => &$value) { if (is_array($value)) { $value = self::parseDropdowns($value); } if (is_integer($key)) { continue; } if (isForeignKeyField($key)) { // specific key transformations if ($key == "items_id" && isset($fields['itemtype'])) { $key = getForeignKeyFieldForItemType($fields['itemtype']); } if ($key == "auths_id" && isset($fields['authtype']) && $fields['authtype'] == Auth::LDAP) { $key = "authldaps_id"; } if ($key == "default_requesttypes_id") { $key = "requesttypes_id"; } if (!empty($value) || $key == 'entities_id' && $value >= 0) { $tablename = getTableNameForForeignKeyField($key); $itemtype = getItemTypeForTable($tablename); // get hateoas if ($params['get_hateoas']) { $fields['links'][] = array('rel' => $itemtype, 'href' => self::$api_url . "/{$itemtype}/" . $value); } // expand dropdown if ($params['expand_dropdowns']) { $value = Dropdown::getDropdownName($tablename, $value); // fix value for inexistent items if ($value == " ") { $value = ""; } } } } } return $fields; }
/** * Check field unicity before insert or update * * @param add true for insert, false for update * @param $options array * * @return true if item can be written in DB, false if not **/ function checkUnicity($add = false, $options = array()) { global $LANG, $DB, $CFG_GLPI; $p['unicity_error_message'] = true; $p['add_event_on_duplicate'] = true; $p['disable_unicity_check'] = false; if (is_array($options) && count($options)) { foreach ($options as $key => $value) { $p[$key] = $value; } } $result = true; //Do not check unicity when creating infocoms or if checking is expliclty disabled if ($p['disable_unicity_check']) { return $result; } //Get all checks for this itemtype and this entity if (in_array(get_class($this), $CFG_GLPI["unicity_types"])) { // Get input entities if set / else get object one if (isset($this->input['entities_id'])) { $entities_id = $this->input['entities_id']; } else { $entities_id = $this->fields['entities_id']; } $all_fields = FieldUnicity::getUnicityFieldsConfig(get_class($this), $entities_id); foreach ($all_fields as $key => $fields) { //If there's fields to check if (!empty($fields) && !empty($fields['fields'])) { $where = ""; $continue = true; foreach (explode(',', $fields['fields']) as $field) { if (isset($this->input[$field]) && (getTableNameForForeignKeyField($field) == '' && $this->input[$field] != '' || getTableNameForForeignKeyField($field) != '' && $this->input[$field] > 0) && !Fieldblacklist::isFieldBlacklisted(get_class($this), $entities_id, $field, $this->input[$field])) { $where .= " AND `" . $this->getTable() . "`.`{$field}` = '" . $this->input[$field] . "'"; } else { $continue = false; } } if ($continue && $where != '') { $entities = $fields['entities_id']; if ($fields['is_recursive']) { $entities = getSonsOf('glpi_entities', $fields['entities_id']); } $where_global = getEntitiesRestrictRequest(" AND", $this->getTable(), '', $entities); //If update, exclude ID of the current object if (!$add) { $where .= " AND `" . $this->getTable() . "`.`id` NOT IN (" . $this->input['id'] . ") "; } if (countElementsInTable($this->table, "1 {$where} {$where_global}") > 0) { if ($p['unicity_error_message'] || $p['add_event_on_duplicate']) { $message = array(); foreach (explode(',', $fields['fields']) as $field) { $table = getTableNameForForeignKeyField($field); if ($table != '') { $searchOption = $this->getSearchOptionByField('field', 'name', $table); } else { $searchOption = $this->getSearchOptionByField('field', $field); } $message[] = $searchOption['name'] . '=' . $this->input[$field]; } $doubles = getAllDatasFromTable($this->table, "1 {$where} {$where_global}"); $message_text = $this->getUncityErrorMessage($message, $fields, $doubles); if ($p['unicity_error_message']) { if (!$fields['action_refuse']) { $show_other_messages = $fields['action_refuse'] ? true : false; } else { $show_other_messages = true; } addMessageAfterRedirect($message_text, true, $show_other_messages, $show_other_messages); } if ($p['add_event_on_duplicate']) { Event::log(!$add ? $this->fields['id'] : 0, get_class($this), 4, 'inventory', $_SESSION["glpiname"] . " " . $LANG['log'][123] . ' : ' . $message_text); } } if ($fields['action_refuse']) { $result = false; } if ($fields['action_notify']) { $params = array('message' => html_clean($message_text), 'action_type' => $add, 'action_user' => getUserName(getLoginUserID()), 'entities_id' => $entities_id, 'itemtype' => get_class($this), 'date' => $_SESSION['glpi_currenttime'], 'refuse' => $fields['action_refuse']); NotificationEvent::raiseEvent('refuse', new FieldUnicity(), $params); } } } } } } return $result; }
/** * Delete a field in DB * @param table the table * @param field the field to delete * @return nothing */ static function deleteField($table, $field) { global $DB; //Remove field from displaypreferences self::deleteDisplayPreferences($table, $field); //If field exists, drop it ! if (FieldExists($table, $field)) { $DB->query("ALTER TABLE `{$table}` DROP `{$field}`"); } $table = getTableNameForForeignKeyField($field); //If dropdown is managed by the plugin if ($table != '' && preg_match('/plugin_genericobject_(.*)/', $table, $results)) { //Delete dropdown table $query = "DROP TABLE `{$table}`"; $DB->query($query); //Delete dropdown files & class $name = getSingular($results[1]); PluginGenericobjectType::deleteClassFile($name); PluginGenericobjectType::deleteFormFile($name); PluginGenericobjectType::deletesearchFile($name); } }
function showForm($ID, $options = array()) { global $CFG_GLPI; if (!$this->isNewID($ID)) { $this->check($ID, READ); } else { // Create item $this->check(-1, CREATE); } $this->showFormHeader($options); $fields = $this->getAdditionalFields(); $nb = count($fields); echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>"; echo "<td>"; if ($this instanceof CommonDevice) { // Awfull hack for CommonDevice where name is designation Html::autocompletionTextField($this, "designation"); } else { Html::autocompletionTextField($this, "name"); } echo "</td>"; echo "<td rowspan='" . ($nb + 1) . "'>" . __('Comments') . "</td>"; echo "<td rowspan='" . ($nb + 1) . "'>\n <textarea cols='45' rows='" . ($nb + 2) . "' name='comment' >" . $this->fields["comment"]; echo "</textarea></td></tr>\n"; foreach ($fields as $field) { if ($field['name'] == 'entities_id' && $ID == 0 && !$this->isNewID($ID)) { // No display for root entity echo "<tr class='tab_bg_1'><td colspan='2'> </td></tr>"; break; } if (!isset($field['type'])) { $field['type'] = ''; } if ($field['name'] == 'header') { echo "<tr class='tab_bg_1'><th colspan='2'>" . $field['label'] . "</th></tr>"; continue; } echo "<tr class='tab_bg_1'><td>" . $field['label']; if (isset($field['comment']) && !empty($field['comment'])) { echo " "; Html::showToolTip($field['comment']); } echo "</td><td>"; switch ($field['type']) { case 'UserDropdown': $param = array('name' => $field['name'], 'value' => $this->fields[$field['name']], 'right' => 'interface', 'entity' => $this->fields["entities_id"]); if (isset($field['right'])) { $params['right'] = $field['right']; } User::dropdown($param); break; case 'dropdownValue': $params = array('value' => $this->fields[$field['name']], 'name' => $field['name'], 'entity' => $this->getEntityID()); if (isset($field['condition'])) { $params['condition'] = $field['condition']; } Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField($field['name'])), $params); break; case 'text': Html::autocompletionTextField($this, $field['name']); break; case 'textarea': $cols = 40; $rows = 3; if (isset($field['rows'])) { $rows = $field['rows']; } if (isset($field['cols'])) { $cols = $field['cols']; } echo "<textarea name='" . $field['name'] . "' cols='{$cols}' rows='{$rows}'>" . $this->fields[$field['name']] . "</textarea >"; break; case 'integer': Dropdown::showNumber($field['name'], array('value' => $this->fields[$field['name']])); break; case 'timestamp': $param = array('value' => $this->fields[$field['name']]); if (isset($field['min'])) { $param['min'] = $field['min']; } if (isset($field['max'])) { $param['max'] = $field['max']; } if (isset($field['step'])) { $param['step'] = $field['step']; } Dropdown::showTimeStamp($field['name'], $param); break; case 'parent': if ($field['name'] == 'entities_id') { $restrict = -1; } else { $restrict = $this->getEntityID(); } Dropdown::show(getItemTypeForTable($this->getTable()), array('value' => $this->fields[$field['name']], 'name' => $field['name'], 'entity' => $restrict, 'used' => $ID > 0 ? getSonsOf($this->getTable(), $ID) : array())); break; case 'icon': Dropdown::dropdownIcons($field['name'], $this->fields[$field['name']], GLPI_ROOT . "/pics/icones"); if (!empty($this->fields[$field['name']])) { echo " <img style='vertical-align:middle;' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $this->fields[$field['name']] . "'>"; } break; case 'bool': Dropdown::showYesNo($field['name'], $this->fields[$field['name']]); break; case 'color': Html::showColorField($field['name'], array('value' => $this->fields[$field['name']])); break; case 'date': Html::showDateField($field['name'], array('value' => $this->fields[$field['name']])); break; case 'datetime': Html::showDateTimeField($field['name'], array('value' => $this->fields[$field['name']])); break; case 'password': echo "<input type='password' name='password' value='' size='20' autocomplete='off'>"; break; default: $this->displaySpecificTypeField($ID, $field); break; } if (isset($field['unit'])) { echo " " . $field['unit']; } echo "</td></tr>\n"; } if (isset($this->fields['is_protected']) && $this->fields['is_protected']) { $options['candel'] = false; } if (isset($_REQUEST['_in_modal'])) { echo "<input type='hidden' name='_in_modal' value='1'>"; } $this->showFormButtons($options); return true; }
function executeActions($output, $params) { PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-locationrules", "execute action\n"); if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "assign": PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-locationrules", "value " . $action->fields["value"] . "\n"); $output[$action->fields["field"]] = $action->fields["value"]; break; case "regex_result": $res = ''; if (isset($this->regex_results[0])) { $res .= RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]); } else { $res .= $action->fields["value"]; } if ($res != '') { $entities_id = 0; if (isset($_SESSION["plugin_fusioninventory_entity"]) && $_SESSION["plugin_fusioninventory_entity"] > 0) { $entities_id = $_SESSION["plugin_fusioninventory_entity"]; } $res = Dropdown::importExternal(getItemTypeForTable(getTableNameForForeignKeyField($action->fields['field'])), $res, $entities_id); } $output[$action->fields["field"]] = $res; break; } } } return $output; }
function getSearchOptions() { $tab = array(); $tab[1]['table'] = $this->getTable(); $tab[1]['field'] = 'name'; $tab[1]['linkfield'] = 'name'; $tab[1]['name'] = __('Name'); $tab[1]['datatype'] = 'itemlink'; $tab[1]['itemlink_type'] = $this->getType(); $tab[19]['table'] = $this->getTable(); $tab[19]['field'] = 'date_mod'; $tab[19]['linkfield'] = ''; $tab[19]['name'] = __('Last update'); $tab[19]['datatype'] = 'datetime'; $tab[2]['table'] = $this->getTable(); $tab[2]['field'] = 'url'; $tab[2]['linkfield'] = 'url'; $tab[2]['name'] = __('Mirror server address', 'fusioninventory'); $tab[2]['datatype'] = 'string'; $tab[16]['table'] = $this->getTable(); $tab[16]['field'] = 'comment'; $tab[16]['linkfield'] = 'comment'; $tab[16]['name'] = __('Comments'); $tab[16]['datatype'] = 'text'; $tab[80]['table'] = 'glpi_entities'; $tab[80]['field'] = 'completename'; $tab[80]['name'] = __('Entity'); $tab[81]['table'] = getTableNameForForeignKeyField('locations_id'); $tab[81]['field'] = 'completename'; $tab[81]['linkfield'] = 'locations_id'; $tab[81]['name'] = Location::getTypeName(); $tab[81]['datatype'] = 'itemlink'; $tab[86]['table'] = $this->getTable(); $tab[86]['field'] = 'is_recursive'; $tab[86]['linkfield'] = 'is_recursive'; $tab[86]['name'] = __('Child entities'); $tab[86]['datatype'] = 'bool'; return $tab; }
/** * Print the HTML array children of a TreeDropdown * *@param $ID of the dropdown * *@return Nothing (display) **/ function showChildren($ID) { global $DB, $CFG_GLPI, $LANG; $this->check($ID, 'r'); $fields = $this->getAdditionalFields(); $nb = count($fields); $entity_assign = $this->isEntityAssign(); // Minimal form for quick input. if ($this->canCreate()) { $link = $this->getFormURL(); echo "<div class='firstbloc'>"; echo "<form action='" . $link . "' method='post'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . $LANG['common'][93] . "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . $LANG['common'][16] . " : "; autocompletionTextField($this, "name", array('value' => '')); if ($entity_assign && $this->getForeignKeyField() != 'entities_id') { echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>"; } if ($entity_assign && $this->isRecursive()) { echo "<input type='hidden' name='is_recursive' value='1'>"; } echo "<input type='hidden' name='" . $this->getForeignKeyField() . "' value='{$ID}'></td>"; echo "<td><input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table></form></div>\n"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='" . ($nb + 3) . "'>" . $LANG['setup'][76] . " " . $this->getTreeLink(); echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; // Name if ($entity_assign) { echo "<th>" . $LANG['entity'][0] . "</th>"; // Entity } foreach ($fields as $field) { if ($field['list']) { echo "<th>" . $field['label'] . "</th>"; } } echo "<th>" . $LANG['common'][25] . "</th>"; echo "</tr>\n"; $fk = $this->getForeignKeyField(); $crit = array($fk => $ID, 'ORDER' => 'name'); if ($entity_assign) { if ($fk == 'entities_id') { $crit['id'] = $_SESSION['glpiactiveentities']; $crit['id'] += $_SESSION['glpiparententities']; } else { $crit['entities_id'] = $_SESSION['glpiactiveentities']; } } foreach ($DB->request($this->getTable(), $crit) as $data) { echo "<tr class='tab_bg_1'>"; echo "<td><a href='" . $this->getFormURL(); echo '?id=' . $data['id'] . "'>" . $data['name'] . "</a></td>"; if ($entity_assign) { echo "<td>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]) . "</td>"; } foreach ($fields as $field) { if ($field['list']) { echo "<td>"; switch ($field['type']) { case 'UserDropdown': echo getUserName($data[$field['name']]); break; case 'bool': echo Dropdown::getYesNo($data[$field['name']]); break; case 'dropdownValue': echo Dropdown::getDropdownName(getTableNameForForeignKeyField($field['name']), $data[$field['name']]); break; default: echo $data[$field['name']]; } echo "</td>"; } } echo "<td>" . $data['comment'] . "</td>"; echo "</tr>\n"; } echo "</table></div>\n"; }
/** * Display a list of available fields for unicity checks * * @param $unicity an instance of CommonDBTM class * * @return nothing **/ static function selectCriterias(CommonDBTM $unicity) { global $DB; //Do not check unicity on fields in DB with theses types $blacklisted_types = array('longtext', 'text'); echo "<span id='span_fields' name='span_fields'>"; if (!isset($unicity->fields['itemtype']) || !$unicity->fields['itemtype']) { echo "</span>"; return; } if (!isset($unicity->fields['entities_id'])) { $unicity->fields['entities_id'] = $_SESSION['glpiactive_entity']; } $unicity_fields = explode(',', $unicity->fields['fields']); //Search option for this type $target = new $unicity->fields['itemtype'](); //Construct list echo "<span id='span_fields' name='span_fields'>"; echo "<select name='_fields[]' multiple size='15' style='width:400px'>"; foreach ($DB->list_fields(getTableForItemType($unicity->fields['itemtype'])) as $field) { $searchOption = $target->getSearchOptionByField('field', $field['Field']); if (empty($searchOption)) { if ($table = getTableNameForForeignKeyField($field['Field'])) { $searchOption = $target->getSearchOptionByField('field', 'name', $table); } } if (!empty($searchOption) && !in_array($field['Type'], $blacklisted_types) && !in_array($field['Field'], $target->getUnallowedFieldsForUnicity())) { echo "<option value='" . $field['Field'] . "'"; if (isset($unicity_fields) && in_array($field['Field'], $unicity_fields)) { echo " selected "; } echo ">" . $searchOption['name'] . "</option>"; } } echo "</select></span>"; }
function transfer($new_entity) { global $DB; if ($this->fields['id'] > 0 && $this->fields['entities_id'] != $new_entity) { //Update entity for this object $tmp['id'] = $this->fields['id']; $tmp['entities_id'] = $new_entity; $this->update($tmp); $toupdate = array('id' => $this->fields['id']); foreach (PluginGenericobjectSingletonObjectField::getInstance(get_called_class()) as $field => $data) { $table = getTableNameForForeignKeyField($field); //It is a dropdown table ! if ($field != 'entities_id' && $table != '' && isset($this->fields[$field]) && $this->fields[$field] > 0) { //Instanciate a new dropdown object $dropdown_itemtype = getItemTypeForTable($table); $dropdown = new $dropdown_itemtype(); $dropdown->getFromDB($this->fields[$field]); //If dropdown is only accessible in the other entity //do not go further if (!$dropdown->isEntityAssign() || in_array($new_entity, getAncestorsOf('glpi_entities', $dropdown->getEntityID()))) { continue; } else { $tmp = array(); $where = ""; if ($dropdown instanceof CommonTreeDropdown) { $tmp['completename'] = $dropdown->fields['completename']; $where = "`completename`='" . addslashes_deep($tmp['completename']) . "'"; } else { $tmp['name'] = $dropdown->fields['name']; $where = "`name`='" . addslashes_deep($tmp['name']) . "'"; } $tmp['entities_id'] = $new_entity; $where .= " AND `entities_id`='" . $tmp['entities_id'] . "'"; //There's a dropdown value in the target entity if ($found = $this->find($where)) { $myfound = array_pop($found); if ($myfound['id'] != $this->fields[$field]) { $toupdate[$field] = $myfound['id']; } } else { $clone = $dropdown->fields; if ($dropdown instanceof CommonTreeDropdown) { unset($clone['completename']); } unset($clone['id']); $clone['entities_id'] = $new_entity; $new_id = $dropdown->import($clone); $toupdate[$field] = $new_id; } } } } $this->update($toupdate); } return true; }
/** * Get all dropdown fields associated with an itemtype * @param itemtype the itemtype * @return an array or fields that represents the dropdown tables */ static function getDropdownForItemtype($itemtype) { global $DB; $associated_tables = array(); if (class_exists($itemtype)) { $source_table = getTableForItemType($itemtype); foreach (PluginGenericobjectSingletonObjectField::getInstance($itemtype) as $field => $value) { $table = getTableNameForForeignKeyField($field); $options = PluginGenericobjectField::getFieldOptions($field, $itemtype); if (isset($options['input_type']) and $options['input_type'] === 'dropdown' and preg_match('/^glpi_plugin_genericobject/', $table)) { $associated_tables[] = $table; } } } return $associated_tables; }
/** * Print the HTML array children of a TreeDropdown * * @return Nothing (display) **/ function showChildren() { global $DB, $CFG_GLPI; $ID = $this->getID(); $this->check($ID, READ); $fields = $this->getAdditionalFields(); $nb = count($fields); $entity_assign = $this->isEntityAssign(); // Minimal form for quick input. if (static::canCreate()) { $link = $this->getFormURL(); echo "<div class='firstbloc'>"; echo "<form action='" . $link . "' method='post'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='3'>" . __('New child heading') . "</th></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td><td>"; Html::autocompletionTextField($this, "name", array('value' => '')); if ($entity_assign && $this->getForeignKeyField() != 'entities_id') { echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>"; } if ($entity_assign && $this->isRecursive()) { echo "<input type='hidden' name='is_recursive' value='1'>"; } echo "<input type='hidden' name='" . $this->getForeignKeyField() . "' value='{$ID}'></td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table>"; Html::closeForm(); echo "</div>\n"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixehov'>"; echo "<tr class='noHover'><th colspan='" . ($nb + 3) . "'>" . sprintf(__('Sons of %s'), $this->getTreeLink()); echo "</th></tr>"; $header = "<tr><th>" . __('Name') . "</th>"; if ($entity_assign) { $header .= "<th>" . __('Entity') . "</th>"; } foreach ($fields as $field) { if ($field['list']) { $header .= "<th>" . $field['label'] . "</th>"; } } $header .= "<th>" . __('Comments') . "</th>"; $header .= "</tr>\n"; echo $header; $fk = $this->getForeignKeyField(); $crit = array($fk => $ID, 'ORDER' => 'name'); if ($entity_assign) { if ($fk == 'entities_id') { $crit['id'] = $_SESSION['glpiactiveentities']; $crit['id'] += $_SESSION['glpiparententities']; } else { $crit['entities_id'] = $_SESSION['glpiactiveentities']; } } $nb = 0; foreach ($DB->request($this->getTable(), $crit) as $data) { $nb++; echo "<tr class='tab_bg_1'>"; echo "<td><a href='" . $this->getFormURL(); echo '?id=' . $data['id'] . "'>" . $data['name'] . "</a></td>"; if ($entity_assign) { echo "<td>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]) . "</td>"; } foreach ($fields as $field) { if ($field['list']) { echo "<td>"; switch ($field['type']) { case 'UserDropdown': echo getUserName($data[$field['name']]); break; case 'bool': echo Dropdown::getYesNo($data[$field['name']]); break; case 'dropdownValue': echo Dropdown::getDropdownName(getTableNameForForeignKeyField($field['name']), $data[$field['name']]); break; default: echo $data[$field['name']]; } echo "</td>"; } } echo "<td>" . $data['comment'] . "</td>"; echo "</tr>\n"; } if ($nb) { echo $header; } echo "</table></div>\n"; }
/** * @covers ::getTableNameForForeignKeyField * @dataProvider dataTableKey **/ public function testGetTableNameForForeignKeyField($table, $key) { if ($key) { $this->assertEquals($table, getTableNameForForeignKeyField($key)); } }
/** * Export rules in a xml format * * @param items array the input data to transform to xml * * @since version 0.85 * * @return nothing, send attachment to browser **/ static function exportRulesToXML($items = array()) { if (!count($items)) { return false; } $rulecollection = new self(); $rulecritera = new RuleCriteria(); $ruleaction = new RuleAction(); //create xml $xmlE = new SimpleXMLElement('<rules/>'); //parse all rules foreach ($items as $key => $ID) { $rulecollection->getFromDB($ID); if (!class_exists($rulecollection->fields['sub_type'])) { continue; } $rule = new $rulecollection->fields['sub_type'](); unset($rulecollection->fields['id']); unset($rulecollection->fields['date_mod']); $name = Dropdown::getDropdownName("glpi_entities", $rulecollection->fields['entities_id']); $rulecollection->fields['entities_id'] = $name; //add root node $xmlERule = $xmlE->addChild('rule'); //convert rule direct indexes in XML foreach ($rulecollection->fields as $key => $val) { $xmlERule->{$key} = $val; } //find criterias $criterias = $rulecritera->find("`rules_id` = '{$ID}'"); foreach ($criterias as &$criteria) { unset($criteria['id']); unset($criteria['rules_id']); $available_criteria = $rule->getCriterias(); $crit = $criteria['criteria']; if (self::isCriteraADropdown($available_criteria, $criteria['condition'], $crit)) { $criteria['pattern'] = Html::clean(Dropdown::getDropdownName($available_criteria[$crit]['table'], $criteria['pattern'])); } //convert criterias in XML $xmlECritiera = $xmlERule->addChild('rulecriteria'); foreach ($criteria as $key => $val) { $xmlECritiera->{$key} = $val; } } //find actions $actions = $ruleaction->find("`rules_id` = '{$ID}'"); foreach ($actions as &$action) { unset($action['id']); unset($action['rules_id']); //process FK (just in case of "assign" action) if ($action['action_type'] == "assign" && strpos($action['field'], '_id') !== false && !($action['field'] == "entities_id" && $action['value'] == 0)) { $field = $action['field']; if ($action['field'][0] == "_") { $field = substr($action['field'], 1); } $table = getTableNameForForeignKeyField($field); $action['value'] = Html::clean(Dropdown::getDropdownName($table, $action['value'])); } //convert actions in XML $xmlEAction = $xmlERule->addChild('ruleaction'); foreach ($action as $key => $val) { $xmlEAction->{$key} = $val; } } } //convert SimpleXMLElement to xml string $xml = $xmlE->asXML(); //send attachment to browser header('Content-type: application/xml'); header('Content-Disposition: attachment; filename="rules.xml"'); echo $xml; //exit; }
static function getComputerInformations($ocs_fields = array(), $cfg_ocs, $entities_id, $locations_id = 0) { $input = array(); $input["is_dynamic"] = 1; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entities_id; if ($locations_id) { $input["locations_id"] = $locations_id; } $input['ocsid'] = $ocs_fields['ID']; foreach (self::getOcsFieldsMatching() as $glpi_field => $ocs_field) { if (isset($ocs_fields[$ocs_field])) { $table = getTableNameForForeignKeyField($glpi_field); $ocs_field = Toolbox::encodeInUtf8($ocs_field); //Field a a foreing key if ($table != '') { $itemtype = getItemTypeForTable($table); $item = new $itemtype(); $external_params = array(); foreach ($item->additional_fields_for_dictionnary as $field) { if (isset($ocs_fields[$field])) { $external_params[$field] = $ocs_fields[$field]; } else { $external_params[$field] = ""; } } $input[$glpi_field] = Dropdown::importExternal($itemtype, $ocs_fields[$ocs_field], $entities_id, $external_params); } else { switch ($glpi_field) { default: $input[$glpi_field] = $ocs_fields[$ocs_field]; break; case 'contact': if ($users_id = User::getIDByField('name', $ocs_fields[$ocs_field])) { $input[$glpi_field] = $users_id; } break; case 'comment': $input[$glpi_field] = ''; if (!empty($ocs_fields["DESCRIPTION"]) && $ocs_fields["DESCRIPTION"] != NOT_AVAILABLE) { $input[$glpi_field] .= $ocs_fields["DESCRIPTION"] . "\r\n"; } $input[$glpi_field] .= addslashes(sprintf(__('%1$s %2$s'), $input[$glpi_field], sprintf(__('%1$s: %2$s'), __('Swap', 'ocsinventoryng'), $ocs_fields["SWAP"]))); break; } } } } return $input; }
static function showFields($item, $itemclass) { global $DB; if (isset($item["fields"]) && !empty($item["fields"])) { $input = explode(',', $item['fields']); $target = new $item['itemtype'](); foreach ($DB->list_fields(getTableForItemType($item['itemtype'])) as $field) { if (in_array($field['Field'], $input)) { $searchOption = $target->getSearchOptionByField('field', $field['Field']); if (empty($searchOption)) { $table = getTableNameForForeignKeyField($field['Field']); if ($table = getTableNameForForeignKeyField($field['Field'])) { $crit = getItemForItemtype(getItemTypeForTable($table)); if ($crit instanceof CommonTreeDropdown) { $searchOption = $target->getSearchOptionByField('field', 'completename', $table); } else { $searchOption = $target->getSearchOptionByField('field', 'name', $table); } } } if (!empty($searchOption) && isset($itemclass->fields[$field['Field']]) && !empty($itemclass->fields[$field['Field']]) && !in_array($field['Field'], self::getUnallowedFields($item['itemtype']))) { self::getFieldsValue($searchOption, $field, $itemclass); } } } } }
function getValueForKey($val, $key) { if (strstr($key, "_id") || $key == 'is_ocs_import' and $val == '0') { $val = ""; } $table = getTableNameForForeignKeyField($key); if ($table != "") { $linkItemtype = getItemTypeForTable($table); $class = new $linkItemtype(); // $name = $class->getTypeName(); if ($val == "0" or $val == "") { $val = ""; } else { $class->getFromDB($val); $val = $class->getName(); } } return $val; }
function replaceids($array) { global $CFG_GLPI; foreach ($array as $key => $value) { if (!is_int($key) && ($key == "software" || $key == 'ipaddress' || $key == 'internalport')) { // do nothing } else { //if (is_array($value)) { if ((array) $value === $value) { $array[$key] = $this->replaceids($value); } else { if (!is_numeric($key) && ($key == "manufacturers_id" || $key == 'bios_manufacturers_id')) { $manufacturer = new Manufacturer(); $array[$key] = $manufacturer->processName($value); if ($key == 'bios_manufacturers_id') { $this->foreignkey_itemtype[$key] = getItemTypeForTable(getTableNameForForeignKeyField('manufacturers_id')); } else { if (isset($CFG_GLPI['plugin_fusioninventory_computermanufacturer'][$value])) { $CFG_GLPI['plugin_fusioninventory_computermanufacturer'][$value] = $array[$key]; } } } if (!is_numeric($key)) { if ($key == "bios_manufacturers_id") { $array[$key] = Dropdown::importExternal($this->foreignkey_itemtype['manufacturers_id'], $value); } else { if ($key == "locations_id") { $array[$key] = Dropdown::importExternal('Location', $value, $_SESSION["plugin_fusioninventory_entity"]); } else { if (isset($this->foreignkey_itemtype[$key])) { $array[$key] = Dropdown::importExternal($this->foreignkey_itemtype[$key], $value, $_SESSION["plugin_fusioninventory_entity"]); } else { if (isForeignKeyField($key) && $key != "users_id") { $this->foreignkey_itemtype[$key] = getItemTypeForTable(getTableNameForForeignKeyField($key)); if ($key == 'computermodels_id') { if (isset($CFG_GLPI['plugin_fusioninventory_computermanufacturer'])) { $manufacturer = current($CFG_GLPI['plugin_fusioninventory_computermanufacturer']); $array[$key] = Dropdown::importExternal($this->foreignkey_itemtype[$key], $value, $_SESSION["plugin_fusioninventory_entity"], array('manufacturer' => $manufacturer)); } else { $array[$key] = 0; } } else { $array[$key] = Dropdown::importExternal($this->foreignkey_itemtype[$key], $value, $_SESSION["plugin_fusioninventory_entity"]); } } } } } } } } } return $array; }
/** * List doubles * * @param $unicity an instance of FieldUnicity class **/ static function showDoubles(FieldUnicity $unicity) { global $DB; $fields = array(); $where_fields = array(); if (!($item = getItemForItemtype($unicity->fields['itemtype']))) { return; } foreach (explode(',', $unicity->fields['fields']) as $field) { $fields[] = $field; $where_fields[] = $field; } if (!empty($fields)) { $colspan = count($fields) + 1; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='" . $colspan . "'>" . __('Duplicates') . "</th></tr>"; $entities = array($unicity->fields['entities_id']); if ($unicity->fields['is_recursive']) { $entities = getSonsOf('glpi_entities', $unicity->fields['entities_id']); } $fields_string = implode(',', $fields); if ($item->maybeTemplate()) { $where_template = " AND `" . $item->getTable() . "`.`is_template` = '0'"; } else { $where_template = ""; } $where_fields_string = ""; foreach ($where_fields as $where_field) { if (getTableNameForForeignKeyField($where_field)) { $where_fields_string .= " AND `{$where_field}` IS NOT NULL AND `{$where_field}` <> '0'"; } else { $where_fields_string .= " AND `{$where_field}` IS NOT NULL AND `{$where_field}` <> ''"; } } $query = "SELECT {$fields_string},\n COUNT(*) AS cpt\n FROM `" . $item->getTable() . "`\n WHERE `" . $item->getTable() . "`.`entities_id` IN (" . implode(',', $entities) . ")\n {$where_template}\n {$where_fields_string}\n GROUP BY {$fields_string}\n ORDER BY cpt DESC"; $results = array(); foreach ($DB->request($query) as $data) { if ($data['cpt'] > 1) { $results[] = $data; } } if (empty($results)) { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='{$colspan}'>" . __('No item to display') . "</td></tr>"; } else { echo "<tr class='tab_bg_2'>"; foreach ($fields as $field) { $searchOption = $item->getSearchOptionByField('field', $field); echo "<th>" . $searchOption["name"] . "</th>"; } echo "<th>" . _x('quantity', 'Number') . "</th></tr>"; foreach ($results as $result) { echo "<tr class='tab_bg_2'>"; foreach ($fields as $field) { $table = getTableNameForForeignKeyField($field); if ($table != '') { echo "<td>" . Dropdown::getDropdownName($table, $result[$field]) . "</td>"; } else { echo "<td>" . $result[$field] . "</td>"; } } echo "<td class='numeric'>" . $result['cpt'] . "</td></tr>"; } } } else { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='{$colspan}'>" . __('No item to display') . "</td></tr>"; } echo "</table>"; }
static function prepareHtmlFields($fields, $items_id, $canedit = true, $show_table = true, $massiveaction = false) { if (empty($fields)) { return false; } //get object associated with this fields $tmp = $fields; $first_field = array_shift($tmp); $container_obj = new PluginFieldsContainer(); $container_obj->getFromDB($first_field['plugin_fields_containers_id']); $items_itemtype = ucfirst($container_obj->fields['itemtype']); $classname = "PluginFields" . $items_itemtype . preg_replace('/s$/', '', $container_obj->fields['name']); $obj = new $classname(); //find row for this object with the items_id $found_values = $obj->find("plugin_fields_containers_id = " . $first_field['plugin_fields_containers_id'] . " AND items_id = " . $items_id); $found_v = array_shift($found_values); // find profiles (to check if current profile can edit fields) $fprofile = new PluginFieldsProfile(); $found_p = $fprofile->find("`profiles_id` = '" . $_SESSION['glpiactiveprofile']['id'] . "'\n AND `plugin_fields_containers_id` = '" . $first_field['plugin_fields_containers_id'] . "'"); $first_found_p = array_shift($found_p); // test status for "CommonITILObject" objects if (is_subclass_of($items_itemtype, "CommonITILObject")) { $items_obj = new $items_itemtype(); $items_obj->getFromDB($items_id); if (in_array($items_obj->fields['status'], $items_obj->getClosedStatusArray()) || in_array($items_obj->fields['status'], $items_obj->getSolvedStatusArray()) || $first_found_p['right'] != CREATE) { $canedit = false; } } //show all fields $html = ""; $odd = 0; foreach ($fields as $field) { if ($field['type'] === 'header') { $html .= "<tr class='tab_bg_2'>"; $html .= "<th colspan='4'>" . $field['label'] . "</td>"; $html .= "</tr>"; $odd = 0; } else { //get value $value = ""; if (is_array($found_v)) { if ($field['type'] == "dropdown") { $value = $found_v["plugin_fields_" . $field['name'] . "dropdowns_id"]; } else { $value = $found_v[$field['name']]; } } if (isset($_SESSION['plugin']['fields']['values_sent'])) { if ($field['type'] == "dropdown") { $value = $_SESSION['plugin']['fields']['values_sent']["plugin_fields_" . $field['name'] . "dropdowns_id"]; } else { $value = $_SESSION['plugin']['fields']['values_sent'][$field['name']]; } } //get default value if (empty($value) && !empty($field['default_value'])) { $value = $field['default_value']; } //show field if ($show_table) { if ($odd % 2 == 0) { $html .= "<tr class='tab_bg_2'>"; } $required = $field['mandatory'] == 1 ? "<span class='red'>*</span>" : ''; if ($container_obj->fields['itemtype'] == 'Ticket' && $container_obj->fields['type'] == 'dom' && strpos($_SERVER['HTTP_REFERER'], ".injector.php") === false && strpos($_SERVER['HTTP_REFERER'], ".public.php") === false) { $html .= "<th width='13%'>" . $field['label'] . " : {$required}</th>"; } else { $html .= "<td>" . $field['label'] . " : {$required}</td>"; } $html .= "<td>"; } $readonly = $field['is_readonly']; switch ($field['type']) { case 'number': case 'text': $value = Html::cleanInputText($value); if ($canedit && !$readonly) { $html .= "<input type='text' name='" . $field['name'] . "' value=\"{$value}\" />"; } else { $html .= $value; } break; case 'textarea': if ($massiveaction) { continue; } if ($canedit && !$readonly) { $html .= "<textarea cols='45' rows='4' name='" . $field['name'] . "'>" . "{$value}</textarea>"; } else { $html .= nl2br($value); } break; case 'dropdown': if ($canedit && !$readonly) { //find entity on current object $obj = new $container_obj->fields['itemtype'](); $obj->getFromDB($items_id); ob_start(); if (strpos($field['name'], "dropdowns_id") !== false) { $dropdown_itemtype = getItemTypeForTable(getTableNameForForeignKeyField($field['name'])); } else { $dropdown_itemtype = PluginFieldsDropdown::getClassname($field['name']); } Dropdown::show($dropdown_itemtype, array('value' => $value, 'entity' => $obj->getEntityID())); $html .= ob_get_contents(); ob_end_clean(); } else { $dropdown_table = "glpi_plugin_fields_" . $field['name'] . "dropdowns"; $html .= Dropdown::getDropdownName($dropdown_table, $value); } break; case 'yesno': //in massive action, we must skip display for yesno (possible bug in framework) //otherwise double display of field if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); Dropdown::showYesNo($field['name'], $value); $html .= ob_get_contents(); ob_end_clean(); } else { $html .= Dropdown::getYesNo($value); } break; case 'date': if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); Html::showDateFormItem($field['name'], $value); $html .= ob_get_contents(); ob_end_clean(); } else { $html .= Html::convDate($value); } break; case 'datetime': if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); Html::showDateTimeFormItem($field['name'], $value); $html .= ob_get_contents(); ob_end_clean(); } else { $html .= Html::convDateTime($value); } case 'dropdownuser': if ($massiveaction) { continue; } if ($canedit && !$readonly) { ob_start(); User::dropdown(array('name' => $field['name'], 'value' => $value, 'entity' => -1, 'right' => 'all', 'condition' => 'is_active=1 && is_deleted=0')); $html .= ob_get_contents(); ob_end_clean(); } else { $showuserlink = 0; if (Session::haveRight('user', 'r')) { $showuserlink = 1; } $html .= getUserName($value, $showuserlink); } } if ($show_table) { $html .= "</td>"; if ($odd % 2 == 1) { $html .= "</tr>"; } $odd++; } } } if ($show_table && $odd % 2 == 1) { $html .= "</tr>"; } unset($_SESSION['plugin']['fields']['values_sent']); return $html; }
/** * Get all dropdown fields associated with an itemtype * @param itemtype the itemtype * @return an array or fields that represents the dropdown tables */ static function getDropdownForItemtype($itemtype) { global $DB; $associated_tables = array(); if (class_exists($itemtype)) { $source_table = getTableForItemType($itemtype); foreach (PluginGenericobjectSingletonObjectField::getInstance($itemtype) as $field => $value) { $table = getTableNameForForeignKeyField($field); //If it's a drodpdown if ($table && preg_match("/" . getSingular($source_table) . "/", $table)) { $associated_tables[] = $table; } } } return $associated_tables; }
/** * Contruct parameters restriction for listInventoryObjects sql request * * @param $params the input parameters * @param $item CommonDBTM object * @param $table * @param $where **/ static function listInventoryObjectsRequestParameters($params, CommonDBTM $item, $table, $where = "WHERE 1") { $already_used = array(); foreach ($params as $key => $value) { //Key representing the FK associated with the _name value $key_transformed = preg_replace("/_name/", "s_id", $key); $fk_table = getTableNameForForeignKeyField($key); $option = $item->getSearchOptionByField('field', $key_transformed); if (!empty($option)) { if (!in_array($key, $already_used) && isset($params[$key]) && $params[$key] && ($item->getField($option['linkfield']) != NOT_AVAILABLE || $item->getField($option['field']) != NOT_AVAILABLE)) { if (getTableNameForForeignKeyField($key)) { $where .= " AND `{$table}`.`{$key}`='" . Toolbox::addslashes_deep($params[$key]) . "'"; } else { // if ($key != $key_transformed || $table != $option['table']) { $where .= " AND `" . Toolbox::addslashes_deep($option['table']) . "`.`" . Toolbox::addslashes_deep($option['field']) . "`\n LIKE '%" . Toolbox::addslashes_deep($params[$key]) . "%'"; } else { $where .= " AND `{$table}`.`{$key}`\n LIKE '%" . Toolbox::addslashes_deep($params[$key]) . "%'"; } } $already_used[] = $key; } } } return $where; }
/** * Print the network alias form * * @param $ID integer ID of the item * @param $options array * - target for the Form * - withtemplate template or basic computer * * @return Nothing (display) **/ function showForm($ID, $options = array()) { // Show only simple form to add / edit $showsimple = false; if (isset($options['parent'])) { $showsimple = true; $options['networknames_id'] = $options['parent']->getID(); } $this->initForm($ID, $options); $recursiveItems = $this->recursivelyGetItems(); if (count($recursiveItems) == 0) { return false; } $lastItem = $recursiveItems[count($recursiveItems) - 1]; if (!$showsimple) { $this->showTabs(); } $options['entities_id'] = $lastItem->getField('entities_id'); $this->showFormHeader($options); echo "<tr class='tab_bg_1'><td>"; $this->displayRecursiveItems($recursiveItems, 'Type'); echo " :</td>\n<td>"; if (!($ID > 0)) { echo "<input type='hidden' name='networknames_id' value='" . $this->fields["networknames_id"] . "'>\n"; } $this->displayRecursiveItems($recursiveItems, isset($options['popup']) ? "Name" : "Link"); echo "</td><td>" . __('Name') . "</td><td>\n"; Html::autocompletionTextField($this, "name"); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . FQDN::getTypeName() . "</td><td>"; Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField("fqdns_id")), array('value' => $this->fields["fqdns_id"], 'name' => 'fqdns_id', 'entity' => $this->getEntityID(), 'displaywith' => array('view'))); echo "</td>"; echo "<td>" . __('Comments') . "</td>"; echo "<td><textarea cols='45' rows='4' name='comment' >" . $this->fields["comment"]; echo "</textarea></td>\n"; echo "</tr>\n"; $this->showFormButtons($options); if (!$showsimple) { $this->addDivForTabs(); } return true; }
/** * Generic Function to display Items * * @param $itemtype item type * @param $ID ID of the SEARCH_OPTION item * @param $data array containing data results * @param $num item num in the request * @param $meta is a meta item ? * * @return string to print **/ static function giveItem($itemtype, $ID, $data, $num, $meta = 0) { global $CFG_GLPI, $LANG; $searchopt =& self::getOptions($itemtype); if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) { return self::giveItem($data["TYPE"], $ID, $data, $num, $meta); } // Plugin can override core definition for its type if ($plug = isPluginItemType($itemtype)) { $function = 'plugin_' . $plug['plugin'] . '_giveItem'; if (function_exists($function)) { $out = $function($itemtype, $ID, $data, $num); if (!empty($out)) { return $out; } } } $NAME = "ITEM_"; if ($meta) { $NAME = "META_"; } $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $linkfield = $searchopt[$ID]["linkfield"]; switch ($table . '.' . $field) { case "glpi_users.name": // USER search case if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if ($split[$k] > 0) { if ($count_display) { $out .= "<br>"; } $count_display++; if ($itemtype == 'Ticket') { $userdata = getUserName($split[$k], 2); $out .= $userdata['name'] . " " . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } else { $out .= getUserName($split[$k], 1); } } } // Manage alternative_email for tickets_users if ($itemtype == 'Ticket' && isset($data[$NAME . $num . '_2'])) { $split = explode("\$\$\$\$", $data[$NAME . $num . '_2']); for ($k = 0; $k < count($split); $k++) { $split2 = explode(" ", $split[$k]); if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>"; } } } return $out; } if ($itemtype != 'User') { $toadd = ''; if ($itemtype == 'Ticket' && $data[$NAME . $num . "_3"] > 0) { $userdata = getUserName($data[$NAME . $num . "_3"], 2); $toadd = " " . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } return formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 1) . $toadd; } break; case "glpi_profiles.interface": return Profile::getInterfaceName($data[$NAME . $num]); case "glpi_profiles.name": if ($itemtype == 'User' && $ID == 20) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . Dropdown::getDropdownName('glpi_entities', $split2[$k]); if ($split3[$k]) { $text .= " (R)"; } if (!in_array($text, $added)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_complete_entities.completename": if ($itemtype == 'User') { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $added = array(); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . Dropdown::getDropdownName('glpi_profiles', $split2[$k]); if ($split3[$k]) { $text .= " (R)"; } if (!in_array($text, $added)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_entities.completename": if ($data[$NAME . $num . "_2"] == 0) { // Set name for Root entity $data[$NAME . $num] = $LANG['entity'][2]; } break; case "glpi_documenttypes.icon": if (!empty($data[$NAME . $num])) { return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$NAME . $num] . "'>"; } return " "; case "glpi_documents.filename": $doc = new Document(); if ($doc->getFromDB($data['id'])) { return $doc->getDownloadLink(); } return NOT_AVAILABLE; case "glpi_deviceharddrives.specificity": case "glpi_devicememories.specificity": case "glpi_deviceprocessors.specificity": return $data[$NAME . $num]; case "glpi_networkports.mac": $out = ""; if ($itemtype == 'Computer') { $displayed = array(); if (!empty($data[$NAME . $num . "_2"])) { $split = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { $lowstr = utf8_strtolower($split[$k]); if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $split[$k]; $displayed[] = $lowstr; } } if (!empty($data[$NAME . $num])) { $out .= "<br>"; } } if (!empty($data[$NAME . $num])) { $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { $lowstr = utf8_strtolower($split[$k]); if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $split[$k]; $displayed[] = $lowstr; } } } return $out; } break; case "glpi_contracts.duration": case "glpi_contracts.notice": case "glpi_contracts.periodicity": case "glpi_contracts.billing": if (!empty($data[$NAME . $num])) { $split = explode('$$$$', $data[$NAME . $num]); $output = ""; foreach ($split as $duration) { $output .= (empty($output) ? '' : '<br>') . $duration . " " . $LANG['financial'][57]; } return $output; } return " "; case "glpi_contracts.renewal": return Contract::getContractRenewalName($data[$NAME . $num]); case "glpi_infocoms.sink_time": if (!empty($data[$NAME . $num])) { $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= empty($out) ? '' : '<br>'; if ($val > 0) { $out .= $val . " " . $LANG['financial'][9]; } } return $out; } return " "; case "glpi_infocoms.warranty_duration": if (!empty($data[$NAME . $num])) { $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= empty($out) ? '' : '<br>'; if ($val > 0) { $out .= $val . " " . $LANG['financial'][57]; } if ($val < 0) { $out .= $LANG['financial'][2]; } } return $out; } return " "; case "glpi_infocoms.sink_type": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . Infocom::getAmortTypeName($val); } return $out; case "glpi_infocoms.alert": if ($data[$NAME . $num] == pow(2, Alert::END)) { return $LANG['financial'][80]; } return ""; case "glpi_contracts.alert": switch ($data[$NAME . $num]) { case pow(2, Alert::END): return $LANG['buttons'][32]; case pow(2, Alert::NOTICE): return $LANG['financial'][10]; case pow(2, Alert::END) + pow(2, Alert::NOTICE): return $LANG['buttons'][32] . " + " . $LANG['financial'][10]; } return ""; case "glpi_tickets_tickets.tickets_id_1": $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $displayed = array(); for ($k = 0; $k < count($split); $k++) { $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split[$k]; if ($linkid > 0 && !isset($displayed[$linkid])) { $text = $linkid . " - " . Dropdown::getDropdownName('glpi_tickets', $linkid); if (count($displayed)) { $out .= "<br>"; } $displayed[$linkid] = $linkid; $out .= $text; } } return $out; case "glpi_tickets.count": if ($data[$NAME . $num] > 0 && haveRight("show_all_ticket", "1")) { if ($itemtype == 'User') { $options['field'][0] = 4; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $data['id']; $options['link'][0] = 'AND'; $options['field'][1] = 22; $options['searchtype'][1] = 'equals'; $options['contains'][1] = $data['id']; $options['link'][1] = 'OR'; $options['field'][2] = 5; $options['searchtype'][2] = 'equals'; $options['contains'][2] = $data['id']; $options['link'][2] = 'OR'; } else { $options['field'][0] = 12; $options['searchtype'][0] = 'equals'; $options['contains'][0] = 'all'; $options['link'][0] = 'AND'; $options['itemtype2'][0] = $itemtype; $options['field2'][0] = self::getOptionNumber($itemtype, 'name'); $options['searchtype2'][0] = 'equals'; $options['contains2'][0] = $data['id']; $options['link2'][0] = 'AND'; } $options['reset'] = 'reset'; $out = "<a id='ticket{$itemtype}" . $data['id'] . "' "; $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&') . "\">"; $out .= $data[$NAME . $num] . "</a>"; } else { $out = $data[$NAME . $num]; } return $out; case "glpi_softwarelicenses.number": if ($data[$NAME . $num . "_2"] == -1) { return $LANG['software'][4]; } if (empty($data[$NAME . $num])) { return 0; } return $data[$NAME . $num]; case "glpi_auth_tables.name": return Auth::getMethodName($data[$NAME . $num], $data[$NAME . $num . "_2"], 1, $data[$NAME . $num . "_3"] . $data[$NAME . $num . "_4"]); case "glpi_reservationitems.comment": if (empty($data[$NAME . $num])) { return "<a title=\"" . $LANG['reservation'][22] . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . $LANG['common'][49] . "</a>"; } return "<a title=\"" . $LANG['reservation'][22] . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . resume_text($data[$NAME . $num]) . "</a>"; case 'glpi_notifications.mode': return Notification::getMode($data[$NAME . $num]); case 'glpi_notifications.event': $item = NotificationTarget::getInstanceByType($data['itemtype']); if ($item) { $events = $item->getAllEvents(); return $events[$data[$NAME . $num]]; } return ''; case 'glpi_crontasks.description': $tmp = new CronTask(); return $tmp->getDescription($data['id']); case 'glpi_crontasks.state': return CronTask::getStateName($data[$NAME . $num]); case 'glpi_crontasks.mode': return CronTask::getModeName($data[$NAME . $num]); case 'glpi_crontasks.itemtype': if ($plug = isPluginItemType($data[$NAME . $num])) { return $plug['plugin']; } return ''; case 'glpi_tickets.status': $status = Ticket::getStatus($data[$NAME . $num]); return "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . $data[$NAME . $num] . ".png\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_tickets.type': return Ticket::getTicketTypeName($data[$NAME . $num]); case 'glpi_tickets.priority': return Ticket::getPriorityName($data[$NAME . $num]); case 'glpi_tickets.urgency': return Ticket::getUrgencyName($data[$NAME . $num]); case 'glpi_tickets.impact': return Ticket::getImpactName($data[$NAME . $num]); case 'glpi_tickets.items_id': if (!empty($data[$NAME . $num . "_2"]) && class_exists($data[$NAME . $num . "_2"])) { $item = new $data[$NAME . $num . "_2"](); if ($item->getFromDB($data[$NAME . $num])) { return $item->getLink(true); } } return ' '; case 'glpi_tickets.name': $link = getItemTypeFormURL('Ticket'); $out = "<a id='ticket" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"]; // Force solution tab if solved if ($data[$NAME . $num . "_4"] == 'solved') { $out .= "&forcetab=4"; } $out .= "\">" . $data[$NAME . $num]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; $out .= showToolTip(nl2br($data[$NAME . $num . "_3"]), array('applyto' => 'ticket' . $data[$NAME . $num . "_2"], 'display' => false)); return $out; case "glpi_tickets.due_date": // No due date in waiting status if ($data[$NAME . $num . '_2'] == 'waiting') { $data[$NAME . $num] = ""; } break; case 'glpi_ticketvalidations.status': case "glpi_tickets.global_validation": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $status = TicketValidation::getStatus($val); $bgcolor = TicketValidation::getStatusColor($val); $out .= (empty($out) ? '' : '<br>') . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>'; } return $out; case 'glpi_ticketsatisfactions.type': return TicketSatisfaction::getTypeInquestName($data[$NAME . $num]); case 'glpi_ticketsatisfactions.satisfaction': return TicketSatisfaction::displaySatisfaction($data[$NAME . $num]); case 'glpi_notimportedemails.reason': return NotImportedEmail::getReason($data[$NAME . $num]); case 'glpi_notimportedemails.messageid': $clean = array('<' => '', '>' => ''); return strtr($data[$NAME . $num], $clean); case 'glpi_fieldunicities.fields': $values = explode(',', $data[$NAME . $num]); $item = new $data['ITEMTYPE'](); $message = array(); foreach ($values as $field) { $table = getTableNameForForeignKeyField($field); if ($table != '') { $searchOption = $item->getSearchOptionByField('field', 'name', $table); } else { $searchOption = $item->getSearchOptionByField('field', $field); } $message[] = $searchOption['name']; } return implode(',', $message); } //// Default case // Link with plugin tables : need to know left join structure if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) { if (count($matches) == 2) { $plug = $matches[1]; $function = 'plugin_' . $plug . '_giveItem'; if (function_exists($function)) { $out = $function($itemtype, $ID, $data, $num); if (!empty($out)) { return $out; } } } } $unit = ''; if (isset($searchopt[$ID]['unit'])) { $unit = $searchopt[$ID]['unit']; } // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": if (!empty($data[$NAME . $num . "_2"])) { if (isset($searchopt[$ID]["itemlink_type"])) { $link = getItemTypeFormURL($searchopt[$ID]["itemlink_type"]); } else { $link = getItemTypeFormURL($itemtype); } $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"] . "\">" . $data[$NAME . $num] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; return $out; } if (isset($searchopt[$ID]["itemlink_type"])) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $split2 = explode("\$\$", $split[$k]); if (isset($split2[1]) && $split2[1] > 0) { if ($count_display) { $out .= $separate; } $count_display++; $page = getItemTypeFormURL($searchopt[$ID]["itemlink_type"]); $page .= strpos($page, '?') ? '&id' : '?id'; $out .= "<a id='" . $searchopt[$ID]["itemlink_type"] . "_" . $data['id'] . "_" . $split2[1] . "' href='{$page}=" . $split2[1] . "'>" . $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } } } return $out; } break; case "text": $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } $text = str_replace('$$$$', $separate, nl2br($data[$NAME . $num])); if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) { $text = html_clean(unclean_cross_side_scripting_deep($text)); } return $text; case "date": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . convDate($val); } return $out; case "datetime": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . convDateTime($val); } return $out; case "timestamp": $withseconds = false; if (isset($searchopt[$ID]['withseconds'])) { $withseconds = $searchopt[$ID]['withseconds']; } return timestampToString($data[$NAME . $num], $withseconds); case "date_delay": $split = explode('$$$$', $data[$NAME . $num]); $out = ''; foreach ($split as $val) { if (strpos($val, ',')) { list($dat, $dur) = explode(',', $val); if (!empty($dat)) { $out .= (empty($out) ? '' : '<br>') . getWarrantyExpir($dat, $dur); } } } return empty($out) ? " " : $out; case "email": $email = trim($data[$NAME . $num]); if (!empty($email)) { return "<a href='mailto:{$email}'>{$email}</a>"; } return " "; case "weblink": $orig_link = trim($data[$NAME . $num]); if (!empty($orig_link)) { // strip begin of link $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link); $link = preg_replace('/\\/$/', '', $link); if (utf8_strlen($link) > $CFG_GLPI["url_maxlength"]) { $link = utf8_substr($link, 0, $CFG_GLPI["url_maxlength"]) . "..."; } return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>"; } return " "; case "number": if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', formatNumber($split[$k], false, 0)) . $unit; } } return $out; } return str_replace(' ', ' ', formatNumber($data[$NAME . $num], false, 0)) . $unit; case "decimal": if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', formatNumber($split[$k])) . $unit; } } return $out; } return str_replace(' ', ' ', formatNumber($data[$NAME . $num])) . $unit; case "bool": return Dropdown::getYesNo($data[$NAME . $num]) . $unit; case "right": return Profile::getRightValue($data[$NAME . $num]); case "itemtypename": if (class_exists($data[$NAME . $num])) { $obj = new $data[$NAME . $num](); return $obj->getTypeName(); } return ""; case "language": if (isset($CFG_GLPI['languages'][$data[$NAME . $num]])) { return $CFG_GLPI['languages'][$data[$NAME . $num]][0]; } return $LANG['setup'][46]; } } // Manage items with need group by / group_concat if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { if ($count_display) { $out .= $separate; } $count_display++; $out .= $split[$k] . $unit; } } return $out; } return $data[$NAME . $num] . $unit; }