Exemplo n.º 1
1
 /**
  * Do a specific SLAlevel for a ticket
  *
  * @param $data array data of an entry of slalevels_tickets
  *
  * @return nothing
  **/
 static function doLevelForTicket(array $data)
 {
     $ticket = new Ticket();
     $slalevelticket = new self();
     // existing ticket and not deleted
     if ($ticket->getFromDB($data['tickets_id']) && !$ticket->isDeleted()) {
         $slalevel = new SlaLevel();
         $sla = new SLA();
         // Check if sla datas are OK
         if ($ticket->fields['slas_id'] > 0 && $ticket->fields['slalevels_id'] == $data['slalevels_id']) {
             if ($ticket->fields['status'] == CommonITILObject::CLOSED) {
                 // Drop line when status is closed
                 $slalevelticket->delete(array('id' => $data['id']));
             } else {
                 if ($ticket->fields['status'] != CommonITILObject::SOLVED) {
                     // If status = solved : keep the line in case of solution not validated
                     $input['id'] = $ticket->getID();
                     $input['_auto_update'] = true;
                     if ($slalevel->getRuleWithCriteriasAndActions($data['slalevels_id'], 1, 1) && $sla->getFromDB($ticket->fields['slas_id'])) {
                         $doit = true;
                         if (count($slalevel->criterias)) {
                             $doit = $slalevel->checkCriterias($ticket->fields);
                         }
                         // Process rules
                         if ($doit) {
                             $input = $slalevel->executeActions($input, array());
                         }
                     }
                     // Put next level in todo list
                     $next = $slalevel->getNextSlaLevel($ticket->fields['slas_id'], $ticket->fields['slalevels_id']);
                     $input['slalevels_id'] = $next;
                     $ticket->update($input);
                     $sla->addLevelToDo($ticket);
                     // Action done : drop the line
                     $slalevelticket->delete(array('id' => $data['id']));
                 }
             }
         } else {
             // Drop line
             $slalevelticket->delete(array('id' => $data['id']));
         }
     } else {
         // Drop line
         $slalevelticket->delete(array('id' => $data['id']));
     }
 }
 function post_addItem()
 {
     if ($this->fields['itemtype'] == 'Ticket') {
         $ticket = new Ticket();
         $ticket->update(array('id' => $this->fields['items_id'], 'date_mod' => $_SESSION["glpi_currenttime"], '_forcenotif' => true, '_donotadddocs' => true));
     }
     parent::post_addItem();
 }
 function post_purgeItem()
 {
     $ticket = new Ticket();
     $input = array('id' => $this->fields['tickets_id'], 'date_mod' => $_SESSION["glpi_currenttime"], '_donotadddocs' => true);
     if (!isset($this->input['_do_notif']) || $this->input['_do_notif']) {
         $input['_forcenotif'] = true;
     }
     $ticket->update($input);
     parent::post_purgeItem();
 }
 function post_deleteFromDB()
 {
     global $CFG_GLPI;
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
         $donotif = false;
     }
     $t = new Ticket();
     if ($t->getFromDB($this->fields['tickets_id'])) {
         if ($t->fields["suppliers_id_assign"] == 0 && $t->countUsers(Ticket::ASSIGN) == 0 && $t->countGroups(Ticket::ASSIGN) == 0) {
             $t->update(array('id' => $this->fields['tickets_id'], 'status' => 'new'));
         } else {
             $t->updateDateMod($this->fields['tickets_id']);
             if ($donotif) {
                 NotificationEvent::raiseEvent("update", $t);
             }
         }
     }
     parent::post_deleteFromDB();
 }
    $ttask = new TicketTask();
    if (isset($_POST["add"])) {
        $ttask->check(-1, 'w', $_POST);
        $ttask->add($_POST);
        Event::log($ttask->getField('tickets_id'), "ticket", 4, "tracking", sprintf(__('%s adds a task'), $_SESSION["glpiname"]));
    }
}
//add document
if (isset($_REQUEST['filename']) && !empty($_REQUEST['filename'])) {
    $doc = new Document();
    if (isset($_POST["add"])) {
        $doc->check(-1, 'w', $_POST);
        if ($newID = $doc->add($_POST)) {
            Event::log($newID, "documents", 4, "login", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $doc->fields["name"]));
        }
    }
}
//change ticket status
if (isset($_REQUEST['status']) && !empty($_REQUEST['status'])) {
    $ticket = new Ticket();
    $ticket->update(array('id' => intval($_REQUEST['tickets_id']), 'status' => intval($_REQUEST['status'])));
}
//delete document
if (isset($_REQUEST['delete_document'])) {
    $document_item = new Document_Item();
    $found_document_items = $document_item->find("itemtype = 'Ticket' " . " AND items_id = " . intval($_REQUEST['tickets_id']) . " AND documents_id = " . intval($_REQUEST['documents_id']));
    foreach ($found_document_items as $item) {
        $document_item->delete($item, true);
    }
}
Html::back();
Exemplo n.º 6
0
 /**
  * Delete all tickets for an itemtype
  * @param the itemtype
  * @return nothing
  */
 public static function deleteTicketAssignation($itemtype)
 {
     global $DB;
     $ticket = new Ticket();
     foreach ($ticket->find("`itemtype`='{$itemtype}'") as $data) {
         $data['itemtype'] = '';
         $data['items_id'] = 0;
         $ticket->update($data);
     }
 }
Exemplo n.º 7
0
 /**
  * updates the ticket's status & priority.
  * A log entry about this will be created only if the newStatus is different from the current status and also when the newPriority is different from the current priority.
  * @todo break this function up into a updateStatus (already exists) and updatePriority function and perhaps write a wrapper function for the combo.
  * @param $ticket_id the id of the ticket of which we want to change the status & priority
  * @param $newStatus the new status value (integer)
  * @param $newPriority the new priority value (integer)
  * @param $author the user (id) that performed the update
  */
 public static function updateTicketStatusAndPriority($ticket_id, $newStatus, $newPriority, $author)
 {
     $ticket = new Ticket();
     $ticket->load_With_TId($ticket_id);
     if ($ticket->getStatus() != $newStatus) {
         $ticket->setStatus($newStatus);
         Ticket_Log::createLogEntry($ticket_id, $author, 5, $newStatus);
     }
     if ($ticket->getPriority() != $newPriority) {
         $ticket->setPriority($newPriority);
         Ticket_Log::createLogEntry($ticket_id, $author, 6, $newPriority);
     }
     $ticket->update();
 }
 /**
  * 
  * Update Ticket into Database
  * @param	array 		$aryTicket		Ticket object	
  */
 private function UpdateTicket($aryTicket)
 {
     global $db, $conf;
     $function = "UpdateTicket";
     $idTicket = -1;
     $data = $aryTicket['data'];
     $lines = $data['lines'];
     $idTicket = $data['id'];
     $statut = 0;
     if (!$data['customerId']) {
         $cash = new Cash($db);
         $terminal = $_SESSION['TERMINAL_ID'];
         $cash->fetch($terminal);
         $socid = $cash->fk_soc;
     } else {
         $socid = $data['customerId'];
     }
     if (!$data['employeeId']) {
         $employee = $_SESSION['uid'];
     } else {
         $employee = $data['employeeId'];
     }
     $object = new Ticket($db);
     $object->fetch($idTicket);
     $object->type = $data['type'];
     $object->socid = $socid;
     $object->statut = $data['state'];
     $object->fk_cash = $_SESSION['TERMINAL_ID'];
     $object->remise_percent = $data['discount_percent'];
     $object->remise_absolut = $data['discount_qty'];
     $object->mode_reglement_id = $data['payment_type'];
     $object->fk_place = $data['id_place'];
     $object->note = $data['note'];
     $cash = new Cash($db);
     $cash->fetch($_SESSION['TERMINAL_ID']);
     if ($data['payment_type'] != $cash->fk_modepaycash) {
         if ($data['points'] > 0) {
             $object->customer_pay = $data['total_with_points'];
         } else {
             $object->customer_pay = $data['total'];
         }
     } else {
         $object->customer_pay = $data['customerpay'];
     }
     $data['customerpay'] = $object->customer_pay;
     $object->diff_payment = $data['difpayment'];
     $object->id_source = $data['idsource'];
     $userstatic = new User($db);
     $userstatic->fetch($employee);
     $db->begin;
     $res = $object->update($userstatic->id);
     $data['ref'] = $object->ref;
     if ($res < 0) {
         $db->rollback();
         return -5;
     } else {
         //Adding lines
         $idLines = self::addTicketLines($lines, $idTicket);
         if ($idLines < 0) {
             $db->rollback();
             return -2;
         } else {
             $place = new Place($db);
             $place->fetch($object->fk_place);
             if ($object->statut != 0) {
                 //Adding Payments
                 $payment = self::addPayment($data);
                 if (!$payment) {
                     $db->rollback();
                     return -3;
                 } else {
                     if ($object->diff_payment <= 0) {
                         $object->set_paid($user);
                     }
                 }
                 //Decrease stock
                 $stock = self::quitSotck($lines);
                 if ($stock) {
                     $db->rollback();
                     return -4;
                 }
                 // liberar puesto
                 $place->free_place();
             } else {
                 // usar puesto
                 $place->set_place($idTicket);
             }
         }
     }
     $db->commit;
     return $idTicket;
 }
 function post_addItem()
 {
     global $LANG, $CFG_GLPI;
     $job = new Ticket();
     $mailsend = false;
     if ($job->getFromDB($this->fields["tickets_id"])) {
         // Set global validation to waiting
         if ($job->fields['global_validation'] == 'accepted' || $job->fields['global_validation'] == 'none') {
             $input['id'] = $this->fields["tickets_id"];
             $input['global_validation'] = 'waiting';
             // to fix lastupdater
             if (isset($this->input['_auto_update'])) {
                 $input['_auto_update'] = $this->input['_auto_update'];
             }
             $job->update($input);
         }
         if ($CFG_GLPI["use_mailing"]) {
             $options = array('validation_id' => $this->fields["id"], 'validation_status' => $this->fields["status"]);
             $mailsend = NotificationEvent::raiseEvent('validation', $job, $options);
         }
         if ($mailsend) {
             $user = new User();
             $user->getFromDB($this->fields["users_id_validate"]);
             if (!empty($user->fields["email"])) {
                 addMessageAfterRedirect($LANG['validation'][13] . " " . $user->getName());
             } else {
                 addMessageAfterRedirect($LANG['validation'][23], false, ERROR);
             }
         }
         // Add log entry in the ticket
         $changes[0] = 0;
         $changes[1] = '';
         $changes[2] = addslashes($LANG['validation'][13] . " " . getUserName($this->fields["users_id_validate"]));
         Log::history($this->getField('tickets_id'), 'Ticket', $changes, $this->getType(), HISTORY_LOG_SIMPLE_MESSAGE);
     }
 }
Exemplo n.º 10
0
 public static function changeTicketDetails($id, $title, $text, $location, $solution, $reference, $handle_id)
 {
     $ticket = new Ticket(array('id' => $id, 'title' => $title, 'text' => $text, 'location' => $location, 'solution' => $solution, 'reference' => $reference, 'handle_id' => $handle_id));
     $ticket->update();
 }
Exemplo n.º 11
0
    if ($th->status_from != $th->status_to) {
        $changed = true;
    }
    if ($th->milestone_from_id != $th->milestone_to_id) {
        $changed = true;
    }
    if (strlen($th->comment) > 0) {
        $changed = true;
    }
    if ($changed) {
        $ticket->assigned_to = $th->user_to;
        $ticket->milestone_id = $th->milestone_to_id;
        $ticket->status = $th->status_to;
        $ticket->dt_last_state = dater();
        $th->insert();
        $ticket->update();
        redirect('/ticket/' . $ticket->id . '/');
    }
} else {
    $tags = '';
}
include 'inc/header.inc.php';
?>

        <div id="bd">
            <div id="yui-main">
                <div class="yui-b"><div class="yui-g">

                    <div class="block tabs spaces">
                        <div class="hd">
                            <h2><?php 
Exemplo n.º 12
0
 public function post_receive()
 {
     if (empty($_POST['payload'])) {
         exit("Empty payload.");
     }
     $json = json_decode($_POST['payload']);
     # Handle special keywords that stand for models.
     $targets = array("milestone" => array("Milestone", "name"), "owner" => array("User", "login"), "user" => array("User", "login"));
     foreach ($json->commits as $commit) {
         if (!preg_match("/\\[#[0-9]+(\\s[^\\]]+)?\\]/", $commit->message)) {
             continue;
         }
         $user = new User(array("email" => $commit->author->email));
         $message = "Updated in commit [" . substr($commit->id, 0, 8) . "](" . $commit->url . "):\n\n" . $commit->message;
         preg_match_all("/\\[#([0-9]+)\\s?([^\\]]*)\\]/", $commit->message, $updates, PREG_SET_ORDER);
         foreach ($updates as $update) {
             $ticket = new Ticket($update[1], array("filter" => false));
             if ($ticket->no_results) {
                 continue;
             }
             preg_match_all("/([a-zA-Z]+):(\"([^\"]+)\"|([^ ]+))/", $update[2], $changes, PREG_SET_ORDER);
             $revchanges = array();
             foreach ($changes as $change) {
                 $attribute = $change[1];
                 $value = oneof($change[3], $change[4]);
                 if (!in_array($attribute, array("title", "description", "state", "milestone", "owner", "user"))) {
                     continue;
                 }
                 foreach ($targets as $name => $target) {
                     if ($attribute == $name) {
                         $model = $target[0];
                         if (is_numeric($value)) {
                             $value = new $model($value);
                         } else {
                             $value = new $model(array($target[1] => $value));
                         }
                     }
                 }
                 $revchanges[$attribute] = $value;
             }
             $fromto = array();
             foreach ($revchanges as $attr => $val) {
                 $old = @$ticket->{$attr};
                 $new = $val;
                 foreach ($targets as $name => $target) {
                     if ($attr == $name) {
                         $old = $ticket->{$name}->{$target}[1];
                         $new = $val->{$target}[1];
                     }
                 }
                 $fromto[$attr] = array("from" => $old, "to" => $new);
             }
             $ticket->update(@$revchanges["title"], @$revchanges["description"], @$revchanges["state"], @$revchanges["milestone"], @$revchanges["owner"], @$revchanges["user"]);
             Revision::add($message, $fromto, $ticket, $user);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Clean data in the tables which have linked the deleted item
  * Clear 1/N Relation
  *
  * @return nothing
  **/
 function cleanRelationData()
 {
     global $DB, $CFG_GLPI;
     $RELATION = getDbRelations();
     if (isset($RELATION[$this->getTable()])) {
         $newval = isset($this->input['_replace_by']) ? $this->input['_replace_by'] : 0;
         foreach ($RELATION[$this->getTable()] as $tablename => $field) {
             if ($tablename[0] != '_') {
                 $itemtype = getItemTypeForTable($tablename);
                 // Code factorization : we transform the singleton to an array
                 if (!is_array($field)) {
                     $field = array($field);
                 }
                 foreach ($field as $f) {
                     foreach ($DB->request($tablename, array($f => $this->getID())) as $data) {
                         // Be carefull : we must use getIndexName because self::update rely on that !
                         if ($object = getItemForItemtype($itemtype)) {
                             $idName = $object->getIndexName();
                             // And we must ensure that the index name is not the same as the field
                             // we try to modify. Otherwise we will loose this element because all
                             // will be set to $newval ...
                             if ($idName != $f) {
                                 $object->update(array($idName => $data[$idName], $f => $newval, '_disablenotif' => true));
                                 // Disable notifs
                             }
                         }
                     }
                 }
             }
         }
     }
     // Clean ticket open against the item
     if (in_array($this->getType(), $CFG_GLPI["ticket_types"])) {
         $job = new Ticket();
         $query = "SELECT *\n                   FROM `glpi_tickets`\n                   WHERE `items_id` = '" . $this->fields['id'] . "'\n                         AND `itemtype`='" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result)) {
             while ($data = $DB->fetch_assoc($result)) {
                 if ($CFG_GLPI["keep_tickets_on_delete"] == 1) {
                     $input = array();
                     $input['id'] = $data["id"];
                     $input['items_id'] = 0;
                     $input['itemtype'] = '';
                     if ($data['status'] == 'closed') {
                         $input['_disablenotif'] = true;
                     }
                     $job->update($input);
                 } else {
                     $job->delete(array("id" => $data["id"]));
                 }
             }
         }
     }
 }
Exemplo 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);
                 }
             }
         }
     }
 }
Exemplo n.º 15
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);
                 }
             }
         }
     }
 }
Exemplo n.º 16
0
 static function updateTicketFromForm($idform, $idticket)
 {
     global $DB;
     $datas = array();
     $templates_id = PluginFormcreatorForm::getTemplateTicketFromForm($idform);
     $ttp = new TicketTemplatePredefinedField();
     $predefined_fields = $ttp->getPredefinedFields($templates_id, true);
     $Ticket = new Ticket();
     $listaObjetos = $Ticket->find("id = '{$idticket}'");
     //$listaobjetos es un array que contiene, por cada ticket que comple la condición del find, un array con los campos del ticket
     $clave = array_keys($listaObjetos);
     if (isset($clave[0])) {
         if (isset($listaObjetos[$clave[0]])) {
             $datas = $listaObjetos[$clave[0]];
             unset($datas['urgency']);
             //
             unset($datas['priority']);
             //
             unset($datas['type']);
             //
             unset($datas['itilcategories_id']);
             //
             unset($datas['slas_id']);
             //
             $datas = array_merge($datas, $predefined_fields);
             $Ticket->update($datas);
         }
     }
 }
Exemplo n.º 17
0
 function post_addItem()
 {
     global $CFG_GLPI;
     if (isset($this->input['_planningrecall'])) {
         $this->input['_planningrecall']['items_id'] = $this->fields['id'];
         PlanningRecall::manageDatas($this->input['_planningrecall']);
     }
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->fields["begin"]) && !empty($this->fields["begin"])) {
         Planning::checkAlreadyPlanned($this->fields["users_id_tech"], $this->fields["begin"], $this->fields["end"], array($this->getType() => array($this->fields["id"])));
         $calendars_id = Entity::getUsedConfig('calendars_id', $this->input["_job"]->fields['entities_id']);
         $calendar = new Calendar();
         // Using calendar
         if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
             if (!$calendar->isAWorkingHour(strtotime($this->fields["begin"]))) {
                 Session::addMessageAfterRedirect(__('Start of the selected timeframe is not a working hour.'), false, ERROR);
             }
             if (!$calendar->isAWorkingHour(strtotime($this->fields["end"]))) {
                 Session::addMessageAfterRedirect(__('End of the selected timeframe is not a working hour.'), false, ERROR);
             }
         }
     }
     //       if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
     //          $donotif = false;
     //       }
     $this->input["_job"]->updateDateMod($this->input[$this->input["_job"]->getForeignKeyField()]);
     if (isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $this->input["_job"]->updateActionTime($this->input[$this->input["_job"]->getForeignKeyField()]);
     }
     //change ticket status
     if (isset($_REQUEST['_status']) && !empty($_REQUEST['_status'])) {
         $ticket = new Ticket();
         $ticket->update(array('id' => intval($_REQUEST['tickets_id']), 'status' => intval($_REQUEST['_status'])));
     }
     if (!empty($this->fields['begin']) && $this->input["_job"]->isStatusExists(CommonITILObject::PLANNED) && ($this->input["_job"]->fields["status"] == CommonITILObject::INCOMING || $this->input["_job"]->fields["status"] == CommonITILObject::ASSIGNED)) {
         $input2['id'] = $this->input["_job"]->getID();
         $input2['status'] = CommonITILObject::PLANNED;
         $input2['_disablenotif'] = true;
         $this->input["_job"]->update($input2);
     }
     if ($donotif) {
         $options = array('task_id' => $this->fields["id"], 'is_private' => $this->isPrivate());
         NotificationEvent::raiseEvent('add_task', $this->input["_job"], $options);
     }
     // Add log entry in the ITIL object
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField($this->input["_job"]->getForeignKeyField()), $this->input["_job"]->getTYpe(), $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
 }
Exemplo n.º 18
0
 /**
  * Clean data in the tables which have linked the deleted item
  * Clear 1/N Relation
  *
  * @return nothing
  **/
 function cleanRelationData()
 {
     global $DB, $CFG_GLPI;
     $RELATION = getDbRelations();
     if (isset($RELATION[$this->getTable()])) {
         $newval = isset($this->input['_replace_by']) ? $this->input['_replace_by'] : 0;
         foreach ($RELATION[$this->getTable()] as $tablename => $field) {
             if ($tablename[0] != '_') {
                 if (!is_array($field)) {
                     $query = "UPDATE `{$tablename}`\n                            SET `{$field}` = '{$newval}'\n                            WHERE `{$field}` = '" . $this->fields['id'] . "'";
                     $DB->query($query);
                 } else {
                     foreach ($field as $f) {
                         $query = "UPDATE `{$tablename}`\n                               SET `{$f}` = '{$newval}'\n                               WHERE `{$f}` = '" . $this->fields['id'] . "'";
                         $DB->query($query);
                     }
                 }
             }
         }
     }
     // Clean ticket open against the item
     if (in_array($this->getType(), $CFG_GLPI["ticket_types"])) {
         $job = new Ticket();
         $query = "SELECT *\n                   FROM `glpi_tickets`\n                   WHERE `items_id` = '" . $this->fields['id'] . "'\n                         AND `itemtype`='" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result)) {
             while ($data = $DB->fetch_array($result)) {
                 if ($CFG_GLPI["keep_tickets_on_delete"] == 1) {
                     $job->update(array('id' => $data["id"], 'items_id' => 0, 'itemtype' => ''));
                 } else {
                     $job->delete(array("id" => $data["id"]));
                 }
             }
         }
     }
 }
Exemplo n.º 19
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'add_task':
             if (!($task = getItemForItemtype('TicketTask'))) {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 break;
             }
             $ticket = new Ticket();
             $field = $ticket->getForeignKeyField();
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($item->can($id, READ)) {
                     if ($ticket->getFromDB($item->fields['tickets_id'])) {
                         $input2 = array($field => $item->fields['tickets_id'], 'taskcategories_id' => $input['taskcategories_id'], 'actiontime' => $input['actiontime'], 'content' => $input['content']);
                         if ($task->can(-1, CREATE, $input2)) {
                             if ($task->add($input2)) {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             }
             return;
         case 'solveticket':
             $input = $ma->getInput();
             $ticket = new Ticket();
             foreach ($ids as $id) {
                 if ($item->can($id, READ)) {
                     if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) {
                         $toupdate = array();
                         $toupdate['id'] = $ticket->getID();
                         $toupdate['solutiontypes_id'] = $input['solutiontypes_id'];
                         $toupdate['solution'] = $input['solution'];
                         if ($ticket->update($toupdate)) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 static function postAddCloseTicket($item)
 {
     if (!is_array($item->input) || !count($item->input)) {
         // Already cancel by another plugin
         return false;
     }
     $ticket = new Ticket();
     if (isset($_POST['solution'])) {
         $item->input['solution'] = str_replace(array('\\r\\n', '\\r', '\\n'), '', $_POST['solution']);
     }
     // Get allowed status
     $config = new PluginMoreticketConfig();
     $solution_status = array_keys(json_decode($config->solutionStatus(), true));
     if (isset($item->input['id'])) {
         if (isset($item->input['status']) && isset($_POST['solutiontypes_id']) && isset($_POST['solution']) && in_array($item->input['status'], $solution_status)) {
             if (self::checkMandatory($_POST)) {
                 // Then we add tickets informations
                 $ticket->update(array('id' => $item->input['id'], 'solutiontypes_id' => $_POST['solutiontypes_id'], 'solution' => $_POST['solution']));
                 unset($_SESSION['glpi_plugin_moreticket_close']);
             } else {
                 //$item->input = array();
                 $_SESSION['saveInput'][$item->getType()] = $item->input;
                 $item->input = array();
             }
         }
     }
     return true;
 }
Exemplo n.º 21
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'solveticket':
             $input = $ma->getInput();
             $ticket = new Ticket();
             foreach ($ids as $id) {
                 if ($item->can($id, READ)) {
                     if ($ticket->getFromDB($item->fields['tickets_id']) && $ticket->canSolve()) {
                         $toupdate = array();
                         $toupdate['id'] = $ticket->getID();
                         $toupdate['solutiontypes_id'] = $input['solutiontypes_id'];
                         $toupdate['solution'] = $input['solution'];
                         if ($ticket->update($toupdate)) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($ticket->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($ticket->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Exemplo n.º 22
0
             }
         }
     }
     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();
             }
         }
Exemplo n.º 23
0
 /**
  * Do a specific SLAlevel for a ticket
  *
  * @param $data array data of an entry of slalevels_tickets
  *
  * @return nothing
  **/
 static function doLevelForTicket(array $data)
 {
     $ticket = new Ticket();
     $slalevelticket = new self();
     // existing ticket and not deleted
     if ($ticket->getFromDB($data['tickets_id']) && !$ticket->isDeleted()) {
         // search all actors of a ticket
         foreach ($ticket->getUsers(CommonITILActor::REQUESTER) as $user) {
             $ticket->fields['_users_id_requester'][] = $user['users_id'];
         }
         foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $user) {
             $ticket->fields['_users_id_assign'][] = $user['users_id'];
         }
         foreach ($ticket->getUsers(CommonITILActor::OBSERVER) as $user) {
             $ticket->fields['_users_id_observer'][] = $user['users_id'];
         }
         foreach ($ticket->getGroups(CommonITILActor::REQUESTER) as $group) {
             $ticket->fields['_groups_id_requester'][] = $group['groups_id'];
         }
         foreach ($ticket->getGroups(CommonITILActor::ASSIGN) as $group) {
             $ticket->fields['_groups_id_assign'][] = $group['groups_id'];
         }
         foreach ($ticket->getGroups(CommonITILActor::OBSERVER) as $groups) {
             $ticket->fields['_groups_id_observer'][] = $group['groups_id'];
         }
         foreach ($ticket->getSuppliers(CommonITILActor::ASSIGN) as $supplier) {
             $ticket->fields['_suppliers_id_assign'][] = $supplier['suppliers_id'];
         }
         $slalevel = new SlaLevel();
         $sla = new SLA();
         // Check if sla datas are OK
         if ($ticket->fields['slas_id'] > 0 && $ticket->fields['slalevels_id'] == $data['slalevels_id']) {
             if ($ticket->fields['status'] == CommonITILObject::CLOSED) {
                 // Drop line when status is closed
                 $slalevelticket->delete(array('id' => $data['id']));
             } else {
                 if ($ticket->fields['status'] != CommonITILObject::SOLVED) {
                     // If status = solved : keep the line in case of solution not validated
                     $input['id'] = $ticket->getID();
                     $input['_auto_update'] = true;
                     if ($slalevel->getRuleWithCriteriasAndActions($data['slalevels_id'], 1, 1) && $sla->getFromDB($ticket->fields['slas_id'])) {
                         $doit = true;
                         if (count($slalevel->criterias)) {
                             $doit = $slalevel->checkCriterias($ticket->fields);
                         }
                         // Process rules
                         if ($doit) {
                             $input = $slalevel->executeActions($input, array());
                         }
                     }
                     // Put next level in todo list
                     $next = $slalevel->getNextSlaLevel($ticket->fields['slas_id'], $ticket->fields['slalevels_id']);
                     $input['slalevels_id'] = $next;
                     $ticket->update($input);
                     $sla->addLevelToDo($ticket);
                     // Action done : drop the line
                     $slalevelticket->delete(array('id' => $data['id']));
                 }
             }
         } else {
             // Drop line
             $slalevelticket->delete(array('id' => $data['id']));
         }
     } else {
         // Drop line
         $slalevelticket->delete(array('id' => $data['id']));
     }
 }
Exemplo n.º 24
0
 /**
  * Solution of 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 methodsetTicketSolution($params, $protocol)
 {
     global $DB, $CFG_GLPI;
     if (isset($params['help'])) {
         return array('ticket' => 'integer,mandatory', 'id2name' => 'bool,optional', 'type' => 'integer,optional', 'solution' => 'text,mandatory', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     $ticket = new Ticket();
     if (!isset($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'ticket');
     }
     if (!isset($params['solution'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'solution');
     }
     if (isset($params['type']) && !is_numeric($params['type'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'type=' . $params['type']);
     }
     if (!$ticket->can($params['ticket'], 'r')) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, '', 'ticket');
     }
     if (!$ticket->getFromDB($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, '', 'solution');
     }
     $input = array('id' => $ticket->getField('id'), 'solution' => addslashes(Toolbox::clean_cross_side_scripting_deep($params['solution'])), 'status' => Ticket::SOLVED);
     if (isset($params['type'])) {
         $input['solutiontypes_id'] = $params['type'];
     }
     if (!$ticket->canSolve($params['ticket'], 'w')) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     if ($ticket->update($input)) {
         unset($params['solution'], $params['type']);
         return self::methodGetTicket($params, $protocol);
     }
     return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
 }
Exemplo n.º 25
0
$track = new Ticket();
if (!isset($_GET['id'])) {
    $_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)) {
Exemplo n.º 26
0
 /**
  * @since version 0.83
  *
  * @see CommonDBTM::post_purgeItem()
  **/
 function post_purgeItem()
 {
     if ($this->fields['itemtype'] == 'Ticket') {
         $ticket = new Ticket();
         $input = array('id' => $this->fields['items_id'], 'date_mod' => $_SESSION["glpi_currenttime"], '_donotadddocs' => true);
         if (!isset($this->input['_do_notif']) || $this->input['_do_notif']) {
             $input['_forcenotif'] = true;
         }
         //Clean ticket description if an image is in it
         $doc = new Document();
         $doc->getFromDB($this->fields['documents_id']);
         if (!empty($doc->fields['tag'])) {
             $ticket->getFromDB($this->fields['items_id']);
             $input['content'] = $ticket->cleanTagOrImage($ticket->fields['content'], array($doc->fields['tag']));
         }
         $ticket->update($input);
     }
     parent::post_purgeItem();
 }
Exemplo n.º 27
0
 function post_addItem()
 {
     global $CFG_GLPI;
     $job = new Ticket();
     $mailsend = false;
     if ($job->getFromDB($this->fields["tickets_id"])) {
         // Set global validation to waiting
         if ($job->fields['global_validation'] == 'accepted' || $job->fields['global_validation'] == 'none') {
             $input['id'] = $this->fields["tickets_id"];
             $input['global_validation'] = 'waiting';
             // to fix lastupdater
             if (isset($this->input['_auto_update'])) {
                 $input['_auto_update'] = $this->input['_auto_update'];
             }
             // to know update by rules
             if (isset($this->input["_rule_process"])) {
                 $input['_rule_process'] = $this->input["_rule_process"];
             }
             // No update ticket notif on ticket add
             if (isset($this->input["_ticket_add"])) {
                 $input['_disablenotif'] = true;
             }
             $job->update($input);
         }
         if ($CFG_GLPI["use_mailing"]) {
             $options = array('validation_id' => $this->fields["id"], 'validation_status' => $this->fields["status"]);
             $mailsend = NotificationEvent::raiseEvent('validation', $job, $options);
         }
         if ($mailsend) {
             $user = new User();
             $user->getFromDB($this->fields["users_id_validate"]);
             $email = $user->getDefaultEmail();
             if (!empty($email)) {
                 //TRANS: %s is the user name
                 Session::addMessageAfterRedirect(sprintf(__('Approval request send to %s'), $user->getName()));
             } else {
                 Session::addMessageAfterRedirect(sprintf(__('The selected user (%s) has no valid email address. The request has been created, without email confirmation.'), $user->getName()), false, ERROR);
             }
         }
     }
     parent::post_addItem();
 }
Exemplo n.º 28
0
 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  *
  * @since version 0.84
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "solveticket":
             $ticket = new Ticket();
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($this->can($key, 'r')) {
                         if ($ticket->getFromDB($this->fields['tickets_id']) && $ticket->canSolve()) {
                             $toupdate = array();
                             $toupdate['id'] = $ticket->getID();
                             $toupdate['solutiontypes_id'] = $input['solutiontypes_id'];
                             $toupdate['solution'] = $input['solution'];
                             if ($ticket->update($toupdate)) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     } else {
                         $res['noright']++;
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
Exemplo n.º 29
0
 /**
  * Transfer tickets
  *
  * @param $itemtype type of transfered item
  * @param $ID original ID of the ticket
  * @param $newID new ID of the ticket
  **/
 function transferTickets($itemtype, $ID, $newID)
 {
     global $DB;
     $job = new Ticket();
     $query = "SELECT *\n                FROM `glpi_tickets`\n                WHERE `items_id` = '{$ID}'\n                      AND `itemtype` = '{$itemtype}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             switch ($this->options['keep_ticket']) {
                 // Transfer
                 case 2:
                     // Same Item / Copy Item -> update entity
                     while ($data = $DB->fetch_array($result)) {
                         $input = $this->transferTicketAdditionalInformations($data);
                         $input['id'] = $data['id'];
                         $input['entities_id'] = $this->to;
                         $input['items_id'] = $newID;
                         $input['itemtype'] = $itemtype;
                         $job->update($input);
                         $this->addToAlreadyTransfer('Ticket', $data['id'], $data['id']);
                         $this->transferTicketTaskCategory($input['id'], $input['id']);
                     }
                     break;
                     // Clean ref : keep ticket but clean link
                 // Clean ref : keep ticket but clean link
                 case 1:
                     // Same Item / Copy Item : keep and clean ref
                     while ($data = $DB->fetch_array($result)) {
                         $job->update(array('id' => $data['id'], 'itemtype' => 0, 'items_id' => 0));
                         $this->addToAlreadyTransfer('Ticket', $data['id'], $data['id']);
                     }
                     break;
                     // Delete
                 // Delete
                 case 0:
                     // Same item -> delete
                     if ($ID == $newID) {
                         while ($data = $DB->fetch_array($result)) {
                             $job->delete(array('id' => $data['id']));
                         }
                     }
                     // Copy Item : nothing to do
                     break;
             }
         }
     }
 }
Exemplo n.º 30
0
 static function assign_me($tickets_id)
 {
     $tu = new Ticket_User();
     $found = $tu->find("`tickets_id` = '{$tickets_id}'\n                           AND `users_id` = '" . $_SESSION['glpiID'] . "'\n                           AND `type` = '" . CommonITILActor::ASSIGN . "'");
     if (empty($found)) {
         $ticket = new Ticket();
         $ticket->update(array('id' => $tickets_id, '_itil_assign' => array('users_id' => $_SESSION['glpiID'], '_type' => 'user')));
     }
 }