Problem_Ticket::showForProblem PHP Method

showForProblem() static public method

Show tickets for a problem
static public showForProblem ( Problem $problem )
$problem Problem Problem object
    static function showForProblem(Problem $problem)
    {
        global $DB, $CFG_GLPI;
        $ID = $problem->getField('id');
        if (!$problem->can($ID, READ)) {
            return false;
        }
        $canedit = $problem->canEdit($ID);
        $rand = mt_rand();
        $query = "SELECT DISTINCT `glpi_problems_tickets`.`id` AS linkID,\n                                `glpi_tickets`.*\n                FROM `glpi_problems_tickets`\n                LEFT JOIN `glpi_tickets`\n                     ON (`glpi_problems_tickets`.`tickets_id` = `glpi_tickets`.`id`)\n                WHERE `glpi_problems_tickets`.`problems_id` = '{$ID}'\n                ORDER BY `glpi_tickets`.`name`";
        $result = $DB->query($query);
        $tickets = array();
        $used = array();
        if ($numrows = $DB->numrows($result)) {
            while ($data = $DB->fetch_assoc($result)) {
                $tickets[$data['id']] = $data;
                $used[$data['id']] = $data['id'];
            }
        }
        if ($canedit) {
            echo "<div class='firstbloc'>";
            echo "<form name='changeticket_form{$rand}' id='changeticket_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 ticket') . "</th></tr>";
            echo "<tr class='tab_bg_2'><td class='right'>";
            echo "<input type='hidden' name='problems_id' value='{$ID}'>";
            $condition = "`glpi_tickets`.`status`\n                        NOT IN ('" . implode("', '", array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . "')";
            Ticket::dropdown(array('used' => $used, 'entity' => $problem->getEntityID(), 'entity_sons' => $problem->isRecursive(), 'condition' => $condition, 'displaywith' => array('id')));
            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, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'), __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'solveticket' => __('Solve tickets'), __CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'add_task' => __('Add a new task')), 'extraparams' => array('problems_id' => $problem->getID()), 'width' => 1000, 'height' => 500);
            Html::showMassiveActions($massiveactionparams);
        }
        echo "<table class='tab_cadre_fixehov'>";
        echo "<tr class='noHover'><th colspan='12'>" . Ticket::getTypeName($numrows) . "</th>";
        echo "</tr>";
        if ($numrows) {
            Ticket::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
            Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), Problem::getTypeName(1), $problem->fields["name"]));
            $i = 0;
            foreach ($tickets as $data) {
                Session::addToNavigateListItems('Ticket', $data["id"]);
                Ticket::showShort($data['id'], array('followups' => false, 'row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID']));
                $i++;
            }
            Ticket::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
        }
        echo "</table>";
        if ($canedit && $numrows) {
            $massiveactionparams['ontop'] = false;
            Html::showMassiveActions($massiveactionparams);
            Html::closeForm();
        }
        echo "</div>";
    }

Usage Example

Exemplo n.º 1
0
 static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     switch ($item->getType()) {
         case 'Change':
             Change_Ticket::showForChange($item);
             break;
         case 'Problem':
             Problem_Ticket::showForProblem($item);
             break;
         case __CLASS__:
             switch ($tabnum) {
                 case 2:
                     if (!isset($_POST['load_kb_sol'])) {
                         $_POST['load_kb_sol'] = 0;
                     }
                     $item->showSolutionForm($_POST['load_kb_sol']);
                     if ($item->canApprove()) {
                         $fup = new TicketFollowup();
                         $fup->showApprobationForm($item);
                     }
                     break;
                 case 3:
                     $satisfaction = new TicketSatisfaction();
                     if ($item->fields['status'] == self::CLOSED && $satisfaction->getFromDB($_POST["id"])) {
                         $satisfaction->showSatisfactionForm($item);
                     } else {
                         echo "<p class='center b'>" . __('No generated survey') . "</p>";
                     }
                     break;
                 case 4:
                     $item->showStats();
                     break;
             }
             break;
         case 'Group':
         case 'SLA':
         default:
             self::showListForItem($item);
     }
     return true;
 }