Пример #1
0
 public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     echo '<table class="tab_cadre_fixe">';
     echo '<tr>';
     echo '<th colspan="3">' . _n('Destinations', 'Destinations', 2, 'formcreator') . '</th>';
     echo '</tr>';
     $target_class = new PluginFormcreatorTarget();
     $found_targets = $target_class->find('plugin_formcreator_forms_id = ' . $item->getID());
     $target_number = count($found_targets);
     $token = Session::getNewCSRFToken();
     $i = 0;
     foreach ($found_targets as $target) {
         $i++;
         echo '<tr class="line' . $i % 2 . '">';
         echo '<td onclick="document.location=\'../front/targetticket.form.php?id=' . $target['items_id'] . '\'" style="cursor: pointer">';
         echo $target['name'];
         echo '</td>';
         echo '<td align="center" width="32">';
         echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/pencil.png"
               alt="*" title="' . __('Edit') . '"
               onclick="document.location=\'../front/targetticket.form.php?id=' . $target['items_id'] . '\'" align="absmiddle" style="cursor: pointer" /> ';
         echo '</td>';
         echo '<td align="center" width="32">';
         echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/delete.png"
               alt="*" title="' . __('Delete', 'formcreator') . '"
               onclick="deleteTarget(' . $item->getID() . ', \'' . $token . '\', ' . $target['id'] . ', \'' . addslashes($target['name']) . '\')" align="absmiddle" style="cursor: pointer" /> ';
         echo '</td>';
         echo '</tr>';
     }
     // Display add target link...
     echo '<tr class="line' . ($i + 1) % 2 . '" id="add_target_row">';
     echo '<td colspan="3">';
     echo '<a href="javascript:addTarget(' . $item->getID() . ', \'' . $token . '\');">
             <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" />
             ' . __('Add a destination', 'formcreator') . '
         </a>';
     echo '</td>';
     echo '</tr>';
     // OR display add target form
     echo '<tr class="line' . ($i + 1) % 2 . '" id="add_target_form" style="display: none;">';
     echo '<td colspan="3" id="add_target_form_td"></td>';
     echo '</tr>';
     echo "</table>";
 }
Пример #2
0
 public function generateTarget()
 {
     // Get all targets
     $target_class = new PluginFormcreatorTarget();
     $found_targets = $target_class->find('plugin_formcreator_forms_id = ' . $this->fields['plugin_formcreator_forms_id']);
     // Generate targets
     foreach ($found_targets as $target) {
         $obj = new $target['itemtype']();
         $obj->getFromDB($target['items_id']);
         if (!$obj->save($this)) {
             return false;
         }
     }
     return true;
 }
Пример #3
0
<?php

include "../../../inc/includes.php";
Session::checkRight("entity", UPDATE);
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $target = new PluginFormcreatorTarget();
    // Add a new target
    if (isset($_POST["add"]) && !empty($_POST['plugin_formcreator_forms_id'])) {
        Session::checkRight("entity", UPDATE);
        $target->add($_POST);
        Html::back();
        // Delete a target
    } elseif (isset($_POST["delete_target"])) {
        Session::checkRight("entity", UPDATE);
        $target->delete($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
    } else {
        Html::back();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}
Пример #4
0
 function showFormEdit($params, $options = array())
 {
     global $LANG, $CFG_GLPI;
     if ($params['id'] > 0) {
         $this->check($params['id'], 'r');
     } else {
         // Create item
         $this->check(-1, 'w');
     }
     echo "<form method='POST' \n      action='" . $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/section.form.php'>";
     echo "<input type='hidden' name='plugin_formcreator_forms_id' \n            value='" . $this->fields['plugin_formcreator_forms_id'] . "' />";
     echo "<input type='hidden' name='id' \n            value='" . $this->fields['id'] . "' />";
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe fix_tab_height'>";
     echo "<tr>";
     echo "<th colspan='2'>" . $LANG['plugin_formcreator']["target"][1] . "</th>";
     echo "<th colspan='2'>&nbsp;</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $LANG['plugin_formcreator']["target"][8] . "&nbsp;:</td><td>";
     PluginFormcreatorTarget::getSelectTarget($this->fields['plugin_formcreator_forms_id'], 'plugin_formcreator_targets_id', $this->fields['plugin_formcreator_targets_id']);
     echo "</td>";
     echo "<td>" . __('Name') . "&nbsp;:</td>";
     echo "<td>";
     echo '<input type="text" name="name" value="' . $this->fields['name'] . '" size="54"/>';
     echo "</td>";
     echo "</tr>";
     echo '<tr class="tab_bg_1">';
     echo '<td>' . $LANG['plugin_formcreator']["question"][11] . ' :</td>';
     echo '<td><input type="text" name="position" 
                        value="' . $this->fields['position'] . '" size="3" /></td>';
     echo "<td>" . __('Description') . "&nbsp;:</td>";
     echo "<td>";
     echo "<textarea name='content' cols='55' rows='6'>";
     echo $this->fields["content"];
     echo "</textarea>";
     echo "</td>";
     echo '</tr>';
     echo "<tr>";
     echo "<td class='center' colspan='2'>";
     echo "<input class='submit' type='submit' value='" . __('Update') . "' name='update'>";
     echo "</td>";
     echo "<td class='center' colspan='2'>";
     echo "<input class='submit' type='submit' value='" . __('Purge') . "' name='delete'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "</div>";
     Html::closeForm();
 }
Пример #5
0
<?php

include "../../../inc/includes.php";
Session::checkRight("entity", UPDATE);
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $target = new PluginFormcreatorTarget();
    // Add a new target
    if (isset($_POST["add"]) && !empty($_POST['plugin_formcreator_forms_id'])) {
        Session::checkRight("entity", UPDATE);
        $target->add($_POST);
        Html::back();
        // Delete a target
    } elseif (isset($_POST["delete_target"])) {
        Session::checkRight("entity", UPDATE);
        $target->delete($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
    } elseif (isset($_GET['id'])) {
        $target->getFromDB($_GET['id']);
        Html::redirect(Toolbox::getItemTypeFormURL($target->fields['itemtype']) . '?id=' . $_GET['id']);
    } else {
        Html::back();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}
        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 {
        Html::header(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF'], 'admin', 'PluginFormcreatorForm');
        $itemtype = "PluginFormcreatorTargetTicket";
        $target = new PluginFormcreatorTarget();
        $found = $target->find("itemtype = '{$itemtype}' AND items_id = " . (int) $_REQUEST['id']);
        $first = array_shift($found);
        $form = new PluginFormcreatorForm();
        $form->getFromDB($first['plugin_formcreator_forms_id']);
        $_SESSION['glpilisttitle'][$itemtype] = sprintf(__('%1$s = %2$s'), $form->getTypeName(1), $form->getName());
        $_SESSION['glpilisturl'][$itemtype] = $form->getFormURL() . "?id=" . $form->getID();
        $targetticket->display($_REQUEST);
        Html::footer();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}
Пример #7
0
<?php

include "../../../inc/includes.php";
Session::checkRight("config", "w");
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $target = new PluginFormcreatorTarget();
    // Add a new target
    if (isset($_POST["add"]) && !empty($_POST['plugin_formcreator_forms_id'])) {
        $target->check(-1, 'w', $_POST);
        if ($target->add($_POST)) {
            switch ($_POST['itemtype']) {
                case 'PluginFormcreatorTargetTicket':
                    Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/targetticket.form.php?id=' . $target->fields['items_id']);
                    break;
                default:
                    Html::back();
                    break;
            }
        } else {
            Html::back();
        }
        // Delete a target
    } elseif (isset($_POST["delete"])) {
        $target->check($_POST['id'], 'd');
        $target->delete($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
    } else {
        Html::back();
    }
Пример #8
0
        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`                         = \"{$actor_value}\",\n                  `use_notification`                    = \"{$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 {
        Html::header(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF'], 'admin', 'PluginFormcreatorForm');
        $itemtype = "PluginFormcreatorTargetTicket";
        $target = new PluginFormcreatorTarget();
        $found = $target->find("itemtype = '{$itemtype}' AND items_id = '" . $_REQUEST['id'] . "'");
        $first = array_shift($found);
        $form = new PluginFormcreatorForm();
        $form->getFromDB($first['plugin_formcreator_forms_id']);
        $_SESSION['glpilisttitle'][$itemtype] = sprintf(__('%1$s = %2$s'), $form->getTypeName(1), $form->getName());
        $_SESSION['glpilisturl'][$itemtype] = $form->getFormURL() . "?id=" . $form->getID();
        $targetticket->display($_REQUEST);
        Html::footer();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}
Пример #9
0
    public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
    {
        echo '<table class="tab_cadre_fixe">';
        echo '<tr>';
        echo '<th colspan="3">' . _n('Destinations', 'Destinations', 2, 'formcreator') . '</th>';
        echo '</tr>';
        $target_class = new PluginFormcreatorTarget();
        $founded_targets = $target_class->find('plugin_formcreator_forms_id = ' . $item->getID());
        $target_number = count($founded_targets);
        $i = 0;
        foreach ($founded_targets as $target) {
            $i++;
            echo '<tr class="line' . $i % 2 . '">';
            echo '<td onclick="document.location=\'../front/targetticket.form.php?id=' . $target['items_id'] . '\'" style="cursor: pointer">';
            echo $target['name'];
            echo '</td>';
            echo '<td align="center" width="32">';
            echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/pencil.png"
                  alt="*" title="' . __('Edit') . '"
                  onclick="document.location=\'../front/targetticket.form.php?id=' . $target['items_id'] . '\'" align="absmiddle" style="cursor: pointer" /> ';
            echo '</td>';
            echo '<td align="center" width="32">';
            echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/delete.png"
                  alt="*" title="' . __('Delete', 'formcreator') . '"
                  onclick="deleteTarget(' . $target['id'] . ', \'' . addslashes($target['name']) . '\')" align="absmiddle" style="cursor: pointer" /> ';
            echo '</td>';
            echo '</tr>';
        }
        // Display add target link...
        echo '<tr class="line' . ($i + 1) % 2 . '" id="add_target_row">';
        echo '<td colspan="3">';
        echo '<a href="javascript:addTarget(' . $item->fields['id'] . ');">
                <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" />
                ' . __('Add a destination', 'formcreator') . '
            </a>';
        echo '</td>';
        echo '</tr>';
        // OR display add target form
        echo '<tr class="line' . ($i + 1) % 2 . '" id="add_target_form" style="display: none;">';
        echo '<td colspan="3" id="add_target_form_td"></td>';
        echo '</tr>';
        echo "</table>";
        echo '<script type="text/javascript">
               function addTarget(form) {
                  document.getElementById("add_target_form").style.display = "table-row";
                  document.getElementById("add_target_row").style.display = "none";
                  Ext.get("add_target_form_td").load({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/ajax/target.php",
                     scripts: true,
                     params: "form_id=" + ' . $item->getId() . '
                  });
               }

               function cancelAddTarget() {
                  document.getElementById("add_target_row").style.display = "table-row";
                  document.getElementById("add_target_form").style.display = "none";
               }

               function deleteTarget(target_id, target_name) {
                  if(confirm("' . __('Are you sure you want to delete this destination:', 'formcreator') . ' " + target_name)) {
                     Ext.Ajax.request({
                        url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/target.form.php",
                        success: reloadTab,
                        params: {
                           delete: 1,
                           id: target_id,
                           plugin_formcreator_forms_id: ' . $item->getId() . ',
                           _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                        }
                     });
                  }
               }
            </script>';
    }
 /**
  * Show the Form edit form the the adminsitrator in the config page
  *
  * @param  Array  $options Optional options
  *
  * @return NULL         Nothing, just display the form
  */
 public function showForm($options = array())
 {
     if (!$this->getFromDB($options['id'])) {
         Html::displayNotFoundError();
     }
     $obj = new PluginFormcreatorTarget();
     $founded = $obj->find('itemtype = "' . __CLASS__ . '" AND items_id = ' . $this->getID());
     $target = array_shift($founded);
     echo '<form name="form_target" method="post" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="5">' . __('Edit a destination', 'formcreator') . '</th></tr>';
     echo '<tr class="line1">';
     echo '<td width="20%"><strong>' . __('Name') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td width="70%" colspan="4"><input type="text" name="name" style="width:650px;" value="' . $target['name'] . '"></textarea</td>';
     echo '</tr>';
     echo '<tr><td colspan="5">&nbsp;</td></tr>';
     echo '<tr><th colspan="5">' . _n('Target ticket', 'Target tickets', 1, 'formcreator') . '</th></tr>';
     echo '<tr class="line1">';
     echo '<td width="20%"><strong>' . __('Ticket title', 'formcreator') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td width="70%" colspan="4"><input type="text" name="title" style="width:650px;" value="' . $this->fields['name'] . '"></textarea</td>';
     echo '</tr>';
     echo '<tr class="line0">';
     echo '<td width="20%"><strong>' . __('Description') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td width="70%" colspan="4"><textarea name="comment" style="width:646px;" rows="15">' . $this->fields['comment'] . '</textarea></td>';
     echo '</tr>';
     echo '<tr class="line1">';
     echo '<td width="20%">' . _n('Ticket template', 'Ticket templates', 1) . '</td>';
     echo '<td width="70%" colspan="4">';
     Dropdown::show('TicketTemplate', array('name' => 'tickettemplates_id', 'value' => $this->fields['tickettemplates_id']));
     echo '</td>';
     echo '</tr>';
     echo '<tr><td colspan="5">&nbsp;</td></tr>';
     echo '<tr><th colspan="5">' . __('List of available tags') . '</th></tr>';
     echo '<tr>';
     echo '<th width="40%" colspan="2">' . _n('Question', 'Questions', 1, 'formcreator') . '</th>';
     echo '<th width="20%">' . __('Title') . '</th>';
     echo '<th width="20%">' . __('Answer', 'formcreator') . '</th>';
     echo '<th width="20%">' . _n('Section', 'Sections', 1, 'formcreator') . '</th>';
     echo '</tr>';
     echo '<tr class="line0">';
     echo '<td colspan="2"><strong>' . __('Full form', 'formcreator') . '</strong></td>';
     echo '<td align="center"><code>-</code></td>';
     echo '<td align="center"><code><strong>##FULLFORM##</strong></code></td>';
     echo '<td align="center">-</td>';
     echo '</tr>';
     $table_questions = getTableForItemType('PluginFormcreatorQuestion');
     $table_sections = getTableForItemType('PluginFormcreatorSection');
     $query = "SELECT q.`id`, q.`name` AS question, s.`name` AS section\n                FROM {$table_questions} q\n                LEFT JOIN {$table_sections} s ON q.`plugin_formcreator_sections_id` = s.`id`\n                WHERE s.`plugin_formcreator_forms_id` = " . $target['plugin_formcreator_forms_id'] . "\n                ORDER BY s.`order`, q.`order`";
     $result = $GLOBALS['DB']->query($query);
     $i = 0;
     while ($question = $GLOBALS['DB']->fetch_array($result)) {
         $i++;
         echo '<tr class="line' . $i % 2 . '">';
         echo '<td colspan="2">' . $question['question'] . '</td>';
         echo '<td align="center"><code>##question_' . $question['id'] . '##</code></td>';
         echo '<td align="center"><code>##answer_' . $question['id'] . '##</code></td>';
         echo '<td align="center">' . $question['section'] . '</td>';
         echo '</tr>';
     }
     echo '<tr class="line' . ++$i % 2 . '"><td colspan="5">&nbsp;</td></tr>';
     echo '<tr class="line' . ++$i % 2 . '">';
     echo '<td colspan="5" class="center">';
     echo '<input type="reset" name="reset" class="submit_button" value="' . __('Cancel', 'formcreator') . '"
            onclick="document.location = \'form.form.php?id=' . $target['plugin_formcreator_forms_id'] . '\'" /> &nbsp; ';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="submit" name="update" class="submit_button" value="' . __('Save') . '" />';
     echo '</td>';
     echo '</tr>';
     echo '</table>';
     Html::closeForm();
 }
Пример #11
0
 function createDefaultTarget($formID)
 {
     global $LANG;
     $target = new PluginFormcreatorTarget();
     $defaultTarget['name'] = $LANG['plugin_formcreator']["default"]["target"][0];
     $defaultTarget['content'] = $LANG['plugin_formcreator']["default"]["target"][1];
     $defaultTarget['plugin_formcreator_forms_id'] = $formID;
     $targetID = $target->add($defaultTarget);
     return $targetID;
 }
 /**
  * Show the Form edit form the the adminsitrator in the config page
  *
  * @param  Array  $options Optional options
  *
  * @return NULL         Nothing, just display the form
  */
 public function showForm($options = array())
 {
     $rand = mt_rand();
     $obj = new PluginFormcreatorTarget();
     $found = $obj->find("itemtype = '" . __CLASS__ . "' AND items_id = " . (int) $this->getID());
     $target = array_shift($found);
     $form = new PluginFormcreatorForm();
     $form->getFromDB($target['plugin_formcreator_forms_id']);
     echo '<div class="center" style="width: 950px; margin: 0 auto;">';
     echo '<form name="form_target" method="post" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     // General information : name
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="2">' . __('Edit a destination', 'formcreator') . '</th></tr>';
     echo '<tr class="line1">';
     echo '<td width="15%"><strong>' . __('Name') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td width="85%"><input type="text" name="name" style="width:704px;" value="' . $target['name'] . '"></textarea</td>';
     echo '</tr>';
     echo '</table>';
     // Ticket information : title, template...
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="4">' . _n('Target ticket', 'Target tickets', 1, 'formcreator') . '</th></tr>';
     echo '<tr class="line1">';
     echo '<td><strong>' . __('Ticket title', 'formcreator') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td colspan="3"><input type="text" name="title" style="width:704px;" value="' . $this->fields['name'] . '"></textarea</td>';
     echo '</tr>';
     echo '<tr class="line0">';
     echo '<td><strong>' . __('Description') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td colspan="3">';
     echo '<textarea name="comment" style="width:700px;" rows="15">' . $this->fields['comment'] . '</textarea>';
     if ($GLOBALS['CFG_GLPI']["use_rich_text"]) {
         Html::initEditorSystem('comment');
     }
     echo '</td>';
     echo '</tr>';
     // Ticket Template
     echo '<tr class="line1">';
     echo '<td width="15%">' . _n('Ticket template', 'Ticket templates', 1) . '</td>';
     echo '<td width="25%">';
     Dropdown::show('TicketTemplate', array('name' => 'tickettemplates_id', 'value' => $this->fields['tickettemplates_id']));
     echo '</td>';
     echo '<td width="15%">' . __('Due date') . '</td>';
     echo '<td width="45%">';
     // -------------------------------------------------------------------------------------------
     // Due date type selection
     // -------------------------------------------------------------------------------------------
     Dropdown::showFromArray('due_date_rule', array('' => Dropdown::EMPTY_VALUE, 'answer' => __('equals to the answer to the question', 'formcreator'), 'ticket' => __('calculated from the ticket creation date', 'formcreator'), 'calcul' => __('calculated from the answer to the question', 'formcreator')), array('value' => $this->fields['due_date_rule'], 'on_change' => 'formcreatorChangeDueDate(this.value)'));
     // for each section ...
     $questions_list = array(Dropdown::EMPTY_VALUE);
     $query = "SELECT s.id, s.name\n                FROM glpi_plugin_formcreator_targets t\n                INNER JOIN glpi_plugin_formcreator_sections s ON s.plugin_formcreator_forms_id = t.plugin_formcreator_forms_id\n                WHERE t.items_id = " . (int) $this->getID() . "\n                ORDER BY s.order";
     $result = $GLOBALS['DB']->query($query);
     while ($section = $GLOBALS['DB']->fetch_array($result)) {
         // select all date and datetime questions
         $query2 = "SELECT q.id, q.name\n                   FROM glpi_plugin_formcreator_questions q\n                   INNER JOIN glpi_plugin_formcreator_sections s ON s.id = q.plugin_formcreator_sections_id\n                   WHERE s.id = {$section['id']}\n                   AND q.fieldtype IN ('date', 'datetime')";
         $result2 = $GLOBALS['DB']->query($query2);
         $section_questions = array();
         while ($question = $GLOBALS['DB']->fetch_array($result2)) {
             $section_questions[$question['id']] = $question['name'];
         }
         if (count($section_questions) > 0) {
             $questions_list[$section['name']] = $section_questions;
         }
     }
     // List questions
     if ($this->fields['due_date_rule'] != 'answer' && $this->fields['due_date_rule'] != 'calcul') {
         echo '<div id="due_date_questions" style="display:none">';
     } else {
         echo '<div id="due_date_questions">';
     }
     Dropdown::showFromArray('due_date_question', $questions_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     if ($this->fields['due_date_rule'] != 'ticket' && $this->fields['due_date_rule'] != 'calcul') {
         echo '<div id="due_date_time" style="display:none">';
     } else {
         echo '<div id="due_date_time">';
     }
     Dropdown::showNumber("due_date_value", array('value' => $this->fields['due_date_value'], 'min' => -30, 'max' => 30));
     Dropdown::showFromArray('due_date_period', array('minute' => _n('Minute', 'Minutes', 2), 'hour' => _n('Hour', 'Hours', 2), 'day' => _n('Day', 'Days', 2), 'month' => __('Month')), array('value' => $this->fields['due_date_period']));
     echo '</div>';
     echo '</td>';
     echo '</tr>';
     // -------------------------------------------------------------------------------------------
     // Due date type selection end
     // -------------------------------------------------------------------------------------------
     if ($form->fields['validation_required']) {
         echo '<tr class="line0">';
         echo '<td colspan="4">';
         echo '<input type="hidden" name="validation_followup" value="0" />';
         echo '<input type="checkbox" name="validation_followup" id="validation_followup" value="1" ';
         if (!isset($this->fields['validation_followup']) || $this->fields['validation_followup'] == 1) {
             echo ' checked="checked"';
         }
         echo '/>';
         echo ' <label for="validation_followup">';
         echo __('Add validation message as first ticket followup', 'formcreator');
         echo '</label>';
         echo '</td>';
         echo '</tr>';
     }
     echo '</table>';
     // Buttons
     echo '<table class="tab_cadre_fixe">';
     echo '<tr class="line1">';
     echo '<td colspan="5" class="center">';
     echo '<input type="reset" name="reset" class="submit_button" value="' . __('Cancel', 'formcreator') . '"
            onclick="document.location = \'form.form.php?id=' . $target['plugin_formcreator_forms_id'] . '\'" /> &nbsp; ';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="submit" name="update" class="submit_button" value="' . __('Save') . '" />';
     echo '</td>';
     echo '</tr>';
     echo '</table>';
     Html::closeForm();
     // Get available questions for actors lists
     $questions_user_list = array(Dropdown::EMPTY_VALUE);
     $questions_group_list = array(Dropdown::EMPTY_VALUE);
     $questions_supplier_list = array(Dropdown::EMPTY_VALUE);
     $query = "SELECT s.id, s.name\n                FROM glpi_plugin_formcreator_targets t\n                INNER JOIN glpi_plugin_formcreator_sections s ON s.plugin_formcreator_forms_id = t.plugin_formcreator_forms_id\n                WHERE t.items_id = " . (int) $this->getID() . "\n                ORDER BY s.order";
     $result = $GLOBALS['DB']->query($query);
     while ($section = $GLOBALS['DB']->fetch_array($result)) {
         // select all user, group or supplier questions (GLPI Object)
         $query2 = "SELECT q.id, q.name, q.values\n                   FROM glpi_plugin_formcreator_questions q\n                   INNER JOIN glpi_plugin_formcreator_sections s ON s.id = q.plugin_formcreator_sections_id\n                   WHERE s.id = {$section['id']}\n                   AND q.fieldtype = 'glpiselect'\n                   AND q.values IN ('User', 'Group', 'Supplier')";
         $result2 = $GLOBALS['DB']->query($query2);
         $section_questions_user = array();
         $section_questions_group = array();
         $section_questions_supplier = array();
         while ($question = $GLOBALS['DB']->fetch_array($result2)) {
             switch ($question['values']) {
                 case 'User':
                     $section_questions_user[$question['id']] = $question['name'];
                     break;
                 case 'Group':
                     $section_questions_group[$question['id']] = $question['name'];
                     break;
                 case 'Supplier':
                     $section_questions_supplier[$question['id']] = $question['name'];
                     break;
             }
         }
         $questions_user_list[$section['name']] = $section_questions_user;
         $questions_group_list[$section['name']] = $section_questions_group;
         $questions_supplier_list[$section['name']] = $section_questions_supplier;
     }
     // Get available questions for actors lists
     $actors = array('requester' => array(), 'observer' => array(), 'assigned' => array());
     $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)) {
         $actors[$actor['actor_role']][$actor['id']] = array('actor_type' => $actor['actor_type'], 'actor_value' => $actor['actor_value'], 'use_notification' => $actor['use_notification']);
     }
     $img_user = '******' . __('User') . '" title="' . __('User') . '" width="20" />';
     $img_group = '<img src="../../../pics/groupes.png" alt="' . __('Group') . '" title="' . __('Group') . '" width="20" />';
     $img_supplier = '<img src="../../../pics/supplier.png" alt="' . __('Supplier') . '" title="' . __('Supplier') . '" width="20" />';
     $img_mail = '<img src="../pics/email.png" alt="' . __('Yes') . '" title="' . __('Email followup') . ' ' . __('Yes') . '" />';
     $img_nomail = '<img src="../pics/email-no.png" alt="' . __('No') . '" title="' . __('Email followup') . ' ' . __('No') . '" />';
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="3">' . __('Ticket actors', 'formcreator') . '</th></tr>';
     echo '<tr>';
     echo '<th width="33%">';
     echo _n('Requester', 'Requesters', 1) . ' &nbsp;';
     echo '<img title="Ajouter" alt="Ajouter" onclick="displayRequesterForm()" class="pointer"
            id="btn_add_requester" src="../../../pics/add_dropdown.png">';
     echo '<img title="Annuler" alt="Annuler" onclick="hideRequesterForm()" class="pointer"
            id="btn_cancel_requester" src="../../../pics/delete.png" style="display:none">';
     echo '</th>';
     echo '<th width="34%">';
     echo _n('Watcher', 'Watchers', 1) . ' &nbsp;';
     echo '<img title="Ajouter" alt="Ajouter" onclick="displayWatcherForm()" class="pointer"
            id="btn_add_watcher" src="../../../pics/add_dropdown.png">';
     echo '<img title="Annuler" alt="Annuler" onclick="hideWatcherForm()" class="pointer"
            id="btn_cancel_watcher" src="../../../pics/delete.png" style="display:none">';
     echo '</th>';
     echo '<th width="33%">';
     echo __('Assigned to') . ' &nbsp;';
     echo '<img title="Ajouter" alt="Ajouter" onclick="displayAssignedForm()" class="pointer"
            id="btn_add_assigned" src="../../../pics/add_dropdown.png">';
     echo '<img title="Annuler" alt="Annuler" onclick="hideAssignedForm()" class="pointer"
            id="btn_cancel_assigned" src="../../../pics/delete.png" style="display:none">';
     echo '</th>';
     echo '</tr>';
     echo '<tr>';
     // Requester
     echo '<td valign="top">';
     // => Add requester form
     echo '<form name="form_target" id="form_add_requester" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorRequester(this.value)'));
     echo '<div id="block_requester_user" style="display:none">';
     User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0));
     echo '</div>';
     echo '<div id="block_requester_group" style="display:none">';
     Group::dropdown(array('name' => 'actor_value_group'));
     echo '</div>';
     echo '<div id="block_requester_question_user" style="display:none">';
     Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_requester_question_group" style="display:none">';
     Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div>';
     echo __('Email followup');
     Dropdown::showYesNo('use_notification', 1);
     echo '</div>';
     echo '<p align="center">';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="hidden" name="actor_role" value="requester" />';
     echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
     echo '</p>';
     echo "<hr>";
     Html::closeForm();
     // => List of saved requesters
     foreach ($actors['requester'] as $id => $values) {
         echo '<div>';
         switch ($values['actor_type']) {
             case 'creator':
                 echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>';
                 break;
             case 'validator':
                 echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>';
                 break;
             case 'person':
                 $user = new User();
                 $user->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"';
                 break;
             case 'question_person':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'group':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_group':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
         }
         echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
         echo self::getDeleteImage($id);
         echo '</div>';
     }
     echo '</td>';
     // Observer
     echo '<td valign="top">';
     // => Add observer form
     echo '<form name="form_target" id="form_add_watcher" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorWatcher(this.value)'));
     echo '<div id="block_watcher_user" style="display:none">';
     User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0));
     echo '</div>';
     echo '<div id="block_watcher_group" style="display:none">';
     Group::dropdown(array('name' => 'actor_value_group'));
     echo '</div>';
     echo '<div id="block_watcher_question_user" style="display:none">';
     Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_watcher_question_group" style="display:none">';
     Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div>';
     echo __('Email followup');
     Dropdown::showYesNo('use_notification', 1);
     echo '</div>';
     echo '<p align="center">';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="hidden" name="actor_role" value="observer" />';
     echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
     echo '</p>';
     echo "<hr>";
     Html::closeForm();
     // => List of saved observers
     foreach ($actors['observer'] as $id => $values) {
         echo '<div>';
         switch ($values['actor_type']) {
             case 'creator':
                 echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>';
                 break;
             case 'validator':
                 echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>';
                 break;
             case 'person':
                 $user = new User();
                 $user->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"';
                 break;
             case 'question_person':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'group':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_group':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
         }
         echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
         echo self::getDeleteImage($id);
         echo '</div>';
     }
     echo '</td>';
     // Assigned to
     echo '<td valign="top">';
     // => Add assigned to form
     echo '<form name="form_target" id="form_add_assigned" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator'), 'supplier' => __('Specific supplier', 'formcreator'), 'question_supplier' => __('Supplier from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorAssigned(this.value)'));
     echo '<div id="block_assigned_user" style="display:none">';
     User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0));
     echo '</div>';
     echo '<div id="block_assigned_group" style="display:none">';
     Group::dropdown(array('name' => 'actor_value_group'));
     echo '</div>';
     echo '<div id="block_assigned_supplier" style="display:none">';
     Supplier::dropdown(array('name' => 'actor_value_supplier'));
     echo '</div>';
     echo '<div id="block_assigned_question_user" style="display:none">';
     Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_assigned_question_group" style="display:none">';
     Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_assigned_question_supplier" style="display:none">';
     Dropdown::showFromArray('actor_value_question_supplier', $questions_supplier_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div>';
     echo __('Email followup');
     Dropdown::showYesNo('use_notification', 1);
     echo '</div>';
     echo '<p align="center">';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="hidden" name="actor_role" value="assigned" />';
     echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
     echo '</p>';
     echo "<hr>";
     Html::closeForm();
     // => List of saved assigned to
     foreach ($actors['assigned'] as $id => $values) {
         echo '<div>';
         switch ($values['actor_type']) {
             case 'creator':
                 echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>';
                 break;
             case 'validator':
                 echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>';
                 break;
             case 'person':
                 $user = new User();
                 $user->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"';
                 break;
             case 'question_person':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'group':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_group':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'supplier':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_supplier . ' <b>' . __('Supplier') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_supplier':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_supplier . ' <b>' . __('Supplier from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
         }
         echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
         echo self::getDeleteImage($id);
         echo '</div>';
     }
     echo '</td>';
     echo '</tr>';
     echo '</table>';
     // List of available tags
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="5">' . __('List of available tags') . '</th></tr>';
     echo '<tr>';
     echo '<th width="40%" colspan="2">' . _n('Question', 'Questions', 1, 'formcreator') . '</th>';
     echo '<th width="20%">' . __('Title') . '</th>';
     echo '<th width="20%">' . _n('Answer', 'Answers', 1, 'formcreator') . '</th>';
     echo '<th width="20%">' . _n('Section', 'Sections', 1, 'formcreator') . '</th>';
     echo '</tr>';
     echo '<tr class="line0">';
     echo '<td colspan="2"><strong>' . __('Full form', 'formcreator') . '</strong></td>';
     echo '<td align="center"><code>-</code></td>';
     echo '<td align="center"><code><strong>##FULLFORM##</strong></code></td>';
     echo '<td align="center">-</td>';
     echo '</tr>';
     $table_questions = getTableForItemType('PluginFormcreatorQuestion');
     $table_sections = getTableForItemType('PluginFormcreatorSection');
     $query = "SELECT q.`id`, q.`name` AS question, s.`name` AS section\n                FROM {$table_questions} q\n                LEFT JOIN {$table_sections} s ON q.`plugin_formcreator_sections_id` = s.`id`\n                WHERE s.`plugin_formcreator_forms_id` = " . $target['plugin_formcreator_forms_id'] . "\n                ORDER BY s.`order`, q.`order`";
     $result = $GLOBALS['DB']->query($query);
     $i = 0;
     while ($question = $GLOBALS['DB']->fetch_array($result)) {
         $i++;
         echo '<tr class="line' . $i % 2 . '">';
         echo '<td colspan="2">' . $question['question'] . '</td>';
         echo '<td align="center"><code>##question_' . $question['id'] . '##</code></td>';
         echo '<td align="center"><code>##answer_' . $question['id'] . '##</code></td>';
         echo '<td align="center">' . $question['section'] . '</td>';
         echo '</tr>';
     }
     echo '</table>';
     echo '</div>';
 }
Пример #13
0
 public function generateTarget()
 {
     // Get all targets
     $target_class = new PluginFormcreatorTarget();
     $found_targets = $target_class->find('plugin_formcreator_forms_id = ' . (int) $this->fields['plugin_formcreator_forms_id']);
     // Generate targets
     foreach ($found_targets as $target) {
         $obj = new $target['itemtype']();
         $obj->getFromDB($target['items_id']);
         if (!$obj->save($this)) {
             return false;
         }
     }
     Session::addMessageAfterRedirect(__('The form have been successfully saved!', 'formcreator'), true, INFO);
     return true;
 }
Пример #14
0
<?php

include '../../../inc/includes.php';
Session::checkLoginUser();
if (empty($_REQUEST["id"])) {
    $_REQUEST["id"] = "";
}
$form = new PluginFormcreatorTarget();
if (isset($_POST["add"])) {
    $form->check(-1, 'w', $_POST);
    $newID = $form->add($_POST);
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $form->check($_POST["id"], 'd');
        $form->delete($_POST);
        $form->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $form->check($_POST["id"], 'd');
            $form->restore($_POST);
            $form->redirectToList();
        } else {
            if (isset($_REQUEST["purge"])) {
                $form->check($_REQUEST["id"], 'd');
                $form->delete($_REQUEST, 1);
                $form->redirectToList();
            } else {
                if (isset($_POST["update"])) {
                    $form->check($_POST["id"], 'w');
                    $form->update($_POST);
Пример #15
0
     $form->delete($_POST);
     $formID = $_POST["id"];
     //suppresion question
     $question = new PluginFormcreatorQuestion();
     $listQuestion = $question->find("plugin_formcreator_forms_id = '{$formID}'");
     foreach ($listQuestion as $question_id => $values) {
         $question->delete($values);
     }
     //suppresion section
     $section = new PluginFormcreatorSection();
     $listSection = $section->find("plugin_formcreator_forms_id = '{$formID}'");
     foreach ($listSection as $section_id => $values) {
         $section->delete($values);
     }
     //suppression target
     $target = new PluginFormcreatorTarget();
     $listTarget = $target->find("plugin_formcreator_forms_id = '{$formID}'");
     foreach ($listTarget as $target_id => $values) {
         $target->delete($values);
     }
     $form->redirectToList();
 } else {
     if (isset($_POST["restore"])) {
         $form->check($_POST["id"], 'd');
         $form->restore($_POST);
         $form->redirectToList();
     } else {
         if (isset($_REQUEST["purge"])) {
             $form->check($_REQUEST["id"], 'd');
             $form->delete($_REQUEST, 1);
             $form->redirectToList();
Пример #16
0
 public function saveToTargets($datas)
 {
     $valid = true;
     // Validate form fields
     foreach ($_POST as $key => $value) {
         if (substr($key, 0, 18) == 'formcreator_field_') {
             $question_id = (int) substr($key, 18);
             $question = new PluginFormcreatorQuestion();
             $question->getFromDB($question_id);
             $className = $question->fields['fieldtype'] . 'Field';
             $filePath = dirname(__FILE__) . '/fields/' . $question->fields['fieldtype'] . '-field.class.php';
             if ($question->fields['fieldtype'] == 'float') {
                 $value = str_replace(',', '.', $datas['formcreator_field_' . $question_id]);
                 $datas['formcreator_field_' . $question_id] = $value;
             }
             if (is_file($filePath)) {
                 include_once $filePath;
                 if (class_exists($className)) {
                     if (!$className::isValid($question->fields, $value, $datas)) {
                         $valid = false;
                     }
                 }
             } else {
                 $valid = false;
             }
         }
     }
     // If not valid back to form
     if (!$valid) {
         $_SESSION['formcreator']['datas'] = $datas;
         Html::back();
         // Otherwize  generate targets
     } else {
         $_SESSION['formcreator_documents'] = array();
         // Save files as Documents
         foreach ($_FILES as $question_name => $file) {
             if (isset($file['tmp_name']) && is_file($file['tmp_name'])) {
                 $doc = new Document();
                 $question_id = trim(strrchr($question_name, '_'), '_');
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($question_id);
                 $file_datas = array();
                 $file_datas["name"] = $this->fields['name'] . ' - ' . $question->fields['name'];
                 $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $this->fields['entities_id'];
                 $file_datas["is_recursive"] = $this->fields['is_recursive'];
                 Document::uploadDocument($file_datas, $file);
                 if ($docID = $doc->add($file_datas)) {
                     $_SESSION['formcreator_documents'][] = $docID;
                     $table = getTableForItemType('Document');
                     $query = "UPDATE {$table} SET filename = '" . addslashes($file['name']) . "' WHERE id = " . $docID;
                     $GLOBALS['DB']->query($query);
                 }
             }
         }
         // Get all targets
         $target_class = new PluginFormcreatorTarget();
         $founded_targets = $target_class->find('plugin_formcreator_forms_id = ' . $this->getID());
         foreach ($founded_targets as $target) {
             $obj = new $target['itemtype']();
             $obj->getFromDB($target['items_id']);
             $obj->save($this, $datas);
         }
         Session::addMessageAfterRedirect(__('The form have been successfully saved!', 'formcreator'), true, INFO);
         unset($_SESSION['formcreator_documents']);
     }
 }