Пример #1
0
 /**
  * @dataProvider ticketProvider
  */
 public function testCreateTicketWithActors($ticketActors)
 {
     $ticket = new Ticket();
     $ticket->add(array('name' => 'ticket title', 'description' => 'a description') + $ticketActors);
     $this->assertFalse($ticket->isNewItem());
     $ticketId = $ticket->getID();
     foreach ($ticketActors as $actorType => $actorsList) {
         // Convert single actor (scalar value) to array
         if (!is_array($actorsList)) {
             $actorsList = array($actorsList);
         }
         // Check all actors are assigned to the ticket
         foreach ($actorsList as $index => $actor) {
             $notify = isset($actorList['_users_id_requester_notif']['use_notification'][$index]) ? $actorList['_users_id_requester_notif']['use_notification'][$index] : 1;
             $alternateEmail = isset($actorList['_users_id_requester_notif']['use_notification'][$index]) ? $actorList['_users_id_requester_notif']['alternative_email'][$index] : '';
             switch ($actorType) {
                 case '_users_id_assign':
                     $this->_testTicketUser($ticket, $actor, CommonITILActor::REQUESTER, $notify, $alternateEmail);
                     break;
                 case '_users_id_observer':
                     $this->_testTicketUser($ticket, $actor, CommonITILActor::OBSERVER, $notify, $alternateEmail);
                     break;
                 case '_users_id_assign':
                     $this->_testTicketUser($ticket, $actor, CommonITILActor::ASSIGN, $notify, $alternateEmail);
                     break;
             }
         }
     }
 }
        Html::header(__('Simplified interface'), '', $_SESSION["glpiname"], "helpdesk", "tracking");
    }
}
if (isset($_POST["my_items"]) && !empty($_POST["my_items"])) {
    $splitter = explode("_", $_POST["my_items"]);
    if (count($splitter) == 2) {
        $_POST["itemtype"] = $splitter[0];
        $_POST["items_id"] = $splitter[1];
    }
}
if (!isset($_POST["itemtype"]) || empty($_POST["items_id"]) && $_POST["itemtype"] != 0) {
    $_POST["itemtype"] = '';
    $_POST["items_id"] = 0;
}
if (isset($_POST['add'])) {
    if ($newID = $track->add($_POST)) {
        if (isset($_POST["_type"]) && $_POST["_type"] == "Helpdesk") {
            echo "<div class='center spaced'>" . __('Your ticket has been registered, its treatment is in progress.');
            Html::displayBackLink();
            echo "</div>";
        } else {
            echo "<div class='center b spaced'>";
            echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' alt='" . __s('OK') . "'>";
            Session::addMessageAfterRedirect(__('Thank you for using our automatic helpdesk system.'));
            Html::displayMessageAfterRedirect();
            echo "</div>";
        }
    } else {
        echo "<div class='center'>";
        echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/warning.png' alt='" . __s('Warning') . "'><br>";
        Html::displayMessageAfterRedirect();
 public function save($form, $input)
 {
     $datas = array();
     $ticket = new Ticket();
     $docItem = new Document_Item();
     // Get default request type
     $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';";
     $result = $GLOBALS['DB']->query($query) or die($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);
     $datas['name'] = $this->parseTags($this->fields['name'], $form, $input);
     $datas['content'] = $this->parseTags($this->fields['comment'], $form, $input);
     $datas['entities_id'] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id'];
     $ticketID = $ticket->add($datas);
     if (!empty($_SESSION['formcreator_documents'])) {
         foreach ($_SESSION['formcreator_documents'] as $docID) {
             $docItem->add(array('documents_id' => $docID, 'itemtype' => 'Ticket', 'items_id' => $ticketID));
         }
     }
 }
 /**
  * Create a ticket based on ticket recurrent infos
  *
  * @param $data array data of a entry of glpi_ticketrecurrents
  *
  * @return boolean
  **/
 static function createTicket($data)
 {
     $result = false;
     $tt = new TicketTemplate();
     // Create ticket based on ticket template and entity information of ticketrecurrent
     if ($tt->getFromDB($data['tickettemplates_id'])) {
         // Get default values for ticket
         $input = Ticket::getDefaultValues($data['entities_id']);
         // Apply tickettemplates predefined values
         $ttp = new TicketTemplatePredefinedField();
         $predefined = $ttp->getPredefinedFields($data['tickettemplates_id'], true);
         if (count($predefined)) {
             foreach ($predefined as $predeffield => $predefvalue) {
                 $input[$predeffield] = $predefvalue;
             }
         }
         // Set date to creation date
         $createtime = strtotime($data['next_creation_date']) + $data['create_before'];
         $input['date'] = date('Y-m-d H:i:s', $createtime);
         if (isset($predefined['date'])) {
             $input['date'] = Html::computeGenericDateTimeSearch($predefined['date'], false, $createtime);
         }
         // Compute due_date if predefined based on create date
         if (isset($predefined['due_date'])) {
             $input['due_date'] = Html::computeGenericDateTimeSearch($predefined['due_date'], false, $createtime);
         }
         // Set entity
         $input['entities_id'] = $data['entities_id'];
         $input['_auto_import'] = true;
         $ticket = new Ticket();
         $input = Toolbox::addslashes_deep($input);
         if ($tid = $ticket->add($input)) {
             $msg = sprintf(__('Ticket %d successfully created'), $tid);
             $result = true;
         } else {
             $msg = __('Ticket creation failed (check mandatory fields)');
         }
     } else {
         $msg = __('Ticket creation failed (no template)');
     }
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = addslashes($msg);
     Log::history($data['id'], __CLASS__, $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE);
     // Compute next creation date
     $tr = new self();
     if ($tr->getFromDB($data['id'])) {
         $input = array();
         $input['id'] = $data['id'];
         $input['next_creation_date'] = $tr->computeNextCreationDate($data['begin_date'], $data['end_date'], $data['periodicity'], $data['create_before'], $data['calendars_id']);
         $tr->update($input);
     }
     return $result;
 }
Пример #5
0
 public function generateNewItem($params)
 {
     global $DB;
     // Retrieve plugin configuration
     $config = new PluginOrderConfig();
     $reference = new PluginOrderReference();
     foreach ($params["id"] as $tmp => $values) {
         //If itemtype cannot be generated, go to the new occurence
         if (in_array($values['itemtype'], self::getTypesThanCannotBeGenerared())) {
             continue;
         }
         $entity = $values["entities_id"];
         //------------- Template management -----------------------//
         //Look for a template in the entity
         $templateID = $reference->checkIfTemplateExistsInEntity($values["id"], $values["itemtype"], $entity);
         $item = new $values["itemtype"]();
         if ($values['itemtype']) {
             $order = new PluginOrderOrder();
         }
         $order->getFromDB($values["plugin_order_orders_id"]);
         $reference->getFromDB($params["plugin_order_references_id"]);
         if ($templateID) {
             $item->getFromDB($templateID);
             unset($item->fields["is_template"]);
             unset($item->fields["date_mod"]);
             $fields = array();
             foreach ($item->fields as $key => $value) {
                 if ($value != '' && (!isset($fields[$key]) || $fields[$key] == '' || $fields[$key] == 0)) {
                     $input[$key] = $value;
                 }
             }
             if ($config->getGeneratedAssetState()) {
                 $input["states_id"] = $config->getGeneratedAssetState();
             }
             $input["entities_id"] = $entity;
             $input["serial"] = $values["serial"];
             if ($item->fields['name']) {
                 $input["name"] = autoName($item->fields["name"], "name", $templateID, $values["itemtype"], $entity);
             } else {
                 $input["name"] = $values["name"];
             }
             if ($item->getField('otherserial') != NOT_AVAILABLE) {
                 if ($item->fields['otherserial']) {
                     $input["otherserial"] = autoName($item->fields["otherserial"], "otherserial", $templateID, $values["itemtype"], $entity);
                 } else {
                     $input["otherserial"] = $values["otherserial"];
                 }
             }
             if ($config->canAddLocation()) {
                 $input['locations_id'] = $order->fields['locations_id'];
             }
         } elseif ($values["itemtype"] == 'Contract') {
             $input["name"] = $values["name"];
             $input["entities_id"] = $entity;
             $input['contracttypes_id'] = $reference->fields['types_id'];
         } else {
             if ($config->getGeneratedAssetState()) {
                 $input["states_id"] = $config->getGeneratedAssetState();
             } else {
                 $input["states_id"] = 0;
             }
             $input["entities_id"] = $entity;
             $input["serial"] = $values["serial"];
             $input["otherserial"] = $values["otherserial"];
             $input["name"] = $values["name"];
             // Get bill data
             if ($config->canAddLocation()) {
                 $input['locations_id'] = $order->fields['locations_id'];
             }
             $input["manufacturers_id"] = $reference->fields["manufacturers_id"];
             $typefield = getForeignKeyFieldForTable(getTableForItemType($values["itemtype"] . "Type"));
             $input[$typefield] = $reference->fields["types_id"];
             $modelfield = getForeignKeyFieldForTable(getTableForItemType($values["itemtype"] . "Model"));
             $input[$modelfield] = $reference->fields["models_id"];
         }
         $input = Toolbox::addslashes_deep($input);
         $newID = $item->add($input);
         // Attach new ticket if option is on
         if (isset($params['generate_ticket'])) {
             $tkt = new TicketTemplate();
             if ($tkt->getFromDB($params['generate_ticket']['tickettemplates_id'])) {
                 $input = array();
                 $input = Ticket::getDefaultValues($entity);
                 $ttp = new TicketTemplatePredefinedField();
                 $predefined = $ttp->getPredefinedFields($params['generate_ticket']['tickettemplates_id'], true);
                 if (count($predefined)) {
                     foreach ($predefined as $predeffield => $predefvalue) {
                         $input[$predeffield] = $predefvalue;
                     }
                 }
                 $input['entities_id'] = $entity;
                 $input['_users_id_requester'] = empty($order->fields['users_id']) ? Session::getLoginUserID() : $order->fields['users_id'];
                 $input['items_id'] = $newID;
                 $input['itemtype'] = $values["itemtype"];
                 $ticket = new Ticket();
                 $ticketID = $ticket->add($input);
             }
         }
         //-------------- End template management ---------------------------------//
         $result = $this->createLinkWithItem($values["id"], $newID, $values["itemtype"], $values["plugin_order_orders_id"], $entity, $templateID, false, false);
         //Add item's history
         $new_value = __("Item generated by using order", "order") . ' : ' . $order->fields["name"];
         $order->addHistory($values["itemtype"], '', $new_value, $newID);
         //Add order's history
         $new_value = __("Item generated by using order", "order") . ' : ';
         $new_value .= $item->getTypeName() . " -> " . $item->getField("name");
         $order->addHistory('PluginOrderOrder', '', $new_value, $values["plugin_order_orders_id"]);
         //Copy order documents if needed
         self::copyDocuments($values['itemtype'], $newID, $values["plugin_order_orders_id"], $entity);
         Session::addMessageAfterRedirect(__("Item successfully selected", "order"), true);
     }
 }
Пример #6
0
 /**
  * 
  * @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);
 }
Пример #7
0
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkLoginUser();
$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";
Пример #8
0
/** Generate bigdump : add tickets to an item
 *
 * @param $type      item type
 * @param $ID        item ID
 * @param $ID_entity entity ID
**/
function addTracking($type, $ID, $ID_entity) {
   global $percent, $DB, $MAX, $FIRST, $LAST;

   $current_year = date("Y");

   while (mt_rand(0,100)<$percent['tracking_on_item']) {
      // ticket closed ?
      $status    = CommonITILObject::CLOSED;
      $closedate = "";
      $solvedate = "";

      $opendate  = time() - mt_rand(0, 365)*DAY_TIMESTAMP - mt_rand(0, 10)*HOUR_TIMESTAMP
                   - mt_rand(0, 60)*MINUTE_TIMESTAMP - mt_rand(0, 60);

      if (mt_rand(0,100)<$percent['closed_tracking']) {
         $rtype = mt_rand(0, 100);

         if ($rtype<20) {
            $status = CommonITILObject::SOLVED;
         } else {
            $status = CommonITILObject::CLOSED;
         }

      } else {
         $rtype = mt_rand(0, 100);

         if ($rtype<20) {
            $status = CommonITILObject::INCOMING;

         } else if ($rtype<40) {
            $status = CommonITILObject::WAITING;

         } else if ($rtype<80) {
            $status = CommonITILObject::PLANNED;
            $date3  = $opendate+mt_rand(10800, 7776000); // + entre 3 heures et 3 mois
            $date4  = $date3+10800; // + 3 heures

         } else {
            $status = CommonITILObject::ASSIGNED;
         }
      }

      // Author
      $users[0] = mt_rand($FIRST['users_normal'], $LAST['users_postonly']);

      // Assign user
      $users[1] = 0;

      if ($status != CommonITILObject::INCOMING) {
         $users[1] = mt_rand($FIRST['users_sadmin'], $LAST['users_admin']);
      }
      $enterprise = 0;

      if (mt_rand(0,100)<20) {
         $enterprise = mt_rand($FIRST["enterprises"], $LAST['enterprises']);
      }

      $firstactiontime = mt_rand(0, 10)*DAY_TIMESTAMP+mt_rand(0, 10)*HOUR_TIMESTAMP
                         +mt_rand(0, 60)*MINUTE_TIMESTAMP;
      $solvetime       = 0;
      $closetime       = 0;
      $actiontime      = 0;

      $solution        = "";
      $solutiontype    = 0;
      $due_date        = $opendate + $firstactiontime+mt_rand(0, 10)*DAY_TIMESTAMP+
                         mt_rand(0, 10)*HOUR_TIMESTAMP+mt_rand(0, 60)*MINUTE_TIMESTAMP;
      $duedatetoadd    = date("Y-m-d H:i:s", intval($due_date));


      if (($status == CommonITILObject::CLOSED) || ($status == CommonITILObject::SOLVED)) {
         $solvetime = $firstactiontime+mt_rand(0, 10)*DAY_TIMESTAMP+mt_rand(0, 10)*HOUR_TIMESTAMP+
                      mt_rand(0, 60)*MINUTE_TIMESTAMP;
         $solvedate = $opendate+$solvetime;
         $closedate = $opendate+$solvetime;
         $actiontime = mt_rand(0, 10)*HOUR_TIMESTAMP+
                      mt_rand(0, 60)*MINUTE_TIMESTAMP;
         if ($status == CommonITILObject::CLOSED) {
            $closetime = $solvetime+mt_rand(0, 5)*DAY_TIMESTAMP+mt_rand(0, 10)*HOUR_TIMESTAMP+
                         mt_rand(0, 60)*MINUTE_TIMESTAMP;
            $closedate = $opendate+$closetime;
         }
         $solutiontype = mt_rand($FIRST['solutiontypes'], $LAST['solutiontypes']);
         $solution     = "Solution '".Toolbox::getRandomString(20);
      }
      $updatedate = $opendate+max($firstactiontime, $solvetime, $closetime);
      $hour_cost  = 100;

      $closedatetoadd = 'NULL';
      if (!empty($closedate)) {
         $closedatetoadd = date("Y-m-d H:i:s", intval($closedate));
      }

      $solvedatetoadd = 'NULL';
      if (!empty($solvedate)) {
         $solvedatetoadd = date("Y-m-d H:i:s",intval($solvedate));
      }
      $t   = new Ticket();
      $tID = $t->add(toolbox::addslashes_deep(
                     array('entities_id'                 => $ID_entity,
                           'name'                        => "Title '".Toolbox::getRandomString(20),
                           'date'                        => date("Y-m-d H:i:s", intval($opendate)),
                           'closedate'                   => $closedatetoadd,
                           'solvedate'                   => $solvedatetoadd,
                           'date_mod'                    => date("Y-m-d H:i:s", intval($updatedate)),
                           'users_id_lastupdater'        => $users[0],
                           'status'                      => $status,
                           'users_id_recipient'          => $users[0],
                           'requesttypes_id'             => mt_rand(0,6),
                           '_suppliers_id_assign'        => $enterprise,
                           'itemtype'                    => $type,
                           'items_id'                    => $ID,
                           'content'                     => "tracking '".Toolbox::getRandomString(15),
                           'urgency'                     => mt_rand(1,5),
                           'impact'                      => mt_rand(1,5),
                           'priority'                    => mt_rand(1,5),
                           'itilcategories_id'           => mt_rand(0, $MAX['tracking_category']),
                           'type'                        => mt_rand(1,2),
                           'solutiontypes_id'            => $solutiontype,
                           'locations_id'                => mt_rand($FIRST['locations'],
                                                                    $LAST['locations']),
                           'solution'                    => $solution,
                           'actiontime'                  => $actiontime,
                           'due_date'                    => $duedatetoadd,
                           'close_delay_stat'            => $closetime,
                           'solve_delay_stat'            => $solvetime,
                           'takeintoaccount_delay_stat'  => $firstactiontime,
                           '_users_id_requester'         => $users[0],
                           '_users_id_assign'            => $users[1],
                           '_groups_id_assign'           => mt_rand($FIRST["techgroups"],
                                                                    $LAST['techgroups']),
                           '_groups_id_requester'        => mt_rand($FIRST["groups"], $LAST['groups']),
                     )));

      // Add followups
      $i     = 0;
      $fID   = 0;
      $first = true;
      $date  = 0;
      $tf    = new TicketFollowup();
      while (mt_rand(0,100)<$percent['followups']) {
         if ($first) {
            $date = $opendate+$firstactiontime;
            $first = false;

         } else {
            $date += mt_rand(3600, 7776000);
         }
         $tf->add(toolbox::addslashes_deep(
                  array('tickets_id'      => $tID,
                        'date'            => date("Y-m-d H:i:s", $date),
                        'users_id'        => $users[1],
                        'content'         => "followup $i '".Toolbox::getRandomString(15),
                        'requesttypes_id' => mt_rand(0, 3))));
         $i++;
      }
      $tt = new TicketTask();
      while (mt_rand(0,100)<$percent['tasks']) {
         $doplan=false;
         if ($first) {
            $date   = $opendate+$firstactiontime;
            $first  = false;
            $doplan = true;
         } else {
            $date += mt_rand(3600, 7776000);
         }

         $begin       = $end = 'NULL';
         $assign_user = 0;
         $state       = 1;
         if ($status == CommonITILObject::PLANNED && $doplan) {
            $endtask = date("Y-m-d H:i:s", $date4);
            if ($endtask < date("Y-m-d H:i:s")) {
               $state = 2; // done
            }
         }
         $params = toolbox::addslashes_deep(
                   array('tickets_id'        => $tID,
                         'taskcategories_id' => mt_rand($FIRST['taskcategory'], $LAST['taskcategory']),
                         'date'              => date("Y-m-d H:i:s",$date),
                         'users_id'          => $users[1],
                         'content'           => "task $i '".Toolbox::getRandomString(15),
                         'is_private'        => mt_rand(0,1),
                         'state'             => $state,
                         'users_id_tech'    => $users[1]));

         if ($status == CommonITILObject::PLANNED && $doplan) {
            $params['plan'] = array('begin'       => date("Y-m-d H:i:s", $date3),
                                    'end'         => $endtask);
         }
         $tt->add($params);
         $i++;
      }

      $tc = new TicketCost();
      $params = toolbox::addslashes_deep(
                array('tickets_id'        => $tID,
                     'entities_id'       => $ID_entity,
                     'begin_date'        => date("Y-m-d H:i:s", intval($opendate)),
                     'name'              => "C'ost",
                     'cost_time'         => $hour_cost,
                     'actiontime'        => floor($actiontime/2)));

      // Insert satisfaction for stats
      if ($status == CommonITILObject::CLOSED
          && mt_rand(0,100) < $percent['satisfaction']) {

         $answerdate = 'NULL';
         if (mt_rand(0,100) < $percent['answersatisfaction']) {
            $answerdate = $closedatetoadd;
         }
         $ts = new TicketSatisfaction();
         $ts->add(toolbox::addslashes_deep(
                  array('tickets_id'   => $tID,
                        'type'         => mt_rand(1,2),
                        'date_begin'   => $closedatetoadd,
                        'date_answer'  => $answerdate,
                        'satisfaction' => mt_rand(0,5),
                        'comment'      => "comment ' satisfaction $tID")));
      }

   }

}
Пример #9
0
 public function add_ticket()
 {
     if (!Visitor::current()->group->can("add_ticket")) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to create tickets.", "progress"));
     }
     if (empty($_POST['title'])) {
         Flash::warning(__("Please provide a summary of the ticket in the form of a title.", "progress"));
     }
     if (empty($_POST['milestone_id'])) {
         Flash::warning(__("No milestone selected.", "progress"));
     }
     $milestone = new Milestone($_POST['milestone_id']);
     if ($milestone->no_results) {
         error(__("Error"), __("Invalid milestone.", "progress"));
     }
     if (Flash::exists()) {
         redirect($milestone->url());
     }
     $ticket = Ticket::add($_POST['title'], $_POST['description'], "new", $_POST['milestone_id'], $_POST['owner_id']);
     $files = array();
     foreach ($_FILES['attachment'] as $key => $val) {
         foreach ($val as $file => $attr) {
             $files[$file][$key] = $attr;
         }
     }
     foreach ($files as $attachment) {
         if ($attachment['error'] != 4) {
             $path = upload($attachment, null, "attachments");
             Attachment::add(basename($path), $path, "ticket", $ticket->id);
         }
     }
     $domain = parse_url(Config::current()->url, PHP_URL_HOST);
     if (!empty($ticket->owner->email) and Visitor::current()->id != $ticket->owner->id) {
         mail($ticket->owner->email, _f("Ticket #%d Created! (%s)", array($ticket->id, $ticket->title), "progress"), _f("%s has created the ticket \"%s\" and assigned the owner to you. Description:<br />\n<br />\n%s", array(oneof($ticket->user->full_name, $ticket->user->login), $ticket->title, $ticket->description)), "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=utf-8\r\n" . "From: no-reply@" . $domain);
     }
     Flash::notice(__("Ticket added.", "progress"), $ticket->url());
 }
Пример #10
0
 /**
  * CLone a ticket and his relations
  * @param  integer $tickets_id id of the ticket to clone
  * @return print a json response (return nothing)
  */
 static function cloneAndLink($tickets_id)
 {
     global $DB;
     //get old ticket
     $ticket = new Ticket();
     if (!$ticket->getFromDB($tickets_id)) {
         echo "{\"success\":false, \"message\":\"" . __("Error : get old ticket", "escalade") . "\"}";
         exit;
     }
     //set fields
     $fields = $ticket->fields;
     $fields = array_map(array('Toolbox', 'addslashes_deep'), $fields);
     $fields['id'] = 0;
     $fields['_users_id_requester'] = 0;
     $fields['status'] = CommonITILObject::INCOMING;
     /*var_dump($fields);
       exit;*/
     //create new ticket (duplicate from previous)
     if (!($newID = $ticket->add($fields))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding new ticket", "escalade") . "\"}";
         exit;
     }
     //add link between them
     $ticket_ticket = new Ticket_Ticket();
     if (!$ticket_ticket->add(array('tickets_id_1' => $tickets_id, 'tickets_id_2' => $newID, 'link' => Ticket_Ticket::LINK_TO))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding link between the two tickets", "escalade") . "\"}";
         exit;
     }
     //add a followup to indicate duplication
     $followup = new TicketFollowup();
     if (!$followup->add(array('tickets_id' => $newID, 'users_id' => Session::getLoginUserID(), 'content' => __("This ticket has been from the ticket num", "escalade") . " " . $tickets_id, 'is_private' => true, 'requesttypes_id' => 6))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding followups", "escalade") . "\"}";
         exit;
     }
     //add actors to the new ticket (without assign)
     //users
     $query_users = "INSERT INTO glpi_tickets_users\n      SELECT '' AS id, {$newID} as tickets_id, users_id, type, use_notification, alternative_email\n      FROM glpi_tickets_users\n      WHERE tickets_id = {$tickets_id} AND type != 2";
     if (!($res = $DB->query($query_users))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding actors (user)", "escalade") . "\"}";
         exit;
     }
     //groups
     $query_groups = "INSERT INTO glpi_groups_tickets\n      SELECT '' AS id, {$newID} as tickets_id, groups_id, type\n      FROM glpi_groups_tickets\n      WHERE tickets_id = {$tickets_id} AND type != 2";
     if (!($res = $DB->query($query_groups))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding actors (group)", "escalade") . "\"}";
         exit;
     }
     //add documents
     $query_docs = "INSERT INTO glpi_documents_items (documents_id, items_id, itemtype, entities_id, is_recursive, date_mod)\n      SELECT documents_id, {$newID}, 'Ticket', entities_id, is_recursive, date_mod\n      FROM glpi_documents_items\n      WHERE items_id = {$tickets_id} AND itemtype = 'Ticket'";
     if (!($res = $DB->query($query_docs))) {
         echo "{\"success\":false, \"message\":\"" . __("Error : adding documents", "escalade") . "\"}";
         exit;
     }
     //add history to the new ticket
     $changes[0] = '0';
     $changes[1] = __("This ticket has been from the ticket num", "escalade") . " " . $tickets_id;
     $changes[2] = "";
     Log::history($newID, 'Ticket', $changes, 'Ticket');
     //add message (ticket cloned) after redirect
     Session::addMessageAfterRedirect(__("This ticket has been from the ticket num", "escalade") . " " . $tickets_id);
     //all ok
     echo "{\"success\":true, \"newID\":{$newID}}";
 }
        $fields['items_id'] = $_POST['items_id'];
        // $fields['slas_id'] =             $_POST['slas_id'];
        $fields['entities_id'] = $_POST['entities_id'];
        // $fields['type'] =                $_POST['type'];
        $fields['itilcategories_id'] = $_POST['itilcategories_id'];
        $fields['locations_id'] = $_POST['locations_id'];
        $fields['name'] = $track_name;
        $fields['content'] .= "\n-----\n" . $_POST['comment'];
        /*
              echo "<pre>";
              print_r($fields);
              echo "</pre>";
              die('test');
        */
        // Create a new ticket ...
        $_POST['tickets_id'] = $track->add($fields);
        // Create new downtime with associated ticket ...
        $pmDowntime->add($_POST);
        // Redirect to new ticket form if required
        if (isset($_POST["redirect"])) {
            Html::redirect($_POST["redirect"] . "?id=" . $_POST['tickets_id']);
        } else {
            $pmDowntime->redirectToList();
        }
    } else {
        // Create new downtime without associated ticket ...
        $pmDowntime->add($_POST);
        $pmDowntime->redirectToList();
    }
} else {
    if (isset($_POST["update"])) {
Пример #12
0
                     $input["itemtype"] = "PluginResourcesResource";
                     $input["items_id"] = $checklist->fields["plugin_resources_resources_id"];
                     $input["requesttypes_id"] = "6";
                     $input["urgency"] = "3";
                     $input["_users_id_assign"] = 0;
                     $input['_groups_id_assign'] = 0;
                     $input["entities_id"] = $checklist->fields["entities_id"];
                     if ($cat->getfromDB(1)) {
                         $input["itilcategories_id"] = $cat->fields["ticketcategories_id"];
                     } else {
                         $input["itilcategories_id"] = 0;
                     }
                     $rules = new RuleTicketCollection();
                     $input = $rules->processAllRules($input, $input);
                     $Ticket = new Ticket();
                     $Ticket->add($input);
                 }
             }
         }
     }
     Html::redirect(Toolbox::getItemTypeFormURL('PluginResourcesResource') . "?id=" . $_POST["plugin_resources_resources_id"]);
 } else {
     if (isset($_POST["report"])) {
         $restrict = "`itemtype` = 'User' AND `plugin_resources_resources_id` = '" . $_POST["id"] . "'";
         $linkeduser = getAllDatasFromTable('glpi_plugin_resources_resources_items', $restrict);
         if (!empty($linkeduser)) {
             $resource->sendReport($_POST);
             Session::addMessageAfterRedirect(__('Creation report sent', 'resources'), true);
         } else {
             Session::addMessageAfterRedirect(__('The report is not sent because the resource is not linked with a user', 'resources'), true, ERROR);
         }
Пример #13
0
 }
 if (isset($predefined['suppliers_id_assign'])) {
     $ticket['suppliers_id_assign'] = $predefined['suppliers_id_assign'];
 }
 if (isset($predefined['requesttypes_id'])) {
     $ticket['requesttypes_id'] = $predefined['requesttypes_id'];
 }
 // **********fin modif yt pour prendre en compte valeurs prédéfinies du gabarit**********;
 $user = new User();
 $user->getFromDB(Session::getLoginUserID());
 $ticket['users_id_recipient'] = $user->fields['id'];
 $ticket['users_id_lastupdater'] = $user->fields['id'];
 $ticket['type'] = $target_value['type'];
 $ticket['name'] = str_replace("'", "\\'", $ticket['name']);
 $track = new Ticket();
 $ticketID = $track->add($ticket);
 if ($validation_exist) {
     for ($cpt_valid = 0; $cpt_valid < count($validationTab); $cpt_valid++) {
         $validationTab[$cpt_valid]['tickets_id'] = $ticketID;
         $validation = new Ticketvalidation();
         $validation->add($validationTab[$cpt_valid]);
     }
 }
 $sections = new PluginFormcreatorSection();
 $sections = $sections->find("plugin_formcreator_targets_id = '{$target_id}'");
 foreach ($sections as $section_id => $section_value) {
     $questions = $helpdesk->getQuestionBySectionTypeFile($section_id);
     foreach ($questions as $question_id => $question_value) {
         $question_name = "question_" . $question_id;
         if (array_key_exists($question_name, $_FILES)) {
             if ($_FILES[$question_name]['error'] != 4) {
Пример #14
0
 static function createTicket($data)
 {
     $result = false;
     $tt = new TicketTemplate();
     // Create ticket based on ticket template and entity informations of ticketrecurrent
     if ($tt->getFromDB($data['tickettemplates_id'])) {
         // Get default values for ticket
         $input = Ticket::getDefaultValues($data['entities_id']);
         // Apply tickettemplates predefined values
         $ttp = new TicketTemplatePredefinedField();
         $predefined = $ttp->getPredefinedFields($data['tickettemplates_id'], true);
         if (count($predefined)) {
             foreach ($predefined as $predeffield => $predefvalue) {
                 $input[$predeffield] = $predefvalue;
             }
         }
         // Set date to creation date
         $createtime = date('Y-m-d H:i:s');
         $input['date'] = $createtime;
         // Compute due_date if predefined based on create date
         if (isset($predefined['due_date'])) {
             $input['due_date'] = Html::computeGenericDateTimeSearch($predefined['due_date'], false, $createtime);
         }
         // Set entity
         $input['entities_id'] = $data['entities_id'];
         $input['actiontime'] = $data['actiontime'];
         $res = new PluginResourcesResource();
         if ($res->getFromDB($data['plugin_resources_resources_id'])) {
             $input['users_id_recipient'] = $res->fields['users_id_recipient'];
             $input['_users_id_requester'] = $res->fields['users_id_recipient'];
             if (isset($res->fields['users_id'])) {
                 $input['_users_id_observer'] = $res->fields['users_id'];
             }
             $input['_users_id_assign'] = Session::getLoginUserID();
             $input["itemtype"] = "PluginResourcesResource";
             $input["items_id"] = $data['plugin_resources_resources_id'];
             $input["name"] .= addslashes(" " . PluginResourcesResource::getResourceName($data['plugin_resources_resources_id']));
         }
         //TODO : ADD checklist lists or add config into plugin ?
         $input["content"] .= addslashes("\n\n");
         $input['status'] = Ticket::CLOSED;
         $ticket = new Ticket();
         $input = Toolbox::addslashes_deep($input);
         if ($tid = $ticket->add($input)) {
             $msg = __('Create a end treatment ticket', 'resources') . " OK - ({$tid})";
             // Success
             $result = true;
         } else {
             $msg = __('Failed operation');
             // Failure
         }
     } else {
         $msg = __('No selected element or badly defined operation');
         // Not defined
     }
     if ($tid) {
         $changes[0] = 0;
         $changes[1] = '';
         $changes[2] = addslashes($msg);
         Log::history($data['plugin_resources_resources_id'], "PluginResourcesResource", $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE);
     }
     return $result;
 }
 /**
  * Constructor
  *
  * @param $mailgateID ID of the mailgate
  * @param $display display messages in MessageAfterRedirect or just return error
  *
  * @return if $display = false return messages result string
  **/
 function collect($mailgateID, $display = 0)
 {
     global $LANG, $CFG_GLPI;
     if ($this->getFromDB($mailgateID)) {
         $this->mid = -1;
         $this->fetch_emails = 0;
         //Connect to the Mail Box
         $this->connect();
         $rejected = new NotImportedEmail();
         // Clean from previous collect (from GUI, cron already truncate the table)
         $rejected->deleteByCriteria(array('mailcollectors_id' => $this->fields['id']));
         if ($this->marubox) {
             // Get Total Number of Unread Email in mail box
             $tot = $this->getTotalMails();
             //Total Mails in Inbox Return integer value
             $error = 0;
             $refused = 0;
             for ($i = 1; $i <= $tot && $this->fetch_emails < $this->maxfetch_emails; $i++) {
                 $tkt = $this->buildTicket($i, array('mailgates_id' => $mailgateID, 'play_rules' => true));
                 //Indicates that the mail must be deleted from the mailbox
                 $delete_mail = false;
                 //If entity assigned, or email refused by rule, or no user associated with the email
                 $user_condition = $CFG_GLPI["use_anonymous_helpdesk"] || isset($tkt['_users_id_requester']) && $tkt['_users_id_requester'] > 0;
                 // Manage blacklisted emails
                 if (isset($tkt['_blacklisted']) && $tkt['_blacklisted']) {
                     $this->deleteMails($i);
                     // entities_id set when new ticket / tickets_id when new followup
                 } else {
                     if ((isset($tkt['entities_id']) || isset($tkt['tickets_id'])) && $user_condition || isset($tkt['_refuse_email_no_response']) || isset($tkt['_refuse_email_with_response'])) {
                         if (isset($tkt['_refuse_email_with_response'])) {
                             $this->sendMailRefusedResponse($tkt['_head']['from'], $tkt['name']);
                             $delete_mail = true;
                             $refused++;
                         } else {
                             if (isset($tkt['_refuse_email_no_response'])) {
                                 $delete_mail = true;
                                 $refused++;
                             } else {
                                 if (isset($tkt['entities_id']) || isset($tkt['tickets_id'])) {
                                     $tkt['_mailgate'] = $mailgateID;
                                     $result = imap_fetchheader($this->marubox, $i);
                                     // Is a mail responding of an already existgin ticket ?
                                     if (isset($tkt['tickets_id'])) {
                                         // Deletion of message with sucess
                                         if (false === is_array($result)) {
                                             $fup = new TicketFollowup();
                                             if ($fup->add($tkt)) {
                                                 $delete_mail = true;
                                             }
                                         } else {
                                             $error++;
                                         }
                                     } else {
                                         // New ticket
                                         // Deletion of message with sucess
                                         if (false === is_array($result)) {
                                             $track = new Ticket();
                                             if ($track->add($tkt)) {
                                                 $delete_mail = true;
                                             }
                                         } else {
                                             $error++;
                                         }
                                     }
                                 } else {
                                     // Case never raise
                                     $delete_mail = true;
                                     $refused++;
                                 }
                             }
                         }
                         //Delete Mail from Mail box if ticket is added successfully
                         if ($delete_mail) {
                             $this->deleteMails($i);
                         }
                     } else {
                         $input = array();
                         $input['mailcollectors_id'] = $mailgateID;
                         $input['from'] = $tkt['_head']['from'];
                         $input['to'] = $tkt['_head']['to'];
                         if (!$tkt['_users_id_requester']) {
                             $input['reason'] = NotImportedEmail::USER_UNKNOWN;
                         } else {
                             $input['reason'] = NotImportedEmail::MATCH_NO_RULE;
                         }
                         $input['users_id'] = $tkt['_users_id_requester'];
                         $input['subject'] = $this->textCleaner($tkt['_head']['subject']);
                         $input['messageid'] = $tkt['_head']['message_id'];
                         $input['date'] = $_SESSION["glpi_currenttime"];
                         $rejected->add($input);
                     }
                 }
                 $this->fetch_emails++;
             }
             imap_expunge($this->marubox);
             $this->close_mailbox();
             //Close Mail Box
             if ($display) {
                 if ($error == 0) {
                     addMessageAfterRedirect($LANG['mailgate'][3] . "&nbsp;: " . $this->fetch_emails);
                 } else {
                     addMessageAfterRedirect($LANG['mailgate'][3] . "&nbsp;: " . $this->fetch_emails . " ({$error} " . $LANG['common'][63] . ")", false, ERROR);
                 }
             } else {
                 return "Number of messages: available={$tot}, collected=" . $this->fetch_emails . ($error > 0 ? " ({$error} error(s))" : "" . ($refused > 0 ? " ({$refused} refused)" : ""));
             }
         } else {
             if ($display) {
                 addMessageAfterRedirect($LANG['log'][41], false, ERROR);
             } else {
                 return "Could not connect to mailgate server";
             }
         }
     } else {
         if ($display) {
             addMessageAfterRedirect($LANG['common'][54] . "&nbsp;: mailgate " . $mailgateID, false, ERROR);
         } else {
             return 'Could find mailgate ' . $mailgateID;
         }
     }
 }
Пример #16
0
 /**
  * @group api
  *
  * This function test https://github.com/glpi-project/glpi/issues/1103
  * A post-only user could retrieve tickets of others users when requesting itemtype
  * without first letter in uppercase
  **/
 public function testgetItemsForPostonly()
 {
     // init session for postonly
     $res = $this->doHttpRequest('GET', 'initSession/', ['auth' => ['post-only', 'postonly']]);
     $body = $res->getBody();
     $data = json_decode($body, true);
     // create a ticket for another user (glpi - super-admin)
     $ticket = new Ticket();
     $tickets_id = $ticket->add(array('name' => 'test post-only', 'content' => 'test post-only', '_users_id_requester' => 2));
     // try to access this ticket with post-only
     try {
         $res = $this->doHttpRequest('GET', "ticket/{$tickets_id}", ['headers' => ['Session-Token' => $data['session_token']]]);
         $this->assertGreaterThanOrEqual(400, $res->getStatusCode());
     } catch (ClientException $e) {
         $response = $e->getResponse();
         $this->assertEquals(401, $this->last_error->getStatusCode());
     }
     // try to access ticket list (we should get empty return)
     $res = $this->doHttpRequest('GET', 'ticket/', ['headers' => ['Session-Token' => $data['session_token']]]);
     $this->assertNotEquals(null, $res, $this->last_error);
     $this->assertEquals(200, $res->getStatusCode());
     $body = $res->getBody();
     $data = json_decode($body, true);
     $this->assertEquals(0, count($data));
     // delete ticket
     $ticket->delete(array('id' => $tickets_id), true);
 }
Пример #17
0
Session::checkLoginUser();
$fup = new TicketFollowup();
$track = new Ticket();
if (!isset($_GET['id'])) {
    $_GET['id'] = "";
}
if (isset($_POST["add"])) {
    $track->check(-1, 'w', $_POST);
    if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
        $splitter = explode("_", $_POST["_my_items"]);
        if (count($splitter) == 2) {
            $_POST["itemtype"] = $splitter[0];
            $_POST["items_id"] = $splitter[1];
        }
    }
    $track->add($_POST);
    Html::back();
} else {
    if (isset($_POST['update'])) {
        $track->check($_POST['id'], 'w');
        if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
            $splitter = explode("_", $_POST["_my_items"]);
            if (count($splitter) == 2) {
                $_POST["itemtype"] = $splitter[0];
                $_POST["items_id"] = $splitter[1];
            }
        }
        $track->update($_POST);
        Event::log($_POST["id"], "ticket", 4, "tracking", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
        // Copy solution to KB redirect to KB
        if (isset($_POST['_sol_to_kb']) && $_POST['_sol_to_kb']) {
 /**
  * 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;
 }
Пример #19
0
<?php

include '../../config.inc.php';
global $currentUser;
$response['success'] = false;
$errors = array();
if (empty($currentUser)) {
    $errors[] = 'You must be logged in to perform this action.';
}
if (empty($_POST['message'])) {
    $errors[] = 'Message is required';
}
if (empty($errors)) {
    $ticket = new Ticket(array('issue_title' => $_POST['title'], 'description' => $_POST['message'], 'opened_by' => array('id' => $currentUser->getId()), 'category' => array('id' => 1), 'date_opened' => time()));
    if ($ticket->add()) {
        $response['success'] = true;
        $response['tickets_id'] = $ticket->getId();
    } else {
        $response['error'] = "Adding the new ticket failed.";
    }
} else {
    $response['error'] = implode("<br />", $errors);
}
echo json_encode($response);
Пример #20
0
 /**
  * Create a new ticket
  * for an authenticated user
  *
  * @param $params    array of options
  *    (entity, user, group, date, itemtype, itemid, title, content, urgency, category)
  * @param $protocol        the communication protocol used
  *
  * @return array of hashtable
  **/
 static function methodCreateTicket($params = array(), $protocol)
 {
     global $CFG_GLPI;
     if (isset($params['help'])) {
         return array('content' => 'string,mandatory', 'title' => 'string,optional', 'entity' => 'integer,optional', 'urgency' => 'integer,optional', 'impact' => 'integer,optional', 'category' => 'integer,optional', 'user' => 'integer,optional', 'requester' => 'integer,optional', 'observer' => 'integer,optional', 'group' => 'integer,optional', 'groupassign' => 'integer,optional', 'date' => 'datetime,optional', 'type' => 'integer,optional', 'category' => 'integer,optional', 'itemtype' => 'string,optional', 'item' => 'integer,optional', 'source' => 'string,optional', 'user_email' => 'string,optional', 'use_email_notification' => 'bool,optional', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     // ignore config for content : always mandatory
     if (!isset($params['content']) || empty($params['content'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'content');
     }
     // Source of the ticket, dynamically created
     if (isset($params['source'])) {
         if (empty($params['content'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'source');
         }
         $source = Dropdown::importExternal('RequestType', $params['source']);
     } else {
         $source = Dropdown::importExternal('RequestType', 'WebServices');
     }
     // ===== Build the Ticket =====
     // author : always the logged user
     $data = array('_users_id_requester' => Session::getLoginUserID(), 'users_id_recipient' => Session::getLoginUserID(), 'requesttypes_id' => $source, 'status' => Ticket::INCOMING, 'content' => addslashes(Toolbox::clean_cross_side_scripting_deep($params["content"])), 'itemtype' => '', 'type' => Ticket::INCIDENT_TYPE, 'items_id' => 0);
     // Title : optional (default = start of contents set by add method)
     if (isset($params['title'])) {
         $data['name'] = addslashes(Toolbox::clean_cross_side_scripting_deep($params['title']));
     }
     // entity : optionnal, default = current one
     if (!isset($params['entity'])) {
         $data['entities_id'] = $_SESSION['glpiactive_entity'];
     } else {
         if (!is_numeric($params['entity']) || !in_array($params['entity'], $_SESSION['glpiactiveentities'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'entity');
         }
         $data['entities_id'] = $params['entity'];
     }
     // user (author) : optionnal,  default = current one
     if (isset($params['user'])) {
         if (!is_numeric($params['user'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user');
         }
         $data['_users_id_requester'] = $params['user'];
     }
     // Email notification
     if (isset($params['user_email'])) {
         if (!NotificationMail::isUserAddressValid($params['user_email'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user_email');
         }
         $data['_users_id_requester_notif']['alternative_email'] = $params['user_email'];
         $data['_users_id_requester_notif']['use_notification'] = 1;
     } else {
         if (isset($params['use_email_notification']) && $params['use_email_notification']) {
             $data['_users_id_requester_notif']['use_notification'] = 1;
         } else {
             if (isset($params['use_email_notification']) && !$params['use_email_notification']) {
                 $data['_users_id_requester_notif']['use_notification'] = 0;
             }
         }
     }
     if (isset($params['requester'])) {
         if (is_array($params['requester'])) {
             foreach ($params['requester'] as $id) {
                 if (is_numeric($id) && $id > 0) {
                     $data['_additional_requesters'][] = array('users_id' => $id, 'use_notification' => true);
                 } else {
                     return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'requester');
                 }
             }
         } else {
             if (is_numeric($params['requester']) && $params['requester'] > 0) {
                 $data['_additional_requesters'][] = array('users_id' => $params['requester'], 'use_notification' => true);
             } else {
                 return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'requester');
             }
         }
     }
     if (isset($params['victim'])) {
         if (is_array($params['victim'])) {
             foreach ($params['victim'] as $id) {
                 if (is_numeric($id) && $id > 0) {
                     $data['_additional_requesters'][] = array('users_id' => $id, 'use_notification' => false);
                 } else {
                     return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'victim');
                 }
             }
         } else {
             if (is_numeric($params['victim']) && $params['victim'] > 0) {
                 $data['_additional_requesters'][] = array('users_id' => $params['victim'], 'use_notification' => false);
             } else {
                 return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'victim');
             }
         }
     }
     if (isset($params['observer'])) {
         if (is_array($params['observer'])) {
             foreach ($params['observer'] as $id) {
                 if (is_numeric($id) && $id > 0) {
                     $data['_additional_observers'][] = array('users_id' => $id, 'use_notification' => true);
                 } else {
                     return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'observer');
                 }
             }
         } else {
             if (is_numeric($params['observer']) && $params['observer'] > 0) {
                 $data['_additional_observers'][] = array('users_id' => $params['observer'], 'use_notification' => true);
             } else {
                 return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'observer');
             }
         }
     }
     // group (author) : optionnal,  default = none
     if (!isset($params['group'])) {
         $data['_groups_id_requester'] = 0;
     } else {
         if (!is_numeric($params['group'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group');
         }
         $data['_groups_id_requester'] = $params['group'];
     }
     // groupassign (technicians group) : optionnal,  default = none
     if (!isset($params['groupassign'])) {
         $data['_groups_id_assign'] = 0;
     } else {
         if (!is_numeric($params['groupassign'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'groupassign');
         }
         $data['_groups_id_assign'] = $params['groupassign'];
     }
     // date (open) : optional, default set by add method
     if (isset($params['date'])) {
         if (preg_match(WEBSERVICES_REGEX_DATETIME, $params['date'])) {
             $data['date'] = $params['date'];
         } else {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date');
         }
     }
     if (isset($params['itemtype']) && empty($params['itemtype'])) {
         unset($params['itemtype']);
     }
     if (isset($params['item']) && !$params['item']) {
         unset($params['item']);
     }
     // Item type + id
     if (isset($params['itemtype'])) {
         if (!isset($params['item'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'item');
         }
         if (!class_exists($params['itemtype'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'itemtype=' . $params['itemtype']);
         }
     }
     if (isset($params['item'])) {
         if (!isset($params['itemtype'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'itemtype');
         }
         if (!is_numeric($params['item']) || $params['item'] <= 0) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'item=' . $params['item']);
         }
         // Both ok
         $data['itemtype'] = $params['itemtype'];
         $data['items_id'] = $params['item'];
     }
     // Hack for compatibility with previous version
     if (isset($params['urgence'])) {
         $params['urgency'] = $params['urgence'];
     }
     // urgence (priority while not exists) : optionnal,  default = 3
     if (!isset($params['urgency'])) {
         $data['urgency'] = 3;
     } else {
         if (!is_numeric($params['urgency']) || $params['urgency'] < 1 || $params['urgency'] > 5 || isset($params['urgency']) && !($CFG_GLPI['urgency_mask'] & 1 << $params["urgency"])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'urgency');
         } else {
             $data['urgency'] = $params['urgency'];
         }
     }
     if (isset($params['impact'])) {
         if (!is_numeric($params['impact']) || $params['impact'] < 1 || $params['impact'] > 5 || isset($params['impact']) && !($CFG_GLPI['impact_mask'] & 1 << $params["impact"])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'impact');
         } else {
             $data['impact'] = $params['impact'];
         }
     }
     // category : optionnal
     if (isset($params['category'])) {
         if (!is_numeric($params['category']) || $params['category'] < 1) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'category');
         }
         $data['itilcategories_id'] = $params['category'];
     }
     // type : optionnal (default = INCIDENT)
     if (isset($params['type'])) {
         $types = Ticket::getTypes();
         if (!is_numeric($params['type']) || !isset($types[$params['type']])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'type');
         }
         $data['type'] = $params['type'];
     }
     $ticket = new Ticket();
     if ($newID = $ticket->add($data)) {
         return self::methodGetTicket(array('ticket' => $newID), $protocol);
     }
     return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
 }
Пример #21
0
 /**
  * Constructor
  *
  * @param $mailgateID   ID of the mailgate
  * @param $display      display messages in MessageAfterRedirect or just return error (default 0=)
  *
  * @return if $display = false return messages result string
  **/
 function collect($mailgateID, $display = 0)
 {
     global $CFG_GLPI;
     if ($this->getFromDB($mailgateID)) {
         $this->mid = -1;
         $this->fetch_emails = 0;
         //Connect to the Mail Box
         $this->connect();
         $rejected = new NotImportedEmail();
         // Clean from previous collect (from GUI, cron already truncate the table)
         $rejected->deleteByCriteria(array('mailcollectors_id' => $this->fields['id']));
         if ($this->marubox) {
             // Get Total Number of Unread Email in mail box
             $tot = $this->getTotalMails();
             //Total Mails in Inbox Return integer value
             $error = 0;
             $refused = 0;
             $blacklisted = 0;
             for ($i = 1; $i <= $tot && $this->fetch_emails < $this->maxfetch_emails; $i++) {
                 $tkt = $this->buildTicket($i, array('mailgates_id' => $mailgateID, 'play_rules' => true));
                 toolbox::logdebug("tkt", $tkt);
                 //Indicates that the mail must be deleted from the mailbox
                 $delete_mail = false;
                 //If entity assigned, or email refused by rule, or no user and no supplier associated with the email
                 $user_condition = $CFG_GLPI["use_anonymous_helpdesk"] || isset($tkt['_users_id_requester']) && $tkt['_users_id_requester'] > 0 || isset($tkt['_supplier_email']) && $tkt['_supplier_email'];
                 $rejinput = array();
                 $rejinput['mailcollectors_id'] = $mailgateID;
                 if (!$tkt['_blacklisted']) {
                     $rejinput['from'] = $tkt['_head']['from'];
                     $rejinput['to'] = $tkt['_head']['to'];
                     $rejinput['users_id'] = $tkt['_users_id_requester'];
                     $rejinput['subject'] = $this->textCleaner($tkt['_head']['subject']);
                     $rejinput['messageid'] = $tkt['_head']['message_id'];
                 }
                 $rejinput['date'] = $_SESSION["glpi_currenttime"];
                 // Manage blacklisted emails
                 if (isset($tkt['_blacklisted']) && $tkt['_blacklisted']) {
                     $this->deleteMails($i, self::REFUSED_FOLDER);
                     $blacklisted++;
                     // entities_id set when new ticket / tickets_id when new followup
                 } else {
                     if ((isset($tkt['entities_id']) || isset($tkt['tickets_id'])) && $user_condition || isset($tkt['_refuse_email_no_response']) || isset($tkt['_refuse_email_with_response'])) {
                         if (isset($tkt['_refuse_email_with_response'])) {
                             $this->sendMailRefusedResponse($tkt['_head']['from'], $tkt['name']);
                             $delete_mail = self::REFUSED_FOLDER;
                             $refused++;
                         } else {
                             if (isset($tkt['_refuse_email_no_response'])) {
                                 $delete_mail = self::REFUSED_FOLDER;
                                 $refused++;
                             } else {
                                 if (isset($tkt['entities_id']) || isset($tkt['tickets_id'])) {
                                     // Is a mail responding of an already existing ticket ?
                                     if (isset($tkt['tickets_id'])) {
                                         $fup = new TicketFollowup();
                                         if ($fup->add($tkt)) {
                                             $delete_mail = self::ACCEPTED_FOLDER;
                                         } else {
                                             $error++;
                                             $rejinput['reason'] = NotImportedEmail::FAILED_INSERT;
                                             $rejected->add($rejinput);
                                         }
                                     } else {
                                         // New ticket
                                         $track = new Ticket();
                                         if ($track->add($tkt)) {
                                             $delete_mail = self::ACCEPTED_FOLDER;
                                         } else {
                                             $error++;
                                             $rejinput['reason'] = NotImportedEmail::FAILED_INSERT;
                                             $rejected->add($rejinput);
                                         }
                                     }
                                 } else {
                                     // Case never raise
                                     $delete_mail = self::REFUSED_FOLDER;
                                     $refused++;
                                 }
                             }
                         }
                         //Delete Mail from Mail box if ticket is added successfully
                         if ($delete_mail) {
                             $this->deleteMails($i, $delete_mail);
                         }
                     } else {
                         if (!$tkt['_users_id_requester']) {
                             $rejinput['reason'] = NotImportedEmail::USER_UNKNOWN;
                         } else {
                             $rejinput['reason'] = NotImportedEmail::MATCH_NO_RULE;
                         }
                         $rejected->add($rejinput);
                     }
                 }
                 $this->fetch_emails++;
             }
             imap_expunge($this->marubox);
             $this->close_mailbox();
             //Close Mail Box
             //TRANS: %1$d, %2$d, %3$d, %4$d and %5$d are number of messages
             $msg = sprintf(__('Number of messages: available=%1$d, retrieved=%2$d, refused=%3$d, errors=%4$d, blacklisted=%5$d'), $tot, $this->fetch_emails, $refused, $error, $blacklisted);
             if ($display) {
                 Session::addMessageAfterRedirect($msg, false, $error ? ERROR : INFO);
             } else {
                 return $msg;
             }
         } else {
             $msg = __('Could not connect to mailgate server');
             if ($display) {
                 Session::addMessageAfterRedirect($msg, false, ERROR);
             } else {
                 return $msg;
             }
         }
     } else {
         //TRANS: %s is the ID of the mailgate
         $msg = sprintf(__('Could not find mailgate %d'), $mailgateID);
         if ($display) {
             Session::addMessageAfterRedirect($msg, false, ERROR);
         } else {
             return $msg;
         }
     }
 }
Пример #22
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;
 }