Exemplo n.º 1
0
 static function afterAdd(Group_Ticket $item)
 {
     global $DB;
     //Toolbox::logDebug(__METHOD__, $item);
     $config = PluginBehaviorsConfig::getInstance();
     if ($config->getField('add_notif')) {
         if ($item->getField('type') == CommonITILActor::ASSIGN) {
             $ticket = new Ticket();
             if ($ticket->getFromDB($item->getField('tickets_id'))) {
                 NotificationEvent::raiseEvent('plugin_behaviors_ticketnewgrp', $ticket);
             }
         }
     }
     // Check is the connected user is a tech
     if (!is_numeric(Session::getLoginUserID(false)) || !Session::haveRight('own_ticket', 1)) {
         return false;
         // No check
     }
     $config = PluginBehaviorsConfig::getInstance();
     if ($config->getField('single_tech_mode') != 0 && $item->input['type'] == CommonITILActor::ASSIGN) {
         $crit = array('tickets_id' => $item->input['tickets_id'], 'type' => CommonITILActor::ASSIGN);
         foreach ($DB->request('glpi_groups_tickets', $crit) as $data) {
             if ($data['id'] != $item->getID()) {
                 $gu = new Group_Ticket();
                 $gu->delete($data);
             }
         }
         if ($config->getField('single_tech_mode') == 2) {
             foreach ($DB->request('glpi_tickets_users', $crit) as $data) {
                 $gu = new Ticket_User();
                 $gu->delete($data);
             }
         }
     }
 }
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');
Exemplo n.º 3
0
     $track->deleteSLA($_POST["id"]);
     Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
     Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST["id"]);
 } else {
     if (isset($_POST['delete_user'])) {
         ///TODO try to move it to specific form page
         $ticket_user = new Ticket_User();
         $ticket_user->check($_POST['id'], 'd');
         $ticket_user->delete($_POST);
         Event::log($_POST['tickets_id'], "ticket", 4, "tracking", sprintf(__('%s deletes an actor'), $_SESSION["glpiname"]));
         Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST['tickets_id']);
     } else {
         if (isset($_POST['delete_group'])) {
             $group_ticket = new Group_Ticket();
             $group_ticket->check($_POST['id'], 'd');
             $group_ticket->delete($_POST);
             Event::log($_POST['tickets_id'], "ticket", 4, "tracking", sprintf(__('%s deletes an actor'), $_SESSION["glpiname"]));
             Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST['tickets_id']);
         } else {
             if (isset($_POST['delete_supplier'])) {
                 $supplier_ticket = new Supplier_Ticket();
                 $supplier_ticket->check($_POST['id'], 'd');
                 $supplier_ticket->delete($_POST);
                 Event::log($_POST['tickets_id'], "ticket", 4, "tracking", sprintf(__('%s deletes an actor'), $_SESSION["glpiname"]));
                 Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST['tickets_id']);
             } else {
                 if (isset($_POST['addme_observer'])) {
                     $ticket_user = new Ticket_User();
                     $track->check($_POST['tickets_id'], 'r');
                     $input = array('tickets_id' => $_POST['tickets_id'], 'users_id' => Session::getLoginUserID(), 'use_notification' => 1, 'type' => CommonITILActor::OBSERVER);
                     $ticket_user->add($input);
Exemplo n.º 4
0
         $ticket_ticket->check($_REQUEST['id'], 'w');
         $ticket_ticket->delete($_REQUEST);
         Event::log($_REQUEST['tickets_id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . $LANG['log'][120]);
         glpi_header($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_REQUEST['tickets_id']);
     } else {
         if (isset($_REQUEST['delete_user'])) {
             $ticket_user = new Ticket_User();
             $ticket_user->check($_REQUEST['id'], 'w');
             $ticket_user->delete($_REQUEST);
             Event::log($_REQUEST['tickets_id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . $LANG['log'][122]);
             glpi_header($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_REQUEST['tickets_id']);
         } else {
             if (isset($_REQUEST['delete_group'])) {
                 $group_ticket = new Group_Ticket();
                 $group_ticket->check($_REQUEST['id'], 'w');
                 $group_ticket->delete($_REQUEST);
                 Event::log($_REQUEST['tickets_id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . $LANG['log'][122]);
                 glpi_header($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_REQUEST['tickets_id']);
             } else {
                 if (isset($_REQUEST['addme_observer'])) {
                     $ticket_user = new Ticket_User();
                     $track->check($_REQUEST['tickets_id'], 'r');
                     $input = array('tickets_id' => $_REQUEST['tickets_id'], 'users_id' => getLoginUserID(), 'use_notification' => 1, 'type' => Ticket::OBSERVER);
                     $ticket_user->add($input);
                     Event::log($_REQUEST['tickets_id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . $LANG['log'][21]);
                     glpi_header($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_REQUEST['tickets_id']);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 static function fromcreatorDropUserAndGrouponTicket($ticketid)
 {
     global $DB;
     $crit = array('tickets_id' => $ticketid, 'type' => 2);
     foreach ($DB->request('glpi_groups_tickets', $crit) as $data) {
         $gu = new Group_Ticket();
         $gu->delete($data);
     }
     foreach ($DB->request('glpi_tickets_users', $crit) as $data) {
         $gu = new Ticket_User();
         $gu->delete($data);
     }
     return true;
 }
Exemplo n.º 6
0
    $a_users = $ticket_user->find("`tickets_id`='" . $_POST['tickets_id'] . "'\n         AND `type`='2'");
    foreach ($a_users as $data) {
        $query = "SELECT * FROM `glpi_groups_users`\n            WHERE `groups_id`='" . $_POST['group_assign'] . "'\n               AND `users_id`='" . $data['users_id'] . "'\n            LIMIT 1";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $ticket_user->delete($data);
            Event::log($_POST['tickets_id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . __('Deletion of an actor to the ticket'));
        }
    }
    $_SESSION['glpiactiveprofile']['assign_ticket'] = $assign_ticket_right;
    // delete group
    $group_ticket = new Group_Ticket();
    $a_groups = $group_ticket->find("`tickets_id`='" . $_POST['tickets_id'] . "'\n         AND `type`='2'");
    foreach ($a_groups as $data) {
        if ($data['groups_id'] != $_POST['group_assign']) {
            $group_ticket->delete($data);
            Event::log($_POST['tickets_id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . __('Deletion of an actor to the ticket'));
        }
    }
    Html::back();
} else {
    if (isset($_POST['update']) and $_POST['_users_id_assign'] > 0) {
        $assign_ticket_right = $_SESSION['glpiactiveprofile']['assign_ticket'];
        $_SESSION['glpiactiveprofile']['assign_ticket'] = 1;
        // Add
        $ticket = new Ticket();
        $input = array();
        $input['id'] = $_POST['tickets_id'];
        $input['_itil_assign'] = array('_type' => 'user', 'users_id' => $_POST['_users_id_assign']);
        $ticket->update($input);
        $ticket_user = new Ticket_User();
Exemplo n.º 7
0
 /**
  * Clean all assigned groups for the ticket
  * @param  int $tickets_id
  * @return nothing
  */
 static function removeAssignGroups($tickets_id, $keep_groups_id = false)
 {
     $where_keep = "";
     if ($keep_groups_id !== false) {
         if (is_array($keep_groups_id)) {
             $where_keep = "AND groups_id NOT IN (" . implode(",", $keep_groups_id) . ")";
         } else {
             $where_keep = "AND groups_id != {$keep_groups_id}";
         }
     }
     $group_ticket = new Group_Ticket();
     $found = $group_ticket->find("tickets_id = {$tickets_id} AND type = 2 {$where_keep}");
     foreach ($found as $id => $gt) {
         $group_ticket->delete($gt);
     }
     //add a var to prevent status changes unwanted
     $_SESSION['plugin_escalade']['remove_assign'] = true;
 }
Exemplo n.º 8
0
 static function notMultiple($item)
 {
     if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
         $peConfig = new PluginEscalationConfig();
         $unique_assigned = $peConfig->getValue("unique_assigned", $item->fields['entities_id']);
         if ($unique_assigned == '1') {
             $ticket_User = new Ticket_User();
             $group_Ticket = new Group_Ticket();
             $group_User = new Group_User();
             if (isset($item->input['_itil_assign'])) {
                 if ($item->input['_itil_assign']['_type'] == 'user') {
                     $in_group = 0;
                     $a_groups = $group_Ticket->find("`type`='2'\n                     AND `tickets_id`='" . $item->fields['id'] . "'");
                     $groups = Group_User::getUserGroups($item->input['_itil_assign']['users_id']);
                     if (count($a_groups) > 0) {
                         foreach ($a_groups as $data) {
                             foreach ($groups as $dat) {
                                 if ($dat['id'] == $data['groups_id']) {
                                     $in_group = 1;
                                 }
                             }
                         }
                     }
                     //if ($in_group == '0') {
                     //   unset($item->input['_itil_assign']['users_id']);
                     //}
                 } else {
                     if ($item->input['_itil_assign']['_type'] == 'group') {
                         $a_groups = $group_Ticket->find("`type`='2'\n                     AND `tickets_id`='" . $item->getID() . "'");
                         if (count($a_groups) > 0) {
                             foreach ($a_groups as $data) {
                                 $group_Ticket->delete($data);
                             }
                         }
                         $a_users = $ticket_User->find("`type`='2'\n                     AND `tickets_id`='" . $item->getID() . "'");
                         foreach ($a_users as $data) {
                             if (countElementsInTable($group_User->getTable(), "`users_id`='" . $data['users_id'] . "'\n                             AND `groups_id`='" . $item->input['_itil_assign']['groups_id'] . "'") == '0') {
                                 $ticket_User->delete($data);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
 private function manageTicket($closed = true)
 {
     global $DB, $CFG_GLPI;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.83/";
     $plugin = new Plugin();
     $plugin->getFromDBbyDir("timelineticket");
     $plugin->activate($plugin->fields['id']);
     Plugin::load("timelineticket");
     Session::loadLanguage("en_GB");
     $ticket = new Ticket();
     $group = new Group();
     $group_ticket = new Group_Ticket();
     $GLPIlog = new GLPIlogs();
     $ticket_User = new Ticket_User();
     $_SESSION['plugin_timelineticket_date'] = array();
     $group->add(array('name' => 'grtech1'));
     $group->add(array('name' => 'grtech2'));
     // * 01/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate = array('1' => $_SESSION["glpi_currenttime"]);
     $input = array();
     $input['name'] = 'Pb with the ticket';
     $input['content'] = 'I have a problem with the ticket';
     $tickets_id = $ticket->add($input);
     $GLPIlog->testSQLlogs('01/');
     $GLPIlog->testPHPlogs('01/');
     // * 02/
     sleep(2);
     // * 03/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[3] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('03/');
     $GLPIlog->testPHPlogs('03/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group1');
     $a_db = getAllDatasFromTable('glpi_tickets_users');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'users_id' => '2', 'type' => '1', 'use_notification' => '1', 'alternative_email' => '');
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'users_id' => '2', 'type' => '2', 'use_notification' => '1', 'alternative_email' => '');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to user 2 (glpi)');
     // * 04/
     sleep(2);
     // * 05/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[5] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('05/');
     $GLPIlog->testPHPlogs('05/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], 'May have status waiting');
     // * 06/
     sleep(1);
     // * 07/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[7] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $ticket_User->check($input['id'], 'w');
     $ticket_User->delete($input);
     $input = array();
     $input['id'] = 1;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('07/');
     $GLPIlog->testPHPlogs('07/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $this->assertEquals(array(), $a_db, 'May have no group assigned');
     // * 08/
     sleep(1);
     // * 09/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[9] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('09/');
     $GLPIlog->testPHPlogs('09/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'groups_id' => '2', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group2');
     $ticket->getFromDB(1);
     $this->assertEquals('assign', $ticket->fields['status'], '(09/) Status is assign');
     // * 10/
     sleep(1);
     // * 11/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[11] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 4;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('11/');
     $GLPIlog->testPHPlogs('11/');
     // * 12/
     sleep(1);
     // * 13/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[13] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('13/');
     $GLPIlog->testPHPlogs('13/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(13/)May have always status waiting');
     // * 14/
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('14/');
     $GLPIlog->testPHPlogs('14/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[3] = array('id' => '3', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, '(14/) May have ticket assigned to group1');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(14/) Status is waiting');
     // * 15/
     sleep(2);
     // * 16/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[16] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::ASSIGNED;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('16/');
     $GLPIlog->testPHPlogs('16/');
     // * 17/
     sleep(1);
     // * 18/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[18] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['solution'] = "solution";
     $ticket->update($input);
     $GLPIlog->testSQLlogs('18/');
     $GLPIlog->testPHPlogs('18/');
     $ticket->getFromDB(1);
     $this->assertEquals('solved', $ticket->fields['status'], '(18/) Status is solved');
     if ($closed) {
         // * 19/
         sleep(1);
         // * 20/
         $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
         $a_storedate[20] = $_SESSION["glpi_currenttime"];
         $fup = new TicketFollowup();
         $input = array();
         $input['tickets_id'] = $tickets_id;
         $input['add_close'] = 'add_close';
         $fup->add($input);
         $GLPIlog->testSQLlogs('20/');
         $GLPIlog->testPHPlogs('20/');
         $ticket->getFromDB(1);
         $this->assertEquals('closed', $ticket->fields['status'], '(19/) Status is closed');
     }
     self::$storedate = $a_storedate;
 }