コード例 #1
0
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkLoginUser();
$item = new Item_Ticket();
if (isset($_POST["add"])) {
    if (isset($_POST['my_items']) && !empty($_POST['my_items'])) {
        list($_POST['itemtype'], $_POST['items_id']) = explode('_', $_POST['my_items']);
    }
    if (!isset($_POST['items_id']) || empty($_POST['items_id'])) {
        $message = sprintf(__('Mandatory fields are not filled. Please correct: %s'), _n('Associated element', 'Associated elements', 1));
        Session::addMessageAfterRedirect($message, false, ERROR);
        Html::back();
    }
    $item->check(-1, CREATE, $_POST);
    if ($item->add($_POST)) {
        Event::log($_POST["tickets_id"], "ticket", 4, "tracking", sprintf(__('%s adds a link with an item'), $_SESSION["glpiname"]));
    }
    Html::back();
}
Html::displayErrorAndDie("lost");
コード例 #2
0
ファイル: ticket.class.php プロジェクト: glpi-project/glpi
 function post_addItem()
 {
     global $CFG_GLPI;
     if (isset($this->input['content'])) {
         if (isset($this->input['_stock_image'])) {
             $this->addImagePaste();
         }
     }
     // Log this event
     $username = '******';
     if (isset($_SESSION["glpiname"])) {
         $username = $_SESSION["glpiname"];
     }
     Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s adds the item %2$s'), $username, $this->fields['id']));
     if (isset($this->input["_followup"]) && is_array($this->input["_followup"]) && strlen($this->input["_followup"]['content']) > 0) {
         $fup = new TicketFollowup();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id']);
         if (isset($this->input["_followup"]['content']) && strlen($this->input["_followup"]['content']) > 0) {
             $toadd["content"] = $this->input["_followup"]['content'];
         }
         if (isset($this->input["_followup"]['is_private'])) {
             $toadd["is_private"] = $this->input["_followup"]['is_private'];
         }
         // $toadd['_no_notif'] = true;
         $fup->add($toadd);
     }
     if (isset($this->input["plan"]) && count($this->input["plan"]) || isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $task = new TicketTask();
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         $toadd = array("type" => $type, "tickets_id" => $this->fields['id'], "actiontime" => $this->input["actiontime"]);
         if (isset($this->input["plan"]) && count($this->input["plan"])) {
             $toadd["plan"] = $this->input["plan"];
         }
         if (isset($_SESSION['glpitask_private'])) {
             $toadd['is_private'] = $_SESSION['glpitask_private'];
         }
         // $toadd['_no_notif'] = true;
         $task->add($toadd);
     }
     $ticket_ticket = new Ticket_Ticket();
     // From interface
     if (isset($this->input['_link'])) {
         $this->input['_link']['tickets_id_1'] = $this->fields['id'];
         // message if ticket's ID doesn't exist
         if (!empty($this->input['_link']['tickets_id_2'])) {
             if ($ticket_ticket->can(-1, CREATE, $this->input['_link'])) {
                 $ticket_ticket->add($this->input['_link']);
             } else {
                 Session::addMessageAfterRedirect(__('Unknown ticket'), false, ERROR);
             }
         }
     }
     // From mailcollector : do not check rights
     if (isset($this->input["_linkedto"])) {
         $input2['tickets_id_1'] = $this->fields['id'];
         $input2['tickets_id_2'] = $this->input["_linkedto"];
         $input2['link'] = Ticket_Ticket::LINK_TO;
         $ticket_ticket->add($input2);
     }
     // Manage SLT Level : add actions
     foreach (array(SLT::TTR, SLT::TTO) as $sltType) {
         list($dateField, $sltField) = SLT::getSltFieldNames($sltType);
         if (isset($this->input[$sltField]) && $this->input[$sltField] > 0) {
             $this->manageSltLevel($this->input[$sltField]);
         }
     }
     // Add project task link if needed
     if (isset($this->input['_projecttasks_id'])) {
         $projecttask = new ProjectTask();
         if ($projecttask->getFromDB($this->input['_projecttasks_id'])) {
             $pt = new ProjectTask_Ticket();
             $pt->add(array('projecttasks_id' => $this->input['_projecttasks_id'], 'tickets_id' => $this->fields['id']));
         }
     }
     if (!empty($this->input['items_id'])) {
         $item_ticket = new Item_Ticket();
         foreach ($this->input['items_id'] as $itemtype => $items) {
             foreach ($items as $items_id) {
                 $item_ticket->add(array('items_id' => $items_id, 'itemtype' => $itemtype, 'tickets_id' => $this->fields['id'], '_disablenotif' => true));
             }
         }
     }
     parent::post_addItem();
     $this->manageValidationAdd($this->input);
     // Processing Email
     if ($CFG_GLPI["use_mailing"]) {
         // Clean reload of the ticket
         $this->getFromDB($this->fields['id']);
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
     if (isset($_SESSION['glpiis_ids_visible']) && !$_SESSION['glpiis_ids_visible']) {
         Session::addMessageAfterRedirect(sprintf(__('%1$s (%2$s)'), __('Your ticket has been registered, its treatment is in progress.'), sprintf(__('%1$s: %2$s'), __('Ticket'), "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $this->fields['id'] . "'>" . $this->fields['id'] . "</a>")));
     }
 }
コード例 #3
0
 /**
  * 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;
 }