Get items to display for showGenericDateTimeSearch
static public getGenericDateTimeSearchItems ( $options ) : array | ||
$options | array of possible options: - with_time display with time selection ? (default false) - with_future display with future date selection ? (default false) - with_days display specific days selection TODAY, BEGINMONTH, LASTMONDAY... ? (default true) | |
return | array | of posible values |
/** * Show generic date search * * @param $element name of the html element * @param $value default value (default '') * @param $options array of possible options: * - with_time display with time selection ? (default false) * - with_future display with future date selection ? (default false) * - with_days display specific days selection TODAY, BEGINMONTH, LASTMONDAY... ? (default true) * * @return rand value of dropdown **/ static function showGenericDateTimeSearch($element, $value = '', $options = array()) { global $CFG_GLPI; $p['with_time'] = false; $p['with_future'] = false; $p['with_days'] = true; $p['with_specific_date'] = true; $p['display'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $output = ''; // Validate value if ($value != 'NOW' && $value != 'TODAY' && !preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value) && !strstr($value, 'HOUR') && !strstr($value, 'DAY') && !strstr($value, 'WEEK') && !strstr($value, 'MONTH') && !strstr($value, 'YEAR')) { $value = ""; } if (empty($value)) { $value = 'NOW'; } $specific_value = date("Y-m-d H:i:s"); if (preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value)) { $specific_value = $value; $value = 0; } $output .= "<table><tr><td>"; $output .= "<select id='genericdate{$element}{$rand}' name='_select_{$element}'>"; $dates = Html::getGenericDateTimeSearchItems($options); foreach ($dates as $key => $val) { $output .= "<option value='{$key}' " . ($value === $key ? 'selected' : '') . ">{$val}</option>"; } $output .= "</select>"; $output .= "</td><td>"; $output .= "<div id='displaygenericdate{$element}{$rand}'></div>"; $params = array('value' => '__VALUE__', 'name' => $element, 'withtime' => $p['with_time'], 'specificvalue' => $specific_value); $output .= Ajax::updateItemOnSelectEvent("genericdate{$element}{$rand}", "displaygenericdate{$element}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, false); $params['value'] = $value; $output .= Ajax::updateItem("displaygenericdate{$element}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, '', false); $output .= "</td></tr></table>"; if ($p['display']) { echo $output; return $rand; } return $output; }
/** * Show generic date search * * @param $element name of the html element * @param $value default value (default '') * @param $options array of possible options: * - with_time display with time selection ? (default false) * - with_future display with future date selection ? (default false) * - with_days display specific days selection TODAY, BEGINMONTH, LASTMONDAY... ? (default true) * * @return rand value of dropdown **/ static function showGenericDateTimeSearch($element, $value = '', $options = array()) { global $CFG_GLPI; $p['with_time'] = false; $p['with_future'] = false; $p['with_days'] = true; $p['with_specific_date'] = true; $p['display'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $output = ''; // Validate value if ($value != 'NOW' && $value != 'TODAY' && !preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value) && !strstr($value, 'HOUR') && !strstr($value, 'DAY') && !strstr($value, 'WEEK') && !strstr($value, 'MONTH') && !strstr($value, 'YEAR')) { $value = ""; } if (empty($value)) { $value = 'NOW'; } $specific_value = date("Y-m-d H:i:s"); if (preg_match("/\\d{4}-\\d{2}-\\d{2}.*/", $value)) { $specific_value = $value; $value = 0; } $output .= "<table width='100%'><tr><td width='50%'>"; $dates = Html::getGenericDateTimeSearchItems($p); $output .= Dropdown::showFromArray("_select_{$element}", $dates, array('value' => $value, 'display' => false, 'rand' => $rand)); $field_id = Html::cleanId("dropdown__select_{$element}{$rand}"); $output .= "</td><td width='50%'>"; $contentid = Html::cleanId("displaygenericdate{$element}{$rand}"); $output .= "<span id='{$contentid}'></span>"; $params = array('value' => '__VALUE__', 'name' => $element, 'withtime' => $p['with_time'], 'specificvalue' => $specific_value); $output .= Ajax::updateItemOnSelectEvent($field_id, $contentid, $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, false); $params['value'] = $value; $output .= Ajax::updateItem($contentid, $CFG_GLPI["root_doc"] . "/ajax/genericdate.php", $params, '', false); $output .= "</td></tr></table>"; if ($p['display']) { echo $output; return $rand; } return $output; }
/** * display a field using standard system * * @since version 0.83 * * @param $field_id_or_search_options integer/string/array id of the search option field * or field name * or search option array * @param $values mixed value to display * @param $options array of possible options: * Parameters which could be used in options array : * - comments : boolean / is the comments displayed near the value (default false) * - any others options passed to specific display method * * @return return the string to display **/ function getValueToDisplay($field_id_or_search_options, $values, $options = array()) { global $CFG_GLPI; $param['comments'] = false; $param['html'] = false; foreach ($param as $key => $val) { if (!isset($options[$key])) { $options[$key] = $val; } } $searchoptions = array(); if (is_array($field_id_or_search_options)) { $searchoptions = $field_id_or_search_options; } else { $searchopt = $this->getSearchOptions(); // Get if id of search option is passed if (is_numeric($field_id_or_search_options)) { if (isset($searchopt[$field_id_or_search_options])) { $searchoptions = $searchopt[$field_id_or_search_options]; } } else { // Get if field name is passed $searchoptions = $this->getSearchOptionByField('field', $field_id_or_search_options, $this->getTable()); } } if (count($searchoptions)) { $field = $searchoptions['field']; // Normalize option if (is_array($values)) { $value = $values[$field]; } else { $value = $values; $values = array($field => $value); } if (isset($searchoptions['datatype'])) { $unit = ''; if (isset($searchoptions['unit'])) { $unit = $searchoptions['unit']; } switch ($searchoptions['datatype']) { case "count": case "number": if (isset($searchoptions['toadd']) && isset($searchoptions['toadd'][$value])) { return $searchoptions['toadd'][$value]; } if ($options['html']) { return Dropdown::getValueWithUnit(Html::formatNumber($value, false, 0), $unit); } return $value; case "decimal": if ($options['html']) { return Dropdown::getValueWithUnit(Html::formatNumber($value), $unit); } return $value; case "string": case "mac": case "ip": return $value; case "text": if ($options['html']) { $text = nl2br($value); } else { $text = $value; } if (isset($searchoptions['htmltext']) && $searchoptions['htmltext']) { $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep($text)); } return $text; case "bool": return Dropdown::getYesNo($value); case "date": case "date_delay": if (isset($options['relative_dates']) && $options['relative_dates']) { $dates = Html::getGenericDateTimeSearchItems(array('with_time' => true, 'with_future' => true)); return $dates[$value]; } return Html::convDate(Html::computeGenericDateTimeSearch($value, true)); case "datetime": if (isset($options['relative_dates']) && $options['relative_dates']) { $dates = Html::getGenericDateTimeSearchItems(array('with_time' => true, 'with_future' => true)); return $dates[$value]; } return Html::convDateTime(Html::computeGenericDateTimeSearch($value, false)); case "timestamp": if ($value == 0 && isset($searchoptions['emptylabel'])) { return $searchoptions['emptylabel']; } $withseconds = false; if (isset($searchoptions['withseconds'])) { $withseconds = $searchoptions['withseconds']; } return Html::timestampToString($value, $withseconds); case "email": if ($options['html']) { return "<a href='mailto:{$value}'>{$value}</a>"; } return $value; case "weblink": $orig_link = trim($value); if (!empty($orig_link)) { // strip begin of link $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link); $link = preg_replace('/\\/$/', '', $link); if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) { $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "..."; } return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}" . "</a>"; } return " "; case "itemlink": if ($searchoptions['table'] == $this->getTable()) { break; } case "dropdown": if (isset($searchoptions['toadd']) && isset($searchoptions['toadd'][$value])) { return $searchoptions['toadd'][$value]; } if (!is_numeric($value)) { return $value; } if ($value == 0 && isset($searchoptions['emptylabel'])) { return $searchoptions['emptylabel']; } if ($searchoptions['table'] == 'glpi_users') { if ($param['comments']) { $tmp = getUserName($value, 2); return $tmp['name'] . ' ' . Html::showToolTip($tmp['comment'], array('display' => false)); } return getUserName($value); } if ($param['comments']) { $tmp = Dropdown::getDropdownName($searchoptions['table'], $value, 1); return $tmp['name'] . ' ' . Html::showToolTip($tmp['comment'], array('display' => false)); } return Dropdown::getDropdownName($searchoptions['table'], $value); case "itemtypename": if ($obj = getItemForItemtype($value)) { return $obj->getTypeName(1); } break; case "language": if (isset($CFG_GLPI['languages'][$value])) { return $CFG_GLPI['languages'][$value][0]; } return __('Default value'); } } // Get specific display if available $itemtype = getItemTypeForTable($searchoptions['table']); if ($item = getItemForItemtype($itemtype)) { $options['searchopt'] = $searchoptions; $specific = $item->getSpecificValueToDisplay($field, $values, $options); if (!empty($specific)) { return $specific; } } } return $value; }