<?php include "../../../inc/includes.php"; Session::checkLoginUser(); $Plugin = new PluginFormcreatorForm(); $PluginItem = new PluginFormcreatorForm_Item(); if (isset($_POST["add"])) { } else { if (isset($_POST["agregarGrupo"])) { $listForm = $PluginItem->find("plugin_formcreator_forms_id = " . $_POST['peticion_id'] . " and items_id = " . $_POST['groups_id'] . " and itemtype = '" . $_POST['itemtype'] . "'"); if (empty($listForm)) { $input11 = array('plugin_formcreator_forms_id' => $_POST['peticion_id'], 'items_id' => $_POST['groups_id'], 'itemtype' => $_POST['itemtype']); $PluginItem->add($input11); } Html::back(); } else { Html::header(PluginFormcreatorForm::getTypeName(2), $_SERVER['PHP_SELF'], 'plugins', 'formcreator', 'form'); $form->display($_GET); //$form->showForm($_REQUEST["id"]); Html::footer(); } }
/** * Execute massive action for PluginFormcreatorFrom * * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $DB; switch ($ma->getAction()) { case 'Duplicate': foreach ($ids as $id) { if ($item->getFromDB($id) && $item->Duplicate()) { Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName())); $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { // Example of ko count $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } } //return; break; //[CRI] //[CRI] case "Pedido": if ($item->getType() == 'Ticket') { // [CRI] $Plugin = new PluginFormcreatorForm(); $PluginItem = new PluginFormcreatorForm_Item(); $Target = new PluginFormcreatorTarget(); $helpdesk = new PluginFormcreatorTargetTicket(); $input = $ma->getInput(); foreach ($ids as $key) { $listForm = $PluginItem->find("items_id = " . $key . " and itemtype = '" . $item->getType() . "'"); if (empty($listForm)) { $input11 = array('plugin_formcreator_forms_id' => $input['plugin_formcreator_forms_id'], 'items_id' => $key, 'itemtype' => $item->getType()); $PluginItem->add($input11); } else { foreach ($listForm as $form_id => $value) { $input12 = array('id' => $form_id); $input12['plugin_formcreator_forms_id'] = $input['plugin_formcreator_forms_id']; $input12['items_id'] = $key; $input12['itemtype'] = $item->getType(); $PluginItem->update($input12); } } //Actualizar Ticket PluginFormcreatorForm::fromcreatorDropUserAndGrouponTicket($key); // PluginFormcreatorForm::updateTicketFromForm($input['plugin_formcreator_forms_id'], $key); $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } } break; //parent::processMassiveActionsForOneItemtype($ma, $item, $ids); } }
/** * 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(); $formID = $formanswer->fields['plugin_formcreator_forms_id']; //[CRI] $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'] = plugin_formcreator_encode($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 = ' . $formanswer->fields['id'] . ' AND plugin_formcreator_question_id = ' . $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; } // Create the target ticket $ticketID = $ticket->add($datas); /* if (!$ticketID = $ticket->add($datas)) { return false; }*/ // Ajout des acteurs du 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 = ' . $actor['actor_value'] . ' AND plugin_formcreator_formanwers_id = ' . $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 = ' . $formanswer->getID()); if (count($found) > 0) { foreach ($found as $document) { $docItem->add(array('documents_id' => $document['documents_id'], 'itemtype' => 'Ticket', 'items_id' => $ticketID)); } } /*[CRI] Guardar el objeto ticket el grupo asignado desde el targets */ $slaticket = new Ticket(); $PluginItem = new PluginFormcreatorForm_Item(); print_r($form); if ($slaticket->getFromDB($ticketID)) { $slas_itemtype = $slaticket->getType(); $input11 = array('plugin_formcreator_forms_id' => $formID, 'items_id' => $ticketID, 'itemtype' => $slas_itemtype); $PluginItem->add($input11); } // 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); } }