Наследование: extends CommonDBTM
Пример #1
0
 static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job)
 {
     global $CFG_GLPI, $DB;
     $ID = $job->getField('id');
     //////////////followups///////////
     $query = "SELECT *\n                FROM `glpi_ticketcosts`\n                WHERE `tickets_id` = '{$ID}'\n                ORDER BY `begin_date`";
     $result = $DB->query($query);
     if (!$DB->numrows($result)) {
         $pdf->setColumnsSize(100);
         $pdf->displayLine(__('No ticket cost for this ticket', 'pdf'));
     } else {
         $pdf->setColumnsSize(60, 20, 20);
         $pdf->displayTitle("<b>" . TicketCost::getTypeName($DB->numrows($result)), __('Ticket duration'), CommonITILObject::getActionTime($job->fields['actiontime']) . "</b>");
         $pdf->setColumnsSize(20, 10, 10, 10, 10, 10, 10, 10, 10);
         $pdf->setColumnsAlign('center', 'center', 'center', 'left', 'right', 'right', 'right', 'right', 'right');
         $pdf->displayTitle("<b><i>" . __('Name') . "</i></b>", "<b><i>" . __('Begin date') . "</i></b>", "<b><i>" . __('End date') . "</i></b>", "<b><i>" . __('Budget') . "</i></b>", "<b><i>" . __('Duration') . "</i></b>", "<b><i>" . __('Time cost') . "</i></b>", "<b><i>" . __('Fixed cost') . "</i></b>", "<b><i>" . __('Material cost') . "</i></b>", "<b><i>" . __('Total cost') . "</i></b>");
         while ($data = $DB->fetch_array($result)) {
             $cost = TicketCost::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']);
             $pdf->displayLine($data['name'], Html::convDate($data['begin_date']), Html::convDate($data['end_date']), Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']), CommonITILObject::getActionTime($data['actiontime']), Html::formatNumber($data['cost_time']), Html::formatNumber($data['cost_fixed']), Html::formatNumber($data['cost_material']), Html::formatNumber($cost));
             $total_time += $data['actiontime'];
             $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP;
             $total_fixed += $data['cost_fixed'];
             $total_material += $data['cost_material'];
             $total += $cost;
         }
         $pdf->setColumnsSize(50, 10, 10, 10, 10, 10);
         $pdf->setColumnsAlign('right', 'right', 'right', 'right', 'right', 'right');
         $pdf->displayLine('<b>' . __('Total'), CommonITILObject::getActionTime($total_time), Html::formatNumber($total_costtime), Html::formatNumber($total_fixed), Html::formatNumber($total_material), Html::formatNumber($total));
     }
     $pdf->displaySpace();
 }
Пример #2
0
 /**
  * @since version 0.84
  *
  * @param $field
  * @param $name            (default '')
  * @param $values          (default '')
  * @param $options   array
  *
  * @return string
  **/
 static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = array())
 {
     if (!is_array($values)) {
         $values = array($field => $values);
     }
     $options['display'] = false;
     switch ($field) {
         case 'priority':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             $options['withmajor'] = 1;
             return CommonITILObject::dropdownPriority($options);
         case 'visibility':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             return self::dropdownVisibility($options);
         case 'state':
             return Planning::dropdownState($name, $values[$field], false);
     }
     return parent::getSpecificValueToSelect($field, $name, $values, $options);
 }
Пример #3
0
 /**
  * Select a field using standard system
  *
  * @since version 9.1
  */
 function getValueToSelect($field_id_or_search_options, $name = '', $values = '', $options = array())
 {
     if (isset($field_id_or_search_options['linkfield'])) {
         switch ($field_id_or_search_options['linkfield']) {
             case 'requesttypes_id':
                 $opt = 'is_ticketheader = 1';
                 if (Toolbox::in_array_recursive('glpi_ticketfollowups', $field_id_or_search_options['joinparams'])) {
                     $opt = 'is_ticketfollowup = 1';
                 }
                 if ($field_id_or_search_options['linkfield'] == $name) {
                     $opt .= ' AND is_active = 1';
                 }
                 if (isset($options['condition'])) {
                     $opt .= ' AND ' . $options['condition'];
                 }
                 $options['condition'] = $opt;
                 break;
         }
     }
     return parent::getValueToSelect($field_id_or_search_options, $name, $values, $options);
 }
Пример #4
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>";
     }
 }
Пример #5
0
 /**
  * Generate link for ticket satisfaction
  *
  * @since version 0.84 (before in entitydata.class)
  *
  * @param $ticket ticket object
  *
  * @return url contents
  **/
 static function generateLinkSatisfaction($ticket)
 {
     global $DB;
     $url = self::getUsedConfig('inquest_config', $ticket->fields['entities_id'], 'inquest_URL');
     if (strstr($url, "[TICKET_ID]")) {
         $url = str_replace("[TICKET_ID]", $ticket->fields['id'], $url);
     }
     if (strstr($url, "[TICKET_NAME]")) {
         $url = str_replace("[TICKET_NAME]", urlencode($ticket->fields['name']), $url);
     }
     if (strstr($url, "[TICKET_CREATEDATE]")) {
         $url = str_replace("[TICKET_CREATEDATE]", $ticket->fields['date'], $url);
     }
     if (strstr($url, "[TICKET_SOLVEDATE]")) {
         $url = str_replace("[TICKET_SOLVEDATE]", $ticket->fields['solvedate'], $url);
     }
     if (strstr($url, "[REQUESTTYPE_ID]")) {
         $url = str_replace("[REQUESTTYPE_ID]", $ticket->fields['requesttypes_id'], $url);
     }
     if (strstr($url, "[REQUESTTYPE_NAME]")) {
         $url = str_replace("[REQUESTTYPE_NAME]", urlencode(Dropdown::getDropdownName('glpi_requesttypes', $ticket->fields['requesttypes_id'])), $url);
     }
     if (strstr($url, "[TICKET_PRIORITY]")) {
         $url = str_replace("[TICKET_PRIORITY]", $ticket->fields['priority'], $url);
     }
     if (strstr($url, "[TICKET_PRIORITYNAME]")) {
         $url = str_replace("[TICKET_PRIORITYNAME]", urlencode(CommonITILObject::getPriorityName($ticket->fields['priority'])), $url);
     }
     if (strstr($url, "[TICKETCATEGORY_ID]")) {
         $url = str_replace("[TICKETCATEGORY_ID]", $ticket->fields['itilcategories_id'], $url);
     }
     if (strstr($url, "[TICKETCATEGORY_NAME]")) {
         $url = str_replace("[TICKETCATEGORY_NAME]", urlencode(Dropdown::getDropdownName('glpi_itilcategories', $ticket->fields['itilcategories_id'])), $url);
     }
     if (strstr($url, "[TICKETTYPE_ID]")) {
         $url = str_replace("[TICKETTYPE_ID]", $ticket->fields['type'], $url);
     }
     if (strstr($url, "[TICKET_TYPENAME]")) {
         $url = str_replace("[TICKET_TYPENAME]", Ticket::getTicketTypeName($ticket->fields['type']), $url);
     }
     if (strstr($url, "[SOLUTIONTYPE_ID]")) {
         $url = str_replace("[SOLUTIONTYPE_ID]", $ticket->fields['solutiontypes_id'], $url);
     }
     if (strstr($url, "[SOLUTIONTYPE_NAME]")) {
         $url = str_replace("[SOLUTIONTYPE_NAME]", urlencode(Dropdown::getDropdownName('glpi_solutiontypes', $ticket->fields['solutiontypes_id'])), $url);
     }
     if (strstr($url, "[SLA_ID]")) {
         $url = str_replace("[SLA_ID]", $ticket->fields['slas_id'], $url);
     }
     if (strstr($url, "[SLA_NAME]")) {
         $url = str_replace("[SLA_NAME]", urlencode(Dropdown::getDropdownName('glpi_slas', $ticket->fields['slas_id'])), $url);
     }
     if (strstr($url, "[SLALEVEL_ID]")) {
         $url = str_replace("[SLALEVEL_ID]", $ticket->fields['slalevels_id'], $url);
     }
     if (strstr($url, "[SLALEVEL_NAME]")) {
         $url = str_replace("[SLALEVEL_NAME]", urlencode(Dropdown::getDropdownName('glpi_slalevels', $ticket->fields['slalevels_id'])), $url);
     }
     return $url;
 }
Пример #6
0
 /**
  * Show the current task sumnary
  *
  * @param $item   CommonITILObject
  **/
 function showSummary(CommonITILObject $item)
 {
     global $DB, $CFG_GLPI;
     if (!static::canView()) {
         return false;
     }
     $tID = $item->fields['id'];
     // Display existing Followups
     $showprivate = $this->canViewPrivates();
     $caneditall = $this->canEditAll();
     $tmp = array($item->getForeignKeyField() => $tID);
     $canadd = $this->can(-1, CREATE, $tmp);
     $canpurge = $this->canPurgeItem();
     $canview = $this->canViewItem();
     $RESTRICT = "";
     if ($this->maybePrivate() && !$showprivate) {
         $RESTRICT = " AND (`is_private` = '0'\n                            OR `users_id` ='" . Session::getLoginUserID() . "'\n                            OR `users_id_tech` ='" . Session::getLoginUserID() . "'\n                            OR `groups_id_tech` IN ('" . implode("','", $_SESSION["glpigroups"]) . "')) ";
     }
     $query = "SELECT `id`, `date`\n                FROM `" . $this->getTable() . "`\n                WHERE `" . $item->getForeignKeyField() . "` = '{$tID}'\n                      {$RESTRICT}\n                ORDER BY `date` DESC";
     $result = $DB->query($query);
     $rand = mt_rand();
     if ($caneditall || $canadd || $canpurge) {
         echo "<div id='viewfollowup" . $tID . "{$rand}'></div>\n";
     }
     if ($canadd) {
         echo "<script type='text/javascript' >\n";
         echo "function viewAddTask" . $item->fields['id'] . "{$rand}() {\n";
         $params = array('type' => $this->getType(), 'parenttype' => $item->getType(), $item->getForeignKeyField() => $item->fields['id'], 'id' => -1);
         Ajax::updateItemJsCode("viewfollowup" . $item->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo Html::jsHide('addbutton' . $item->fields['id'] . "{$rand}");
         echo "};";
         echo "</script>\n";
         if (!in_array($item->fields["status"], array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray()))) {
             echo "<div id='addbutton" . $item->fields['id'] . "{$rand}' class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddTask" . $item->fields['id'] . "{$rand}();'>";
             echo __('Add a new task') . "</a></div>\n";
         }
     }
     if ($DB->numrows($result) == 0) {
         echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'><th>" . __('No task found.');
         echo "</th></tr></table>";
     } else {
         echo "<table class='tab_cadre_fixehov'>";
         $header = "<tr><th>&nbsp;</th><th>" . __('Type') . "</th><th>" . __('Date') . "</th>";
         $header .= "<th>" . __('Description') . "</th><th>" . __('Duration') . "</th>";
         $header .= "<th>" . __('Writer') . "</th>";
         if ($this->maybePrivate() && $showprivate) {
             $header .= "<th>" . __('Private') . "</th>";
         }
         $header .= "<th>" . __('Planning') . "</th></tr>\n";
         echo $header;
         while ($data = $DB->fetch_assoc($result)) {
             if ($this->getFromDB($data['id'])) {
                 $options = array('parent' => $item, 'rand' => $rand, 'showprivate' => $showprivate);
                 Plugin::doHook('pre_show_item', array('item' => $this, 'options' => &$options));
                 $this->showInObjectSumnary($item, $rand, $showprivate);
                 Plugin::doHook('post_show_item', array('item' => $this, 'options' => $options));
             }
         }
         echo $header;
         echo "</table>";
     }
 }
Пример #7
0
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $DB;
     if (!static::canView()) {
         return false;
     }
     // Set default options
     if (!$ID) {
         $values = array('_users_id_requester' => Session::getLoginUserID(), '_users_id_requester_notif' => array('use_notification' => 1), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => 1), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => 1), '_groups_id_observer' => 0, '_suppliers_id_assign' => 0, 'priority' => 3, 'urgency' => 3, 'impact' => 3, 'content' => '', 'entities_id' => $_SESSION['glpiactive_entity'], 'name' => '', 'itilcategories_id' => 0);
         foreach ($values as $key => $val) {
             if (!isset($options[$key])) {
                 $options[$key] = $val;
             }
         }
         if (isset($options['tickets_id'])) {
             $ticket = new Ticket();
             if ($ticket->getFromDB($options['tickets_id'])) {
                 $options['content'] = $ticket->getField('content');
                 $options['name'] = $ticket->getField('name');
                 $options['impact'] = $ticket->getField('impact');
                 $options['urgency'] = $ticket->getField('urgency');
                 $options['priority'] = $ticket->getField('priority');
                 $options['itilcategories_id'] = $ticket->getField('itilcategories_id');
             }
         }
         if (isset($options['problems_id'])) {
             $problem = new Problem();
             if ($problem->getFromDB($options['problems_id'])) {
                 $options['content'] = $problem->getField('content');
                 $options['name'] = $problem->getField('name');
                 $options['impact'] = $problem->getField('impact');
                 $options['urgency'] = $problem->getField('urgency');
                 $options['priority'] = $problem->getField('priority');
                 $options['itilcategories_id'] = $problem->getField('itilcategories_id');
             }
         }
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         // Create item
         $this->check(-1, 'w', $options);
     }
     $showuserlink = 0;
     if (Session::haveRight('user', 'r')) {
         $showuserlink = 1;
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr>";
     echo "<th class='left' colspan='2'>";
     if (isset($options['tickets_id'])) {
         echo "<input type='hidden' name='_tickets_id' value='" . $options['tickets_id'] . "'>";
     }
     if (isset($options['problems_id'])) {
         echo "<input type='hidden' name='_problems_id' value='" . $options['problems_id'] . "'>";
     }
     echo "<table>";
     echo "<tr>";
     echo "<td><span class='tracking_small'>" . __('Opening date') . "</span></td>";
     echo "<td>";
     $date = $this->fields["date"];
     if (!$ID) {
         $date = date("Y-m-d H:i:s");
     }
     Html::showDateTimeFormItem("date", $date, 1, false);
     echo "</td></tr>";
     if ($ID) {
         echo "<tr><td><span class='tracking_small'>" . __('By') . "</span></td><td>";
         User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
         echo "</td></tr>";
     }
     echo "</table>";
     echo "</th>";
     echo "<th class='left' colspan='2'>";
     echo "<table>";
     if ($ID) {
         echo "<tr><td><span class='tracking_small'>" . __('Last update') . "</span></td>";
         echo "<td><span class='tracking_small'>" . Html::convDateTime($this->fields["date_mod"]) . "\n";
         if ($this->fields['users_id_lastupdater'] > 0) {
             //TRANS: %s is the user name
             printf(__('By %s'), getUserName($this->fields["users_id_lastupdater"], $showuserlink));
         }
         echo "</span>";
         echo "</td></tr>";
     }
     // SLA
     echo "<tr>";
     echo "<td><span class='tracking_small'>" . __('Due date') . "</span></td>";
     echo "<td>";
     if ($this->fields["due_date"] == 'NULL') {
         $this->fields["due_date"] = '';
     }
     Html::showDateTimeFormItem("due_date", $this->fields["due_date"], 1, true);
     echo "</td></tr>";
     if ($ID) {
         switch ($this->fields["status"]) {
             case self::CLOSED:
                 echo "<tr>";
                 echo "<td><span class='tracking_small'>" . __('Close date') . "</span></td>";
                 echo "<td>";
                 Html::showDateTimeFormItem("closedate", $this->fields["closedate"], 1, false);
                 echo "</td></tr>";
                 break;
             case self::SOLVED:
             case self::OBSERVED:
                 echo "<tr>";
                 echo "<td><span class='tracking_small'>" . __('Resolution date') . "</span></td>";
                 echo "<td>";
                 Html::showDateTimeFormItem("solvedate", $this->fields["solvedate"], 1, false);
                 echo "</td></tr>";
                 break;
         }
     }
     echo "</table>";
     echo "</th></tr>";
     echo "<tr>";
     echo "<th>" . __('Status') . "</th>";
     echo "<td>";
     self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed'));
     echo "</td>";
     echo "<th>" . __('Urgency') . "</th>";
     echo "<td>";
     // Only change during creation OR when allowed to change priority OR when user is the creator
     $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Category') . "</th>";
     echo "<td >";
     $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"]);
     ITILCategory::dropdown($opt);
     echo "</td>";
     echo "<th>" . __('Impact') . "</th>";
     echo "<td>";
     $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Total duration') . "</th>";
     echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>";
     echo "<th class='left'>" . __('Priority') . "</th>";
     echo "<td>";
     $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
     $idajax = 'change_priority_' . mt_rand();
     echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
     Ajax::updateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     $this->showActorsPartForm($ID, $options);
     echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10%'>" . __('Title') . "</th>";
     echo "<td colspan='3'>";
     $rand = mt_rand();
     echo "<script type='text/javascript' >\n";
     echo "function showName{$rand}() {\n";
     echo "Ext.get('name{$rand}').setDisplayed('none');";
     $params = array('maxlength' => 250, 'size' => 50, 'name' => 'name', 'data' => rawurlencode($this->fields["name"]));
     Ajax::updateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params);
     echo "}";
     echo "</script>\n";
     echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n";
     if (empty($this->fields["name"])) {
         _e('Without title');
     } else {
         echo $this->fields["name"];
     }
     echo "</div>\n";
     echo "<div id='viewname{$rand}'></div>\n";
     if (!$ID) {
         echo "<script type='text/javascript' >\n\n         showName{$rand}();\n         </script>";
     }
     echo "</td>";
     echo "<td colspan='2' width='50%'>&nbsp;</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Description') . "</th>";
     echo "<td colspan='3'>";
     $rand = mt_rand();
     echo "<script type='text/javascript' >\n";
     echo "function showDesc{$rand}() {\n";
     echo "Ext.get('desc{$rand}').setDisplayed('none');";
     $params = array('rows' => 6, 'cols' => 50, 'name' => 'content', 'data' => rawurlencode($this->fields["content"]));
     Ajax::updateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params);
     echo "}";
     echo "</script>\n";
     echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n";
     if (!empty($this->fields["content"])) {
         echo nl2br($this->fields["content"]);
     } else {
         _e('Empty description');
     }
     echo "</div>\n";
     echo "<div id='viewdesc{$rand}'></div>\n";
     if (!$ID) {
         echo "<script type='text/javascript' >\n\n         showDesc{$rand}();\n         </script>";
     }
     echo "</td>";
     echo "<td colspan='2' width='50%'>&nbsp;</td>";
     echo "</tr>";
     $options['colspan'] = 3;
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
Пример #8
0
 /**
  * @param $item       CommonITILObject
  * @param $type
  */
 static function alertValidation(CommonITILObject $item, $type)
 {
     global $CFG_GLPI;
     // No alert for new item
     if ($item->isNewID($item->getID())) {
         return;
     }
     $status = array_merge($item->getClosedStatusArray(), $item->getSolvedStatusArray());
     $message = __s("This item is waiting for approval, do you really want to resolve or close it?");
     switch ($type) {
         case 'status':
             Html::scriptStart();
             echo "\$('[name=\"status\"]').change(function() {\n                     var status_ko = 0;\n                     var input_status = \$(this).val();\n                     if (input_status != undefined) {\n                        if ((";
             $first = true;
             foreach ($status as $val) {
                 if (!$first) {
                     echo "||";
                 }
                 echo "input_status == {$val}";
                 $first = false;
             }
             echo "           )\n                                 && input_status != " . $item->fields['status'] . "){\n                           status_ko = 1;\n                        }\n                     }\n                     if ((status_ko == 1)\n                         && ('" . $item->fields['global_validation'] . "' == '" . self::WAITING . "')) {\n                        alert('" . $message . "');\n                     }\n                  });";
             echo Html::scriptEnd();
             break;
         case 'solution':
             if (!in_array($item->fields['status'], $status) && $item->fields['global_validation'] == self::WAITING) {
                 Html::displayTitle($CFG_GLPI['root_doc'] . "/pics/warning.png", $message, $message);
             }
             break;
     }
 }
Пример #9
0
 /**
  * Print the item costs
  *
  * @param $item                  CommonITILObject object or Project
  * @param $withtemplate boolean  Template or basic item (default '')
  *
  * @return total cost
  **/
 static function showForObject($item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $forproject = false;
     if (Toolbox::is_a($item, 'Project')) {
         $forproject = true;
     }
     $ID = $item->fields['id'];
     if (!$item->getFromDB($ID) || !$item->canViewItem() || !static::canView()) {
         return false;
     }
     $canedit = false;
     if (!$forproject) {
         $canedit = $item->canUpdateItem();
     }
     echo "<div class='center'>";
     $condition = "= '{$ID}'";
     if ($forproject) {
         $condition = " IN ('" . implode("','", ProjectTask::getAllTicketsForProject($ID)) . "')";
     }
     $query = "SELECT *\n                FROM `" . static::getTable() . "`\n                WHERE `" . static::$items_id . "` {$condition}\n                ORDER BY `begin_date`";
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n";
         echo "<script type='text/javascript' >\n";
         echo "function viewAddCost" . $ID . "_{$rand}() {\n";
         $params = array('type' => static::getType(), 'parenttype' => static::$itemtype, static::$items_id => $ID, 'id' => -1);
         Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         if (static::canCreate()) {
             echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>";
             echo __('Add a new cost') . "</a></div>\n";
         }
     }
     $total = 0;
     $total_time = 0;
     $total_costtime = 0;
     $total_fixed = 0;
     $total_material = 0;
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr class='noHover'>";
         if ($forproject) {
             echo "<th colspan='10'>" . _n('Ticket cost', 'Ticket costs', $DB->numrows($result)) . "</th>";
         } else {
             echo "<th colspan='7'>" . self::getTypeName($DB->numrows($result)) . "</th>";
             echo "<th>" . __('Item duration') . "</th>";
             echo "<th>" . CommonITILObject::getActionTime($item->fields['actiontime']) . "</th>";
         }
         echo "</tr>";
         if ($DB->numrows($result)) {
             echo "<tr>";
             if ($forproject) {
                 echo "<th>" . __('Ticket') . "</th>";
                 $ticket = new Ticket();
             }
             echo "<th>" . __('Name') . "</th>";
             echo "<th>" . __('Begin date') . "</th>";
             echo "<th>" . __('End date') . "</th>";
             echo "<th>" . __('Budget') . "</th>";
             echo "<th>" . __('Duration') . "</th>";
             echo "<th>" . __('Time cost') . "</th>";
             echo "<th>" . __('Fixed cost') . "</th>";
             echo "<th>" . __('Material cost') . "</th>";
             echo "<th>" . __('Total cost') . "</th>";
             echo "</tr>";
             Session::initNavigateListItems(static::getType(), sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data[static::$items_id] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">";
                 $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name'];
                 if ($forproject) {
                     $ticket->getFromDB($data['tickets_id']);
                     echo "<td>" . $ticket->getLink() . "</td>";
                 }
                 echo "<td>";
                 printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false)));
                 if ($canedit) {
                     echo "\n<script type='text/javascript' >\n";
                     echo "function viewEditCost" . $data[static::$items_id] . "_" . $data["id"] . "_{$rand}() {\n";
                     $params = array('type' => static::getType(), 'parenttype' => static::$itemtype, static::$items_id => $data[static::$items_id], 'id' => $data["id"]);
                     Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                     echo "};";
                     echo "</script>\n";
                 }
                 echo "</td>";
                 echo "<td>" . Html::convDate($data['begin_date']) . "</td>";
                 echo "<td>" . Html::convDate($data['end_date']) . "</td>";
                 echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>";
                 echo "<td>" . CommonITILObject::getActionTime($data['actiontime']) . "</td>";
                 $total_time += $data['actiontime'];
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_time']) . "</td>";
                 $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP;
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_fixed']) . "</td>";
                 $total_fixed += $data['cost_fixed'];
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_material']) . "</td>";
                 $total_material += $data['cost_material'];
                 $cost = self::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']);
                 echo "<td class='numeric'>" . Html::formatNumber($cost) . "</td>";
                 $total += $cost;
                 echo "</tr>";
                 Session::addToNavigateListItems(static::getType(), $data['id']);
             }
             $colspan = 4;
             if ($forproject) {
                 $colspan++;
             }
             echo "<tr class='b noHover'><td colspan='{$colspan}' class='right'>" . __('Total') . '</td>';
             echo "<td>" . CommonITILObject::getActionTime($total_time) . "</td>";
             echo "<td class='numeric'>" . Html::formatNumber($total_costtime) . "</td>";
             echo "<td class='numeric'>" . Html::formatNumber($total_fixed) . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total_material) . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>';
         } else {
             echo "<tr><th colspan='9'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
     return $total;
 }
 /**
  * @see NotificationTarget::getDatasForTemplate()
  **/
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI, $DB;
     //----------- Reservation infos -------------- //
     $events = $this->getAllEvents();
     $item = $this->obj;
     $this->datas['##project.action##'] = $events[$event];
     $this->datas['##project.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("id"));
     $this->datas["##project.name##"] = $item->getField('name');
     $this->datas["##project.code##"] = $item->getField('code');
     $this->datas["##project.description##"] = $item->getField('content');
     $this->datas["##project.comments##"] = $item->getField('comment');
     $this->datas["##project.creationdate##"] = Html::convDateTime($item->getField('date'));
     $this->datas["##project.lastupdatedate##"] = Html::convDateTime($item->getField('date_mod'));
     $this->datas["##project.priority##"] = CommonITILObject::getPriorityName($item->getField('priority'));
     $this->datas["##project.percent##"] = Dropdown::getValueWithUnit($item->getField('percent_done'), "%");
     $this->datas["##project.planstartdate##"] = Html::convDateTime($item->getField('plan_start_date'));
     $this->datas["##project.planenddate##"] = Html::convDateTime($item->getField('plan_end_date'));
     $this->datas["##project.realstartdate##"] = Html::convDateTime($item->getField('real_start_date'));
     $this->datas["##project.realenddate##"] = Html::convDateTime($item->getField('real_end_date'));
     $this->datas["##project.plannedduration##"] = Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($item->getID()), false);
     $this->datas["##project.effectiveduration##"] = Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($item->getID()), false);
     $entity = new Entity();
     $this->datas["##project.entity##"] = '';
     $this->datas["##project.shortentity##"] = '';
     if ($entity->getFromDB($this->getEntity())) {
         $this->datas["##project.entity##"] = $entity->getField('completename');
         $this->datas["##project.shortentity##"] = $entity->getField('name');
     }
     $this->datas["##project.father##"] = '';
     if ($item->getField('projects_id')) {
         $this->datas["##project.father##"] = Dropdown::getDropdownName('glpi_projects', $item->getField('projects_id'));
     }
     $this->datas["##project.state##"] = '';
     if ($item->getField('projectstates_id')) {
         $this->datas["##project.state##"] = Dropdown::getDropdownName('glpi_projectstates', $item->getField('projectstates_id'));
     }
     $this->datas["##project.type##"] = '';
     if ($item->getField('projecttypes_id')) {
         $this->datas["##project.type##"] = Dropdown::getDropdownName('glpi_projecttypes', $item->getField('projecttypes_id'));
     }
     $this->datas["##project.manager##"] = '';
     if ($item->getField('users_id')) {
         $user_tmp = new User();
         $user_tmp->getFromDB($item->getField('users_id'));
         $this->datas["##project.manager##"] = $user_tmp->getName();
     }
     $this->datas["##project.managergroup##"] = '';
     if ($item->getField('groups_id')) {
         $this->datas["##project.managergroup##"] = Dropdown::getDropdownName('glpi_groups', $item->getField('groups_id'));
     }
     // Team infos
     $restrict = "`projects_id` = '" . $item->getField('id') . "'";
     $items = getAllDatasFromTable('glpi_projectteams', $restrict);
     $this->datas['teammembers'] = array();
     if (count($items)) {
         foreach ($items as $data) {
             if ($item2 = getItemForItemtype($data['itemtype'])) {
                 if ($item2->getFromDB($data['items_id'])) {
                     $tmp = array();
                     $tmp['##teammember.itemtype##'] = $item2->getTypeName();
                     $tmp['##teammember.name##'] = $item2->getName();
                     $this->datas['teammembers'][] = $tmp;
                 }
             }
         }
     }
     $this->datas['##project.numberofteammembers##'] = count($this->datas['teammembers']);
     // Task infos
     $restrict = "`projects_id`='" . $item->getField('id') . "'";
     $restrict .= " ORDER BY `date` DESC, `id` ASC";
     $tasks = getAllDatasFromTable('glpi_projecttasks', $restrict);
     $this->datas['tasks'] = array();
     foreach ($tasks as $task) {
         $tmp = array();
         $tmp['##task.creationdate##'] = Html::convDateTime($task['date']);
         $tmp['##task.lastupdatedate##'] = Html::convDateTime($task['date_mod']);
         $tmp['##task.name##'] = $task['name'];
         $tmp['##task.description##'] = $task['content'];
         $tmp['##task.comments##'] = $task['comment'];
         $tmp['##task.state##'] = Dropdown::getDropdownName('glpi_projectstates', $task['projectstates_id']);
         $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_projecttasktypes', $task['projecttasktypes_id']);
         $tmp['##task.percent##'] = Dropdown::getValueWithUnit($task['percent_done'], "%");
         $this->datas["##task.planstartdate##"] = '';
         $this->datas["##task.planenddate##"] = '';
         $this->datas["##task.realstartdate##"] = '';
         $this->datas["##task.realenddate##"] = '';
         if (!is_null($task['plan_start_date'])) {
             $tmp['##task.planstartdate##'] = Html::convDateTime($task['plan_start_date']);
         }
         if (!is_null($task['plan_end_date'])) {
             $tmp['##task.planenddate##'] = Html::convDateTime($task['plan_end_date']);
         }
         if (!is_null($task['real_start_date'])) {
             $tmp['##task.realstartdate##'] = Html::convDateTime($task['real_start_date']);
         }
         if (!is_null($task['real_end_date'])) {
             $tmp['##task.realenddate##'] = Html::convDateTime($task['real_end_date']);
         }
         $this->datas['tasks'][] = $tmp;
     }
     $this->datas["##project.numberoftasks##"] = count($this->datas['tasks']);
     //costs infos
     $restrict = "`projects_id`='" . $item->getField('id') . "'";
     $restrict .= " ORDER BY `begin_date` DESC, `id` ASC";
     $costs = getAllDatasFromTable('glpi_projectcosts', $restrict);
     $this->datas['costs'] = array();
     $this->datas["##project.totalcost##"] = 0;
     foreach ($costs as $cost) {
         $tmp = array();
         $tmp['##cost.name##'] = $cost['name'];
         $tmp['##cost.comment##'] = $cost['comment'];
         $tmp['##cost.datebegin##'] = Html::convDate($cost['begin_date']);
         $tmp['##cost.dateend##'] = Html::convDate($cost['end_date']);
         $tmp['##cost.cost##'] = Html::formatNumber($cost['cost']);
         $tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']);
         $this->datas["##project.totalcost##"] += $cost['cost'];
         $this->datas['costs'][] = $tmp;
         /// TODO add ticket costs ?
     }
     $this->datas["##project.numberofcosts##"] = count($this->datas['costs']);
     // History infos
     $this->datas['log'] = array();
     // Use list_limit_max or load the full history ?
     foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) {
         $tmp = array();
         $tmp["##project.log.date##"] = $data['date_mod'];
         $tmp["##project.log.user##"] = $data['user_name'];
         $tmp["##project.log.field##"] = $data['field'];
         $tmp["##project.log.content##"] = $data['change'];
         $this->datas['log'][] = $tmp;
     }
     $this->datas["##project.numberoflogs##"] = count($this->datas['log']);
     // Changes infos
     $restrict = "`projects_id`='" . $item->getField('id') . "'";
     $changes = getAllDatasFromTable('glpi_changes_projects', $restrict);
     $this->datas['changes'] = array();
     if (count($changes)) {
         $change = new Change();
         foreach ($changes as $data) {
             if ($change->getFromDB($data['changes_id'])) {
                 $tmp = array();
                 $tmp['##change.id##'] = $data['changes_id'];
                 $tmp['##change.date##'] = $change->getField('date');
                 $tmp['##change.title##'] = $change->getField('name');
                 $tmp['##change.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "change_" . $data['changes_id']);
                 $tmp['##change.content##'] = $change->getField('content');
                 $this->datas['changes'][] = $tmp;
             }
         }
     }
     $this->datas['##project.numberofchanges##'] = count($this->datas['changes']);
     // Document
     $query = "SELECT `glpi_documents`.*\n                FROM `glpi_documents`\n                LEFT JOIN `glpi_documents_items`\n                  ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n                WHERE `glpi_documents_items`.`itemtype` =  'Project'\n                      AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'";
     $this->datas["documents"] = array();
     if ($result = $DB->query($query)) {
         while ($data = $DB->fetch_assoc($result)) {
             $tmp = array();
             $tmp['##document.id##'] = $data['id'];
             $tmp['##document.name##'] = $data['name'];
             $tmp['##document.weblink##'] = $data['link'];
             $tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']);
             $downloadurl = "/front/document.send.php?docid=" . $data['id'];
             $tmp['##document.downloadurl##'] = $this->formatURL($options['additionnaloption']['usertype'], $downloadurl);
             $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']);
             $tmp['##document.filename##'] = $data['filename'];
             $this->datas['documents'][] = $tmp;
         }
     }
     $this->datas["##project.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("id") . '_Document_Item$1');
     $this->datas["##project.numberofdocuments##"] = count($this->datas['documents']);
     // Items infos
     $restrict = "`projects_id` = '" . $item->getField('id') . "'";
     $items = getAllDatasFromTable('glpi_items_projects', $restrict);
     $this->datas['items'] = array();
     if (count($items)) {
         foreach ($items as $data) {
             if ($item2 = getItemForItemtype($data['itemtype'])) {
                 if ($item2->getFromDB($data['items_id'])) {
                     $tmp = array();
                     $tmp['##item.itemtype##'] = $item2->getTypeName();
                     $tmp['##item.name##'] = $item2->getField('name');
                     $tmp['##item.serial##'] = $item2->getField('serial');
                     $tmp['##item.otherserial##'] = $item2->getField('otherserial');
                     $tmp['##item.contact##'] = $item2->getField('contact');
                     $tmp['##item.contactnum##'] = $item2->getField('contactnum');
                     $tmp['##item.location##'] = '';
                     $tmp['##item.user##'] = '';
                     $tmp['##item.group##'] = '';
                     $tmp['##item.model##'] = '';
                     //Object location
                     if ($item2->getField('locations_id') != NOT_AVAILABLE) {
                         $tmp['##item.location##'] = Dropdown::getDropdownName('glpi_locations', $item2->getField('locations_id'));
                     }
                     //Object user
                     if ($item2->getField('users_id')) {
                         $user_tmp = new User();
                         if ($user_tmp->getFromDB($item2->getField('users_id'))) {
                             $tmp['##item.user##'] = $user_tmp->getName();
                         }
                     }
                     //Object group
                     if ($item2->getField('groups_id')) {
                         $tmp['##item.group##'] = Dropdown::getDropdownName('glpi_groups', $item2->getField('groups_id'));
                     }
                     $modeltable = getSingular($item2->getTable()) . "models";
                     $modelfield = getForeignKeyFieldForTable($modeltable);
                     if ($item2->isField($modelfield)) {
                         $tmp['##item.model##'] = $item2->getField($modelfield);
                     }
                     $this->datas['items'][] = $tmp;
                 }
             }
         }
     }
     $this->datas['##project.numberofitems##'] = count($this->datas['items']);
     $this->getTags();
     foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }
Пример #11
0
 /**
  * Show the current task sumnary
  *
  * @param $item   CommonITILObject
  **/
 function showSummary(CommonITILObject $item)
 {
     global $DB, $CFG_GLPI;
     if (!static::canView()) {
         return false;
     }
     $tID = $item->fields['id'];
     // Display existing Followups
     $showprivate = $this->canViewPrivates();
     $caneditall = $this->canEditAll();
     $tmp = array($item->getForeignKeyField() => $tID);
     $canadd = $this->can(-1, 'w', $tmp);
     $RESTRICT = "";
     if ($this->maybePrivate() && !$showprivate) {
         $RESTRICT = " AND (`is_private` = '0'\n                            OR `users_id` ='" . Session::getLoginUserID() . "') ";
     }
     $query = "SELECT `id`, `date`\n                FROM `" . $this->getTable() . "`\n                WHERE `" . $item->getForeignKeyField() . "` = '{$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" . $item->fields['id'] . "{$rand}() {\n";
         $params = array('type' => $this->getType(), 'parenttype' => $item->getType(), $item->getForeignKeyField() => $item->fields['id'], 'id' => -1);
         Ajax::updateItemJsCode("viewfollowup" . $item->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         if ($item->fields["status"] != CommonITILObject::SOLVED && $item->fields["status"] != CommonITILObject::CLOSED) {
             echo "<div class='center'>" . "<a class='vsubmit' href='javascript:viewAddFollowup" . $item->fields['id'] . "{$rand}();'>";
             echo __('Add a new task') . "</a></div></p><br>\n";
         }
     }
     if ($DB->numrows($result) == 0) {
         echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'><th>" . __('No task found.');
         echo "</th></tr></table>";
     } else {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th>" . __('Type') . "</th><th>" . __('Date') . "</th>";
         echo "<th>" . __('Description') . "</th><th>" . __('Duration') . "</th>";
         echo "<th>" . __('Writer') . "</th>";
         if ($this->maybePrivate() && $showprivate) {
             echo "<th>" . __('Private') . "</th>";
         }
         echo "<th>" . __('Planning') . "</th></tr>\n";
         while ($data = $DB->fetch_assoc($result)) {
             if ($this->getFromDB($data['id'])) {
                 $this->showInObjectSumnary($item, $rand, $showprivate);
             }
         }
         echo "</table>";
     }
 }
Пример #12
0
 function getWidgetContentForItem($widgetId)
 {
     global $CFG_GLPI, $DB;
     if (empty($this->form)) {
         $this->init();
     }
     switch ($widgetId) {
         case $this->getType() . "1":
             $plugin = new Plugin();
             if ($plugin->isActivated("tasklists")) {
                 $widget = new PluginMydashboardDatatable();
                 $headers = array(__('Name'), __('Priority'), _n('Context', 'Contexts', 1, 'tasklists'), __('User'), __('Percent done'), __('Due date'), __('Action'));
                 $query = "SELECT `glpi_plugin_tasklists_tasks`.*,`glpi_plugin_tasklists_tasktypes`.`completename` as 'type' \n                            FROM `glpi_plugin_tasklists_tasks`\n                            LEFT JOIN `glpi_plugin_tasklists_tasktypes` ON (`glpi_plugin_tasklists_tasks`.`plugin_tasklists_tasktypes_id` = `glpi_plugin_tasklists_tasktypes`.`id`) \n                            WHERE NOT `glpi_plugin_tasklists_tasks`.`is_deleted`\n                                 AND `glpi_plugin_tasklists_tasks`.`state` < 2 ";
                 $query .= getEntitiesRestrictRequest('AND', 'glpi_plugin_tasklists_tasks');
                 $query .= "ORDER BY `glpi_plugin_tasklists_tasks`.`priority`DESC ";
                 $tasks = array();
                 if ($result = $DB->query($query)) {
                     if ($DB->numrows($result)) {
                         while ($data = $DB->fetch_array($result)) {
                             //$groups = Group_User::getGroupUsers($data['groups_id']);
                             $groupusers = Group_User::getGroupUsers($data['groups_id']);
                             $groups = array();
                             foreach ($groupusers as $groupuser) {
                                 $groups[] = $groupuser["id"];
                             }
                             if ($data['visibility'] == 1 && $data['users_id'] == Session::getLoginUserID() || $data['visibility'] == 2 && ($data['users_id'] == Session::getLoginUserID() || in_array(Session::getLoginUserID(), $groups)) || $data['visibility'] == 3) {
                                 $ID = $data['id'];
                                 $rand = mt_rand();
                                 $url = Toolbox::getItemTypeFormURL("PluginTasklistsTask") . "?id=" . $data['id'];
                                 $tasks[$data['id']][0] = "<a id='task" . $data["id"] . $rand . "' target='_blank' href='{$url}'>" . $data['name'] . "</a>";
                                 $tasks[$data['id']][0] .= Html::showToolTip($data['comment'], array('applyto' => 'task' . $data["id"] . $rand, 'display' => false));
                                 $bgcolor = $_SESSION["glpipriority_" . $data['priority']];
                                 $tasks[$data['id']][1] = "<div class='center' style='background-color:{$bgcolor};'>" . CommonITILObject::getPriorityName($data['priority']) . "</div>";
                                 $tasks[$data['id']][2] = $data['type'];
                                 $tasks[$data['id']][3] = getUserName($data['users_id']);
                                 $tasks[$data['id']][4] = Dropdown::getValueWithUnit($data['percent_done'], "%");
                                 $due_date = $data['due_date'];
                                 $display = Html::convDate($data['due_date']);
                                 if ($due_date <= date('Y-m-d') && !empty($due_date)) {
                                     $display = "<div class='deleted'>" . Html::convDate($data['due_date']) . "</div>";
                                 }
                                 $tasks[$data['id']][5] = $display;
                                 $tasks[$data['id']][6] = "<div align='center'>";
                                 if (Session::haveRight("plugin_tasklists", UPDATE)) {
                                     $tasks[$data['id']][6] .= "<a class='pointer' onclick=\" submitGetLink('" . $CFG_GLPI['root_doc'] . "/plugins/tasklists/front/task.form.php', {'done': 'done', 'id': '" . $data['id'] . "', '_glpi_csrf_token': '" . Session::getNewCSRFToken() . "', '_glpi_simple_form': '1'});\"><img src='" . $CFG_GLPI['root_doc'] . "/plugins/tasklists/pics/ok.png' title='" . __('Mark as done', 'tasklists') . "'></a>";
                                 }
                                 if (Session::haveRight("plugin_tasklists", UPDATENOTE)) {
                                     $link = "&nbsp;<a href=\"javascript:" . Html::jsGetElementbyID('comment' . $rand) . ".dialog('open');\">";
                                     $link .= "<img class='pointer' src='" . $CFG_GLPI['root_doc'] . "/plugins/tasklists/pics/plus.png' title='" . __('Add comment', 'tasklists') . "'>";
                                     $link .= "</a>";
                                     $link .= Ajax::createIframeModalWindow('comment' . $rand, $CFG_GLPI["root_doc"] . "/plugins/tasklists/front/comment.form.php?id=" . $ID, array('title' => __('Add comment', 'tasklists'), 'reloadonclose' => false, 'width' => 1100, 'display' => false, 'height' => 300));
                                     $tasks[$data['id']][6] .= $link;
                                 }
                                 $tasks[$data['id']][6] .= "</div>";
                             }
                         }
                     }
                 }
                 $widget->setTabDatas($tasks);
                 $widget->setTabNames($headers);
                 $widget->setOption("bSort", false);
                 $widget->toggleWidgetRefresh();
                 $link = "<div align='right'><a class='vsubmit' href=\"javascript:" . Html::jsGetElementbyID('task') . ".dialog('open');\">";
                 $link .= __('Add task', 'tasklists');
                 $link .= "</a></div>";
                 $link .= Ajax::createIframeModalWindow('task', $CFG_GLPI["root_doc"] . "/plugins/tasklists/front/task.form.php", array('title' => __('Add task', 'tasklists'), 'reloadonclose' => false, 'width' => 1180, 'display' => false, 'height' => 600));
                 $widget->appendWidgetHtmlContent($link);
                 $widget->setWidgetTitle(__("Tasks list", 'tasklists'));
                 return $widget;
             } else {
                 $widget = new PluginMydashboardDatatable();
                 $widget->setWidgetTitle(__("Tasks list", 'tasklists'));
                 return $widget;
             }
             break;
     }
 }
Пример #13
0
 /**
  * Print the ticket costs
  *
  * @param $ticket                  Ticket object
  * @param $withtemplate boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForTicket(Ticket $ticket, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->fields['id'];
     if (!$ticket->getFromDB($ID) || !$ticket->can($ID, "r") || !Session::haveRight('ticketcost', 'r')) {
         return false;
     }
     $canedit = Session::haveRight('ticketcost', 'w');
     echo "<div class='center'>";
     $query = "SELECT *\n                FROM `glpi_ticketcosts`\n                WHERE `tickets_id` = '{$ID}'\n                ORDER BY `begin_date`";
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n";
         echo "<script type='text/javascript' >\n";
         echo "function viewAddCost" . $ID . "_{$rand}() {\n";
         $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $ID, 'id' => -1);
         Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>";
         echo __('Add a new cost') . "</a></div>\n";
     }
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th colspan='7'>" . self::getTypeName($DB->numrows($result)) . "</th>";
         echo "<th>" . __('Ticket duration') . "</th>";
         echo "<th>" . CommonITILObject::getActionTime($ticket->fields['actiontime']) . "</th>";
         echo "</tr>";
         if ($DB->numrows($result)) {
             echo "<tr><th>" . __('Name') . "</th>";
             echo "<th>" . __('Begin date') . "</th>";
             echo "<th>" . __('End date') . "</th>";
             echo "<th>" . __('Budget') . "</th>";
             echo "<th>" . __('Duration') . "</th>";
             echo "<th>" . __('Time cost') . "</th>";
             echo "<th>" . __('Fixed cost') . "</th>";
             echo "<th>" . __('Material cost') . "</th>";
             echo "<th>" . __('Total cost') . "</th>";
             echo "</tr>";
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->getName()));
             $total = 0;
             $total_time = 0;
             $total_costtime = 0;
             $total_fixed = 0;
             $total_material = 0;
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['tickets_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">";
                 $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name'];
                 echo "<td>";
                 printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false)));
                 if ($canedit) {
                     echo "\n<script type='text/javascript' >\n";
                     echo "function viewEditCost" . $data['tickets_id'] . "_" . $data["id"] . "_{$rand}() {\n";
                     $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $data["tickets_id"], 'id' => $data["id"]);
                     Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                     echo "};";
                     echo "</script>\n";
                 }
                 echo "</td>";
                 echo "<td>" . Html::convDate($data['begin_date']) . "</td>";
                 echo "<td>" . Html::convDate($data['end_date']) . "</td>";
                 echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>";
                 echo "<td>" . CommonITILObject::getActionTime($data['actiontime']) . "</td>";
                 $total_time += $data['actiontime'];
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_time']) . "</td>";
                 $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP;
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_fixed']) . "</td>";
                 $total_fixed += $data['cost_fixed'];
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_material']) . "</td>";
                 $total_material += $data['cost_material'];
                 $cost = self::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']);
                 echo "<td class='numeric'>" . Html::formatNumber($cost) . "</td>";
                 $total += $cost;
                 echo "</tr>";
                 Session::addToNavigateListItems(__CLASS__, $data['id']);
             }
             echo "<tr class='b'><td colspan='4' class='right'>" . __('Total') . '</td>';
             echo "<td>" . CommonITILObject::getActionTime($total_time) . "</td>";
             echo "<td class='numeric'>" . Html::formatNumber($total_costtime) . "</td>";
             echo "<td class='numeric'>" . Html::formatNumber($total_fixed) . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total_material) . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>';
         } else {
             echo "<tr><th colspan='9'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
 }
Пример #14
0
 /**
  * @since version 0.85
  *
  * @return string
  */
 function getForbiddenStandardMassiveAction()
 {
     $forbidden = parent::getForbiddenStandardMassiveAction();
     if (!Session::haveRight('delete_problem', 1)) {
         $forbidden[] = 'delete';
         $forbidden[] = 'purge';
         $forbidden[] = 'restore';
     }
     return $forbidden;
 }
Пример #15
0
 /**
  * @since version 0.85
  *
  * @see commonDBTM::getRights()
  **/
 function getRights($interface = 'central')
 {
     $values = parent::getRights();
     unset($values[READ]);
     $values[self::READALL] = __('See all');
     $values[self::READMY] = __('See (author)');
     return $values;
 }
Пример #16
0
 /**
  * @since version 0.85
  *
  * @see commonDBTM::getRights()
  **/
 function getRights($interface = 'central')
 {
     $values = parent::getRights();
     unset($values[READ]);
     $values[self::READMY] = __('See my ticket');
     //TRANS: short for : See tickets created by my groups
     $values[self::READGROUP] = array('short' => __('See group ticket'), 'long' => __('See tickets created by my groups'));
     if ($interface == 'central') {
         $values[self::READALL] = __('See all tickets');
         //TRANS: short for : See assigned tickets (group associated)
         $values[self::READASSIGN] = array('short' => __('See assigned'), 'long' => __('See assigned tickets'));
         //TRANS: short for : Assign a ticket
         $values[self::ASSIGN] = array('short' => __('Assign'), 'long' => __('Assign a ticket'));
         //TRANS: short for : Steal a ticket
         $values[self::STEAL] = array('short' => __('Steal'), 'long' => __('Steal a ticket'));
         //TRANS: short for : To be in charge of a ticket
         $values[self::OWN] = array('short' => __('Beeing in charge'), 'long' => __('To be in charge of a ticket'));
         $values[self::CHANGEPRIORITY] = __('Change the priority');
     }
     if ($interface == 'helpdesk') {
         unset($values[UPDATE], $values[DELETE], $values[PURGE]);
     }
     return $values;
 }
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
// Make a select box
if (isset($_POST["itemtype"]) && CommonITILObject::isPossibleToAssignType($_POST["itemtype"])) {
    $table = getTableForItemType($_POST["itemtype"]);
    $rand = mt_rand();
    // Message for post-only
    if (!isset($_POST["admin"]) || $_POST["admin"] == 0) {
        echo "<br>" . __('Enter the first letters (user, item name, serial or asset number)');
    }
    echo "<br>";
    $field_id = Html::cleanId("dropdown_" . $_POST['myname'] . $rand);
    $p = array('itemtype' => $_POST["itemtype"], 'entity_restrict' => $_POST['entity_restrict'], 'table' => $table, 'myname' => $_POST["myname"]);
    if (isset($_POST["used"]) && !empty($_POST["used"])) {
        if (isset($_POST["used"][$_POST["itemtype"]])) {
            $p["used"] = $_POST["used"][$_POST["itemtype"]];
        }
    }
    echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownFindNum.php", $p);
Пример #18
0
 function showFormEdit($params, $options = array())
 {
     global $LANG, $CFG_GLPI;
     if ($params['id'] > 0) {
         $this->check($params['id'], 'r');
     } else {
         // Create item
         $this->check(-1, 'w');
     }
     echo "<form method='POST' \n      action='" . $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/target.form.php'>";
     echo "<input type='hidden' name='plugin_formcreator_forms_id' \n            value='" . $this->fields['plugin_formcreator_forms_id'] . "' />";
     echo "<input type='hidden' name='id' \n            value='" . $this->fields['id'] . "' />";
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe fix_tab_height'>";
     echo "<tr>";
     echo "<th colspan='2'>" . $LANG['plugin_formcreator']["target"][5] . "</th>";
     echo "<th colspan='2'>" . $LANG['plugin_formcreator']["target"][3] . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['plugin_formcreator']["target"][4] . "&nbsp;:</td>";
     echo '<td><input type="text" name="name" 
            value="' . $this->fields['name'] . '" size="54"/></td>';
     echo "</td>";
     echo "<td>" . __('Category') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::show('ITILCategory', array('value' => $this->fields["itilcategories_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td rowspan='3'>";
     echo __('Description') . " :";
     echo "</td><td rowspan='3'>";
     echo "<textarea name='content' cols='65' rows='12'>" . $this->fields['content'] . "</textarea>";
     echo "</td>";
     echo "<td>" . __('Type') . " :</td>";
     echo "<td>";
     echo '<select name="type">';
     if ($this->fields['type'] == 2) {
         echo '<option value="2">' . __('Request') . '</option>';
         echo '<option value="1">' . __('Incident') . '</option>';
     } else {
         echo '<option value="2">' . __('Request') . '</option>';
         echo '<option value="1" SELECTED>' . __('Incident') . '</option>';
     }
     echo '</select>';
     echo "</td>";
     echo "</tr><tr>";
     echo "<td>" . __('Urgency') . " :</td>";
     echo "<td>";
     Ticket::dropdownUrgency(array("urgency", $this->fields["urgency"]));
     echo "</td>";
     echo "</tr><tr>";
     echo "<td rownspan='2'>" . __('Priority') . " :</td>";
     echo "<td>";
     CommonITILObject::dropdownPriority(array("priority", $this->fields["priority"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='center' colspan='2'>";
     echo "<input class='submit' type='submit' value='" . __('Update') . "' name='update'>";
     echo "</td>";
     echo "<td class='center' colspan='2'>";
     echo "<input class='submit' type='submit' value='" . __('Purge') . "' name='delete'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "</div>";
     Html::closeForm();
     self::popupContent($this->fields['plugin_formcreator_forms_id']);
 }