Ejemplo n.º 1
0
    $_GET['id'] = "";
}
if (isset($_POST["add"])) {
    $track->check(-1, CREATE, $_POST);
    if ($id = $track->add($_POST)) {
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($track->getFormURL() . "?id=" . $id);
        }
    }
    Html::back();
} else {
    if (isset($_POST['update'])) {
        $track->check($_POST['id'], UPDATE);
        $track->update($_POST);
        Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
        if ($track->can($_POST["id"], READ)) {
            $toadd = '';
            // Copy solution to KB redirect to KB
            if (isset($_POST['_sol_to_kb']) && $_POST['_sol_to_kb']) {
                $toadd = "&_sol_to_kb=1";
            }
            Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST["id"] . $toadd);
        }
        Session::addMessageAfterRedirect(__('You have been redirected because you no longer have access to this ticket'), true, ERROR);
        Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.php");
    } else {
        if (isset($_POST['delete'])) {
            $track->check($_POST['id'], DELETE);
            if ($track->delete($_POST)) {
                Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
            }
 /**
  * Check is the curent user is allowed to see the file
  *
  * @param $options array of options (only 'tickets_id' used)
  *
  * @return boolean
  **/
 function canViewFile($options)
 {
     global $DB, $CFG_GLPI;
     if (isset($_SESSION["glpiactiveprofile"]["interface"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") {
         // My doc Check and Common doc right access
         if ($this->can($this->fields["id"], READ) || $this->fields["users_id"] === Session::getLoginUserID()) {
             return true;
         }
         // Reminder Case
         $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_reminders`\n                        ON (`glpi_reminders`.`id` = `glpi_documents_items`.`items_id`\n                            AND `glpi_documents_items`.`itemtype` = 'Reminder')\n                   " . Reminder::addVisibilityJoins() . "\n                   WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND " . Reminder::addVisibilityRestrict();
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             return true;
         }
         // Knowbase Case
         if (Session::haveRight("knowbase", READ)) {
             $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`\n                               AND `glpi_documents_items`.`itemtype` = 'KnowbaseItem')\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND " . KnowbaseItem::addVisibilityRestrict();
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
         }
         if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) {
             $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`\n                               AND `glpi_documents_items`.`itemtype` = 'KnowbaseItem')\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND `glpi_knowbaseitems`.`is_faq` = '1'\n                            AND " . KnowbaseItem::addVisibilityRestrict();
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
         }
         // Tracking Case
         if (isset($options["tickets_id"])) {
             $job = new Ticket();
             if ($job->can($options["tickets_id"], READ)) {
                 $query = "SELECT *\n                         FROM `glpi_documents_items`\n                         WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n                               AND `glpi_documents_items`.`itemtype` = 'Ticket'\n                               AND `documents_id`='" . $this->fields["id"] . "'";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     return true;
                 }
             }
         }
     } else {
         if (Session::getLoginUserID()) {
             // ! central
             // Check if it is my doc
             if ($this->fields["users_id"] === Session::getLoginUserID()) {
                 return true;
             }
             // Reminder Case
             $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_reminders`\n                        ON (`glpi_reminders`.`id` = `glpi_documents_items`.`items_id`\n                            AND `glpi_documents_items`.`itemtype` = 'Reminder')\n                   " . Reminder::addVisibilityJoins() . "\n                   WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND " . Reminder::addVisibilityRestrict();
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
             if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) {
                 // Check if it is a FAQ document
                 $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                            AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND `glpi_knowbaseitems`.`is_faq` = '1'\n                            AND " . KnowbaseItem::addVisibilityRestrict();
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     return true;
                 }
             }
             // Tracking Case
             if (isset($options["tickets_id"])) {
                 $job = new Ticket();
                 if ($job->can($options["tickets_id"], READ)) {
                     $query = "SELECT *\n                         FROM `glpi_documents_items`\n                         WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n                               AND `glpi_documents_items`.`itemtype` = 'Ticket'\n                               AND `documents_id` = '" . $this->fields["id"] . "'";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) > 0) {
                         return true;
                     }
                 }
             }
         }
     }
     // Public FAQ for not connected user
     if ($CFG_GLPI["use_public_faq"]) {
         $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_knowbaseitems`\n                        ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                   LEFT JOIN `glpi_entities_knowbaseitems`\n                        ON (`glpi_knowbaseitems`.`id` = `glpi_entities_knowbaseitems`.`knowbaseitems_id`)\n                   WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                         AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND `glpi_knowbaseitems`.`is_faq` = '1'\n                         AND `glpi_entities_knowbaseitems`.`entities_id` = '0'\n                         AND `glpi_entities_knowbaseitems`.`is_recursive` = '1'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Show changes for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!$ticket->can($ID, READ)) {
         return false;
     }
     $canedit = $ticket->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_changes_tickets`.`id` AS linkID,\n                                `glpi_changes`.*\n                FROM `glpi_changes_tickets`\n                LEFT JOIN `glpi_changes`\n                     ON (`glpi_changes_tickets`.`changes_id` = `glpi_changes`.`id`)\n                WHERE `glpi_changes_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_changes`.`name`";
     $result = $DB->query($query);
     $changes = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $changes[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='changeticket_form{$rand}' id='changeticket_form{$rand}' method='post'\n               action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a change') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>";
         echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         Change::dropdown(array('used' => $used, 'entity' => $ticket->getEntityID()));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td><td>";
         if (Session::haveRight('change', CREATE)) {
             echo "<a href='" . Toolbox::getItemTypeFormURL('Change') . "?tickets_id={$ID}'>";
             _e('Create a change from this ticket');
             echo "</a>";
         }
         echo "</td></tr></table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr class='noHover'><th colspan='12'>" . Change::getTypeName($numrows) . "</th>";
     echo "</tr>";
     if ($numrows) {
         Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
         Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->fields["name"]));
         $i = 0;
         foreach ($changes as $data) {
             Session::addToNavigateListItems('Change', $data["id"]);
             Change::showShort($data['id'], array('row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID']));
             $i++;
         }
         Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Ejemplo n.º 4
0
 /**
  * Affect the same solution for duplicates tickets
  *
  * @param $ID ID of the ticket id
  *
  * @return nothing do the change
  **/
 static function manageLinkedTicketsOnSolved($ID)
 {
     $ticket = new Ticket();
     if ($ticket->getfromDB($ID)) {
         $input['solution'] = addslashes($ticket->fields['solution']);
         $input['solutiontypes_id'] = addslashes($ticket->fields['solutiontypes_id']);
         $tickets = self::getLinkedTicketsTo($ID);
         if (count($tickets)) {
             foreach ($tickets as $data) {
                 $input['id'] = $data['tickets_id'];
                 if ($ticket->can($input['id'], UPDATE) && $data['link'] == self::DUPLICATE_WITH && $ticket->fields['status'] != CommonITILObject::SOLVED && $ticket->fields['status'] != CommonITILObject::CLOSED) {
                     $ticket->update($input);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 if (isset($_POST['update'])) {
     $track->check($_POST['id'], 'w');
     if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
         $splitter = explode("_", $_POST["_my_items"]);
         if (count($splitter) == 2) {
             $_POST["itemtype"] = $splitter[0];
             $_POST["items_id"] = $splitter[1];
         }
     }
     $track->update($_POST);
     Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
     // Copy solution to KB redirect to KB
     if (isset($_POST['_sol_to_kb']) && $_POST['_sol_to_kb']) {
         Html::redirect($CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=new&item_itemtype=Ticket&item_items_id=" . $_POST["id"]);
     } else {
         if ($track->can($_POST["id"], 'r')) {
             Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST["id"]);
         }
         Session::addMessageAfterRedirect(__('You have been redirected because you no longer have access to this ticket'), true, ERROR);
         Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.php");
     }
 } else {
     if (isset($_POST['delete'])) {
         $track->check($_POST['id'], 'd');
         if ($track->delete($_POST)) {
             Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
         }
         $track->redirectToList();
     } else {
         if (isset($_POST['purge'])) {
             $track->check($_POST['id'], 'd');
 /**
  * Is the current user have right to update the current followup ?
  *
  * @return boolean
  **/
 function canUpdateItem()
 {
     if ($this->fields["users_id"] != Session::getLoginUserID() && !Session::haveRight(self::$rightname, self::UPDATEALL)) {
         return false;
     }
     $ticket = new Ticket();
     if (!$ticket->can($this->getField('tickets_id'), READ)) {
         return false;
     }
     if ($this->fields["users_id"] === Session::getLoginUserID() && Session::haveRight(self::$rightname, self::UPDATEMY)) {
         return true;
     }
     // Only the technician
     return Session::haveRight(self::$rightname, self::UPDATEALL) || $ticket->isUser(CommonITILActor::ASSIGN, Session::getLoginUserID()) || isset($_SESSION["glpigroups"]) && $ticket->haveAGroup(CommonITILActor::ASSIGN, $_SESSION['glpigroups']);
 }
Ejemplo n.º 7
0
 if (isset($_POST['update'])) {
     $track->check($_POST['id'], 'w');
     if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
         $splitter = explode("_", $_POST["_my_items"]);
         if (count($splitter) == 2) {
             $_POST["itemtype"] = $splitter[0];
             $_POST["items_id"] = $splitter[1];
         }
     }
     $track->update($_POST);
     Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
     // Copy solution to KB redirect to KB
     if (isset($_POST['_sol_to_kb']) && $_POST['_sol_to_kb']) {
         Html::redirect($CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=new&item_itemtype=Ticket&item_items_id=" . $_POST["id"]);
     } else {
         if ($track->can($_POST["id"], 'r')) {
             Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST["id"]);
         }
         Session::addMessageAfterRedirect(__('You have been redirected because you no longer have access to this ticket'), true, ERROR);
         Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.php");
     }
 } else {
     if (isset($_POST['delete'])) {
         $track->check($_POST['id'], 'd');
         if ($track->delete($_POST)) {
             Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
         }
         $track->redirectToList();
     } else {
         if (isset($_POST['purge'])) {
             $track->check($_POST['id'], 'd');
Ejemplo n.º 8
0
 /**
  * Assign and actor in a ticket for an authenticated user
  *
  * @param $params    array of options (ticket, id2name)
  * @param $protocol        the communication protocol used
  *
  * @return array of hashtable as glpi.getTicket
  **/
 static function methodsetTicketAssign($params, $protocol)
 {
     global $DB, $CFG_GLPI;
     if (isset($params['help'])) {
         return array('ticket' => 'integer,mandatory', 'user' => 'integer,optional', 'supplier' => 'integer,optional', 'group' => 'integer,optional', 'user_email' => 'string,optional', 'use_email_notification' => 'bool,optional', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     if (!Session::haveRight("assign_ticket", "1")) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     if (!isset($params['user']) && !isset($params['group']) && !isset($params['supplier'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'user or group or supplier');
     }
     $ticket = new Ticket();
     if (!isset($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'ticket');
     }
     if (!is_numeric($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'ticket=' . $params['ticket']);
     }
     if (!$ticket->can($params['ticket'], 'r')) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND);
     }
     if (!$ticket->getFromDB($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, '', 'ticket');
     }
     $ticket_user = new Ticket_User();
     $user = array('tickets_id' => $params['ticket'], 'type' => CommonITILActor::ASSIGN);
     // technician : optionnal,  default = none
     if (isset($params['user'])) {
         if (!is_numeric($params['user'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user');
         }
         $user['users_id'] = $params['user'];
         if ($ticket->getFromDB($params['ticket'])) {
             $entity = $ticket->getField('entities_id');
         }
         if (!$ticket_user->can(-1, 'w', $user) || !self::checkUserRights($params['user'], "own_ticket", 1, $entity)) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
         if ($ticket->isUser(CommonITILActor::ASSIGN, $user['users_id'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'User already assign for this ticket');
         }
         if (isset($params['user_email'])) {
             if (!NotificationMail::isUserAddressValid($params['user_email'])) {
                 return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user_email');
             }
             $user['alternative_email'] = $params['user_email'];
             $user['use_notification'] = 1;
         } else {
             if (isset($params['use_email_notification']) && $params['use_email_notification']) {
                 $user['_additional_assigns'][] = array('users_id' => $params['user'], 'use_notification' => 1);
             } else {
                 if (isset($params['use_email_notification']) && !$params['use_email_notification']) {
                     $user['_additional_assigns'][] = array('users_id' => $params['user'], 'use_notification' => 0);
                 }
             }
         }
         if (!$ticket_user->add($user)) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'user not assign');
         }
     }
     // group (technicians group) : optionnal,  default = none
     $group_ticket = new Group_Ticket();
     $group = array('tickets_id' => $params['ticket'], 'type' => CommonITILActor::ASSIGN);
     if (isset($params['group'])) {
         if (!is_numeric($params['group'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group');
         }
         $group['groups_id'] = $params['group'];
         if (!$group_ticket->can(-1, 'w', $group)) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
         if ($ticket->isGroup(CommonITILActor::ASSIGN, $params['group'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'Group already assign for this ticket');
         }
         if (!$group_ticket->add($group)) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'group not assign');
         }
     }
     // supplier to assign : optionnal,  default = none
     $supplier_ticket = new Supplier_Ticket();
     $supplier = array('tickets_id' => $params['ticket'], 'type' => CommonITILActor::ASSIGN);
     if (isset($params['supplier'])) {
         if (!is_numeric($params['supplier'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'supplier');
         }
         $supplier['suppliers_id'] = $params['supplier'];
         if (!$supplier_ticket->can(-1, 'w', $supplier)) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
         if ($ticket->isSupplier(CommonITILActor::ASSIGN, $params['supplier'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'Supplier already assign for this ticket');
         }
         if (!$supplier_ticket->add($supplier)) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'supplier not assign');
         }
     }
     return self::methodGetTicket(array('ticket' => $params['ticket']), $protocol);
     return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
 }
Ejemplo n.º 9
0
 /**
  * Print the HTML array for Items linked to a ticket
  *
  * @param $ticket Ticket object
  *
  * @return Nothing (display)
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $instID = $ticket->fields['id'];
     if (!$ticket->can($instID, READ)) {
         return false;
     }
     $canedit = $ticket->canEdit($instID) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central";
     $rand = mt_rand();
     $query = "SELECT DISTINCT `itemtype`\n                FROM `glpi_items_tickets`\n                WHERE `glpi_items_tickets`.`tickets_id` = '{$instID}'\n                ORDER BY `itemtype`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='ticketitem_form{$rand}' id='ticketitem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td>";
         // Select hardware on creation or if have update right
         $class = new $ticket->userlinkclass();
         $tickets_user = $class->getActors($instID);
         $dev_user_id = 0;
         if (isset($tickets_user[CommonITILActor::REQUESTER]) && count($tickets_user[CommonITILActor::REQUESTER]) == 1) {
             foreach ($tickets_user[CommonITILActor::REQUESTER] as $user_id_single) {
                 $dev_user_id = $user_id_single['users_id'];
             }
         }
         if ($dev_user_id > 0) {
             self::dropdownMyDevices($dev_user_id, $ticket->fields["entities_id"], null, 0, array('tickets_id' => $instID));
         }
         $data = array_keys(getAllDatasFromTable('glpi_items_tickets'));
         $used = array();
         if (!empty($data)) {
             foreach ($data as $val) {
                 $used[$val['itemtype']] = $val['id'];
             }
         }
         self::dropdownAllDevices("itemtype", null, 0, 1, $dev_user_id, $ticket->fields["entities_id"], array('tickets_id' => $instID));
         echo "<span id='item_ticket_selection_information'></span>";
         echo "</td><td class='center' width='30%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "<input type='hidden' name='tickets_id' value='{$instID}'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number) {
         $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_top .= "</th>";
         $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= "</th>";
     }
     $header_end .= "<th>" . __('Type') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . __('Name') . "</th>";
     $header_end .= "<th>" . __('Serial number') . "</th>";
     $header_end .= "<th>" . __('Inventory number') . "</th></tr>";
     echo $header_begin . $header_top . $header_end;
     $totalnb = 0;
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
             $itemtable = getTableForItemType($itemtype);
             $query = "SELECT `{$itemtable}`.*,\n                             `glpi_items_tickets`.`id` AS IDD,\n                             `glpi_entities`.`id` AS entity\n                      FROM `glpi_items_tickets`,\n                           `{$itemtable}`";
             if ($itemtype != 'Entity') {
                 $query .= " LEFT JOIN `glpi_entities`\n                                 ON (`{$itemtable}`.`entities_id`=`glpi_entities`.`id`) ";
             }
             $query .= " WHERE `{$itemtable}`.`id` = `glpi_items_tickets`.`items_id`\n                              AND `glpi_items_tickets`.`itemtype` = '{$itemtype}'\n                              AND `glpi_items_tickets`.`tickets_id` = '{$instID}'";
             if ($item->maybeTemplate()) {
                 $query .= " AND `{$itemtable}`.`is_template` = '0'";
             }
             $query .= getEntitiesRestrictRequest(" AND", $itemtable, '', '', $item->maybeRecursive()) . "\n                      ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`name`";
             $result_linked = $DB->query($query);
             $nb = $DB->numrows($result_linked);
             for ($prem = true; $data = $DB->fetch_assoc($result_linked); $prem = false) {
                 $name = $data["name"];
                 if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                     $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
                 }
                 if ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk') {
                     $link = $itemtype::getFormURLWithID($data['id']);
                     $namelink = "<a href=\"" . $link . "\">" . $name . "</a>";
                 } else {
                     $namelink = $name;
                 }
                 echo "<tr class='tab_bg_1'>";
                 if ($canedit) {
                     echo "<td width='10'>";
                     Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]);
                     echo "</td>";
                 }
                 if ($prem) {
                     $typename = $item->getTypeName($nb);
                     echo "<td class='center top' rowspan='{$nb}'>" . ($nb > 1 ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename) . "</td>";
                 }
                 echo "<td class='center'>";
                 echo Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>";
                 echo "<td class='center" . (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'");
                 echo ">" . $namelink . "</td>";
                 echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                 echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                 echo "</tr>";
             }
             $totalnb += $nb;
         }
     }
     if ($number) {
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Ejemplo n.º 10
0
 /**
  * Is the current user have right to update the current task ?
  *
  * @return boolean
  **/
 function canUpdateItem()
 {
     if ($this->fields["users_id"] != getLoginUserID() && !haveRight('update_tasks', 1)) {
         return false;
     }
     $ticket = new Ticket();
     if (!$ticket->can($this->getField('tickets_id'), 'r')) {
         return false;
     }
     return true;
 }
Ejemplo n.º 11
0
                 $ticket->update($input);
             }
         }
     }
     break;
 case "link_ticket":
     $ticket = new Ticket();
     if (isset($_POST['link']) && isset($_POST['tickets_id_1'])) {
         if ($ticket->getFromDB($_POST['tickets_id_1'])) {
             foreach ($_POST["item"] as $key => $val) {
                 if ($val == 1) {
                     $input['id'] = $_POST['tickets_id_1'];
                     $input['_link']['tickets_id_1'] = $_POST['tickets_id_1'];
                     $input['_link']['link'] = $_POST['link'];
                     $input['_link']['tickets_id_2'] = $key;
                     if ($ticket->can($_POST['tickets_id_1'], 'w')) {
                         $ticket->update($input);
                     }
                 }
             }
         }
     }
     break;
 case 'reset':
     if ($_POST["itemtype"] == 'CronTask') {
         checkRight('config', 'w');
         $crontask = new CronTask();
         foreach ($_POST["item"] as $key => $val) {
             if ($val == 1 && $crontask->getFromDB($key)) {
                 $crontask->resetDate();
             }
Ejemplo n.º 12
0
 /**
  * Check is the curent user is allowed to see the file
  *
  * @param $options array of options (only 'tickets_id' used)
  *
  * @return boolean
  **/
 function canViewFile($options)
 {
     global $DB, $CFG_GLPI;
     if (isset($_SESSION["glpiactiveprofile"]["interface"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") {
         // My doc Check and Common doc right access
         if ($this->can($this->fields["id"], 'r') || $this->fields["users_id"] === getLoginUserID()) {
             return true;
         }
         // Knowbase Case
         if (haveRight("knowbase", "r")) {
             $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                      WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                            AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'" . getEntitiesRestrictRequest(' AND', 'glpi_knowbaseitems', '', '', true);
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
         }
         if (haveRight("faq", "r")) {
             $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                      WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                            AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND `glpi_knowbaseitems`.`is_faq` = '1'" . getEntitiesRestrictRequest(' AND', 'glpi_knowbaseitems', '', '', true);
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
         }
         // Tracking Case
         if (isset($options["tickets_id"])) {
             $job = new Ticket();
             if ($job->can($options["tickets_id"], 'r')) {
                 $query = "SELECT *\n                         FROM `glpi_documents_items`\n                         WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n                               AND `glpi_documents_items`.`itemtype` = 'Ticket'\n                               AND `documents_id`='" . $this->fields["id"] . "'";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     return true;
                 }
             }
         }
     } else {
         if (getLoginUserID()) {
             // ! central
             // Check if it is my doc
             if ($this->fields["users_id"] === getLoginUserID()) {
                 return true;
             }
             if (haveRight("faq", "r")) {
                 // Check if it is a FAQ document
                 $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                      WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                            AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND `glpi_knowbaseitems`.`is_faq` = '1'" . getEntitiesRestrictRequest(' AND', 'glpi_knowbaseitems', '', '', true);
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     return true;
                 }
             }
             // Tracking Case
             if (isset($options["tickets_id"])) {
                 $job = new Ticket();
                 if ($job->can($options["tickets_id"], 'r')) {
                     $query = "SELECT *\n                         FROM `glpi_documents_items`\n                         WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n                               AND `glpi_documents_items`.`itemtype` = 'Ticket'\n                               AND `documents_id` = '" . $this->fields["id"] . "'";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) > 0) {
                         return true;
                     }
                 }
             }
         }
     }
     // Public FAQ for not connected user
     if ($CFG_GLPI["use_public_faq"]) {
         $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_knowbaseitems`\n                        ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                   WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                         AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND `glpi_knowbaseitems`.`is_faq` = '1'\n                         AND `glpi_knowbaseitems`.`entities_id` = '0'\n                         AND `glpi_knowbaseitems`.`is_recursive` = '1'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 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>";
 }
Ejemplo n.º 14
0
 /**
  * Affect the same solution for duplicates tickets
  *
  * @param $ID ID of the ticket id
  *
  * @return nothing do the change
  **/
 static function manageLinkedTicketsOnSolved($ID)
 {
     $ticket = new Ticket();
     if ($ticket->getfromDB($ID)) {
         $input['solution'] = addslashes($ticket->fields['solution']);
         $input['ticketsolutiontypes_id'] = addslashes($ticket->fields['ticketsolutiontypes_id']);
         $tickets = self::getLinkedTicketsTo($ID);
         if (count($tickets)) {
             foreach ($tickets as $data) {
                 $input['id'] = $data['tickets_id'];
                 if ($ticket->can($input['id'], 'w') && $data['link'] == self::DUPLICATE_WITH && $ticket->fields['status'] != 'solved' && $ticket->fields['status'] != 'closed') {
                     $ticket->update($input);
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
 static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job)
 {
     global $CFG_GLPI, $DB;
     $ID = $job->getField('id');
     if (!$job->can($ID, 'r')) {
         return false;
     }
     $pdf->setColumnsSize(100);
     $pdf->displayTitle('<b>' . (empty($job->fields["name"]) ? __('Without title') : ($name = $job->fields["name"])) . '</b>');
     if (count($_SESSION['glpiactiveentities']) > 1) {
         $entity = " (" . Dropdown::getDropdownName("glpi_entities", $job->fields["entities_id"]) . ")";
     } else {
         $entity = '';
     }
     $pdf->setColumnsSize(50, 50);
     $recipient_name = '';
     if ($job->fields["users_id_recipient"]) {
         $recipient = new User();
         $recipient->getFromDB($job->fields["users_id_recipient"]);
         $recipient_name = $recipient->getName();
     }
     $sla = $due = $commentsla = '';
     if ($job->fields['due_date']) {
         $due = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Due date') . "</b></i>", Html::convDateTime($job->fields['due_date']));
     }
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Opening date') . "</i></b>", Html::convDateTime($job->fields["date"])), $due);
     $pdf->setColumnsSize(100);
     if ($job->fields["slas_id"] > 0) {
         $sla = "<b><i>" . sprintf(__('%1$s: %2$s'), __('SLA') . "</b></i>", Html::clean(Dropdown::getDropdownName("glpi_slas", $job->fields["slas_id"])));
         $slalevel = new SlaLevel();
         if ($slalevel->getFromDB($job->fields['slalevels_id'])) {
             $commentsla = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Escalation level') . "</b></i>", $slalevel->getName());
         }
         $nextaction = new SlaLevel_Ticket();
         if ($nextaction->getFromDBForTicket($job->fields["id"])) {
             $commentsla .= " <b><i>" . sprintf(__('Next escalation: %s') . "</b></i>", Html::convDateTime($nextaction->fields['date']));
             if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) {
                 $commentsla .= " <b><i>" . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName());
             }
         }
         $pdf->displayText($sla, $commentsla, 1);
     }
     $pdf->setColumnsSize(50, 50);
     $lastupdate = Html::convDateTime($job->fields["date_mod"]);
     if ($job->fields['users_id_lastupdater'] > 0) {
         $lastupdate = sprintf(__('%1$s by %2$s'), $lastupdate, getUserName($job->fields["users_id_lastupdater"]));
     }
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('By') . "</i></b>", $recipient_name), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Last update') . '</i></b>', $lastupdate));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Type') . "</i></b>", Html::clean(Ticket::getTicketTypeName($job->fields["type"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Category') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_itilcategories", $job->fields["itilcategories_id"]))));
     $status = '';
     if (in_array($job->fields["status"], $job->getSolvedStatusArray()) || in_array($job->fields["status"], $job->getClosedStatusArray())) {
         $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields["solvedate"]));
     }
     if (in_array($job->fields["status"], $job->getClosedStatusArray())) {
         $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields["closedate"]));
     }
     if ($job->fields["status"] == Ticket::WAITING) {
         $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['begin_waiting_date']));
     }
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Status') . "</i></b>", Html::clean($job->getStatus($job->fields["status"])) . $status), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Request source') . "</i></b>", Html::clean(Dropdown::getDropdownName('glpi_requesttypes', $job->fields['requesttypes_id']))));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Urgency') . "</i></b>", Html::clean($job->getUrgencyName($job->fields["urgency"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Approval') . "</i></b>", TicketValidation::getStatus($job->fields['global_validation'])));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Impact') . "</i></b>", Html::clean($job->getImpactName($job->fields["impact"]))));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Priority') . "</i></b>", Html::clean($job->getPriorityName($job->fields["priority"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Location') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_locations", $job->fields["locations_id"]))));
     // Item
     $name = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Associated element') . "</i></b>", '');
     $commentitem = '';
     $pdf->setColumnsSize(100);
     if ($job->fields['itemtype'] && ($item = getItemForItemtype($job->fields['itemtype']))) {
         if ($item->getFromDB($job->fields["items_id"])) {
             $name = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Associated element') . "</i></b>", $item->getNameID());
             if (isset($item->fields["serial"])) {
                 $commentitem = ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Serial number') . "</i></b>", Html::clean($item->fields["serial"]));
                 Html::clean($item->fields["serial"]);
             }
             if (isset($item->fields["otherserial"])) {
                 $commentitem .= ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Inventory number') . "</i></b>", Html::clean($item->fields["otherserial"]));
             }
             if (isset($item->fields["locations_id"])) {
                 $commentitem .= ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Location') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_locations", $item->fields["locations_id"])));
             }
         }
     }
     $pdf->displayText($name, $commentitem, 1);
     $pdf->setColumnsSize(50, 50);
     // Requester
     $users = array();
     $listusers = '';
     $requester = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Requester'), $listusers);
     foreach ($job->getUsers(CommonITILActor::REQUESTER) as $d) {
         if ($d['users_id']) {
             $tmp = Html::clean(getUserName($d['users_id']));
             if ($d['alternative_email']) {
                 $tmp .= ' (' . $d['alternative_email'] . ')';
             }
         } else {
             $tmp = $d['alternative_email'];
         }
         $users[] = $tmp;
     }
     if (count($users)) {
         $listusers = implode(', ', $users);
     }
     $pdf->displayText($requester, $listusers, 1);
     $groups = array();
     $listgroups = '';
     $requestergroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Requester group'), $listgroups);
     foreach ($job->getGroups(CommonITILActor::REQUESTER) as $d) {
         $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
     }
     if (count($groups)) {
         $listgroups = implode(', ', $groups);
     }
     $pdf->displayText($requestergroup, $listgroups, 1);
     // Observer
     $users = array();
     $listusers = '';
     $watcher = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Watcher'), $listusers);
     foreach ($job->getUsers(CommonITILActor::OBSERVER) as $d) {
         if ($d['users_id']) {
             $tmp = Html::clean(getUserName($d['users_id']));
             if ($d['alternative_email']) {
                 $tmp .= ' (' . $d['alternative_email'] . ')';
             }
         } else {
             $tmp = $d['alternative_email'];
         }
         $users[] = $tmp;
     }
     if (count($users)) {
         $listusers = implode(', ', $users);
     }
     $pdf->displayText($watcher, $listusers, 1);
     $groups = array();
     $listgroups = '';
     $watchergroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Watcher group'), $listgroups);
     foreach ($job->getGroups(CommonITILActor::OBSERVER) as $d) {
         $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
     }
     if (count($groups)) {
         $listgroups = implode(', ', $groups);
     }
     $pdf->displayText($watchergroup, $listgroups, 1);
     // Assign to
     $users = array();
     $listusers = '';
     $assign = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('User assigned'), $listusers);
     foreach ($job->getUsers(CommonITILActor::ASSIGN) as $d) {
         if ($d['users_id']) {
             $tmp = Html::clean(getUserName($d['users_id']));
             if ($d['alternative_email']) {
                 $tmp .= ' (' . $d['alternative_email'] . ')';
             }
         } else {
             $tmp = $d['alternative_email'];
         }
         $users[] = $tmp;
     }
     if (count($users)) {
         $listusers = implode(', ', $users);
     }
     $pdf->displayText($assign, $listusers, 1);
     $groups = array();
     $listgroups = '';
     $assigngroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Group assigned'), $listgroups);
     foreach ($job->getGroups(CommonITILActor::ASSIGN) as $d) {
         $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
     }
     if (count($groups)) {
         $listgroups = implode(', ', $groups);
     }
     $pdf->displayText($assigngroup, $listgroups, 1);
     // Supplier
     $suppliers = array();
     $listsuppliers = '';
     $assignsupplier = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Supplier assigned'), $listsuppliers);
     foreach ($job->getSuppliers(CommonITILActor::ASSIGN) as $d) {
         $suppliers[] = Html::clean(Dropdown::getDropdownName("glpi_suppliers", $d['suppliers_id']));
     }
     if (count($suppliers)) {
         $listsuppliers = implode(', ', $suppliers);
     }
     $pdf->displayText($assignsupplier, $listsuppliers, 1);
     $pdf->setColumnsSize(100);
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Title') . "</i></b>", $job->fields["name"]));
     $pdf->displayText("<b><i>" . sprintf(__('%1$s: %2$s'), __('Description') . "</i></b>", $job->fields['content']));
     // Linked tickets
     $tickets = Ticket_Ticket::getLinkedTicketsTo($ID);
     if (is_array($tickets) && count($tickets)) {
         $ticket = new Ticket();
         foreach ($tickets as $linkID => $data) {
             $tmp = sprintf(__('%1$s %2$s'), Ticket_Ticket::getLinkName($data['link']), sprintf(__('%1$s %2$s'), __('ID'), $data['tickets_id']));
             if ($ticket->getFromDB($data['tickets_id'])) {
                 $tmp = sprintf(__('%1$s: %2$s'), $tmp, $ticket->getName());
             }
             $jobs[] = $tmp;
             $jobs = implode("\n", $jobs);
         }
         $linked = "<b><i>" . sprintf(__('%1$s: %2$s') . "</i></b>", __('Linked tickets'), '');
         $pdf->displayText($linked, $jobs, 1);
     }
     $pdf->displaySpace();
 }
 /**
  * Is the current user have right to update the current followup ?
  *
  * @return boolean
  **/
 function canUpdateItem()
 {
     if ($this->fields["users_id"] != getLoginUserID() && !haveRight('update_followups', 1)) {
         return false;
     }
     $ticket = new Ticket();
     if (!$ticket->can($this->getField('tickets_id'), 'r')) {
         return false;
     }
     if ($this->fields["users_id"] === getLoginUserID() && haveRight('update_own_followups', 1)) {
         return true;
     }
     // Only the technician
     return haveRight("update_followups", "1") || $ticket->isUser(Ticket::ASSIGN, getLoginUserID()) || isset($_SESSION["glpigroups"]) && $ticket->haveAGroup(Ticket::ASSIGN, $_SESSION['glpigroups']);
 }
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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
* @since version 0.85
*/
if (!defined('GLPI_ROOT')) {
    include '../inc/includes.php';
}
$link = new Group_Ticket();
$item = new Ticket();
Session::checkLoginUser();
if (isset($_POST['delete'])) {
    $link->check($_POST['id'], DELETE);
    $link->delete($_POST);
    Event::log($link->fields['tickets_id'], "ticket", 4, "tracking", sprintf(__('%s deletes an actor'), $_SESSION["glpiname"]));
    if ($item->can($link->fields["tickets_id"], READ)) {
        Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $link->fields['tickets_id']);
    }
    Session::addMessageAfterRedirect(__('You have been redirected because you no longer have access to this item'), true, ERROR);
    Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.php");
}
Html::displayErrorAndDie('Lost');
Ejemplo n.º 18
0
 /**
  * Show problems for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!Session::haveRight("show_all_problem", 1) || !$ticket->can($ID, 'r')) {
         //      if (!$ticket->can($ID,'r')) {
         return false;
     }
     $canedit = $ticket->can($ID, 'w');
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_problems_tickets`.`id` AS linkID,\n                                `glpi_problems`.*\n                FROM `glpi_problems_tickets`\n                LEFT JOIN `glpi_problems`\n                     ON (`glpi_problems_tickets`.`problems_id` = `glpi_problems`.`id`)\n                WHERE `glpi_problems_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_problems`.`name`";
     $result = $DB->query($query);
     $problems = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $problems[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='problemticket_form{$rand}' id='problemticket_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a problem') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>";
         echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         $condition = "`glpi_problems`.`status` NOT IN ('" . implode("', '", array_merge(Problem::getSolvedStatusArray(), Problem::getClosedStatusArray())) . "')";
         Problem::dropdown(array('used' => $used, 'entity' => $ticket->getEntityID(), 'condition' => $condition));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td><td>";
         echo "<a href='" . Toolbox::getItemTypeFormURL('Problem') . "?tickets_id={$ID}'>";
         _e('Create a problem from this ticket');
         echo "</a>";
         echo "</td></tr></table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='11'>" . Problem::getTypeName($numrows) . "</th>";
     echo "</tr>";
     if ($numrows) {
         Problem::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
         Session::initNavigateListItems('Problem', sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->fields["name"]));
         $i = 0;
         foreach ($problems as $data) {
             Session::addToNavigateListItems('Problem', $data["id"]);
             Problem::showShort($data['id'], Search::HTML_OUTPUT, $i, $data['linkID']);
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Ejemplo n.º 19
0
 /**
  * Show projecttasks for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!$ticket->can($ID, READ)) {
         return false;
     }
     $canedit = $ticket->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_projecttasks_tickets`.`id` AS linkID,\n                                `glpi_projecttasks`.*\n                FROM `glpi_projecttasks`\n                LEFT JOIN `glpi_projecttasks_tickets`\n                   ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n                WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_projecttasks`.`name`";
     $result = $DB->query($query);
     $pjtasks = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $pjtasks[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     //       if ($canedit) {
     //          echo "<div class='firstbloc'>";
     //          echo "<form name='projecttaskticket_form$rand' id='projecttaskticket_form$rand'
     //                 method='post' action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
     //
     //          echo "<table class='tab_cadre_fixe'>";
     //          echo "<tr class='tab_bg_2'><th colspan='3'>".__('Add a project task')."</th></tr>";
     //
     //          echo "<tr class='tab_bg_2'><td class='right'>";
     //          echo "<input type='hidden' name='tickets_id' value='$ID'>";
     //          $condition = "`glpi_projecttasks`.`projectstates_id` <> 3";
     //          ProjectTask::dropdown(array('used'        => $used,
     //                                      'entity'      => $ticket->getEntityID(),
     //                                      'entity_sons' => $ticket->isRecursive(),
     //                                      'condition'   => $condition,
     //                                      'displaywith' => array('id')));
     //          echo "</td><td width='20%'>";
     // //          echo "<a href='".Toolbox::getItemTypeFormURL('ProjectTask')."?tickets_id=$ID'>";
     // //                 _e('Create a project task from this ticket');
     // //          echo "</a>";
     //          echo "</td><td class='center'>";
     //          echo "<input type='submit' name='add' value=\""._sx('button', 'Add')."\" class='submit'>";
     //          echo "</td></tr>";
     //
     //          echo "</table>";
     //          Html::closeForm();
     //          echo "</div>";
     //       }
     echo "<div class='spaced'>";
     if ($numrows) {
         $columns = array('projectname' => Project::getTypeName(Session::getPluralNumber()), 'name' => ProjectTask::getTypeName(Session::getPluralNumber()), 'tname' => __('Type'), 'sname' => __('Status'), 'percent_done' => __('Percent done'), 'plan_start_date' => __('Planned start date'), 'plan_end_date' => __('Planned end date'), 'planned_duration' => __('Planned duration'), '_effect_duration' => __('Effective duration'), 'fname' => __('Father'));
         if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
             $order = "DESC";
         } else {
             $order = "ASC";
         }
         if (!isset($_GET["sort"]) || empty($_GET["sort"])) {
             $_GET["sort"] = "plan_start_date";
         }
         if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
             $sort = "`" . $_GET["sort"] . "`";
         } else {
             $sort = "`plan_start_date` {$order}, `name`";
         }
         $query = "SELECT `glpi_projecttasks`.*,\n                       `glpi_projecttasktypes`.`name` AS tname,\n                       `glpi_projectstates`.`name` AS sname,\n                       `glpi_projectstates`.`color`,\n                       `father`.`name` AS fname,\n                       `father`.`id` AS fID,\n                       `glpi_projects`.`name` AS projectname,\n                       `glpi_projects`.`content` AS projectcontent\n                FROM `glpi_projecttasks`\n                LEFT JOIN `glpi_projecttasktypes`\n                   ON (`glpi_projecttasktypes`.`id` = `glpi_projecttasks`.`projecttasktypes_id`)\n                LEFT JOIN `glpi_projectstates`\n                   ON (`glpi_projectstates`.`id` = `glpi_projecttasks`.`projectstates_id`)\n                LEFT JOIN `glpi_projecttasks` as father\n                   ON (`father`.`id` = `glpi_projecttasks`.`projecttasks_id`)\n                LEFT JOIN `glpi_projecttasks_tickets`\n                   ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n                LEFT JOIN `glpi_projects`\n                   ON (`glpi_projecttasks`.`projects_id` = `glpi_projects`.`id`)\n                WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY {$sort} {$order}";
         Session::initNavigateListItems('ProjectTask', sprintf(__('%1$s = %2$s'), $ticket::getTypeName(1), $ticket->getName()));
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result)) {
                 echo "<table class='tab_cadre_fixehov'>";
                 echo "<tr><th colspan='10'>" . ProjectTask::getTypeName($numrows) . "</th>";
                 echo "</tr>";
                 $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
                 $header = '<tr>';
                 foreach ($columns as $key => $val) {
                     // Non order column
                     if ($key[0] == '_') {
                         $header .= "<th>{$val}</th>";
                     } else {
                         $header .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                     }
                 }
                 $header .= "</tr>\n";
                 echo $header;
                 while ($data = $DB->fetch_assoc($result)) {
                     Session::addToNavigateListItems('ProjectTask', $data['id']);
                     $rand = mt_rand();
                     echo "<tr class='tab_bg_2'>";
                     echo "<td>";
                     $link = "<a id='Project" . $data["projects_id"] . $rand . "' href='project.form.php?id=" . $data['projects_id'] . "'>" . $data['projectname'] . (empty($data['projectname']) ? "(" . $data['projects_id'] . ")" : "") . "</a>";
                     echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['projectcontent'], array('display' => false, 'applyto' => "Project" . $data["projects_id"] . $rand)));
                     echo "</td>";
                     echo "<td>";
                     $link = "<a id='ProjectTask" . $data["id"] . $rand . "' href='projecttask.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a>";
                     echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['content'], array('display' => false, 'applyto' => "ProjectTask" . $data["id"] . $rand)));
                     echo "</td>";
                     echo "<td>" . $data['tname'] . "</td>";
                     echo "<td";
                     echo " style=\"background-color:" . $data['color'] . "\"";
                     echo ">" . $data['sname'] . "</td>";
                     echo "<td>";
                     echo Dropdown::getValueWithUnit($data["percent_done"], "%");
                     echo "</td>";
                     echo "<td>" . Html::convDateTime($data['plan_start_date']) . "</td>";
                     echo "<td>" . Html::convDateTime($data['plan_end_date']) . "</td>";
                     echo "<td>" . Html::timestampToString($data['planned_duration'], false) . "</td>";
                     echo "<td>" . Html::timestampToString(ProjectTask::getTotalEffectiveDuration($data['id']), false) . "</td>";
                     echo "<td>";
                     if ($data['projecttasks_id'] > 0) {
                         $father = Dropdown::getDropdownName('glpi_projecttasks', $data['projecttasks_id']);
                         echo "<a id='ProjectTask" . $data["projecttasks_id"] . $rand . "' href='projecttask.form.php?id=" . $data['projecttasks_id'] . "'>" . $father . (empty($father) ? "(" . $data['projecttasks_id'] . ")" : "") . "</a>";
                     }
                     echo "</td></tr>";
                 }
                 echo $header;
                 echo "</table>\n";
             } else {
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr><th>" . __('No item found') . "</th></tr>";
                 echo "</table>\n";
             }
         }
         echo "</div>";
     }
 }
Ejemplo n.º 20
0
 /**
  * Show changes for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!$ticket->can($ID, 'r')) {
         return false;
     }
     $canedit = $ticket->can($ID, 'w');
     $rand = mt_rand();
     echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     $query = "SELECT DISTINCT `glpi_changes_tickets`.`id` AS linkID,\n                                `glpi_changes`.*\n                FROM `glpi_changes_tickets`\n                LEFT JOIN `glpi_changes`\n                     ON (`glpi_changes_tickets`.`changes_id` = `glpi_changes`.`id`)\n                WHERE `glpi_changes_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_changes`.`name`";
     $result = $DB->query($query);
     $changes = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $changes[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n               action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a change') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>";
         echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         Change::dropdown(array('used' => $used, 'entity' => $ticket->getEntityID()));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td><td>";
         echo "<a href='" . Toolbox::getItemTypeFormURL('Change') . "?tickets_id={$ID}'>";
         _e('Create a change from this ticket');
         echo "</a>";
         echo "</td></tr></table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr>";
     if ($canedit && $numrows) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Title') . "</th>";
     echo "</tr>";
     $used = array();
     if ($numrows) {
         Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->fields["name"]));
         foreach ($changes as $data) {
             $used[$data['id']] = $data['id'];
             Session::addToNavigateListItems('Change', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 echo "</td>";
             }
             echo "<td><a href='" . Toolbox::getItemTypeFormURL('Change') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>";
             echo "</tr>";
         }
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }