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); } } } }
function cleanDBonPurge() { global $DB; $gu = new Group_User(); $gu->cleanDBonItemDelete($this->getType(), $this->fields['id']); $gt = new Group_Ticket(); $gt->cleanDBonItemDelete($this->getType(), $this->fields['id']); $gp = new Group_Problem(); $gp->cleanDBonItemDelete($this->getType(), $this->fields['id']); $cg = new Change_Group(); $cg->cleanDBonItemDelete($this->getType(), $this->fields['id']); $query1 = "DELETE\n FROM `glpi_projecttaskteams`\n WHERE `items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . __CLASS__ . "'"; $DB->query($query1); $query1 = "DELETE\n FROM `glpi_projectteams`\n WHERE `items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . __CLASS__ . "'"; $DB->query($query1); $gki = new Group_KnowbaseItem(); $gki->cleanDBonItemDelete($this->getType(), $this->fields['id']); $gr = new Group_Reminder(); $gr->cleanDBonItemDelete($this->getType(), $this->fields['id']); // Ticket rules use various _groups_id_* Rule::cleanForItemAction($this, '_groups_id%'); Rule::cleanForItemCriteria($this, '_groups_id%'); // GROUPS for RuleMailcollector Rule::cleanForItemCriteria($this, 'GROUPS'); // Set no group to consumables $query = "UPDATE `glpi_consumables`\n SET `items_id` = '0'\n WHERE `items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = 'Group'"; $DB->query($query); }
function cleanDBonPurge() { global $DB; $gu = new Group_User(); $gu->cleanDBonItemDelete($this->getType(), $this->fields['id']); $gt = new Group_Ticket(); $gt->cleanDBonItemDelete($this->getType(), $this->fields['id']); }
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');
function post_addItem() { global $LANG, $CFG_GLPI; // Add document if needed $this->addFiles($this->fields['id']); if (isset($this->input["_followup"]) && is_array($this->input["_followup"]) && strlen($this->input["_followup"]['content']) > 0) { $fup = new TicketFollowup(); $type = "new"; if (isset($this->fields["status"]) && $this->fields["status"] == "solved") { $type = "solved"; } $toadd = array("type" => $type, "tickets_id" => $this->fields['id']); if (isset($this->input["_followup"]['content']) && strlen($this->input["_followup"]['content']) > 0) { $toadd["content"] = $this->input["_followup"]['content']; } if (isset($this->input["_followup"]['is_private'])) { $toadd["is_private"] = $this->input["_followup"]['is_private']; } $toadd['_no_notif'] = true; $fup->add($toadd); } if (isset($this->input["plan"]) || isset($this->input["_hour"]) && isset($this->input["_minute"]) && isset($this->input["realtime"]) && $this->input["realtime"] > 0) { $task = new TicketTask(); $type = "new"; if (isset($this->fields["status"]) && $this->fields["status"] == "solved") { $type = "solved"; } $toadd = array("type" => $type, "tickets_id" => $this->fields['id']); if (isset($this->input["_hour"])) { $toadd["hour"] = $this->input["_hour"]; } if (isset($this->input["_minute"])) { $toadd["minute"] = $this->input["_minute"]; } if (isset($this->input["plan"])) { $toadd["plan"] = $this->input["plan"]; } $toadd['_no_notif'] = true; $task->add($toadd); } $ticket_ticket = new Ticket_Ticket(); // From interface if (isset($this->input['_link'])) { $this->input['_link']['tickets_id_1'] = $this->fields['id']; if ($ticket_ticket->can(-1, 'w', $this->input['_link'])) { $ticket_ticket->add($this->input['_link']); } } // From mailcollector : do not check rights if (isset($this->input["_linkedto"])) { $input2['tickets_id_1'] = $this->fields['id']; $input2['tickets_id_2'] = $this->input["_linkedto"]; $input2['link'] = Ticket_Ticket::LINK_TO; $ticket_ticket->add($input2); } // Manage SLA Level : add actions if (isset($this->input["slas_id"]) && $this->input["slas_id"] > 0 && isset($this->input["slalevels_id"]) && $this->input["slalevels_id"] > 0) { $sla = new SLA(); if ($sla->getFromDB($this->input["slas_id"])) { // Add first level in working table if ($this->input["slalevels_id"] > 0) { $sla->addLevelToDo($this); } } } // Add user groups linked to tickets $ticket_user = new Ticket_User(); $group_ticket = new Group_Ticket(); if (isset($this->input["_users_id_requester"]) && ($this->input["_users_id_requester"] > 0 || isset($this->input["_users_id_requester_notif"]['alternative_email']) && !empty($this->input["_users_id_requester_notif"]['alternative_email']))) { $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_requester"], 'type' => self::REQUESTER); if (isset($this->input["_users_id_requester_notif"])) { foreach ($this->input["_users_id_requester_notif"] as $key => $val) { $input2[$key] = $val; } } $ticket_user->add($input2); } if (isset($this->input["_users_id_observer"]) && ($this->input["_users_id_observer"] > 0 || isset($this->input["_users_id_observer_notif"]['alternative_email']) && !empty($this->input["_users_id_observer_notif"]['alternative_email']))) { $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_observer"], 'type' => self::OBSERVER); if (isset($this->input["_users_id_observer_notif"])) { foreach ($this->input["_users_id_observer_notif"] as $key => $val) { $input2[$key] = $val; } } $ticket_user->add($input2); } if (isset($this->input["_users_id_assign"]) && $this->input["_users_id_assign"] > 0) { $input2 = array('tickets_id' => $this->fields['id'], 'users_id' => $this->input["_users_id_assign"], 'type' => self::ASSIGN); if (isset($this->input["_users_id_assign_notif"])) { foreach ($this->input["_users_id_assign_notif"] as $key => $val) { $input2[$key] = $val; } } $ticket_user->add($input2); } if (isset($this->input["_groups_id_requester"]) && $this->input["_groups_id_requester"] > 0) { $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_requester"], 'type' => self::REQUESTER)); } if (isset($this->input["_groups_id_assign"]) && $this->input["_groups_id_assign"] > 0) { $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_assign"], 'type' => self::ASSIGN)); } if (isset($this->input["_groups_id_observer"]) && $this->input["_groups_id_observer"] > 0) { $group_ticket->add(array('tickets_id' => $this->fields['id'], 'groups_id' => $this->input["_groups_id_observer"], 'type' => self::OBSERVER)); } // Additional actors : using default notification parameters // Observers : for mailcollector if (isset($this->input["_additional_observers"]) && is_array($this->input["_additional_observers"]) && count($this->input["_additional_observers"])) { $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::OBSERVER); foreach ($this->input["_additional_observers"] as $tmp) { if (isset($tmp['users_id'])) { foreach ($tmp as $key => $val) { $input2[$key] = $val; } $ticket_user->add($input2); } } } if (isset($this->input["_additional_assigns"]) && is_array($this->input["_additional_assigns"]) && count($this->input["_additional_assigns"])) { $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::ASSIGN); foreach ($this->input["_additional_assigns"] as $tmp) { if (isset($tmp['users_id'])) { foreach ($tmp as $key => $val) { $input2[$key] = $val; } $ticket_user->add($input2); } } } if (isset($this->input["_additional_requesters"]) && is_array($this->input["_additional_requesters"]) && count($this->input["_additional_requesters"])) { $input2 = array('tickets_id' => $this->fields['id'], 'type' => self::REQUESTER); foreach ($this->input["_additional_requesters"] as $tmp) { if (isset($tmp['users_id'])) { foreach ($tmp as $key => $val) { $input2[$key] = $val; } $ticket_user->add($input2); } } } //Action for send_validation rule if (isset($this->input["_add_validation"]) && $this->input["_add_validation"] > 0) { $validation = new Ticketvalidation(); $values['tickets_id'] = $this->fields['id']; $values['users_id_validate'] = $this->input["_add_validation"]; if ($validation->can(-1, 'w', $values)) { $validation->add($values); Event::log($this->fields['id'], "ticket", 4, "tracking", $_SESSION["glpiname"] . " " . $LANG['log'][21]); } } // Processing Email if ($CFG_GLPI["use_mailing"]) { // Clean reload of the ticket $this->getFromDB($this->fields['id']); $type = "new"; if (isset($this->fields["status"]) && $this->fields["status"] == "solved") { $type = "solved"; } NotificationEvent::raiseEvent($type, $this); } if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) { addMessageAfterRedirect($LANG['help'][18] . " (" . $LANG['job'][38] . " " . "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>)"); } }
if (isset($_POST['sla_delete'])) { $track->check($_POST["id"], 'w'); $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');
if (isset($_REQUEST['delete_link'])) { $ticket_ticket = new Ticket_Ticket(); $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']); } } }
/** * @see CommonDBTM::prepareInputForAdd() **/ function prepareInputForAdd($input) { // Avoid duplicate entry $restrict = " `tickets_id` = '" . $input['tickets_id'] . "'\n AND `itemtype` = '" . $input['itemtype'] . "'\n AND `items_id` = '" . $input['items_id'] . "'"; if (countElementsInTable($this->getTable(), $restrict) > 0) { return false; } $ticket = new Ticket(); $ticket->getFromDB($input['tickets_id']); // Get item location if location is not already set in ticket if (empty($ticket->fields['locations_id'])) { if ($input["items_id"] > 0 && !empty($input["itemtype"])) { if ($item = getItemForItemtype($input["itemtype"])) { if ($item->getFromDB($input["items_id"])) { if ($item->isField('locations_id')) { $ticket->fields['items_locations'] = $item->fields['locations_id']; // Process Business Rules $rules = new RuleTicketCollection($ticket->fields['entities_id']); $ticket->fields = $rules->processAllRules(Toolbox::stripslashes_deep($ticket->fields), Toolbox::stripslashes_deep($ticket->fields), array('recursive' => true)); unset($ticket->fields['items_locations']); $ticket->updateInDB(array('locations_id')); } } } } } $group = new Group_Ticket(); $groups = $group->find("`tickets_id` = " . $input['tickets_id'] . " AND `type` = " . CommonITILActor::REQUESTER); if (count($groups) <= 0) { if ($input["items_id"] > 0 && !empty($input["itemtype"])) { if ($item = getItemForItemtype($input["itemtype"])) { if ($item->getFromDB($input["items_id"])) { if ($item->isField('groups_id')) { $ticket->fields['items_groups'] = $item->fields['groups_id']; // Process Business Rules $rules = new RuleTicketCollection($ticket->fields['entities_id']); $ticket->fields = $rules->processAllRules(Toolbox::stripslashes_deep($ticket->fields), Toolbox::stripslashes_deep($ticket->fields), array('recursive' => true)); unset($ticket->fields['items_groups']); $group->add(array('tickets_id' => $input['tickets_id'], 'groups_id' => $item->fields['groups_id'], 'type' => CommonITILActor::REQUESTER)); } } } } } return parent::prepareInputForAdd($input); }
/** * 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()); }
/** * Save form datas to the target * * @param PluginFormcreatorFormanswer $formanswer Answers previously saved */ public function save(PluginFormcreatorFormanswer $formanswer) { $datas = array(); $ticket = new Ticket(); $docItem = new Document_Item(); $form = new PluginFormcreatorForm(); $form->getFromDB($formanswer->fields['plugin_formcreator_forms_id']); // Get default request type $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';"; $result = $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); list($requesttypes_id) = $GLOBALS['DB']->fetch_array($result); $datas['requesttypes_id'] = $requesttypes_id; // Get predefined Fields $ttp = new TicketTemplatePredefinedField(); $predefined_fields = $ttp->getPredefinedFields($this->fields['tickettemplates_id'], true); $datas = array_merge($datas, $predefined_fields); // Parse datas and tags $datas['name'] = addslashes($this->parseTags($this->fields['name'], $formanswer)); $datas['content'] = htmlentities($this->parseTags($this->fields['comment'], $formanswer)); $datas['entities_id'] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id']; $datas['_users_id_requester'] = 0; $datas['_users_id_recipient'] = $_SESSION['glpiID']; $datas['_tickettemplates_id'] = $this->fields['tickettemplates_id']; // Define due date $answer = new PluginFormcreatorAnswer(); $found = $answer->find('plugin_formcreator_formanwers_id = ' . (int) $formanswer->fields['id'] . ' AND plugin_formcreator_question_id = ' . (int) $this->fields['due_date_question']); $date = array_shift($found); $str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period']; switch ($this->fields['due_date_rule']) { case 'answer': $due_date = $date['answer']; break; case 'ticket': $due_date = date('Y-m-d H:i:s', strtotime($str)); break; case 'calcul': $due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str)); break; default: $due_date = null; break; } if (!is_null($due_date)) { $datas['due_date'] = $due_date; } // Select ticket actors $query = "SELECT id, actor_type, actor_value, use_notification\n FROM glpi_plugin_formcreator_targettickets_actors\n WHERE plugin_formcreator_targettickets_id = " . $this->getID() . "\n AND actor_role = 'requester'"; $result = $GLOBALS['DB']->query($query); // If there is only one requester add it on creation, otherwize we will add them later if ($GLOBALS['DB']->numrows($result) == 1) { $actor = $GLOBALS['DB']->fetch_array($result); switch ($actor['actor_type']) { case 'creator': $user_id = $formanswer->fields['requester_id']; break; case 'validator': $user_id = $formanswer->fields['validator_id']; break; case 'person': case 'group': case 'supplier': $user_id = $actor['actor_value']; break; case 'question_person': case 'question_group': case 'question_supplier': $answer = new PluginFormcreatorAnswer(); $found = $answer->find('`plugin_formcreator_question_id` = ' . (int) $actor['actor_value'] . ' AND `plugin_formcreator_formanwers_id` = ' . (int) $formanswer->fields['id']); $found = array_shift($found); if (empty($found['answer'])) { continue; } else { $user_id = (int) $found['answer']; } break; } $datas['_users_id_requester'] = $user_id; } // Create the target ticket if (!($ticketID = $ticket->add($datas))) { return false; } // Add link between Ticket and FormAnswer $itemlink = new Item_Ticket(); $itemlink->add(array('itemtype' => 'PluginFormcreatorFormanswer', 'items_id' => $formanswer->fields['id'], 'tickets_id' => $ticketID)); // Add actors to ticket $query = "SELECT id, actor_role, actor_type, actor_value, use_notification\n FROM glpi_plugin_formcreator_targettickets_actors\n WHERE plugin_formcreator_targettickets_id = " . $this->getID(); $result = $GLOBALS['DB']->query($query); while ($actor = $GLOBALS['DB']->fetch_array($result)) { // If actor type is validator and if the form doesn't have a validator, continue to other actors if ($actor['actor_type'] == 'validator' && !$form->fields['validation_required']) { continue; } switch ($actor['actor_role']) { case 'requester': $role = CommonITILActor::REQUESTER; break; case 'observer': $role = CommonITILActor::OBSERVER; break; case 'assigned': $role = CommonITILActor::ASSIGN; break; } switch ($actor['actor_type']) { case 'creator': $user_id = $formanswer->fields['requester_id']; break; case 'validator': $user_id = $formanswer->fields['validator_id']; break; case 'person': case 'group': case 'supplier': $user_id = $actor['actor_value']; break; case 'question_person': case 'question_group': case 'question_supplier': $answer = new PluginFormcreatorAnswer(); $found = $answer->find('`plugin_formcreator_question_id` = ' . (int) $actor['actor_value'] . ' AND `plugin_formcreator_formanwers_id` = ' . (int) $formanswer->fields['id']); $found = array_shift($found); if (empty($found['answer'])) { continue; } else { $user_id = (int) $found['answer']; } break; } switch ($actor['actor_type']) { case 'creator': case 'validator': case 'person': case 'question_person': $obj = new Ticket_User(); $obj->add(array('tickets_id' => $ticketID, 'users_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification'])); break; case 'group': case 'question_group': $obj = new Group_Ticket(); $obj->add(array('tickets_id' => $ticketID, 'groups_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification'])); break; case 'supplier': case 'question_supplier': $obj = new Supplier_Ticket(); $obj->add(array('tickets_id' => $ticketID, 'suppliers_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification'])); break; } } // Attach documents to ticket $found = $docItem->find("itemtype = 'PluginFormcreatorFormanswer' AND items_id = " . (int) $formanswer->getID()); if (count($found) > 0) { foreach ($found as $document) { $docItem->add(array('documents_id' => $document['documents_id'], 'itemtype' => 'Ticket', 'items_id' => $ticketID)); } } // Attach validation message as first ticket followup if validation is required and // if is set in ticket target configuration // /!\ Followup is directly saved to the database to avoid double notification on ticket // creation and add followup if ($form->fields['validation_required'] && $this->fields['validation_followup']) { $message = addslashes(__('Your form have been accepted by the validator', 'formcreator')); if (!empty($formanswer->fields['comment'])) { $message .= "\n" . addslashes($formanswer->fields['comment']); } $query = "INSERT INTO `glpi_ticketfollowups` SET\n `tickets_id` = {$ticketID},\n `date` = NOW(),\n `users_id` = {$_SESSION['glpiID']},\n `content` = \"{$message}\""; $GLOBALS['DB']->query($query); } return true; }
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; }
$input['_disablenotif'] = true; $ticket->update($input); // Check if user assigned is in this new group $ticket_user = new Ticket_User(); $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();
/** * On ticket category change, add ticket category group and user * @param CommonDBTM $item * @return nothing */ static function qualification(CommonDBTM $item) { global $DB; //get auto-assign mode (config in entity) $auto_assign_mode = Entity::getUsedConfig('auto_assign_mode', $_SESSION['glpiactive_entity']); if ($auto_assign_mode == Entity::CONFIG_NEVER) { return true; } //get category $category = new ITILCategory(); $category->getFromDB($item->input['itilcategories_id']); //category group if (!empty($category->fields['groups_id']) && $_SESSION['plugins']['escalade']['config']['reassign_group_from_cat']) { $group_ticket = new Group_Ticket(); //check if group is not already present $group_found = $group_ticket->find("tickets_id = '" . $item->fields['id'] . "' AND groups_id = '" . $category->fields['groups_id'] . "' AND type = 2"); if (empty($group_found)) { //add group to ticket $group_ticket->add(array('tickets_id' => $item->fields['id'], 'groups_id' => $category->fields['groups_id'], 'type' => CommonITILActor::ASSIGN)); } } //category user if (!empty($category->fields['users_id']) && $_SESSION['plugins']['escalade']['config']['reassign_tech_from_cat']) { $ticket_user = new Ticket_User(); //check if user is not already present $user_found = $ticket_user->find("tickets_id = '" . $item->fields['id'] . "' AND users_id = '" . $category->fields['users_id'] . "' AND type = 2"); if (empty($user_found)) { //add user to ticket $ticket_user->add(array('tickets_id' => $item->fields['id'], 'users_id' => $category->fields['users_id'], 'type' => CommonITILActor::ASSIGN)); } } }
/** * * @param type $items_id id of the ticket */ static function createSubTicket($items_id) { global $CFG_GLPI; if ($_POST['slas_id'] == 0 || $_POST['groupsubticket'] == 0) { // return; } $ticket = new Ticket(); $ticketFollowup = new TicketFollowup(); $ticketTask = new TicketTask(); $document_Item = new Document_Item(); $ticket_User = new Ticket_User(); $group_Ticket = new Group_Ticket(); // Disable send notification $use_mailing = $CFG_GLPI["use_mailing"]; $CFG_GLPI["use_mailing"] = false; $ticket->getFromDB($items_id); unset($ticket->fields['id']); $ticket->fields['_link']['link'] = 1; $ticket->fields['_link']['tickets_id_1'] = 0; $ticket->fields['_link']['tickets_id_2'] = $items_id; $ticket->fields['bypassgrouponadd'] = true; $ticket->fields['slas_id'] = $_POST['slas_id']; $ticket->fields['date'] = date("Y-m-d H:i:s"); $ticket->fields = Toolbox::addslashes_deep($ticket->fields); foreach ($ticket->fields as $key => $value) { if ($value == '') { unset($ticket->fields[$key]); } } $new_tickets_id = $ticket->add($ticket->fields); $a_followups = $ticketFollowup->find("`tickets_id`='" . $items_id . "'", "`id`"); foreach ($a_followups as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; $ticketFollowup->add($data); } $a_tasks = $ticketTask->find("`tickets_id`='" . $items_id . "'", "`id`"); foreach ($a_tasks as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; foreach ($data as $key => $value) { if ($value == '') { unset($data[$key]); } } $ticketTask->add($data); } $a_documents = $document_Item->find("`items_id`='" . $items_id . "'\n AND `itemtype`='Ticket'", "`id`"); foreach ($a_documents as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['items_id'] = $new_tickets_id; $document_Item->add($data); } $a_ticketusers = $ticket_User->find("`tickets_id`='" . $items_id . "'\n AND `type`='1'", "`id`"); foreach ($a_ticketusers as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; $ticket_User->add($data); } $a_ticketgroups = $group_Ticket->find("`tickets_id`='" . $items_id . "'\n AND `type`='1'", "`id`"); foreach ($a_ticketgroups as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; $group_Ticket->add($data); } $CFG_GLPI["use_mailing"] = $use_mailing; $input = array(); $input['tickets_id'] = $new_tickets_id; $input['groups_id'] = $_POST['groupsubticket']; $input['type'] = 2; $group_Ticket->add($input); }
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); } } } } } } } }
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; }