Beispiel #1
0
 public function saveForm()
 {
     $valid = true;
     $tab_section = array();
     $sections = new PluginFormcreatorSection();
     $found_sections = $sections->find('`plugin_formcreator_forms_id` = ' . $this->getID());
     foreach ($found_sections as $id => $fields) {
         $tab_section[] = $id;
     }
     $questions = new PluginFormcreatorQuestion();
     $found_questions = $questions->find('`plugin_formcreator_sections_id` IN (' . implode(',', $tab_section) . ')');
     // Validate form fields
     foreach ($found_questions as $id => $fields) {
         // If field was not post, it's value is empty
         if (isset($_POST['formcreator_field_' . $id])) {
             $datas[$id] = is_array($_POST['formcreator_field_' . $id]) ? json_encode($_POST['formcreator_field_' . $id]) : $_POST['formcreator_field_' . $id];
             // Replace "," by "." if field is a float field and remove spaces
             if ($fields['fieldtype'] == 'float') {
                 $datas[$id] = str_replace(',', '.', $datas[$id]);
                 $datas[$id] = str_replace(' ', '', $datas[$id]);
             }
             unset($_POST['formcreator_field_' . $id]);
         } else {
             $datas[$id] = '';
         }
         $className = $fields['fieldtype'] . 'Field';
         $filePath = dirname(__FILE__) . '/fields/' . $fields['fieldtype'] . '-field.class.php';
         if (is_file($filePath)) {
             include_once $filePath;
             if (class_exists($className)) {
                 $obj = new $className($fields, $datas);
                 if (!$obj->isValid($datas[$id])) {
                     $valid = false;
                 }
             }
         } else {
             $valid = false;
         }
     }
     $datas = $datas + $_POST;
     // Check required_validator
     if ($this->fields['validation_required'] && empty($datas['formcreator_validator'])) {
         Session::addMessageAfterRedirect(__('You must select validator !', 'formcreator'), false, ERROR);
         $valid = false;
     }
     // If not valid back to form
     if (!$valid) {
         foreach ($datas as $key => $value) {
             if (is_array($value)) {
                 foreach ($value as $key2 => $value2) {
                     $datas[$key][$key2] = plugin_formcreator_encode($value2);
                 }
             } elseif (is_array(json_decode($value))) {
                 $value = json_decode($value);
                 foreach ($value as $key2 => $value2) {
                     $value[$key2] = plugin_formcreator_encode($value2);
                 }
                 $datas[$key] = json_encode($value);
             } else {
                 $datas[$key] = plugin_formcreator_encode($value);
             }
         }
         $_SESSION['formcreator']['datas'] = $datas;
         Html::back();
         // Save form
     } else {
         $formanswer = new PluginFormcreatorFormanswer();
         $formanswer->saveAnswers($datas);
     }
 }
include "../../../inc/includes.php";
Session::redirectIfNotLoggedIn();
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $formanswer = new PluginFormcreatorFormanswer();
    // Edit an existing target ticket
    if (isset($_POST['update'])) {
        $formanswer->update($_POST);
        Html::back();
    } elseif (isset($_POST['refuse_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'refused';
        $_POST['save_formanswer'] = true;
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
    } elseif (isset($_POST['accept_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'accepted';
        $_POST['save_formanswer'] = true;
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
    } elseif (isset($_POST['save_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'waiting';
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
        // Show target ticket form
    } else {
        if ($_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {