Make a select box for software to install
static public dropdownForOneSoftware ( $options = [] ) : nothing | ||
$options | array of possible options: - name : string / name of the select (default is softwareversions_id) - softwares_id : integer / ID of the software (mandatory) - value : integer / value of the selected version - used : array / already used items | |
Результат | nothing | (print out an HTML select box) |
/** * Print the Software / license form * * @param $ID integer Id of the version or the template to print * @param $options array of possible options: * - target form target * - softwares_id ID of the software for add process * * @return true if displayed false if item not found or not right to display **/ function showForm($ID, $options = array()) { global $CFG_GLPI; $softwares_id = -1; if (isset($options['softwares_id'])) { $softwares_id = $options['softwares_id']; } if ($ID < 0) { // Create item $this->fields['softwares_id'] = $softwares_id; $this->fields['number'] = 1; $soft = new Software(); if ($soft->getFromDB($softwares_id) && in_array($_SESSION['glpiactive_entity'], getAncestorsOf('glpi_entities', $soft->getEntityID()))) { $options['entities_id'] = $soft->getEntityID(); } } $this->initForm($ID, $options); $this->showFormHeader($options); // Restore saved value or override with page parameter if (!isset($options['template_preview'])) { if (isset($_REQUEST)) { $saved = Html::cleanPostForTextArea($_REQUEST); } } foreach ($this->fields as $name => $value) { if (isset($saved[$name]) && empty($this->fields[$name])) { $this->fields[$name] = $saved[$name]; } } echo "<input type='hidden' name='withtemplate' value='" . $options['withtemplate'] . "'>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . Software::getTypeName(1) . "</td>"; echo "<td>"; if ($ID > 0) { $softwares_id = $this->fields["softwares_id"]; echo "<input type='hidden' name='softwares_id' value='{$softwares_id}'>"; echo "<a href='software.form.php?id=" . $softwares_id . "'>" . Dropdown::getDropdownName("glpi_softwares", $softwares_id) . "</a>"; } else { Dropdown::show('Software', array('condition' => "`is_template`='0' AND `is_deleted`='0'", 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => $_SESSION['glpiactive_entity_recursive'], 'on_change' => 'this.form.submit()', 'value' => $softwares_id)); } echo "</td>"; echo "<td colspan='2'>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Name'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["name"], "name", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'name', array('value' => $objectName)); echo "</td>"; echo "<td>" . __('Status') . "</td>"; echo "<td>"; State::dropdown(array('value' => $this->fields["states_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_visible_softwarelicense`")); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Location') . "</td><td>"; Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Type') . "</td>"; echo "<td>"; SoftwareLicenseType::dropdown(array('value' => $this->fields["softwarelicensetypes_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Technician in charge of the hardware') . "</td>"; echo "<td>"; User::dropdown(array('name' => 'users_id_tech', 'value' => $this->fields["users_id_tech"], 'right' => 'own_ticket', 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Publisher') . "</td>"; echo "<td>"; Manufacturer::dropdown(array('value' => $this->fields["manufacturers_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group in charge of the hardware') . "</td>"; echo "<td>"; Group::dropdown(array('name' => 'groups_id_tech', 'value' => $this->fields['groups_id_tech'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_assign`')); echo "</td>"; echo "<td>" . __('Serial number') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, "serial"); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td >" . __('User') . "</td>"; echo "<td >"; User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Inventory number'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : ""); echo "</td>"; echo "<td>"; $objectName = autoName($this->fields["otherserial"], "otherserial", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'otherserial', array('value' => $objectName)); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group') . "</td><td>"; Group::dropdown(array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_itemgroup`')); echo "</td>"; echo "<td rowspan='4' class='middle'>" . __('Comments') . "</td>"; echo "<td class='center middle' rowspan='4'>"; echo "<textarea cols='45' rows='4' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Version in use') . "</td>"; echo "<td>"; SoftwareVersion::dropdownForOneSoftware(array('name' => "softwareversions_id_use", 'softwares_id' => $this->fields["softwares_id"], 'value' => $this->fields["softwareversions_id_use"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Purchase version') . "</td>"; echo "<td>"; SoftwareVersion::dropdownForOneSoftware(array('name' => "softwareversions_id_buy", 'softwares_id' => $this->fields["softwares_id"], 'value' => $this->fields["softwareversions_id_buy"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . _x('quantity', 'Number') . "</td>"; echo "<td>"; Dropdown::showNumber("number", array('value' => $this->fields["number"], 'min' => 1, 'max' => 10000, 'step' => 1, 'toadd' => array(-1 => __('Unlimited')))); if ($ID > 0) { echo " "; if ($this->fields['is_valid']) { echo "<span class='green'>" . _x('adjective', 'Valid') . '<span>'; } else { echo "<span class='red'>" . _x('adjective', 'Invalid') . '<span>'; } } echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Expiration') . "</td>"; echo "<td>"; Html::showDateField('expire', array('value' => $this->fields["expire"])); if ($ID && is_null($this->fields["expire"])) { echo "<br>" . __('Never expire') . " "; Html::showToolTip(__('On search engine, use "Expiration contains NULL" to search licenses with no expiration date')); } Alert::displayLastAlert('SoftwareLicense', $ID); echo "</td><td colspan='2'></td></tr>\n"; $this->showFormButtons($options); return true; }
/** * @since version 0.85 * * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { global $CFG_GLPI; switch ($ma->getAction()) { case 'add': Software::dropdownSoftwareToInstall('peer_softwareversions_id', $_SESSION["glpiactive_entity"]); echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')) . "</span>"; return true; case 'move_version': $input = $ma->getInput(); if (isset($input['options'])) { if (isset($input['options']['move'])) { $options = array('softwares_id' => $input['options']['move']['softwares_id']); if (isset($input['options']['move']['used'])) { $options['used'] = $input['options']['move']['used']; } SoftwareVersion::dropdownForOneSoftware($options); echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; } } return false; } return parent::showMassiveActionsSubForm($ma); }