Dropdown::showNumber PHP Method

showNumber() static public method

Dropdown numbers
static public showNumber ( $myname, $options = [] )
$myname select name
$options array of additionnal options : - value default value (default 0) - rand random value - min min value (default 0) - max max value (default 100) - step step used (default 1) - toadd array of values to add at the beginning - unit string unit to used - display boolean if false get string - width specific width needed (default 80%) - on_change string / value to transmit to "onChange" - used array / Already used items ID: not to display in dropdown (default empty)
    static function showNumber($myname, $options = array())
    {
        global $CFG_GLPI;
        $p['value'] = 0;
        $p['rand'] = mt_rand();
        $p['min'] = 0;
        $p['max'] = 100;
        $p['step'] = 1;
        $p['toadd'] = array();
        $p['unit'] = '';
        $p['display'] = true;
        $p['width'] = '';
        $p['on_change'] = '';
        $p['used'] = array();
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $p[$key] = $val;
            }
        }
        if ($p['value'] < $p['min'] && !isset($p['toadd'][$p['value']])) {
            $p['value'] = $p['min'];
        }
        $field_id = Html::cleanId("dropdown_" . $myname . $p['rand']);
        if (!isset($p['toadd'][$p['value']])) {
            $valuename = self::getValueWithUnit($p['value'], $p['unit']);
        } else {
            $valuename = $p['toadd'][$p['value']];
        }
        $param = array('value' => $p['value'], 'valuename' => $valuename, 'width' => $p['width'], 'on_change' => $p['on_change'], 'used' => $p['used'], 'unit' => $p['unit'], 'min' => $p['min'], 'max' => $p['max'], 'step' => $p['step'], 'toadd' => $p['toadd']);
        $out = Html::jsAjaxDropdown($myname, $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownNumber.php", $param);
        if ($p['display']) {
            echo $out;
            return $p['rand'];
        }
        return $out;
    }

Usage Example

 function showForm($items_id, $options = array())
 {
     if ($items_id == '-1') {
         $items_id = '';
     }
     $this->initForm($items_id, $options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . " :</td>";
     echo "<td>";
     echo "<input type='text' name='name' value='" . $this->fields["name"] . "' size='30'/>";
     echo "</td>";
     echo "<td>" . __('Check definition', 'monitoring') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::show("PluginMonitoringCheck", array('name' => 'plugin_monitoring_checks_id', 'value' => $this->fields['plugin_monitoring_checks_id']));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . _n('Comment', 'Comments', 2) . "&nbsp;: </td>";
     echo "<td>";
     echo "<textarea cols='45' rows='2' name='comment'>" . $this->fields["comment"] . "</textarea>";
     echo "</td>";
     echo "<td>" . __('Check period', 'monitoring') . "&nbsp;:</td>";
     echo "<td>";
     dropdown::show("Calendar", array('name' => 'calendars_id', 'value' => $this->fields['calendars_id']));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2'></td>";
     echo "<td>" . __('Interval between 2 notifications', 'monitoring') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::showNumber('notification_interval', array('value' => $this->fields['notification_interval'], 'min' => 0, 'max' => 2880, 'unit' => 'minute(s)'));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2'></td>";
     echo "<td>" . __('Business priority level', 'monitoring') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::showNumber('business_priority', array('value' => $this->fields['business_priority'], 'min' => 1, 'max' => 5));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2'></td>";
     echo "<td>" . __('Services catalog template ?', 'monitoring') . "&nbsp;:</td>";
     echo "<td>";
     if (PluginMonitoringServicescatalog::canUpdate()) {
         Dropdown::showYesNo('is_generic', $this->fields['is_generic']);
     } else {
         echo Dropdown::getYesNo($this->fields['is_generic']);
     }
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
All Usage Examples Of Dropdown::showNumber