Dropdown::dropdownIcons PHP Method

dropdownIcons() static public method

Make a select box for icons
static public dropdownIcons ( $myname, $value, $store_path, $display = true ) : nothing
$myname the name of the HTML select
$value the preselected value we want
$store_path path where icons are stored
$display boolean display of get string ? (true by default)
return nothing (print out an HTML select box)
    static function dropdownIcons($myname, $value, $store_path, $display = true)
    {
        $output = '';
        if (is_dir($store_path)) {
            if ($dh = opendir($store_path)) {
                $files = array();
                while (($file = readdir($dh)) !== false) {
                    $files[] = $file;
                }
                closedir($dh);
                sort($files);
                foreach ($files as $file) {
                    if (preg_match("/\\.png\$/i", $file)) {
                        $values[$file] = $file;
                    }
                }
                Dropdown::showFromArray($myname, $values, array('value' => $value, 'display_emptychoice' => true));
            } else {
                //TRANS: %s is the store path
                printf(__('Error reading directory %s'), $store_path);
            }
        } else {
            //TRANS: %s is the store path
            printf(__('Error: %s is not a directory'), $store_path);
        }
        if ($display) {
            echo $output;
        } else {
            return $output;
        }
    }

Usage Example

Exemplo n.º 1
0
 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'>&nbsp;</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 "&nbsp;";
             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 "&nbsp;<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 "&nbsp;" . $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;
 }
All Usage Examples Of Dropdown::dropdownIcons