dropdown() static public method

Parameters which could be used in options array : - name : string / name of the select (default is documents_id) - entity : integer or array / restrict to a defined entity or array of entities (default -1 : no restriction) - used : array / Already used items ID: not to display in dropdown (default empty)
static public dropdown ( $options = [] ) : nothing
$options array of possible options
return nothing (print out an HTML select box)
示例#1
0
 /**
  * @since version 0.90
  *
  * @param $item
  * @param $withtemplate    (default '')
  * @param $options         array
  *
  * @return boolean
  **/
 static function showAddFormForItem(CommonDBTM $item, $withtemplate = '', $options = array())
 {
     global $DB, $CFG_GLPI;
     //default options
     $params['rand'] = mt_rand();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     // find documents already associated to the item
     $doc_item = new self();
     $used_found = $doc_item->find("`items_id` = '" . $item->getID() . "'\n                                    AND `itemtype` = '" . $item->getType() . "'");
     $used = array_keys($used_found);
     $used = array_combine($used, $used);
     if ($item->canAddItem('Document') && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$item->getID()] = $item->getID();
         }
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form" . $params['rand'] . "' id='documentitem_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         _e('Heading');
         echo "</td><td width='20%'>";
         DocumentCategory::dropdown(array('entity' => $entities));
         echo "</td>";
         echo "<td class='right'>";
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='" . $item->isRecursive() . "'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
         }
         echo Html::file(array('multiple' => true));
         echo "</td><td class='left'>(" . Document::getMaxUploadSize() . ")&nbsp;</td>";
         echo "<td class='center' width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         if (Document::canView() && $nb > count($used)) {
             echo "<form name='document_form" . $params['rand'] . "' id='document_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
 }
     echo "<input type='submit' name='massiveaction' class='submit' value='" . $LANG['buttons'][2] . "'>";
     break;
 case "add_group":
     Dropdown::show('Group');
     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":
示例#3
0
 /**
  * Show documents associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated documents must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if ($item->getType() != 'Ticket' && $item->getType() != 'KnowbaseItem' && !Session::haveRight('document', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $linkparam = '';
     if (get_class($item) == 'Ticket') {
         $linkparam = "&amp;tickets_id=" . $item->fields['id'];
     }
     $canedit = $item->canadditem('Document');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_documents`.`name` AS assocName,\n                       `glpi_documents`.*\n                FROM `glpi_documents_items`\n                LEFT JOIN `glpi_documents`\n                          ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_documents_items`.`items_id` = '{$ID}'\n                      AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
     if (Session::getLoginUserID()) {
         $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
     } else {
         // Anonymous access from FAQ
         $query .= " AND `glpi_documents`.`entities_id`= '0' ";
     }
     // Document : search links in both order using union
     if ($item->getType() == 'Document') {
         $query .= "UNION\n                    SELECT `glpi_documents_items`.`id` AS assocID,\n                           `glpi_entities`.`id` AS entity,\n                           `glpi_documents`.`name` AS assocName,\n                           `glpi_documents`.*\n                    FROM `glpi_documents_items`\n                    LEFT JOIN `glpi_documents`\n                              ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n                    LEFT JOIN `glpi_entities`\n                              ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                    WHERE `glpi_documents_items`.`documents_id` = '{$ID}'\n                          AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
         if (Session::getLoginUserID()) {
             $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
         } else {
             // Anonymous access from FAQ
             $query .= " AND `glpi_documents`.`entities_id`='0' ";
         }
     }
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $documents = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $documents[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$ID] = $ID;
         }
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form{$rand}' id='documentitem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL('Document') . "'  enctype=\"multipart/form-data\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         _e('Heading');
         echo '</td><td>';
         DocumentCategory::dropdown(array('entity' => $entities));
         echo "</td>";
         echo "<td class='right'>";
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         }
         echo "<input type='file' name='filename' size='25'>";
         echo "</td><td class='left'>";
         echo "(" . Document::getMaxUploadSize() . ")&nbsp;";
         echo "</td>";
         echo "<td class='center' width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         if (Session::haveRight('document', 'r') && $nb > count($used)) {
             echo "<form name='document_form{$rand}' id='document_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         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 && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('Entity') . "</th>";
     echo "<th>" . __('File') . "</th>";
     echo "<th>" . __('Web link') . "</th>";
     echo "<th>" . __('Heading') . "</th>";
     echo "<th>" . __('MIME type') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         // Don't use this for document associated to document
         // To not loose navigation list for current document
         if ($item->getType() != 'Document') {
             Session::initNavigateListItems('Document', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         }
         $document = new Document();
         foreach ($documents as $data) {
             $docID = $data["id"];
             $link = NOT_AVAILABLE;
             $downloadlink = NOT_AVAILABLE;
             if ($document->getFromDB($docID)) {
                 $link = $document->getLink();
                 $downloadlink = $document->getDownloadLink($linkparam);
             }
             if ($item->getType() != 'Document') {
                 Session::addToNavigateListItems('Document', $docID);
             }
             $used[$docID] = $docID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']);
             echo "</td>";
             echo "<td class='center'>{$downloadlink}</td>";
             echo "<td class='center'>";
             if (!empty($data["link"])) {
                 echo "<a target=_blank href='" . formatOutputWebLink($data["link"]) . "'>" . $data["link"];
                 echo "</a>";
             } else {
                 echo "&nbsp;";
             }
             echo "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_documentcategories", $data["documentcategories_id"]);
             echo "</td>";
             echo "<td class='center'>" . $data["mime"] . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
示例#4
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;
 }
 /**
  * Show documents associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated documents must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if ($item->getType() != 'Ticket' && $item->getType() != 'KnowbaseItem' && $item->getType() != 'Reminder' && !Document::canView()) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'filename' => __('File'), 'link' => __('Web link'), 'headings' => __('Heading'), 'mime' => __('MIME type'));
     if ($CFG_GLPI['use_rich_text']) {
         $columns['tag'] = __('Tag');
     }
     $columns['assocdate'] = __('Date');
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $linkparam = '';
     if (get_class($item) == 'Ticket') {
         $linkparam = "&amp;tickets_id=" . $item->fields['id'];
     }
     if (isset($_GET["order"]) && $_GET["order"] == "ASC") {
         $order = "ASC";
     } else {
         $order = "DESC";
     }
     if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
         $sort = "`" . $_GET["sort"] . "`";
     } else {
         $sort = "`assocdate`";
     }
     $canedit = $item->canAddItem('Document') && Document::canView();
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                       `glpi_documents_items`.`date_mod` AS assocdate,\n                       `glpi_entities`.`id` AS entityID,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_documentcategories`.`completename` AS headings,\n                       `glpi_documents`.*\n                FROM `glpi_documents_items`\n                LEFT JOIN `glpi_documents`\n                          ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                LEFT JOIN `glpi_documentcategories`\n                        ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                WHERE `glpi_documents_items`.`items_id` = '{$ID}'\n                      AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
     if (Session::getLoginUserID()) {
         $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
     } else {
         // Anonymous access from FAQ
         $query .= " AND `glpi_documents`.`entities_id`= '0' ";
     }
     // Document : search links in both order using union
     if ($item->getType() == 'Document') {
         $query .= "UNION\n                    SELECT `glpi_documents_items`.`id` AS assocID,\n                           `glpi_documents_items`.`date_mod` AS assocdate,\n                           `glpi_entities`.`id` AS entityID,\n                           `glpi_entities`.`completename` AS entity,\n                           `glpi_documentcategories`.`completename` AS headings,\n                           `glpi_documents`.*\n                    FROM `glpi_documents_items`\n                    LEFT JOIN `glpi_documents`\n                        ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n                    LEFT JOIN `glpi_entities`\n                        ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                    LEFT JOIN `glpi_documentcategories`\n                        ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                    WHERE `glpi_documents_items`.`documents_id` = '{$ID}'\n                          AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
         if (Session::getLoginUserID()) {
             $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
         } else {
             // Anonymous access from FAQ
             $query .= " AND `glpi_documents`.`entities_id`='0' ";
         }
     }
     $query .= " ORDER BY {$sort} {$order}";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $documents = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $documents[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($item->canAddItem('Document') && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$ID] = $ID;
         }
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form{$rand}' id='documentitem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         _e('Heading');
         echo "</td><td width='20%'>";
         DocumentCategory::dropdown(array('entity' => $entities));
         echo "</td>";
         echo "<td class='right'>";
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         }
         echo Html::file();
         echo "</td><td class='left'>";
         echo "(" . Document::getMaxUploadSize() . ")&nbsp;";
         echo "</td>";
         echo "<td class='center' width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         if (Document::canView() && $nb > count($used)) {
             echo "<form name='document_form{$rand}' id='document_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
     echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number && $withtemplate < 2) {
         $header_top .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_top .= "</th>";
         $header_bottom .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= "</th>";
     }
     foreach ($columns as $key => $val) {
         $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
     }
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     $used = array();
     if ($number) {
         // Don't use this for document associated to document
         // To not loose navigation list for current document
         if ($item->getType() != 'Document') {
             Session::initNavigateListItems('Document', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         }
         $document = new Document();
         foreach ($documents as $data) {
             $docID = $data["id"];
             $link = NOT_AVAILABLE;
             $downloadlink = NOT_AVAILABLE;
             if ($document->getFromDB($docID)) {
                 $link = $document->getLink();
                 $downloadlink = $document->getDownloadLink($linkparam);
             }
             if ($item->getType() != 'Document') {
                 Session::addToNavigateListItems('Document', $docID);
             }
             $used[$docID] = $docID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             echo "<td class='center'>" . $data['entity'] . "</td>";
             echo "<td class='center'>{$downloadlink}</td>";
             echo "<td class='center'>";
             if (!empty($data["link"])) {
                 echo "<a target=_blank href='" . formatOutputWebLink($data["link"]) . "'>" . $data["link"];
                 echo "</a>";
             } else {
                 echo "&nbsp;";
             }
             echo "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_documentcategories", $data["documentcategories_id"]);
             echo "</td>";
             echo "<td class='center'>" . $data["mime"] . "</td>";
             if ($CFG_GLPI['use_rich_text']) {
                 echo "<td class='center'>";
                 echo !empty($data["tag"]) ? Document::getImageTag($data["tag"]) : '';
                 echo "</td>";
             }
             echo "<td class='center'>" . Html::convDateTime($data["assocdate"]) . "</td>";
             echo "</tr>";
             $i++;
         }
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 static function showSubFormDocument_Item($ID, $params)
 {
     global $DB, $CFG_GLPI;
     $item = new Ticket();
     $item->getFromDB($ID);
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $linkparam = '';
     if (get_class($item) == 'Ticket') {
         $linkparam = "&amp;tickets_id=" . $item->fields['id'];
     }
     $canedit = $item->canAddItem('Document') && Document::canView();
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $order = "DESC";
     $sort = "`assocdate`";
     $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                       `glpi_documents_items`.`date_mod` AS assocdate,\n                       `glpi_entities`.`id` AS entityID,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_documentcategories`.`completename` AS headings,\n                       `glpi_documents`.*\n                FROM `glpi_documents_items`\n                LEFT JOIN `glpi_documents`\n                          ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                LEFT JOIN `glpi_documentcategories`\n                        ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                WHERE `glpi_documents_items`.`items_id` = '{$ID}'\n                      AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
     if (Session::getLoginUserID()) {
         $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
     } else {
         // Anonymous access from FAQ
         $query .= " AND `glpi_documents`.`entities_id`= '0' ";
     }
     // Document : search links in both order using union
     if ($item->getType() == 'Document') {
         $query .= "UNION\n                    SELECT `glpi_documents_items`.`id` AS assocID,\n                           `glpi_documents_items`.`date_mod` AS assocdate,\n                           `glpi_entities`.`id` AS entityID,\n                           `glpi_entities`.`completename` AS entity,\n                           `glpi_documentcategories`.`completename` AS headings,\n                           `glpi_documents`.*\n                    FROM `glpi_documents_items`\n                    LEFT JOIN `glpi_documents`\n                              ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n                    LEFT JOIN `glpi_entities`\n                              ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                    LEFT JOIN `glpi_documentcategories`\n                              ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                    WHERE `glpi_documents_items`.`documents_id` = '{$ID}'\n                          AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
         if (Session::getLoginUserID()) {
             $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
         } else {
             // Anonymous access from FAQ
             $query .= " AND `glpi_documents`.`entities_id`='0' ";
         }
     }
     $query .= " ORDER BY {$sort} {$order} ";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $documents = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $documents[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($item->canAddItem('Document') && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$ID] = $ID;
         }
         if (!isset($params['no_form']) || $params['no_form'] == false) {
             echo "<div class='firstbloc'>";
             echo "<form name='documentitem_form{$rand}' id='documentitem_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('Document') . "'  enctype=\"multipart/form-data\">";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         }
         echo "<tr class='tab_bg_1'>";
         if (!isset($params['no_form']) || $params['no_form'] == false) {
             echo "<td class='center'>";
             _e('Heading');
             echo "</td><td>";
             DocumentCategory::dropdown(array('entity' => $entities));
             echo "</td>";
             echo "<td class='right'>";
         } else {
             echo "<td class='center'>" . __('Add a document') . "</td>";
             echo "<td style='padding-left:50px'>";
         }
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         }
         echo Html::file();
         echo "</td><td class='left'>";
         echo "(" . Document::getMaxUploadSize() . ")&nbsp;";
         echo "</td>";
         if (!isset($params['no_form']) || $params['no_form'] == false) {
             echo "<td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                   class='submit'></td>";
         }
         echo "</tr>";
         if (!isset($params['no_form']) || $params['no_form'] == false) {
             echo "</table>";
             Html::closeForm();
         }
         if (Session::haveRight('document', READ) && $nb > count($used) && (!isset($params['no_form']) || $params['no_form'] == false)) {
             echo "<form name='document_form{$rand}' id='document_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('Document') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td>";
             echo "<td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
 }