/**
  * 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";
             }
         }
     }
 }
Example #2
0
 /**
  * @since version 0.90
  *
  * @param $rand
  **/
 function showTimeline($rand)
 {
     global $CFG_GLPI, $DB, $autolink_options;
     //get ticket actors
     $ticket_users_keys = $this->getTicketActors();
     $user = new User();
     $group = new Group();
     $followup_obj = new TicketFollowup();
     $pics_url = $CFG_GLPI['root_doc'] . "/pics/timeline";
     $timeline = $this->getTimelineItems();
     $autolink_options['strip_protocols'] = false;
     //display timeline
     echo "<div class='timeline_history'>";
     $tmp = array_values($timeline);
     $first_item = array_shift($tmp);
     // show approbation form on top when ticket is solved
     if ($this->fields["status"] == CommonITILObject::SOLVED) {
         echo "<div class='approbation_form' id='approbation_form{$rand}'>";
         $followup_obj->showApprobationForm($this);
         echo "</div>";
     }
     // show title for timeline
     self::showTimelineHeader();
     $timeline_index = 0;
     foreach ($timeline as $item) {
         $options = array('parent' => $this, 'rand' => $rand);
         if ($obj = getItemForItemtype($item['type'])) {
             $obj->fields = $item['item'];
         } else {
             $obj = $item;
         }
         Plugin::doHook('pre_show_item', array('item' => &$obj, 'options' => &$options));
         if (is_array($obj)) {
             $item_i = $obj['item'];
         } else {
             $item_i = $obj->fields;
         }
         $date = "";
         if (isset($item_i['date'])) {
             $date = $item_i['date'];
         }
         if (isset($item_i['date_mod'])) {
             $date = $item_i['date_mod'];
         }
         // check if curent item user is assignee or requester
         $user_position = 'left';
         if (isset($ticket_users_keys[$item_i['users_id']]) && $ticket_users_keys[$item_i['users_id']] == CommonItilActor::ASSIGN || $item['type'] == 'Assign') {
             $user_position = 'right';
         }
         //display solution in middle
         if ($timeline_index == 0 && $item['type'] == "Solution" && $this->fields["status"] == CommonITILObject::SOLVED) {
             $user_position .= ' middle';
         }
         echo "<div class='h_item {$user_position}'>";
         echo "<div class='h_info'>";
         echo "<div class='h_date'>" . Html::convDateTime($date) . "</div>";
         if ($item_i['users_id'] !== false) {
             echo "<div class='h_user'>";
             if (isset($item_i['users_id']) && $item_i['users_id'] != 0) {
                 $user->getFromDB($item_i['users_id']);
                 echo "<div class='tooltip_picture_border'>";
                 echo "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($user->fields['picture']) . "'>";
                 echo "</div>";
                 echo "<span class='h_user_name'>";
                 $userdata = getUserName($item_i['users_id'], 2);
                 echo $user->getLink() . "&nbsp;";
                 echo Html::showToolTip($userdata["comment"], array('link' => $userdata['link']));
                 echo "</span>";
             } else {
                 _e("Requester");
             }
             echo "</div>";
             // h_user
         }
         echo "</div>";
         //h_date
         echo "<div class='h_content " . $item['type'] . (isset($item_i['status']) ? " " . $item_i['status'] : "") . "'" . "id='viewitem" . $item['type'] . $item_i['id'] . $rand . "'>";
         if (isset($item_i['can_edit']) && $item_i['can_edit']) {
             echo "<div class='edit_item_content'></div>";
             echo "<span class='cancel_edit_item_content'></span>";
         }
         echo "<div class='displayed_content'>";
         if (!in_array($item['type'], array('Document_Item', 'Assign')) && $item_i['can_edit']) {
             echo "<span class='edit_item' ";
             echo "onclick='javascript:viewEditSubitem" . $this->fields['id'] . "{$rand}(event, \"" . $item['type'] . "\", " . $item_i['id'] . ", this, \"viewitem" . $item['type'] . $item_i['id'] . $rand . "\")'";
             echo "></span>";
         }
         if (isset($item_i['requesttypes_id']) && file_exists("{$pics_url}/" . $item_i['requesttypes_id'] . ".png")) {
             echo "<img src='{$pics_url}/" . $item_i['requesttypes_id'] . ".png' title='' class='h_requesttype' />";
         }
         if (isset($item_i['content'])) {
             $content = $item_i['content'];
             $content = autolink($content, 40);
             //$content = nl2br($content);
             $long_text = "";
             if (substr_count($content, "<br") > 30 || strlen($content) > 2000) {
                 $long_text = "long_text";
             }
             echo "<div class='item_content {$long_text}'>";
             echo "<p>";
             if (isset($item_i['state'])) {
                 $onClick = "onclick='change_task_state(" . $item_i['id'] . ", this)'";
                 if (!$item_i['can_edit']) {
                     $onClick = "style='cursor: not-allowed;'";
                 }
                 echo "<span class='state state_" . $item_i['state'] . "'\n                           {$onClick}\n                           title='" . Planning::getState($item_i['state']) . "'>";
                 echo "</span>";
             }
             echo $content;
             echo "</p>";
             if (!empty($long_text)) {
                 echo "<p class='read_more'>";
                 echo "<a class='read_more_button'>.....</a>";
                 echo "</p>";
             }
             echo "</div>";
         }
         echo "<div class='b_right'>";
         if (isset($item_i['solutiontypes_id']) && !empty($item_i['solutiontypes_id'])) {
             echo Dropdown::getDropdownName("glpi_solutiontypes", $item_i['solutiontypes_id']) . "<br>";
         }
         if (isset($item_i['taskcategories_id']) && !empty($item_i['taskcategories_id'])) {
             echo Dropdown::getDropdownName("glpi_taskcategories", $item_i['taskcategories_id']) . "<br>";
         }
         if (isset($item_i['requesttypes_id']) && !empty($item_i['requesttypes_id'])) {
             echo Dropdown::getDropdownName("glpi_requesttypes", $item_i['requesttypes_id']) . "<br>";
         }
         if (isset($item_i['actiontime']) && !empty($item_i['actiontime'])) {
             echo "<span class='actiontime'>";
             echo Html::timestampToString($item_i['actiontime'], false);
             echo "</span>";
         }
         if (isset($item_i['begin'])) {
             echo "<span class='planification'>";
             echo Html::convDateTime($item_i["begin"]);
             echo " &rArr; ";
             echo Html::convDateTime($item_i["end"]);
             echo "</span>";
         }
         if (isset($item_i['users_id_tech']) && $item_i['users_id_tech'] > 0) {
             echo "<div class='users_id_tech' id='users_id_tech_" . $item_i['users_id_tech'] . "'>";
             $user->getFromDB($item_i['users_id_tech']);
             echo Html::image($CFG_GLPI['root_doc'] . "/pics/user.png") . "&nbsp;";
             $userdata = getUserName($item_i['users_id_tech'], 2);
             echo $user->getLink() . "&nbsp;";
             echo Html::showToolTip($userdata["comment"], array('link' => $userdata['link']));
             echo "</div>";
         }
         if (isset($item_i['groups_id_tech']) && $item_i['groups_id_tech'] > 0) {
             echo "<div class='groups_id_tech'>";
             $group->getFromDB($item_i['groups_id_tech']);
             echo Html::image($CFG_GLPI['root_doc'] . "/pics/group.png") . "&nbsp;";
             echo $group->getLink() . "&nbsp;";
             echo Html::showToolTip($group->getComments(), array('link' => $group->getLinkURL()));
             echo "</div>";
         }
         // show "is_private" icon
         if (isset($item_i['is_private']) && $item_i['is_private']) {
             echo "<div class='private'>" . __('Private') . "</div>";
         }
         echo "</div>";
         // b_right
         if ($item['type'] == 'Document_Item') {
             $filename = $item_i['filename'];
             $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
             echo "<img src='";
             if (empty($filename)) {
                 $filename = $item_i['name'];
             }
             if (file_exists(GLPI_ROOT . "/pics/icones/{$ext}-dist.png")) {
                 echo $CFG_GLPI['root_doc'] . "/pics/icones/{$ext}-dist.png";
             } else {
                 echo "{$pics_url}/file.png";
             }
             echo "' title='file' />&nbsp;";
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/document.send.php?docid=" . $item_i['id'] . "&tickets_id=" . $this->getID() . "' target='_blank'>{$filename}";
             if (in_array($ext, array('jpg', 'jpeg', 'png', 'bmp'))) {
                 echo "<div class='timeline_img_preview'>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/document.send.php?docid=" . $item_i['id'] . "&tickets_id=" . $this->getID() . "'/>";
                 echo "</div>";
             }
             echo "</a>";
             if (!empty($item_i['mime'])) {
                 echo "&nbsp;(" . $item_i['mime'] . ")";
             }
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/document.form.php?id=" . $item_i['id'] . "' class='edit_document' title='" . _sx("button", "Update") . "'>";
             echo "<img src='{$pics_url}/edit.png' /></a>";
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/ticket.form.php?delete_document&documents_id=" . $item_i['id'] . "&tickets_id=" . $this->getID() . "' class='delete_document' title='" . _sx("button", "Delete permanently") . "'>";
             echo "<img src='{$pics_url}/delete.png' /></a>";
         }
         echo "</div>";
         // displayed_content
         echo "</div>";
         //end h_content
         echo "</div>";
         //end  h_info
         $timeline_index++;
         Plugin::doHook('post_show_item', array('item' => $obj, 'options' => $options));
     }
     // end foreach timeline
     echo "<div class='break'></div>";
     // recall ticket content (not needed in classic and splitted layout)
     if (!CommonGLPI::isLayoutWithMain()) {
         echo "<div class='h_item middle'>";
         echo "<div class='h_info'>";
         echo "<div class='h_date'>" . Html::convDateTime($this->fields['date']) . "</div>";
         echo "<div class='h_user'>";
         $dem = '0';
         foreach ($DB->request("glpi_tickets_users", "`tickets_id` = " . $this->fields['id'] . " AND `type` = 1") as $req) {
             $dem = $req['users_id'];
         }
         if ((!isset($item_i['users_id_recipient']) || $item_i['users_id_recipient'] == 0) && $dem == 0) {
             _e("Requester");
         } else {
             if (isset($item_i['users_id_recipient']) && $item_i['users_id_recipient'] != 0) {
                 $user->getFromDB($this->fields['users_id_recipient']);
             } else {
                 if ($dem > 0) {
                     $requester = new User();
                     if ($requester->getFromDB($dem)) {
                         $user = $requester;
                     }
                 }
             }
             echo "<div class='tooltip_picture_border'>";
             $picture = "";
             if (isset($user->fields['picture'])) {
                 $picture = $user->fields['picture'];
             }
             echo "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($picture) . "'>";
             echo "</div>";
             echo $user->getLink();
         }
         echo "</div>";
         // h_user
         echo "</div>";
         //h_info
         echo "<div class='h_content TicketContent'>";
         echo "<div class='b_right'>" . __("Ticket recall") . "</div>";
         echo "<div class='ticket_title'>";
         echo html_entity_decode($this->fields['name']);
         echo "</div>";
         echo "<div class='ticket_description'>";
         echo $this->setSimpleTextContent($this->fields['content']);
         echo "</div>";
         echo "</div>";
         // h_content TicketContent
         echo "</div>";
         // h_item middle
         echo "<div class='break'></div>";
     }
     // end timeline
     echo "</div>";
     // h_item $user_position
     echo "<script type='text/javascript'>read_more();</script>";
 }
Example #3
0
 /**
  * Print the user preference form
  *
  * @param $target          form target
  * @param $ID     integer  Id of the user
  *
  * @return boolean : user found
  **/
 function showMyForm($target, $ID)
 {
     global $CFG_GLPI, $PLUGIN_HOOKS;
     // Affiche un formulaire User
     if ($ID != Session::getLoginUserID() && !$this->currentUserHaveMoreRightThan($ID)) {
         return false;
     }
     if ($this->getFromDB($ID)) {
         $rand = mt_rand();
         $authtype = $this->getAuthMethodsByID();
         $extauth = !($this->fields["authtype"] == Auth::DB_GLPI || $this->fields["authtype"] == Auth::NOT_YET_AUTHENTIFIED && !empty($this->fields["password"]));
         // No autocopletion :
         $save_autocompletion = $CFG_GLPI["use_ajax_autocompletion"];
         $CFG_GLPI["use_ajax_autocompletion"] = false;
         echo "<div class='center'>";
         echo "<form method='post' name='user_manager' enctype='multipart/form-data' action='" . $target . "' autocomplete='off'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Login'), $this->fields["name"]);
         echo "<input type='hidden' name='name' value='" . $this->fields["name"] . "'>";
         echo "<input type='hidden' name='id' value='" . $this->fields["id"] . "'>";
         echo "</th></tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Surname') . "</td><td>";
         if ($extauth && isset($authtype['realname_field']) && !empty($authtype['realname_field'])) {
             echo $this->fields["realname"];
         } else {
             Html::autocompletionTextField($this, "realname");
         }
         echo "</td>";
         if (!empty($this->fields["name"])) {
             echo "<td rowspan='3'>" . __('Picture') . "</td>";
             echo "<td rowspan='3'>";
             echo "<div class='user_picture_border_small' id='picture{$rand}'>";
             echo "<img class='user_picture_small' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($this->fields['picture']) . "'>";
             echo "</div>";
             $full_picture = "<div class='user_picture_border'>";
             $full_picture .= "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getURLForPicture($this->fields['picture']) . "'>";
             $full_picture .= "</div>";
             Html::showTooltip($full_picture, array('applyto' => "picture{$rand}"));
             echo "<input type='file' name='picture' accept='image/*'>";
             echo "&nbsp;";
             Html::showCheckbox(array('name' => '_blank_picture', 'title' => __('Clear')));
             echo "&nbsp;" . __('Clear');
             echo "</td>";
             echo "</tr>";
         }
         echo "<tr class='tab_bg_1'><td>" . __('First name') . "</td><td>";
         if ($extauth && isset($authtype['firstname_field']) && !empty($authtype['firstname_field'])) {
             echo $this->fields["firstname"];
         } else {
             Html::autocompletionTextField($this, "firstname");
         }
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         if (!GLPI_DEMO_MODE) {
             echo "<td>" . __('Language') . "</td><td>";
             // Use session variable because field in table may be null if same of the global config
             Dropdown::showLanguages("language", array('value' => $_SESSION["glpilanguage"]));
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
         //do some rights verification
         if (!$extauth && Session::haveRight("password_update", "1")) {
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Password') . "</td>";
             echo "<td><input id='password' type='password' name='password' value='' size='30' autocomplete='off' onkeyup=\"return passwordCheck();\">";
             echo "</td>";
             echo "<td rowspan='2'>" . __('Password security policy') . "</td>";
             echo "<td rowspan='2'>";
             Config::displayPasswordSecurityChecks();
             echo "</td>";
             echo "</tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Password confirmation') . "</td>";
             echo "<td><input type='password' name='password2' value='' size='30' autocomplete='off'>";
             echo "</td></tr>";
         }
         echo "<tr class='tab_bg_1'><td>" . __('Phone') . "</td><td>";
         if ($extauth && isset($authtype['phone_field']) && !empty($authtype['phone_field'])) {
             echo $this->fields["phone"];
         } else {
             Html::autocompletionTextField($this, "phone");
         }
         echo "</td>";
         echo "<td class='top'>" . _n('Email', 'Emails', Session::getPluralNumber());
         UserEmail::showAddEmailButton($this);
         echo "</td><td>";
         UserEmail::showForUser($this);
         echo "</td>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Mobile phone') . "&nbsp;</td><td>";
         if ($extauth && isset($authtype['mobile_field']) && !empty($authtype['mobile_field'])) {
             echo $this->fields["mobile"];
         } else {
             Html::autocompletionTextField($this, "mobile");
         }
         echo "</td>";
         if (count($_SESSION['glpiprofiles']) > 1) {
             echo "<td>" . __('Default profile') . "</td><td>";
             $options = Dropdown::getDropdownArrayNames('glpi_profiles', Profile_User::getUserProfiles($this->fields['id']));
             Dropdown::showFromArray("profiles_id", $options, array('value' => $this->fields["profiles_id"], 'display_emptychoice' => true));
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Phone 2') . "</td><td>";
         if ($extauth && isset($authtype['phone2_field']) && !empty($authtype['phone2_field'])) {
             echo $this->fields["phone2"];
         } else {
             Html::autocompletionTextField($this, "phone2");
         }
         echo "</td>";
         $entities = Profile_User::getUserEntities($this->fields['id'], 1);
         if (!GLPI_DEMO_MODE && count($_SESSION['glpiactiveentities']) > 1) {
             echo "<td>" . __('Default entity') . "</td><td>";
             Entity::dropdown(array('value' => $this->fields['entities_id'], 'entity' => $entities));
         } else {
             echo "<td colspan='2'>&nbsp;";
         }
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Administrative number') . "</td><td>";
         if ($extauth && isset($authtype['registration_number_field']) && !empty($authtype['registration_number_field'])) {
             echo $this->fields["registration_number"];
         } else {
             Html::autocompletionTextField($this, "registration_number");
         }
         echo "</td><td colspan='2'></td></tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Location') . "</td><td>";
         $entities = Profile_User::getUserEntities($ID, true);
         Location::dropdown(array('value' => $this->fields['locations_id'], 'entity' => $entities));
         if (Config::canUpdate()) {
             echo "<td>" . __('Use GLPI in mode') . "</td><td>";
             $modes[Session::NORMAL_MODE] = __('Normal');
             //$modes[Session::TRANSLATION_MODE] = __('Translation');
             $modes[Session::DEBUG_MODE] = __('Debug');
             Dropdown::showFromArray('use_mode', $modes, array('value' => $this->fields["use_mode"]));
         } else {
             echo "<td colspan='2'>&nbsp;";
         }
         echo "</td></tr>";
         echo "<tr><td class='tab_bg_2 center' colspan='4'>";
         echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
         $CFG_GLPI["use_ajax_autocompletion"] = $save_autocompletion;
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * Show notepads for an item
  *
  * @param $item                  CommonDBTM object
  * @param $withtemplate integer  template or basic item (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI;
     if (!Session::haveRight($item::$rightname, READNOTE)) {
         return false;
     }
     $notes = static::getAllForItem($item);
     $rand = mt_rand();
     $canedit = Session::haveRight($item::$rightname, UPDATENOTE);
     $showuserlink = 0;
     if (User::canView()) {
         $showuserlink = 1;
     }
     if ($canedit) {
         echo "<div class='boxnote center'>";
         echo "<div class='boxnoteleft'></div>";
         echo "<form name='addnote_form{$rand}' id='addnote_form{$rand}' ";
         echo " method='post' action='" . Toolbox::getItemTypeFormURL('Notepad') . "'>";
         echo Html::hidden('itemtype', array('value' => $item->getType()));
         echo Html::hidden('items_id', array('value' => $item->getID()));
         echo "<div class='boxnotecontent'>";
         echo "<div class='floatleft'>";
         echo "<textarea name='content' rows=5 cols=100></textarea>";
         echo "</div>";
         echo "</div>";
         // box notecontent
         echo "<div class='boxnoteright'><br>";
         echo Html::submit(_x('button', 'Add'), array('name' => 'add'));
         echo "</div>";
         Html::closeForm();
         echo "</div>";
         // boxnote
     }
     if (count($notes)) {
         foreach ($notes as $note) {
             $id = 'note' . $note['id'] . $rand;
             $classtoadd = '';
             if ($canedit) {
                 $classtoadd = " pointer";
             }
             echo "<div class='boxnote' id='view{$id}'>";
             echo "<div class='boxnoteleft'>";
             echo "<img class='user_picture_verysmall' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($note['picture']) . "'>";
             echo "</div>";
             // boxnoteleft
             echo "<div class='boxnotecontent'>";
             echo "<div class='boxnotefloatright'>";
             $username = NOT_AVAILABLE;
             if ($note['users_id_lastupdater']) {
                 $username = getUserName($note['users_id_lastupdater'], $showuserlink);
             }
             $update = sprintf(__('Last update by %1$s on %2$s'), $username, Html::convDateTime($note['date_mod']));
             $username = NOT_AVAILABLE;
             if ($note['users_id']) {
                 $username = getUserName($note['users_id'], $showuserlink);
             }
             $create = sprintf(__('Create by %1$s on %2$s'), $username, Html::convDateTime($note['date']));
             printf(__('%1$s / %2$s'), $update, $create);
             echo "</div>";
             // floatright
             echo "<div class='boxnotetext {$classtoadd}' ";
             if ($canedit) {
                 echo "onclick=\"" . Html::jsHide("view{$id}") . " " . Html::jsShow("edit{$id}") . "\"";
             }
             echo ">";
             $content = nl2br($note['content']);
             if (empty($content)) {
                 $content = NOT_AVAILABLE;
             }
             echo $content . '</div>';
             // boxnotetext
             echo "</div>";
             // boxnotecontent
             echo "<div class='boxnoteright'>";
             if ($canedit) {
                 Html::showSimpleForm(Toolbox::getItemTypeFormURL('Notepad'), array('purge' => 'purge'), _x('button', 'Delete permanently'), array('id' => $note['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png", '', __('Confirm the final deletion?'));
             }
             echo "</div>";
             // boxnoteright
             echo "</div>";
             // boxnote
             if ($canedit) {
                 echo "<div class='boxnote starthidden' id='edit{$id}'>";
                 echo "<form name='update_form{$id}{$rand}' id='update_form{$id}{$rand}' ";
                 echo " method='post' action='" . Toolbox::getItemTypeFormURL('Notepad') . "'>";
                 echo "<div class='boxnoteleft'></div>";
                 echo "<div class='boxnotecontent'>";
                 echo Html::hidden('id', array('value' => $note['id']));
                 echo "<textarea name='content' rows=5 cols=100>" . $note['content'] . "</textarea>";
                 echo "</div>";
                 // boxnotecontent
                 echo "<div class='boxnoteright'><br>";
                 echo Html::submit(_x('button', 'Update'), array('name' => 'update'));
                 echo "</div>";
                 // boxnoteright
                 Html::closeForm();
                 echo "</div>";
                 // boxnote
             }
         }
     }
     return true;
 }
Example #5
0
 /**
  * @since version 0.90
  *
  * @param $rand
  **/
 function showTimeline($rand)
 {
     global $CFG_GLPI, $DB;
     //get ticket actors
     $ticket_users_keys = $this->getTicketActors();
     $user = new User();
     $followup_obj = new TicketFollowup();
     $pics_url = $CFG_GLPI['root_doc'] . "/pics/timeline";
     $timeline = $this->getTimelineItems();
     //include lib for parsing url
     require GLPI_ROOT . "/lib/urllinker/urllinker.php";
     //display timeline
     echo "<div class='timeline_history'>";
     $tmp = array_values($timeline);
     $first_item = array_shift($tmp);
     // show approbation form on top when ticket is solved
     if ($this->fields["status"] == CommonITILObject::SOLVED) {
         echo "<div class='approbation_form' id='approbation_form{$rand}'>";
         $followup_obj->showApprobationForm($this);
         echo "</div>";
     }
     // show title for timeline
     self::showTimelineHeader();
     $timeline_index = 0;
     foreach ($timeline as $item) {
         $item_i = $item['item'];
         // don't display empty followup (ex : solution approbation)
         if ($item['type'] == 'TicketFollowup' && empty($item_i['content'])) {
             continue;
         }
         $date = "";
         if (isset($item_i['date'])) {
             $date = $item_i['date'];
         }
         if (isset($item_i['date_mod'])) {
             $date = $item_i['date_mod'];
         }
         // check if curent item user is assignee or requester
         $user_position = 'left';
         if (isset($ticket_users_keys[$item_i['users_id']]) && $ticket_users_keys[$item_i['users_id']] == CommonItilActor::ASSIGN || $item['type'] == 'Assign') {
             $user_position = 'right';
         }
         //display solution in middle
         if ($timeline_index == 0 && $item['type'] == "Solution" && $this->fields["status"] == CommonITILObject::SOLVED) {
             $user_position .= ' middle';
         }
         echo "<div class='h_item {$user_position}'>";
         echo "<div class='h_info'>";
         echo "<div class='h_date'>" . Html::convDateTime($date) . "</div>";
         if ($item_i['users_id'] !== false) {
             echo "<div class='h_user'>";
             if (isset($item_i['users_id']) && $item_i['users_id'] != 0) {
                 $user->getFromDB($item_i['users_id']);
                 echo "<div class='tooltip_picture_border'>";
                 echo "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($user->fields['picture']) . "'>";
                 echo "</div>";
                 echo $user->getLink();
             } else {
                 _e("Requester");
             }
             echo "</div>";
             // h_user
         }
         echo "</div>";
         //h_date
         echo "<div class='h_content " . $item['type'] . (isset($item_i['status']) ? " " . $item_i['status'] : "") . "'";
         if (!in_array($item['type'], array('Document_Item', 'Assign')) && $item_i['can_edit']) {
             echo " ondblclick='javascript:viewEditSubitem" . $this->fields['id'] . "{$rand}(event, \"" . $item['type'] . "\", " . $item_i['id'] . ", this)'";
         }
         echo ">";
         if (isset($item_i['requesttypes_id']) && file_exists("{$pics_url}/" . $item_i['requesttypes_id'] . ".png")) {
             echo "<img src='{$pics_url}/" . $item_i['requesttypes_id'] . ".png' title='' class='h_requesttype' />";
         }
         if (isset($item_i['content'])) {
             $content = $item_i['content'];
             $content = linkUrlsInTrustedHtml($content);
             //$content = nl2br($content);
             $long_text = "";
             if (substr_count($content, "<br") > 30 || strlen($content) > 2000) {
                 $long_text = "long_text";
             }
             echo "<div class='item_content {$long_text}'>";
             echo "<p>{$content}</p>";
             if (!empty($long_text)) {
                 echo "<p class='read_more'>";
                 echo "<a class='read_more_button'>.....</a>";
                 echo "</p>";
             }
             echo "</div>";
         }
         echo "<div class='b_right'>";
         if (isset($item_i['solutiontypes_id']) && !empty($item_i['solutiontypes_id'])) {
             echo Dropdown::getDropdownName("glpi_solutiontypes", $item_i['solutiontypes_id']) . "<br>";
         }
         if (isset($item_i['taskcategories_id']) && !empty($item_i['taskcategories_id'])) {
             echo Dropdown::getDropdownName("glpi_taskcategories", $item_i['taskcategories_id']) . "<br>";
         }
         if (isset($item_i['actiontime']) && !empty($item_i['actiontime'])) {
             echo "<span class='actiontime'>";
             echo Html::timestampToString($item_i['actiontime'], false);
             echo "</span>";
         }
         if (isset($item_i['state'])) {
             echo "<span class='state state_" . $item_i['state'] . "'>";
             echo Planning::getState($item_i['state']);
             echo "</span>";
         }
         if (isset($item_i['begin'])) {
             echo "<span class='planification'>";
             echo Html::convDateTime($item_i["begin"]);
             echo " &rArr; ";
             echo Html::convDateTime($item_i["end"]);
             echo "</span>";
         }
         if (isset($item_i['users_id_tech'])) {
             echo "<div class='users_id_tech'>";
             $user->getFromDB($item_i['users_id_tech']);
             echo "<div class='tooltip_picture_border'>";
             echo "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($user->fields['picture']) . "'>";
             echo "</div>";
             echo $user->getLink();
             echo "</div>";
         }
         // show "is_private" icon
         if (isset($item_i['is_private']) && $item_i['is_private']) {
             echo "<div class='private'>" . __('Private') . "</div>";
         }
         echo "</div>";
         // b_right
         if ($item['type'] == 'Document_Item') {
             $filename = $item_i['filename'];
             $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
             echo "<img src='";
             if (empty($filename)) {
                 $filename = $item_i['name'];
             }
             if (file_exists(GLPI_ROOT . "/pics/icones/{$ext}-dist.png")) {
                 echo $CFG_GLPI['root_doc'] . "/pics/icones/{$ext}-dist.png";
             } else {
                 echo "{$pics_url}/file.png";
             }
             echo "' title='file' />&nbsp;";
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/document.send.php?docid=" . $item_i['id'] . "&tickets_id=" . $this->getID() . "' target='_blank'>{$filename}";
             if (in_array($ext, array('jpg', 'jpeg', 'png', 'bmp'))) {
                 echo "<div class='timeline_img_preview'>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/document.send.php?docid=" . $item_i['id'] . "&tickets_id=" . $this->getID() . "'/>";
                 echo "</div>";
             }
             echo "</a>";
             if (!empty($item_i['mime'])) {
                 echo "&nbsp;(" . $item_i['mime'] . ")";
             }
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/document.form.php?id=" . $item_i['id'] . "' class='edit_document' title='" . _sx("button", "Update") . "'>";
             echo "<img src='{$pics_url}/edit.png' /></a>";
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/ticket.form.php?delete_document&documents_id=" . $item_i['id'] . "&tickets_id=" . $this->getID() . "' class='delete_document' title='" . _sx("button", "Delete permanently") . "'>";
             echo "<img src='{$pics_url}/delete.png' /></a>";
         }
         echo "</div>";
         //end h_content
         echo "</div>";
         //end  h_info
         $timeline_index++;
     }
     // end foreach timeline
     echo "<div class='break'></div>";
     // recall ticket content (not needed in classic and splitted layout)
     if (!CommonGLPI::isLayoutWithMain()) {
         echo "<div class='h_item middle'>";
         echo "<div class='h_info'>";
         echo "<div class='h_date'>" . Html::convDateTime($this->fields['date']) . "</div>";
         echo "<div class='h_user'>";
         if (isset($item_i['users_id_recipient']) && $item_i['users_id_recipient'] != 0) {
             $user->getFromDB($this->fields['users_id_recipient']);
             echo "<div class='tooltip_picture_border'>";
             $picture = "";
             if (isset($user->fields['picture'])) {
                 $picture = $user->fields['picture'];
             }
             echo "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($picture) . "'>";
             echo "</div>";
             echo $user->getLink();
         } else {
             _e("Requester");
         }
         echo "</div>";
         // h_user
         echo "</div>";
         //h_info
         echo "<div class='h_content TicketContent'>";
         echo "<div class='b_right'>" . __("Ticket recall") . "</div>";
         echo "<div class='ticket_title'>";
         echo html_entity_decode($this->fields['name']);
         echo "</div>";
         echo "<div class='ticket_description'>";
         echo Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content']));
         echo "</div>";
         echo "</div>";
         // h_content TicketContent
         echo "</div>";
         // h_item middle
         echo "<div class='break'></div>";
     }
     // end timeline
     echo "</div>";
     // h_item $user_position
     echo "<script type='text/javascript'>read_more();</script>";
 }
/**
 * Get name of the user with ID=$ID (optional with link to user.form.php)
 *
 *@param $ID   integer  ID of the user.
 *@param $link integer  1 = Show link to user.form.php 2 = return array with comments and link
 *                      (default =0)
 *
 *@return string : username string (realname if not empty and name if realname is empty).
**/
function getUserName($ID, $link = 0)
{
    global $DB, $CFG_GLPI;
    $user = "";
    if ($link == 2) {
        $user = array("name" => "", "link" => "", "comment" => "");
    }
    if ($ID) {
        $query = "SELECT *\n                 FROM `glpi_users`\n                 WHERE `id` = '{$ID}'";
        $result = $DB->query($query);
        if ($link == 2) {
            $user = array("name" => "", "comment" => "", "link" => "");
        }
        if ($DB->numrows($result) == 1) {
            $data = $DB->fetch_assoc($result);
            $username = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], $link);
            if ($link == 2) {
                $user["name"] = $username;
                $user["link"] = $CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $ID;
                $user['comment'] = '';
                $comments = array();
                $comments[] = array('name' => __('Name'), 'value' => $username);
                $comments[] = array('name' => __('Login'), 'value' => $data["name"]);
                $email = UserEmail::getDefaultForUser($ID);
                if (!empty($email)) {
                    $comments[] = array('name' => __('Email'), 'value' => $email);
                }
                if (!empty($data["phone"])) {
                    $comments[] = array('name' => __('Phone'), 'value' => $data["phone"]);
                }
                if (!empty($data["mobile"])) {
                    $comments[] = array('name' => __('Mobile phone'), 'value' => $data["mobile"]);
                }
                if ($data["locations_id"] > 0) {
                    $comments[] = array('name' => __('Location'), 'value' => Dropdown::getDropdownName("glpi_locations", $data["locations_id"]));
                }
                if ($data["usertitles_id"] > 0) {
                    $comments[] = array('name' => _x('person', 'Title'), 'value' => Dropdown::getDropdownName("glpi_usertitles", $data["usertitles_id"]));
                }
                if ($data["usercategories_id"] > 0) {
                    $comments[] = array('name' => __('Category'), 'value' => Dropdown::getDropdownName("glpi_usercategories", $data["usercategories_id"]));
                }
                if (count($comments)) {
                    $user['comment'] = $user['comment'];
                    foreach ($comments as $datas) {
                        // Do not use SPAN here
                        $user['comment'] .= sprintf(__('%1$s: %2$s') . "<br>", "<strong>" . $datas['name'] . "</strong>", $datas['value']);
                    }
                }
                if (!empty($data['picture'])) {
                    $user['comment'] = "<div class='tooltip_picture_border'>" . "<img  class='tooltip_picture' src='" . User::getThumbnailURLForPicture($data['picture']) . "' /></div>" . "<div class='tooltip_text'>" . $user['comment'] . "</div>";
                }
            } else {
                $user = $username;
            }
        }
    }
    return $user;
}