/** * @since version 0.85 * * @see CommonDBTM::getMassiveActionsForItemtype() **/ static function getMassiveActionsForItemtype(array &$actions, $itemtype, $is_deleted = 0, CommonDBTM $checkitem = NULL) { global $CFG_GLPI; $action_prefix = 'Document_Item' . MassiveAction::CLASS_ACTION_SEPARATOR; if (self::canApplyOn($itemtype)) { if (Document::canView()) { $actions[$action_prefix . 'add'] = _x('button', 'Add a document'); $actions[$action_prefix . 'remove'] = _x('button', 'Remove a document'); } } if (Toolbox::is_a($itemtype, __CLASS__) && static::canUpdate()) { $actions[$action_prefix . 'add_item'] = _x('button', 'Add an item'); $actions[$action_prefix . 'remove_item'] = _x('button', 'Remove an item'); } }
/** * @since version 0.90 * * @param $item * @param $withtemplate (default '') * @param $options array */ static function showListForItem(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; } } $canedit = $item->canAddItem('Document') && Document::canView(); $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 (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`"; } if (empty($withtemplate)) { $withtemplate = 0; } $linkparam = ''; if (get_class($item) == 'Ticket') { $linkparam = "&tickets_id=" . $item->fields['id']; } $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` = '" . $item->getID() . "'\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` = '" . $item->getID() . "'\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']; } } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $params['rand']); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $params['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'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && $number && $withtemplate < 2) { $header_top .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $params['rand']); $header_top .= "</th>"; $header_bottom .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $params['rand']); $header_bottom .= "</th>"; } foreach ($columns as $key => $val) { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&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 " "; } 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>"; }
/** * Return the instance fields of itemtype identified by id * * @param $itemtype string itemtype (class) of object * @param $id integer identifier of object * @param $params array with theses options : * - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal * - 'get_hateoas': Show relation of current item in a links attribute. default: true. Optionnal * - 'get_sha1': Get a sha1 signature instead of the full answer. default: false. Optionnal * - 'with_components': Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal. * - 'with_disks': Only for Computer, retrieve the associated filesystems. Optionnal. * - 'with_softwares': Only for Computer, retrieve the associated softwares installations. Optionnal. * - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal. * - 'with_networkports':Retrieve all network connections and advanced network informations. Optionnal. * - 'with_infocoms': Retrieve financial and administrative informations. Optionnal. * - 'with_contracts': Retrieve associated contracts. Optionnal. * - 'with_documents': Retrieve associated external documents. Optionnal. * - 'with_tickets': Retrieve associated itil tickets. Optionnal. * - 'with_problems': Retrieve associated itil problems. Optionnal. * - 'with_changes': Retrieve associated itil changes. Optionnal. * - 'with_notes': Retrieve Notes (if exists, not all itemtypes have notes). Optionnal. * - 'with_logs': Retrieve historical. Optionnal. * * @return array fields of found object **/ protected function getItem($itemtype, $id, $params = array()) { global $CFG_GLPI, $DB; $this->initEndpoint(); // default params $default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'get_sha1' => false, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false); $params = array_merge($default, $params); $item = new $itemtype(); if (!$item->getFromDB($id)) { return $this->messageNotfoundError(); } if (!$item->can($id, READ)) { return $this->messageRightError(); } $fields = $item->fields; // avoid disclosure of critical fields $item::unsetUndisclosedFields($fields); // retrieve devices if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) { $all_devices = array(); foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) { $found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'", true); foreach ($found_devices as $devices_id => &$device) { unset($device['items_id']); unset($device['itemtype']); unset($device['is_deleted']); } if (!empty($found_devices)) { $all_devices[$device_type] = $found_devices; } } $fields['_devices'] = $all_devices; } // retrieve computer disks if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") { // build query to retrive filesystems $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$id}'\n AND `is_deleted` = '0'"; $fields['_disks'] = array(); if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { unset($data['computers_id']); unset($data['is_deleted']); $fields['_disks'][] = array('name' => $data); } } } // retrieve computer softwares if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") { $fields['_softwares'] = array(); if (!Software::canView()) { $fields['_softwares'] = self::arrayRightError(); } else { $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`id` AS softwares_id,\n `glpi_softwareversions`.`id` AS softwareversions_id,\n `glpi_computers_softwareversions`.`is_dynamic`,\n `glpi_softwareversions`.`states_id`,\n `glpi_softwares`.`is_valid`\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_softwares'][] = $data; } } } } // retrieve item connections if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") { $fields['_connections'] = array(); foreach ($CFG_GLPI["directconnect_types"] as $connect_type) { $connect_item = new $connect_type(); if ($connect_item->canView()) { $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n `glpi_computers_items`.`items_id` AS assoc_items_id,\n `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n " . getTableForItemType($connect_type) . ".*\n FROM `glpi_computers_items`\n LEFT JOIN `" . getTableForItemType($connect_type) . "`\n ON (`" . getTableForItemType($connect_type) . "`.`id`\n = `glpi_computers_items`.`items_id`)\n WHERE `computers_id` = '{$id}'\n AND `itemtype` = '" . $connect_type . "'\n AND `glpi_computers_items`.`is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_connections'][$connect_type][] = $data; } } } } } // retrieve item networkports if (isset($params['with_networkports']) && $params['with_networkports']) { $fields['_networkports'] = array(); if (!NetworkEquipment::canView()) { $fields['_networkports'] = self::arrayRightError(); } else { foreach (NetworkPort::getNetworkPortInstantiations() as $networkport_type) { $netport_table = $networkport_type::getTable(); $query = "SELECT\n netp.`id` as netport_id,\n netp.`entities_id`,\n netp.`is_recursive`,\n netp.`logical_number`,\n netp.`name`,\n netp.`mac`,\n netp.`comment`,\n netp.`is_dynamic`,\n netp_subtable.*\n FROM glpi_networkports AS netp\n LEFT JOIN `{$netport_table}` AS netp_subtable\n ON netp_subtable.`networkports_id` = netp.`id`\n WHERE netp.`instantiation_type` = '{$networkport_type}'\n AND netp.`items_id` = '{$id}'\n AND netp.`itemtype` = '{$itemtype}'\n AND netp.`is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { if (isset($data['netport_id'])) { // append network name $query_netn = "SELECT\n GROUP_CONCAT(CONCAT(ipadr.`id`, '" . Search::SHORTSEP . "' , ipadr.`name`)\n SEPARATOR '" . Search::LONGSEP . "') as ipadresses,\n netn.`id` as networknames_id,\n netn.`name` as networkname,\n netn.`fqdns_id`,\n fqdn.`name` as fqdn_name,\n fqdn.`fqdn`\n FROM `glpi_networknames` AS netn\n LEFT JOIN `glpi_ipaddresses` AS ipadr\n ON ipadr.`itemtype` = 'NetworkName' AND ipadr.`items_id` = netn.`id`\n LEFT JOIN `glpi_fqdns` AS fqdn\n ON fqdn.`id` = netn.`fqdns_id`\n LEFT JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n ON ipadnet.`ipaddresses_id` = ipadr.`id`\n LEFT JOIN `glpi_ipnetworks` `ipnet`\n ON ipnet.`id` = ipadnet.`ipnetworks_id`\n WHERE netn.`itemtype` = 'NetworkPort'\n AND netn.`items_id` = " . $data['netport_id'] . "\n GROUP BY netn.`id`, netn.`name`, netn.fqdns_id, fqdn.name, fqdn.fqdn"; if ($result_netn = $DB->query($query_netn)) { $data_netn = $DB->fetch_assoc($result_netn); $raw_ipadresses = explode(Search::LONGSEP, $data_netn['ipadresses']); $ipadresses = array(); foreach ($raw_ipadresses as $ipadress) { $ipadress = explode(Search::SHORTSEP, $ipadress); //find ip network attached to these ip $ipnetworks = array(); $query_ipnet = "SELECT\n ipnet.`id`,\n ipnet.`completename`,\n ipnet.`name`,\n ipnet.`address`,\n ipnet.`netmask`,\n ipnet.`gateway`,\n ipnet.`ipnetworks_id`,\n ipnet.`comment`\n FROM `glpi_ipnetworks` ipnet\n INNER JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n ON ipnet.`id` = ipadnet.`ipnetworks_id`\n AND ipadnet.`ipaddresses_id` = " . $ipadress[0]; if ($result_ipnet = $DB->query($query_ipnet)) { while ($data_ipnet = $DB->fetch_assoc($result_ipnet)) { $ipnetworks[] = $data_ipnet; } } $ipadresses[] = array('id' => $ipadress[0], 'name' => $ipadress[1], 'IPNetwork' => $ipnetworks); } $data['NetworkName'] = array('id' => $data_netn['networknames_id'], 'name' => $data_netn['networkname'], 'fqdns_id' => $data_netn['fqdns_id'], 'FQDN' => array('id' => $data_netn['fqdns_id'], 'name' => $data_netn['fqdn_name'], 'fqdn' => $data_netn['fqdn']), 'IPAddress' => $ipadresses); } } $fields['_networkports'][$networkport_type][] = $data; } } } } } // retrieve item infocoms if (isset($params['with_infocoms']) && $params['with_infocoms']) { $fields['_infocoms'] = array(); if (!Infocom::canView()) { $fields['_infocoms'] = self::arrayRightError(); } else { $ic = new Infocom(); if ($ic->getFromDBforDevice($itemtype, $id)) { $fields['_infocoms'] = $ic->fields; } } } // retrieve item contracts if (isset($params['with_contracts']) && $params['with_contracts']) { $fields['_contracts'] = array(); if (!Contract::canView()) { $fields['_contracts'] = self::arrayRightError(); } else { $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`"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_contracts'][] = $data; } } } } // retrieve item contracts if (isset($params['with_documents']) && $params['with_documents']) { $fields['_documents'] = array(); if (!$itemtype != 'Ticket' && $itemtype != 'KnowbaseItem' && $itemtype != 'Reminder' && !Document::canView()) { $fields['_documents'] = self::arrayRightError(); } else { $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` = '{$itemtype}' "; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_documents'][] = $data; } } } } // retrieve item tickets if (isset($params['with_tickets']) && $params['with_tickets']) { $fields['_tickets'] = array(); if (!Ticket::canView()) { $fields['_tickets'] = self::arrayRightError(); } else { $query = "SELECT " . Ticket::getCommonSelect() . "\n FROM `glpi_tickets` " . Ticket::getCommonLeftJoin() . "\n WHERE `glpi_items_tickets`.`items_id` = '{$id}'\n AND `glpi_items_tickets`.`itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY `glpi_tickets`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_tickets'][] = $data; } } } } // retrieve item problems if (isset($params['with_problems']) && $params['with_problems']) { $fields['_problems'] = array(); if (!Problem::canView()) { $fields['_problems'] = self::arrayRightError(); } else { $query = "SELECT " . Problem::getCommonSelect() . "\n FROM `glpi_problems`\n LEFT JOIN `glpi_items_problems`\n ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . Problem::getCommonLeftJoin() . "\n WHERE `items_id` = '{$id}'\n AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\n ORDER BY `glpi_problems`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_problems'][] = $data; } } } } // retrieve item changes if (isset($params['with_changes']) && $params['with_changes']) { $fields['_changes'] = array(); if (!Change::canView()) { $fields['_changes'] = self::arrayRightError(); } else { $query = "SELECT " . Change::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`problems_id`) " . Change::getCommonLeftJoin() . "\n WHERE `items_id` = '{$id}'\n AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY `glpi_changes`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_changes'][] = $data; } } } } // retrieve item notes if (isset($params['with_notes']) && $params['with_notes']) { $fields['_notes'] = array(); if (!Session::haveRight($itemtype::$rightname, READNOTE)) { $fields['_notes'] = self::arrayRightError(); } else { $fields['_notes'] = Notepad::getAllForItem($item); } } // retrieve item logs if (isset($params['with_logs']) && $params['with_logs']) { $fields['_logs'] = array(); if (!Session::haveRight($itemtype::$rightname, READNOTE)) { $fields['_logs'] = self::arrayRightError(); } else { $fields['_logs'] = getAllDatasFromTable("glpi_logs", "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'"); } } // expand dropdown (retrieve name of dropdowns) and get hateoas from foreign keys $fields = self::parseDropdowns($fields, $params); // get hateoas from children if ($params['get_hateoas']) { $hclasses = self::getHatoasClasses($itemtype); foreach ($hclasses as $hclass) { $fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $item->getID() . "/{$hclass}/"); } } // get sha1 footprint if needed if ($params['get_sha1']) { $fields = sha1(json_encode($fields, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK)); } return $fields; }
/** * 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' && !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 = "&tickets_id=" . $item->fields['id']; } $canedit = $item->canAddItem('Document') && Document::canView(); $rand = mt_rand(); $is_recursive = $item->isRecursive(); if (isset($_POST["order"]) && $_POST["order"] == "ASC") { $order = "ASC"; } else { $order = "DESC"; } if (isset($_POST["sort"]) && !empty($_POST["sort"])) { $sort = "`" . $_POST["sort"] . "`"; } else { $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; } 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() . ") "; 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='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); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'filename' => __('File'), 'link' => __('Web link'), 'headings' => __('Heading'), 'mime' => __('MIME type'), 'assocdate' => __('Date')); foreach ($columns as $key => $val) { echo "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></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['entityID']); 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 " "; } echo "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_documentcategories", $data["documentcategories_id"]); echo "</td>"; echo "<td class='center'>" . $data["mime"] . "</td>"; echo "<td class='center'>" . Html::convDateTime($data["assocdate"]) . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Get the standard massive actions * * @since version 0.84 * * This must not be overloaded in Class * @param $is_deleted massive action for deleted items ? (default 0) * @param $checkitem link item to check right (default NULL) * * @return an array of massive actions **/ function getAllMassiveActions($is_deleted = 0, $checkitem = NULL) { global $CFG_GLPI, $PLUGIN_HOOKS; if (!is_null($checkitem)) { $isadmin = $checkitem->canUpdate(); } else { $isadmin = static::canUpdate(); } $itemtype = $this->getType(); $actions = array(); if ($is_deleted) { if ($isadmin) { $actions['purge'] = _x('button', 'Delete permanently'); $actions['restore'] = _x('button', 'Restore'); } } else { if ($isadmin || in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canUpdate()) { //TRANS: select action 'update' (before doing it) $actions['update'] = _x('button', 'Update'); } if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && Infocom::canCreate()) { $actions['activate_infocoms'] = __('Enable the financial and administrative information'); } // No delete for entities and tracking of not have right if ($isadmin) { // do not take into account is_deleted if items may be dynamic if ($this->maybeDeleted() && !$this->useDeletedToLockIfDynamic()) { $actions['delete'] = _x('button', 'Put in dustbin'); } else { $actions['purge'] = _x('button', 'Delete permanently'); } } if (in_array($itemtype, $CFG_GLPI["document_types"])) { if (Document::canView()) { $actions['add_document'] = _x('button', 'Add a document'); $actions['remove_document'] = _x('button', 'Remove a document'); } } if (in_array($itemtype, $CFG_GLPI["contract_types"])) { if (Contract::canUpdate()) { $actions['add_contract_item'] = _x('button', 'Add a contract'); $actions['remove_contract_item'] = _x('button', 'Remove a contract'); } } // Specific actions $actions += $this->getSpecificMassiveActions($checkitem); // Plugin Specific actions if (isset($PLUGIN_HOOKS['use_massive_action'])) { foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) { $plug_actions = Plugin::doOneHook($plugin, 'MassiveActions', $itemtype); if (count($plug_actions)) { $actions += $plug_actions; } } } } //Add unlock if needed $actions += Lock::getUnlockMassiveActions($itemtype); // Manage forbidden actions $forbidden_actions = $this->getForbiddenStandardMassiveAction(); if (is_array($forbidden_actions) && count($forbidden_actions)) { foreach ($forbidden_actions as $actiontodel) { if (isset($actions[$actiontodel])) { unset($actions[$actiontodel]); } } } return $actions; }
/** * Dropdown of actions for massive action * * @param $itemtype item type * @param $is_deleted massive action for deleted items ? * @param $extraparams array of extra parameters **/ static function showForMassiveAction($itemtype, $is_deleted = 0, $extraparams = array()) { global $LANG, $CFG_GLPI, $PLUGIN_HOOKS; /// TODO include in CommonDBTM defining only getAdditionalMassiveAction in sub classes /// for specific actions (return a array of action name and title) if (!class_exists($itemtype)) { return false; } if ($itemtype == 'NetworkPort') { echo "<select name='massiveaction' id='massiveaction'>"; echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>"; echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>"; echo "<option value='assign_vlan'>" . $LANG['networking'][55] . "</option>"; echo "<option value='unassign_vlan'>" . $LANG['networking'][58] . "</option>"; // Interest of this massive action ? // echo "<option value='move'>".$LANG['buttons'][20]."</option>"; echo "</select>"; $params = array('action' => '__VALUE__', 'itemtype' => $itemtype); ajaxUpdateItemOnSelectEvent("massiveaction", "show_massiveaction", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionPorts.php", $params); echo "<span id='show_massiveaction'> </span>\n"; } else { $item = new $itemtype(); $infocom = new Infocom(); $isadmin = $item->canUpdate(); echo "<select name='massiveaction' id='massiveaction'>"; echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>"; if (!in_array($itemtype, $CFG_GLPI["massiveaction_noupdate_types"]) && ($isadmin && $itemtype != 'Ticket' || in_array($itemtype, $CFG_GLPI["infocom_types"]) && $infocom->canUpdate() || $itemtype == 'Ticket' && haveRight('update_ticket', 1))) { echo "<option value='update'>" . $LANG['buttons'][14] . "</option>"; } if (in_array($itemtype, $CFG_GLPI["infocom_types"]) && $infocom->canCreate()) { echo "<option value='activate_infocoms'>" . $LANG['financial'][68] . "</option>"; } if ($is_deleted && !in_array($itemtype, $CFG_GLPI["massiveaction_nodelete_types"])) { if ($isadmin) { echo "<option value='purge'>" . $LANG['buttons'][22] . "</option>"; echo "<option value='restore'>" . $LANG['buttons'][21] . "</option>"; } } else { // No delete for entities and tracking of not have right if (!in_array($itemtype, $CFG_GLPI["massiveaction_nodelete_types"]) && ($isadmin && $itemtype != 'Ticket' || $itemtype == 'Ticket' && haveRight('delete_ticket', 1))) { if ($item->maybeDeleted()) { echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>"; } else { echo "<option value='purge'>" . $LANG['buttons'][22] . "</option>"; } } if ($isadmin && in_array($itemtype, array('Phone', 'Printer', 'Peripheral', 'Monitor'))) { echo "<option value='connect'>" . $LANG['buttons'][9] . "</option>"; echo "<option value='disconnect'>" . $LANG['buttons'][10] . "</option>"; } if (in_array($itemtype, $CFG_GLPI["document_types"])) { $doc = new Document(); if ($doc->canView()) { echo "<option value='add_document'>" . $LANG['document'][16] . "</option>"; } } if (in_array($itemtype, $CFG_GLPI["contract_types"])) { $contract = new Contract(); if ($contract->canUpdate()) { echo "<option value='add_contract'>" . $LANG['financial'][36] . "</option>"; } } if (haveRight('transfer', 'r') && isMultiEntitiesMode() && in_array($itemtype, array('CartridgeItem', 'Computer', 'ConsumableItem', 'Contact', 'Contract', 'Supplier', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer', 'Software', 'SoftwareLicense', 'Ticket', 'Document', 'Group', 'Link')) && $isadmin) { echo "<option value='add_transfer_list'>" . $LANG['buttons'][48] . "</option>"; } switch ($itemtype) { case 'Software': if ($isadmin && countElementsInTable("glpi_rules", "sub_type='RuleSoftwareCategory'") > 0) { echo "<option value='compute_software_category'>" . $LANG['rulesengine'][38] . " " . $LANG['rulesengine'][40] . "</option>"; } if (haveRight("rule_dictionnary_software", "w") && countElementsInTable("glpi_rules", "sub_type='RuleDictionnarySoftware'") > 0) { echo "<option value='replay_dictionnary'>" . $LANG['rulesengine'][76] . "</option>"; } break; case 'Computer': if ($isadmin) { echo "<option value='connect_to_computer'>" . $LANG['buttons'][9] . "</option>"; echo "<option value='install'>" . $LANG['buttons'][4] . "</option>"; if ($CFG_GLPI['use_ocs_mode']) { if (haveRight("ocsng", "w") || haveRight("sync_ocsng", "w")) { echo "<option value='force_ocsng_update'>" . $LANG['ocsng'][24] . "</option>"; } echo "<option value='unlock_ocsng_field'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][16] . "</option>"; echo "<option value='unlock_ocsng_monitor'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][30] . "</option>"; echo "<option value='unlock_ocsng_peripheral'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][32] . "</option>"; echo "<option value='unlock_ocsng_printer'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][34] . "</option>"; echo "<option value='unlock_ocsng_software'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][52] . "</option>"; echo "<option value='unlock_ocsng_ip'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][50] . "</option>"; echo "<option value='unlock_ocsng_disk'>" . $LANG['buttons'][38] . " " . $LANG['Menu'][33] . " - " . $LANG['ocsng'][55] . "</option>"; } } break; case 'Supplier': if ($isadmin) { echo "<option value='add_contact'>" . $LANG['financial'][24] . "</option>"; } break; case 'Calendar': echo "<option value='duplicate'>" . $LANG['buttons'][54] . "</option>"; break; case 'Contact': if ($isadmin) { echo "<option value='add_enterprise'>" . $LANG['financial'][25] . "</option>"; } break; case 'User': if ($isadmin) { echo "<option value='add_group'>" . $LANG['setup'][604] . "</option>"; echo "<option value='add_userprofile'>" . $LANG['setup'][607] . "</option>"; } if (haveRight("user_authtype", "w")) { echo "<option value='change_authtype'>" . $LANG['login'][30] . "</option>"; echo "<option value='force_user_ldap_update'>" . $LANG['ocsng'][24] . "</option>"; } break; case 'Ticket': $tmp = new TicketFollowup(); if ($tmp->canCreate()) { echo "<option value='add_followup'>" . $LANG['job'][29] . "</option>"; } $tmp = new TicketTask(); if ($tmp->canCreate()) { echo "<option value='add_task'>" . $LANG['job'][30] . "</option>"; } $tmp = new TicketValidation(); if ($tmp->canCreate()) { echo "<option value='submit_validation'>" . $LANG['validation'][26] . "</option>"; } if (haveRight("update_ticket", "1")) { echo "<option value='add_actor'>" . $LANG['job'][27] . "</option>"; echo "<option value='link_ticket'>" . $LANG['job'][56] . "</option>"; } break; case 'CronTask': echo "<option value='reset'>" . $LANG['buttons'][16] . " (" . $LANG['crontask'][40] . ")"; echo "</option>"; break; case 'NotImportedEmail': echo "<option value='delete_email'>" . $LANG['mailing'][133] . "</option>"; echo "<option value='import_email'>" . $LANG['buttons'][37] . "</option>"; break; } if ($item instanceof CommonTreeDropdown) { if ($isadmin) { echo "<option value='move_under'>" . $LANG['buttons'][20] . "</option>"; } } if ($itemtype != 'Entity' && $itemtype != 'Calendar' && $item instanceof CommonDropdown && $item->maybeRecursive()) { if ($isadmin) { echo "<option value='merge'>" . $LANG['buttons'][48] . " - " . $LANG['software'][48]; echo "</option>"; } } // Plugin Specific actions if (isset($PLUGIN_HOOKS['use_massive_action'])) { foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) { $actions = doOneHook($plugin, 'MassiveActions', $itemtype); if (count($actions)) { foreach ($actions as $key => $val) { echo "<option value = '{$key}'>{$val}</option>"; } } } } } echo "</select>"; $params = array('action' => '__VALUE__', 'is_deleted' => $is_deleted, 'itemtype' => $itemtype); if (count($extraparams)) { foreach ($extraparams as $key => $val) { $params['extra_' . $key] = $val; } } ajaxUpdateItemOnSelectEvent("massiveaction", "show_massiveaction", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveAction.php", $params); echo "<span id='show_massiveaction'> </span>\n"; } }
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 = "&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() . ") "; 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>"; } }
/** * Return the instance fields of itemtype identified by id * * @since version 9.1 * * @param string $itemtype itemtype (class) of object * @param integer $id identifier of object * @param array $params array with theses options : * - 'expand_dropdowns' : show dropdown's names instead of id. default: false. Optionnal * - 'get_hateoas' : show relation of current item in a links attribute. default: true. Optionnal * - 'with_components' : Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal. * - 'with_disks' : Only for Computer, retrieve the associated filesystems. Optionnal. * - 'with_softwares' : Only for Computer, retrieve the associated softwares installations. Optionnal. * - 'with_connections' : Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal. * - 'with_networkports' :Retrieve all network connections and advanced network informations. Optionnal. * - 'with_infocoms' : Retrieve financial and administrative informations. Optionnal. * - 'with_contracts' : Retrieve associated contracts. Optionnal. * - 'with_documents' : Retrieve associated external documents. Optionnal. * - 'with_tickets' : Retrieve associated itil tickets. Optionnal. * - 'with_problems' : Retrieve associated itil problems. Optionnal. * - 'with_changes' : Retrieve associated itil changes. Optionnal. * - 'with_notes' : Retrieve Notes (if exists, not all itemtypes have notes). Optionnal. * - 'with_logs' : Retrieve historical. Optionnal. * * @return array fields of found object */ protected function getItem($itemtype, $id, $params = array()) { global $CFG_GLPI, $DB; $this->initEndpoint(); // default params $default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false); $params = array_merge($default, $params); $item = new $itemtype(); if (!$item->getFromDB($id)) { return $this->messageNotfoundError(); } if (!$item->can($id, READ)) { return $this->messageRightError(); } $fields = $item->fields; // retrieve devices if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) { $all_devices = array(); foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) { $found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'\n AND `is_deleted` = '0'", true); foreach ($found_devices as $devices_id => &$device) { unset($device['items_id']); unset($device['itemtype']); unset($device['is_deleted']); } if (!empty($found_devices)) { $all_devices[$device_type] = $found_devices; } } $fields['_devices'] = $all_devices; } // retrieve computer disks if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") { // build query to retrive filesystems $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE `computers_id` = '{$id}'\n AND `is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { unset($data['computers_id']); unset($data['is_deleted']); $fields['_disks'][] = array('name' => $data); } } } // retrieve computer softwares if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") { $fields['_softwares'] = array(); if (!Software::canView()) { $fields['_softwares'] = self::arrayRightError(); } else { $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`id` AS softwares_id,\n `glpi_softwareversions`.`id` AS softwareversions_id,\n `glpi_computers_softwareversions`.`is_dynamic`,\n `glpi_softwareversions`.`states_id`,\n `glpi_softwares`.`is_valid`\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_softwares'][] = $data; } } } } // retrieve item connections if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") { $fields['_connections'] = array(); foreach ($CFG_GLPI["directconnect_types"] as $connect_type) { $connect_item = new $connect_type(); if ($connect_item->canView()) { $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n `glpi_computers_items`.`items_id` AS assoc_items_id,\n `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n " . getTableForItemType($connect_type) . ".*\n FROM `glpi_computers_items`\n LEFT JOIN `" . getTableForItemType($connect_type) . "`\n ON (`" . getTableForItemType($connect_type) . "`.`id`\n = `glpi_computers_items`.`items_id`)\n WHERE `computers_id` = '{$id}'\n AND `itemtype` = '" . $connect_type . "'\n AND `glpi_computers_items`.`is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_connections'][$connect_type][] = $data; } } } } } // retrieve item networkports if (isset($params['with_networkports']) && $params['with_networkports']) { $fields['_networkports'] = array(); if (!NetworkEquipment::canView()) { $fields['_networkports'] = self::arrayRightError(); } else { foreach (NetworkPort::getNetworkPortInstantiations() as $networkport_type) { $query = "SELECT\n netp.`entities_id`,\n netp.`is_recursive`,\n netp.`logical_number`,\n netp.`name`,\n netp.`mac`,\n netp.`comment`,\n netp.`is_dynamic`,\n netp_subtable.*\n FROM glpi_networkports AS netp\n LEFT JOIN " . $networkport_type::getTable() . " AS netp_subtable\n ON netp_subtable.`networkports_id` = netp.`id`\n WHERE netp.`instantiation_type` = '{$networkport_type}'\n AND netp.`items_id` = '{$id}'\n AND netp.`itemtype` = '{$itemtype}'\n AND netp.`is_deleted` = '0'"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_networkports'][$networkport_type][] = $data; } } } } } // retrieve item infocoms if (isset($params['with_infocoms']) && $params['with_infocoms']) { $fields['_infocoms'] = array(); if (!Infocom::canView()) { $fields['_infocoms'] = self::arrayRightError(); } else { $ic = new Infocom(); if ($ic->getFromDBforDevice($itemtype, $id)) { $fields['_infocoms'] = $ic->fields; } } } // retrieve item contracts if (isset($params['with_contracts']) && $params['with_contracts']) { $fields['_contracts'] = array(); if (!Contract::canView()) { $fields['_contracts'] = self::arrayRightError(); } else { $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`"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_contracts'][] = $data; } } } } // retrieve item contracts if (isset($params['with_documents']) && $params['with_documents']) { $fields['_documents'] = array(); if (!$itemtype != 'Ticket' && $itemtype != 'KnowbaseItem' && $itemtype != 'Reminder' && !Document::canView()) { $fields['_documents'] = self::arrayRightError(); } else { $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` = '{$itemtype}' "; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_documents'][] = $data; } } } } // retrieve item tickets if (isset($params['with_tickets']) && $params['with_tickets']) { $fields['_tickets'] = array(); if (!Ticket::canView()) { $fields['_tickets'] = self::arrayRightError(); } else { $query = "SELECT " . Ticket::getCommonSelect() . "\n FROM `glpi_tickets` " . Ticket::getCommonLeftJoin() . "\n WHERE `glpi_items_tickets`.`items_id` = '{$id}'\n AND `glpi_items_tickets`.`itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY `glpi_tickets`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_tickets'][] = $data; } } } } // retrieve item problems if (isset($params['with_problems']) && $params['with_problems']) { $fields['_problems'] = array(); if (!Problem::canView()) { $fields['_problems'] = self::arrayRightError(); } else { $query = "SELECT " . Problem::getCommonSelect() . "\n FROM `glpi_problems`\n LEFT JOIN `glpi_items_problems`\n ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . Problem::getCommonLeftJoin() . "\n WHERE `items_id` = '{$id}'\n AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\n ORDER BY `glpi_problems`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_problems'][] = $data; } } } } // retrieve item changes if (isset($params['with_changes']) && $params['with_changes']) { $fields['_changes'] = array(); if (!Change::canView()) { $fields['_changes'] = self::arrayRightError(); } else { $query = "SELECT " . Change::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`problems_id`) " . Change::getCommonLeftJoin() . "\n WHERE `items_id` = '{$id}'\n AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY `glpi_changes`.`date_mod` DESC"; if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $fields['_changes'][] = $data; } } } } // retrieve item notes if (isset($params['with_notes']) && $params['with_notes']) { $fields['_notes'] = array(); if (!Session::haveRight($itemtype::$rightname, READNOTE)) { $fields['_notes'] = self::arrayRightError(); } else { $fields['_notes'] = Notepad::getAllForItem($itemtype); } } // retrieve item logs if (isset($params['with_logs']) && $params['with_logs']) { $fields['_logs'] = array(); if (!Session::haveRight($itemtype::$rightname, READNOTE)) { $fields['_logs'] = self::arrayRightError(); } else { $fields['_logs'] = getAllDatasFromTable("glpi_logs", "`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "'"); } } // expand dropdown (retrieve name of dropdowns) and get hateoas from foreign keys $fields = self::parseDropdowns($fields, $params); // get hateoas from children if ($params['get_hateoas']) { $hclasses = self::getHatoasClasses($itemtype); foreach ($hclasses as $hclass) { $fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $item->getID() . "/{$hclass}/"); } } return $fields; }