Example #1
0
 static function showShort($id, $followups, $output_type = HTML_OUTPUT, $row_num = 0)
 {
     global $CFG_GLPI, $LANG;
     $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 = haveRight("delete_ticket", "1");
     $canupdate = haveRight("update_ticket", "1");
     $showprivate = 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);
         // First column
         $first_col = "ID : " . $job->fields["id"];
         if ($output_type == HTML_OUTPUT) {
             $first_col .= "<br><img src='" . $CFG_GLPI["root_doc"] . "/pics/" . $job->fields["status"] . ".png'\n                           alt=\"" . self::getStatus($job->fields["status"]) . "\" title=\"" . self::getStatus($job->fields["status"]) . "\">";
         } else {
             $first_col .= " - " . self::getStatus($job->fields["status"]);
         }
         if (($candelete || $canupdate) && $output_type == HTML_OUTPUT) {
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             if (isset($_SESSION['glpimassiveactionselected'][$job->fields["id"]])) {
                 $sel = "checked";
             }
             $first_col .= "&nbsp;<input type='checkbox' name='item[" . $job->fields["id"] . "]'\n                                  value='1' {$sel}>";
         }
         echo Search::showItem($output_type, $first_col, $item_num, $row_num, $align);
         // Second column
         if ($job->fields['status'] == 'closed') {
             $second_col = $LANG['joblist'][12];
             if ($output_type == HTML_OUTPUT) {
                 $second_col .= "&nbsp;:<br>";
             } else {
                 $second_col .= " : ";
             }
             $second_col .= convDateTime($job->fields['closedate']);
         } else {
             if ($job->fields['status'] == 'solved') {
                 $second_col = $LANG['joblist'][14];
                 if ($output_type == HTML_OUTPUT) {
                     $second_col .= "&nbsp;:<br>";
                 } else {
                     $second_col .= " : ";
                 }
                 $second_col .= convDateTime($job->fields['solvedate']);
             } else {
                 if ($job->fields['begin_waiting_date']) {
                     $second_col = $LANG['joblist'][26];
                     if ($output_type == HTML_OUTPUT) {
                         $second_col .= "&nbsp;:<br>";
                     } else {
                         $second_col .= " : ";
                     }
                     $second_col .= convDateTime($job->fields['begin_waiting_date']);
                 } else {
                     if ($job->fields['due_date']) {
                         $second_col = $LANG['sla'][5];
                         if ($output_type == HTML_OUTPUT) {
                             $second_col .= "&nbsp;:<br>";
                         } else {
                             $second_col .= " : ";
                         }
                         $second_col .= convDateTime($job->fields['due_date']);
                     } else {
                         $second_col = $LANG['joblist'][11];
                         if ($output_type == HTML_OUTPUT) {
                             $second_col .= "&nbsp;:<br>";
                         } else {
                             $second_col .= " : ";
                         }
                         $second_col .= convDateTime($job->fields['date']);
                     }
                 }
             }
         }
         echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=130");
         // Second BIS column
         $second_col = 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) {
             if ($job->fields['entities_id'] == 0) {
                 $second_col = $LANG['entity'][2];
             } else {
                 $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, "<strong>" . self::getPriorityName($job->fields["priority"]) . "</strong>", $item_num, $row_num, "{$align} bgcolor='{$bgcolor}'");
         // Fourth Column
         $fourth_col = "";
         if (isset($job->users[self::REQUESTER]) && count($job->users[self::REQUESTER])) {
             foreach ($job->users[self::REQUESTER] as $k => $d) {
                 $userdata = getUserName($k, 2);
                 $fourth_col .= "<strong>" . $userdata['name'] . "</strong>&nbsp;";
                 $fourth_col .= showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                 $fourth_col .= "<br>";
             }
         }
         if (isset($job->groups[self::REQUESTER]) && count($job->groups[self::REQUESTER])) {
             foreach ($job->groups[self::REQUESTER] as $k => $d) {
                 $fourth_col .= Dropdown::getDropdownName("glpi_groups", $k);
                 $fourth_col .= "<br>";
             }
         }
         echo Search::showItem($output_type, $fourth_col, $item_num, $row_num, $align);
         // Fifth column
         $fifth_col = "";
         if (isset($job->users[self::ASSIGN]) && count($job->users[self::ASSIGN])) {
             foreach ($job->users[self::ASSIGN] as $k => $d) {
                 $userdata = getUserName($k, 2);
                 $fifth_col .= "<strong>" . $userdata['name'] . "</strong>&nbsp;";
                 $fifth_col .= showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                 $fifth_col .= "<br>";
             }
         }
         if (isset($job->groups[self::ASSIGN]) && count($job->groups[self::ASSIGN])) {
             foreach ($job->groups[self::ASSIGN] as $k => $d) {
                 $fourth_col .= Dropdown::getDropdownName("glpi_groups", $k);
                 $fourth_col .= "<br>";
             }
         }
         if ($job->fields["suppliers_id_assign"] > 0) {
             if (!empty($fifth_col)) {
                 $fifth_col .= "<br>";
             }
             $fifth_col .= self::getAssignName($job->fields["suppliers_id_assign"], 'Supplier', 1);
         }
         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 (class_exists($job->fields["itemtype"])) {
                 $item = new $job->fields["itemtype"]();
                 if ($item->getFromDB($job->fields["items_id"])) {
                     $is_deleted = $item->isDeleted();
                     $sixth_col .= $item->getTypeName();
                     $sixth_col .= "<br><strong>";
                     if ($item->canView()) {
                         $sixth_col .= $item->getLink($output_type == HTML_OUTPUT);
                     } else {
                         $sixth_col .= $item->getNameID();
                     }
                     $sixth_col .= "</strong>";
                 }
             }
         } else {
             if (empty($job->fields["itemtype"])) {
                 $sixth_col = $LANG['help'][30];
             }
         }
         echo Search::showItem($output_type, $sixth_col, $item_num, $row_num, $is_deleted ? " class='center deleted' " : $align);
         // Seventh column
         echo Search::showItem($output_type, "<strong>" . Dropdown::getDropdownName('glpi_ticketcategories', $job->fields["ticketcategories_id"]) . "</strong>", $item_num, $row_num, $align);
         // ninth column
         $ninth_column = "<strong>" . $job->fields["name"] . "</strong>&nbsp;";
         // Add link
         if ($job->canViewItem()) {
             $ninth_column = "<a id='ticket" . $job->fields["id"] . "{$rand}' href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $job->fields["id"] . "\">{$ninth_column}</a>";
             if ($followups && $output_type == HTML_OUTPUT) {
                 $ninth_column .= TicketFollowup::showShortForTicket($job->fields["id"]);
             } else {
                 $ninth_column .= "&nbsp;(" . $job->numberOfFollowups($showprivate) . "-" . $job->numberOfTasks($showprivate) . ")";
             }
         }
         if ($output_type == HTML_OUTPUT) {
             $ninth_column .= "&nbsp;" . showToolTip($job->fields['content'], array('display' => false, 'applyto' => "ticket" . $job->fields["id"] . $rand));
         }
         echo Search::showItem($output_type, $ninth_column, $item_num, $row_num, $align_desc . "width='300'");
         // Finish Line
         echo Search::showEndLine($output_type);
     } else {
         echo "<tr class='tab_bg_2'><td colspan='6' ><i>" . $LANG['joblist'][16] . "</i></td></tr>";
     }
 }
Example #2
0
 /**
  * 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>&nbsp;";
         // 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>";
     }
 }
Example #3
0
 /**
  * Populate the planning with planned reminder
  *
  * @param $options   array of possible options:
  *    - who ID of the user (0 = undefined)
  *    - who_group ID of the group of users (0 = undefined)
  *    - begin Date
  *    - end Date
  *    - color
  *    - event_type_color
  *    - check_planned (boolean)
  *    - display_done_events (boolean)
  *
  * @return array of planning item
  **/
 static function populatePlanning($options = array())
 {
     global $DB, $CFG_GLPI;
     $default_options = array('color' => '', 'event_type_color' => '', 'check_planned' => false, 'display_done_events' => true);
     $options = array_merge($default_options, $options);
     $interv = array();
     $reminder = new self();
     if (!isset($options['begin']) || $options['begin'] == 'NULL' || !isset($options['end']) || $options['end'] == 'NULL') {
         return $interv;
     }
     $who = $options['who'];
     $who_group = $options['who_group'];
     $begin = $options['begin'];
     $end = $options['end'];
     $readpub = $readpriv = "";
     $joinstoadd = self::addVisibilityJoins(true);
     // See public reminder ?
     if ($who === Session::getLoginUserID() && self::canView()) {
         $readpub = self::addVisibilityRestrict();
     }
     // See my private reminder ?
     if ($who_group === "mine" || $who === Session::getLoginUserID()) {
         $readpriv = "(`glpi_reminders`.`users_id` = '" . Session::getLoginUserID() . "')";
     } else {
         if ($who > 0) {
             $readpriv = "`glpi_reminders`.`users_id` = '{$who}'";
         }
         if ($who_group > 0) {
             if (!empty($readpriv)) {
                 $readpriv .= " OR ";
             }
             $readpriv .= " `glpi_groups_reminders`.`groups_id` = '{$who_group}'";
         }
         if (!empty($readpriv)) {
             $readpriv = '(' . $readpriv . ')';
         }
     }
     $ASSIGN = '';
     if (!empty($readpub) && !empty($readpriv)) {
         $ASSIGN = "({$readpub} OR {$readpriv})";
     } else {
         if ($readpub) {
             $ASSIGN = $readpub;
         } else {
             $ASSIGN = $readpriv;
         }
     }
     $PLANNED = '';
     if ($options['check_planned']) {
         $PLANNED = "AND state != " . Planning::INFO;
     }
     $DONE_EVENTS = '';
     if (!$options['display_done_events']) {
         $DONE_EVENTS = "AND state != " . Planning::DONE;
     }
     if ($ASSIGN) {
         $query2 = "SELECT DISTINCT `glpi_reminders`.*\n                    FROM `glpi_reminders`\n                    {$joinstoadd}\n                    WHERE `glpi_reminders`.`is_planned` = '1'\n                          AND {$ASSIGN}\n                          {$PLANNED}\n                          {$DONE_EVENTS}\n                          AND `begin` < '{$end}'\n                          AND `end` > '{$begin}'\n                    ORDER BY `begin`";
         $result2 = $DB->query($query2);
         if ($DB->numrows($result2) > 0) {
             for ($i = 0; $data = $DB->fetch_assoc($result2); $i++) {
                 if ($reminder->getFromDB($data["id"]) && $reminder->canViewItem()) {
                     $key = $data["begin"] . "\$\$" . "Reminder" . "\$\$" . $data["id"];
                     $interv[$key]['color'] = $options['color'];
                     $interv[$key]['event_type_color'] = $options['event_type_color'];
                     $interv[$key]["itemtype"] = 'Reminder';
                     $interv[$key]["reminders_id"] = $data["id"];
                     $interv[$key]["id"] = $data["id"];
                     if (strcmp($begin, $data["begin"]) > 0) {
                         $interv[$key]["begin"] = $begin;
                     } else {
                         $interv[$key]["begin"] = $data["begin"];
                     }
                     if (strcmp($end, $data["end"]) < 0) {
                         $interv[$key]["end"] = $end;
                     } else {
                         $interv[$key]["end"] = $data["end"];
                     }
                     $interv[$key]["name"] = Html::resume_text($data["name"], $CFG_GLPI["cut"]);
                     $interv[$key]["text"] = Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($data["text"])), $CFG_GLPI["cut"]);
                     $interv[$key]["users_id"] = $data["users_id"];
                     $interv[$key]["state"] = $data["state"];
                     $interv[$key]["state"] = $data["state"];
                     $interv[$key]["url"] = $CFG_GLPI["root_doc"] . "/front/reminder.form.php?id=" . $data['id'];
                     $interv[$key]["ajaxurl"] = $CFG_GLPI["root_doc"] . "/ajax/planning.php" . "?action=edit_event_form" . "&itemtype=Reminder" . "&id=" . $data['id'] . "&url=" . $interv[$key]["url"];
                     $interv[$key]["editable"] = $reminder->canUpdateItem();
                 }
             }
         }
     }
     return $interv;
 }