/** * 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::haveRight("show_all_ticket", "1")) { 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['field'][0] = 4; // status $options['searchtype'][0] = 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = 'AND'; break; case 'SLA': $restrict = "(`slas_id` = '" . $item->getID() . "')"; $order = '`glpi_tickets`.`due_date` DESC'; $options['field'][0] = 30; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = '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['field'][0] = 6; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = '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}\n AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['field'][0] = 71; $options['searchtype'][0] = $tree ? 'under' : 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = 'AND'; break; default: $restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_tickets`.`date_mod` DESC'; $options['field'][0] = 12; $options['searchtype'][0] = 'equals'; $options['contains'][0] = 'all'; $options['link'][0] = 'AND'; $options['itemtype2'][0] = $item->getType(); $options['field2'][0] = Search::getOptionNumber($item->getType(), 'id'); $options['searchtype2'][0] = 'equals'; $options['contains2'][0] = $item->getID(); $options['link2'][0] = '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); // Ticket for the item echo "<div class='firstbloc'>"; // Link to open a new ticket if ($item->getID() && Ticket::isPossibleToAssignType($item->getType()) && Session::haveRight('create_ticket', 1)) { 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 "<table class='tab_cadre_fixe'>"; if ($number > 0) { Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); echo "<tr><th colspan='11'>"; $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>" . __('No ticket found.') . "</th></tr>"; } if ($item->getID() && $item->getType() == 'User' && Session::haveRight('create_ticket', 1)) { echo "<tr><td class='tab_bg_2 center b' colspan='11'>"; 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"], 0); } } echo "</table></div>"; // Tickets for linked items if ($subquery = $item->getSelectLinkedItem()) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE (`itemtype`,`items_id`) IN (" . $subquery . ")" . 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='11'>"; 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"], 0); } } else { echo "<tr><th>" . __('No ticket found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }
/** * Display problems for an item * * Will also display problems of linked items * * @param $item CommonDBTM object * * @return nothing (display a table) **/ static function showListForItem(CommonDBTM $item) { global $DB, $CFG_GLPI; if (!Session::haveRight("show_all_problem", "1")) { return false; } if ($item->isNewID($item->getID())) { return false; } $restrict = ''; $order = ''; $options['reset'] = 'reset'; switch ($item->getType()) { case 'User': $restrict = "(`glpi_problems_users`.`users_id` = '" . $item->getID() . "'\n AND `glpi_problems_users`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_problems`.`date_mod` DESC'; $options['reset'] = 'reset'; $options['field'][0] = 4; // status $options['searchtype'][0] = 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = 'AND'; break; case 'Supplier': $restrict = "(`glpi_problems_suppliers`.`suppliers_id` = '" . $item->getID() . "'\n AND `glpi_problems_suppliers`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_problems`.`date_mod` DESC'; $options['field'][0] = 6; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = '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 problems') . "</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_groups_problems`.`groups_id` {$restrict}\n AND `glpi_groups_problems`.`type` = " . CommonITILActor::REQUESTER . ")"; $order = '`glpi_problems`.`date_mod` DESC'; $options['field'][0] = 71; $options['searchtype'][0] = $tree ? 'under' : 'equals'; $options['contains'][0] = $item->getID(); $options['link'][0] = 'AND'; break; default: $restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')"; $order = '`glpi_problems`.`date_mod` DESC'; // $options['field'][0] = 12; // $options['searchtype'][0] = 'equals'; // $options['contains'][0] = 'all'; // $options['link'][0] = 'AND'; // // $options['itemtype2'][0] = $item->getType(); // $options['field2'][0] = Search::getOptionNumber($item->getType(), 'id'); // $options['searchtype2'][0] = 'equals'; // $options['contains2'][0] = $item->getID(); // $options['link2'][0] = 'AND'; break; } $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_problems`\n LEFT JOIN `glpi_items_problems`\n ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\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'>"; if ($number > 0) { Session::initNavigateListItems('Problem', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); if (count($_SESSION["glpiactiveentities"]) > 1) { echo "<tr><th colspan='9'>"; } else { echo "<tr><th colspan='8'>"; } //TRANS : %d is the number of problems echo sprintf(_n('Last %d problem', 'Last %d problems', $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 problem 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"]); } } echo "</table></div>"; // Tickets for linked items if ($subquery = $item->getSelectLinkedItem()) { $query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_problems`\n LEFT JOIN `glpi_items_problems`\n ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . self::getCommonLeftJoin() . "\n WHERE (`itemtype`,`items_id`) IN (" . $subquery . ")" . getEntitiesRestrictRequest(' AND ', 'glpi_problems') . "\n ORDER BY `glpi_problems`.`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='8'>"; _e('Problems 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"]); } } else { echo "<tr><th>" . __('No problem found.') . "</th></tr>"; } echo "</table></div>"; } // Subquery for linked item }