Exemplo n.º 1
0
 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\n                              `name` = \"{$line['name']}\",\n                              `tickettemplates_id` = \"{$line['tickettemplates_id']}\",\n                              `comment` = \"{$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` = {$targetticket_id} WHERE `id` = {$line['id']}";
             $GLOBALS['DB']->query($query_update);
         }
         // Remove useless column content
         $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `content`;");
     }
     return true;
 }
<?php

include "../../../inc/includes.php";
Session::checkRight("entity", UPDATE);
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $targetticket = new PluginFormcreatorTargetTicket();
    // Edit an existing target ticket
    if (isset($_POST["update"])) {
        Session::checkRight("entity", UPDATE);
        $target = new PluginFormcreatorTarget();
        $found = $target->find('items_id = ' . (int) $_POST['id']);
        $found = array_shift($found);
        $target->update(array('id' => $found['id'], 'name' => $name));
        $targetticket->update($_POST);
        Html::back();
    } elseif (isset($_POST['actor_role'])) {
        Session::checkRight("entity", UPDATE);
        $id = (int) $_POST['id'];
        $actor_value = isset($_POST['actor_value_' . $_POST['actor_type']]) ? $_POST['actor_value_' . $_POST['actor_type']] : '';
        $use_notification = $_POST['use_notification'] == 0 ? 0 : 1;
        $query = "INSERT INTO glpi_plugin_formcreator_targettickets_actors SET\n                  `plugin_formcreator_targettickets_id` = {$id},\n                  `actor_role`                          = '" . $_POST['actor_role'] . "',\n                  `actor_type`                          = '" . $_POST['actor_type'] . "',\n                  `actor_value`                         = " . (int) $actor_value . ",\n                  `use_notification`                    = " . (int) $use_notification;
        $DB->query($query);
        Html::back();
    } elseif (isset($_GET['delete_actor'])) {
        $query = "DELETE FROM glpi_plugin_formcreator_targettickets_actors\n                WHERE id = " . (int) $_GET['delete_actor'];
        $DB->query($query);
        Html::back();
        // Show target ticket form
    } else {
<?php

include "../../../inc/includes.php";
Session::checkRight("config", "w");
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $targetticket = new PluginFormcreatorTargetTicket();
    // Edit an existing target ticket
    if (isset($_POST["update"])) {
        $targetticket->check($_POST['id'], 'w');
        $targetticket->update($_POST);
        Html::back();
        // Show target ticket form
    } else {
        Html::header(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF'], 'plugins', 'formcreator', 'options');
        $targetticket->showForm($_REQUEST);
        Html::footer();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}