Get the massive action checkbox
static public getMassiveActionCheckBox ( $itemtype, $id, array $options = [] ) : get | ||
$itemtype | Massive action itemtype | |
$id | ID of the item | |
$options | array | array |
return | get | checkbox |
/** * Display datas extracted from DB * * @param $data array of search datas prepared to get datas * * @return nothing **/ static function displayDatas(array &$data) { global $CFG_GLPI; $item = null; if (class_exists($data['itemtype'])) { $item = new $data['itemtype'](); } $rand = mt_rand(); if (!isset($data['data']) || !isset($data['data']['totalcount'])) { return false; } // Contruct Pager parameters $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&'); $parameters = "sort=" . $data['search']['sort'] . "&order=" . $data['search']['order'] . '&' . $globallinkto; if (isset($_GET['_in_modal'])) { $parameters .= "&_in_modal=1"; } // Global search header if ($data['display_type'] == self::GLOBAL_SEARCH) { if ($data['item']) { echo "<div class='center'><h2>" . $data['item']->getTypeName(); // More items if ($data['data']['totalcount'] > $data['search']['start'] + self::GLOBAL_DISPLAY_COUNT) { echo " <a href='" . $data['search']['target'] . "?{$parameters}'>" . __('All') . "</a>"; } echo "</h2></div>\n"; } else { return false; } } // If the begin of the view is before the number of items if ($data['data']['count'] > 0) { // Display pager only for HTML if ($data['display_type'] == self::HTML_OUTPUT) { // For plugin add new parameter if available if ($plug = isPluginItemType($data['itemtype'])) { $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport'; if (function_exists($function)) { $out = $function($data['itemtype']); if (is_array($out) && count($out)) { $parameters .= Toolbox::append_params($out, '&'); } } } $search_config_top = ""; $search_config_bottom = ""; if (!isset($_GET['_in_modal']) && Session::haveRightsOr('search_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL))) { $search_config_top = $search_config_bottom = "<div class='pager_controls'><img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config_top .= " class='pointer' onClick=\""; $search_config_top .= Html::jsGetElementbyID('search_config_top') . ".dialog('open');\">"; $search_config_bottom .= " class='pointer' onClick=\""; $search_config_bottom .= Html::jsGetElementbyID('search_config_bottom') . ".dialog('open');\">"; $search_config_top .= Ajax::createIframeModalWindow('search_config_top', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false)); $search_config_bottom .= Ajax::createIframeModalWindow('search_config_bottom', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false)); } if ($item !== null && $item->maybeDeleted()) { $delete_ctrl = self::isDeletedSwitch($data['search']['is_deleted']); $search_config_top .= $delete_ctrl; } Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top); $search_config_top .= "</div>"; $search_config_bottom .= "</div>"; } // Define begin and end var for loop // Search case $begin_display = $data['data']['begin']; $end_display = $data['data']['end']; // Form to massive actions $isadmin = $data['item'] && $data['item']->canUpdate(); if (!$isadmin && InfoCom::canApplyOn($data['itemtype'])) { $isadmin = Infocom::canUpdate() || Infocom::canCreate(); } if ($data['itemtype'] != 'AllAssets') { $showmassiveactions = count(MassiveAction::getAllMassiveActions($data['item'], $data['search']['is_deleted'])); } else { $showmassiveactions = true; } $massformid = 'massform' . $data['itemtype']; if ($showmassiveactions && $data['display_type'] == self::HTML_OUTPUT) { Html::openMassiveActionsForm($massformid); $massiveactionparams = $data['search']['massiveactionparams']; $massiveactionparams['num_displayed'] = $end_display - $begin_display; $massiveactionparams['fixed'] = false; $massiveactionparams['is_deleted'] = $data['search']['is_deleted']; $massiveactionparams['container'] = $massformid; Html::showMassiveActions($massiveactionparams); } // Compute number of columns to display // Add toview elements $nbcols = count($data['data']['cols']); if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $nbcols++; } // Display List Header echo self::showHeader($data['display_type'], $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; $headers_line_top .= self::showBeginHeader($data['display_type']); $headers_line_top .= self::showNewLine($data['display_type']); if ($data['display_type'] == self::HTML_OUTPUT) { // $headers_line_bottom .= self::showBeginHeader($data['display_type']); $headers_line_bottom .= self::showNewLine($data['display_type']); } $header_num = 1; if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $headers_line_top .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']); if ($data['display_type'] == self::HTML_OUTPUT) { $headers_line_bottom .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']); } } // Display column Headers for toview items $metanames = array(); foreach ($data['data']['cols'] as $key => $val) { $linkto = ''; if (!$val['meta'] && (!isset($val['searchopt']['nosort']) || !$val['searchopt']['nosort'])) { $linkto = $data['search']['target'] . (strpos($data['search']['target'], '?') ? '&' : '?') . "itemtype=" . $data['itemtype'] . "&sort=" . $val['id'] . "&order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $data['search']['start'] . "&" . $globallinkto; } $name = $val["name"]; // prefix by group name (corresponding to optgroup in dropdown) if exists if (isset($val['groupname'])) { $name = $val['groupname'] . " - " . $name; } // Not main itemtype add itemtype to display if ($data['itemtype'] != $val['itemtype']) { if (!isset($metanames[$val['itemtype']])) { if ($metaitem = getItemForItemtype($val['itemtype'])) { $metanames[$val['itemtype']] = $metaitem->getTypeName(); } } $name = sprintf(__('%1$s - %2$s'), $metanames[$val['itemtype']], $val["name"]); } $headers_line .= self::showHeaderItem($data['display_type'], $name, $header_num, $linkto, !$val['meta'] && $data['search']['sort'] == $val['id'], $data['search']['order']); } // Add specific column Header if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $headers_line .= self::showHeaderItem($data['display_type'], __('Item type'), $header_num); } // End Line for column headers $headers_line .= self::showEndLine($data['display_type']); $headers_line_top .= $headers_line; if ($data['display_type'] == self::HTML_OUTPUT) { $headers_line_bottom .= $headers_line; } $headers_line_top .= self::showEndHeader($data['display_type']); // $headers_line_bottom .= self::showEndHeader($data['display_type']); echo $headers_line_top; // Init list of items displayed if ($data['display_type'] == self::HTML_OUTPUT) { Session::initNavigateListItems($data['itemtype']); } // Num of the row (1=header_line) $row_num = 1; $massiveaction_field = 'id'; if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $massiveaction_field = 'refID'; } $typenames = array(); // Display Loop foreach ($data['data']['rows'] as $rowkey => $row) { // Column num $item_num = 1; $row_num++; // New line echo self::showNewLine($data['display_type'], $row_num % 2, $data['search']['is_deleted']); $current_type = isset($row['TYPE']) ? $row['TYPE'] : $data['itemtype']; $massiveaction_type = $current_type; if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { $massiveaction_type = $data['itemtype']; } // Add item in item list Session::addToNavigateListItems($current_type, $row["id"]); if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $tmpcheck = ""; if ($data['itemtype'] == 'Entity' && !in_array($row["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $tmpcheck = Html::getMassiveActionCheckBox($massiveaction_type, $row[$massiveaction_field]); } } echo self::showItem($data['display_type'], $tmpcheck, $item_num, $row_num, "width='10'"); } // Print other toview items foreach ($data['data']['cols'] as $colkey => $col) { if (!$col['meta']) { echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num, self::displayConfigItem($data['itemtype'], $col['id'], $row, $colkey)); } else { // META case echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num); } } if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) { if (!isset($typenames[$row["TYPE"]])) { if ($itemtmp = getItemForItemtype($row["TYPE"])) { $typenames[$row["TYPE"]] = $itemtmp->getTypeName(); } } echo self::showItem($data['display_type'], $typenames[$row["TYPE"]], $item_num, $row_num); } // End Line echo self::showEndLine($data['display_type']); } // Create title $title = ''; if ($data['display_type'] == self::PDF_OUTPUT_LANDSCAPE || $data['display_type'] == self::PDF_OUTPUT_PORTRAIT) { $title = self::computeTitle($data); } if ($data['display_type'] == self::HTML_OUTPUT) { echo $headers_line_bottom; } // Display footer echo self::showFooter($data['display_type'], $title); // Delete selected item if ($data['display_type'] == self::HTML_OUTPUT) { if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); // End form for delete item Html::closeForm(); } else { echo "<br>"; } } if ($data['display_type'] == self::HTML_OUTPUT) { // In case of HTML display Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom); } } else { if ($item !== null && $item->maybeDeleted()) { echo "<div class='center'>" . self::isDeletedSwitch($data['search']['is_deleted']) . "</div><br/>"; } echo self::showError($data['display_type']); } }
function displayValue($output_type, $row) { if (!isset($row[$this->name]) || !$row[$this->name]) { return ''; } if ($this->obj && $output_type == Search::HTML_OUTPUT && $this->obj->can($row[$this->name], UPDATE)) { return Html::getMassiveActionCheckBox(get_class($this->obj), $row[$this->name]); } return ''; }
/** Show LDAP users to add or synchronise * * @return nothing **/ static function showLdapUsers() { global $CFG_GLPI; $values['order'] = 'DESC'; $values['start'] = 0; foreach ($_SESSION['ldap_import'] as $option => $value) { $values[$option] = $value; } $rand = mt_rand(); $results = array(); $limitexceeded = false; $ldap_users = self::getAllUsers($values, $results, $limitexceeded); if (is_array($ldap_users)) { $numrows = count($ldap_users); if ($numrows > 0) { self::displaySizeLimitWarning($limitexceeded); Html::printPager($values['start'], $numrows, $_SERVER['PHP_SELF'], ''); // delete end array_splice($ldap_users, $values['start'] + $_SESSION['glpilist_limit']); // delete begin if ($values['start'] > 0) { array_splice($ldap_users, 0, $values['start']); } $form_action = ''; $textbutton = ''; if ($_SESSION['ldap_import']['mode']) { $textbutton = _x('button', 'Synchronize'); $form_action = __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'sync'; } else { $textbutton = _x('button', 'Import'); $form_action = __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'import'; } Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => min(count($ldap_users), $_SESSION['glpilist_limit']), 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array($form_action => $textbutton)); Html::showMassiveActions($massiveactionparams); echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; $num = 0; echo Search::showHeaderItem(Search::HTML_OUTPUT, _n('User', 'Users', Session::getPluralNumber()), $num, $_SERVER['PHP_SELF'] . "?order=" . ($values['order'] == "DESC" ? "ASC" : "DESC")); echo "<th>" . __('Last update in the LDAP directory') . "</th>"; if ($_SESSION['ldap_import']['mode']) { echo "<th>" . __('Last update in GLPI') . "</th>"; } echo "</tr>"; foreach ($ldap_users as $userinfos) { $link = $user = $userinfos["user"]; if (isset($userinfos['id']) && User::canView()) { $link = "<a href='" . Toolbox::getItemTypeFormURL('User') . '?id=' . $userinfos['id'] . "'>{$user}</a>"; } if (isset($userinfos["timestamp"])) { $stamp = $userinfos["timestamp"]; } else { $stamp = ''; } if (isset($userinfos["date_sync"])) { $date_sync = $userinfos["date_sync"]; } else { $date_sync = ''; } echo "<tr class='tab_bg_2 center'>"; //Need to use " instead of ' because it doesn't work with names with ' inside ! echo "<td>"; echo Html::getMassiveActionCheckBox(__CLASS__, $user); //echo "<input type='checkbox' name=\"item[" . $user . "]\" value='1'>"; echo "</td>"; echo "<td>" . $link . "</td>"; if ($stamp != '') { echo "<td>" . Html::convDateTime(date("Y-m-d H:i:s", $stamp)) . "</td>"; } else { echo "<td> </td>"; } if ($_SESSION['ldap_import']['mode']) { if ($date_sync != '') { echo "<td>" . Html::convDateTime($date_sync) . "</td>"; } else { echo "<td> </td>"; } } echo "</tr>"; } echo "<tr>"; echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; $num = 0; echo Search::showHeaderItem(Search::HTML_OUTPUT, _n('User', 'Users', Session::getPluralNumber()), $num, $_SERVER['PHP_SELF'] . "?order=" . ($values['order'] == "DESC" ? "ASC" : "DESC")); echo "<th>" . __('Last update in the LDAP directory') . "</th>"; if ($_SESSION['ldap_import']['mode']) { echo "<th>" . __('Last update in GLPI') . "</th>"; } echo "</tr>"; echo "</table>"; $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); Html::printPager($values['start'], $numrows, $_SERVER['PHP_SELF'], ''); } else { echo "<div class='center b'>" . ($_SESSION['ldap_import']['mode'] ? __('No user to be synchronized') : __('No user to be imported')) . "</div>"; } } else { echo "<div class='center b'>" . ($_SESSION['ldap_import']['mode'] ? __('No user to be synchronized') : __('No user to be imported')) . "</div>"; } }
/** * Display a line for a ticket * * @param $id Integer ID of the ticket * @param $followups Boolean show followup columns * @param $output_type Integer type of output (default Search::HTML_OUTPUT) * @param $row_num Integer row number (default 0) * @param $id_for_massaction Integer default 0 means no massive action (default 0) * */ static function showShort($id, $followups, $output_type = Search::HTML_OUTPUT, $row_num = 0, $id_for_massaction = 0) { global $CFG_GLPI; $rand = mt_rand(); /// TODO to be cleaned. Get datas and clean display links // Prints a job in short form // Should be called in a <table>-segment // Print links or not in case of user view // Make new job object and fill it from database, if success, print it $job = new self(); $candelete = Session::haveRight("delete_ticket", "1"); $canupdate = Session::haveRight("update_ticket", "1"); $showprivate = Session::haveRight("show_full_ticket", "1"); $align = "class='center"; $align_desc = "class='left"; if ($followups) { $align .= " top'"; $align_desc .= " top'"; } else { $align .= "'"; $align_desc .= "'"; } if ($job->getFromDB($id)) { $item_num = 1; $bgcolor = $_SESSION["glpipriority_" . $job->fields["priority"]]; echo Search::showNewLine($output_type, $row_num % 2); $check_col = ''; if (($candelete || $canupdate) && $output_type == Search::HTML_OUTPUT && $id_for_massaction) { $check_col = Html::getMassiveActionCheckBox(__CLASS__, $id_for_massaction); } echo Search::showItem($output_type, $check_col, $item_num, $row_num, $align); // First column $first_col = sprintf(__('%1$s: %2$s'), __('ID'), $job->fields["id"]); if ($output_type == Search::HTML_OUTPUT) { $first_col .= "<br><img src='" . self::getStatusIconURL($job->fields["status"]) . "'\n alt=\"" . self::getStatus($job->fields["status"]) . "\" title=\"" . self::getStatus($job->fields["status"]) . "\">"; } else { $first_col = sprintf(__('%1$s - %2$s'), $first_col, self::getStatus($job->fields["status"])); } echo Search::showItem($output_type, $first_col, $item_num, $row_num, $align); // Second column if ($job->fields['status'] == self::CLOSED) { $second_col = sprintf(__('Closed on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['closedate'])); } else { if ($job->fields['status'] == self::SOLVED) { $second_col = sprintf(__('Solved on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['solvedate'])); } else { if ($job->fields['begin_waiting_date']) { $second_col = sprintf(__('Put on hold on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['begin_waiting_date'])); } else { if ($job->fields['due_date']) { $second_col = sprintf(__('%1$s: %2$s'), __('Due date'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['due_date'])); } else { $second_col = sprintf(__('Opened on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['date'])); } } } } echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=130"); // Second BIS column $second_col = Html::convDateTime($job->fields["date_mod"]); echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=90"); // Second TER column if (count($_SESSION["glpiactiveentities"]) > 1) { $second_col = Dropdown::getDropdownName('glpi_entities', $job->fields['entities_id']); echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=100"); } // Third Column echo Search::showItem($output_type, "<span class='b'>" . parent::getPriorityName($job->fields["priority"]) . "</span>", $item_num, $row_num, "{$align} bgcolor='{$bgcolor}'"); // Fourth Column $fourth_col = ""; if (isset($job->users[CommonITILActor::REQUESTER]) && count($job->users[CommonITILActor::REQUESTER])) { foreach ($job->users[CommonITILActor::REQUESTER] as $d) { $userdata = getUserName($d["users_id"], 2); $fourth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); $fourth_col .= "<br>"; } } if (isset($job->groups[CommonITILActor::REQUESTER]) && count($job->groups[CommonITILActor::REQUESTER])) { foreach ($job->groups[CommonITILActor::REQUESTER] as $d) { $fourth_col .= Dropdown::getDropdownName("glpi_groups", $d["groups_id"]); $fourth_col .= "<br>"; } } echo Search::showItem($output_type, $fourth_col, $item_num, $row_num, $align); // Fifth column $fifth_col = ""; if (isset($job->users[CommonITILActor::ASSIGN]) && count($job->users[CommonITILActor::ASSIGN])) { foreach ($job->users[CommonITILActor::ASSIGN] as $d) { $userdata = getUserName($d["users_id"], 2); $fifth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); $fifth_col .= "<br>"; } } if (isset($job->groups[CommonITILActor::ASSIGN]) && count($job->groups[CommonITILActor::ASSIGN])) { foreach ($job->groups[CommonITILActor::ASSIGN] as $d) { $fifth_col .= Dropdown::getDropdownName("glpi_groups", $d["groups_id"]); $fifth_col .= "<br>"; } } if (isset($job->suppliers[CommonITILActor::ASSIGN]) && count($job->suppliers[CommonITILActor::ASSIGN])) { foreach ($job->suppliers[CommonITILActor::ASSIGN] as $d) { $fifth_col .= Dropdown::getDropdownName("glpi_suppliers", $d["suppliers_id"]); $fifth_col .= "<br>"; } } echo Search::showItem($output_type, $fifth_col, $item_num, $row_num, $align); // Sixth Colum $sixth_col = ""; $is_deleted = false; if (!empty($job->fields["itemtype"]) && $job->fields["items_id"] > 0) { if ($item = getItemForItemtype($job->fields["itemtype"])) { if ($item->getFromDB($job->fields["items_id"])) { $is_deleted = $item->isDeleted(); $sixth_col .= $item->getTypeName(); $sixth_col .= "<br><span class='b'>"; if ($item->canView()) { $sixth_col .= $item->getLink(array('linkoption' => $output_type == Search::HTML_OUTPUT)); } else { $sixth_col .= $item->getNameID(); } $sixth_col .= "</span>"; } } } else { if (empty($job->fields["itemtype"])) { $sixth_col = __('General'); } } echo Search::showItem($output_type, $sixth_col, $item_num, $row_num, $is_deleted ? " class='center deleted' " : $align); // Seventh column echo Search::showItem($output_type, "<span class='b'>" . Dropdown::getDropdownName('glpi_itilcategories', $job->fields["itilcategories_id"]) . "</span>", $item_num, $row_num, $align); // Eigth column $eigth_column = "<span class='b'>" . $job->fields["name"] . "</span> "; // Add link if ($job->canViewItem()) { $eigth_column = "<a id='ticket" . $job->fields["id"] . "{$rand}' href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $job->fields["id"] . "\">{$eigth_column}</a>"; if ($followups && $output_type == Search::HTML_OUTPUT) { $eigth_column .= TicketFollowup::showShortForTicket($job->fields["id"]); } else { $eigth_column = sprintf(__('%1$s (%2$s)'), $eigth_column, sprintf(__('%1$s - %2$s'), $job->numberOfFollowups($showprivate), $job->numberOfTasks($showprivate))); } } if ($output_type == Search::HTML_OUTPUT) { $eigth_column = sprintf(__('%1$s %2$s'), $eigth_column, Html::showToolTip($job->fields['content'], array('display' => false, 'applyto' => "ticket" . $job->fields["id"] . $rand))); } echo Search::showItem($output_type, $eigth_column, $item_num, $row_num, $align_desc . "width='300'"); // Finish Line echo Search::showEndLine($output_type); } else { echo "<tr class='tab_bg_2'>"; echo "<td colspan='6' ><i>" . __('No ticket in progress.') . "</i></td></tr>"; } }
/** * Print the HTML array of the Netpoint associated to a Location * * @param $item Location * * @return Nothing (display) **/ static function showForLocation($item) { global $DB, $CFG_GLPI; $ID = $item->getField('id'); $netpoint = new self(); $item->check($ID, READ); $canedit = $item->canEdit($ID); if (isset($_GET["start"])) { $start = intval($_GET["start"]); } else { $start = 0; } $number = countElementsInTable('glpi_netpoints', "`locations_id`='{$ID}'"); if ($canedit) { echo "<div class='first-bloc'>"; // 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'>"; echo "<td class='b'>" . _n('Network outlet', 'Network outlets', 1) . "</td>"; echo "<td>" . __('Name') . "</td><td>"; Html::autocompletionTextField($item, "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=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table>\n"; Html::closeForm(); // 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'>"; echo "<td class='b'>" . _n('Network outlet', 'Network outlets', Session::getPluralNumber()) . "</td>"; echo "<td>" . __('Name') . "</td><td>"; echo "<input type='text' maxlength='100' size='10' name='_before'> "; Dropdown::showNumber('_from', array('value' => 0, 'min' => 0, 'max' => 400)); echo " --> "; Dropdown::showNumber('_to', array('value' => 0, 'min' => 0, 'max' => 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}'>"; echo "<input type='hidden' name='_method' value='AddMulti'></td>"; echo "<td><input type='submit' name='execute' value=\"" . _sx('button', 'Add') . "\"\n class='submit'>"; echo "</td></tr>\n"; echo "</table>\n"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . self::getTypeName(1) . "</th>"; echo "<th>" . __('No item found') . "</th></tr>"; echo "</table>\n"; } else { Html::printAjaxPager(sprintf(__('Network outlets for %s'), $item->getTreeLink()), $start, $number); if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'><tr>"; if ($canedit) { echo "<th width='10'>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; } echo "<th>" . __('Name') . "</th>"; // Name echo "<th>" . __('Comments') . "</th>"; // Comment echo "</tr>\n"; $crit = array('locations_id' => $ID, 'ORDER' => 'name', 'START' => $start, 'LIMIT' => $_SESSION['glpilist_limit']); Session::initNavigateListItems('Netpoint', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($DB->request('glpi_netpoints', $crit) as $data) { Session::addToNavigateListItems('Netpoint', $data["id"]); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</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) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(sprintf(__('Network outlets for %s'), $item->getTreeLink()), $start, $number); } echo "</div>\n"; }
/** * Show users linked to a License * * @param $license SoftwareLicense object * * @return nothing **/ static function showForLicense(SoftwareLicense $license) { global $DB, $CFG_GLPI; $searchID = $license->getField('id'); if (!Software::canView() || !$searchID) { return false; } $canedit = PluginFpsoftwareVersionhelper::checkRights("software", array(CREATE, UPDATE, DELETE, PURGE), "Or"); $canshowuser = User::canView(); if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } //SoftwareLicense ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_users_softwarelicenses`\n INNER JOIN `glpi_users`\n ON (`glpi_users_softwarelicenses`.`users_id`\n = `glpi_users`.`id`)\n WHERE `glpi_users_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'"; $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"] . self::$front_url . "/front/user_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>"; //FOR NOW ALL USERS ARE SHOWN, DON'T KNOW IF THERE SHOULD BE ANY RESTRICTION. //ALSO IT CAUSES A POSSIBILITY TO ONE USER MANY TIMES. User::dropdown(array('right' => 'all')); echo "</td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager Html::printAjaxPager(__('Affected users'), $start, $number); $query = "SELECT `glpi_users_softwarelicenses`.*,\n `glpi_users`.`name` AS username,\n `glpi_users`.`id` AS userid,\n `glpi_users`.`realname` AS userrealname,\n `glpi_users`.`firstname` AS userfirstname,\n `glpi_softwarelicenses`.`name` AS license,\n `glpi_softwarelicenses`.`id` AS lID\n FROM `glpi_users_softwarelicenses`\n INNER JOIN `glpi_softwarelicenses`\n ON (`glpi_users_softwarelicenses`.`softwarelicenses_id`\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_users`\n ON (`glpi_users_softwarelicenses`.`users_id` = `glpi_users`.`id`)\n WHERE `glpi_softwarelicenses`.`id` = '{$searchID}'\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); $rand = mt_rand(); if ($result = $DB->query($query)) { if ($data = $DB->fetch_assoc($result)) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); list($higher_version, $massiveactionparams) = PluginFpsoftwareVersionhelper::massiveActionParams($rand, __CLASS__); // Options to update license $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID); $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id']; Html::showMassiveActions($higher_version ? $massiveactionparams : __CLASS__, $massiveactionparams); } $soft = new Software(); $soft->getFromDB($license->fields['softwares_id']); $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]); $text = sprintf(__('%1$s - ID %2$s'), $text, $license->fields['softwares_id']); Session::initNavigateListItems('User', $text); echo "<table class='tab_cadre_fixehov'>"; $columns = array('username' => __('Username'), 'userrealname' => __('Surname'), 'userfirstname' => __('First name'), 'added' => __('Added')); $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } foreach ($columns as $key => $val) { // Non order column $header_end .= "<th>{$val}</th>"; } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; do { Session::addToNavigateListItems('User', $data["userid"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } if ($canshowuser) { echo "<td><a href='user.form.php?id=" . $data['userid'] . "'>" . $data['username'] . "</a></td>"; } else { echo "<td>" . $data['username'] . "</td>"; } echo "<td>" . $data['userrealname'] . "</td>"; echo "<td>" . $data['userfirstname'] . "</td>"; echo "<td style=\"text-align:center;\">" . $data['added'] . "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo $header_begin . $header_bottom . $header_end; echo "</table>\n"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { // Not found _e('No item found'); } } // Query Html::printAjaxPager(__('Affected users'), $start, $number); echo "</div>\n"; }
/** * Print the mandatory fields * * @since version 0.83 * * @param $tt Ticket Template * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '') { global $DB; $ID = $tt->fields['id']; if (!$tt->getFromDB($ID) || !$tt->can($ID, READ)) { return false; } $canedit = $tt->canEdit($ID); $ttm = new self(); $used = $ttm->getMandatoryFields($ID); $fields = $tt->getAllowedFieldsNames(true); $simplified_fields = $tt->getSimplifiedInterfaceFields(); $both_interfaces = sprintf(__('%1$s + %2$s'), __('Simplified interface'), __('Standard interface')); $rand = mt_rand(); $query = "SELECT `glpi_tickettemplatemandatoryfields`.*\n FROM `glpi_tickettemplatemandatoryfields`\n WHERE (`tickettemplates_id` = '{$ID}')"; if ($result = $DB->query($query)) { $mandatoryfields = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $mandatoryfields[$data['id']] = $data; $used[$data['num']] = $data['num']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a mandatory field') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='right'>"; echo "<input type='hidden' name='tickettemplates_id' value='{$ID}'>"; $select_fields = $fields; foreach ($select_fields as $key => $val) { if (in_array($key, $simplified_fields)) { $select_fields[$key] = sprintf(__('%1$s (%2$s)'), $val, $both_interfaces); } else { $select_fields[$key] = sprintf(__('%1$s (%2$s)'), $val, __('Standard interface')); } } Dropdown::showFromArray('num', $select_fields, array('used' => $used)); echo "</td><td class='center'>"; echo " <input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr class='noHover'><th colspan='3'>"; echo self::getTypeName($DB->numrows($result)); echo "</th></tr>"; if ($numrows) { $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_top .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; $header_bottom .= "<th width='10'>"; $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . __("Profile's interface") . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; foreach ($mandatoryfields as $data) { echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } echo "<td>" . $fields[$data['num']] . "</td>"; echo "<td>"; if (in_array($data['num'], $simplified_fields)) { echo $both_interfaces; } else { _e('Standard interface'); } echo "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; } else { echo "<tr><th colspan='2'>" . __('No item found') . "</th></tr>"; } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; } }
/** * @since version 0.84 * * @param $row HTMLTableRow object (default NULL) * @param $item CommonDBTM object (default NULL) * @param $father HTMLTableCell object (default NULL) * @param $options array **/ static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array()) { global $DB, $CFG_GLPI; $column_name = __CLASS__; if (empty($item)) { if (empty($father)) { return; } $item = $father->getItem(); } switch ($item->getType()) { case 'FQDN': $JOINS = ""; $ORDER = "`glpi_networknames`.`name`"; if (isset($options['order'])) { switch ($options['order']) { case 'name': break; case 'ip': $JOINS = " LEFT JOIN `glpi_ipaddresses`\n ON (`glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`\n AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n AND `glpi_ipaddresses`.`is_deleted` = '0')"; $ORDER = "ISNULL (`glpi_ipaddresses`.`id`),\n `glpi_ipaddresses`.`binary_3`, `glpi_ipaddresses`.`binary_2`,\n `glpi_ipaddresses`.`binary_1`, `glpi_ipaddresses`.`binary_0`"; break; case 'alias': $JOINS = " LEFT JOIN `glpi_networkaliases`\n ON (`glpi_networkaliases`.`networknames_id`\n = `glpi_networknames`.`id`)"; $ORDER = "ISNULL(`glpi_networkaliases`.`name`),\n `glpi_networkaliases`.`name`"; break; } } $query = "SELECT `glpi_networknames`.`id`\n FROM `glpi_networknames`\n {$JOINS}\n WHERE `glpi_networknames`.`fqdns_id` = '" . $item->fields["id"] . "'\n AND `glpi_networknames`.`is_deleted` = '0'\n ORDER BY {$ORDER}"; break; case 'NetworkPort': $query = "SELECT `id`\n FROM `glpi_networknames`\n WHERE `itemtype` = '" . $item->getType() . "'\n AND `items_id` = '" . $item->getID() . "'\n AND `glpi_networknames`.`is_deleted` = '0'"; break; case 'NetworkEquipment': $query = "SELECT `glpi_networknames`.`id`\n FROM `glpi_networknames`, `glpi_networkports`\n WHERE `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n AND `glpi_networkports`.`items_id` ='" . $item->getID() . "'\n AND `glpi_networknames`.`itemtype` = 'NetworkPort'\n AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n AND `glpi_networknames`.`is_deleted` = '0'"; break; } if (isset($options['SQL_options'])) { $query .= " " . $options['SQL_options']; } $canedit = isset($options['canedit']) && $options['canedit']; $createRow = isset($options['createRow']) && $options['createRow']; $options['createRow'] = false; $address = new self(); foreach ($DB->request($query) as $line) { if ($address->getFromDB($line["id"])) { if ($createRow) { $row = $row->createAnotherRow(); } if (isset($options['massiveactionnetworkname']) && $options['massiveactionnetworkname']) { $header = $row->getGroup()->getHeaderByName('Internet', 'delete'); $cell_value = Html::getMassiveActionCheckBox(__CLASS__, $line["id"]); $delete_cell = $row->addCell($header, $cell_value, $father); } $internetName = $address->getInternetName(); if (empty($internetName)) { $internetName = "(" . $line["id"] . ")"; } $content = $internetName; if (Session::haveRight('internet', READ)) { $content = "<a href='" . $address->getLinkURL() . "'>" . $internetName . "</a>"; } if (!isset($options['dont_display'][$column_name])) { $header = $row->getGroup()->getHeaderByName('Internet', $column_name); $name_cell = $row->addCell($header, $content, $father, $address); if (isset($options['display_isDynamic']) && $options['display_isDynamic']) { $dyn_header = $row->getGroup()->getHeaderByName('Internet', $column_name . '_dynamic'); $dynamic_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $name_cell); $father_for_children = $dynamic_cell; } else { $father_for_children = $name_cell; } } else { $father_for_children = $father; } NetworkAlias::getHTMLTableCellsForItem($row, $address, $father_for_children, $options); IPAddress::getHTMLTableCellsForItem($row, $address, $father_for_children, $options); } } }
/** * Show the massive action checkbox * * @since version 0.84 * * @param $itemtype Massive action itemtype * @param $id ID of the item * * @return show checkbox **/ static function showMassiveActionCheckBox($itemtype, $id) { echo Html::getMassiveActionCheckBox($itemtype, $id); }
/** * Print the hidden fields * * @since version 0.83 * * @param $tt Ticket Template * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '') { global $DB; $ID = $tt->fields['id']; if (!$tt->getFromDB($ID) || !$tt->can($ID, "r")) { return false; } $ttm = new self(); $used = $ttm->getHiddenFields($ID); $canedit = $tt->can($ID, "w"); $fields = $tt->getAllowedFieldsNames(false, isset($used['itemtype'])); $rand = mt_rand(); $query = "SELECT `glpi_tickettemplatehiddenfields`.*\n FROM `glpi_tickettemplatehiddenfields`\n WHERE (`tickettemplates_id` = '{$ID}')"; if ($result = $DB->query($query)) { $hiddenfields = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $hiddenfields[$data['id']] = $data; $used[$data['num']] = $data['num']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a hidden field') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='right'>"; echo "<input type='hidden' name='tickettemplates_id' value='{$ID}'>"; Dropdown::showFromArray('num', $fields, array('used' => $used)); echo "</td><td class='center'>"; echo " <input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>"; echo self::getTypeName($DB->numrows($result)); echo "</th></tr>"; if ($numrows) { echo "<tr>"; if ($canedit) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; echo "</tr>"; foreach ($hiddenfields as $data) { echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } echo "<td>" . $fields[$data['num']] . "</td>"; echo "</tr>"; } } else { echo "<tr><th colspan='2'>" . __('No item found') . "</th></tr>"; } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; } }
/** * Generic Search and list function * * Build the query, make the search and list items after a search. * * @param $itemtype item type * @param $params array of parameters may include field, contains, searchtype, sort, order, * start, deleted, link, link2, contains2, field2, itemtype2, searchtype2 * * @return Nothing (display) **/ static function showList($itemtype, array $params) { global $DB, $CFG_GLPI; // Instanciate an object to access method $item = NULL; if ($itemtype != 'AllAssets') { $item = getItemForItemtype($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; } if (in_array('all', $p['field']) && !$CFG_GLPI['allow_search_all']) { Html::displayRightError(); } if (in_array('view', $p['field']) && !$CFG_GLPI['allow_search_view']) { Html::displayRightError(); } // 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 = Toolbox::getItemTypeSearchURL($itemtype); $limitsearchopt = self::getCleanedOptions($itemtype); $blacklist_tables = array(); if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $itemtable = $CFG_GLPI['union_search_type'][$itemtype]; $blacklist_tables[] = getTableForItemType($itemtype); } else { $itemtable = getTableForItemType($itemtype); } $LIST_LIMIT = $_SESSION['glpilist_limit']; // Set display type for export if define $output_type = self::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; // Limit to 10 element if ($_GET['display_type'] == self::GLOBAL_SEARCH) { $LIST_LIMIT = self::GLOBAL_DISPLAY_COUNT; } } // hack for AllAssets if (isset($CFG_GLPI['union_search_type'][$itemtype])) { $entity_restrict = true; } else { $entity_restrict = $item->isEntityAssign(); } self::$output_type = $output_type; $metanames = array(); // Get the items to display $toview = self::addDefaultToView($itemtype); // Add items to display depending of personal prefs $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::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 '" . Toolbox::addslashes_deep($_SESSION['glpiname']) . "' AS currentuser,\n " . 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) { if (!in_array($searchopt[$itemtype][$val]["table"], $blacklist_tables)) { $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)) { if (!in_array($searchopt[$itemtype][$key]["table"], $blacklist_tables)) { $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 (isset($val2['nosearch']) && $val2['nosearch']) { continue; } 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},\n '" . Toolbox::addslashes_deep($_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); if (($citem = getItemForItemtype($ctype)) && $citem->canView()) { // State case if ($itemtype == 'AllAssets') { $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $query_num = str_replace($itemtype, $ctype, $query_num); $query_num .= " AND `{$ctable}`.`id` IS NOT NULL "; // 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); if ($item && $item->maybeDeleted()) { $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery); } $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); if (($citem = getItemForItemtype($ctype)) && $citem->canView()) { if ($first) { $first = false; } else { $QUERY .= " UNION "; } $tmpquery = ""; // AllAssets case if ($itemtype == 'AllAssets') { $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE; if ($itemtype == 'AllAssets') { $tmpquery .= " AND `{$ctable}`.`id` IS NOT NULL "; } // 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' "; } $tmpquery .= $GROUPBY . $HAVING; $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery); $tmpquery = str_replace($itemtype, $ctype, $tmpquery); } 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; if ($item->maybeDeleted()) { $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery); } $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 == self::GLOBAL_SEARCH) { if ($item = getItemForItemtype($itemtype)) { echo "<div class='center'><h2>" . $item->getTypeName(); // More items if ($numrows > $p['start'] + self::GLOBAL_DISPLAY_COUNT) { echo " <a href='{$target}?{$parameters}'>" . __('All') . "</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 == self::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}"; } } } } } $search_config = ""; if (Session::haveRight("search_config", DisplayPreference::GENERAL)) { //|| Session::haveRight("search_config_global",CREATE)) { // Ajax::createModalWindow('searchconfig_window', // $CFG_GLPI['root_doc']."/ajax/searchconfig.php?itemtype=$itemtype", // array('title' => __('Select default items to show'), // 'width' => '1000')); // $tmp = " class='pointer' onClick=\"searchconfig_window.show()\""; $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=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' "; $search_config .= $tmp . ">"; } Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config); } // Define begin and end var for loop // Search case $begin_display = $p['start']; $end_display = min($numrows, $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; } // Form to massive actions $isadmin = $item && $item->canUpdate(); if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) { $isadmin = Infocom::canUpdate() || Infocom::canCreate(); } $showmassiveactions = false; if ($itemtype != 'AllAssets') { $showmassiveactions = count($item->getAllMassiveActions($p['is_deleted'])); if ($showmassiveactions && $output_type == self::HTML_OUTPUT) { Html::openMassiveActionsForm('massform' . $itemtype); $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']); Html::showMassiveActions($itemtype, $massiveactionparams); } } // 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]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && (!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 == self::HTML_OUTPUT) { // HTML display - massive modif $nbcols++; } // Display List Header echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols); // New Line for Header Items Line $headers_line = ''; $headers_line_top = ''; $headers_line_bottom = ''; echo self::showNewLine($output_type); $header_num = 1; if ($output_type == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $headers_line_top .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']); $headers_line_bottom .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $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; } $headers_line .= 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]])) { if ($metaitem = getItemForItemtype($p['itemtype2'][$i])) { $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName(); } } $headers_line .= self::showHeaderItem($output_type, sprintf(__('%1$s - %2$s'), $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') { $headers_line .= self::showHeaderItem($output_type, _n('Cartridge', 'Cartridges', 2), $header_num); } if ($itemtype == 'ConsumableItem') { $headers_line .= self::showHeaderItem($output_type, _n('Consumable', 'Consumables', 2), $header_num); } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $headers_line .= self::showHeaderItem($output_type, __('Item type'), $header_num); } if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) { $headers_line .= self::showHeaderItem($output_type, " ", $header_num); } // End Line for column headers $headers_line .= self::showEndLine($output_type); $headers_line_top .= $headers_line; $headers_line_bottom .= $headers_line; echo $headers_line_top; // 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 == self::HTML_OUTPUT) { Session::initNavigateListItems($itemtype); } // Num of the row (1=header_line) $row_num = 1; $massiveaction_field = 'id'; if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $massiveaction_field = 'refID'; } // 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 Session::addToNavigateListItems($itemtype, $data["id"]); if ($output_type == self::HTML_OUTPUT && $showmassiveactions) { // HTML display - massive modif $tmpcheck = ""; if ($itemtype == 'Entity' && !in_array($data["id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { if ($item->maybeRecursive() && !in_array($data["entities_id"], $_SESSION["glpiactiveentities"])) { $tmpcheck = " "; } else { $tmpcheck = Html::getMassiveActionCheckBox($itemtype, $data[$massiveaction_field]); } } 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 = self::explodeWithID("\$\$", $split[$k]); if (isset($split2[1])) { if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype'] == 'itemlink') { $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' "; $out .= "href=\"" . Toolbox::getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $split2[1] . "\">"; $out .= Dropdown::getValueWithUnit($split2[0], $unit); $linkout = $out; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $linkout = sprintf(__('%1$s (%2$s)'), $linkout, $split2[1]); } $out = $linkout . "</a>"; } else { $out .= Dropdown::getValueWithUnit($split2[0], $unit); } } else { $out .= Dropdown::getValueWithUnit($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 != self::HTML_OUTPUT), $item_num, $row_num); } if ($itemtype == 'ConsumableItem') { echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != self::HTML_OUTPUT), $item_num, $row_num); } if (isset($CFG_GLPI["union_search_type"][$itemtype])) { $typename = $data["TYPE"]; if ($itemtmp = getItemForItemtype($data["TYPE"])) { $typename = $itemtmp->getTypeName(); } echo self::showItem($output_type, $typename, $item_num, $row_num); } if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) { if ($data["ACTIVE"]) { echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<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 == self::PDF_OUTPUT_LANDSCAPE || $output_type == self::PDF_OUTPUT_PORTRAIT) { if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) { $titlecontain = ''; if (strlen($p['contains'][$key]) > 0) { if (isset($p["link"][$key])) { $titlecontain = " " . $p["link"][$key] . " "; } switch ($p['field'][$key]) { case "all": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('All')); break; case "view": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('Items seen')); break; default: $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, $searchopt[$itemtype][$p['field'][$key]]["name"]); } switch ($p['searchtype'][$key]) { case "equals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])); } else { $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]); } break; case "notequals": if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) { $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])); } else { $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, $p['contains'][$key]); } break; case "lessthan": $titlecontain = sprintf(__('%1$s < %2$s'), $titlecontain, $p['contains'][$key]); break; case "morethan": $titlecontain = sprintf(__('%1$s > %2$s'), $titlecontain, $p['contains'][$key]); break; case "contains": $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, '%' . $p['contains'][$key] . '%'); break; case "under": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]))); break; case "notunder": $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]))); break; default: $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]); break; } } $title .= $titlecontain; } } if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) { for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) { $titlecontain2 = ''; if (strlen($p['contains2'][$key]) > 0) { if (isset($p['link2'][$key])) { $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, $p['link2'][$key]); } $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s / %2$s'), $metanames[$p['itemtype2'][$key]], $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'))) { $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])); } else { $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]); } break; case "notequals": if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) { $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])); } else { $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, $p['contains2'][$key]); } break; case "lessthan": $titlecontain2 = sprintf(__('%1$s < %2$s'), $titlecontain2, $p['contains2'][$key]); break; case "morethan": $titlecontain2 = sprintf(__('%1$s > %2$s'), $titlecontain2, $p['contains2'][$key]); break; case "contains": $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, '%' . $p['contains2'][$key] . '%'); break; case "under": $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]))); break; case "notunder": $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]))); break; default: $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]); break; } } $title .= $titlecontain2; } } } if ($output_type == self::HTML_OUTPUT) { echo $headers_line_bottom; } // Display footer echo self::showFooter($output_type, $title); // Delete selected item if ($output_type == self::HTML_OUTPUT) { if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($itemtype, $massiveactionparams); // End form for delete item Html::closeForm(); } else { echo "<br>"; } } if ($output_type == self::HTML_OUTPUT) { // In case of HTML display Html::printPager($p['start'], $numrows, $target, $parameters, '', 0, $search_config); } } else { echo self::showError($output_type); } } else { echo $DBread->error(); } }
/** * Display a line for an object * * @since version 0.85 (befor in each object with differents parameters) * * @param $id Integer ID of the object * @param $options array of options * output_type : Default output type (see Search class / default Search::HTML_OUTPUT) * row_num : row num used for display * type_for_massiveaction : itemtype for massive action * id_for_massaction : default 0 means no massive action * followups : only for Tickets : show followup columns */ static function showShort($id, $options = array()) { global $CFG_GLPI, $DB; $p['output_type'] = Search::HTML_OUTPUT; $p['row_num'] = 0; $p['type_for_massiveaction'] = 0; $p['id_for_massiveaction'] = 0; if (count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); // Prints a job in short form // Should be called in a <table>-segment // Print links or not in case of user view // Make new job object and fill it from database, if success, print it $item = new static(); $candelete = static::canDelete(); $canupdate = Session::haveRight(static::$rightname, UPDATE); $align = "class='center"; $align_desc = "class='left"; $align .= "'"; $align_desc .= "'"; if ($item->getFromDB($id)) { $item_num = 1; $bgcolor = $_SESSION["glpipriority_" . $item->fields["priority"]]; echo Search::showNewLine($p['output_type'], $p['row_num'] % 2); $check_col = ''; if (($candelete || $canupdate) && $p['output_type'] == Search::HTML_OUTPUT && $p['id_for_massiveaction']) { $check_col = Html::getMassiveActionCheckBox($p['type_for_massiveaction'], $p['id_for_massiveaction']); } echo Search::showItem($p['output_type'], $check_col, $item_num, $p['row_num'], $align); $id_col = $item->fields["id"]; echo Search::showItem($p['output_type'], $id_col, $item_num, $p['row_num'], $align); // First column $first_col = ''; $color = ''; if ($item->fields["projectstates_id"]) { $query = "SELECT `color`\n FROM `glpi_projectstates`\n WHERE `id` = '" . $item->fields["projectstates_id"] . "'"; foreach ($DB->request($query) as $color) { $color = $color['color']; } $first_col = Dropdown::getDropdownName('glpi_projectstates', $item->fields["projectstates_id"]); } echo Search::showItem($p['output_type'], $first_col, $item_num, $p['row_num'], "{$align} bgcolor='{$color}'"); // Second column $second_col = sprintf(__('Opened on %s'), ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($item->fields['date'])); echo Search::showItem($p['output_type'], $second_col, $item_num, $p['row_num'], $align . " width=130"); // Second BIS column $second_col = Html::convDateTime($item->fields["date_mod"]); echo Search::showItem($p['output_type'], $second_col, $item_num, $p['row_num'], $align . " width=90"); // Second TER column if (count($_SESSION["glpiactiveentities"]) > 1) { $second_col = Dropdown::getDropdownName('glpi_entities', $item->fields['entities_id']); echo Search::showItem($p['output_type'], $second_col, $item_num, $p['row_num'], $align . " width=100"); } // Third Column echo Search::showItem($p['output_type'], "<span class='b'>" . CommonITILObject::getPriorityName($item->fields["priority"]) . "</span>", $item_num, $p['row_num'], "{$align} bgcolor='{$bgcolor}'"); // Fourth Column $fourth_col = ""; if ($item->fields["users_id"]) { $userdata = getUserName($item->fields["users_id"], 2); $fourth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); } echo Search::showItem($p['output_type'], $fourth_col, $item_num, $p['row_num'], $align); // Fifth column $fifth_col = ""; if ($item->fields["groups_id"]) { $fifth_col .= Dropdown::getDropdownName("glpi_groups", $item->fields["groups_id"]); $fifth_col .= "<br>"; } echo Search::showItem($p['output_type'], $fifth_col, $item_num, $p['row_num'], $align); // Eigth column $eigth_column = "<span class='b'>" . $item->fields["name"] . "</span> "; // Add link if ($item->canViewItem()) { $eigth_column = "<a id='" . $item->getType() . $item->fields["id"] . "{$rand}' href=\"" . $item->getLinkURL() . "&forcetab=Project\$\">{$eigth_column}</a>"; } if ($p['output_type'] == Search::HTML_OUTPUT) { $eigth_column = sprintf(__('%1$s %2$s'), $eigth_column, Html::showToolTip($item->fields['content'], array('display' => false, 'applyto' => $item->getType() . $item->fields["id"] . $rand))); } echo Search::showItem($p['output_type'], $eigth_column, $item_num, $p['row_num'], $align_desc . "width='200'"); // Finish Line echo Search::showEndLine($p['output_type']); } else { echo "<tr class='tab_bg_2'>"; echo "<td colspan='6' ><i>" . __('No item in progress.') . "</i></td></tr>"; } }
/** * Show contacts asociated to an enterprise **/ static function showForSupplier(Supplier $supplier) { global $DB, $CFG_GLPI; $instID = $supplier->fields['id']; if (!$supplier->can($instID, READ)) { return false; } $canedit = $supplier->can($instID, UPDATE); $rand = mt_rand(); $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); $contacts = array(); $used = array(); if ($number = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $contacts[$data['ID_ent']] = $data; $used[$data['id']] = $data['id']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='contactsupplier_form{$rand}' id='contactsupplier_form{$rand}'\n method='post' action='"; echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . __('Add a contact') . "</tr>"; echo "<tr class='tab_bg_2'><td class='center'>"; echo "<input type='hidden' name='suppliers_id' value='{$instID}'>"; Contact::dropdown(array('used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->fields["is_recursive"])); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && $number) { $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_top .= "</th>"; $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . __('Entity') . "</th>"; $header_end .= "<th>" . __('Phone') . "</th>"; $header_end .= "<th>" . __('Phone 2') . "</th>"; $header_end .= "<th>" . __('Mobile phone') . "</th>"; $header_end .= "<th>" . __('Fax') . "</th>"; $header_end .= "<th>" . _n('Email', 'Emails', 1) . "</th>"; $header_end .= "<th>" . __('Type') . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; $used = array(); if ($number) { Session::initNavigateListItems('Contact', sprintf(__('%1$s = %2$s'), Supplier::getTypeName(1), $supplier->getName())); foreach ($contacts as $data) { $ID = $data["ID_ent"]; $used[$data["id"]] = $data["id"]; Session::addToNavigateListItems('Contact', $data["id"]); echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["ID_ent"]) . "</td>"; } echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contact.form.php?id=" . $data["id"] . "'>" . sprintf(__('%1$s %2$s'), $data["name"], $data["firstname"]) . "</a></td>"; echo "<td class='center' width='100'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</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"] . "'>" . $data["email"] . "</a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contacttypes", $data["contacttypes_id"]) . "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Show softwares candidates to be merged with the current * * @return nothing **/ function showMergeCandidates() { global $DB, $CFG_GLPI; $ID = $this->getField('id'); $this->check($ID, "w"); $rand = mt_rand(); echo "<div class='center'>"; $sql = "SELECT `glpi_softwares`.`id`,\n `glpi_softwares`.`name`,\n `glpi_entities`.`completename` AS entity\n FROM `glpi_softwares`\n LEFT JOIN `glpi_entities` ON (`glpi_softwares`.`entities_id` = `glpi_entities`.`id`)\n WHERE (`glpi_softwares`.`id` != '{$ID}'\n AND `glpi_softwares`.`name` = '" . addslashes($this->fields["name"]) . "'\n AND `glpi_softwares`.`is_deleted` = '0'\n AND `glpi_softwares`.`is_template` = '0' " . getEntitiesRestrictRequest('AND', 'glpi_softwares', 'entities_id', getSonsOf("glpi_entities", $this->fields["entities_id"]), false) . ")\n ORDER BY `entity`"; $req = $DB->request($sql); if ($nb = $req->numrows()) { $link = Toolbox::getItemTypeFormURL('Software'); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $paramsma = array('num_displayed' => $nb, 'specific_actions' => array('mergesoftware' => __('Merge'))); Html::showMassiveActions(__CLASS__, $paramsma); echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th width='10'>"; echo Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . _n('Installation', 'Installations', 2) . "</th>"; echo "<th>" . _n('License', 'Licenses', 2) . "</th></tr>"; foreach ($req as $data) { echo "<tr class='tab_bg_2'>"; echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; echo "<td><a href='" . $link . "?id=" . $data["id"] . "'>" . $data["name"] . "</a></td>"; echo "<td>" . $data["entity"] . "</td>"; echo "<td class='right'>" . Computer_SoftwareVersion::countForSoftware($data["id"]) . "</td>"; echo "<td class='right'>" . SoftwareLicense::countForSoftware($data["id"]) . "</td></tr>\n"; } echo "</table>\n"; echo "<input type='hidden' name='id' value='{$ID}'>"; $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } else { _e('No item found'); } echo "</div>"; }
/** * @param $sla SLA object **/ function showForSLA(SLA $sla) { global $DB; $ID = $sla->getField('id'); if (!$sla->can($ID, READ)) { return false; } $canedit = $sla->can($ID, UPDATE); $rand = mt_rand(); if ($canedit) { echo "<div class='center first-bloc'>"; echo "<form name='slalevel_form{$rand}' id='slalevel_form{$rand}' method='post' action='"; echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='7'>" . __('Add an escalation level') . "</tr>"; echo "<tr class='tab_bg_2'><td class='center'>" . __('Name') . ""; 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 type='hidden' name='match' value='AND'>"; echo "</td><td><input name='name' value=''>"; echo "</td><td class='center'>" . __('Execution') . "</td><td>"; $resolution_time = $sla->getResolutionTime(); self::dropdownExecutionTime('execution_time', array('max_time' => $resolution_time, 'used' => self::getAlreadyUsedExecutionTime($sla->fields['id']))); echo "</td><td class='center'>" . __('Active') . "</td><td>"; Dropdown::showYesNo("is_active", 1); echo "</td><td class='center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } $query = "SELECT *\n FROM `glpi_slalevels`\n WHERE `slas_id` = '{$ID}'\n ORDER BY `execution_time`"; $result = $DB->query($query); $numrows = $DB->numrows($result); echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr>"; if ($canedit && $numrows) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Execution') . "</th>"; echo "<th>" . __('Active') . "</th>"; echo "</tr>"; Session::initNavigateListItems('SlaLevel', sprintf(__('%1$s = %2$s'), SLA::getTypeName(1), $sla->getName())); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('SlaLevel', $data["id"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } echo "<td>"; if ($canedit) { echo "<a href='" . Toolbox::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 ? Html::timestampToString($data["execution_time"], false) : __('Due date')) . "</td>"; echo "<td>" . Dropdown::getYesNo($data["is_active"]) . "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'><td colspan='2'>"; $this->getRuleWithCriteriasAndActions($data['id'], 1, 1); $this->showCriteriasList($data["id"], array('readonly' => true)); echo "</td><td colspan='2'>"; $this->showActionsList($data["id"], array('readonly' => true)); echo "</td></tr>"; } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * Get the group of elements regarding given item. * Two kind of item : * - Device* feed by a link to the attached item (Computer, Printer ...) * - Computer, Printer ...: feed by the "global" properties of the CommonDevice * Then feed with the specificities of the Item_Device elements * In cas of $item is an instance, then $options contains the type of the item (Computer, * Printer ...). * * @param $item * @param $table * @param $options array * @param $delete_all_column (default NULL) * @param $common_column * @param $specific_column * @param $delete_column (default NULL) * @param $dynamic_column **/ function getTableGroup(CommonDBTM $item, HTMLTableMain $table, array $options, HTMLTableSuperHeader $delete_all_column = NULL, HTMLTableSuperHeader $common_column, HTMLTableSuperHeader $specific_column, HTMLTableSuperHeader $delete_column = NULL, $dynamic_column) { global $DB; $is_device = $item instanceof CommonDevice; if ($is_device) { $peer_type = $options['itemtype']; if (empty($peer_type)) { $column_label = __('Dissociated devices'); $group_name = 'None'; } else { $column_label = $peer_type::getTypeName(Session::getPluralNumber()); $group_name = $peer_type; } $table_group = $table->createGroup($group_name, ''); $peer_column = $table_group->addHeader('item', $column_label, $common_column, NULL); if (!empty($peer_type)) { //TRANS : %1$s is the type of the device // %2$s is the type of the item // %3$s is the name of the item (used for headings of a list), $itemtype_nav_title = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName()); $peer_column->setItemType($peer_type, $itemtype_nav_title); } } else { $peer_type = $this->getDeviceType(); $table_group = $table->createGroup($peer_type, ''); //TRANS : %1$s is the type of the device // %2$s is the type of the item // %3$s is the name of the item (used for headings of a list), $options['itemtype_title'] = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName()); $peer_type::getHTMLTableHeader($item->getType(), $table_group, $common_column, NULL, $options); } $specificity_columns = array(); $link_column = $table_group->addHeader('spec_link', '', $specific_column); $spec_column = $link_column; foreach ($this->getSpecificities() as $field => $attributs) { $spec_column = $table_group->addHeader('spec_' . $field, $attributs['long name'], $specific_column, $spec_column); $specificity_columns[$field] = $spec_column; } $infocom_column = $table_group->addHeader('infocom', Infocom::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column); $document_column = $table_group->addHeader('document', Document::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column); if ($item->isDynamic()) { $dynamics_column = $table_group->addHeader('one', ' ', $dynamic_column, $spec_column); $previous_column = $dynamics_column; } else { $previous_column = $spec_column; } if ($options['canedit']) { $group_checkbox_tag = empty($peer_type) ? '__' : $peer_type; $content = Html::getCheckbox(array('criterion' => array('tag_for_massive' => $group_checkbox_tag))); $delete_one = $table_group->addHeader('one', $content, $delete_column, $previous_column); } if ($is_device) { $fk = 'items_id'; // Entity restrict $leftjoin = ''; $where = ""; if (!empty($peer_type)) { $leftjoin = "LEFT JOIN `" . getTableForItemType($peer_type) . "`\n ON (`" . $this->getTable() . "`.`items_id` = `" . getTableForItemType($peer_type) . "`.`id`\n AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}')"; $where = getEntitiesRestrictRequest(" AND", getTableForItemType($peer_type)); } $query = "SELECT `" . $this->getTable() . "`.*\n FROM `" . $this->getTable() . "`\n {$leftjoin}\n WHERE `" . $this->getDeviceForeignKey() . "` = '" . $item->getID() . "'\n AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}'\n AND `" . $this->getTable() . "`.`is_deleted` = '0'\n {$where}\n ORDER BY `" . $this->getTable() . "`.`itemtype`, `" . $this->getTable() . "`.`{$fk}`"; } else { $fk = $this->getDeviceForeignKey(); $query = "SELECT *\n FROM `" . $this->getTable() . "`\n WHERE `itemtype` = '" . $item->getType() . "'\n AND `items_id` = '" . $item->getID() . "'\n AND `is_deleted` = '0'\n ORDER BY {$fk}"; } if (!empty($peer_type)) { $peer = new $peer_type(); $peer->getEmpty(); } else { $peer = NULL; } foreach ($DB->request($query) as $link) { Session::addToNavigateListItems(static::getType(), $link["id"]); $this->getFromDB($link['id']); if (is_null($peer) || $link[$fk] != $peer->getID()) { if ($peer instanceof CommonDBTM) { $peer->getFromDB($link[$fk]); } $current_row = $table_group->createRow(); $peer_group = $peer_type . '_' . $link[$fk] . '_' . mt_rand(); $current_row->setHTMLID($peer_group); if ($options['canedit']) { $cell_value = Html::getCheckAllAsCheckbox($peer_group); $current_row->addCell($delete_all_column, $cell_value); } if ($is_device) { $cell = $current_row->addCell($peer_column, $peer ? $peer->getLink() : __('None'), NULL, $peer); if (is_null($peer)) { $cell->setHTMLClass('center'); } } else { $peer->getHTMLTableCellForItem($current_row, $item, NULL, $options); } } if (Session::haveRight('device', UPDATE)) { $mode = __s('Update'); } else { $mode = __s('View'); } $spec_cell = $current_row->addCell($link_column, "<a href='" . $this->getLinkURL() . "'>{$mode}</a>"); foreach ($this->getSpecificities() as $field => $attributs) { if (!empty($link[$field])) { $content = $link[$field]; } else { $content = ''; } $spec_cell = $current_row->addCell($specificity_columns[$field], $content, $spec_cell); } if (countElementsInTable('glpi_infocoms', "`itemtype`='" . $this->getType() . "' AND\n `items_id`='" . $link['id'] . "'")) { $content = array(array('function' => 'Infocom::showDisplayLink', 'parameters' => array($this->getType(), $link['id']))); } else { $content = ''; } $current_row->addCell($infocom_column, $content, $spec_cell); $content = array(); // The order is to be sure that specific documents appear first $query = "SELECT `documents_id`\n FROM `glpi_documents_items`\n WHERE (`itemtype` = '" . $this->getType() . "' AND `items_id` = '" . $link['id'] . "')\n OR (`itemtype` = '" . $this->getDeviceType() . "'\n AND `items_id` = '" . $link[$this->getDeviceForeignKey()] . "')\n ORDER BY `itemtype` = '" . $this->getDeviceType() . "'"; $document = new Document(); foreach ($DB->request($query) as $document_link) { if ($document->can($document_link['documents_id'], READ)) { $content[] = $document->getLink(); } } $content = implode('<br>', $content); $current_row->addCell($document_column, $content, $spec_cell); if ($item->isDynamic()) { $previous_cell = $current_row->addCell($dynamics_column, Dropdown::getYesNo($link['is_dynamic']), $spec_cell); } else { $previous_cell = $spec_cell; } if ($options['canedit']) { $cell_value = Html::getMassiveActionCheckBox($this->getType(), $link['id'], array('massive_tags' => $group_checkbox_tag)); $current_row->addCell($delete_one, $cell_value, $previous_cell); } } }
/** * Show computers linked to a License * * @param $license SoftwareLicense object * * @return nothing **/ static function showForLicense(SoftwareLicense $license) { global $DB, $CFG_GLPI; $searchID = $license->getField('id'); if (!Software::canView() || !$searchID) { return false; } $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE)); $canshowcomputer = Computer::canView(); if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"])) { // manage several param like location,compname : order first $tmp = explode(",", $_GET["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`\n = `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'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '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>"; Computer::dropdown(array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive'])); echo "</td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager Html::printAjaxPager(__('Affected computers'), $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_users`.`id` AS userid,\n `glpi_users`.`realname` AS userrealname,\n `glpi_users`.`firstname` AS userfirstname,\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 `glpi_softwarelicenses`.`softwares_id` AS softid\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 AND `glpi_computers_softwarelicenses`.`is_deleted` = '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)) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); // show transfer only if multi licenses for this software if (self::countLicenses($data['softid']) > 1) { $massiveactionparams['specific_actions'][__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'move_license'] = _x('button', 'Move'); } // Options to update license $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID); $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id']; Html::showMassiveActions($massiveactionparams); } $soft = new Software(); $soft->getFromDB($license->fields['softwares_id']); $showEntity = $license->isRecursive(); $linkUser = User::canView(); $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]); $text = sprintf(__('%1$s - %2$s'), $text, $data["vername"]); Session::initNavigateListItems('Computer', $text); $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'>"; $columns = array('compname' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'otherserial' => __('Inventory number'), 'location,compname' => __('Location'), 'state,compname' => __('Status'), 'groupe,compname' => __('Group'), 'username,compname' => __('User')); if (!$showEntity) { unset($columns['entity']); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; do { Session::addToNavigateListItems('Computer', $data["cID"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } $compname = $data['compname']; if (empty($compname) || $_SESSION['glpiis_ids_visible']) { $compname = sprintf(__('%1$s (%2$s)'), $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>" . $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>" . formatUserName($data['userid'], $data['username'], $data['userrealname'], $data['userfirstname'], $linkUser) . "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo $header_begin . $header_bottom . $header_end; echo "</table>\n"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { // Not found _e('No item found'); } } // Query Html::printAjaxPager(__('Affected computers'), $start, $number); echo "</div>\n"; }
/** * Display a line for an object * * @since version 0.85 (befor in each object with differents parameters) * * @param $id Integer ID of the object * @param $options array of options * output_type : Default output type (see Search class / default Search::HTML_OUTPUT) * row_num : row num used for display * type_for_massiveaction : itemtype for massive action * id_for_massaction : default 0 means no massive action * followups : only for Tickets : show followup columns */ static function showShort($id, $options = array()) { global $CFG_GLPI, $DB; $p['output_type'] = Search::HTML_OUTPUT; $p['row_num'] = 0; $p['type_for_massiveaction'] = 0; $p['id_for_massiveaction'] = 0; $p['followups'] = false; if (count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); /// TODO to be cleaned. Get datas and clean display links // Prints a job in short form // Should be called in a <table>-segment // Print links or not in case of user view // Make new job object and fill it from database, if success, print it $item = new static(); $candelete = static::canDelete(); $canupdate = Session::haveRight(static::$rightname, UPDATE); $showprivate = Session::haveRight('followup', TicketFollowup::SEEPRIVATE); $align = "class='center"; $align_desc = "class='left"; if ($p['followups']) { $align .= " top'"; $align_desc .= " top'"; } else { $align .= "'"; $align_desc .= "'"; } if ($item->getFromDB($id)) { $item_num = 1; $bgcolor = $_SESSION["glpipriority_" . $item->fields["priority"]]; echo Search::showNewLine($p['output_type'], $p['row_num'] % 2); $check_col = ''; if (($candelete || $canupdate) && $p['output_type'] == Search::HTML_OUTPUT && $p['id_for_massiveaction']) { $check_col = Html::getMassiveActionCheckBox($p['type_for_massiveaction'], $p['id_for_massiveaction']); } echo Search::showItem($p['output_type'], $check_col, $item_num, $p['row_num'], $align); // First column $first_col = sprintf(__('%1$s: %2$s'), __('ID'), $item->fields["id"]); if ($p['output_type'] == Search::HTML_OUTPUT) { $first_col .= "<br><img src='" . static::getStatusIconURL($item->fields["status"]) . "'\n alt=\"" . static::getStatus($item->fields["status"]) . "\" title=\"" . static::getStatus($item->fields["status"]) . "\">"; } else { $first_col = sprintf(__('%1$s - %2$s'), $first_col, static::getStatus($item->fields["status"])); } echo Search::showItem($p['output_type'], $first_col, $item_num, $p['row_num'], $align); // Second column if ($item->fields['status'] == static::CLOSED) { $second_col = sprintf(__('Closed on %s'), ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($item->fields['closedate'])); } else { if ($item->fields['status'] == static::SOLVED) { $second_col = sprintf(__('Solved on %s'), ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($item->fields['solvedate'])); } else { if ($item->fields['begin_waiting_date']) { $second_col = sprintf(__('Put on hold on %s'), ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($item->fields['begin_waiting_date'])); } else { if ($item->fields['due_date']) { $second_col = sprintf(__('%1$s: %2$s'), __('Due date'), ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($item->fields['due_date'])); } else { $second_col = sprintf(__('Opened on %s'), ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($item->fields['date'])); } } } } echo Search::showItem($p['output_type'], $second_col, $item_num, $p['row_num'], $align . " width=130"); // Second BIS column $second_col = Html::convDateTime($item->fields["date_mod"]); echo Search::showItem($p['output_type'], $second_col, $item_num, $p['row_num'], $align . " width=90"); // Second TER column if (count($_SESSION["glpiactiveentities"]) > 1) { $second_col = Dropdown::getDropdownName('glpi_entities', $item->fields['entities_id']); echo Search::showItem($p['output_type'], $second_col, $item_num, $p['row_num'], $align . " width=100"); } // Third Column echo Search::showItem($p['output_type'], "<span class='b'>" . static::getPriorityName($item->fields["priority"]) . "</span>", $item_num, $p['row_num'], "{$align} bgcolor='{$bgcolor}'"); // Fourth Column $fourth_col = ""; foreach ($item->getUsers(CommonITILActor::REQUESTER) as $d) { $userdata = getUserName($d["users_id"], 2); $fourth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); $fourth_col .= "<br>"; } foreach ($item->getGroups(CommonITILActor::REQUESTER) as $d) { $fourth_col .= Dropdown::getDropdownName("glpi_groups", $d["groups_id"]); $fourth_col .= "<br>"; } echo Search::showItem($p['output_type'], $fourth_col, $item_num, $p['row_num'], $align); // Fifth column $fifth_col = ""; foreach ($item->getUsers(CommonITILActor::ASSIGN) as $d) { $userdata = getUserName($d["users_id"], 2); $fifth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); $fifth_col .= "<br>"; } foreach ($item->getGroups(CommonITILActor::ASSIGN) as $d) { $fifth_col .= Dropdown::getDropdownName("glpi_groups", $d["groups_id"]); $fifth_col .= "<br>"; } foreach ($item->getSuppliers(CommonITILActor::ASSIGN) as $d) { $fifth_col .= Dropdown::getDropdownName("glpi_suppliers", $d["suppliers_id"]); $fifth_col .= "<br>"; } echo Search::showItem($p['output_type'], $fifth_col, $item_num, $p['row_num'], $align); // Sixth Colum // Ticket : simple link to item $sixth_col = ""; $is_deleted = false; $item_ticket = new Item_Ticket(); $data = $item_ticket->find("`tickets_id` = " . $item->fields['id']); if ($item->getType() == 'Ticket') { if (!empty($data)) { foreach ($data as $val) { if (!empty($val["itemtype"]) && $val["items_id"] > 0) { if ($object = getItemForItemtype($val["itemtype"])) { if ($object->getFromDB($val["items_id"])) { $is_deleted = $object->isDeleted(); $sixth_col .= $object->getTypeName(); $sixth_col .= " - <span class='b'>"; if ($item->canView()) { $sixth_col .= $object->getLink(); } else { $sixth_col .= $object->getNameID(); } $sixth_col .= "</span><br>"; } } } } } else { $sixth_col = __('General'); } echo Search::showItem($p['output_type'], $sixth_col, $item_num, $p['row_num'], $is_deleted ? " class='center deleted' " : $align); } // Seventh column echo Search::showItem($p['output_type'], "<span class='b'>" . Dropdown::getDropdownName('glpi_itilcategories', $item->fields["itilcategories_id"]) . "</span>", $item_num, $p['row_num'], $align); // Eigth column $eigth_column = "<span class='b'>" . $item->getName() . "</span> "; // Add link if ($item->canViewItem()) { $eigth_column = "<a id='" . $item->getType() . $item->fields["id"] . "{$rand}' href=\"" . $item->getLinkURL() . "\">{$eigth_column}</a>"; if ($p['followups'] && $p['output_type'] == Search::HTML_OUTPUT) { $eigth_column .= TicketFollowup::showShortForTicket($item->fields["id"]); } else { if (method_exists($item, 'numberOfFollowups')) { $eigth_column = sprintf(__('%1$s (%2$s)'), $eigth_column, sprintf(__('%1$s - %2$s'), $item->numberOfFollowups($showprivate), $item->numberOfTasks($showprivate))); } else { $eigth_column = sprintf(__('%1$s (%2$s)'), $eigth_column, $item->numberOfTasks($showprivate)); } } } if ($p['output_type'] == Search::HTML_OUTPUT) { $eigth_column = sprintf(__('%1$s %2$s'), $eigth_column, Html::showToolTip(Html::clean(Html::entity_decode_deep($item->fields["content"])), array('display' => false, 'applyto' => $item->getType() . $item->fields["id"] . $rand))); } echo Search::showItem($p['output_type'], $eigth_column, $item_num, $p['row_num'], $align_desc . " width='200'"); //tenth column $tenth_column = ''; $planned_infos = ''; $tasktype = $item->getType() . "Task"; $plan = new $tasktype(); $items = array(); foreach ($DB->request($plan->getTable(), array($item->getForeignKeyField() => $item->fields['id'])) as $plan) { if (isset($plan['begin']) && $plan['begin']) { $items[$plan['id']] = $plan['id']; $planned_infos .= sprintf(__('From %s') . ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : ''), Html::convDateTime($plan['begin'])); $planned_infos .= sprintf(__('To %s') . ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : ''), Html::convDateTime($plan['end'])); if ($plan['users_id_tech']) { $planned_infos .= sprintf(__('By %s') . ($p['output_type'] == Search::HTML_OUTPUT ? '<br>' : ''), getUserName($plan['users_id_tech'])); } $planned_infos .= "<br>"; } } unset($i, $j); $tenth_column = count($items); if ($tenth_column) { $tenth_column = "<span class='pointer'\n id='" . $item->getType() . $item->fields["id"] . "planning{$rand}'>" . $tenth_column . '</span>'; $tenth_column = sprintf(__('%1$s %2$s'), $tenth_column, Html::showToolTip($planned_infos, array('display' => false, 'applyto' => $item->getType() . $item->fields["id"] . "planning" . $rand))); } echo Search::showItem($p['output_type'], $tenth_column, $item_num, $p['row_num'], $align_desc . " width='150'"); // Finish Line echo Search::showEndLine($p['output_type']); } else { echo "<tr class='tab_bg_2'>"; echo "<td colspan='6' ><i>" . __('No item in progress.') . "</i></td></tr>"; } }
/** * Print the predefined fields * * @since version 0.83 * * @param $tt Ticket Template * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $tt->fields['id']; if (!$tt->getFromDB($ID) || !$tt->can($ID, READ)) { return false; } $canedit = $tt->canEdit($ID); $fields = $tt->getAllowedFieldsNames(true, true); $searchOption = Search::getOptions('Ticket'); $ticket = new Ticket(); $rand = mt_rand(); $query = "SELECT `glpi_tickettemplatepredefinedfields`.*\n FROM `glpi_tickettemplatepredefinedfields`\n WHERE (`tickettemplates_id` = '{$ID}')\n ORDER BY 'id'"; $display_options = array('relative_dates' => true, 'comments' => true, 'html' => true); if ($result = $DB->query($query)) { $predeffields = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $predeffields[$data['id']] = $data; $used[$data['num']] = $data['num']; } } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a predefined field') . "</th></tr>"; echo "<tr class='tab_bg_2'><td class='right top' width='30%'>"; echo "<input type='hidden' name='tickettemplates_id' value='{$ID}'>"; $display_fields[-1] = Dropdown::EMPTY_VALUE; $display_fields += $fields; // Force validation request as used $used[-2] = -2; // Unset multiple items $multiple = self::getMultiplePredefinedValues(); foreach ($multiple as $val) { if (isset($used[$val])) { unset($used[$val]); } } $rand_dp = Dropdown::showFromArray('num', $display_fields, array('used' => $used, 'toadd')); echo "</td><td class='top'>"; $paramsmassaction = array('id_field' => '__VALUE__', 'itemtype' => 'Ticket', 'inline' => true, 'submitname' => _sx('button', 'Add'), 'options' => array('relative_dates' => 1, 'with_time' => 1, 'with_days' => 0, 'with_specific_date' => 0, 'itemlink_as_string' => 1, 'entity' => $tt->getEntityID())); Ajax::updateItemOnSelectEvent("dropdown_num" . $rand_dp, "show_massiveaction_field", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionField.php", $paramsmassaction); echo "</td><td>"; echo "<span id='show_massiveaction_field'> </span>\n"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; echo "<tr class='noHover'><th colspan='3'>"; echo self::getTypeName($DB->numrows($result)); echo "</th></tr>"; if ($numrows) { $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_top .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; $header_bottom .= "<th width='10'>"; $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . __('Value') . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; foreach ($predeffields as $data) { if (!isset($fields[$data['num']])) { // could happen when itemtype removed and items_id present continue; } echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } echo "<td>" . $fields[$data['num']] . "</td>"; echo "<td>"; $display_datas[$searchOption[$data['num']]['field']] = $data['value']; echo $ticket->getValueToDisplay($searchOption[$data['num']], $display_datas, $display_options); echo "</td>"; echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; } else { echo "<tr><th colspan='3'>" . __('No item found') . "</th></tr>"; } echo "</table>"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; } }
/** * Show the massive action checkbox * * @since version 0.84 * * @param $itemtype Massive action itemtype * @param $id ID of the item * @param $options array * * @return show checkbox **/ static function showMassiveActionCheckBox($itemtype, $id, array $options = array()) { echo Html::getMassiveActionCheckBox($itemtype, $id, $options); }
/** * Show ports for an item * * @param $item CommonDBTM object * @param $withtemplate integer withtemplate param (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $DB, $CFG_GLPI; $rand = mt_rand(); $itemtype = $item->getType(); $items_id = $item->getField('id'); if (!NetworkEquipment::canView() || !$item->can($items_id, READ)) { return false; } $netport = new self(); $netport->item = $item; if ($itemtype == 'NetworkPort') { $canedit = false; } else { $canedit = $item->canEdit($items_id); } $showmassiveactions = false; if ($withtemplate != 2) { $showmassiveactions = $canedit; } // Show Add Form if ($canedit && (empty($withtemplate) || $withtemplate != 2)) { echo "\n<form method='get' action='" . $netport->getFormURL() . "'>\n"; echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>\n"; echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n"; echo "<div class='firstbloc'><table class='tab_cadre_fixe'>\n"; echo "<tr class='tab_bg_2'><td class='center'>\n"; _e('Network port type to be added'); echo " "; $instantiations = array(); foreach (self::getNetworkPortInstantiations() as $inst_type) { if (call_user_func(array($inst_type, 'canCreate'))) { $instantiations[$inst_type] = call_user_func(array($inst_type, 'getTypeName')); } } Dropdown::showFromArray('instantiation_type', $instantiations, array('value' => 'NetworkPortEthernet')); echo "</td>\n"; echo "<td class='tab_bg_2 center' width='50%'>"; _e('Add several ports'); echo " <input type='checkbox' name='several' value='1'></td>\n"; echo "<td>\n"; echo "<input type='submit' name='create' value=\"" . _sx('button', 'Add') . "\" class='submit'>\n"; echo "</td></tr></table></div>\n"; Html::closeForm(); } if ($showmassiveactions) { $checkbox_column = true; Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); } else { $checkbox_column = false; } $is_active_network_port = false; Session::initNavigateListItems('NetworkPort', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); if ($itemtype == 'NetworkPort') { $porttypes = array('NetworkPortAlias', 'NetworkPortAggregate'); } else { $porttypes = self::getNetworkPortInstantiations(); // Manage NetworkportMigration $porttypes[] = ''; } $display_options = self::getDisplayOptions($itemtype); $table = new HTMLTableMain(); $number_port = self::countForItem($item); $table_options = array('canedit' => $canedit, 'display_options' => &$display_options); // Make table name and add the correct show/hide parameters $table_name = sprintf(__('%1$s: %2$d'), self::getTypeName($number_port), $number_port); // Add the link to the modal to display the options ... $table_namelink = self::getDisplayOptionsLink($itemtype); $table_name = sprintf(__('%1$s - %2$s'), $table_name, $table_namelink); $table->setTitle($table_name); $c_main = $table->addHeader('main', self::getTypeName(Session::getPluralNumber())); if ($display_options['dynamic_import'] && $item->isDynamic()) { $table_options['display_isDynamic'] = true; } else { $table_options['display_isDynamic'] = false; } if ($display_options['characteristics']) { $c_instant = $table->addHeader('Instantiation', __('Characteristics')); $c_instant->setHTMLClass('center'); } if ($display_options['internet']) { $options = array('names' => 'NetworkName', 'aliases' => 'NetworkAlias', 'ipaddresses' => 'IPAddress', 'ipnetworks' => 'IPNetwork'); $table_options['dont_display'] = array(); foreach ($options as $option => $itemtype_for_option) { if (!$display_options[$option]) { $table_options['dont_display'][$itemtype_for_option] = true; } } $c_network = $table->addHeader('Internet', __('Internet information')); $c_network->setHTMLClass('center'); } else { $c_network = NULL; } foreach ($porttypes as $portType) { if (empty($portType)) { $group_name = 'Migration'; $group_title = __('Network ports waiting for manual migration'); } else { $group_name = $portType; $group_title = $portType::getTypeName(Session::getPluralNumber()); } $t_group = $table->createGroup($group_name, $group_title); if ($withtemplate != 2 && $canedit) { $c_checkbox = $t_group->addHeader('checkbox', Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand, '__RAND__'), $c_main); } else { $c_checkbox = NULL; } $c_number = $t_group->addHeader('NetworkPort', "#", $c_main); $c_name = $t_group->addHeader("Name", __('Name'), $c_main); $c_name->setItemType('NetworkPort'); $c_name->setHTMLClass('center'); if ($table_options['display_isDynamic']) { $c_dynamic = $t_group->addHeader("Dynamic", __('Automatic inventory'), $c_main); $c_dynamic->setHTMLClass('center'); } if ($display_options['characteristics']) { if (empty($portType)) { NetworkPortMigration::getMigrationInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options); } else { $instantiation = new $portType(); $instantiation->getInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options); unset($instantiation); } } if ($display_options['internet'] && !$display_options['characteristics']) { NetworkName::getHTMLTableHeader(__CLASS__, $t_group, $c_network, NULL, $table_options); } if ($itemtype == 'NetworkPort') { switch ($portType) { case 'NetworkPortAlias': $search_table = 'glpi_networkportaliases'; $search_request = "`networkports_id_alias`='{$items_id}'"; break; case 'NetworkPortAggregate': $search_table = 'glpi_networkportaggregates'; $search_request = "`networkports_id_list` like '%\"{$items_id}\"%'"; break; } $query = "SELECT `networkports_id` AS id\n FROM `{$search_table}`\n WHERE {$search_request}"; } else { $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '{$items_id}'\n AND `itemtype` = '{$itemtype}'\n AND `instantiation_type` = '{$portType}'\n AND `is_deleted` = '0'\n ORDER BY `name`,\n `logical_number`"; } if ($result = $DB->query($query)) { echo "<div class='spaced'>"; $number_port = $DB->numrows($result); if ($number_port != 0) { $is_active_network_port = true; $save_canedit = $canedit; if (!empty($portType)) { $name = sprintf(__('%1$s (%2$s)'), self::getTypeName($number_port), call_user_func(array($portType, 'getTypeName'))); $name = sprintf(__('%1$s: %2$s'), $name, $number_port); } else { $name = __('Network ports waiting for manual migration'); $canedit = false; } while ($devid = $DB->fetch_row($result)) { $t_row = $t_group->createRow(); $netport->getFromDB(current($devid)); // No massive action for migration ports if ($withtemplate != 2 && $canedit && !empty($portType)) { $ce_checkbox = $t_row->addCell($c_checkbox, Html::getMassiveActionCheckBox(__CLASS__, $netport->fields["id"])); } else { $ce_checkbox = NULL; } $content = "<span class='b'>"; // Display link based on default rights if ($save_canedit && $withtemplate != 2) { if (!empty($portType)) { $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">"; } else { $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkportmigration.form.php?id=" . $netport->fields["id"] . "\">"; } } $content .= $netport->fields["logical_number"]; if ($canedit && $withtemplate != 2) { $content .= "</a>"; } $content .= "</span>"; $content .= Html::showToolTip($netport->fields['comment'], array('display' => false)); $t_row->addCell($c_number, $content); $value = $netport->fields["name"]; $t_row->addCell($c_name, $value, NULL, $netport); if ($table_options['display_isDynamic']) { $t_row->addCell($c_dynamic, Dropdown::getYesNo($netport->fields['is_dynamic'])); } $instant_cell = NULL; if ($display_options['characteristics']) { $instantiation = $netport->getInstantiation(); if ($instantiation !== false) { $instantiation->getInstantiationHTMLTable($netport, $t_row, NULL, $table_options); unset($instantiation); } } else { if ($display_options['internet']) { NetworkName::getHTMLTableCellsForItem($t_row, $netport, NULL, $table_options); } } } $canedit = $save_canedit; } echo "</div>"; } } if ($is_active_network_port && $showmassiveactions) { $massiveactionparams = array('num_displayed' => $number_port, 'check_itemtype' => $itemtype, 'container' => 'mass' . __CLASS__ . $rand, 'check_items_id' => $items_id); Html::showMassiveActions($massiveactionparams); } $table->display(array('display_thead' => false, 'display_tfoot' => false, 'display_header_on_foot_for_each_group' => true)); unset($table); if (!$is_active_network_port) { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network port found') . "</th></tr>"; echo "</table>"; } if ($is_active_network_port && $showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } if ($showmassiveactions) { Html::closeForm(); } }
/** * Show Licenses of a software * * @param $software Software object * * @return nothing **/ static function showForSoftware(Software $software) { global $DB, $CFG_GLPI; $softwares_id = $software->getField('id'); $license = new self(); $computer = new Computer(); if (!$software->can($softwares_id, READ)) { return false; } $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'number' => _x('quantity', 'Number'), '_affected' => __('Affected computers'), 'typename' => __('Type'), 'buyname' => __('Purchase version'), 'usename' => __('Version in use'), 'expire' => __('Expiration')); if (!$software->isRecursive()) { unset($columns['entity']); } if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) { $sort = "`" . $_GET["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = Software::canUpdate(); $showmassiveactions = $canedit; // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName())); if ($canedit) { echo "<div class='center firstbloc'>"; echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a license') . "</a>"; echo "</div>"; } $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']); if ($result = $DB->query($query)) { if ($num_displayed = $DB->numrows($result)) { // Display the pager Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); if ($showmassiveactions) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $num_displayed, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('options' => array('glpi_softwareversions.name' => array('condition' => "`glpi_softwareversions`.`softwares_id`\n = {$softwares_id}"), 'glpi_softwarelicenses.name' => array('itemlink_as_string' => true)))); Html::showMassiveActions($massiveactionparams); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr><th>"; $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end = ''; foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { Session::addToNavigateListItems('SoftwareLicense', $data['id']); $expired = true; if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) { $expired = false; } echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>"; if ($license->canEdit($data['id'])) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</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 (isset($columns['entity'])) { echo "<td>"; echo $data['entity']; echo "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; $color = $data['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $nb_assoc . "</td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Expire license not count if (!$expired) { // Not illimited, add the current number $tot += $data['number']; } } } } echo "<tr class='tab_bg_1 noHover'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>"; echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>"; $color = $software->fields['is_valid'] ? 'green' : 'red'; echo "<td class='numeric {$color}'>" . $tot_assoc . "</td><td></td><td></td><td></td><td></td>"; echo "</tr>"; echo "</table>\n"; if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number); } else { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No item found') . "</th></tr></table>"; } } echo "</div>"; }
echo Dropdown::getDropdownName("glpi_computermodels", $comp->getField('computermodels_id')); echo "</td><td>" . $comp->getField('serial'); echo "</td><td>" . $comp->getField('otherserial') . "</td>"; } else { echo "<td colspan='5'>" . $data["Aname"] . "</td>"; } if ($col) { echo "<td>" . $data["Aaddr"] . "</td>"; } echo "<td>"; if ($ocs_installed) { echo getLastOcsUpdate($data['AID']); } echo "</td>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox('Computer', $data["BID"]) . "</td>"; } echo "<td class='b blue'>" . $data["BID"] . "</td>"; if ($comp->getFromDB($data["BID"])) { echo "<td class='blue'>"; echo $comp->getLink(true); echo "</td><td class='blue'>"; echo Dropdown::getDropdownName("glpi_manufacturers", $comp->getField('manufacturers_id')); echo "</td><td class='blue'>"; echo Dropdown::getDropdownName("glpi_computermodels", $comp->getField('computermodels_id')); echo "</td><td class='blue'>" . $comp->getField('serial'); echo "</td><td class='blue'>" . $comp->getField('otherserial') . "</td>"; } else { echo "<td colspan='5' class='blue'>" . $data["Aname"] . "</td>"; } if ($col) {