public function isValid($value)
 {
     // If the field is not visible, don't check it's value
     if (!PluginFormcreatorFields::isVisible($this->fields['id'], $this->fields['answer'])) {
         return true;
     }
     // If the field is required it can't be empty
     if ($this->isRequired() && strtotime($value) == '') {
         Session::addMessageAfterRedirect(__('A required field is empty:', 'formcreator') . ' ' . $this->getLabel(), false, ERROR);
         return false;
     }
     // All is OK
     return true;
 }
 public function isValid($value)
 {
     // If the field is not visible, don't check it's value
     if (!PluginFormcreatorFields::isVisible($this->fields['id'], $this->fields['answer'])) {
         return true;
     }
     // If the field is required it can't be empty
     if ($this->isRequired() && (empty($_FILES['formcreator_field_' . $this->fields['id']]['tmp_name']) || !is_file($_FILES['formcreator_field_' . $this->fields['id']]['tmp_name']))) {
         Session::addMessageAfterRedirect(__('A required file is missing:', 'formcreator') . ' ' . $this->fields['name'], false, ERROR);
         return false;
     }
     // All is OK
     return true;
 }
示例#3
0
 /**
  * Get entire form to be inserted into a target content
  *
  * @return String                                    Full form questions and answers to be print
  */
 public function getFullForm()
 {
     $question_no = 0;
     $output = '';
     if ($GLOBALS['CFG_GLPI']['use_rich_text']) {
         $output .= '<h1>' . __('Form data', 'formcreator') . '</h1>';
     } else {
         $output .= __('Form data', 'formcreator') . PHP_EOL;
         $output .= '=================';
         $output .= PHP_EOL . PHP_EOL;
     }
     $section_class = new PluginFormcreatorSection();
     $find_sections = $section_class->find('plugin_formcreator_forms_id = ' . $this->fields['plugin_formcreator_forms_id'], '`order` ASC');
     $answer = new PluginFormcreatorAnswer();
     $answers = $answer->find('`plugin_formcreator_formanwers_id` = ' . $this->getID());
     $answers_values = array();
     foreach ($answers as $found_answer) {
         $answers_values[$found_answer['plugin_formcreator_question_id']] = $found_answer['answer'];
     }
     foreach ($find_sections as $section_line) {
         if ($GLOBALS['CFG_GLPI']['use_rich_text']) {
             $output .= '<h2>' . $section_line['name'] . '</h2>';
         } else {
             $output .= PHP_EOL . $section_line['name'] . PHP_EOL;
             $output .= '---------------------------------';
             $output .= PHP_EOL;
         }
         // Display all fields of the section
         $question = new PluginFormcreatorQuestion();
         $questions = $question->find('plugin_formcreator_sections_id = ' . $section_line['id'], '`order` ASC');
         foreach ($questions as $question_line) {
             $id = $question_line['id'];
             $name = $question_line['name'];
             $found = $answer->find('`plugin_formcreator_formanwers_id` = ' . $this->getID() . ' AND `plugin_formcreator_question_id` = ' . $id);
             if (!PluginFormcreatorFields::isVisible($question_line['id'], $answers_values)) {
                 continue;
             }
             if ($question_line['fieldtype'] != 'file' && $question_line['fieldtype'] != 'description') {
                 $question_no++;
                 if (count($found)) {
                     $datas = array_shift($found);
                     $value = $datas['answer'];
                 } else {
                     $value = '';
                 }
                 $output_value = PluginFormcreatorFields::getValue($question_line, $value);
                 if (in_array($question_line['fieldtype'], array('checkboxes', 'multiselect'))) {
                     if (is_array($value)) {
                         $output_value = PHP_EOL . " - " . implode(PHP_EOL . " - ", $value);
                     } elseif (is_array(json_decode($value))) {
                         $output_value = PHP_EOL . " - " . implode(PHP_EOL . " - ", json_decode($value));
                     } else {
                         $output_value = $value;
                     }
                 } elseif ($question_line['fieldtype'] == 'textarea') {
                     if ($GLOBALS['CFG_GLPI']['use_rich_text']) {
                         $output_value = '<br /><blockquote>' . $value . '</blockquote>';
                     } else {
                         $output_value = PHP_EOL . $value;
                     }
                 }
                 if ($GLOBALS['CFG_GLPI']['use_rich_text']) {
                     $output .= '<div>';
                     $output .= '<b>' . $question_no . ') ' . $question_line['name'] . ' : </b>';
                     $output .= $output_value;
                     $output .= '</div>';
                 } else {
                     $output .= $question_no . ') ' . $question_line['name'] . ' : ';
                     $output .= $output_value . PHP_EOL . PHP_EOL;
                 }
             }
         }
     }
     return $output;
 }
示例#4
0
 public function isRequired()
 {
     $is_visible = PluginFormcreatorFields::isVisible($this->fields['id'], $this->fields['answer']);
     return $is_visible && $this->fields['required'];
 }
示例#5
0
<?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);