/** * Show holidays for a calendar * * @param $calendar Calendar object **/ static function showForCalendar(Calendar $calendar) { global $DB, $CFG_GLPI, $LANG; $ID = $calendar->getField('id'); if (!$calendar->can($ID, 'r')) { return false; } $canedit = $calendar->can($ID, 'w'); $rand = mt_rand(); echo "<form name='calendarholiday_form{$rand}' id='calendarholiday_form{$rand}' method='post'\n action='"; echo getItemTypeFormURL(__CLASS__) . "'>"; echo "<div class='center'><table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='2'>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['buttons'][33] . "</th>"; echo "<th>" . $LANG['buttons'][32] . "</th>"; echo "<th>" . $LANG['calendar'][3] . "</th>"; echo "</tr>"; $query = "SELECT DISTINCT `glpi_calendars_holidays`.`id` AS linkID,\n `glpi_holidays`.*\n FROM `glpi_calendars_holidays`\n LEFT JOIN `glpi_holidays`\n ON (`glpi_calendars_holidays`.`holidays_id` = `glpi_holidays`.`id`)\n WHERE `glpi_calendars_holidays`.`calendars_id` = '{$ID}'\n ORDER BY `glpi_holidays`.`name`"; $result = $DB->query($query); $used = array(); if ($DB->numrows($result) > 0) { initNavigateListItems('Holiday', $LANG['buttons'][15] . " = " . $calendar->fields["name"]); while ($data = $DB->fetch_array($result)) { addToNavigateListItems('Holiday', $data["id"]); echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; if ($canedit) { echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1'>"; } else { echo " "; } echo "</td>"; $used[] = $data['id']; echo "<td><a href='" . getItemTypeFormURL('Holiday') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>"; echo "<td>" . convDate($data["begin_date"]) . "</td>"; echo "<td>" . convDate($data["end_date"]) . "</td>"; echo "<td>" . Dropdown::getYesNo($data["is_perpetual"]) . "</td>"; echo "</tr>"; } } if ($canedit) { echo "<tr class='tab_bg_2'><td class='right' colspan='4'>"; echo "<input type='hidden' name='calendars_id' value='{$ID}'>"; Dropdown::show('Holiday', array('used' => $used, 'entity' => $calendar->fields["entities_id"])); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>"; } echo "</table></div>"; if ($canedit) { openArrowMassive("calendarholiday_form{$rand}", true); closeArrowMassive('delete', $LANG['buttons'][6]); } echo "</form>"; }
function showForSLA(SLA $sla) { global $DB, $CFG_GLPI, $LANG; $ID = $sla->getField('id'); if (!$sla->can($ID, 'r')) { return false; } $canedit = $sla->can($ID, 'w'); $rand = mt_rand(); echo "<form name='slalevel_form{$rand}' id='slalevel_form{$rand}' method='post' action='"; echo getItemTypeFormURL(__CLASS__) . "'>"; if ($canedit) { echo "<div class='center first-bloc'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['sla'][4] . "</tr>"; echo "<tr class='tab_bg_2'><td class='center'>" . $LANG['common'][16] . " : "; echo "<input type='hidden' name='slas_id' value='{$ID}'>"; echo "<input type='hidden' name='entities_id' value='" . $sla->getEntityID() . "'>"; echo "<input type='hidden' name='is_recursive' value='" . $sla->isRecursive() . "'>"; echo "<input name='name' value=''>"; echo "</td><td class='center'>" . $LANG['sla'][3] . " : "; self::dropdownExecutionTime('execution_time', array('max_time' => $sla->fields['resolution_time'], 'used' => self::getAlreadyUsedExecutionTime($sla->fields['id']))); echo "</td><td class='center'>" . $LANG['common'][60] . " : "; Dropdown::showYesNo("is_active", array('value' => 1)); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>"; echo "</table></div>"; $query = "SELECT *\n FROM `glpi_slalevels`\n WHERE `slas_id` = '{$ID}'\n ORDER BY `execution_time`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { echo "<div class='center'><table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='2'>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['sla'][3] . "</th>"; echo "<th>" . $LANG['common'][60] . "</th>"; echo "</tr>"; initNavigateListItems('SlaLevel', $LANG['sla'][1] . " - " . $sla->getName()); while ($data = $DB->fetch_array($result)) { addToNavigateListItems('SlaLevel', $data["id"]); echo "<tr class='tab_bg_2'>"; echo "<td width='10'>"; if ($canedit) { echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>"; } else { echo " "; } echo "</td>"; echo "<td>"; if ($canedit) { echo "<a href='" . getItemTypeFormURL('SlaLevel') . "?id=" . $data["id"] . "'>"; } echo $data["name"]; if (empty($data["name"])) { echo "(" . $data['id'] . ")"; } if ($canedit) { echo "</a>"; } echo "</td>"; echo "<td>" . ($data["execution_time"] != 0 ? timestampToString($data["execution_time"], false) : $LANG['sla'][5]) . "</td>"; echo "<td>" . Dropdown::getYesNo($data["is_active"]) . "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'><td colspan='4'>"; $this->getRuleWithCriteriasAndActions($data['id'], 0, 1); $this->showActionsList($data["id"], array('readonly' => true)); echo "</td></tr>"; } openArrowMassive("slalevel_form{$rand}", true); closeArrowMassive('delete', $LANG['buttons'][6]); echo "</table></div>"; } } echo "</form>"; }
function showSummary(NotificationTemplate $template, $options = array()) { global $DB, $LANG, $CFG_GLPI; $nID = $template->getField('id'); $canedit = haveRight("config", "w"); if ($canedit) { echo "<div class='center'>" . "<a href='" . getItemTypeFormURL('NotificationTemplateTranslation') . "?notificationtemplates_id=" . $nID . "'>" . $LANG['mailing'][124] . "</a></div><br>"; } echo "<div class='center' id='tabsbody'>"; initNavigateListItems('NotificationTemplateTranslation', $template->getTypeName() . " = " . $template->fields["name"]); echo "<form name='form_language' id='form_language' method='post'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th></th><th>" . $LANG['setup'][41] . "</th></tr>"; foreach ($DB->request('glpi_notificationtemplatetranslations', array('notificationtemplates_id' => $nID)) as $data) { if ($this->getFromDB($data['id'])) { addToNavigateListItems('NotificationTemplateTranslation', $data['id']); echo "<tr class='tab_bg_1'><td class='center'>"; echo "<input type='checkbox' name=\"languages[" . $data['id'] . "]\"></td>"; echo "<td class='center'>"; echo "<a href='" . getItemTypeFormURL('NotificationTemplateTranslation') . "?id=" . $data['id'] . "¬ificationtemplates_id=" . $nID . "'>"; if ($data['language'] != '') { echo $CFG_GLPI['languages'][$data['language']][0]; } else { echo $LANG['mailing'][125]; } echo "</a></td></tr>"; } } echo "</table>"; if ($canedit) { openArrowMassive("form_language", true); closeArrowMassive("delete_languages", $LANG["buttons"][6]); } }
/** * 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>"; }
/** *Print out list kb item * * @param $options : $_GET * @param $faq display on faq ? **/ static function showList($options, $faq = 0) { global $DB, $LANG, $CFG_GLPI; // Default values of parameters $params["start"] = "0"; $params["knowbaseitemcategories_id"] = "0"; $params["contains"] = ""; $params["target"] = $_SERVER['PHP_SELF']; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } // Lists kb Items $where = ""; $order = ""; $score = ""; // Build query if (getLoginUserID()) { $where = getEntitiesRestrictRequest("", "glpi_knowbaseitems", "", "", true) . " AND "; } else { // Anonymous access if (isMultiEntitiesMode()) { $where = " (`glpi_knowbaseitems`.`entities_id` = '0'\n AND `glpi_knowbaseitems`.`is_recursive` = '1')\n AND "; } } if ($faq) { // helpdesk $where .= " (`glpi_knowbaseitems`.`is_faq` = '1')\n AND "; } // a search with $contains if (strlen($params["contains"]) > 0) { $search = unclean_cross_side_scripting_deep($params["contains"]); $score = " ,MATCH(glpi_knowbaseitems.question, glpi_knowbaseitems.answer)\n AGAINST('{$search}' IN BOOLEAN MODE) AS SCORE "; $where_1 = $where . " MATCH(glpi_knowbaseitems.question, glpi_knowbaseitems.answer)\n AGAINST('{$search}' IN BOOLEAN MODE) "; $order = "ORDER BY `SCORE` DESC"; // preliminar query to allow alternate search if no result with fulltext $query_1 = "SELECT COUNT(`id`)\n FROM `glpi_knowbaseitems`\n WHERE {$where_1}"; $result_1 = $DB->query($query_1); $numrows_1 = $DB->result($result_1, 0, 0); if ($numrows_1 <= 0) { // not result this fulltext try with alternate search $search1 = array('/\\\\"/', "/\\+/", "/\\*/", "/~/", "/</", "/>/", "/\\(/", "/\\)/", "/\\-/"); $contains = preg_replace($search1, "", $params["contains"]); $where .= " (`glpi_knowbaseitems`.`question` " . makeTextSearch($contains) . "\n OR `glpi_knowbaseitems`.`answer` " . makeTextSearch($contains) . ")"; } else { $where = $where_1; } } else { // no search -> browse by category $where .= " (`glpi_knowbaseitems`.`knowbaseitemcategories_id`\n = '" . $params["knowbaseitemcategories_id"] . "')"; $order = " ORDER BY `glpi_knowbaseitems`.`question` ASC"; } if (!$params["start"]) { $params["start"] = 0; } $query = "SELECT `glpi_knowbaseitems`.*,\n `glpi_knowbaseitemcategories`.`completename` AS category\n {$score}\n FROM `glpi_knowbaseitems`\n LEFT JOIN `glpi_knowbaseitemcategories`\n ON (`glpi_knowbaseitemcategories`.`id`\n = `glpi_knowbaseitems`.`knowbaseitemcategories_id`)\n WHERE {$where}\n {$order}"; // Get it from database if ($result = $DB->query($query)) { $KbCategory = new KnowbaseItemCategory(); $title = ""; if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) { $title = $LANG['common'][36] . " = " . (empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name']); } initNavigateListItems('KnowbaseItem', $title); $numrows = $DB->numrows($result); $list_limit = $_SESSION['glpilist_limit']; // Limit the result, if no limit applies, use prior result if ($numrows > $list_limit && !isset($_GET['export_all'])) { $query_limit = $query . " LIMIT " . intval($params["start"]) . ", " . intval($list_limit) . " "; $result_limit = $DB->query($query_limit); $numrows_limit = $DB->numrows($result_limit); } else { $numrows_limit = $numrows; $result_limit = $result; } if ($numrows_limit > 0) { // Set display type for export if define $output_type = HTML_OUTPUT; if (isset($_GET["display_type"])) { $output_type = $_GET["display_type"]; } // Pager $parameters = "start=" . $params["start"] . "&knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&contains=" . $params["contains"] . "&is_faq={$faq}"; if (isset($options['tickets_id'])) { $parameters .= "&tickets_id=" . $options['tickets_id']; } if ($output_type == HTML_OUTPUT) { printPager($params['start'], $numrows, getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } $nbcols = 1; // Display List Header echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols); $header_num = 1; echo Search::showHeaderItem($output_type, $LANG['knowbase'][14], $header_num); if ($output_type != HTML_OUTPUT) { echo Search::showHeaderItem($output_type, $LANG['knowbase'][15], $header_num); } echo Search::showHeaderItem($output_type, $LANG['common'][36], $header_num); if (isset($options['tickets_id']) && $output_type == HTML_OUTPUT) { echo Search::showHeaderItem($output_type, ' ', $header_num); } // Num of the row (1=header_line) $row_num = 1; for ($i = 0; $i < $numrows_limit; $i++) { $data = $DB->fetch_array($result_limit); addToNavigateListItems('KnowbaseItem', $data["id"]); // Column num $item_num = 1; $row_num++; echo Search::showNewLine($output_type, $i % 2); if ($output_type == HTML_OUTPUT) { if (isset($options['tickets_id'])) { $href = " href='#' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=show_kb&id=" . $data['id'] . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' );w.focus();\""; } else { $href = " href=\"" . $params['target'] . "?id=" . $data["id"] . "\" "; } echo Search::showItem($output_type, "<div class='kb'><a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " {$href}>" . resume_text($data["question"], 80) . "</a></div>\n <div class='kb_resume'>" . resume_text(html_clean(unclean_cross_side_scripting_deep($data["answer"])), 600) . "</div>", $item_num, $row_num); } else { echo Search::showItem($output_type, $data["question"], $item_num, $row_num); echo Search::showItem($output_type, html_clean(unclean_cross_side_scripting_deep(html_entity_decode($data["answer"], ENT_QUOTES, "UTF-8"))), $item_num, $row_num); } echo Search::showItem($output_type, $data["category"], $item_num, $row_num); if (isset($options['tickets_id']) && $output_type == HTML_OUTPUT) { $content = "<a href='" . $CFG_GLPI['root_doc'] . "/front/ticket.form.php?load_kb_sol=" . $data['id'] . "&id=" . $options['tickets_id'] . "&forcetab=4'>" . $LANG['job'][24] . "</a>"; echo Search::showItem($output_type, $content, $item_num, $row_num); } // End Line echo Search::showEndLine($output_type); } // Display footer if ($output_type == PDF_OUTPUT_LANDSCAPE || $output_type == PDF_OUTPUT_PORTRAIT) { echo Search::showFooter($output_type, Dropdown::getDropdownName("glpi_knowbaseitemcategories", $params['knowbaseitemcategories_id'])); } else { echo Search::showFooter($output_type); } echo "<br>"; if ($output_type == HTML_OUTPUT) { printPager($params['start'], $numrows, getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem'); } } else { if ($params["knowbaseitemcategories_id"] != 0) { echo "<div class='center b'>" . $LANG['search'][15] . "</div>"; } } } }
/** * Show the list of rules * * @param $target * @param $tab * @param $options * * @return nothing **/ function showListRules($target, $tab = 0, $options = array()) { global $CFG_GLPI, $LANG; $p['inherited'] = true; $p['childrens'] = false; $p['active'] = false; foreach (array('inherited', 'childrens') as $param) { if (isset($options[$param]) && $this->isRuleRecursive()) { $p[$param] = $options[$param]; } } $display_entities = $this->isRuleRecursive() && ($p['inherited'] || $p['childrens']); // Do not know what it is ? $canedit = haveRight($this->right, "w") && !$display_entities; $nb = $this->getCollectionSize($p['inherited']); $p['start'] = isset($options["start"]) ? $options["start"] : 0; if ($p['start'] >= $nb) { $p['start'] = 0; } $p['limit'] = $_SESSION['glpilist_limit']; $this->getCollectionPart($p); printAjaxPager('', $p['start'], $nb); echo "<form name='ruleactions_form' id='ruleactions_form' method='post'action='" . $target . "'>"; echo "\n<div class='spaced'>"; echo "<table class='tab_cadre_fixehov'>"; $colspan = 6; if ($display_entities) { $colspan++; } echo "<tr><th colspan='{$colspan}'>" . $this->getTitle() . "</th></tr>\n"; echo "<tr><th colspan='2'>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['joblist'][6] . "</th>"; echo "<th>" . $LANG['common'][60] . "</th>"; if ($display_entities) { echo "<th>" . $LANG['entity'][0] . "</th>\n"; } if (!$display_entities) { echo "<th colspan='2'> </th>"; } echo "</tr>\n"; if (count($this->RuleList->list)) { $ruletype = $this->RuleList->list[0]->getType(); initNavigateListItems($ruletype); } for ($i = $p['start'], $j = 0; isset($this->RuleList->list[$j]); $i++, $j++) { $this->RuleList->list[$j]->showMinimalForm($target, $i == 0, $i == $nb - 1, $display_entities); addToNavigateListItems($ruletype, $this->RuleList->list[$j]->fields['id']); } echo "</table>\n"; if ($canedit && $nb > 0) { openArrowMassive("ruleactions_form", true); echo "<select name='massiveaction' id='massiveaction'>"; echo "<option value='-1' selected>" . DROPDOWN_EMPTY_VALUE . "</option>"; echo "<option value='delete'>" . $LANG['buttons'][6] . "</option>"; if ($this->orderby == "ranking") { echo "<option value='move_rule'>" . $LANG['buttons'][20] . "</option>"; } echo "<option value='activate_rule'>" . $LANG['buttons'][41] . "</option>"; echo "</select>\n"; $params = array('action' => '__VALUE__', 'itemtype' => 'Rule', 'sub_type' => $this->getRuleClassName(), 'entity_restrict' => $this->entity); ajaxUpdateItemOnSelectEvent("massiveaction", "show_massiveaction", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveAction.php", $params); echo "<span id='show_massiveaction'> </span>\n"; if ($this->can_replay_rules) { echo "</td>"; // close td of openArrowMassive echo "<td><input type='submit' name='replay_rule' value='" . $LANG['rulesengine'][76] . "' class='submit'></td>"; echo "<td>"; // open td for closeArrowMassive } closeArrowMassive(); } echo "</div></form>"; echo "<div class='spaced center'><span class='icon_consol'>"; if ($plugin = isPluginItemType($this->getType())) { $url = $CFG_GLPI["root_doc"] . "/plugins/" . strtolower($plugin['plugin']); } else { $url = $CFG_GLPI["root_doc"]; } echo "<a href='#' onClick=\"var w=window.open('" . $url . "/front/popup.php?popup=test_all_rules&sub_type=" . $this->getRuleClassName() . "&' ,'glpipopup', 'height=400, width=1000, top=100, left=100, scrollbars=yes' );" . "w.focus();\">" . $LANG['rulesengine'][84] . "</a></span></div>"; echo "<div class='spaced'>"; $this->showAdditionalInformationsInForm($target); echo "</div>"; }
/** * Show software installed on a computer * * @param $comp Computer object * @param $withtemplate template case of the view process * * @return nothing **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; if (!haveRight("software", "r")) { return false; } $computers_id = $comp->getField('id'); $rand = mt_rand(); $canedit = haveRight("software", "w"); $entities_id = $comp->fields["entities_id"]; $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`name` AS softname,\n `glpi_computers_softwareversions`.`id`,\n `glpi_states`.`name` AS state,\n `glpi_softwareversions`.`id` AS verid,\n `glpi_softwareversions`.`softwares_id`,\n `glpi_softwareversions`.`name` AS version\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n ORDER BY `softwarecategories_id`, `softname`, `version`"; $result = $DB->query($query); $i = 0; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<tr class='tab_bg_1'><td class='center' colspan='3'>"; echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>"; echo $LANG['Menu'][4] . " : "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id); echo "<input type='submit' name='install' value=\"" . $LANG['buttons'][4] . "\" class='submit'>"; echo "</form>"; echo "</td>"; echo "<td class='cneter' clospan='2'>"; echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo $LANG['software'][11] . " : "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id); echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</form>"; echo "</td></tr>\n"; } echo "<tr><th colspan='5'>"; if ($DB->numrows($result) == 1) { echo $LANG['software'][16]; } else { echo $LANG['software'][17]; } echo "</th></tr>"; $cat = -1; initNavigateListItems('Software', $LANG['help'][25] . " = " . (empty($comp->fields["name"]) ? "(" . $comp->fields["id"] . ")" : $comp->fields["name"])); initNavigateListItems('SoftwareLicense', $LANG['help'][25] . " = " . (empty($comp->fields["name"]) ? "(" . $comp->fields["id"] . ")" : $comp->fields["name"])); $installed = array(); if ($DB->numrows($result)) { while ($data = $DB->fetch_array($result)) { if ($data["softwarecategories_id"] != $cat) { self::displayCategoryFooter($cat, $rand, $canedit); $cat = self::displayCategoryHeader($computers_id, $data, $rand, $canedit); } $licids = self::displaySoftsByCategory($data, $computers_id, $withtemplate, $canedit); addToNavigateListItems('Software', $data["softwares_id"]); foreach ($licids as $licid) { addToNavigateListItems('SoftwareLicense', $licid); $installed[] = $licid; } } self::displayCategoryFooter($cat, $rand, $canedit); } // Affected licenses NOT installed $query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_softwares`.`name` AS softname,\n `glpi_softwareversions`.`name` AS version,\n `glpi_states`.`name` AS state\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_computers_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_softwares`\n ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n = `glpi_softwareversions`.`id`\n OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n = `glpi_softwareversions`.`id`))\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}' "; if (count($installed)) { $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")"; } $req = $DB->request($query); if ($req->numrows()) { $cat = true; foreach ($req as $data) { if ($cat) { self::displayCategoryHeader($computers_id, $data, $rand, $canedit); $cat = false; } self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit); addToNavigateListItems('SoftwareLicense', $data["id"]); } self::displayCategoryFooter(NULL, $rand, $canedit); } echo "</table></div>\n"; }
/** * Print the computers disks * * @param $comp Computer * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp) { global $DB, $LANG; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) { return false; } $canedit = $comp->can($ID, "w"); echo "<div class='spaced center'>"; $virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}'"); echo "<table class='tab_cadre_fixe'>"; if (empty($virtualmachines)) { echo "<tr><th>" . $LANG['computers'][59] . "</th></tr>"; } else { echo "<tr><th colspan='9'>" . $LANG['computers'][66] . "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['computers'][62] . "</th>"; echo "<th>" . $LANG['computers'][60] . "</th>"; echo "<th>" . $LANG['computers'][63] . "</th>"; echo "<th>" . $LANG['computers'][58] . "</th>"; echo "<th>" . $LANG['computers'][61] . "</th>"; echo "<th>" . $LANG['computers'][24] . "</th>"; echo "<th>" . $LANG['computers'][64] . "</th>"; echo "</tr>"; initNavigateListItems('ComputerVirtualMachine', $LANG['help'][25] . " = " . (empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name'])); foreach ($virtualmachines as $virtualmachine) { $href = "<a href='computervirtualmachine.form.php?id=" . $virtualmachine['id'] . "'>"; echo "<tr class='tab_bg_2'>"; echo "<td>{$href}" . $virtualmachine['name'] . "</a></td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id']); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id']); echo "</td>"; echo "<td>"; echo Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id']); echo "</td>"; echo "<td>{$href}" . $virtualmachine['uuid'] . "</a></td>"; echo "<td>" . $virtualmachine['vcpu'] . "</td>"; echo "<td>" . $virtualmachine['ram'] . "</td>"; echo "<td>"; if ($link_computer = self::findVirtualMachine($virtualmachine)) { $computer = new Computer(); if ($computer->can($link_computer, 'r')) { $url = "<a href='computer.form.php?id=" . $link_computer . "'>"; $url .= $computer->fields["name"] . "</a>"; $tooltip = $LANG['common'][16] . " : " . $computer->fields['name']; $tooltip .= "<br>" . $LANG['common'][19] . " : "; $tooltip .= "<br>" . $computer->fields['serial']; $tooltip .= "<br>" . $computer->fields['comment']; $url .= " " . showToolTip($tooltip, array('display' => false)); } else { $url = $computer->fields['name']; } echo $url; } echo "</td>"; echo "</tr>"; addToNavigateListItems('ComputerVirtualMachine', $virtualmachine['id']); } } if ($canedit) { echo "<tr class='tab_bg_2'><th colspan='8'>"; echo "<a href='computervirtualmachine.form.php?computers_id={$ID}'>" . $LANG['computers'][55] . "</a></th></tr>"; } echo "</table>"; echo "</div>"; }
/** * Print the HTML array of the Netpoint associated to a Location * *@param $ID of the Location * *@return Nothing (display) **/ function showNetpoints($ID) { global $DB, $CFG_GLPI, $LANG; $netpoint = new Netpoint(); $this->check($ID, 'r'); $canedit = $this->can($ID, 'w'); if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } else { $start = 0; } $number = countElementsInTable('glpi_netpoints', "`locations_id`='{$ID}'"); echo "<br><div class='center'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan>" . $LANG['networking'][51] . " - " . $LANG['search'][15] . "</th></tr>"; echo "</table>\n"; } else { printAjaxPager($this->getTreeLink() . " - " . $LANG['networking'][51], $start, $number); if ($canedit) { echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action='" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php'>"; } echo "<table class='tab_cadre_fixe'><tr>"; if ($canedit) { echo "<th width='10'> </th>"; } echo "<th>" . $LANG['common'][16] . "</th>"; // Name echo "<th>" . $LANG['common'][25] . "</th>"; // Comment echo "</tr>\n"; $crit = array('locations_id' => $ID, 'ORDER' => 'name', 'START' => $start, 'LIMIT' => $_SESSION['glpilist_limit']); initNavigateListItems('Netpoint', $this->getTypeName() . "= " . $this->fields['name']); foreach ($DB->request('glpi_netpoints', $crit) as $data) { addToNavigateListItems('Netpoint', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>"; } echo "<td><a href='" . $netpoint->getFormURL(); echo '?id=' . $data['id'] . "'>" . $data['name'] . "</a></td>"; echo "<td>" . $data['comment'] . "</td>"; echo "</tr>\n"; } echo "</table>\n"; if ($canedit) { openArrowMassive("massiveaction_form", true); echo "<input type='hidden' name='itemtype' value='Netpoint'>"; echo "<input type='hidden' name='action' value='delete'>"; closeArrowMassive('massiveaction', $LANG['buttons'][6]); echo "</form>\n"; } } if ($canedit) { // Minimal form for quick input. echo "<form action='" . $netpoint->getFormURL() . "' method='post'>"; echo "<br><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'><td class='b'>" . $LANG['common'][87] . "</td>"; echo "<td>" . $LANG['common'][16] . " : "; autocompletionTextField($this, "name", array('value' => '')); echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>"; echo "<input type='hidden' name='locations_id' value='{$ID}'></td>"; echo "<td><input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table></form>\n"; // Minimal form for massive input. echo "<form action='" . $netpoint->getFormURL() . "' method='post'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'><td class='b'>" . $LANG['common'][87] . "</td>"; echo "<td>" . $LANG['common'][16] . " : "; echo "<input type='text' maxlength='100' size='10' name='_before'> "; Dropdown::showInteger('_from', 0, 0, 400); echo " --> "; Dropdown::showInteger('_to', 0, 0, 400); echo " <input type='text' maxlength='100' size='10' name='_after'><br>"; echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>"; echo "<input type='hidden' name='locations_id' value='{$ID}'></td>"; echo "<input type='hidden' name='_method' value='addMulti'></td>"; echo "<td><input type='submit' name='execute' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td></tr>\n"; echo "</table></form>\n"; } echo "</div>\n"; }
/** * Generic Search and list function * * Build the query, make the search and list items after a search. * * @param $itemtype item type * @param $params parameters array may include field, contains, searchtype, sort, order, start, deleted, link, link2, contains2, field2, itemtype2, searchtype2 * * @return Nothing (display) **/ static function showList($itemtype, $params) { global $DB, $CFG_GLPI, $LANG; // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } // Default values of parameters $p['link'] = array(); // $p['field'] = array(); // $p['contains'] = array(); // $p['searchtype'] = array(); // $p['sort'] = '1'; // $p['order'] = 'ASC'; // $p['start'] = 0; // $p['is_deleted'] = 0; $p['export_all'] = 0; $p['link2'] = ''; // $p['contains2'] = ''; // $p['field2'] = ''; // $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } if ($p['export_all']) { $p['start'] = 0; } // Manage defautll seachtype value : for bookmark compatibility if (count($p['contains'])) { foreach ($p['contains'] as $key => $val) { if (!isset($p['searchtype'][$key])) { $p['searchtype'][$key] = 'contains'; } } } if (is_array($p['contains2']) && count($p['contains2'])) { foreach ($p['contains2'] as $key => $val) { if (!isset($p['searchtype2'][$key])) { $p['searchtype2'][$key] = 'contains'; } } } $target = getItemTypeSearchURL($itemtype); $limitsearchopt = self::getCleanedOptions($itemtype); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; } else { $itemtable = getTableForItemType($itemtype); } $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == GLOBAL_SEARCH) { $LIST_LIMIT = GLOBAL_SEARCH_DISPLAY_COUNT; } } // hack for States if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } $metanames = array(); // Get the items to display $toview = self::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, getLoginUserID()); if (count($displaypref)) { foreach ($displaypref as $val) { array_push($toview, $val); } } // Add searched items if (count($p['field']) > 0) { foreach ($p['field'] as $key => $val) { if (!in_array($val, $toview) && $val != 'all' && $val != 'view') { array_push($toview, $val); } } } // Add order item if (!in_array($p['sort'], $toview)) { array_push($toview, $p['sort']); } // Special case for Ticket : put ID in front if ($itemtype == 'Ticket') { array_unshift($toview, 2); } // Clean toview array $toview = array_unique($toview); foreach ($toview as $key => $val) { if (!isset($limitsearchopt[$val])) { unset($toview[$key]); } } $toview_count = count($toview); // Construct the request //// 1 - SELECT // request currentuser for SQL supervision, not displayed $SELECT = "SELECT '" . $_SESSION['glpiname'] . "' AS currentuser, " . self::addDefaultSelect($itemtype); // Add select for all toview item foreach ($toview as $key => $val) { $SELECT .= self::addSelect($itemtype, $val, $key, 0); } //// 2 - FROM AND LEFT JOIN // Set reference table $FROM = " FROM `{$itemtable}`"; // Init already linked tables array in order not to link a table several times $already_link_tables = array(); // Put reference table array_push($already_link_tables, $itemtable); // Add default join $COMMONLEFTJOIN = self::addDefaultJoin($itemtype, $itemtable, $already_link_tables); $FROM .= $COMMONLEFTJOIN; $searchopt = array(); $searchopt[$itemtype] =& self::getOptions($itemtype); // Add all table for toview items foreach ($toview as $key => $val) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]); } // Search all case : if (in_array("all", $p['field'])) { foreach ($searchopt[$itemtype] as $key => $val) { // Do not search on Group Name if (is_array($val)) { $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]); } } } //// 3 - WHERE // default string $COMMONWHERE = self::addDefaultWhere($itemtype); $first = empty($COMMONWHERE); // Add deleted if item have it if ($item && $item->maybeDeleted()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' "; } // Remove template items if ($item && $item->maybeTemplate()) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' "; } // Add Restrict to current entities if ($entity_restrict) { $LINK = " AND "; if ($first) { $LINK = " "; $first = false; } if ($itemtype == 'Entity') { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true); } else { if (isset($CFG_GLPI["union_search_type"][$itemtype])) { // Will be replace below in Union/Recursivity Hack $COMMONWHERE .= $LINK . " ENTITYRESTRICT "; } else { $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, '', '', $item->maybeRecursive()); } } } $WHERE = ""; $HAVING = ""; // Add search conditions // If there is search items if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { // if real search (strlen >0) and not all and view search if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) { // common search if ($p['field'][$key] != "all" && $p['field'][$key] != "view") { $LINK = " "; $NOT = 0; $tmplink = ""; if (is_array($p['link']) && isset($p['link'][$key])) { if (strstr($p['link'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link'][$key]; } } else { $tmplink = " AND "; } if (isset($searchopt[$itemtype][$p['field'][$key]]["usehaving"])) { // Manage Link if not first item if (!empty($HAVING)) { $LINK = $tmplink; } // Find key $item_num = array_search($p['field'][$key], $toview); $HAVING .= self::addHaving($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num); } else { // Manage Link if not first item if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]); } // view and all search } else { $LINK = " OR "; $NOT = 0; $globallink = " AND "; if (is_array($p['link']) && isset($p['link'][$key])) { switch ($p['link'][$key]) { case "AND": $LINK = " OR "; $globallink = " AND "; break; case "AND NOT": $LINK = " AND "; $NOT = 1; $globallink = " AND "; break; case "OR": $LINK = " OR "; $globallink = " OR "; break; case "OR NOT": $LINK = " AND "; $NOT = 1; $globallink = " OR "; break; } } else { $tmplink = " AND "; } // Manage Link if not first item if (!empty($WHERE)) { $WHERE .= $globallink; } $WHERE .= " ( "; $first2 = true; $items = array(); if ($p['field'][$key] == "all") { $items = $searchopt[$itemtype]; } else { // toview case : populate toview foreach ($toview as $key2 => $val2) { $items[$val2] = $searchopt[$itemtype][$val2]; } } foreach ($items as $key2 => $val2) { if (is_array($val2)) { // Add Where clause if not to be done in HAVING CLAUSE if (!isset($val2["usehaving"])) { $tmplink = $LINK; if ($first2) { $tmplink = " "; $first2 = false; } $WHERE .= self::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]); } } } $WHERE .= " ) "; } } } } //// 4 - ORDER $ORDER = " ORDER BY `id` "; foreach ($toview as $key => $val) { if ($p['sort'] == $val) { $ORDER = self::addOrderBy($itemtype, $p['sort'], $p['order'], $key); } } //// 5 - META SEARCH // Preprocessing if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { // a - SELECT for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { $SELECT .= self::addSelect($p['itemtype2'][$i], $p['field2'][$i], $i, 1, $p['itemtype2'][$i]); } } // b - ADD LEFT JOIN // Already link meta table in order not to linked a table several times $already_link_tables2 = array(); // Link reference tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!in_array(getTableForItemType($p['itemtype2'][$i]), $already_link_tables2)) { $FROM .= self::addMetaLeftJoin($itemtype, $p['itemtype2'][$i], $already_link_tables2, $p['contains2'][$i] == "NULL" || strstr($p['link2'][$i], "NOT")); } } } // Link items tables for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($searchopt[$p['itemtype2'][$i]])) { $searchopt[$p['itemtype2'][$i]] =& self::getOptions($p['itemtype2'][$i]); } if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) { $FROM .= self::addLeftJoin($p['itemtype2'][$i], getTableForItemType($p['itemtype2'][$i]), $already_link_tables2, $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["linkfield"], 1, $p['itemtype2'][$i], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["joinparams"]); } } } } //// 6 - Add item ID // Add ID to the select if (!empty($itemtable)) { $SELECT .= "`{$itemtable}`.`id` AS id "; } //// 7 - Manage GROUP BY $GROUPBY = ""; // Meta Search / Search All / Count tickets if ($_SESSION["glpisearchcount2"][$itemtype] > 0 || !empty($HAVING) || in_array('all', $p['field'])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } if (empty($GROUPBY)) { foreach ($toview as $key2 => $val2) { if (!empty($GROUPBY)) { break; } if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) { $GROUPBY = " GROUP BY `{$itemtable}`.`id`"; } } } // Specific search for others item linked (META search) if (is_array($p['itemtype2'])) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (isset($p['itemtype2'][$key]) && !empty($p['itemtype2'][$key]) && isset($p['contains2'][$key]) && strlen($p['contains2'][$key]) > 0) { $LINK = ""; // For AND NOT statement need to take into account all the group by items if (strstr($p['link2'][$key], "AND NOT") || isset($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["usehaving"])) { $NOT = 0; if (strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { $tmplink = " " . $p['link2'][$key]; } if (!empty($HAVING)) { $LINK = $tmplink; } $HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key); } else { // Meta Where Search $LINK = " "; $NOT = 0; // Manage Link if not first item if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) { $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]); $NOT = 1; } else { if (is_array($p['link2']) && isset($p['link2'][$key])) { $tmplink = " " . $p['link2'][$key]; } else { $tmplink = " AND "; } } if (!empty($WHERE)) { $LINK = $tmplink; } $WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1); } } } } // Use a ReadOnly connection if available and configured to be used $DBread = DBConnection::getReadConnection(); // If no research limit research to display item and compute number of item using simple request $nosearch = true; for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) { $nosearch = false; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { $nosearch = false; } $LIMIT = ""; $numrows = 0; //No search : count number of items using a simple count(ID) request and LIMIT search if ($nosearch) { $LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT; // Force group by for all the type -> need to count only on table ID if (!isset($searchopt[$itemtype][1]['forcegroupby'])) { $count = "count(*)"; } else { $count = "count(DISTINCT `{$itemtable}`.`id`)"; } // request currentuser for SQL supervision, not displayed $query_num = "SELECT {$count}, '" . $_SESSION['glpiname'] . "' AS currentuser\n FROM `{$itemtable}`" . $COMMONLEFTJOIN; $first = true; if (!empty($COMMONWHERE)) { $LINK = " AND "; if ($first) { $LINK = " WHERE "; $first = false; } $query_num .= $LINK . $COMMONWHERE; } // Union Search : if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $tmpquery = $query_num; $numrows = 0; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { // State case if ($itemtype == 'States') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num .= " AND {$ctable}.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $query_num .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $query_num .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $replace = "FROM `{$reftable}`\n INNER JOIN `{$ctable}`\n ON (`{$reftable}`.`items_id` =`{$ctable}`.`id`\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $query_num = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $query_num); } $query_num = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $query_num); $result_num = $DBread->query($query_num); $numrows += $DBread->result($result_num, 0, 0); } } } else { $result_num = $DBread->query($query_num); $numrows = $DBread->result($result_num, 0, 0); } } // If export_all reset LIMIT condition if ($p['export_all']) { $LIMIT = ""; } if (!empty($WHERE) || !empty($COMMONWHERE)) { if (!empty($COMMONWHERE)) { $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : ''); } else { $WHERE = ' WHERE ' . $WHERE . ' '; } $first = false; } if (!empty($HAVING)) { $HAVING = ' HAVING ' . $HAVING; } // Create QUERY if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $first = true; $QUERY = ""; foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) { $ctable = getTableForItemType($ctype); $citem = new $ctype(); if ($citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // State case if ($itemtype == 'States') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery .= " AND `{$ctable}`.`states_id` > '0' "; // Add deleted if item have it if ($citem && $citem->maybeDeleted()) { $tmpquery .= " AND `{$ctable}`.`is_deleted` = '0' "; } // Remove template items if ($citem && $citem->maybeTemplate()) { $tmpquery .= " AND `{$ctable}`.`is_template` = '0' "; } } else { // Ref table case $reftable = getTableForItemType($itemtype); $tmpquery = $SELECT . ", '{$ctype}' AS TYPE,\n `{$reftable}`.`id` AS refID, " . "\n `{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE; $replace = "FROM `{$reftable}`" . "\n INNER JOIN `{$ctable}`" . "\n ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`" . "\n AND `{$reftable}`.`itemtype` = '{$ctype}')"; $tmpquery = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery); $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); } $tmpquery = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $tmpquery); // SOFTWARE HACK if ($ctype == 'Software') { $tmpquery = str_replace("glpi_softwares.serial", "''", $tmpquery); $tmpquery = str_replace("glpi_softwares.otherserial", "''", $tmpquery); } $QUERY .= $tmpquery; } } if (empty($QUERY)) { echo self::showError($output_type); return; } $QUERY .= str_replace($CFG_GLPI["union_search_type"][$itemtype] . ".", "", $ORDER) . $LIMIT; } else { $QUERY = $SELECT . $FROM . $WHERE . $GROUPBY . $HAVING . $ORDER . $LIMIT; } $DBread->query("SET SESSION group_concat_max_len = 4096;"); $result = $DBread->query($QUERY); /// Check group concat limit : if warning : increase limit if ($result2 = $DBread->query('SHOW WARNINGS')) { if ($DBread->numrows($result2) > 0) { $data = $DBread->fetch_assoc($result2); if ($data['Code'] == 1260) { $DBread->query("SET SESSION group_concat_max_len = 4194304;"); $result = $DBread->query($QUERY); } } } // Get it from database and DISPLAY if ($result) { // if real search or complete export : get numrows from request if (!$nosearch || $p['export_all']) { $numrows = $DBread->numrows($result); } // Contruct Pager parameters $globallinkto = self::getArrayUrlLink("field", $p['field']) . self::getArrayUrlLink("link", $p['link']) . self::getArrayUrlLink("contains", $p['contains']) . self::getArrayUrlLink("searchtype", $p['searchtype']) . self::getArrayUrlLink("field2", $p['field2']) . self::getArrayUrlLink("contains2", $p['contains2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("link2", $p['link2']); $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto; // Not more used : clean pages : try to comment it /* $tmp=explode('?',$target,2); if (count($tmp)>1) { $target = $tmp[0]; $parameters = $tmp[1].'&'.$parameters; } */ if ($output_type == GLOBAL_SEARCH) { if (class_exists($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + GLOBAL_SEARCH_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . $LANG['common'][66] . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($p['start'] < $numrows) { // Display pager only for HTML if ($output_type == HTML_OUTPUT) { // For plugin add new parameter if available if ($plug = isPluginItemType($itemtype)) { $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport'; if (function_exists($function)) { $out = $function($itemtype); if (is_array($out) && count($out)) { foreach ($out as $key => $val) { if (is_array($val)) { $parameters .= self::getArrayUrlLink($key, $val); } else { $parameters .= "&{$key}={$val}"; } } } } } printPager($p['start'], $numrows, $target, $parameters, $itemtype); } // Form to massive actions $isadmin = $item && $item->canUpdate(); if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) { $infoc = new Infocom(); $isadmin = $infoc->canUpdate() || $infoc->canCreate(); } if ($isadmin && $output_type == HTML_OUTPUT) { echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">"; } // Compute number of columns to display // Add toview elements $nbcols = $toview_count; $already_printed = array(); // Add meta search elements if real search (strlen>0) or only NOT search if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && !empty($p['itemtype2'][$i]) && (!isset($p['link2'][$i]) || !strstr($p['link2'][$i], "NOT"))) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { $nbcols++; $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } if ($output_type == HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = $p['start'] + $LIST_LIMIT; // No search Case if ($nosearch) { $begin_display = 0; $end_display = min($numrows - $p['start'], $LIST_LIMIT); } // Export All case if ($p['export_all']) { $begin_display = 0; $end_display = $numrows; } // Display List Header echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line echo self::showNewLine($output_type); $header_num = 1; if ($output_type == HTML_OUTPUT) { // HTML display - massive modif $search_config = ""; if (haveRight("search_config", "w") || haveRight("search_config_global", "w")) { $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&itemtype={$itemtype}' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes'); w.focus();\""; $search_config = "<img alt=\"" . $LANG['setup'][252] . "\" title=\"" . $LANG['setup'][252] . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } echo self::showHeaderItem($output_type, $search_config, $header_num, "", 0, $p['order']); } // Display column Headers for toview items foreach ($toview as $key => $val) { $linkto = ''; if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) { $linkto = "{$target}?itemtype={$itemtype}&sort=" . $val . "&order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $p['start'] . $globallinkto; } echo self::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']); } // Display columns Headers for meta items $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) { if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) { if (!isset($metanames[$p['itemtype2'][$i]])) { $metaitem = new $p['itemtype2'][$i](); $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName(); } echo self::showHeaderItem($output_type, $metanames[$p['itemtype2'][$i]] . " - " . $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["name"], $header_num); $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1; } } } } // Add specific column Header if ($itemtype == 'CartridgeItem') { echo self::showHeaderItem($output_type, $LANG['cartridges'][0], $header_num); } if ($itemtype == 'ConsumableItem') { echo self::showHeaderItem($output_type, $LANG['consumables'][0], $header_num); } if ($itemtype == 'States' || $itemtype == 'ReservationItem') { echo self::showHeaderItem($output_type, $LANG['state'][6], $header_num); } if ($itemtype == 'ReservationItem' && $output_type == HTML_OUTPUT) { if (haveRight("reservation_central", "w")) { echo self::showHeaderItem($output_type, $LANG['reservation'][4], $header_num); echo self::showHeaderItem($output_type, " ", $header_num); } echo self::showHeaderItem($output_type, " ", $header_num); } // End Line for column headers echo self::showEndLine($output_type); // if real search seek to begin of items to display (because of complete search) if (!$nosearch) { $DBread->data_seek($result, $p['start']); } // Define begin and end var for loop // Search case $i = $begin_display; // Init list of items displayed if ($output_type == HTML_OUTPUT) { initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; // Display Loop while ($i < $numrows && $i < $end_display) { // Column num $item_num = 1; // Get data and increment loop variables $data = $DBread->fetch_assoc($result); $i++; $row_num++; // New line echo self::showNewLine($output_type, $i % 2, $p['is_deleted']); // Add item in item list addToNavigateListItems($itemtype, $data["id"]); if ($output_type == HTML_OUTPUT) { // HTML display - massive modif $tmpcheck = ""; if ($isadmin) { if ($itemtype == 'Entity' && !in_array($data["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($item->maybeRecursive() && !in_array($data["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } if (isset($_SESSION['glpimassiveactionselected'][$data["id"]])) { $sel = "checked"; } $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'\n {$sel}>"; } } } echo self::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'"); } // Print other toview items foreach ($toview as $key => $val) { echo self::showItem($output_type, self::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, self::displayConfigItem($itemtype, $val, $data, $key)); } // Print Meta Item $already_printed = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) { for ($j = 0; $j < $_SESSION["glpisearchcount2"][$itemtype]; $j++) { if (isset($p['itemtype2'][$j]) && !empty($p['itemtype2'][$j]) && isset($p['contains2'][$j]) && strlen($p['contains2'][$j]) > 0) { if (!isset($already_printed[$p['itemtype2'][$j] . $p['field2'][$j]])) { // General case if (strpos($data["META_{$j}"], "\$\$\$\$") === false) { $out = self::giveItem($p['itemtype2'][$j], $p['field2'][$j], $data, $j, 1); echo self::showItem($output_type, $out, $item_num, $row_num); // Case of GROUP_CONCAT item : split item and multilline display } else { $split = explode("\$\$\$\$", $data["META_{$j}"]); $count_display = 0; $out = ""; $unit = ""; $separate = '<br>'; if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) { $separate = '<hr>'; } if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit'])) { $unit = $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit']; } for ($k = 0; $k < count($split); $k++) { if ($p['contains2'][$j] == "NULL" || strlen($p['contains2'][$j]) == 0 || preg_match('/' . $p['contains2'][$j] . '/i', $split[$k]) || isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['forcegroupby'])) { if ($count_display) { $out .= $separate; } $count_display++; // Manage Link to item $split2 = explode("\$\$", $split[$k]); if (isset($split2[1])) { $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' "; $out .= "href=\"" . getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $p['itemtype2'][$j] . "\">"; $out .= $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } else { $out .= $split[$k] . $unit; } } } echo self::showItem($output_type, $out, $item_num, $row_num); } $already_printed[$p['itemtype2'][$j] . $p['field2'][$j]] = 1; } } } } // Specific column display if ($itemtype == 'CartridgeItem') { echo self::showItem($output_type, Cartridge::getCount($data["id"], $data["ALARM"], $output_type != HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'ConsumableItem') { echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'States' || $itemtype == 'ReservationItem') { $typename = $data["TYPE"]; if (class_exists($data["TYPE"])) { $itemtmp = new $data["TYPE"](); $typename = $itemtmp->getTypeName(); } echo self::showItem($output_type, $typename, $item_num, $row_num); } if ($itemtype == 'ReservationItem' && $output_type == HTML_OUTPUT) { if (haveRight("reservation_central", "w")) { if (!haveAccessToEntity($data["ENTITY"])) { echo self::showItem($output_type, " ", $item_num, $row_num); echo self::showItem($output_type, " ", $item_num, $row_num); } else { echo self::showItem($output_type, "<a href=\"" . getItemTypeFormURL($itemtype) . "?id=" . $data["refID"] . "&is_active=" . ($data["ACTIVE"] ? 0 : 1) . "&update=update\" " . "title=\"" . ($data["ACTIVE"] ? $LANG['buttons'][42] : $LANG['buttons'][41]) . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($data["ACTIVE"] ? "moins" : "plus") . ".png\" alt=''\n title=''></a>", $item_num, $row_num, "class='center'"); echo self::showItem($output_type, "<a href='" . getItemTypeFormURL($itemtype) . "?id=" . $data["refID"] . "&delete=delete' " . addConfirmationOnAction(array($LANG['reservation'][38], $LANG['reservation'][39])) . " title=\"" . $LANG['reservation'][6] . "\">" . "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png'\n alt='' title=''></a>", $item_num, $row_num, "class='center'"); } } if ($data["ACTIVE"]) { echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . $LANG['reservation'][21] . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>", $item_num, $row_num, "class='center'"); } else { echo self::showItem($output_type, " ", $item_num, $row_num); } } // End Line echo self::showEndLine($output_type); } $title = ""; // Create title if ($output_type == PDF_OUTPUT_LANDSCAPE || $output_type == PDF_OUTPUT_PORTRAIT) { if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { if (strlen($p['contains'][$key]) > 0) { if (isset($p["link"][$key])) { $title .= " " . $p["link"][$key] . " "; } switch ($p['field'][$key]) { case "all": $title .= $LANG['common'][66]; break; case "view": $title .= $LANG['search'][11]; break; default: $title .= $searchopt[$itemtype][$p['field'][$key]]["name"]; } switch ($p['searchtype'][$key]) { case "equals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $title .= ' = ' . Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]); } else { $title .= ' = ' . $p['contains'][$key]; } break; case "notequals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $title .= ' <> ' . Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]); } else { $title .= ' <> ' . $p['contains'][$key]; } break; case "lessthan": $title .= ' < ' . $p['contains'][$key]; break; case "morethan": $title .= ' > ' . $p['contains'][$key]; break; case "contains": $title .= ' = %' . $p['contains'][$key] . '%'; break; default: $title .= ' = ' . $p['contains'][$key]; break; } } } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { if (strlen($p['contains2'][$key]) > 0) { if (isset($p['link2'][$key])) { $title .= " " . $p['link2'][$key] . " "; } $title .= $metanames[$p['itemtype2'][$key]] . "/"; $title .= $searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["name"]; switch ($p['searchtype2'][$key]) { case "equals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $title .= ' = ' . Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]); } else { $title .= ' = ' . $p['contains2'][$key]; } break; case "notequals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $title .= ' <> ' . Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]); } else { $title .= ' <> ' . $p['contains2'][$key]; } break; case "lessthan": $title .= ' < ' . $p['contains2'][$key]; break; case "morethan": $title .= ' > ' . $p['contains2'][$key]; break; case "contains": $title .= ' = %' . $p['contains2'][$key] . '%'; break; default: $title .= ' = ' . $p['contains2'][$key]; break; } } } } } // Display footer echo self::showFooter($output_type, $title); // Delete selected item if ($output_type == HTML_OUTPUT) { if ($isadmin) { openArrowMassive("massiveaction_form"); Dropdown::showForMassiveAction($itemtype, $p['is_deleted']); closeArrowMassive(); // End form for delete item echo "</form>\n"; } else { echo "<br>"; } } if ($output_type == HTML_OUTPUT) { // In case of HTML display printPager($p['start'], $numrows, $target, $parameters); } } else { echo self::showError($output_type); } } else { echo $DBread->error(); } // Clean selection $_SESSION['glpimassiveactionselected'] = array(); }
function showAndAddRuleForm($item) { global $LANG; $canedit = haveRight($this->right, "w"); if ($canedit && $item->getType() == 'Entity') { $this->showNewRuleForm($item->getField('id')); } //Get all rules and actions $crit = array('field' => getForeignKeyFieldForTable($item->getTable()), 'value' => $item->getField('id')); $rules = $this->getRulesForCriteria($crit); echo "<div class='spaced'>"; if (empty($rules)) { echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th>" . $LANG['search'][15] . "</th>"; echo "</tr>\n"; echo "</table>\n"; } else { if ($canedit) { $formname = $item->getType() . "_" . $this->getType() . "_form"; echo "\n<form name='{$formname}' id='{$formname}' method='post' " . "action='" . getItemTypeSearchURL(get_class($this)) . "'>"; } echo "<table class='tab_cadre_fixehov'><tr>"; if ($canedit) { echo "<th></th>"; } echo "<th>" . $this->getTitle() . "</th>"; echo "<th>" . $LANG['joblist'][6] . "</th>"; echo "<th>" . $LANG['common'][60] . "</th>"; echo "</tr>\n"; initNavigateListItems(get_class($this), $item->getTypeName() . "=" . $item->getName()); foreach ($rules as $rule) { addToNavigateListItems(get_class($this), $rule->fields["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; echo "<input type='checkbox' name='item[" . $rule->fields["id"] . "]' value='1'>"; echo "</td>"; echo "<td><a href='" . getItemTypeFormURL(get_class($this)) . "?id=" . $rule->fields["id"] . "&onglet=1'>" . $rule->fields["name"] . "</a></td>"; } else { echo "<td>" . $rule->fields["name"] . "</td>"; } echo "<td>" . $rule->fields["description"] . "</td>"; echo "<td>" . Dropdown::getYesNo($rule->fields["is_active"]) . "</td>"; echo "</tr>\n"; } echo "</table>\n"; if ($canedit) { openArrowMassive($formname, true); echo "<input type='hidden' name='action' value='delete'>"; closeArrowMassive('massiveaction', $LANG['buttons'][6]); echo "</form>"; } } echo "</div>"; }
/** * Print the HTML array for entreprises on the current contact * *@return Nothing (display) * **/ function showSuppliers() { global $DB, $CFG_GLPI, $LANG; $instID = $this->fields['id']; if (!$this->can($instID, 'r')) { return false; } $canedit = $this->can($instID, 'w'); $query = "SELECT `glpi_contacts_suppliers`.`id`,\n `glpi_suppliers`.`id` AS entID,\n `glpi_suppliers`.`name` AS name,\n `glpi_suppliers`.`website` AS website,\n `glpi_suppliers`.`fax` AS fax,\n `glpi_suppliers`.`phonenumber` AS phone,\n `glpi_suppliers`.`suppliertypes_id` AS type,\n `glpi_suppliers`.`is_deleted`,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contacts_suppliers`, `glpi_suppliers`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_suppliers`.`entities_id`)\n WHERE `glpi_contacts_suppliers`.`contacts_id` = '{$instID}'\n AND `glpi_contacts_suppliers`.`suppliers_id` = `glpi_suppliers`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_suppliers", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`, `name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contact.form.php\">"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][67]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][64]; } else { echo $LANG['financial'][65]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['financial'][26] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][79] . "</th>"; echo "<th>" . $LANG['help'][35] . "</th>"; echo "<th>" . $LANG['financial'][30] . "</th>"; echo "<th>" . $LANG['financial'][45] . "</th>"; echo "<th> </th></tr>"; $used = array(); if ($number > 0) { initNavigateListItems('Supplier', $LANG['common'][92] . " = " . $this->fields['name']); while ($data = $DB->fetch_array($result)) { $ID = $data["id"]; addToNavigateListItems('Supplier', $data["entID"]); $used[$data["entID"]] = $data["entID"]; $website = $data["website"]; if (!empty($website)) { $website = $data["website"]; if (!preg_match("?https*://?", $website)) { $website = "http://" . $website; } $website = "<a target=_blank href='{$website}'>" . $data["website"] . "</a>"; } echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id=" . $data["entID"] . "'>" . Dropdown::getDropdownName("glpi_suppliers", $data["entID"]) . "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_suppliertypes", $data["type"]); echo "</td>"; echo "<td class='center' width='80'>" . $data["phone"] . "</td>"; echo "<td class='center' width='80'>" . $data["fax"] . "</td>"; echo "<td class='center'>" . $website . "</td>"; echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contact.form.php?deletecontactsupplier=1" . "&id={$ID}&contacts_id={$instID}'><strong>" . $LANG['buttons'][6] . "</strong></a>"; } else { echo " "; } echo "</td></tr>"; } } if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_suppliers", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_suppliers", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<tr class='tab_bg_1'><td> </td><td class='center' colspan='4'>"; echo "<input type='hidden' name='contacts_id' value='{$instID}'>"; Dropdown::show('Supplier', array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"])); echo " <input type='submit' name='addcontactsupplier' value='" . $LANG['buttons'][8] . "' class='submit'>"; echo "</td><td> </td><td> </td>"; echo "</tr>"; } } echo "</table></div></form>"; }
/** * Show computers linked to a License * * @param $license SoftwareLicense object * * @return nothing **/ static function showForLicense(SoftwareLicense $license) { global $DB, $CFG_GLPI, $LANG; $searchID = $license->getField('id'); if (!haveRight("software", "r") || !$searchID) { return false; } $canedit = haveRight("software", "w"); $canshowcomputer = haveRight("computer", "r"); if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } else { $start = 0; } if (isset($_REQUEST["order"]) && $_REQUEST["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_REQUEST["sort"]) && !empty($_REQUEST["sort"])) { // manage several param like location,compname : order first $tmp = explode(",", $_REQUEST["sort"]); $sort = "`" . implode("` {$order},`", $tmp) . "`"; } else { $sort = "`entity` {$order}, `compname`"; } //SoftwareLicense ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`)\n WHERE `glpi_computers_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'"; $number = 0; if ($result = $DB->query($query_number)) { $number = $DB->result($result, 0, 0); } echo "<div class='center'>"; if ($canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'>"; echo "<td>"; Dropdown::show('Computer', array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive'])); echo "</td>"; echo "<td><input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>"; echo "</table></form>"; } if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['search'][15] . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager printAjaxPager($LANG['software'][9], $start, $number); $query = "SELECT `glpi_computers_softwarelicenses`.*,\n `glpi_computers`.`name` AS compname,\n `glpi_computers`.`id` AS cID,\n `glpi_computers`.`serial`,\n `glpi_computers`.`otherserial`,\n `glpi_users`.`name` AS username,\n `glpi_softwarelicenses`.`name` AS license,\n `glpi_softwarelicenses`.`id` AS vID,\n `glpi_softwarelicenses`.`name` AS vername,\n `glpi_entities`.`completename` AS entity,\n `glpi_locations`.`completename` AS location,\n `glpi_states`.`name` AS state,\n `glpi_groups`.`name` AS groupe,\n `glpi_softwarelicenses`.`name` AS lname,\n `glpi_softwarelicenses`.`id` AS lID\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id`\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`)\n LEFT JOIN `glpi_locations`\n ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`)\n LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`)\n LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`)\n WHERE (`glpi_softwarelicenses`.`id` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); $rand = mt_rand(); if ($result = $DB->query($query)) { if ($data = $DB->fetch_assoc($result)) { $soft = new Software(); $soft->getFromDB($license->fields['softwares_id']); $showEntity = $license->isRecursive(); $title = $LANG['help'][31] . " = " . $soft->fields["name"] . " - " . $data["vername"]; initNavigateListItems('Computer', $title); $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt='' title=''>"; if ($canedit) { echo "<form name='softinstall" . $rand . "' id='softinstall" . $rand . "' method='post'\n action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th> </th>"; } else { echo "<table class='tab_cadre_fixehov'><tr>"; } echo "<th>" . ($sort == "`compname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][16] . "</a></th>"; if ($showEntity) { echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['entity'][0] . "</a></th>"; } echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][19] . "</a></th>"; echo "<th>" . ($sort == "`otherserial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=otherserial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][20] . "</a></th>"; echo "<th>" . (strstr($sort, "`location`") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=location,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][15] . "</a></th>"; echo "<th>" . (strstr($sort, "state") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=state,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['state'][0] . "</a></th>"; echo "<th>" . (strstr($sort, "groupe") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=groupe,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][35] . "</a></th>"; echo "<th>" . (strstr($sort, "username") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=username,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][34] . "</a></th>"; echo "</tr>\n"; do { addToNavigateListItems('Computer', $data["cID"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>"; } $compname = $data['compname']; if (empty($compname) || $_SESSION['glpiis_ids_visible']) { $compname .= " (" . $data['cID'] . ")"; } if ($canshowcomputer) { echo "<td><a href='computer.form.php?id=" . $data['cID'] . "'>{$compname}</a></td>"; } else { echo "<td>" . $compname . "</td>"; } if ($showEntity) { echo "<td>" . (empty($data['entity']) ? $LANG['entity'][2] : $data['entity']) . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td>" . $data['otherserial'] . "</td>"; echo "<td>" . $data['location'] . "</td>"; echo "<td>" . $data['state'] . "</td>"; echo "<td>" . $data['groupe'] . "</td>"; echo "<td>" . $data['username'] . "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo "</table>\n"; if ($canedit) { openArrowMassive("softinstall" . $rand . "", true); Dropdown::show('SoftwareLicense', array('condition' => "`glpi_softwarelicenses`.`softwares_id`\n = '" . $license->fields['softwares_id'] . "'", 'used' => array($searchID))); echo " <input type='submit' name='move' value=\"" . $LANG['buttons'][20] . "\" class='submit'> "; closeArrowMassive('delete', $LANG['buttons'][6]); echo "</form>"; } } else { // Not found echo $LANG['search'][15]; } } // Query echo "</div>\n"; }
/** * Print the computers disks * * @param $comp Computer * @param $withtemplate='' boolean : Template or basic item. * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB, $LANG; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) { return false; } $canedit = $comp->can($ID, "w"); echo "<div class='center'>"; $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n `glpi_computerdisks`.*\n FROM `glpi_computerdisks`\n LEFT JOIN `glpi_filesystems`\n ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n WHERE (`computers_id` = '{$ID}')"; if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 1) { echo $LANG['computers'][0]; } else { echo $LANG['computers'][8]; } echo "</th></tr>"; if ($DB->numrows($result)) { echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['computers'][6] . "</th>"; echo "<th>" . $LANG['computers'][5] . "</th>"; echo "<th>" . $LANG['computers'][4] . "</th>"; echo "<th>" . $LANG['computers'][3] . "</th>"; echo "<th>" . $LANG['computers'][2] . "</th>"; echo "<th>" . $LANG['computers'][1] . "</th>"; echo "</tr>"; initNavigateListItems('ComputerDisk', $LANG['help'][25] . " = " . (empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name'])); while ($data = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td><a href='computerdisk.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</a></td>"; } else { echo "<td>" . $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</td>"; } echo "<td>" . $data['device'] . "</td>"; echo "<td>" . $data['mountpoint'] . "</td>"; echo "<td>" . $data['fsname'] . "</td>"; echo "<td class='right'>" . formatNumber($data['totalsize'], false, 0) . " " . $LANG['common'][82] . "<span class='small_space'></span></td>"; echo "<td class='right'>" . formatNumber($data['freesize'], false, 0) . " " . $LANG['common'][82] . "<span class='small_space'></span></td>"; echo "<td>"; $percent = 0; if ($data['totalsize'] > 0) { $percent = round(100 * $data['freesize'] / $data['totalsize']); } displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false)); echo "</td>"; addToNavigateListItems('ComputerDisk', $data['id']); } } else { echo "<tr><th colspan='7'>" . $LANG['search'][15] . "</th></tr>"; } if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) { echo "<tr class='tab_bg_2'><th colspan='7'>"; echo "<a href='computerdisk.form.php?computers_id={$ID}&withtemplate=" . $withtemplate . "'>" . $LANG['computers'][7] . "</a></th></tr>"; } echo "</table>"; } echo "</div><br>"; }
/** * Show Licenses of a software * * @param $software software object * * @return nothing **/ static function showForSoftware($software) { global $DB, $CFG_GLPI, $LANG; $softwares_id = $software->getField('id'); $license = new SoftwareLicense(); $computer = new Computer(); if (!$software->can($softwares_id, "r")) { return false; } if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } else { $start = 0; } if (isset($_REQUEST["order"]) && $_REQUEST["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_REQUEST["sort"]) && !empty($_REQUEST["sort"])) { $sort = "`" . $_REQUEST["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = haveRight("software", "w"); // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['search'][15] . "</th></tr>\n"; if ($canedit) { echo "<tr class='tab_bg_2'><td class='center'>"; echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>"; echo "</td></tr>\n"; } echo "</table></div>\n"; return; } // Display the pager printAjaxPager($LANG['software'][11], $start, $number); $rand = mt_rand(); $query = "SELECT `glpi_softwarelicenses`.*,\n `buyvers`.`name` AS buyname,\n `usevers`.`name` AS usename,\n `glpi_entities`.`completename` AS entity,\n `glpi_softwarelicensetypes`.`name` AS typename\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_softwareversions` AS buyvers\n ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n LEFT JOIN `glpi_softwareversions` AS usevers\n ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicensetypes`.`id`\n = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); initNavigateListItems('SoftwareLicense', $LANG['help'][31] . " = " . $software->fields["name"]); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { if ($canedit) { echo "<form method='post' name='massiveactionlicense_form{$rand}' id='" . "massiveactionlicense_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">"; } $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'><tr>"; echo "<th> </th>"; echo "<th>" . ($sort == "`name`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=name&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][16] . "</a></th>"; if ($software->isRecursive()) { // Ereg to search entity in string for match default order echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['entity'][0] . "</a></th>"; } echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][19] . "</a></th>"; echo "<th>" . ($sort == "`number`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=number&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['tracking'][29] . "</a></th>"; echo "<th>" . $LANG['software'][9] . "</th>"; echo "<th>" . ($sort == "`typename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=typename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][17] . "</a></th>"; echo "<th>" . ($sort == "`buyname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=buyname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][1] . "</a></th>"; echo "<th>" . ($sort == "`usename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=usename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][2] . "</a></th>"; echo "<th>" . ($sort == "`expire`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=expire&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][32] . "</a></th>"; echo "</tr>\n"; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { addToNavigateListItems('SoftwareLicense', $data['id']); echo "<tr class='tab_bg_2'>"; if ($license->can($data['id'], "w")) { echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>"; } else { echo "<td> </td>"; } echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</a></td>"; if ($software->isRecursive()) { echo "<td>" . $data['entity'] . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='right'>" . ($data['number'] > 0 ? $data['number'] . " " : $LANG['software'][4]) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; echo "<td class='right'>{$nb_assoc} </td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Not illimited, add the current number $tot += $data['number']; } } } echo "<tr class='tab_bg_1'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . $LANG['common'][33] . "</td>"; echo "<td class='right b'>" . ($tot > 0 ? $tot . " " : $LANG['software'][4]) . "</td>"; echo "<td class='right b'>{$tot_assoc} </td>"; echo "<td colspan='4' class='center'>"; if ($canedit) { echo "<a href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][8] . "</a>"; } echo "</td></tr>"; echo "</table>\n"; if ($canedit) { openArrowMassive("massiveactionlicense_form{$rand}", true); Dropdown::showForMassiveAction('SoftwareLicense', 0, array('softwares_id' => $softwares_id)); closeArrowMassive(); echo "</form>"; } } else { echo $LANG['search'][15]; } } echo "</div>"; }
/** * Show users of a group * * @param $target string : where to go on action * @param $group the group **/ static function showForGroup($target, Group $group) { global $DB, $LANG; $ID = $group->fields['id']; if (!haveRight("user", "r") || !$group->can($ID, 'r')) { return false; } // Have right to manage members $canedit = $group->can($ID, 'r') && $group->canUpdate(); $rand = mt_rand(); $nb_per_line = 3; $query = "SELECT `glpi_users`.*,\n `glpi_groups_users`.`id` AS linkID,\n `glpi_groups_users`.`is_dynamic` AS is_dynamic\n FROM `glpi_groups_users`\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_groups_users`.`users_id`)\n WHERE `glpi_groups_users`.`groups_id`='{$ID}'\n ORDER BY `glpi_users`.`name`,\n `glpi_users`.`realname`,\n `glpi_users`.`firstname`"; $used = array(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { $used[$data["id"]] = $data; } } $used_ids = array_keys($used); if ($canedit) { $headerspan = $nb_per_line * 2; echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'\n action='{$target}'>"; echo "<input type='hidden' name='groups_id' value='{$ID}'>"; if ($group->fields['is_recursive']) { $entityrestrict = getSonsOf('glpi_entities', $group->fields['entities_id']); // active entity could be a child of object entity if ($_SESSION['glpiactive_entity'] != $group->fields['entities_id'] && in_array($_SESSION['glpiactive_entity'], $entityrestrict)) { $entityrestrict = getSonsOf('glpi_entities', $_SESSION['glpiactive_entity']); } } else { $entityrestrict = $group->fields['entities_id']; } $res = User::getSqlSearchResult(true, "all", $entityrestrict, 0, $used_ids); $nb = $res ? $DB->result($res, 0, "CPT") : 0; if ($nb) { echo "<div class='firstbloc'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . $LANG['setup'][603] . "</tr>"; echo "<tr><td class='tab_bg_2 center'>"; User::dropdown(array('right' => "all", 'entity' => $entityrestrict, 'used' => $used_ids)); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='hidden' name'is_dynamic' value='0'>"; echo "<input type='submit' name='adduser' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table></div>"; } } else { $headerspan = $nb_per_line; } if (count($used)) { echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='{$headerspan}'>" . $LANG['Menu'][14] . " (D=" . $LANG['profiles'][29] . ")"; echo "</th></tr>"; initNavigateListItems('User', $group->getTypeName() . " = " . $group->getName()); $i = 0; $user = new User(); foreach ($used as $id => $data) { if (!$user->can($id, 'r')) { // For recursive group, could be in another (sister) entity continue; } addToNavigateListItems('User', $data["id"]); if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>"; } echo "<tr class='tab_bg_1'>"; } if ($canedit) { echo "<td width='10'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1' {$sel}>"; echo "</td>"; } echo "<td>"; echo $user->getLink(); if ($data["is_dynamic"]) { echo "<strong> (D)</strong>"; } echo "</td>"; $i++; } while ($i % $nb_per_line != 0) { echo "<td> </td>"; if ($canedit) { echo "<td> </td>"; } $i++; } echo "</tr>"; echo "</table>"; if ($canedit) { openArrowMassive("groupuser_form{$rand}", true); closeArrowMassive('deleteuser', $LANG['buttons'][6]); } echo "</div>"; } if ($canedit) { echo "</form>"; } }
/** * Show users of an entity * * @param $entity Entity object **/ static function showForEntity(Entity $entity) { global $DB, $CFG_GLPI, $LANG; $ID = $entity->getField('id'); if (!$entity->can($ID, "r")) { return false; } $canedit = $entity->can($ID, "w"); $canshowuser = haveRight("user", "r"); $nb_per_line = 3; $rand = mt_rand(); if ($canedit) { echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='"; echo getItemTypeFormURL(__CLASS__) . "'>"; $headerspan = $nb_per_line * 2; } else { $headerspan = $nb_per_line; } if ($canedit) { echo "<div class='firstbloc'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='5'>" . $LANG['setup'][605] . "</tr>"; echo "<tr><td class='tab_bg_2 center'>" . $LANG['common'][34] . " : "; echo "<input type='hidden' name='entities_id' value='{$ID}'>"; User::dropdown(array('right' => 'all')); echo "</td><td class='tab_bg_2 center'>" . $LANG['profiles'][22] . " : "; Profile::dropdownUnder(array('value' => Profile::getDefault())); echo "</td><td class='tab_bg_2 center'>" . $LANG['profiles'][28] . " : "; Dropdown::showYesNo("is_recursive", 0); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</td></tr>"; echo "</table></div>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='{$headerspan}'>" . $LANG['Menu'][14] . " (D=" . $LANG['profiles'][29] . ", R=" . $LANG['profiles'][28] . ")</th></tr>"; $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { initNavigateListItems('User', $LANG['entity'][0] . " = " . $entity->fields['name']); while ($data = $DB->fetch_array($result)) { echo "<tr><th colspan='{$headerspan}'>" . $LANG['profiles'][22] . " : " . $data["name"]; echo "</th></tr>"; $query = "SELECT `glpi_users`.*,\n `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'\n AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n ORDER BY `glpi_profiles_users`.`profiles_id`,\n `glpi_users`.`name`,\n `glpi_users`.`realname`,\n `glpi_users`.`firstname`"; $result2 = $DB->query($query); if ($DB->numrows($result2) > 0) { $i = 0; while ($data2 = $DB->fetch_array($result2)) { addToNavigateListItems('User', $data2["id"]); if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>"; } echo "<tr class='tab_bg_1'>"; } if ($canedit) { echo "<td width='10'>"; echo "<input type='checkbox' name='item[" . $data2["linkID"] . "]' value='1'>"; echo "</td>"; } echo "<td>"; echo formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser); if ($data2["is_dynamic"] || $data2["is_recursive"]) { echo "<strong> ("; if ($data2["is_dynamic"]) { echo "D"; } if ($data2["is_dynamic"] && $data2["is_recursive"]) { echo ", "; } if ($data2["is_recursive"]) { echo "R"; } echo ")</strong>"; } echo "</td>"; $i++; } while ($i % $nb_per_line != 0) { echo "<td> </td>"; if ($canedit) { echo "<td> </td>"; } $i++; } echo "</tr>"; } else { echo "<tr colspan='{$headerspan}'>" . $LANG['common'][54] . "</tr>"; } } } echo "</table>"; if ($canedit) { openArrowMassive("entityuser_form{$rand}", true); closeArrowMassive('delete', $LANG['buttons'][6]); echo "</form>"; } echo "</div>"; }
/** * Show ports for an item * * @param $itemtype integer : item type * @param $ID integer : item ID * @param $withtemplate integer : withtemplate param **/ static function showForItem($itemtype, $ID, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $rand = mt_rand(); if (!class_exists($itemtype)) { return false; } $item = new $itemtype(); if (!haveRight('networking', 'r') || !$item->can($ID, 'r')) { return false; } $canedit = $item->can($ID, 'w'); // Show Add Form if ($canedit && (empty($withtemplate) || $withtemplate != 2)) { echo "\n<div class='firstbloc'><table class='tab_cadre_fixe'>"; echo "<tr><td class='tab_bg_2 center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?items_id={$ID}&itemtype={$itemtype}'><strong>" . $LANG['networking'][19] . "</strong></a></td>\n"; echo "<td class='tab_bg_2 center' width='50%'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?items_id={$ID}&itemtype={$itemtype}&several=1'>\n <strong>" . $LANG['networking'][46] . "</strong></a></td>\n"; echo "</tr></table></div>\n"; } initNavigateListItems('NetworkPort', $item->getTypeName() . " = " . $item->getName()); $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$ID}'\n AND `itemtype` = '{$itemtype}'\n ORDER BY `name`,\n `logical_number`"; if ($result = $DB->query($query)) { echo "<div class='spaced'>"; if ($DB->numrows($result) != 0) { $colspan = 9; if ($withtemplate != 2) { if ($canedit) { $colspan++; echo "\n<form id='networking_ports{$rand}' name='networking_ports{$rand}' method='post'\n action='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php'>\n"; } } echo "<table class='tab_cadre_fixe'>\n"; echo "<tr><th colspan='{$colspan}'>\n"; if ($DB->numrows($result) == 1) { echo $LANG['networking'][12]; } else { echo $LANG['networking'][11]; } echo " : " . $DB->numrows($result) . "</th></tr>\n"; echo "<tr>"; if ($withtemplate != 2 && $canedit) { echo "<th> </th>\n"; } echo "<th>#</th>\n"; echo "<th>" . $LANG['common'][16] . "</th>\n"; echo "<th>" . $LANG['networking'][51] . "</th>\n"; echo "<th>" . $LANG['networking'][14] . "<br>" . $LANG['networking'][15] . "</th>\n"; echo "<th>" . $LANG['networking'][60] . " / " . $LANG['networking'][61] . "<br>" . $LANG['networking'][59] . "</th>\n"; echo "<th>" . $LANG['networking'][56] . "</th>\n"; echo "<th>" . $LANG['common'][65] . "</th>\n"; echo "<th>" . $LANG['networking'][17] . " :</th>\n"; echo "<th>" . $LANG['networking'][14] . "<br>" . $LANG['networking'][15] . "</th></tr>\n"; $i = 0; $netport = new NetworkPort(); while ($devid = $DB->fetch_row($result)) { $netport->getFromDB(current($devid)); addToNavigateListItems('NetworkPort', $netport->fields["id"]); echo "<tr class='tab_bg_1'>\n"; if ($withtemplate != 2 && $canedit) { echo "<td class='center' width='20'>"; echo "<input type='checkbox' name='del_port[" . $netport->fields["id"] . "]' value='1'>"; echo "</td>\n"; } echo "<td class='center'><strong>"; if ($canedit && $withtemplate != 2) { echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">"; } echo $netport->fields["logical_number"]; if ($canedit && $withtemplate != 2) { echo "</a>"; } echo "</strong>"; showToolTip($netport->fields['comment']); echo "</td>\n"; echo "<td>" . $netport->fields["name"] . "</td>\n"; echo "<td>" . Dropdown::getDropdownName("glpi_netpoints", $netport->fields["netpoints_id"]) . "</td>\n"; echo "<td>" . $netport->fields["ip"] . "<br>" . $netport->fields["mac"] . "</td>\n"; echo "<td>" . $netport->fields["netmask"] . " / " . $netport->fields["subnet"] . "<br>" . $netport->fields["gateway"] . "</td>\n"; // VLANs echo "<td>"; NetworkPort_Vlan::showForNetworkPort($netport->fields["id"], $canedit, $withtemplate); echo "</td>\n"; echo "<td>" . Dropdown::getDropdownName("glpi_networkinterfaces", $netport->fields["networkinterfaces_id"]) . "</td>\n"; echo "<td width='300' class='tab_bg_2'>"; self::showConnection($item, $netport, $withtemplate); echo "</td>\n"; echo "<td class='tab_bg_2'>"; if ($netport->getContact($netport->fields["id"])) { echo $netport->fields["ip"] . "<br>"; echo $netport->fields["mac"]; } echo "</td></tr>\n"; } echo "</table>\n"; if ($canedit && $withtemplate != 2) { openArrowMassive("networking_ports{$rand}", true); Dropdown::showForMassiveAction('NetworkPort'); closeArrowMassive(); } if ($canedit && $withtemplate != 2) { echo "</form>"; } } else { echo "<table class='tab_cadre_fixe'><tr><th>" . $LANG['networking'][10] . "</th></tr>"; echo "</table>"; } echo "</div>"; } }
/** * Print the validation list into ticket * * @param $ticket class **/ function showSummary($ticket) { global $DB, $LANG, $CFG_GLPI; if (!haveRight('validate_ticket', 1) && !haveRight('create_validation', 1)) { return false; } $tID = $ticket->fields['id']; //$canadd = haveRight("create_validation", "1"); $tmp = array('tickets_id' => $tID); $canadd = $this->can(-1, 'w', $tmp); $rand = mt_rand(); echo "<div id='viewfollowup" . $tID . "{$rand}'></div>\n"; if ($canadd) { echo "<script type='text/javascript' >\n"; echo "function viewAddValidation" . $tID . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'tickets_id' => $tID, 'id' => -1); ajaxUpdateItemJsCode("viewfollowup" . $tID . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewfollowup.php", $params, false); echo "};"; echo "</script>\n"; if ($ticket->fields["status"] != 'solved' && $ticket->fields["status"] != 'closed') { echo "<div class='center'><a href='javascript:viewAddValidation" . $tID . "{$rand}();'>"; echo $LANG['validation'][1] . "</a></div><br>\n"; } } $query = "SELECT *\n FROM `" . $this->getTable() . "`\n WHERE `tickets_id` = '" . $ticket->getField('id') . "'"; if (!$canadd) { $query .= " AND `users_id_validate` = '" . getLoginUserID() . "' "; } $query .= " ORDER BY submission_date DESC"; $result = $DB->query($query); $number = $DB->numrows($result); if ($number) { $colonnes = array($LANG['validation'][2], $LANG['validation'][3], $LANG['validation'][18], $LANG['validation'][5], $LANG['validation'][4], $LANG['validation'][21], $LANG['validation'][6]); $nb_colonnes = count($colonnes); echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='" . $nb_colonnes . "'>" . $LANG['validation'][7] . "</th></tr>"; echo "<tr>"; foreach ($colonnes as $colonne) { echo "<th>" . $colonne . "</th>"; } echo "</tr>"; initNavigateListItems('TicketValidation', $LANG['validation'][26] . " = " . $ticket->fields['name']); while ($row = $DB->fetch_assoc($result)) { $canedit = $this->can($row["id"], 'w'); addToNavigateListItems('TicketValidation', $row["id"]); $bgcolor = $this->getStatusColor($row['status']); $status = $this->getStatus($row['status']); echo "<tr class='tab_bg_1' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditValidation" . $ticket->fields['id'] . $row["id"] . "{$rand}();\"" : '') . " id='viewfollowup" . $this->fields['tickets_id'] . $row["id"] . "{$rand}'>"; echo "<td>"; if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditValidation" . $ticket->fields['id'] . $row["id"] . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'tickets_id' => $this->fields["tickets_id"], 'id' => $row["id"]); ajaxUpdateItemJsCode("viewfollowup" . $ticket->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewfollowup.php", $params, false); echo "};"; echo "</script>\n"; } echo "<div style='background-color:" . $bgcolor . ";'>" . $status . "</div></td>"; if ($ticket->can($ticket->fields['id'], 'r') && !strstr($ticket->fields["status"], "solved") && !strstr($ticket->fields["status"], "closed")) { $link_validation = getItemTypeFormURL('TicketValidation'); echo "<td>" . convDateTime($row["submission_date"]) . "</td>"; } else { echo "<td>" . convDateTime($row["submission_date"]) . "</a></td>"; } echo "<td>" . getUserName($row["users_id"]) . "</td>"; echo "<td>" . $row["comment_submission"] . "</td>"; echo "<td>" . convDateTime($row["validation_date"]) . "</td>"; echo "<td>" . getUserName($row["users_id_validate"]) . "</td>"; echo "<td>" . $row["comment_validation"] . "</td>"; echo "</tr>"; } echo "</table>"; } else { echo "<div class='center b'>" . $LANG['search'][15] . "</div>"; } }
/** * Show contacts asociated to an enterprise **/ function showContacts() { global $DB, $CFG_GLPI, $LANG; $instID = $this->fields['id']; if (!$this->can($instID, 'r')) { return false; } $canedit = $this->can($instID, 'w'); $query = "SELECT `glpi_contacts`.*,\n `glpi_contacts_suppliers`.`id` AS ID_ent,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contacts_suppliers`, `glpi_contacts`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contacts`.`entities_id`)\n WHERE `glpi_contacts_suppliers`.`contacts_id`=`glpi_contacts`.`id`\n AND `glpi_contacts_suppliers`.`suppliers_id` = '{$instID}'" . getEntitiesRestrictRequest(" AND", "glpi_contacts", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`, `glpi_contacts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<div class='firstbloc'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='9'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][40]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][41]; } else { echo $LANG['financial'][46]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['help'][35] . "</th>"; echo "<th>" . $LANG['help'][35] . " 2</th>"; echo "<th>" . $LANG['common'][42] . "</th>"; echo "<th>" . $LANG['financial'][30] . "</th>"; echo "<th>" . $LANG['setup'][14] . "</th>"; echo "<th>" . $LANG['common'][17] . "</th>"; echo "<th> </th></tr>"; $used = array(); if ($number) { initNavigateListItems('Contact', $LANG['financial'][26] . " = " . $this->fields['name']); while ($data = $DB->fetch_array($result)) { $ID = $data["ID_ent"]; $used[$data["id"]] = $data["id"]; addToNavigateListItems('Contact', $data["id"]); echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contact.form.php?id=" . $data["id"] . "'>" . $data["name"] . " " . $data["firstname"] . "</a></td>"; echo "<td class='center' width='100'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]) . "</td>"; echo "<td class='center' width='100'>" . $data["phone"] . "</td>"; echo "<td class='center' width='100'>" . $data["phone2"] . "</td>"; echo "<td class='center' width='100'>" . $data["mobile"] . "</td>"; echo "<td class='center' width='100'>" . $data["fax"] . "</td>"; echo "<td class='center'>"; echo "<a href='mailto:" . $data["email"] . "'>" . $DB->result($result, $i, "glpi_contacts.email") . "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contacttypes", $data["contacttypes_id"]) . "</td>"; echo "<td class='center' class='tab_bg_2'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contact.form.php?deletecontactsupplier=1&id={$ID}&contacts_id=" . $data["id"] . "'><img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td></tr>"; $i++; } } echo "</table></div>"; if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_contacts", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_contacts", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<div class='spaced'>"; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contact.form.php\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . $LANG['financial'][33] . "</tr>"; echo "<tr><td class='tab_bg_2 center'>"; echo "<input type='hidden' name='suppliers_id' value='{$instID}'>"; Dropdown::show('Contact', array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"])); echo "</td><td class='tab_bg_2 center'>"; echo "<input type='submit' name='addcontactsupplier' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td></tr>"; } echo "</table></form></div>"; } }
static function showListForUser($userID) { global $DB, $CFG_GLPI, $LANG; if (!haveRight("show_all_ticket", "1")) { return false; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE (`glpi_tickets_users`.`users_id` = '{$userID}'\n AND `glpi_tickets_users`.`type` = " . self::REQUESTER . ") " . 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'>"; if ($number > 0) { $user = new User(); $user->getFromDB($userID); initNavigateListItems('Ticket', $LANG['common'][34] . " = " . $user->getName()); $options['reset'] = 'reset'; $options['field'][0] = 4; // status $options['searchtype'][0] = 'equals'; $options['contains'][0] = $userID; $options['link'][0] = 'AND'; echo "<tr><th colspan='11'>"; if ($number == 1) { echo $LANG['job'][10] . " : " . $number; echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&') . "'>" . $LANG['buttons'][40] . "</a></SPAN>"; } else { echo $LANG['job'][8] . " : " . $number; echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&') . "'>" . $LANG['buttons'][40] . "</a></SPAN>"; } echo "</th></tr>"; self::commonListHeader(HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { addToNavigateListItems('Ticket', $data["id"]); self::showShort($data["id"], 0); } } else { echo "<tr><th>" . $LANG['joblist'][8] . "</th></tr>"; } echo "</table></div>"; }
/** * Print the form for devices linked to a computer or a template * * @param $computer Computer object * @param $withtemplate='' boolean : template or basic computer * * @return Nothing (display) **/ static function showForComputer(Computer $computer, $withtemplate = '') { global $DB, $LANG; $devtypes = self::getDeviceTypes(); $ID = $computer->getField('id'); if (!$computer->can($ID, 'r')) { return false; } $canedit = $withtemplate != 2 && $computer->can($ID, 'w'); echo "<div class='spaced'>"; if ($canedit) { echo "<form name='form_device_action' action='" . getItemTypeFormURL(__CLASS__) . "' method='post'>"; echo "<input type='hidden' name='computers_id' value='{$ID}'>"; } echo "<table class='tab_cadre_fixe' >"; echo "<tr><th colspan='63'>" . $LANG['title'][30] . "</th></tr>"; $nb = 0; $specificity_units = array('DeviceProcessor' => $LANG['setup'][35], 'DeviceMemory' => $LANG['common'][82], 'DeviceHardDrive' => $LANG['common'][82], 'DeviceGraphicCard' => $LANG['common'][82]); foreach ($devtypes as $itemtype) { initNavigateListItems($itemtype, $computer->getTypeName() . " = " . $computer->getName()); $device = new $itemtype(); $specificities = $device->getSpecifityLabel(); $specif_fields = array_keys($specificities); $specif_text = implode(',', $specif_fields); if (!empty($specif_text)) { $specif_text = " ," . $specif_text . " "; } $linktable = getTableForItemType('Computer_' . $itemtype); $fk = getForeignKeyFieldForTable(getTableForItemType($itemtype)); $query = "SELECT COUNT(*) AS NB,\n `id`,\n `{$fk}`\n {$specif_text}\n FROM `{$linktable}`\n WHERE `computers_id` = '{$ID}'\n GROUP BY `{$fk}` {$specif_text}"; $prev = ''; foreach ($DB->request($query) as $data) { addToNavigateListItems($itemtype, $data[$fk]); if ($device->getFromDB($data[$fk])) { echo "<tr class='tab_bg_2'>"; echo "<td class='center'>"; Dropdown::showInteger("quantity_" . $itemtype . "_" . $data['id'], $data['NB']); echo "</td><td>"; if ($device->canCreate()) { echo "<a href='" . $device->getSearchURL() . "'>" . $device->getTypeName() . "</a>"; } else { echo $device->getTypeName(); } echo "</td><td>" . $device->getLink() . "</td>"; $spec = $device->getFormData(); if (isset($spec['label']) && count($spec['label'])) { $colspan = 60 / count($spec['label']); foreach ($spec['label'] as $i => $label) { if (isset($spec['value'][$i])) { echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo $spec['value'][$i] . "</td>"; } else { if ($canedit) { // Specificity echo "<td class='right' colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo "<input type='text' name='value_" . $itemtype . "_" . $data['id'] . "' value='" . $data['specificity'] . "' size='" . $spec['size'] . "'>"; if (isset($specificity_units[$device->getType()])) { echo ' ' . $specificity_units[$device->getType()]; } echo "</td>"; } else { echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . " : "; echo $data['specificity']; if (isset($specificity_units[$device->getType()])) { echo ' ' . $specificity_units[$device->getType()]; } echo "</td>"; } } } } else { echo "<td colspan='60'> </td>"; } echo "</tr>"; $nb++; } } } if ($canedit) { if ($nb > 0) { echo "<tr><td colspan='63' class='tab_bg_1 center'>"; echo "<input type='submit' class='submit' name='updateall' value='" . $LANG['buttons'][7] . "'></td></tr>"; } echo "<tr><td colspan='63' class='tab_bg_1 center'>"; echo $LANG['devices'][0] . " : "; Dropdown::showAllItems('items_id', '', 0, -1, $devtypes); echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>"; echo "</tr></table></form>"; } else { echo "</table>"; } echo "</div>"; }
/** * Show Versions of a software * * @param $soft Software object * @return nothing **/ static function showForSoftware($soft) { global $DB, $CFG_GLPI, $LANG; $softwares_id = $soft->getField('id'); if (!$soft->can($softwares_id, 'r')) { return false; } $canedit = $soft->can($softwares_id, "w"); echo "<div class='spaced'>"; $query = "SELECT `glpi_softwareversions`.*,\n `glpi_states`.`name` AS sname\n FROM `glpi_softwareversions`\n LEFT JOIN `glpi_states` ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `softwares_id` = '{$softwares_id}'\n ORDER BY `name`"; initNavigateListItems('SoftwareVersion', $LANG['help'][31] . " = " . $soft->fields["name"]); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { echo "<table class='tab_cadre'><tr>"; echo "<th> " . $LANG['software'][5] . " </th>"; echo "<th> " . $LANG['state'][0] . " </th>"; echo "<th> " . $LANG['setup'][5] . " </th>"; echo "<th> " . $LANG['software'][19] . " </th>"; echo "<th> " . $LANG['common'][25] . " </th>"; echo "</tr>\n"; for ($tot = $nb = 0; $data = $DB->fetch_assoc($result); $tot += $nb) { addToNavigateListItems('SoftwareVersion', $data['id']); $nb = Computer_SoftwareVersion::countForVersion($data['id']); echo "<tr class='tab_bg_2'>"; echo "<td><a href='softwareversion.form.php?id=" . $data['id'] . "'>"; echo $data['name'] . (empty($data['name']) ? $data['id'] : "") . "</a></td>"; echo "<td>" . $data['sname'] . "</td>"; echo "<td class='right'>" . Dropdown::getDropdownName('glpi_operatingsystems', $data['operatingsystems_id']); echo "</td>"; echo "<td class='right'>{$nb} </td>"; echo "<td>" . $data['comment'] . "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td class='right b' colspan='3'>" . $LANG['common'][33] . "</td>"; echo "<td class='right b'>{$tot} </td><td>"; if ($canedit) { echo "<a href='softwareversion.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][7] . "</a>"; } echo "</td></tr>"; echo "</table>\n"; } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['search'][15] . "</th></tr>"; if ($canedit) { echo "<tr class='tab_bg_2'><td class='center'>"; echo "<a href='softwareversion.form.php?softwares_id={$softwares_id}'>" . $LANG['software'][7] . "</a></td></tr>"; } echo "</table>\n"; } } echo "</div>"; }
/** * Print an HTML array of contract associated to an object * * *@param $item CommonDBTM : object wanted *@param $withtemplate='' not used (to be deleted) * *@return Nothing (display) * **/ static function showAssociated(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI, $LANG; $itemtype = $item->getType(); $ID = $item->fields['id']; if (!haveRight("contract", "r") || !$item->can($ID, "r")) { return false; } $canedit = $item->can($ID, "w"); $query = "SELECT `glpi_contracts_items`.*\n FROM `glpi_contracts_items`,\n `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n AND `glpi_contracts_items`.`items_id` = '{$ID}'\n AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_contracts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<div class='spaced'>"; if ($withtemplate != 2) { echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/contract.form.php\">"; } echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='8'>"; if ($number == 0) { echo $LANG['financial'][58]; } else { if ($number == 1) { echo $LANG['financial'][63]; } else { echo $LANG['financial'][66]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][4] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['financial'][26] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['financial'][8] . "</th>"; if ($withtemplate != 2) { echo "<th> </th>"; } echo "</tr>"; if ($number > 0) { initNavigateListItems('Contract', $item->getTypeName() . " = " . $item->getName()); } $contracts = array(); while ($i < $number) { $cID = $DB->result($result, $i, "contracts_id"); addToNavigateListItems('Contract', $cID); $contracts[] = $cID; $assocID = $DB->result($result, $i, "id"); $con = new Contract(); $con->getFromDB($cID); echo "<tr class='tab_bg_1" . ($con->fields["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>"; echo "<strong>" . $con->fields["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($con->fields["name"])) { echo " (" . $con->fields["id"] . ")"; } echo "</strong></a></td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_entities", $con->fields["entities_id"]) . "</td>"; echo "<td class='center'>" . $con->fields["num"] . "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . $con->getSuppliersNames() . "</td>"; echo "<td class='center'>" . convDate($con->fields["begin_date"]) . "</td>"; echo "<td class='center'>" . $con->fields["duration"] . " " . $LANG['financial'][57]; if ($con->fields["begin_date"] != '' && !empty($con->fields["begin_date"])) { echo " -> " . getWarrantyExpir($con->fields["begin_date"], $con->fields["duration"]); } echo "</td>"; if ($withtemplate != 2) { echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deleteitem=deleteitem&id={$assocID}&contracts_id={$cID}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td>"; } echo "</tr>"; $i++; } $q = "SELECT *\n FROM `glpi_contracts`\n WHERE `is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_contracts", "entities_id", $item->getEntityID(), true); $result = $DB->query($q); $nb = $DB->numrows($result); if ($canedit) { if ($withtemplate != 2 && $nb > count($contracts)) { echo "<tr class='tab_bg_1'><td class='right' colspan='3'>"; echo "<input type='hidden' name='items_id' value='{$ID}'>"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; self::dropdown(array('entity' => $item->getEntityID(), 'used' => $contracts)); echo "</td><td class='center'>"; echo "<input type='submit' name='additem' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td>"; echo "<td> </td><td> </td><td> </td><td> </td></tr>"; } } echo "</table>"; if ($withtemplate != 2) { echo "</form>"; } echo "</div>"; }