grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } class Dropdown { //Empty value displayed in a dropdown const EMPTY_VALUE = '-----'; /** * Print out an HTML ""; if (isset($elements[$value])) { $to_display[] = $elements[$value]; } } $output .= implode('
',$to_display); } else { $output .= ""; if ($param['other'] !== false) { $output .= " $param["width"])); if ($param["multiple"]) { // Hack for All / None because select2 does not provide it $select = __('All'); $deselect = __('None'); $output .= ""; $js = " var multichecksappend$field_id = false; $('#$field_id').on('select2-open', function() { if (!multichecksappend$field_id) { $('#select2-drop').append($('#selectallbuttons_$field_id').html()); multichecksappend$field_id = true; } });"; $output .= Html::scriptBlock($js); } $output .= Ajax::commonDropdownUpdateItem($param, false); if ($param['display']) { echo $output; return $param['rand']; } return $output; } /** * Dropdown for global item management * * @param $ID item ID * @param attrs array which contains the extra paramters * * Parameters can be : * - target target for actions * - withtemplate template or basic computer * - value value of global state * - management_restrict global management restrict mode **/ static function showGlobalSwitch($ID, $attrs=array()) { global $CFG_GLPI; $params['management_restrict'] = 0; $params['value'] = 0; $params['name'] = 'is_global'; $params['target'] = ''; foreach ($attrs as $key => $value) { if ($value != '') { $params[$key] = $value; } } if ($params['value'] && empty($params['withtemplate'])) { _e('Global management'); if ($params['management_restrict'] == 2) { echo " "; Html::showSimpleForm($params['target'], 'unglobalize', __('Use unitary management'), array('id' => $ID), '', '', array(__('Do you really want to use unitary management for this item?'), __('Duplicate the element as many times as there are connections'))); echo " "; echo "\"".__s('Duplicate"; } } else { if ($params['management_restrict'] == 2) { $rand = mt_rand(); $values = array(MANAGEMENT_UNITARY => __('Unit management'), MANAGEMENT_GLOBAL => __('Global management')); Dropdown::showFromArray($params['name'], $values, array('value' => $params['value'])); } else { // Templates edition if (!empty($params['withtemplate'])) { echo ""; echo (!$params['management_restrict']?__('Unit management') :__('Global management')); } else { echo (!$params['value']?__('Unit management'):__('Global management')); } } } } /** * Import a dropdown - check if already exists * * @param $itemtype string name of the class * @param $input array of value to import * * @return the ID of the new **/ static function import($itemtype, $input) { if (!($item = getItemForItemtype($itemtype))) { return false; } return $item->import($input); } /** * Import a value in a dropdown table. * * This import a new dropdown if it doesn't exist - Play dictionnary if needed * * @param $itemtype string name of the class * @param $value string Value of the new dropdown. (need to be addslashes) * @param $entities_id integer entity in case of specific dropdown (default -1) * @param $external_params array (need to be addslashes) * @param $comment (default '') (need to be addslashes) * @param $add if true, add it if not found. if false, just check if exists * (true by default) * * @return integer : dropdown id. **/ static function importExternal($itemtype, $value, $entities_id=-1, $external_params=array(), $comment='', $add=true) { if (!($item = getItemForItemtype($itemtype))) { return false; } return $item->importExternal($value, $entities_id, $external_params, $comment, $add); } /** * Get the label associated with a management type * * @param value the type of management (default 0) * * @return the label corresponding to it, or "" **/ static function getGlobalSwitch($value=0) { switch ($value) { case 0 : return __('Unit management'); case 1 : return __('Global management'); default : return ""; } } /** * show dropdown for output format * * @since version 0.83 **/ static function showOutputFormat() { global $CFG_GLPI; $values[Search::PDF_OUTPUT_LANDSCAPE] = __('Current page in landscape PDF'); $values[Search::PDF_OUTPUT_PORTRAIT] = __('Current page in portrait PDF'); $values[Search::SYLK_OUTPUT] = __('Current page in SLK'); $values[Search::CSV_OUTPUT] = __('Current page in CSV'); $values['-'.Search::PDF_OUTPUT_LANDSCAPE] = __('All pages in landscape PDF'); $values['-'.Search::PDF_OUTPUT_PORTRAIT] = __('All pages in portrait PDF'); $values['-'.Search::SYLK_OUTPUT] = __('All pages in SLK'); $values['-'.Search::CSV_OUTPUT] = __('All pages in CSV'); Dropdown::showFromArray('display_type', $values); echo ""; } /** * show dropdown to select list limit * * @since version 0.83 * * @param $onchange String optional, for ajax (default '') **/ static function showListLimit($onchange='') { global $CFG_GLPI; if (isset($_SESSION['glpilist_limit'])) { $list_limit = $_SESSION['glpilist_limit']; } else { $list_limit = $CFG_GLPI['list_limit']; } $values = array(); for ($i=5 ; $i<20 ; $i+=5) { $values[$i] = $i; } for ($i=20 ; $i<50 ; $i+=10) { $values[$i] = $i; } for ($i=50 ; $i<250 ; $i+=50) { $values[$i] = $i; } for ($i=250 ; $i<1000 ; $i+=250) { $values[$i] = $i; } for ($i=1000 ; $i<5000 ; $i+=1000) { $values[$i] = $i; } for ($i=5000 ; $i<=10000 ; $i+=5000) { $values[$i] = $i; } $values[9999999] = 9999999; // Propose max input vars -10 $max = Toolbox::get_max_input_vars(); if ($max > 10) { $values[$max-10] = $max-10; } ksort($values); return self::showFromArray('glpilist_limit', $values, array('on_change' => $onchange, 'value' => $list_limit)); } } ?>