dropdown() static public méthode

Print a select named $name with contracts options and selected value $value
static public dropdown ( $options = [] ) : Nothing
$options array of possible options: - name : string / name of the select (default is contracts_id) - value : integer / preselected value (default 0) - entity : integer or array / restrict to a defined entity or array of entities (default -1 : no restriction) - rand : (defauolt mt_rand) - entity_sons : boolean / if entity restrict specified auto select its sons only available if entity is a single value not an array (default false) - used : array / Already used items ID: not to display in dropdown (default empty) - nochecklimit : boolean / disable limit for nomber of device (for supplier, default false) - on_change : string / value to transmit to "onChange" - display : boolean / display or return string (default true) - expired : boolean / display expired contract (default false)
Résultat Nothing (display)
 /**
  * Print an HTML array with contracts associated to the enterprise
  *
  * @since version 0.84
  *
  * @param $supplier   Supplier object
  *
  * @return Nothing (display)
  **/
 static function showForSupplier(Supplier $supplier)
 {
     global $DB, $CFG_GLPI;
     $ID = $supplier->fields['id'];
     if (!Session::haveRight("contract", "r") || !$supplier->can($ID, 'r')) {
         return false;
     }
     $canedit = $supplier->can($ID, 'w');
     $rand = mt_rand();
     $query = "SELECT `glpi_contracts`.*,\n                       `glpi_contracts_suppliers`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity\n                FROM `glpi_contracts_suppliers`, `glpi_contracts`\n                LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n                WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n                      AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                ORDER BY `glpi_entities`.`completename`,\n                         `glpi_contracts`.`name`";
     $result = $DB->query($query);
     $contracts = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $contracts[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='contractsupplier_form{$rand}' id='contractsupplier_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<input type='hidden' name='suppliers_id' value='{$ID}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a contract') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         Contract::dropdown(array('used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->fields["is_recursive"], 'nochecklimit' => true));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('Entity') . "</th>";
     echo "<th>" . _x('phone', 'Number') . "</th>";
     echo "<th>" . __('Contract type') . "</th>";
     echo "<th>" . __('Start date') . "</th>";
     echo "<th>" . __('Initial contract period') . "</th>";
     echo "</tr>";
     $used = array();
     foreach ($contracts as $data) {
         $cID = $data["id"];
         $used[$cID] = $cID;
         $assocID = $data["assocID"];
         echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
         if ($canedit) {
             echo "<td>";
             Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
             echo "</td>";
         }
         $name = $data["name"];
         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
             $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
         }
         echo "<td class='center b'>\n               <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name . "</a>";
         echo "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]);
         echo "</td><td class='center'>" . $data["num"] . "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>";
         echo "<td class='center'>" . Html::convDate($data["begin_date"]) . "</td>";
         echo "<td class='center'>";
         sprintf(_n('%d month', '%d months', $data["duration"]), $data["duration"]);
         if ($data["begin_date"] != '' && !empty($data["begin_date"])) {
             echo " -> " . Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], 0, true);
         }
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Print an HTML array of contract associated to an object
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object wanted
  * @param $withtemplate    not used (to be deleted) (default '')
  *
  * @return Nothing (display)
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $itemtype = $item->getType();
     $ID = $item->fields['id'];
     if (!Contract::canView() || !$item->can($ID, READ)) {
         return false;
     }
     $canedit = $item->can($ID, UPDATE);
     $rand = mt_rand();
     $query = "SELECT `glpi_contracts_items`.*\n                FROM `glpi_contracts_items`,\n                     `glpi_contracts`\n                LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n                      AND `glpi_contracts_items`.`items_id` = '{$ID}'\n                      AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                ORDER BY `glpi_contracts`.`name`";
     $result = $DB->query($query);
     $contracts = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $contracts[$data['id']] = $data;
             $used[$data['contracts_id']] = $data['contracts_id'];
         }
     }
     if ($canedit && $withtemplate != 2) {
         echo "<div class='firstbloc'>";
         echo "<form name='contractitem_form{$rand}' id='contractitem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         echo "<input type='hidden' name='itemtype' value='{$itemtype}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a contract') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td>";
         Contract::dropdown(array('entity' => $item->getEntityID(), 'used' => $used));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($withtemplate != 2) {
         if ($canedit && $number) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
     }
     echo "<table class='tab_cadre_fixehov'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number && $withtemplate != 2) {
         $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_top .= "</th>";
         $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= "</th>";
     }
     $header_end .= "<th>" . __('Name') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . _x('phone', 'Number') . "</th>";
     $header_end .= "<th>" . __('Contract type') . "</th>";
     $header_end .= "<th>" . __('Supplier') . "</th>";
     $header_end .= "<th>" . __('Start date') . "</th>";
     $header_end .= "<th>" . __('Initial contract period') . "</th>";
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     if ($number > 0) {
         Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($contracts as $data) {
             $cID = $data["contracts_id"];
             Session::addToNavigateListItems(__CLASS__, $cID);
             $contracts[] = $cID;
             $assocID = $data["id"];
             $con = new Contract();
             $con->getFromDB($cID);
             echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate != 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td class='center b'>";
             $name = $con->fields["name"];
             if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) {
                 $name = sprintf(__('%1$s (%2$s)'), $name, $con->fields["id"]);
             }
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name;
             echo "</a></td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>";
             echo "<td class='center'>" . $con->fields["num"] . "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>";
             echo "<td class='center'>" . $con->getSuppliersNames() . "</td>";
             echo "<td class='center'>" . Html::convDate($con->fields["begin_date"]) . "</td>";
             echo "<td class='center'>" . sprintf(__('%1$s %2$s'), $con->fields["duration"], _n('month', 'months', $con->fields["duration"]));
             if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) {
                 echo " -> " . Infocom::getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"], 0, true);
             }
             echo "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate != 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Print an HTML array with contracts associated to the enterprise
  *
  *@return Nothing (display)
  **/
 function showContracts()
 {
     global $DB, $CFG_GLPI, $LANG;
     $ID = $this->fields['id'];
     if (!haveRight("contract", "r") || !$this->can($ID, 'r')) {
         return false;
     }
     $canedit = $this->can($ID, 'w');
     $query = "SELECT `glpi_contracts`.*,\n                       `glpi_contracts_suppliers`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity\n                FROM `glpi_contracts_suppliers`, `glpi_contracts`\n                LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n                WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n                      AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                ORDER BY `glpi_entities`.`completename`,\n                         `glpi_contracts`.`name`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php'>";
     echo "<div class='spaced'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='7'>";
     if ($DB->numrows($result) == 0) {
         echo $LANG['financial'][58];
     } else {
         if ($DB->numrows($result) == 1) {
             echo $LANG['financial'][63];
         } else {
             echo $LANG['financial'][66];
         }
     }
     echo "</th></tr>";
     echo "<tr><th>" . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['entity'][0] . "</th>";
     echo "<th>" . $LANG['financial'][4] . "</th>";
     echo "<th>" . $LANG['financial'][6] . "</th>";
     echo "<th>" . $LANG['search'][8] . "</th>";
     echo "<th>" . $LANG['financial'][8] . "</th>";
     echo "<th>&nbsp;</th>";
     echo "</tr>";
     $used = array();
     while ($data = $DB->fetch_array($result)) {
         $cID = $data["id"];
         $used[$cID] = $cID;
         $assocID = $data["assocID"];
         echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
         echo "<td class='center'>\n               <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>";
         echo "<strong>" . $data["name"];
         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
             echo " (" . $data["id"] . ")";
         }
         echo "</strong></a></td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]);
         echo "</td><td class='center'>" . $data["num"] . "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>";
         echo "<td class='center'>" . convDate($data["begin_date"]) . "</td>";
         echo "<td class='center'>" . $data["duration"] . " " . $LANG['financial'][57];
         if ($data["begin_date"] != '' && !empty($data["begin_date"])) {
             echo " -> " . getWarrantyExpir($data["begin_date"], $data["duration"]);
         }
         echo "</td>";
         echo "<td class='tab_bg_2 center'>";
         if ($canedit) {
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deletecontractsupplier=" . "1&amp;id={$assocID}&amp;contracts_id={$cID}'>";
             echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>";
         } else {
             echo "&nbsp;";
         }
         echo "</td></tr>";
         $i++;
     }
     if ($canedit) {
         if ($this->fields["is_recursive"]) {
             $nb = countElementsInTableForEntity("glpi_contracts", getSonsOf("glpi_entities", $this->fields["entities_id"]));
         } else {
             $nb = countElementsInTableForEntity("glpi_contracts", $this->fields["entities_id"]);
         }
         if ($nb > count($used)) {
             echo "<tr class='tab_bg_1'><td class='center' colspan='5'>";
             echo "<input type='hidden' name='suppliers_id' value='{$ID}'>";
             Contract::dropdown(array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"], 'nochecklimit' => true));
             echo "</td><td class='center'>";
             echo "<input type='submit' name='addcontractsupplier' value=\"" . $LANG['buttons'][8] . "\"\n                   class='submit'>";
             echo "</td>";
             echo "<td>&nbsp;</td></tr>";
         }
     }
     echo "</table></div></form>";
 }
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_userprofile":
     Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities']));
     echo ".&nbsp;" . $LANG['profiles'][22] . "&nbsp;:&nbsp;";
     Profile::dropdownUnder();
     echo ".&nbsp;" . $LANG['profiles'][28] . "&nbsp;:&nbsp;";
     Dropdown::showYesNo("is_recursive", 0);
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_document":
     Document::dropdown(array('name' => 'docID'));
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_contract":
     Contract::dropdown(array('name' => "conID"));
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_contact":
     Dropdown::show('Contact', array('name' => "conID"));
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_enterprise":
     Dropdown::show('Supplier', array('name' => "conID"));
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "import_email":
     Dropdown::show('Entity');
     echo "&nbsp;<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_user_to_email":
Exemple #5
0
 /**
  * Display options add action button for massive actions
  *
  * @since version 0.84
  *
  * This must not be overloaded in Class
  *
  * @param $input array of input datas
  *
  * @return nothing display
  **/
 function showMassiveActionsParameters($input = array())
 {
     global $CFG_GLPI;
     switch ($input['action']) {
         case "add_contract_item":
             if ($input['itemtype'] == 'Contract') {
                 Dropdown::showAllItems("items_id", 0, 0, 1, $CFG_GLPI["contract_types"], false, true, 'item_itemtype');
                 echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>";
             } else {
                 Contract::dropdown(array('name' => "contracts_id"));
                 echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>";
             }
             break;
         case "remove_contract_item":
             if ($input['itemtype'] == 'Contract') {
                 Dropdown::showAllItems("items_id", 0, 0, 1, $CFG_GLPI["contract_types"], false, true, 'item_itemtype');
                 echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>";
             } else {
                 Contract::dropdown(array('name' => "contracts_id"));
                 echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>";
             }
             break;
         case "add_document":
             Document::dropdown(array('name' => 'documents_id'));
             echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Add') . "'>";
             break;
         case "remove_document":
             Document::dropdown(array('name' => 'documents_id'));
             echo "<br><br><input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Delete permanently') . "'>";
             break;
         case "update":
             // Specific options for update fields
             if (isset($input['options'])) {
                 $input['options'] = Toolbox::decodeArrayFromInput($input['options']);
             } else {
                 $input['options'] = array();
             }
             $first_group = true;
             $newgroup = "";
             $items_in_group = 0;
             $show_all = true;
             $show_infocoms = true;
             if (in_array($input["itemtype"], $CFG_GLPI["infocom_types"]) && (!static::canUpdate() || !Infocom::canUpdate())) {
                 $show_all = false;
                 $show_infocoms = Infocom::canUpdate();
             }
             $searchopt = Search::getCleanedOptions($input["itemtype"], 'w');
             echo "<select name='id_field' id='massiveaction_field'>";
             echo "<option value='0' selected>" . Dropdown::EMPTY_VALUE . "</option>";
             foreach ($searchopt as $key => $val) {
                 if (!is_array($val)) {
                     if (!empty($newgroup) && $items_in_group > 0) {
                         echo $newgroup;
                         $first_group = false;
                     }
                     $items_in_group = 0;
                     $newgroup = "";
                     if (!$first_group) {
                         $newgroup .= "</optgroup>";
                     }
                     $newgroup .= "<optgroup label=\"{$val}\">";
                 } else {
                     // No id and no entities_id massive action and no first item
                     if ($val["field"] != 'id' && $key != 1 && ($val["linkfield"] != 'entities_id' || isset($val['massiveaction']) && $val['massiveaction'])) {
                         if (!isset($val['massiveaction']) || $val['massiveaction']) {
                             if ($show_all) {
                                 $newgroup .= "<option value='{$key}'>" . $val["name"] . "</option>";
                                 $items_in_group++;
                             } else {
                                 // Do not show infocom items
                                 if ($show_infocoms && Search::isInfocomOption($input["itemtype"], $key) || !$show_infocoms && !Search::isInfocomOption($input["itemtype"], $key)) {
                                     $newgroup .= "<option value='{$key}'>" . $val["name"] . "</option>";
                                     $items_in_group++;
                                 }
                             }
                         }
                     }
                 }
             }
             if (!empty($newgroup) && $items_in_group > 0) {
                 echo $newgroup;
             }
             if (!$first_group) {
                 echo "</optgroup>";
             }
             echo "</select>";
             $paramsmassaction = array('id_field' => '__VALUE__', 'itemtype' => $input["itemtype"], 'options' => $input['options']);
             foreach ($input as $key => $val) {
                 if (preg_match("/extra_/", $key, $regs)) {
                     $paramsmassaction[$key] = $val;
                 }
             }
             Ajax::updateItemOnSelectEvent("massiveaction_field", "show_massiveaction_field", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionField.php", $paramsmassaction);
             echo "<br><br><span id='show_massiveaction_field'>&nbsp;</span>\n";
             break;
         default:
             if (!$this->showSpecificMassiveActionsParameters($input)) {
                 echo "<input type='submit' name='massiveaction' class='submit' value='" . _sx('button', 'Post') . "'>\n";
             }
     }
     return false;
 }