/** * Display changes for an item * * Will also display changes of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::READALL)) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'OR'; $options['criteria'][1]['field'] = 66; // status $options['criteria'][1]['searchtype'] = 'equals'; $options['criteria'][1]['value'] = $item->getID(); $options['criteria'][1]['link'] = 'OR'; $options['criteria'][5]['field'] = 5; // status $options['criteria'][5]['searchtype'] = 'equals'; $options['criteria'][5]['value'] = $item->getID(); $options['criteria'][5]['link'] = 'OR'; break; case 'Supplier': $restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last changes') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; _e('Child groups'); Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_changes_groups`.`groups_id` {$restrict}\n AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_changes`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_changes`.`date_mod` DESC'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); // Ticket for the item echo "<div class='firstbloc'><table class='tab_cadre_fixe'>"; $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } if ($number > 0) { Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr><th colspan='{$colspan}'>"; //TRANS : %d is the number of problems echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number); // echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?". // Toolbox::append_params($options,'&')."'>".__('Show all')."</a></span>"; echo "</th></tr>"; } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Problem', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`itemtype` = '{$ltype}' AND `items_id` = '{$lID}')"; } } } if (count($restrict)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_changes') . "\n ORDER BY `glpi_changes`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='{$colspan}'>"; _e('Changes on linked items'); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No change found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Show items for the group * * @param $tech boolean false search groups_id, true, search groups_id_tech **/ function showItems($tech) { global $DB, $CFG_GLPI; $rand = mt_rand(); $ID = $this->fields['id']; if ($tech) { $types = $CFG_GLPI['linkgroup_tech_types']; $field = 'groups_id_tech'; $title = __('Managed items'); } else { $types = $CFG_GLPI['linkgroup_types']; $field = 'groups_id'; $title = __('Used items'); } $tree = Session::getSavedOption(__CLASS__, 'tree', 0); $user = Session::getSavedOption(__CLASS__, 'user', 0); $type = Session::getSavedOption(__CLASS__, 'onlytype', ''); if (!in_array($type, $types)) { $type = ''; } echo "<div class='spaced'>"; // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='3'>{$title}</tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Type') . " "; Dropdown::showItemType($types, array('value' => $type, 'name' => 'onlytype', 'plural' => true, 'on_change' => 'reloadTab("start=0&onlytype="+this.value)', 'checkright' => true)); if ($this->haveChildren()) { echo "</td><td class='center'>" . __('Child groups') . " "; Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } if ($this->getField('is_usergroup')) { echo "</td><td class='center'>" . User::getTypeName(Session::getPluralNumber()) . " "; Dropdown::showYesNo('user', $user, -1, array('on_change' => 'reloadTab("start=0&user="******"</td></tr></table>"; $datas = array(); if ($type) { $types = array($type); } $start = isset($_GET['start']) ? intval($_GET['start']) : 0; $nb = $this->getDataItems($types, $field, $tree, $user, $start, $datas); $nbcan = 0; if ($nb) { Html::printAjaxPager('', $start, $nb); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); echo Html::hidden('field', array('value' => $field, 'data-glpicore-ma-tags' => 'common')); $massiveactionparams = array('num_displayed' => $nb, 'check_itemtype' => 'Group', 'check_items_id' => $ID, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('is_tech' => $tech, 'massive_action_fields' => array('field')), 'specific_actions' => array(__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'changegroup' => __('Move'))); Html::showMassiveActions($massiveactionparams); echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr><th width='10'>"; $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end = '</th>'; $header_end .= "<th>" . __('Type') . "</th><th>" . __('Name') . "</th><th>" . __('Entity') . "</th>"; if ($tree || $user) { $header_end .= "<th>" . sprintf(__('%1$s / %2$s'), self::getTypeName(1), User::getTypeName(1)) . "</th>"; } $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; $tuser = new User(); $group = new Group(); foreach ($datas as $data) { if (!($item = getItemForItemtype($data['itemtype']))) { continue; } echo "<tr class='tab_bg_1'><td>"; if ($item->canEdit($data['items_id'])) { Html::showMassiveActionCheckBox($data['itemtype'], $data['items_id']); } echo "</td><td>" . $item->getTypeName(1); echo "</td><td>" . $item->getLink(array('comments' => true)); echo "</td><td>" . Dropdown::getDropdownName("glpi_entities", $item->getEntityID()); if ($tree || $user) { echo "</td><td>"; if ($grp = $item->getField($field)) { if ($group->getFromDB($grp)) { echo $group->getLink(array('comments' => true)); } } else { if ($usr = $item->getField(str_replace('groups', 'users', $field))) { if ($tuser->getFromDB($usr)) { echo $tuser->getLink(array('comments' => true)); } } } } echo "</td></tr>"; } echo $header_begin . $header_bottom . $header_end; echo "</table>"; } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } if ($nb) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } Html::closeForm(); if ($nb) { Html::printAjaxPager('', $start, $nb); } echo "</div>"; }
/** * Display tickets for an item * * Will also display tickets of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRightsOr(self::$rightname, array(self::READALL, self::READMY, self::READASSIGN, CREATE))) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "' " . " AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['reset'] = 'reset'; $options['criteria'][0]['field'] = 4; // status $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'SLT': $restrict = "`slts_tto_id` = '" . $item->getID() . "'\n OR `slts_ttr_id` = '" . $item->getID() . "'"; $order = '`glpi_tickets`.`due_date` DESC'; $options['criteria'][0]['field'] = 30; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Supplier': $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "' " . " AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 6; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; case 'Group': // Mini search engine if ($item->haveChildren()) { $tree = Session::getSavedOption(__CLASS__, 'tree', 0); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>" . __('Last tickets') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Child groups') . " "; Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; if ($tree) { $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")"; } else { $restrict = "='" . $item->getID() . "'"; } $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}" . " AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 71; $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals'; $options['criteria'][0]['value'] = $item->getID(); $options['criteria'][0]['link'] = 'AND'; break; default: $restrict = "(`glpi_items_tickets`.`items_id` = '" . $item->getID() . "' " . " AND `glpi_items_tickets`.`itemtype` = '" . $item->getType() . "')"; // you can only see your tickets if (!Session::haveRight(self::$rightname, self::READALL)) { $restrict .= " AND (`glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'\n OR (`glpi_tickets_users`.`tickets_id` = '" . $item->getID() . "'\n AND `glpi_tickets_users`.`users_id`\n = '" . Session::getLoginUserID() . "'))"; } $order = '`glpi_tickets`.`date_mod` DESC'; $options['criteria'][0]['field'] = 12; $options['criteria'][0]['searchtype'] = 'equals'; $options['criteria'][0]['value'] = 'all'; $options['criteria'][0]['link'] = 'AND'; $options['metacriteria'][0]['itemtype'] = $item->getType(); $options['metacriteria'][0]['field'] = Search::getOptionNumber($item->getType(), 'id'); $options['metacriteria'][0]['searchtype'] = 'equals'; $options['metacriteria'][0]['value'] = $item->getID(); $options['metacriteria'][0]['link'] = 'AND'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); $colspan = 11; if (count($_SESSION["glpiactiveentities"]) > 1) { $colspan++; } // Ticket for the item echo "<div class='firstbloc'>"; // Link to open a new ticket if ($item->getID() && Ticket::isPossibleToAssignType($item->getType()) && self::canCreate()) { Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('itemtype' => $item->getType(), 'items_id' => $item->getID())); } echo "</div><div>"; if ($number > 0) { echo "<table class='tab_cadre_fixehov'>"; if (Session::haveRight(self::$rightname, self::READALL)) { Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr class='noHover'><th colspan='{$colspan}'>"; $title = sprintf(_n('Last %d ticket', 'Last %d tickets', $number), $number); $link = "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&') . "'>" . __('Show all') . "</a>"; $title = printf(__('%1$s (%2$s)'), $title, $link); echo "</th></tr>"; } else { echo "<tr><th colspan='{$colspan}'>" . __("You don't have right to see all tickets") . "</th></tr>"; } } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } if ($item->getID() && $item->getType() == 'User' && self::canCreate()) { echo "<tr><td class='tab_bg_2 center b' colspan='{$colspan}'>"; Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('_users_id_requester' => $item->getID())); echo "</td></tr>"; } // Ticket list if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { Session::addToNavigateListItems('Ticket', $data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } echo "</table></div>"; // Tickets for linked items $linkeditems = $item->getLinkedItems(); $restrict = array(); if (count($linkeditems)) { foreach ($linkeditems as $ltype => $tab) { foreach ($tab as $lID) { $restrict[] = "(`glpi_items_tickets`.`itemtype` = '{$ltype}' AND `glpi_items_tickets`.`items_id` = '{$lID}')"; } } } if (count($restrict) && Session::haveRight(self::$rightname, self::READALL)) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n ORDER BY `glpi_tickets`.`date_mod` DESC\n LIMIT " . intval($_SESSION['glpilist_limit']); $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='12'>"; echo _n('Ticket on linked items', 'Tickets on linked items', $number); echo "</th></tr>"; if ($number > 0) { self::commonListHeader(Search::HTML_OUTPUT); while ($data = $DB->fetch_assoc($result)) { // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]); self::showShort($data["id"]); } self::commonListHeader(Search::HTML_OUTPUT); } else { echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Display debug information for current object * NotificationTemplateTranslation => translation preview * * @since version 0.84 **/ function showDebug() { $template = new NotificationTemplate(); if (!$template->getFromDB($this->fields['notificationtemplates_id'])) { return; } $itemtype = $template->getField('itemtype'); if (!($item = getItemForItemtype($itemtype))) { return; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('Preview') . "</th></tr>"; $oktypes = array('CartridgeItem', 'Change', 'ConsumableItem', 'Contract', 'Crontask', 'Problem', 'Project', 'Ticket', 'User'); if (!in_array($itemtype, $oktypes)) { // this itemtype doesn't work, need to be fixed echo "<tr class='tab_bg_2 center'><td>" . NOT_AVAILABLE . "</td>"; echo "</table></div>"; return; } // Criteria Form $key = getForeignKeyFieldForItemType($item->getType()); $id = Session::getSavedOption(__CLASS__, $key, 0); $event = Session::getSavedOption(__CLASS__, $key . '_event', ''); echo "<tr class='tab_bg_2'><td>" . $item->getTypeName(1) . " "; $item->dropdown(array('value' => $id, 'on_change' => 'reloadTab("' . $key . '="+this.value)')); echo "</td><td>" . NotificationEvent::getTypeName(1) . " "; NotificationEvent::dropdownEvents($item->getType(), array('value' => $event, 'on_change' => 'reloadTab("' . $key . '_event="+this.value)')); echo "</td>"; // Preview if ($event && $item->getFromDB($id)) { $options = array('_debug' => true); // TODO Awfull Hack waiting for https://forge.indepnet.net/issues/3439 $multi = array('alert', 'alertnotclosed', 'end', 'notice', 'periodicity', 'periodicitynotice'); if (in_array($event, $multi)) { // Won't work for Cardridge and Consumable $options['entities_id'] = $item->getEntityID(); $options['items'] = array($item->getID() => $item->fields); } $target = NotificationTarget::getInstance($item, $event, $options); $infos = array('language' => $_SESSION['glpilanguage'], 'additionnaloption' => array('usertype' => NotificationTarget::GLPI_USER)); $template->resetComputedTemplates(); $template->setSignature(Notification::getMailingSignature($_SESSION['glpiactive_entity'])); if ($tid = $template->getTemplateByLanguage($target, $infos, $event, $options)) { $data = $template->templates_by_languages[$tid]; echo "<tr><th colspan='2'>" . __('Subject') . "</th></tr>"; echo "<tr class='tab_bg_2 b'><td colspan='2'>" . $data['subject'] . "</td></tr>"; echo "<tr><th>" . __('Email text body') . "</th>"; echo "<th>" . __('Email HTML body') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>" . nl2br($data['content_text']) . "</td>"; echo "<td>" . $data['content_html'] . "</td></tr>"; } } echo "</table></div>"; }
/** * Show users of a group * * @since version 0.83 * * @param $group Group object: the group **/ static function showForGroup(Group $group) { global $DB, $CFG_GLPI; $ID = $group->getID(); if (!User::canView() || !$group->can($ID, READ)) { return false; } // Have right to manage members $canedit = self::canUpdate(); $rand = mt_rand(); $user = new User(); $crit = Session::getSavedOption(__CLASS__, 'criterion', ''); $tree = Session::getSavedOption(__CLASS__, 'tree', 0); $used = array(); $ids = array(); // Retrieve member list $entityrestrict = self::getDataForGroup($group, $used, $ids, $crit, $tree); if ($canedit) { self::showAddUserForm($group, $ids, $entityrestrict, $crit); } // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . User::getTypeName(Session::getPluralNumber()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo _n('Criterion', 'Criteria', 1) . " "; $crits = array('' => Dropdown::EMPTY_VALUE, 'is_manager' => __('Manager'), 'is_userdelegate' => __('Delegatee')); Dropdown::showFromArray('crit', $crits, array('value' => $crit, 'on_change' => 'reloadTab("start=0&criterion="+this.value)')); if ($group->haveChildren()) { echo "</td><td class='center'>" . __('Child groups'); Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } echo "</td></tr></table>"; $number = count($used); $start = isset($_GET['start']) ? intval($_GET['start']) : 0; if ($start >= $number) { $start = 0; } // Display results if ($number) { echo "<div class='spaced'>"; Html::printAjaxPager(sprintf(__('%1$s (%2$s)'), User::getTypeName(Session::getPluralNumber()), __('D=Dynamic')), $start, $number); Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Group::getTypeName(1), $group->getName())); if ($canedit) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => min($number - $start, $_SESSION['glpilist_limit']), 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $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>"; } $header_end .= "<th>" . User::getTypeName(1) . "</th>"; if ($tree) { $header_end .= "<th>" . Group::getTypeName(1) . "</th>"; } $header_end .= "<th>" . __('Dynamic') . "</th>"; $header_end .= "<th>" . __('Manager') . "</th>"; $header_end .= "<th>" . __('Delegatee') . "</th></tr>"; echo $header_begin . $header_top . $header_end; $tmpgrp = new Group(); for ($i = $start, $j = 0; $i < $number && $j < $_SESSION['glpilist_limit']; $i++, $j++) { $data = $used[$i]; $user->getFromDB($data["id"]); Session::addToNavigateListItems('User', $data["id"]); echo "\n<tr class='tab_bg_" . ($user->isDeleted() ? '1_2' : '1') . "'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } echo "<td>" . $user->getLink(); if ($tree) { echo "</td><td>"; if ($tmpgrp->getFromDB($data['groups_id'])) { echo $tmpgrp->getLink(array('comments' => true)); } } echo "</td><td class='center'>"; if ($data['is_dynamic']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">"; } echo "</td><td class='center'>"; if ($data['is_manager']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">"; } echo "</td><td class='center'>"; if ($data['is_userdelegate']) { echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">"; } echo "</tr>"; } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } Html::printAjaxPager(sprintf(__('%1$s (%2$s)'), User::getTypeName(Session::getPluralNumber()), __('D=Dynamic')), $start, $number); echo "</div>"; } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } }
/** * Show software installed on a computer * * @param $comp Computer object * @param $withtemplate template case of the view process (default '') * * @return nothing **/ static function showForComputer(Computer $comp, $withtemplate = '') { global $DB, $CFG_GLPI; if (!Software::canView()) { return false; } $computers_id = $comp->getField('id'); $rand = mt_rand(); $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE)); $entities_id = $comp->fields["entities_id"]; $crit = Session::getSavedOption(__CLASS__, 'criterion', -1); $where = ''; if ($crit > -1) { $where = " AND `glpi_softwares`.`softwarecategories_id` = {$crit}"; } $add_dynamic = ''; if (Plugin::haveImport()) { $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,"; } $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n `glpi_softwares`.`name` AS softname,\n `glpi_computers_softwareversions`.`id`,\n {$add_dynamic}\n `glpi_states`.`name` AS state,\n `glpi_softwareversions`.`id` AS verid,\n `glpi_softwareversions`.`softwares_id`,\n `glpi_softwareversions`.`name` AS version,\n `glpi_softwares`.`is_valid` AS softvalid\n FROM `glpi_computers_softwareversions`\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n LEFT JOIN `glpi_softwares`\n ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n {$where}\n ORDER BY `softname`, `version`"; $result = $DB->query($query); $i = 0; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo _n('Software', 'Software', Session::getPluralNumber()) . " "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id); echo "</td><td width='20%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n class='submit'>"; echo "</td>"; echo "</tr>\n"; echo "</table></div>\n"; Html::closeForm(); } echo "<div class='spaced'>"; $cat = -1; Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . Software::getTypeName(Session::getPluralNumber()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Category') . "</td><td>"; SoftwareCategory::dropdown(array('value' => $crit, 'toadd' => array('-1' => __('All categories')), 'emptylabel' => __('Uncategorized software'), 'on_change' => 'reloadTab("start=0&criterion="+this.value)')); echo "</td></tr></table></div>"; $number = $DB->numrows($result); $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0; if ($start >= $number) { $start = 0; } $installed = array(); if ($number) { echo "<div class='spaced'>"; Html::printAjaxPager('', $start, $number); if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $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>"; } $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>"; $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>"; if (Plugin::haveImport()) { $header_end .= "<th>" . __('Automatic inventory') . "</th>"; } $header_end .= "<th>" . SoftwareCategory::getTypeName(1) . "</th>"; $header_end .= "<th>" . __('Valid license') . "</th>"; $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; for ($row = 0; $data = $DB->fetch_assoc($result); $row++) { if ($row >= $start && $row < $start + $_SESSION['glpilist_limit']) { $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, true); } else { $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, false); } Session::addToNavigateListItems('Software', $data["softwares_id"]); foreach ($licids as $licid) { Session::addToNavigateListItems('SoftwareLicense', $licid); $installed[] = $licid; } } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } echo "</div>\n"; if ((empty($withtemplate) || $withtemplate != 2) && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td class='center'>"; echo _n('License', 'Licenses', Session::getPluralNumber()) . " "; echo "<input type='hidden' name='computers_id' value='{$computers_id}'>"; Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id); echo "</td><td width='20%'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; echo "</table></div>\n"; Html::closeForm(); } echo "<div class='spaced'>"; // Affected licenses NOT installed $query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_computers_softwarelicenses`.`id` AS linkID,\n `glpi_softwares`.`name` AS softname,\n `glpi_softwareversions`.`name` AS version,\n `glpi_states`.`name` AS state\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_computers_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_softwares`\n ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n LEFT JOIN `glpi_softwareversions`\n ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n = `glpi_softwareversions`.`id`\n OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n = `glpi_softwareversions`.`id`))\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n {$where}"; if (count($installed)) { $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")"; } $query .= " ORDER BY `softname`, `version`;"; $req = $DB->request($query); if ($number = $req->numrows()) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('massSoftwareLicense' . $rand); $actions = array('Computer_SoftwareLicense' . MassiveAction::CLASS_ACTION_SEPARATOR . 'install' => _x('button', 'Install')); if (SoftwareLicense::canUpdate()) { $actions['purge'] = _x('button', 'Delete permanently'); } $massiveactionparams = array('num_displayed' => $number, 'container' => 'massSoftwareLicense' . $rand, 'specific_actions' => $actions); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand); $header_end .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>"; $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>"; $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; $cat = true; foreach ($req as $data) { self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit); Session::addToNavigateListItems('SoftwareLicense', $data["id"]); } echo $header_begin . $header_bottom . $header_end; echo "</table>"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } echo "</div>\n"; }
/** * Show the list of rules * * @param $target * @param $options array * * @return nothing **/ function showListRules($target, $options = array()) { global $CFG_GLPI; $p['inherited'] = 1; $p['childrens'] = 0; $p['active'] = false; $p['condition'] = 0; $rand = mt_rand(); foreach (array('inherited', 'childrens', 'condition') as $param) { if (isset($options[$param]) && $this->isRuleRecursive()) { $p[$param] = $options[$param]; } } $rule = $this->getRuleClass(); $display_entities = $this->isRuleRecursive() && ($p['inherited'] || $p['childrens']); // Do not know what it is ? $canedit = self::canUpdate() && !$display_entities; $use_conditions = false; if ($rule->useConditions()) { // First get saved option $p['condition'] = Session::getSavedOption($this->getType(), 'condition', 0); if ($p['condition'] == 0) { $p['condition'] = $this->getDefaultRuleConditionForList(); } $use_conditions = true; // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td class='center' width='50%'>"; echo __('Rules used for') . "</td><td>"; $rule->dropdownConditions(array('value' => $p['condition'], 'on_change' => 'reloadTab("start=0&inherited=' . $p['inherited'] . '&childrens=' . $p['childrens'] . '&condition="+this.value)')); echo "</td></tr></table>"; } $nb = $this->getCollectionSize($p['inherited'], $p['condition']); $p['start'] = isset($options["start"]) ? $options["start"] : 0; if ($p['start'] >= $nb) { $p['start'] = 0; } $p['limit'] = $_SESSION['glpilist_limit']; $this->getCollectionPart($p); Html::printAjaxPager('', $p['start'], $nb); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); echo "\n<div class='spaced'>"; if ($canedit && $nb) { $massiveactionparams = array('num_displayed' => min($p['limit'], $nb), 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('entity' => $this->entity, 'condition' => $p['condition'], 'rule_class_name' => $this->getRuleClassName())); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov table-striped table-hover'>"; $colspan = 6; if ($display_entities) { $colspan++; } if ($use_conditions) { $colspan++; } echo "<tr><th colspan='{$colspan}'>" . $this->getTitle() . "</th></tr>\n"; echo "<tr>"; echo "<th>"; if ($canedit) { Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); } echo "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Description') . "</th>"; if ($use_conditions) { echo "<th>" . __('Use rule for') . "</th>"; } echo "<th>" . __('Active') . "</th>"; if ($display_entities) { echo "<th>" . __('Entity') . "</th>\n"; } if (!$display_entities) { echo "<th colspan='2'> </th>"; } echo "</tr>\n"; if (count($this->RuleList->list)) { $ruletype = $this->RuleList->list[0]->getType(); Session::initNavigateListItems($ruletype); } for ($i = $p['start'], $j = 0; isset($this->RuleList->list[$j]); $i++, $j++) { $this->RuleList->list[$j]->showMinimalForm($target, $i == 0, $i == $nb - 1, $display_entities, $p['condition']); Session::addToNavigateListItems($ruletype, $this->RuleList->list[$j]->fields['id']); } if ($nb) { echo "<tr>"; echo "<th>"; if ($canedit) { Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); } echo "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Description') . "</th>"; if ($use_conditions) { echo "<th>" . __('Use rule for') . "</th>"; } echo "<th>" . __('Active') . "</th>"; if ($display_entities) { echo "<th>" . __('Entity') . "</th>\n"; } if (!$display_entities) { echo "<th colspan='2'> </th>"; } echo "</tr>\n"; } echo "</table>\n"; if ($canedit && $nb) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } echo "</div>"; Html::closeForm(); Html::printAjaxPager('', $p['start'], $nb); echo "<div class='spaced center'>"; if ($plugin = isPluginItemType($this->getType())) { $url = $CFG_GLPI["root_doc"] . "/plugins/" . strtolower($plugin['plugin']); } else { $url = $CFG_GLPI["root_doc"]; } echo "<a class='vsubmit' href='#' onClick=\"" . Html::jsGetElementbyID('allruletest' . $rand) . ".dialog('open');\">" . __('Test rules engine') . "</a>"; Ajax::createIframeModalWindow('allruletest' . $rand, $url . "/front/rulesengine.test.php?" . "sub_type=" . $this->getRuleClassName() . "&condition=" . $p['condition'], array('title' => __('Test rules engine'))); echo "</div>"; if ($this->can_replay_rules) { echo "<div class='spaced center'>"; echo "<a class='vsubmit' href='" . $rule->getSearchURL() . "?replay_rule=replay_rule'>" . __s('Replay the dictionary rules') . "</a>"; echo "</div>"; } echo "<div class='spaced'>"; $this->showAdditionalInformationsInForm($target); echo "</div>"; }
/** * Print the HTML array of items for a location * * @since version 0.85 * * @return Nothing (display) **/ function showItems() { global $DB, $CFG_GLPI; $locations_id = $this->fields['id']; $crit = Session::getSavedOption(__CLASS__, 'criterion', ''); if (!$this->can($locations_id, READ)) { return false; } $first = 1; $query = ''; if ($crit) { $table = getTableForItemType($crit); $query = "SELECT `{$table}`.`id`, '{$crit}' AS type\n FROM `{$table}`\n WHERE `{$table}`.`locations_id` = '{$locations_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id"); } else { foreach ($CFG_GLPI['location_types'] as $type) { $table = getTableForItemType($type); $query .= ($first ? "SELECT " : " UNION SELECT ") . "`id`, '{$type}' AS type\n FROM `{$table}`\n WHERE `{$table}`.`locations_id` = '{$locations_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id"); $first = 0; } } $result = $DB->query($query); $number = $DB->numrows($result); $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0; if ($start >= $number) { $start = 0; } // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . __('Type') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Type') . " "; Dropdown::showItemType($CFG_GLPI['location_types'], array('value' => $crit, 'on_change' => 'reloadTab("start=0&criterion="+this.value)')); echo "</td></tr></table>"; if ($number) { echo "<div class='spaced'>"; Html::printAjaxPager('', $start, $number); echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; $DB->data_seek($result, $start); for ($row = 0; ($data = $DB->fetch_assoc($result)) && $row < $_SESSION['glpilist_limit']; $row++) { $item = getItemForItemtype($data['type']); $item->getFromDB($data['id']); echo "<tr class='tab_bg_1'><td class='center top'>" . $item->getTypeName() . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $item->getEntityID()); echo "</td><td class='center'>" . $item->getLink() . "</td>"; echo "<td class='center'>" . (isset($item->fields["serial"]) ? "" . $item->fields["serial"] . "" : "-"); echo "</td>"; echo "<td class='center'>" . (isset($item->fields["otherserial"]) ? "" . $item->fields["otherserial"] . "" : "-"); echo "</td></tr>"; } } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } echo "</table></div>"; }