/** * 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 = '') { $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if ($item->getType() != 'Ticket' && $item->getType() != 'KnowbaseItem' && $item->getType() != 'Reminder' && !Document::canView()) { return false; } $params = array(); $params['rand'] = mt_rand(); self::showAddFormForItem($item, $withtemplate, $params); self::showListForItem($item, $withtemplate, $params); }
/** * Show certificates associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated certificates 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 (!Session::haveRight("plugin_certificates", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginCertificatesCertificate'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_certificates_certificates_items`.`id` AS assocID, `glpi_entities`.`id` AS entity, `glpi_plugin_certificates_certificates`.`name` AS assocName, `glpi_plugin_certificates_certificates`.* FROM `glpi_plugin_certificates_certificates_items` LEFT JOIN `glpi_plugin_certificates_certificates` ON (`glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id`=`glpi_plugin_certificates_certificates`.`id`) LEFT JOIN `glpi_entities` ON (`glpi_plugin_certificates_certificates`.`entities_id`=`glpi_entities`.`id`) WHERE `glpi_plugin_certificates_certificates_items`.`items_id` = '$ID' AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '".$item->getType()."' "; $query .= getEntitiesRestrictRequest(" AND","glpi_plugin_certificates_certificates",'','',true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $certificates = array(); $certificate = new PluginCertificatesCertificate(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $certificates[$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_plugin_certificates_certificates",'',$entities,true); $q = "SELECT COUNT(*) FROM `glpi_plugin_certificates_certificates` WHERE `is_deleted` = '0' $limit"; $result = $DB->query($q); $nb = $DB->result($result,0,0); echo "<div class='firstbloc'>"; if (Session::haveRight("plugin_certificates", READ) && ($nb > count($used))) { echo "<form name='certificate_form$rand' id='certificate_form$rand' method='post' action='".Toolbox::getItemTypeFormURL('PluginCertificatesCertificate')."'>"; 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'>"; } PluginCertificatesCertificate::dropdown(array('entity' => $entities , 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"". _sx('button', 'Associate a certificate', 'certificates')."\" 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($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>"; if (Session::isMultiEntitiesMode()) { echo "<th>".__('Entity')."</th>"; } echo "<th>".__('Type')."</th>"; echo "<th>".__('DNS name', 'certificates')."</th>"; echo "<th>".__('DNS suffix', 'certificates')."</th>"; echo "<th>".__('Creation date')."</th>"; echo "<th>".__('Expiration date')."</th>"; echo "<th>".__('Status')."</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginCertificatesCertificate', //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($certificates as $data) { $certificateID = $data["id"]; $link = NOT_AVAILABLE; if ($certificate->getFromDB($certificateID)) { $link = $certificate->getLink(); } Session::addToNavigateListItems('PluginCertificatesCertificate', $certificateID); $used[$certificateID] = $certificateID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities", $data['entities_id']). "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatetypes", $data["plugin_certificates_certificatetypes_id"]); echo "</td>"; echo "<td class='center'>".$data["dns_name"]."</td>"; echo "<td class='center'>".$data["dns_suffix"]."</td>"; echo "<td class='center'>".Html::convdate($data["date_query"])."</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>".Html::convdate($data["date_expiration"])."</div>"; echo "</td>"; } else if (empty($data["date_expiration"])) { echo "<td class='center'>".__('Does not expire', 'certificates')."</td>"; } else { echo "<td class='center'>".Html::convdate($data["date_expiration"])."</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatestates", $data["plugin_certificates_certificatestates_id"]); echo "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && ($withtemplate < 2)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show projet associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated projet 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 (!plugin_projet_haveRight('projet', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginProjetProjet'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_projet_projets`.`name` AS assocName,\n `glpi_plugin_projet_projets`.*\n FROM `glpi_plugin_projet_projets_items`\n LEFT JOIN `glpi_plugin_projet_projets`\n ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $projets = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $projets[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } $projet = new PluginProjetProjet(); 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_plugin_projet_projets", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_projet_projets`\n WHERE `is_deleted` = '0'\n AND `is_template` = '0' "; if ($item->getType() != 'User') { $q .= " {$limit}"; } $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) { echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>"; 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}'>"; } if ($item->getType() != 'User') { $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used); } else { $strict_entities = Profile_User::getUserEntities($ID, true); if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) { $canedit = false; } if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) { Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities)); } } echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" 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'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($item->getType() == "Group" || $item->getType() == "User") { echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</th></tr>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Description') . "</th>"; echo "<th>" . __('Progress') . "</th>"; echo "<th>" . __('Start date') . "</th>"; echo "<th>" . __('End date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($projets as $data) { $projetID = $data["id"]; $link = NOT_AVAILABLE; if ($projet->getFromDB($projetID)) { $link = $projet->getLink(); } Session::addToNavigateListItems('PluginProjetProjet', $projetID); $used[$projetID] = $projetID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>"; echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>"; if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) { echo "<td class='center'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>"; } else { echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>"; } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
static function showUsers(CommonDBTM $item) { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_projet_haveRight('projet', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } $canread = $item->can($ID, 'r'); $query = "SELECT `glpi_plugin_projet_projets`.* FROM `glpi_plugin_projet_projets` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_projet_projets`.`entities_id`) "; if ($item->getType() == 'User') { $query .= " WHERE `glpi_plugin_projet_projets`.`users_id` = '" . $ID . "' "; } else { $query .= " WHERE `glpi_plugin_projet_projets`.`groups_id` = '" . $ID . "' "; } $query .= "AND `glpi_plugin_projet_projets`.`is_template` = 0 " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', '', $item->maybeRecursive()); $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($number > 0) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php\">"; echo "<div align='center'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='" . (4 + $colsup) . "'>" . __('Responsible of projects', 'projet') . ":</th></tr>"; echo "<tr><th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Description') . "</th>"; echo "<th>" . __('Progress') . "</th>"; echo "</tr>"; while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>"; if ($canread && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["recursive"])) { echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $data["id"] . "'>" . $data["name"]; if ($_SESSION["glpiis_ids_visible"]) { echo " (" . $data["id"] . ")"; } echo "</a></td>"; } else { echo "<td class='center'>" . $data["name"]; if ($_SESSION["glpiis_ids_visible"]) { echo " (" . $data["id"] . ")"; } echo "</td>"; } if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>"; echo "<td align='center'>" . $data["advance"] . " %</td>"; echo "</tr>"; } echo "</table></div>"; Html::closeForm(); echo "<br>"; } else { echo "<div align='center'><table class='tab_cadre_fixe' style='text-align:center'>"; echo "<tr><th>" . __('Responsible of projects', 'projet') . " - " . __('No item found'); echo "</th></tr></table></div><br>"; } }
/** * Get documents associated to an item * * @param $item CommonDBTM object for which associated documents must be displayed * @param $withtemplate (default '') **/ static function getAssociatedDocuments(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; if (!($item instanceof KnowbaseItem && $CFG_GLPI["use_public_faq"] && !$item->getEntityID())) { if ($item->isNewID($item->getField('id'))) { return array(); } switch ($item->getType()) { case 'Ticket': case 'KnowbaseItem': break; default: if (Session::haveRight('document', READ)) { return array(); } } if (!$item->can($item->fields['id'], READ)) { return array(); } } $query = "SELECT `glpi_documents_items`.`id` as assocID,\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` = '" . $item->getField('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' "; } $docs = array(); foreach ($DB->request($query) as $data) { $docs[] = $data; } return $docs; }
/** * Display changes for an item * * Will also display changes of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::READALL)) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'OR'; $options['criteria'][1]['field'] = 66; // status $options['criteria'][1]['searchtype'] = 'equals'; $options['criteria'][1]['value'] = $item->getID(); $options['criteria'][1]['link'] = 'OR'; $options['criteria'][5]['field'] = 5; // status $options['criteria'][5]['searchtype'] = 'equals'; $options['criteria'][5]['value'] = $item->getID(); $options['criteria'][5]['link'] = 'OR'; break; case 'Supplier': $restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last changes') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; _e('Child groups'); Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_changes_groups`.`groups_id` {$restrict}\n AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); // Ticket for the item echo "<div class='firstbloc'><table class='tab_cadre_fixe'>"; $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } if ($number > 0) { Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr><th colspan='{$colspan}'>"; //TRANS : %d is the number of problems echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number); // echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?". // Toolbox::append_params($options,'&')."'>".__('Show all')."</a></span>"; echo "</th></tr>"; } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Problem', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`itemtype` = '{$ltype}' AND `items_id` = '{$lID}')"; } } } if (count($restrict)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_changes') . "\n ORDER BY `glpi_changes`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='{$colspan}'>"; _e('Changes on linked items'); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * 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 = "&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() . ") "; 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 " "; } 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>"; }
/** * Show resource associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated resource 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 (!plugin_resources_haveRight('resources', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginResourcesResource'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_resources_resources`.`name` AS assocName,\n `glpi_plugin_resources_resources`.*\n FROM `glpi_plugin_resources_resources_items`\n LEFT JOIN `glpi_plugin_resources_resources`\n ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $resources = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $resources[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } $resource = new PluginResourcesResource(); $more = true; if ($item->getType() == "User" && $number != 0) { $more = false; } if ($canedit && $withtemplate < 2 && $more) { // 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_plugin_resources_resources", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_resources_resources`\n WHERE `is_deleted` = '0'\n AND `is_template` = '0' "; if ($item->getType() != 'User') { $q .= " {$limit}"; } $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_resources_haveRight('resources', 'r') && $nb > count($used)) { echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>"; 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}'>"; } PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" 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'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('First name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Location') . "</th>"; echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>"; echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>"; echo "<th>" . __('Arrival date', 'resources') . "</th>"; echo "<th>" . __('Departure date', 'resources') . "</th>"; echo "</tr>"; $used = array(); $resourceID = 0; if ($number) { Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($resources as $data) { $resourceID = $data["id"]; $link = NOT_AVAILABLE; if ($resource->getFromDB($resourceID)) { $link = $resource->getLink(); } Session::addToNavigateListItems('PluginResourcesResource', $resourceID); $used[$resourceID] = $resourceID; $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['firstname'] . "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]); echo "</td>"; echo "<td class='center'>" . Html::convDate($data["date_begin"]) . "</td>"; if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) { echo "<td class='center'>"; echo "<span class='plugin_resources_date_color'>"; echo Html::convDate($data["date_end"]); echo "</span>"; echo "</td>"; } else { if (empty($data["date_end"])) { echo "<td class='center'>" . __('Not defined', 'resources') . "</td>"; } else { echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; if ($item->getType() == "User") { $PluginResourcesEmployee = new PluginResourcesEmployee(); $PluginResourcesEmployee->showForm($resourceID, $ID, 0); } }
/** * Show domains associated to a supplier * * @since version 0.84 * * @param $item CommonDBTM object for which associated domains must be displayed * @param $withtemplate (default '') **/ static function showForSupplier(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!plugin_domains_haveRight('domains', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_domains_domains`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_domains_domains`.`name` AS assocName,\n `glpi_plugin_domains_domains`.* " . "FROM `glpi_plugin_domains_domains` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_domains_domains`.`entities_id`) " . " WHERE `suppliers_id` = '{$ID}' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_domains_domains", '', '', true); $query .= " ORDER BY `assocName` "; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $domains = array(); $domain = new PluginDomainsDomain(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $domains[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Group in charge of the hardware') . "</th>"; echo "<th>" . __('Supplier') . "</th>"; echo "<th>" . __('Technician in charge of the hardware') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginDomainsDomain', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($domains as $data) { $domainID = $data["id"]; $link = NOT_AVAILABLE; if ($domain->getFromDB($domainID)) { $link = $domain->getLink(); } Session::addToNavigateListItems('PluginDomainsDomain', $domainID); $used[$domainID] = $domainID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>{$link}</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . "</td>"; echo "<td>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/enterprise.form.php?ID=" . $data["suppliers_id"] . "\">"; echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]); if ($_SESSION["glpiis_ids_visible"] == 1) { echo " (" . $data["suppliers_id"] . ")"; } echo "</a></td>"; echo "<td class='center'>" . getUsername($data["users_id_tech"]) . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_domains_domaintypes", $data["plugin_domains_domaintypes_id"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'><div class='deleted'>" . convdate($data["date_expiration"]) . "</div></td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Does not expire', 'domains') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; echo "</div>"; }
/** * Show routetables associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated routetables 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 (!plugin_routetables_haveRight('routetables', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginRoutetablesRoutetable'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_routetables_routetables_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_routetables_routetables`.`name` AS assocName,\n `glpi_plugin_routetables_routetables`.*\n FROM `glpi_plugin_routetables_routetables_items`\n LEFT JOIN `glpi_plugin_routetables_routetables`\n ON (`glpi_plugin_routetables_routetables_items`.`plugin_routetables_routetables_id`=`glpi_plugin_routetables_routetables`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_routetables_routetables`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_routetables_routetables_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_routetables_routetables_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_routetables_routetables", '', '', false); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $routetables = array(); $routetable = new PluginRoutetablesRoutetable(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $routetables[$data['id']] = $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_plugin_routetables_routetables", '', $entities, false); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_routetables_routetables`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_routetables_haveRight('routetables', 'r') && $nb > count($used)) { echo "<form name='routetable_form{$rand}' id='routetable_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginRoutetablesRoutetable') . "'>"; 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}'>"; } $routetable->dropdownRouteTables("plugin_routetables_routetables_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a routing table', 'routetables') . "\" 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>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Network') . "</th>"; echo "<th>" . __('Subnet mask') . "</th>"; echo "<th>" . __('Gateway') . "</th>"; echo "<th>" . __('Metric', 'routetables') . "</th>"; echo "<th>" . __('Interface') . "</th>"; echo "<th>" . __('Persistance', 'routetables') . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginRoutetablesRoutetable', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($routetables as $data) { $routetableID = $data["id"]; $link = NOT_AVAILABLE; if ($routetable->getFromDB($routetableID)) { $link = $routetable->getLink(); } Session::addToNavigateListItems('PluginRoutetablesRoutetable', $routetable); $used[$routetableID] = $routetableID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["destination"] . "</td>"; echo "<td class='center'>" . $data["netmask"] . "</td>"; echo "<td class='center'>" . $data["gateway"] . "</td>"; echo "<td class='center'>" . $data["metric"] . "</td>"; echo "<td class='center'>" . $data["interface"] . "</td>"; echo "<td class='center'>" . Dropdown::getYesNo($data["persistence"]) . "</td>"; echo "<td class='center'>" . $data["comment"] . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show domains associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated domains 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 (!plugin_domains_haveRight('domains', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginDomainsDomain'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_domains_domains_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_domains_domains`.`name` AS assocName,\n `glpi_plugin_domains_domains`.*\n FROM `glpi_plugin_domains_domains_items`\n LEFT JOIN `glpi_plugin_domains_domains`\n ON (`glpi_plugin_domains_domains_items`.`plugin_domains_domains_id`=`glpi_plugin_domains_domains`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_domains_domains`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_domains_domains_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_domains_domains_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_domains_domains", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $domains = array(); $domain = new PluginDomainsDomain(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $domains[$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_plugin_domains_domains", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_domains_domains`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_domains_haveRight('domains', 'r') && $nb > count($used)) { echo "<form name='domain_form{$rand}' id='domain_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginDomainsDomain') . "'>"; 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}'>"; } $domain->dropdownDomains("plugin_domains_domains_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a domain', 'domains') . "\" 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>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Group in charge of the hardware') . "</th>"; echo "<th>" . __('Supplier') . "</th>"; echo "<th>" . __('Technician in charge of the hardware') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginDomainsDomain', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($domains as $data) { $domainID = $data["id"]; $link = NOT_AVAILABLE; if ($domain->getFromDB($domainID)) { $link = $domain->getLink(); } Session::addToNavigateListItems('PluginDomainsDomain', $domainID); $used[$domainID] = $domainID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . "</td>"; echo "<td>"; echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/enterprise.form.php?ID=" . $data["suppliers_id"] . "\">"; echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]); if ($_SESSION["glpiis_ids_visible"] == 1) { echo " (" . $data["suppliers_id"] . ")"; } echo "</a></td>"; echo "<td class='center'>" . getUsername($data["users_id_tech"]) . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_domains_domaintypes", $data["plugin_domains_domaintypes_id"]) . "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'><div class='deleted'>" . convdate($data["date_expiration"]) . "</div></td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Does not expire', 'domains') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show accounts associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated accounts 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 (!Session::haveRight("plugin_accounts", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginAccountsAccount'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $who = Session::getLoginUserID(); if (count($_SESSION["glpigroups"]) && Session::haveRight("plugin_accounts_my_groups", 1)) { $first_groups = true; $groups = ""; foreach ($_SESSION['glpigroups'] as $val) { if (!$first_groups) { $groups .= ","; } else { $first_groups = false; } $groups .= "'" . $val . "'"; } $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') "; } else { // Only personal ones $ASSIGN = " `users_id` = '{$who}' "; } $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_accounts_accounts`.`name` AS assocName,\n `glpi_plugin_accounts_accounts`.*\n FROM `glpi_plugin_accounts_accounts_items`\n LEFT JOIN `glpi_plugin_accounts_accounts`\n ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true); if (!Session::haveRight("plugin_accounts_see_all_users", 1)) { $query .= " AND {$ASSIGN} "; } $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $accounts = array(); $account = new PluginAccountsAccount(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $accounts[$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_plugin_accounts_accounts", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_accounts_accounts`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (Session::haveRight('plugin_accounts', READ) && $nb > count($used)) { echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>"; 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}'>"; } PluginAccountsAccount::dropdownAccount(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" 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($massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //hash $hashclass = new PluginAccountsHash(); $hash = 0; $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive()); $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict); if (!empty($hashes)) { foreach ($hashes as $hashe) { $hash = $hashe["hash"]; $hash_id = $hashe["id"]; } $alert = ''; } else { $alert = __('There is no encryption key for this entity', 'accounts'); } $aeskey = new PluginAccountsAesKey(); echo "<tr><th colspan='" . (8 + $colsup) . "'>"; if ($hash) { if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) { _e('Encryption key', 'accounts'); echo "<input type='password' name='aeskey' id='aeskey' autocomplete='off'>"; } else { echo Html::hidden('aeskey', array('value' => $aeskey->fields["name"], 'id' => 'aeskey', 'autocomplete' => 'off')); } } else { echo __('Encryption key', 'accounts'); echo "<div class='red'>"; echo $alert; echo "</div>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Login') . "</th>"; echo "<th>" . __('Password') . "</th>"; echo "<th>" . __('Affected User', 'accounts') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($accounts as $data) { $accountID = $data["id"]; $link = NOT_AVAILABLE; if ($account->getFromDB($accountID)) { $link = $account->getLink(); } Session::addToNavigateListItems('PluginAccountsAccount', $accountID); $used[$accountID] = $accountID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["login"] . "</td>"; echo "<td class='center'>"; //hash if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) { echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off')); echo "<input type='text' id='hidden_password{$accountID}' value='' size='30' >"; echo Html::scriptBlock("\n if (!check_hash()) {\n \$('#hidden_password{$accountID}')\n .after('" . __('Wrong encryption key', 'accounts') . "')\n .remove();\n } else {\n decrypt_password('{$accountID}');\n }\n "); } else { $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php"; echo " <input type='button' id='decrypt_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n class='submit'>"; echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off')); echo Html::scriptBlock("\$(document).on('click', '#decrypt_link{$accountID}', function(event) {\n if (!check_hash()) {\n alert('" . __('Wrong encryption key', 'accounts') . "');\n } else {\n var decrypted_password = decrypt_password('{$accountID}');\n \$('#decrypt_link{$accountID}')\n .after(decrypted_password)\n .remove();\n }\n });"); } echo "</td>"; echo "<td class='center'>"; echo getUsername($data["users_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]); echo "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>"; echo "</td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; echo Html::hidden('good_hash', array('value' => $hash, 'id' => 'good_hash')); if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * 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>"; }
function showForm(CommonDBTM $item, $options = array()) { $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } $rand = mt_rand(); $a_data = getAllDatasFromTable('glpi_plugin_fusioninventory_ipranges_configsecurities', "`plugin_fusioninventory_ipranges_id`='" . $item->getID() . "'", false, '`rank`'); $a_used = array(); foreach ($a_data as $data) { $a_used[] = $data['plugin_fusioninventory_configsecurities_id']; } echo "<div class='firstbloc'>"; echo "<form name='iprange_configsecurity_form{$rand}' id='iprange_configsecurity_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginFusioninventoryIPRange_ConfigSecurity') . "' >"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'>"; echo "<th colspan='2'>" . __('Add a SNMP authentication') . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>"; Dropdown::show('PluginFusioninventoryConfigSecurity', array('used' => $a_used)); echo "</td>"; echo "<td>"; echo Html::hidden('plugin_fusioninventory_ipranges_id', array('value' => $item->getID())); echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; // Display list of auth associated with IP range $rand = mt_rand(); echo "<div class='spaced'>"; Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'>"; echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; echo "<th>"; echo __('SNMP Authentication', 'fusioninventory'); echo "</th>"; echo "<th>"; echo __('Version', 'fusioninventory'); echo "</th>"; echo "<th>"; echo __('Rank'); echo "</th>"; echo "</tr>"; $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); foreach ($a_data as $data) { echo "<tr class='tab_bg_2'>"; echo "<td>"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "</td>"; echo "<td>"; $pfConfigSecurity->getFromDB($data['plugin_fusioninventory_configsecurities_id']); echo $pfConfigSecurity->getLink(); echo "</td>"; echo "<td>"; echo $pfConfigSecurity->getSNMPVersion($pfConfigSecurity->fields['snmpversion']); echo "</td>"; echo "<td>"; echo $data['rank']; echo "</td>"; echo "</tr>"; } echo "</table>"; $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); echo "</div>"; }
/** * Show shellcommands associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated shellcommands 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 (!self::canView()) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $width = 200; $canedit = $item->canadditem('PluginShellcommandsShellcommand'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_shellcommands_shellcommands_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_shellcommands_shellcommands`.`name` AS assocName,\n `glpi_plugin_shellcommands_shellcommands`.*\n FROM `glpi_plugin_shellcommands_shellcommands_items`\n LEFT JOIN `glpi_plugin_shellcommands_shellcommands`\n ON (`glpi_plugin_shellcommands_shellcommands_items`.`plugin_shellcommands_shellcommands_id`=`glpi_plugin_shellcommands_shellcommands`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_shellcommands_shellcommands`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_shellcommands_shellcommands_items`.`itemtype` = '" . $item->getType() . "' \n AND !`glpi_plugin_shellcommands_shellcommands`.`is_deleted`"; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_shellcommands", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $shells = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $shells[$data['assocID']] = $data; } } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>" . __('Associated Commands', 'shellcommands') . "</th>"; echo "</tr>"; if ($number) { Session::initNavigateListItems('PluginShellcommandsShellcommand', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); $selectCommandName[0] = Dropdown::EMPTY_VALUE; // $countCommand = self::countForItem($item, array('type' => 'ALL')); foreach ($shells as $data) { // if(isset($countCommand[$data['link'].$data['id']])) $selectCommandName[$data['link'] . '-' . $data['id']] = $data['assocName']; } echo "<tr class='tab_bg_2'>\n <td class='center'>" . PluginShellcommandsShellcommand::getTypeName(1) . " "; $randSelect = Dropdown::showFromArray("name", $selectCommandName, array('width' => $width)); echo "<span id='command_name{$randSelect}'></span></td>"; echo "</tr>"; Ajax::updateItemOnSelectEvent("dropdown_name{$randSelect}", "command_name{$randSelect}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownCommandValue.php", array('idtable' => $item->getType(), 'width' => $width, 'value' => '__VALUE__', 'itemID' => $ID, 'countItem' => 1, 'itemtype' => $item->getType(), 'toupdate' => 'shellcommand_result', 'command_type' => 'PluginShellcommandsShellcommand', 'myname' => "command_name")); } echo "</table>"; echo "</div>"; echo "<div class='spaced' id='shellcommand_result'></div>"; }
/** * Show Links for an item * * @param $item CommonDBTM object * @param $withtemplate integer withtemplate param (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; if (!Session::haveRight("link", "r")) { return false; } if ($item->isNewID($item->getID())) { return false; } $query = "SELECT `glpi_links`.`id`,\n `glpi_links`.`link` AS link,\n `glpi_links`.`name` AS name ,\n `glpi_links`.`data` AS data\n FROM `glpi_links`\n INNER JOIN `glpi_links_itemtypes`\n ON `glpi_links`.`id` = `glpi_links_itemtypes`.`links_id`\n WHERE `glpi_links_itemtypes`.`itemtype`='" . $item->getType() . "' " . getEntitiesRestrictRequest(" AND", "glpi_links", "entities_id", $item->getEntityID(), true) . "\n ORDER BY name"; $result = $DB->query($query); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if ($DB->numrows($result) > 0) { echo "<tr><th>" . self::getTypeName(2) . "</th></tr>"; while ($data = $DB->fetch_assoc($result)) { $name = $data["name"]; if (empty($name)) { $name = $data["link"]; } $names = self::generateLinkContents($name, $item); $file = trim($data["data"]); if (empty($file)) { // Generate links $links = self::generateLinkContents($data['link'], $item); $i = 1; foreach ($links as $key => $link) { $name = isset($names[$key]) ? $names[$key] : reset($names); echo "<tr class='tab_bg_2'>"; $url = $link; echo "<td class='center'><a href='{$url}' target='_blank'>"; $linkname = sprintf(__('%1$s #%2$s'), $name, $i); $linkname = printf(__('%1$s: %2$s'), $linkname, $link); echo "</a></td></tr>"; $i++; } } else { // Generate files $files = self::generateLinkContents($data['link'], $item); $links = self::generateLinkContents($data['data'], $item); $i = 1; foreach ($links as $key => $link) { $name = isset($names[$key]) ? $names[$key] : reset($names); if (isset($files[$key])) { // a different name for each file, ex name = foo-[IP].txt $file = $files[$key]; } else { // same name for all files, ex name = foo.txt $file = reset($files); } echo "<tr class='tab_bg_2'>"; $url = $CFG_GLPI["root_doc"] . "/front/link.send.php?lID=" . $data['id'] . "&itemtype=" . $item->getType() . "&id=" . $item->getID() . "&rank={$key}"; echo "<td class='center'><a href='{$url}' target='_blank'>"; $linkname = sprintf(__('%1$s #%2$s'), $name, $i); $linkname = printf(__('%1$s: %2$s'), $linkname, $file); echo "</a></td></tr>"; $i++; } } } echo "</table></div>"; } else { echo "<tr class='tab_bg_2'><th>" . self::getTypeName(2) . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='center b'>" . __('No link defined') . "</td></tr>"; echo "</table></div>"; } }
/** * Show documents associated to an item * * @param $item CommonDBTM object for which associated documents must be displayed * @param $withtemplate **/ static function showAssociated(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if ($item->getType() != 'Ticket' && $item->getType() != 'KnowbaseItem' && !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->can($ID, 'w'); $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 (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 (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; if ($withtemplate != 2) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/document.form.php\" enctype=\"multipart/form-data\">"; } echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 0) { echo $LANG['document'][17]; } else { if ($DB->numrows($result) == 1) { echo $LANG['document'][21]; } else { echo $LANG['document'][20]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['document'][2] . "</th>"; echo "<th>" . $LANG['document'][33] . "</th>"; echo "<th>" . $LANG['document'][3] . "</th>"; echo "<th>" . $LANG['document'][4] . "</th>"; if ($withtemplate < 2) { echo "<th> </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') { initNavigateListItems('Document', $item->getTypeName() . " = " . $item->getName()); } $document = new Document(); while ($data = $DB->fetch_assoc($result)) { $docID = $data["id"]; $link = NOT_AVAILABLE; $downloadlink = NOT_AVAILABLE; if ($document->getFromDB($docID)) { $link = $document->getLink(); $downloadlink = $document->getDownloadLink($linkparam); } if ($item->getType() != 'Document') { addToNavigateListItems('Document', $docID); } $used[$docID] = $docID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; 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 " "; } echo "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_documentcategories", $data["documentcategories_id"]); echo "</td>"; echo "<td class='center'>" . $data["mime"] . "</td>"; if ($withtemplate < 2) { echo "<td class='tab_bg_2 center b'>"; if ($canedit && $_SESSION["glpiactiveprofile"]["interface"] != 'helpdesk') { echo "<a href='" . $CFG_GLPI["root_doc"]; echo "/front/document.form.php?deletedocumentitem=1&id={$assocID}"; echo "&itemtype=" . $item->getType() . "&items_id={$ID}&documents_id={$docID}'>"; echo $LANG['buttons'][6] . "</a>"; } else { echo " "; } echo "</td>"; } echo "</tr>"; $i++; } } if ($canedit) { // hack for ticket || get_class($item)=='Ticket') { // Restrict entity for knowbase $entities = ""; $entity = $_SESSION["glpiactive_entity"]; if ($item->isEntityAssign()) { $entity = $item->getEntityID(); if ($item->isRecursive()) { $entities = getSonsOf('glpi_entities', $entity); } else { $entities = $entity; } } if ($withtemplate < 2) { $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); echo "<tr class='tab_bg_1'><td class='center' colspan='3'>"; 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='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>"; echo "<input type='hidden' name='tickets_id' value='{$ID}'>"; } echo "<input type='file' name='filename' size='25'> "; echo "(" . self::getMaxUploadSize() . ") "; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td>"; if ($item->getType() == 'Document') { $used[$ID] = $ID; } if (haveRight('document', 'r') && $nb > count($used)) { echo "<td class='left' colspan='2'>"; self::dropdown(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center'>"; echo "<input type='submit' name='adddocumentitem' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td><td> </td>"; } else { echo "<td colspan='4'> </td>"; } echo "</tr>"; } } echo "</table></form></div>"; }
/** * Show webapplications associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated webapplications 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 (!Session::haveRight("plugin_webapplications", READ)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginWebapplicationsWebapplication'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_webapplications_webapplications_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n `glpi_plugin_webapplications_webapplications`.*\n FROM `glpi_plugin_webapplications_webapplications_items`\n LEFT JOIN `glpi_plugin_webapplications_webapplications`\n ON (`glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id`=`glpi_plugin_webapplications_webapplications`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_webapplications_webapplications_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_webapplications_webapplications_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $webs = array(); $web = new PluginWebapplicationsWebapplication(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $webs[$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_plugin_webapplications_webapplications", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_webapplications_webapplications`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (Session::haveRight("plugin_webapplications", READ) && $nb > count($used)) { echo "<form name='webapplication_form{$rand}' id='webapplication_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginWebapplicationsWebapplication') . "'>"; 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}'>"; } PluginWebapplicationsWebapplication::dropdownWebapplication(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a web application', 'webapplications') . "\" 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($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>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>"; echo "<th>" . __('URL') . "</th>"; echo "<th>" . __('Server') . "</th>"; echo "<th>" . __('Language') . "</th>"; echo "<th>" . __('Version') . "</th>"; echo "<th>" . __('Comments') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginWebapplicationsWebapplication', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($webs as $data) { $webID = $data["id"]; $link = NOT_AVAILABLE; if ($web->getFromDB($webID)) { $link = $web->getLink(); } Session::addToNavigateListItems('PluginWebapplicationsWebapplication', $webID); $used[$webID] = $webID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtypes", $data["plugin_webapplications_webapplicationtypes_id"]) . "</td>"; $link = Toolbox::substr($data["address"], 0, 30) . "..."; echo "<td class='center'>" . "<a href=\"" . str_replace("&", "&", $data["address"]) . "\" target=\"_blank\">" . "<u>" . $link . "</u></a></td>"; echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationservertypes", $data["plugin_webapplications_webapplicationservertypes_id"]) . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtechnics", $data["plugin_webapplications_webapplicationtechnics_id"]) . "</td>"; echo "<td>" . $data["version"] . "</td>"; echo "<td>" . $data["comment"] . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show accounts associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated accounts 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 (!plugin_accounts_haveRight('accounts', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginAccountsAccount'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $who = Session::getLoginUserID(); if (count($_SESSION["glpigroups"]) && plugin_accounts_haveRight("my_groups", "r")) { $first_groups = true; $groups = ""; foreach ($_SESSION['glpigroups'] as $val) { if (!$first_groups) { $groups .= ","; } else { $first_groups = false; } $groups .= "'" . $val . "'"; } $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') "; } else { // Only personal ones $ASSIGN = " `users_id` = '{$who}' "; } $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_accounts_accounts`.`name` AS assocName,\n `glpi_plugin_accounts_accounts`.*\n FROM `glpi_plugin_accounts_accounts_items`\n LEFT JOIN `glpi_plugin_accounts_accounts`\n ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true); if (!plugin_accounts_haveRight("all_users", "r")) { $query .= " AND {$ASSIGN} "; } $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $accounts = array(); $account = new PluginAccountsAccount(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $accounts[$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_plugin_accounts_accounts", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_accounts_accounts`\n WHERE `is_deleted` = '0'\n {$limit}"; $result = $DB->query($q); $nb = $DB->result($result, 0, 0); echo "<div class='firstbloc'>"; if (plugin_accounts_haveRight('accounts', 'r') && $nb > count($used)) { echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>"; 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}'>"; } $account->dropdownAccounts("plugin_accounts_accounts_id", $entities, $used); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" 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'>"; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } //hash $hashclass = new PluginAccountsHash(); $hash = 0; $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive()); $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict); if (!empty($hashes)) { foreach ($hashes as $hashe) { $hash = $hashe["hash"]; $hash_id = $hashe["id"]; } $alert = ''; } else { $alert = __('There is no encryption key for this entity', 'accounts'); } $aeskey = new PluginAccountsAesKey(); if ($hash) { if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) { echo "<tr><th colspan='" . (8 + $colsup) . "'>"; _e('Encryption key', 'accounts'); echo "<input type='password' name='aescrypted_key' id= 'aescrypted_key' autocomplete='off'>"; echo "</th></tr>"; } } else { echo "<tr><th colspan='" . (8 + $colsup) . "'>"; echo __('Encryption key', 'accounts') . "<div class='red'>"; echo $alert; echo "</div>"; echo "</th></tr>"; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Login') . "</th>"; echo "<th>" . __('Password') . "</th>"; echo "<th>" . __('Affected User', 'accounts') . "</th>"; echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Creation date') . "</th>"; echo "<th>" . __('Expiration date') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($accounts as $data) { $accountID = $data["id"]; $link = NOT_AVAILABLE; if ($account->getFromDB($accountID)) { $link = $account->getLink(); } Session::addToNavigateListItems('PluginAccountsAccount', $accountID); $used[$accountID] = $accountID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>" . $data["login"] . "</td>"; echo "<td class='center'>"; //hash if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) { echo "<input type='hidden' name='aeskey' id= 'aeskey'\n value='" . $aeskey->fields["name"] . "' class='' autocomplete='off'>"; echo "<input type='hidden' autocomplete='off'\n name='encrypted_password\${$accountID}' value='" . $data["encrypted_password"] . "'>"; echo "<input type='text' name='hidden_password\${$accountID}' value='' size='30' >"; echo "<script language='javascript'>\n var good_hash=\"{$hash}\";\n var hash=SHA256(SHA256(document.getElementById(\"aeskey\").value));\n if (hash != good_hash) {\n document.getElementsByName(\"hidden_password\${$accountID}\").\n item(0).value=\"" . __s('Wrong encryption key', 'accounts') . "\";\n } else {\n document.getElementsByName(\"hidden_password\${$accountID}\").\n item(0).value=AESDecryptCtr(document.getElementsByName(\"encrypted_password\${$accountID}\").\n item(0).value,SHA256(document.getElementById(\"aeskey\").value), 256)};</script>"; } else { $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php"; echo " <input type='button' id='decrypte_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n class='submit' onclick='return false;'>"; echo "<script type='text/javascript'>\n Ext.get('decrypte_link{$accountID}').on('click', function () {\n\n Ext.Ajax.request({\n url: '../plugins/accounts/ajax/get_new_crsf_token.php',\n success: function(response, opts) {\n var token = response.responseText;\n Ext.select('#account_form input[name=_glpi_csrf_token]')\n .set({'value': token});\n\n },\n failure: function(response, opts) {\n console.log('server-side failure with status code ' + response.status);\n }\n });\n\n var good_hash=\"{$hash}\";\n var hash=SHA256(SHA256(document.getElementById(\"aescrypted_key\").value));\n if (hash != good_hash) {\n alert(\"" . __('Wrong encryption key', 'accounts') . "\");\n return false;\n };\n alert(AESDecryptCtr(\"" . $data['encrypted_password'] . "\",\n SHA256(document.getElementById(\"aescrypted_key\").value),\n 256));\n\n callAjax(\"{$url}\",\n \"{$accountID}\" ,\n document.getElementsByName(\"name\").item(0).value,\n document.getElementsByName(\"_glpi_csrf_token\").item(0).value);\n\n });\n </script>"; } echo "</td>"; echo "<td class='center'>"; echo getUsername($data["users_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]); echo "</td>"; echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>"; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) { echo "<td class='center'>"; echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>"; echo "</td>"; } else { if (empty($data["date_expiration"])) { echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>"; } else { echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Display tickets for an item * * Will also display tickets of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRightsOr(self::$rightname, array(self::READALL, self::READMY, self::READASSIGN, CREATE))) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "' " . " AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['reset'] = 'reset'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'SLT': $restrict = "`slts_tto_id` = '" . $item->getID() . "'\n OR `slts_ttr_id` = '" . $item->getID() . "'"; $order = '`glpi_tickets`.`due_date` DESC'; $options['criteria'][0]['field'] = 30; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Supplier': $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "' " . " AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last tickets') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Child groups') . " "; Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}" . " AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`glpi_items_tickets`.`items_id` = '" . $item->getID() . "' " . " AND `glpi_items_tickets`.`itemtype` = '" . $item->getType() . "')"; // you can only see your tickets if (!Session::haveRight(self::$rightname, self::READALL)) { $restrict .= " AND (`glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'\n OR (`glpi_tickets_users`.`tickets_id` = '" . $item->getID() . "'\n AND `glpi_tickets_users`.`users_id`\n = '" . Session::getLoginUserID() . "'))"; } $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $item->getType(); $options['metacriteria'][0]['field'] = Search::getOptionNumber($item->getType(), 'id'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $item->getID(); $options['metacriteria'][0]['link'] = 'AND'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } // Ticket for the item echo "<div class='firstbloc'>"; // Link to open a new ticket if ($item->getID() && Ticket::isPossibleToAssignType($item->getType()) && self::canCreate()) { Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('itemtype' => $item->getType(), 'items_id' => $item->getID())); } echo "</div><div>"; if ($number > 0) { echo "<table class='tab_cadre_fixehov'>"; if (Session::haveRight(self::$rightname, self::READALL)) { Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr class='noHover'><th colspan='{$colspan}'>"; $title = sprintf(_n('Last %d ticket', 'Last %d tickets', $number), $number); $link = "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&') . "'>" . __('Show all') . "</a>"; $title = printf(__('%1$s (%2$s)'), $title, $link); echo "</th></tr>"; } else { echo "<tr><th colspan='{$colspan}'>" . __("You don't have right to see all tickets") . "</th></tr>"; } } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } if ($item->getID() && $item->getType() == 'User' && self::canCreate()) { echo "<tr><td class='tab_bg_2 center b' colspan='{$colspan}'>"; Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('_users_id_requester' => $item->getID())); echo "</td></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Ticket', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`glpi_items_tickets`.`itemtype` = '{$ltype}' AND `glpi_items_tickets`.`items_id` = '{$lID}')"; } } } if (count($restrict) && Session::haveRight(self::$rightname, self::READALL)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n ORDER BY `glpi_tickets`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='12'>"; echo _n('Ticket on linked items', 'Tickets on linked items', $number); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Show rack associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated rack must be displayed * @param $withtemplate (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $item->getField('id'); if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginRacksRack'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $itemtype = $item->getType() . "Model"; $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n `glpi_plugin_racks_racks_items`.`faces_id`,\n `glpi_plugin_racks_racks_items`.`position`,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_racks_racks`.`name` AS assocName,\n `glpi_plugin_racks_racks`.*\n FROM `glpi_plugin_racks_racks_items`\n LEFT JOIN `glpi_plugin_racks_racks`\n ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $racks = array(); $rack = new PluginRacksRack(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $racks[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number); Html::showMassiveActions($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>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Disposition', 'racks') . "</th>"; echo "<th>" . __('Position', 'racks') . "</th>"; echo "<th>" . __('Location') . "</th>"; echo "<th>" . __('Place', 'racks') . "</th>"; echo "<th>" . __('Manufacturer') . "</th>"; echo "</tr>"; $used = array(); if ($number) { Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($racks as $data) { $rackID = $data["id"]; $link = NOT_AVAILABLE; if ($rack->getFromDB($rackID)) { $link = $rack->getLink(); } Session::addToNavigateListItems('PluginRacksRack', $rackID); $used[$rackID] = $rackID; $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>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) { $faces_id = __('Front', 'racks'); } else { $faces_id = _x('Rack enclosure', 'Back', 'racks'); } echo "<td class='center'>" . $faces_id . "</td>"; echo "<td class='center'>" . $data["position"] . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>"; echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show Links for an item * * @param $item CommonDBTM object * @param $withtemplate integer withtemplate param (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; if (!self::canView()) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = $item->getEntityID(); if ($item->getType() == 'User') { $restrict = Profile_User::getEntitiesForUser($item->getID()); } $query = "SELECT `glpi_links`.`id`,\n `glpi_links`.`link` AS link,\n `glpi_links`.`name` AS name ,\n `glpi_links`.`data` AS data,\n `glpi_links`.`open_window` AS open_window\n FROM `glpi_links`\n INNER JOIN `glpi_links_itemtypes`\n ON `glpi_links`.`id` = `glpi_links_itemtypes`.`links_id`\n WHERE `glpi_links_itemtypes`.`itemtype`='" . $item->getType() . "' " . getEntitiesRestrictRequest(" AND", "glpi_links", "entities_id", $restrict, true) . "\n ORDER BY name"; $result = $DB->query($query); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if ($DB->numrows($result) > 0) { echo "<tr><th>" . self::getTypeName(Session::getPluralNumber()) . "</th></tr>"; while ($data = $DB->fetch_assoc($result)) { $links = self::getAllLinksFor($item, $data); foreach ($links as $link) { echo "<tr class='tab_bg_2'>"; echo "<td class='center'>{$link}</td></tr>"; } } echo "</table></div>"; } else { echo "<tr class='tab_bg_2'><th>" . self::getTypeName(Session::getPluralNumber()) . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='center b'>" . __('No link defined') . "</td></tr>"; echo "</table></div>"; } }
/** * Show shellcommands associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated shellcommands 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 (!self::canView()) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $width = 200; $command_group = new PluginShellcommandsCommandGroup(); $restrict = getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_commandgroups", '', '', true); $data = $command_group->find("1" . $restrict); $shells = array(0 => Dropdown::EMPTY_VALUE); if (!empty($data)) { foreach ($data as $val) { $shells['[IP]-' . $val['id'] . '-0'] = $val['name']; } } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>" . PluginShellcommandsCommandGroup::getTypeName(1) . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_2'>\n <td class='center'>" . PluginShellcommandsCommandGroup::getTypeName(1) . " "; $randSelect = Dropdown::showFromArray("name", $shells, array('width' => $width)); echo "<span id='command_name{$randSelect}'></span></td>"; echo "</tr>"; Ajax::updateItemOnSelectEvent("dropdown_name{$randSelect}", "command_name{$randSelect}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownCommandValue.php", array('idtable' => $item->getType(), 'value' => '__VALUE__', 'itemID' => $ID, 'countItem' => 1, 'width' => $width, 'command_type' => 'PluginShellcommandsCommandGroup', 'toupdate' => 'command_group_result', 'itemtype' => $item->getType(), 'myname' => "command_ip")); echo "</table>"; echo "</div>"; echo "<div class='spaced' id='command_group_result'></div>"; }