public static function install(Migration $migration) { $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL DEFAULT '',\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Migration from previous version if (TableExists('glpi_plugin_formcreator_cats')) { $query = "INSERT IGNORE INTO `{$table}` (`id`, `name`)\n SELECT `id`,`name` FROM glpi_plugin_formcreator_cats"; $GLOBALS['DB']->query($query); $GLOBALS['DB']->query("DROP TABLE glpi_plugin_formcreator_cats"); } /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `name`, `comment`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = "UPDATE `{$table}` SET\n `name` = '" . plugin_formcreator_encode($line['name']) . "',\n `comment` = '" . plugin_formcreator_encode($line['comment']) . "'\n WHERE `id` = " . (int) $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } return true; }
/** * Database table installation for the item type * * @param Migration $migration * @return boolean True on success */ public static function install(Migration $migration) { $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create questions table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n `plugin_formcreator_forms_id` int(11) NOT NULL,\n `requester_id` int(11) NULL,\n `validator_id` int(11) NULL,\n `request_date` datetime NOT NULL,\n `status` enum('waiting', 'refused', 'accepted') NOT NULL DEFAULT 'waiting',\n `comment` text NULL DEFAULT NULL\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `comment`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `' . $table . '` SET `comment` = "' . plugin_formcreator_encode($line['comment']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } // Create standard search options $query = "INSERT IGNORE INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`, `users_id`) VALUES\n (NULL, '" . __CLASS__ . "', 2, 2, 0),\n (NULL, '" . __CLASS__ . "', 3, 3, 0),\n (NULL, '" . __CLASS__ . "', 4, 4, 0),\n (NULL, '" . __CLASS__ . "', 5, 5, 0),\n (NULL, '" . __CLASS__ . "', 6, 6, 0);"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); return true; }
while ($category = $GLOBALS['DB']->fetch_array($result)) { echo '<tr class="noHover"><th>' . $category['name'] . '</th></tr>'; $where = getEntitiesRestrictRequest("", $form_table, "", "", true, false); $table_fp = getTableForItemType('PluginFormcreatorFormprofiles'); $query_forms = "SELECT {$form_table}.id, {$form_table}.name, {$form_table}.description\n FROM {$form_table}\n WHERE {$form_table}.`plugin_formcreator_categories_id` = {$category['id']}\n AND {$form_table}.`is_active` = 1\n AND {$form_table}.`is_deleted` = 0\n AND ({$form_table}.`language` = '{$_SESSION['glpilanguage']}' OR {$form_table}.`language` = '')\n AND {$where}\n AND (`access_rights` != " . PluginFormcreatorForm::ACCESS_RESTRICTED . " OR {$form_table}.`id` IN (\n SELECT plugin_formcreator_forms_id\n FROM {$table_fp}\n WHERE plugin_formcreator_profiles_id = " . (int) $_SESSION['glpiactiveprofile']['id'] . "))\n ORDER BY {$form_table}.name ASC"; $result_forms = $GLOBALS['DB']->query($query_forms); $i = 0; while ($form = $GLOBALS['DB']->fetch_array($result_forms)) { $i++; echo '<tr class="line' . $i % 2 . ' tab_bg_' . ($i % 2 + 1) . '">'; echo '<td>'; echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/plus.png" alt="+" title="" onclick="showDescription(' . $form['id'] . ', this)" align="absmiddle" style="cursor: pointer">'; echo ' '; echo '<a href="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/showform.php?id=' . $form['id'] . '" title="' . plugin_formcreator_encode($form['description']) . '">' . $form['name'] . '</a></td>'; echo '</tr>'; echo '<tr id="desc' . $form['id'] . '" class="line' . $i % 2 . ' form_description">'; echo '<td><div>' . $form['description'] . ' </div></td>'; echo '</tr>'; } } echo '</table>'; echo '<br />'; echo '<script type="text/javascript"> function showDescription(id, img){ if(img.alt == "+") { img.alt = "-"; img.src = "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/moins.png"; document.getElementById("desc" + id).style.display = "table-row"; } else {
/** * Database table installation for the item type * * @param Migration $migration * @return boolean True on success */ public static function install(Migration $migration) { $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create questions table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_sections_id` int(11) NOT NULL,\n `fieldtype` varchar(30) NOT NULL DEFAULT 'text',\n `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `required` boolean NOT NULL DEFAULT FALSE,\n `show_empty` boolean NOT NULL DEFAULT FALSE,\n `default_values` text NULL,\n `values` text NULL,\n `range_min` varchar(10) NULL DEFAULT NULL,\n `range_max` varchar(10) NULL DEFAULT NULL,\n `description` text NOT NULL,\n `regex` varchar(255) NULL DEFAULT NULL,\n `order` int(11) NOT NULL DEFAULT '0',\n `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always'\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // Create questions conditions table (since 0.85-1.1) $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_questions_id` int(11) NOT NULL,\n `show_field` int(11) DEFAULT NULL,\n `show_condition` enum('==','!=','<','>','<=','>=') DEFAULT NULL,\n `show_value` varchar(255) DEFAULT NULL,\n `show_logic` enum('AND','OR','XOR') DEFAULT NULL\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { // Migration 0.83-1.0 => 0.85-1.0 if (!FieldExists($table, 'fieldtype', false)) { // Migration from previous version $query = "ALTER TABLE `{$table}`\n ADD `fieldtype` varchar(30) NOT NULL DEFAULT 'text',\n ADD `show_type` enum ('show', 'hide') NOT NULL DEFAULT 'show',\n ADD `show_field` int(11) DEFAULT NULL,\n ADD `show_condition` enum('equal','notequal','lower','greater') COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `show_value` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `required` tinyint(1) NOT NULL DEFAULT '0',\n ADD `show_empty` tinyint(1) NOT NULL DEFAULT '0',\n ADD `default_values` text COLLATE utf8_unicode_ci,\n ADD `values` text COLLATE utf8_unicode_ci,\n ADD `range_min` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `range_max` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `regex` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n CHANGE `content` `description` text COLLATE utf8_unicode_ci NOT NULL,\n CHANGE `position` `order` int(11) NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // order start from 1 instead of 0 $GLOBALS['DB']->query("UPDATE `{$table}` SET `order` = `order` + 1;") or die($GLOBALS['DB']->error()); // Match new type $query = "SELECT `id`, `type`, `data`, `option`\n FROM {$table}"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $datas = json_decode($line['data']); $options = json_decode($line['option']); $fieldtype = 'text'; $values = ''; $default = ''; $regex = ''; $required = 0; if (isset($datas->value) && !empty($datas->value)) { if (is_object($datas->value)) { foreach ($datas->value as $value) { if (!empty($value)) { $values .= urldecode($value) . "\r\n"; } } } else { $values .= urldecode($datas->value); } } switch ($line['type']) { case '1': $fieldtype = 'text'; if (isset($options->type)) { switch ($options->type) { case '2': $required = 1; break; case '3': $regex = '[[:alpha:]]'; break; case '4': $fieldtype = 'float'; break; case '5': $regex = urldecode($options->value); // Add leading and trailing regex marker (automaticaly added in V1) if (substr($regex, 0, 1) != '/') { $regex = '/' . $regex; } if (substr($regex, -1, 1) != '/') { $regex = $regex . '/'; } break; case '6': $fieldtype = 'email'; break; case '7': $fieldtype = 'date'; break; } } $default_values = $values; $values = ''; break; case '2': $fieldtype = 'select'; break; case '3': $fieldtype = 'checkboxes'; break; case '4': $fieldtype = 'textarea'; if (isset($options->type) && $options->type == 2) { $required = 1; } $default_values = $values; $values = ''; break; case '5': $fieldtype = 'file'; break; case '8': $fieldtype = 'select'; break; case '9': $fieldtype = 'select'; break; case '10': $fieldtype = 'dropdown'; break; default: $data = null; break; } $query_udate = 'UPDATE ' . $table . ' SET `fieldtype` = "' . $fieldtype . '", `values` = "' . htmlspecialchars($values) . '", `default_values` = "' . htmlspecialchars($default) . '", `regex` = "' . $regex . '", `required` = "' . $required . ' " WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_udate) or die($GLOBALS['DB']->error()); } $query = "ALTER TABLE `{$table}`\n DROP `type`,\n DROP `data`,\n DROP `option`,\n DROP `plugin_formcreator_forms_id`;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Migration 0.85-1.0 => 0.85-1.1 if (FieldExists($table, 'show_type', false)) { // Fix type of section ID if (!FieldExists('glpi_plugin_formcreator_questions', 'show_rule')) { $query = "ALTER TABLE `glpi_plugin_formcreator_questions`\n CHANGE `plugin_formcreator_sections_id` `plugin_formcreator_sections_id` INT NOT NULL,\n ADD `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always'"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Create new table for conditionnal show of questions $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_questions_id` int(11) NOT NULL,\n `show_field` int(11) DEFAULT NULL,\n `show_condition` enum('==','!=','<','>','<=','>=') DEFAULT NULL,\n `show_value` varchar(255) DEFAULT NULL,\n `show_logic` enum('AND','OR','XOR') DEFAULT NULL\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // Migrate date from "questions" table to "questions_conditions" table $query = "SELECT `id`, `show_type`, `show_field`, `show_condition`, `show_value`\n FROM {$table}"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { switch ($line['show_type']) { case 'hide': $show_rule = 'hidden'; break; default: $show_rule = 'always'; } switch ($line['show_condition']) { case 'notequal': $show_condition = '!='; break; case 'lower': $show_condition = '<'; break; case 'greater': $show_condition = '>'; break; default: $show_condition = '=='; } $line['show_value'] = addslashes($line['show_value']); $query_udate = "UPDATE `glpi_plugin_formcreator_questions` SET\n `show_rule` = '{$show_rule}'\n WHERE `id` = {$line['id']}"; $GLOBALS['DB']->query($query_udate) or die($GLOBALS['DB']->error()); $query_udate = "INSERT INTO `glpi_plugin_formcreator_questions_conditions` SET\n `plugin_formcreator_questions_id` = {$line['id']},\n `show_field` = '{$line['show_field']}',\n `show_condition` = '{$show_condition}',\n `show_value` = '{$line['show_value']}'"; $GLOBALS['DB']->query($query_udate) or die($GLOBALS['DB']->error()); } // Delete old fields $query = "ALTER TABLE `{$table}`\n DROP `show_type`,\n DROP `show_field`,\n DROP `show_condition`,\n DROP `show_value`;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ // Migrate "questions" table $query = "SELECT `id`, `name`, `values`, `default_values`, `description`\n FROM `glpi_plugin_formcreator_questions`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `glpi_plugin_formcreator_questions` SET `name` = "' . plugin_formcreator_encode($line['name']) . '", `values` = "' . plugin_formcreator_encode($line['values']) . '", `default_values` = "' . plugin_formcreator_encode($line['default_values']) . '", `description` = "' . plugin_formcreator_encode($line['description']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } // Migrate "question_conditions" table $query = "SELECT `id`, `show_value`\n FROM `glpi_plugin_formcreator_questions_conditions`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `glpi_plugin_formcreator_questions_conditions` SET `show_value` = "' . plugin_formcreator_encode($line['show_value']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } return true; }
/** * Database table installation for the item type * * @param Migration $migration * @return boolean True on success */ public static function install(Migration $migration) { $obj = new self(); $table = $obj->getTable(); // Create default request type $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';"; $result = $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); if ($GLOBALS['DB']->numrows($result) > 0) { list($requesttype) = $GLOBALS['DB']->fetch_array($result); } else { $query = "INSERT INTO `glpi_requesttypes` SET `name` = 'Formcreator';"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); $requesttype = $GLOBALS['DB']->insert_id(); } if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create Forms table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n `access_rights` tinyint(1) NOT NULL DEFAULT '1',\n `requesttype` int(11) NOT NULL DEFAULT '{$requesttype}',\n `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `description` varchar(255) COLLATE utf8_unicode_ci,\n `content` longtext COLLATE utf8_unicode_ci,\n `plugin_formcreator_categories_id` tinyint(3) UNSIGNED NOT NULL,\n `is_active` tinyint(1) NOT NULL DEFAULT '0',\n `language` varchar(5) COLLATE utf8_unicode_ci NOT NULL,\n `helpdesk_home` tinyint(1) NOT NULL DEFAULT '0',\n `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n `validation_required` tinyint(1) NOT NULL DEFAULT '0'\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { // Migration from previous version if (FieldExists($table, 'cat', false)) { $query = "ALTER TABLE `{$table}`\n CHANGE `cat` `plugin_formcreator_categories_id` tinyint(3) UNSIGNED NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query); } // Migration from previous version if (!FieldExists($table, 'validation_required', false)) { $query = "ALTER TABLE `{$table}`\n ADD `validation_required` tinyint(1) NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query); } // Migration from previous version if (!FieldExists($table, 'plugin_formcreator_categories_id', false)) { $query = "ALTER TABLE `{$table}`\n ADD `plugin_formcreator_categories_id` tinyint(3) UNSIGNED NOT NULL DEFAULT '1';"; $GLOBALS['DB']->query($query); } // Migration from previous version if (!FieldExists($table, 'requesttype', false)) { $query = "ALTER TABLE `{$table}`\n ADD `access_rights` tinyint(1) NOT NULL DEFAULT '1',\n ADD `requesttype` int(11) NOT NULL DEFAULT '{$requesttype}',\n ADD `description` varchar(255) COLLATE utf8_unicode_ci,\n ADD `helpdesk_home` tinyint(1) NOT NULL DEFAULT '0',\n ADD `is_deleted` tinyint(1) NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query); } /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `name`, `description`, `content`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `' . $table . '` SET `name` = "' . plugin_formcreator_encode($line['name']) . '", `description` = "' . plugin_formcreator_encode($line['description']) . '", `content` = "' . plugin_formcreator_encode($line['content']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } if (!TableExists('glpi_plugin_formcreator_formvalidators')) { $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_formvalidators` (\n `forms_id` int(11) NOT NULL,\n `users_id` int(11) NOT NULL,\n PRIMARY KEY (`forms_id`, `users_id`)\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Create standard search options $query = 'DELETE FROM `glpi_displaypreferences` WHERE `itemtype` = "PluginFormcreatorForm"'; $GLOBALS['DB']->query($query) or die("error deleting glpi_displaypreferences " . $GLOBALS['DB']->error()); $query = "INSERT IGNORE INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`, `users_id`) VALUES\n (NULL, '" . __CLASS__ . "', 30, 1, 0),\n (NULL, '" . __CLASS__ . "', 3, 2, 0),\n (NULL, '" . __CLASS__ . "', 10, 3, 0),\n (NULL, '" . __CLASS__ . "', 7, 4, 0),\n (NULL, '" . __CLASS__ . "', 8, 5, 0),\n (NULL, '" . __CLASS__ . "', 9, 6, 0);"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); return true; }
/** * Prepare input datas for updating the target ticket * * @param $input datas used to add the item * * @return the modified $input array **/ public function prepareInputForUpdate($input) { // Control fields values : // - name is required if (empty($input['title'])) { Session::addMessageAfterRedirect(__('The title cannot be empty!', 'formcreator'), false, ERROR); return array(); } // - comment is required if (empty($input['comment'])) { Session::addMessageAfterRedirect(__('The description cannot be empty!', 'formcreator'), false, ERROR); return array(); } $input['name'] = plugin_formcreator_encode($input['title']); if ($GLOBALS['CFG_GLPI']['use_rich_text']) { $input['comment'] = Html::entity_decode_deep($input['comment']); } return $input; }
/** * 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'] = 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 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)); } } // 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; }
/** * Database table installation for the item type * * @param Migration $migration * @return boolean True on success */ public static function install(Migration $migration) { $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create questions table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_formanwers_id` int(11) NOT NULL,\n `plugin_formcreator_question_id` int(11) NOT NULL,\n `answer` text NOT NULL\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { // Update field type from previous version (Need answer to be text since text can be WYSIWING). $query = "ALTER TABLE `{$table}` CHANGE `answer` `answer` text;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `answer`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = "UPDATE `{$table}` SET\n `answer` = '" . plugin_formcreator_encode($line['answer']) . "'\n WHERE `id` = " . (int) $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } return true; }
<?php include '../../../inc/includes.php'; $currentValues = json_decode(stripslashes($_POST['values']), true); foreach ($currentValues as &$value) { if (is_array($value)) { foreach ($value as &$sub_value) { $sub_value = plugin_formcreator_encode($sub_value); } } elseif (is_array(json_decode($value))) { $tab = json_decode($value); foreach ($tab as &$sub_value) { $sub_value = plugin_formcreator_encode($sub_value); } $value = json_encode($tab); } else { $value = plugin_formcreator_encode($value); } } $questionToShow = array(); foreach ($currentValues as $id => $value) { $questionToShow[$id] = PluginFormcreatorFields::isVisible($id, $currentValues); } echo json_encode($questionToShow);
public static function install(Migration $migration) { $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_forms_id` tinyint(1) NOT NULL,\n `itemtype` varchar(100) NOT NULL DEFAULT 'PluginFormcreatorTargetTicket',\n `items_id` int(11) NOT NULL DEFAULT 0,\n `name` varchar(255) NOT NULL DEFAULT ''\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // Migration from previous version } elseif (!FieldExists($table, 'itemtype', false)) { // Migration from version 1.5 to 1.6 if (!FieldExists($table, 'type', false)) { $query = "ALTER TABLE `{$table}`\n ADD `type` tinyint(1) NOT NULL default '2';"; $GLOBALS['DB']->query($query); } // Add new column for link with target items $query = "ALTER TABLE `{$table}`\n ADD `itemtype` varchar(100) NOT NULL DEFAULT 'PluginFormcreatorTargetTicket',\n ADD `items_id` int(11) NOT NULL DEFAULT 0;"; $GLOBALS['DB']->query($query); // Create ticket template for each configuration in DB $query = "SELECT t.`urgency`, t.`priority`, t.`itilcategories_id`, t.`type`, f.`entities_id`\n FROM `glpi_plugin_formcreator_targets` t, `glpi_plugin_formcreator_forms` f\n WHERE f.`id` = t.`plugin_formcreator_forms_id`\n GROUP BY t.`urgency`, t.`priority`, t.`itilcategories_id`, t.`type`, f.`entities_id`"; $result = $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); $i = 0; while ($ligne = $GLOBALS['DB']->fetch_array($result)) { $i++; $id = $ligne['urgency'] . $ligne['priority'] . $ligne['itilcategories_id'] . $ligne['type']; $template = new TicketTemplate(); $template_id = $template->add(array('name' => 'Template Formcreator ' . $i, 'entities_id' => $ligne['entities_id'], 'is_recursive' => 1)); $predefinedField = new TicketTemplatePredefinedField(); // Urgency if (!empty($ligne['urgency'])) { $predefinedField->add(array('tickettemplates_id' => $template_id, 'num' => 10, 'value' => $ligne['urgency'])); } // Priority if (!empty($ligne['priority'])) { $predefinedField->add(array('tickettemplates_id' => $template_id, 'num' => 3, 'value' => $ligne['priority'])); } // Category if (!empty($ligne['itilcategories_id'])) { $predefinedField->add(array('tickettemplates_id' => $template_id, 'num' => 7, 'value' => $ligne['itilcategories_id'])); } // Type if (!empty($ligne['type'])) { $predefinedField->add(array('tickettemplates_id' => $template_id, 'num' => 14, 'value' => $ligne['type'])); } $_SESSION["formcreator_tmp"]["ticket_template"]["{$id}"] = $template_id; } // Prepare Mysql CASE For each ticket template $mysql_case_template = "CASE CONCAT(`urgency`, `priority`, `itilcategories_id`, `type`)"; foreach ($_SESSION["formcreator_tmp"]["ticket_template"] as $id => $value) { $mysql_case_template .= " WHEN {$id} THEN {$value} "; } $mysql_case_template .= "END AS `tickettemplates_id`"; // Create Target ticket $version = plugin_version_formcreator(); $migration = new Migration($version['version']); require_once 'targetticket.class.php'; PluginFormcreatorTargetTicket::install($migration); $table_targetticket = getTableForItemType('PluginFormcreatorTargetTicket'); $query = "SELECT `id`, `name`, {$mysql_case_template}, `content` FROM `{$table}`;"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { // Insert target ticket $query_insert = 'INSERT INTO ' . $table_targetticket . ' SET `name` = "' . htmlspecialchars($line['name']) . '", `tickettemplates_id` = "' . (int) $line['tickettemplates_id'] . '", `comment` = "' . htmlspecialchars($line['content']) . '"'; $GLOBALS['DB']->query($query_insert); $targetticket_id = $GLOBALS['DB']->insert_id(); // Update target with target ticket id $query_update = 'UPDATE `' . $table . '` SET `items_id` = ' . (int) $targetticket_id . ' WHERE `id` = ' . (int) $line['id']; $GLOBALS['DB']->query($query_update); } // Remove useless column content $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `content`;"); /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `comment`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `' . $table . '` SET `comment` = "' . plugin_formcreator_encode($line['comment']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } return true; }
/** * Prepare input datas for adding the section * Check fields values and get the order for the new section * * @param $input datas used to add the item * * @return the modified $input array **/ public function prepareInputForAdd($input) { // Decode (if already encoded) and encode strings to avoid problems with quotes foreach ($input as $key => $value) { $input[$key] = plugin_formcreator_encode($value); } // Control fields values : // - name is required if (empty($input['name'])) { Session::addMessageAfterRedirect(__('The title is required', 'formcreato'), false, ERROR); return array(); } // Get next order $obj = new self(); $query = "SELECT MAX(`order`) AS `order`\n FROM `{$obj->getTable()}`\n WHERE `plugin_formcreator_forms_id` = {$input['plugin_formcreator_forms_id']}"; $result = $GLOBALS['DB']->query($query); $line = $GLOBALS['DB']->fetch_array($result); $input['order'] = $line['order'] + 1; return $input; }
/** * Prepare input datas for updating the form * * @param $input datas used to add the item * * @return the modified $input array **/ public function prepareInputForUpdate($input) { // Decode (if already encoded) and encode strings to avoid problems with quotes foreach ($input as $key => $value) { $input[$key] = plugin_formcreator_encode($value); } }