. * --------------------------------------------------------------------- */ 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(e) { if (!multichecksappend$field_id) { $('#select2-$field_id-results').parent().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 integer $ID item ID * @param array 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 = []) { $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'])) { echo __('Global management'); if ($params['management_restrict'] == 2) { echo " "; Html::showSimpleForm($params['target'], 'unglobalize', __('Use unitary management'), ['id' => $ID], '', '', [__('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 the element as many times as there are connections') . ""; } } else { if ($params['management_restrict'] == 2) { $rand = mt_rand(); $values = [MANAGEMENT_UNITARY => __('Unit management'), MANAGEMENT_GLOBAL => __('Global management')]; Dropdown::showFromArray($params['name'], $values, ['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 string $itemtype name of the class * @param array $input of value to import * * @return boolean|integer ID of the new item or false on error **/ 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 string $itemtype name of the class * @param string $value Value of the new dropdown. * @param integer $entities_id entity in case of specific dropdown * @param array $external_params * @param string $comment * @param boolean $add if true, add it if not found. if false, just check if exists * * @return integer : dropdown id. **/ static function importExternal($itemtype, $value, $entities_id = -1, $external_params = [], $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 integer value the type of management (default 0) * * @return string 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 0.83 **/ static function showOutputFormat() { $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 "