/**
* Show the current ticketfollowup summary
*
* @param $ticket Ticket object
**/
function showSummary($ticket)
{
global $DB, $CFG_GLPI;
if (!Session::haveRightsOr(self::$rightname, array(self::SEEPUBLIC, self::SEEPRIVATE))) {
return false;
}
$tID = $ticket->fields['id'];
// Display existing Followups
$showprivate = Session::haveRight(self::$rightname, self::SEEPRIVATE);
$caneditall = Session::haveRight(self::$rightname, self::UPDATEALL);
$tmp = array('tickets_id' => $tID);
$canadd = $this->can(-1, CREATE, $tmp);
$showuserlink = 0;
if (User::canView()) {
$showuserlink = 1;
}
$techs = $ticket->getAllUsers(CommonITILActor::ASSIGN);
$reopen_case = false;
if (in_array($ticket->fields["status"], $ticket->getClosedStatusArray()) && $ticket->isAllowedStatus($ticket->fields['status'], Ticket::INCOMING)) {
$reopen_case = true;
}
$tech = Session::haveRight(self::$rightname, self::ADDALLTICKET) || $ticket->isUser(CommonITILActor::ASSIGN, Session::getLoginUserID()) || isset($_SESSION["glpigroups"]) && $ticket->haveAGroup(CommonITILActor::ASSIGN, $_SESSION['glpigroups']);
$RESTRICT = "";
if (!$showprivate) {
$RESTRICT = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "') ";
}
$query = "SELECT `glpi_ticketfollowups`.*, `glpi_users`.`picture`\n FROM `glpi_ticketfollowups`\n LEFT JOIN `glpi_users` ON (`glpi_ticketfollowups`.`users_id` = `glpi_users`.`id`)\n WHERE `tickets_id` = '{$tID}'\n {$RESTRICT}\n ORDER BY `date` DESC";
$result = $DB->query($query);
$rand = mt_rand();
if ($caneditall || $canadd) {
echo "<div id='viewfollowup" . $tID . "{$rand}'></div>\n";
}
if ($canadd) {
echo "<script type='text/javascript' >\n";
echo "function viewAddFollowup" . $ticket->fields['id'] . "{$rand}() {\n";
$params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $ticket->fields['id'], 'id' => -1);
Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
echo Html::jsHide('addbutton' . $ticket->fields['id'] . "{$rand}");
echo "};";
echo "</script>\n";
// Not closed ticket or closed
if (!in_array($ticket->fields["status"], array_merge($ticket->getSolvedStatusArray(), $ticket->getClosedStatusArray())) || $reopen_case) {
if (isset($_GET['_openfollowup']) && $_GET['_openfollowup']) {
echo Html::scriptBlock("viewAddFollowup" . $ticket->fields['id'] . "{$rand}()");
} else {
echo "<div id='addbutton" . $ticket->fields['id'] . "{$rand}' class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddFollowup" . $ticket->fields['id'] . "{$rand}();'>";
if ($reopen_case) {
_e('Reopen the ticket');
} else {
_e('Add a new followup');
}
echo "</a></div>\n";
}
}
}
if ($DB->numrows($result) == 0) {
echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>";
echo "<th class='b'>" . __('No followup for this ticket.') . "</th></tr></table>";
} else {
$today = strtotime('today');
$lastmonday = strtotime('last monday');
$lastlastmonday = strtotime('last monday', strtotime('last monday'));
// Case of monday
if ($today - $lastmonday == 7 * DAY_TIMESTAMP) {
$lastlastmonday = $lastmonday;
$lastmonday = $today;
}
$steps = array(0 => array('end' => $today, 'name' => __('Today')), 1 => array('end' => $lastmonday, 'name' => __('This week')), 2 => array('end' => $lastlastmonday, 'name' => __('Last week')), 3 => array('end' => strtotime('midnight first day of'), 'name' => __('This month')), 4 => array('end' => strtotime('midnight first day of last month'), 'name' => __('Last month')), 5 => array('end' => 0, 'name' => __('Before the last month')));
$currentpos = -1;
while ($data = $DB->fetch_assoc($result)) {
$this->getFromDB($data['id']);
$candelete = $this->canPurge() && $this->canPurgeItem();
$canedit = $this->canUpdate() && $this->canUpdateItem();
$time = strtotime($data['date']);
if (!isset($steps[$currentpos]) || $steps[$currentpos]['end'] > $time) {
$currentpos++;
while ($steps[$currentpos]['end'] > $time && isset($steps[$currentpos + 1])) {
$currentpos++;
}
if (isset($steps[$currentpos])) {
echo "<h3>" . $steps[$currentpos]['name'] . "</h3>";
}
}
$id = 'followup' . $data['id'] . $rand;
$color = 'byuser';
if (isset($techs[$data['users_id']])) {
$color = 'bytech';
}
$classtoadd = '';
if ($canedit) {
$classtoadd = " pointer";
}
echo "<div class='boxnote {$color}' id='view{$id}'";
echo ">";
echo "<div class='boxnoteleft'>";
echo "<img class='user_picture_verysmall' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($data['picture']) . "'>";
echo "</div>";
// boxnoteleft
echo "<div class='boxnotecontent'";
echo ">";
echo "<div class='boxnotefloatleft'>";
$username = NOT_AVAILABLE;
if ($data['users_id']) {
$username = getUserName($data['users_id'], $showuserlink);
}
$name = sprintf(__('Create by %1$s on %2$s'), $username, Html::convDateTime($data['date']));
if ($data['requesttypes_id']) {
$name = sprintf(__('%1$s - %2$s'), $name, Dropdown::getDropdownName('glpi_requesttypes', $data['requesttypes_id']));
}
if ($showprivate && $data["is_private"]) {
$name = sprintf(__('%1$s - %2$s'), $name, __('Private'));
}
echo $name;
echo "</div>";
// floatright
echo "<div class='boxnotetext {$classtoadd}'";
if ($canedit) {
echo " onClick=\"viewEditFollowup" . $ticket->fields['id'] . $data['id'] . "{$rand}(); " . Html::jsHide("view{$id}") . " " . Html::jsShow("viewfollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}") . "\" ";
}
echo ">";
$content = nl2br($data['content']);
if (empty($content)) {
$content = NOT_AVAILABLE;
}
echo $content . '</div>';
// boxnotetext
echo "</div>";
// boxnotecontent
echo "<div class='boxnoteright'>";
if ($candelete) {
Html::showSimpleForm(Toolbox::getItemTypeFormURL('TicketFollowup'), array('purge' => 'purge'), _x('button', 'Delete permanently'), array('id' => $data['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png", '', __('Confirm the final deletion?'));
}
echo "</div>";
// boxnoteright
echo "</div>";
// boxnote
if ($canedit) {
echo "<div id='viewfollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}' class='starthidden'></div>\n";
echo "\n<script type='text/javascript' >\n";
echo "function viewEditFollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}() {\n";
$params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $data["tickets_id"], 'id' => $data["id"]);
Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . $data["id"] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
echo "};";
echo "</script>\n";
}
}
}
}