/** * Delete tag or image from ticket content * * @since version 0.85 * * @param $content html content of input * @param $tags * * @return htlm content **/ function cleanTagOrImage($content, $tags) { global $CFG_GLPI; // RICH TEXT : delete img tag if ($CFG_GLPI["use_rich_text"]) { $content = Html::entity_decode_deep($content); foreach ($tags as $tag) { $content = preg_replace("/<img.*alt=['|\"]" . $tag . "['|\"][^>]*\\>/", "<p></p>", $content); } } else { // SIMPLE TEXT : delete tag foreach ($tags as $tag) { $content = preg_replace('/' . Document::getImageTag($tag) . '/', '\\r\\n', $content); } } return $content; }
/** * add files (from $this->input['_filename']) to an ITIL object * create document if needed * create link from document to ITIL object * * @param $donotif Boolean if we want to raise notification (default 1) * @param $disablenotif (default 0) * * @return array of doc added name **/ function addFiles($donotif = 1, $disablenotif = 0) { global $CFG_GLPI; if (!isset($this->input['_filename']) || count($this->input['_filename']) == 0) { return array(); } $docadded = array(); foreach ($this->input['_filename'] as $key => $file) { $doc = new Document(); $docitem = new Document_Item(); $docID = 0; $filename = GLPI_TMP_DIR . "/" . $file; $input2 = array(); // Crop/Resize image file if needed if (isset($this->input['_coordinates']) && !empty($this->input['_coordinates'][$key])) { $image_coordinates = json_decode(urldecode($this->input['_coordinates'][$key]), true); Toolbox::resizePicture($filename, $filename, $image_coordinates['img_w'], $image_coordinates['img_h'], $image_coordinates['img_y'], $image_coordinates['img_x'], $image_coordinates['img_w'], $image_coordinates['img_h'], 0); } else { Toolbox::resizePicture($filename, $filename, 0, 0, 0, 0, 0, 0, 0); } //If file tag is present if (isset($this->input['_tag_filename']) && !empty($this->input['_tag_filename'][$key])) { $this->input['_tag'][$key] = $this->input['_tag_filename'][$key]; } // Check for duplicate if ($doc->getFromDBbyContent($this->fields["entities_id"], $filename)) { if (!$doc->fields['is_blacklisted']) { $docID = $doc->fields["id"]; } // File already exist, we replace the tag by the existing one if (isset($this->input['_tag'][$key]) && $docID > 0 && isset($this->input['content'])) { $this->input['content'] = preg_replace('/' . Document::getImageTag($this->input['_tag'][$key]) . '/', Document::getImageTag($doc->fields["tag"]), $this->input['content']); $docadded[$docID]['tag'] = $doc->fields["tag"]; } } else { //TRANS: Default document to files attached to tickets : %d is the ticket id $input2["name"] = addslashes(sprintf(__('Document Ticket %d'), $this->getID())); if ($this->getType() == 'Ticket') { $input2["tickets_id"] = $this->getID(); // Insert image tag if (isset($this->input['_tag'][$key])) { $input2["tag"] = $this->input['_tag'][$key]; } } $input2["entities_id"] = $this->fields["entities_id"]; $input2["documentcategories_id"] = $CFG_GLPI["documentcategories_id_forticket"]; $input2["_only_if_upload_succeed"] = 1; $input2["entities_id"] = $this->fields["entities_id"]; $input2["_filename"] = array($file); $docID = $doc->add($input2); } if ($docID > 0) { if ($docitem->add(array('documents_id' => $docID, '_do_notif' => $donotif, '_disablenotif' => $disablenotif, 'itemtype' => $this->getType(), 'items_id' => $this->getID()))) { $docadded[$docID]['data'] = sprintf(__('%1$s - %2$s'), stripslashes($doc->fields["name"]), stripslashes($doc->fields["filename"])); if (isset($input2["tag"])) { $docadded[$docID]['tag'] = $input2["tag"]; unset($this->input['_filename'][$key]); unset($this->input['_tag'][$key]); } if (isset($this->input['_coordinates'][$key])) { unset($this->input['_coordinates'][$key]); } } } // Only notification for the first New doc $donotif = 0; } // Ticket update if (isset($this->input['content'])) { if ($CFG_GLPI["use_rich_text"]) { $this->input['content'] = $this->convertTagToImage($this->input['content'], true, $docadded); $this->input['_forcenotif'] = true; } else { $this->fields['content'] = $this->setSimpleTextContent($this->input['content']); $this->updateInDB(array('content')); } } return $docadded; }
/** * @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>"; }
GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief * @since version 0.85 */ $AJAX_INCLUDE = 1; include '../inc/includes.php'; header('Content-type: application/json'); Html::header_nocache(); Session::checkLoginUser(); if (isset($_POST['data'])) { foreach ($_POST['data'] as $key => $values) { $unique_name = Rule::getUuid(); $response[$key] = array('tag' => Document::getImageTag($unique_name), 'name' => $unique_name); } echo json_encode($response); }
/** * Delete tag or image from ticket content * * @since version 0.85 * * @param $content html content of input * @param $tags * * @return htlm content **/ function cleanTagOrImage($content, $tags) { global $CFG_GLPI; // RICH TEXT : delete img tag if ($CFG_GLPI["use_rich_text"]) { $html = str_replace(array('&', '&nbsp;'), array('&', ' '), html_entity_decode($content, ENT_QUOTES, "ISO-8859-1")); // We parse HTML with dom libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHTML('<html>' . $html . '</html>'); $dom->preserveWhiteSpace = false; // We replace each <img> by a <p> $nodes = $dom->getElementsByTagName('img'); $nodeListLength = $nodes->length; $nodesToDelete = array(); for ($i = 0; $i < $nodeListLength; $i++) { $node = $nodes->item($i); if ($id = $node->getAttribute('alt')) { foreach ($tags as $tag) { if (preg_match("/" . $tag . "/i", $id)) { $nodesToDelete[] = $node; } } } } foreach ($nodesToDelete as $node) { $p = $dom->createElement('p'); $node->parentNode->replaceChild($p, $node); } // Get only body content $doc = new DOMDocument(); $body = $dom->getElementsByTagName('body')->item(0); foreach ($body->childNodes as $child) { $doc->appendChild($doc->importNode($child, true)); } return utf8_decode(Html::entity_decode_deep($doc->saveHTML())); // SIMPLE TEXT : delete tag } else { foreach ($tags as $tag) { $content = preg_replace('/' . Document::getImageTag($tag) . '/', '\\r\\n', $content); } return $content; } }
/** * Send mai lin queue * * @param $ID integer ID of the item * * @return true if send false if not **/ function sendMailById($ID) { global $CFG_GLPI; if ($this->getFromDB($ID)) { $mmail = new GLPIMailer(); $headers = importArrayFromDB($this->fields['headers']); if (is_array($headers) && count($headers)) { foreach ($headers as $key => $val) { $mmail->AddCustomHeader("{$key}: {$val}"); } } // Add custom header for mail grouping in reader $mmail->AddCustomHeader("In-Reply-To: GLPI-" . $this->fields["itemtype"] . "-" . $this->fields["items_id"]); $mmail->SetFrom($this->fields['sender'], $this->fields['sendername']); if ($this->fields['replyto']) { $mmail->AddReplyTo($this->fields['replyto'], $this->fields['replytoname']); } $mmail->Subject = $this->fields['name']; if (empty($this->fields['body_html'])) { $mmail->isHTML(false); $mmail->Body = $this->fields['body_text']; } else { $mmail->isHTML(true); $mmail->Body = ''; $this->fields['body_html'] = Html::entity_decode_deep($this->fields['body_html']); $documents = importArrayFromDB($this->fields['documents']); $link_doc = array(); if (is_array($documents) && count($documents)) { $doc = new Document(); foreach ($documents as $docID) { $doc->getFromDB($docID); // Add embeded image if tag present in ticket content if (preg_match_all('/' . Document::getImageTag($doc->fields['tag']) . '/', $this->fields['body_html'], $matches, PREG_PATTERN_ORDER)) { $mmail->AddEmbeddedImage(GLPI_DOC_DIR . "/" . $doc->fields['filepath'], Document::getImageTag($doc->fields['tag']), $doc->fields['filename'], 'base64', $doc->fields['mime']); // Else Add link to the document } else { $link_doc[] = "<a href='" . rtrim($CFG_GLPI["url_base"], '/') . "/front/document.send.php?docid=" . $doc->fields['id'] . "' >" . $doc->fields['name'] . "</a>"; } } } $mmail->Body .= $this->fields['body_html']; if (count($link_doc)) { $mmail->Body .= '<p style="border:1px solid #cccccc;padding:5px">' . '<b>' . _n('Associated item', 'Associated items', Session::getPluralNumber()) . ' : </b>' . implode(', ', $link_doc) . '</p>'; } $mmail->AltBody = $this->fields['body_text']; } $mmail->AddAddress($this->fields['recipient'], $this->fields['recipientname']); if (!empty($this->fields['messageid'])) { $mmail->MessageID = "<" . $this->fields['messageid'] . ">"; } $messageerror = __('Error in sending the email'); if (!$mmail->Send()) { Session::addMessageAfterRedirect($messageerror . "<br>" . $mmail->ErrorInfo, true); $mmail->ClearAddresses(); $this->update(array('id' => $this->fields['id'], 'sent_try' => $this->fields['sent_try'] + 1)); return false; } else { //TRANS to be written in logs %1$s is the to email / %2$s is the subject of the mail Toolbox::logInFile("mail", sprintf(__('%1$s: %2$s'), sprintf(__('An email was sent to %s'), $this->fields['recipient']), $this->fields['name'] . "\n")); $mmail->ClearAddresses(); $this->update(array('id' => $this->fields['id'], 'sent_time' => $_SESSION['glpi_currenttime'])); $this->delete(array('id' => $this->fields['id'])); return true; } } else { 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 = "&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() . ") "; 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}&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>"; }