예제 #1
0
 /**
  * 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 new table
     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_forms_id` int(11) NOT NULL,\n                     `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n                     `order` int(11) 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 of special chars from previous versions
          *
          * @since 0.85-1.2.3
          */
         $query = "SELECT `id`, `name`\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']) . '"
                          WHERE `id` = ' . $line['id'];
             $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error());
         }
     }
     // Migration from previous version => Remove useless target field
     if (FieldExists($table, 'plugin_formcreator_targets_id', false)) {
         $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `plugin_formcreator_targets_id`;");
     }
     // Migration from previous version => Rename "position" into "order" and start order from 1 instead of 0
     if (FieldExists($table, 'position', false)) {
         $GLOBALS['DB']->query("ALTER TABLE `{$table}` CHANGE `position` `order` INT(11) NOT NULL DEFAULT '0';");
         $GLOBALS['DB']->query("UPDATE `{$table}` SET `order` = `order` + 1;");
     }
     // Migration from previous version => Update Question table, then create a "description" question from content
     if (FieldExists($table, 'content', false)) {
         $version = plugin_version_formcreator();
         $migration = new Migration($version['version']);
         PluginFormcreatorQuestion::install($migration);
         $table_questions = getTableForItemType('PluginFormcreatorQuestion');
         // Increment the order of questions which are in a section with a description
         $query = "UPDATE `{$table_questions}`\n                   SET `order` = `order` + 1\n                   WHERE `plugin_formcreator_sections_id` IN (\n                     SELECT `id`\n                     FROM {$table}\n                     WHERE `content` != ''\n                  );";
         $GLOBALS['DB']->query($query);
         // Create description from content
         $query = "INSERT INTO `{$table_questions}` (`plugin_formcreator_sections_id`, `fieldtype`, `name`, `description`, `order`)\n                     SELECT `id`, 'description' AS fieldtype, CONCAT('Description ', `id`) AS name,  `content`, 1 AS `order`\n                     FROM {$table}\n                     WHERE `content` != ''";
         $GLOBALS['DB']->query($query);
         // Delete content column
         $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `content`;");
     }
     return true;
 }
 /**
  * Parse target content to replace TAGS like ##FULLFORM## by the values
  *
  * @param  String $content                            String to be parsed
  * @param  PluginFormcreatorFormanswer $formanswer    Formanswer object where answers are stored
  * @return String                                     Parsed string with tags replaced by form values
  */
 private function parseTags($content, PluginFormcreatorFormanswer $formanswer)
 {
     $content = str_replace('##FULLFORM##', $formanswer->getFullForm(), $content);
     $section = new PluginFormcreatorSection();
     $found = $section->find('plugin_formcreator_forms_id = ' . (int) $formanswer->fields['plugin_formcreator_forms_id'], '`order` ASC');
     $tab_section = array();
     foreach ($found as $section_item) {
         $tab_section[] = $section_item['id'];
     }
     if (!empty($tab_section)) {
         $question = new PluginFormcreatorQuestion();
         $found = $question->find('plugin_formcreator_sections_id IN (' . implode(', ', $tab_section) . ')', '`order` ASC');
         foreach ($found as $question_line) {
             $id = $question_line['id'];
             $name = $question_line['name'];
             $answer = new PluginFormcreatorAnswer();
             $found = $answer->find('`plugin_formcreator_formanwers_id` = ' . (int) $formanswer->getID() . ' AND `plugin_formcreator_question_id` = ' . (int) $id);
             if (count($found)) {
                 $datas = array_shift($found);
                 $value = $datas['answer'];
             } else {
                 $value = '';
             }
             $value = PluginFormcreatorFields::getValue($question_line, $value);
             if (is_array($value)) {
                 if ($GLOBALS['CFG_GLPI']['use_rich_text']) {
                     $value = '<br />' . implode('<br />', $value);
                 } else {
                     $value = "\r\n" . implode("\r\n", $value);
                 }
             }
             $content = str_replace('##question_' . $id . '##', $name, $content);
             $content = str_replace('##answer_' . $id . '##', $value, $content);
         }
     }
     return $content;
 }
예제 #3
0
 static function popupContent($formID)
 {
     global $LANG;
     echo "<h1>" . $LANG['plugin_formcreator']["headings"][5] . "</h1>";
     //table code questions / réponses
     echo "<table class='tab_cadre_fixe fix_tab_height'>";
     echo "<tr>";
     echo "<th>" . $LANG['plugin_formcreator']["question"][2] . "</th>";
     echo "<th>" . __('Heading') . "</th>";
     echo "<th>" . $LANG['plugin_formcreator']["target"][6] . "</th>";
     echo "<th>" . $LANG['plugin_formcreator']["section"][3] . "</th>";
     echo "</tr>";
     $question = new PluginFormcreatorQuestion();
     $listQuestion = $question->find("plugin_formcreator_forms_id = '" . $formID . "' ORDER BY plugin_formcreator_sections_id, position");
     if (!empty($listQuestion)) {
         foreach ($listQuestion as $question_id => $value) {
             if ($value['type'] != '5' && $value['type'] != 6) {
                 echo "<tr>";
                 echo "<td>" . $value['name'] . "</td>";
                 echo "<td>##question_" . $value['id'] . "##</td>";
                 echo "<td>##answer_" . $value['id'] . "##</td>";
                 echo "<td>" . PluginFormcreatorSection::getSectionName($value['plugin_formcreator_sections_id']) . "</td>";
                 echo "</tr>";
             }
         }
     } else {
         echo "<tr>";
         echo "<td colspan='4' class='center'>" . $LANG['plugin_formcreator']["target"][7] . "</td>";
         echo "</tr>";
     }
     echo "</table><br/>";
 }
예제 #4
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;
 }
예제 #5
0
<?php

include '../../../inc/includes.php';
Session::checkRight("entity", UPDATE);
$question = new PluginFormcreatorQuestion();
if (empty($_REQUEST['question_id'])) {
    $question_id = 0;
    $question->getEmpty();
} else {
    $question_id = (int) $_REQUEST['question_id'];
    $question->getFromDB($question_id);
}
$form_id = (int) $_REQUEST['form_id'];
$rand = mt_rand();
?>

<form name="form_question" method="post"
      action="<?php 
echo $GLOBALS['CFG_GLPI']['root_doc'];
?>
/plugins/formcreator/front/question.form.php">

   <table class="tab_cadre_fixe">
      <tr>
         <th colspan="4">
            <?php 
echo 0 == $question_id ? __('Add a question', 'formcreator') : __('Edit a question', 'formcreator');
?>
         </th>
      </tr>
예제 #6
0
 /**
  * Display a list of all form sections and questions
  *
  * @param  CommonGLPI $item         Instance of a CommonGLPI Item (The Form Item)
  * @param  integer    $tabnum       Number of the current tab
  * @param  integer    $withtemplate
  *
  * @see CommonDBTM::displayTabContentForItem
  *
  * @return null                     Nothing, just display the list
  */
 public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     echo '<table class="tab_cadre_fixe">';
     // Get sections
     $section = new PluginFormcreatorSection();
     $found_sections = $section->find('plugin_formcreator_forms_id = ' . $item->getId(), '`order`');
     $section_number = count($found_sections);
     $tab_sections = array();
     $tab_questions = array();
     $token = Session::getNewCSRFToken();
     foreach ($found_sections as $section) {
         $tab_sections[] = $section['id'];
         echo '<tr id="section_row_' . $section['id'] . '">';
         echo '<th>' . $section['name'] . '</th>';
         echo '<th align="center" width="32">&nbsp;</th>';
         echo '<th align="center" width="32">';
         if ($section['order'] != 1) {
             echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/up2.png"
                  alt="*" title="' . __('Edit') . '"
                  onclick="moveSection(\'' . $token . '\', ' . $section['id'] . ', \'up\');" align="absmiddle" style="cursor: pointer" /> ';
         } else {
             echo '&nbsp;';
         }
         echo '</th>';
         echo '<th align="center" width="32">';
         if ($section['order'] != $section_number) {
             echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/down2.png"
                  alt="*" title="' . __('Edit') . '"
                  onclick="moveSection(\'' . $token . '\', ' . $section['id'] . ', \'down\');" align="absmiddle" style="cursor: pointer" /> ';
         } else {
             echo '&nbsp;';
         }
         echo '</th>';
         echo '<th align="center" width="32">';
         echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/pencil.png"
               alt="*" title="' . __('Edit') . '"
               onclick="editSection(' . $item->getId() . ', \'' . $token . '\', ' . $section['id'] . ')" align="absmiddle" style="cursor: pointer" /> ';
         echo '</th>';
         echo '<th align="center" width="32">';
         echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/delete.png"
               alt="*" title="' . __('Delete', 'formcreator') . '"
               onclick="deleteSection(' . $item->getId() . ', \'' . $token . '\', ' . $section['id'] . ', \'' . addslashes($section['name']) . '\')"
               align="absmiddle" style="cursor: pointer" /> ';
         echo '</th>';
         echo '</tr>';
         // Get questions
         $question = new PluginFormcreatorQuestion();
         $found_questions = $question->find('plugin_formcreator_sections_id = ' . $section['id'], '`order`');
         $question_number = count($found_questions);
         $i = 0;
         foreach ($found_questions as $question) {
             $i++;
             $tab_questions[] = $question['id'];
             echo '<tr class="line' . $i % 2 . '" id="question_row_' . $question['id'] . '">';
             echo '<td onclick="editQuestion(' . $item->getId() . ', \'' . $token . '\', ' . $question['id'] . ', ' . $section['id'] . ')" style="cursor: pointer">';
             echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/ui-' . $question['fieldtype'] . '-field.png" alt="" title="" /> ';
             echo $question['name'];
             echo '</td>';
             echo '<td align="center">';
             $question_type = $question['fieldtype'] . 'Field';
             $question_types = PluginFormcreatorFields::getTypes();
             $classname = $question['fieldtype'] . 'Field';
             $fields = $classname::getPrefs();
             // avoid quote js error
             $question['name'] = htmlspecialchars_decode($question['name'], ENT_QUOTES);
             if ($fields['required'] == 0) {
                 echo '&nbsp;';
             } elseif ($question['required']) {
                 echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/required.png"
                     alt="*" title="' . __('Required', 'formcreator') . '"
                     onclick="setRequired(\'' . $token . '\', ' . $question['id'] . ', 0)" align="absmiddle" style="cursor: pointer" /> ';
             } else {
                 echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/not-required.png"
                     alt="*" title="' . __('Required', 'formcreator') . '"
                     onclick="setRequired(\'' . $token . '\', ' . $question['id'] . ', 1)" align="absmiddle" style="cursor: pointer" /> ';
             }
             echo '</td>';
             echo '<td align="center">';
             if ($question['order'] != 1) {
                 echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/up.png"
                     alt="*" title="' . __('Edit') . '"
                     onclick="moveQuestion(\'' . $token . '\', ' . $question['id'] . ', \'up\');" align="absmiddle" style="cursor: pointer" /> ';
             } else {
                 echo '&nbsp;';
             }
             echo '</td>';
             echo '<td align="center">';
             if ($question['order'] != $question_number) {
                 echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/down.png"
                     alt="*" title="' . __('Edit') . '"
                     onclick="moveQuestion(\'' . $token . '\', ' . $question['id'] . ', \'down\');" align="absmiddle" style="cursor: pointer" /> ';
             } else {
                 echo '&nbsp;';
             }
             echo '</td>';
             echo '<td align="center">';
             echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/pencil.png"
                  alt="*" title="' . __('Edit') . '"
                  onclick="editQuestion(' . $item->getId() . ', \'' . $token . '\', ' . $question['id'] . ', ' . $section['id'] . ')" align="absmiddle" style="cursor: pointer" /> ';
             echo '</td>';
             echo '<td align="center">';
             echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/delete.png"
                  alt="*" title="' . __('Delete', 'formcreator') . '"
                  onclick="deleteQuestion(' . $item->getId() . ', \'' . $token . '\', ' . $question['id'] . ', \'' . addslashes($question['name']) . '\')" align="absmiddle" style="cursor: pointer" /> ';
             echo '</td>';
             echo '</tr>';
         }
         echo '<tr class="line' . ($i + 1) % 2 . '">';
         echo '<td colspan="6" id="add_question_td_' . $section['id'] . '" class="add_question_tds">';
         echo '<a href="javascript:addQuestion(' . $item->getId() . ', \'' . $token . '\', ' . $section['id'] . ');">
                <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" />
                ' . __('Add a question', 'formcreator') . '
            </a>';
         echo '</td>';
         echo '</tr>';
     }
     echo '<tr class="line1">';
     echo '<th colspan="6" id="add_section_th">';
     echo '<a href="javascript:addSection(' . $item->getId() . ', \'' . $token . '\');">
             <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" />
             ' . __('Add a section', 'formcreator') . '
         </a>';
     echo '</th>';
     echo '</tr>';
     echo "</table>";
     $js_tab_sections = "";
     $js_tab_questions = "";
     $js_line_questions = "";
     foreach ($tab_sections as $key) {
         $js_tab_sections .= "tab_sections[{$key}] = document.getElementById('section_row_{$key}').innerHTML;" . PHP_EOL;
         $js_tab_questions .= "tab_questions[{$key}] = document.getElementById('add_question_td_{$key}').innerHTML;" . PHP_EOL;
     }
     foreach ($tab_questions as $key) {
         $js_line_questions .= "line_questions[{$key}] = document.getElementById('question_row_{$key}').innerHTML;" . PHP_EOL;
     }
 }
    public static function show($field, $datas)
    {
        $default_values = explode("\r\n", $field['default_values']);
        $default_value = array_shift($default_values);
        $default_value = !empty($datas['formcreator_field_' . $field['id']]) ? $datas['formcreator_field_' . $field['id']] : $default_value;
        if ($field['required']) {
            $required = ' required';
        } else {
            $required = '';
        }
        $hide = $field['show_type'] == 'hide' ? ' style="display: none"' : '';
        echo '<div class="form-group' . $required . '" id="form-group-field' . $field['id'] . '"' . $hide . '>';
        echo '<label>';
        echo $field['name'];
        if ($field['required']) {
            echo ' <span class="red">*</span>';
        }
        echo '</label>';
        if (!empty($field['values'])) {
            $ldap_values = json_decode($field['values']);
            $ldap_dropdown = new RuleRightParameter();
            $ldap_dropdown->getFromDB($ldap_values->ldap_attribute);
            $attribute = array($ldap_dropdown->fields['value']);
            $config_ldap = new AuthLDAP();
            $config_ldap->getFromDB($ldap_values->ldap_auth);
            if (!function_exists('warning_handler')) {
                function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext)
                {
                    if (0 === error_reporting()) {
                        return false;
                    }
                    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
                }
            }
            set_error_handler("warning_handler", E_WARNING);
            try {
                $ds = $config_ldap->connect();
                $sn = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute);
                $entries = ldap_get_entries($ds, $sn);
                array_shift($entries);
                $tab_values = array();
                foreach ($entries as $id => $attr) {
                    if (isset($attr[$attribute[0]]) && !in_array($attr[$attribute[0]][0], $tab_values)) {
                        $tab_values[$id] = $attr[$attribute[0]][0];
                    }
                }
                if ($field['show_empty']) {
                    $tab_values = array('' => '-----') + $tab_values;
                }
                sort($tab_values);
                Dropdown::showFromArray('formcreator_field_' . $field['id'], $tab_values, array('value' => $default_value));
            } catch (Exception $e) {
                echo '<b><i class="red">';
                echo __('Cannot recover LDAP informations!', 'formcreator');
                echo '</i></b>';
            }
            restore_error_handler();
        }
        echo '<div class="help-block">' . html_entity_decode($field['description']) . '</div>';
        switch ($field['show_condition']) {
            case 'notequal':
                $condition = '!=';
                break;
            case 'lower':
                $condition = '<';
                break;
            case 'greater':
                $condition = '>';
                break;
            default:
                $condition = '==';
                break;
        }
        if ($field['show_type'] == 'hide') {
            $conditionnalField = new PluginFormcreatorQuestion();
            $conditionnalField->getFromDB($field['show_field']);
            switch ($conditionnalField->fields['fieldtype']) {
                case 'checkboxes':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]");

                  for(var i=0; inputElements[i]; ++i) {
                     inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  }

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
                    break;
                case 'multiselect':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]")[1];
                  inputElements.addEventListener("change", function(){showFormGroup' . $field['id'] . '()});

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].selected) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
                    break;
                case 'radios':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '");

                  for(var i=0; inputElements[i]; ++i) {
                     inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  }

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
                    break;
                default:
                    echo '<script type="text/javascript">
                  document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  function showFormGroup' . $field['id'] . '() {
                     var field_value = document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].value;
                     if(field_value ' . $condition . ' "' . $field['show_value'] . '") {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
            }
        }
        echo '</div>' . PHP_EOL;
    }
예제 #8
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);
     }
 }
예제 #9
0
     $question_name = "question_" . $question_id;
     $answer_name = "answer_" . $question_id;
     if (array_key_exists($question_name, $question)) {
         if (empty($question[$question_name])) {
             $ticket['content'] = str_replace("##{$question_name}##", " ", $ticket['content']);
             $ticket['content'] = str_replace("##{$answer_name}##", " ", $ticket['content']);
         } else {
             $ticket['content'] = str_replace("##{$question_name}##", $question_value['name'], $ticket['content']);
             $ticket['content'] = str_replace("##{$answer_name}##", $question[$question_name], $ticket['content']);
         }
         $ticket['name'] = str_replace("##{$question_name}##", $question_value['name'], $ticket['name']);
         $ticket['name'] = str_replace("##{$answer_name}##", $question[$question_name], $ticket['name']);
     }
 }
 $ticket['content'] = str_replace('##FULLFORM##', getFullForm($questions, $question, $ticket['content']), $ticket['content']);
 $ticket['content'] = PluginFormcreatorQuestion::protectData($ticket['content']);
 //modif yt pour prendre en compte valeurs prédéfinies du gabarit**********;
 $query = "SELECT `tickettemplates_id_incident`,`tickettemplates_id_demand` FROM `glpi_itilcategories` WHERE ID= " . $ticket['itilcategories_id'];
 $res = $DB->query($query);
 $tickettemplates_id_demand = $DB->result($res, 0, "tickettemplates_id_demand");
 $tickettemplates_id_incident = $DB->result($res, 0, "tickettemplates_id_incident");
 switch ($target_value['type']) {
     case "1":
         // formulaire par defaut pour les incidents de la catégorie;
         $template_id = $tickettemplates_id_incident;
         break;
     case "2":
         // formulaire par defaut pour les demandes de la catégorie;
         $template_id = $tickettemplates_id_demand;
         break;
     default:
예제 #10
0
<?php

$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '../../../');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
PluginFormcreatorQuestion::changeAddTypeQuestion($_REQUEST['value'], $_REQUEST['id']);
Html::ajaxFooter();
예제 #11
0
<?php

$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '../../../');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
$id = $_REQUEST['id'] + 1;
PluginFormcreatorQuestion::getMultiplication($id);
Html::ajaxFooter();
예제 #12
0
    $_REQUEST["id"] = "";
}
$form = new PluginFormcreatorForm();
if (isset($_POST["add"])) {
    $form->check(-1, 'w', $_POST);
    $newID = $form->add($_POST);
    $newTarget = $form->createDefaultTarget($newID);
    $newSection = $form->createDefaultSection($newID, $newTarget);
    Html::redirect($CFG_GLPI["root_doc"] . "/plugins/formcreator/front/form.form.php?id=" . $newID);
} else {
    if (isset($_POST["delete"])) {
        $form->check($_POST["id"], 'd');
        $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);
예제 #13
0
     echo $helpdesk->getNameRegexType($question_option['type']);
     //si il y a un controle sur le champ
     if ($question_option['type'] != 1) {
         //remplissage de la liste pour effectuer la vérification si le champ est non caché et obligatoire à la fois
         $question_option = json_decode($question_value['option'], true);
         $question_option_value = urldecode($question_option['value']);
         $listequestion .= "sec_" . $section_id . "::" . $question_id . "::" . $question_option_value . "::" . $question_value['name'] . "&&";
     }
 }
 if ($question_value['type'] == "7" || $question_value['type'] == "11") {
     //initialisation d'une variable pour savoir s'il y a un champ de multiplication de champ pour implémenter un champ total somme
     $boolMultiplication = 1;
 }
 if ($question_value['type'] == "8" || $question_value['type'] == "9" || $question_value['type'] == "4") {
     // section dynamique et question dynamique obligatoire
     $tab = PluginFormcreatorQuestion::_unserialize($question_value['data']);
     if (isset($tab["obli"]) && $tab["obli"] == "1") {
         $listequestion .= "sec_" . $section_id . "::" . $question_id . "::" . $question_value['name'] . "&&";
     }
 }
 $chaine = $question_value['content'];
 //remplacement lien url en BBCODE
 $chaine = preg_replace("#\\[url\\]((ht|f)tp://)([^\r\n\t<\"]*?)\\[/url\\]#sie", "'<a href=\"\\1' . str_replace(' ', '%20', '\\3') . '\">\\1\\3</a>'", $chaine);
 $chaine = preg_replace("/\\[url=(.+?)\\](.+?)\\[\\/url\\]/", "<a href=\"\$1\">\$2</a>", $chaine);
 //remplacement gras en BBCODE
 $chaine = str_replace("[b]", "<b>", $chaine);
 $chaine = str_replace("[/b]", "</b>", $chaine);
 //remplacement italique en BBCODE
 $chaine = str_replace("[i]", "<em>", $chaine);
 $chaine = str_replace("[/i]", "</em>", $chaine);
 //remplacement souligne en BBCODE
예제 #14
0
 public function getFullForm($datas)
 {
     $question_no = 0;
     $output = mb_strtoupper(__('Form data', 'formcreator'), 'UTF-8') . PHP_EOL;
     $output .= '=================';
     $output .= PHP_EOL . PHP_EOL;
     $section_class = new PluginFormcreatorSection();
     $find_sections = $section_class->find('plugin_formcreator_forms_id = ' . $this->getID(), '`order` ASC');
     foreach ($find_sections as $section_line) {
         $output .= $section_line['name'] . PHP_EOL;
         $output .= '---------------------------------';
         $output .= PHP_EOL . 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) {
             if ($question_line['fieldtype'] != 'file' && $question_line['fieldtype'] != 'description') {
                 $question_no++;
                 $id = $question_line['id'];
                 $name = $question_line['name'];
                 $value = isset($datas['formcreator_field_' . $id]) ? $datas['formcreator_field_' . $id] : '';
                 $value = PluginFormcreatorFields::getValue($question_line, $value);
                 $output .= $question_no . ') ' . $question_line['name'] . ' : ';
                 $output .= $value . PHP_EOL . PHP_EOL;
             }
         }
     }
     return $output;
 }
예제 #15
0
    /**
     * Display a list of all form sections and questions
     *
     * @param  CommonGLPI $item         Instance of a CommonGLPI Item (The Form Item)
     * @param  integer    $tabnum       Number of the current tab
     * @param  integer    $withtemplate
     *
     * @see CommonDBTM::displayTabContentForItem
     *
     * @return null                     Nothing, just display the list
     */
    public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
    {
        echo '<table class="tab_cadre_fixe">';
        // Get sections
        $section = new PluginFormcreatorSection();
        $founded_sections = $section->find('plugin_formcreator_forms_id = ' . $item->getId(), '`order`');
        $section_number = count($founded_sections);
        $tab_sections = array();
        $tab_questions = array();
        foreach ($founded_sections as $section) {
            $tab_sections[] = $section['id'];
            echo '<tr id="section_row_' . $section['id'] . '">';
            echo '<th>' . $section['name'] . '</th>';
            echo '<th align="center" width="32">&nbsp;</th>';
            echo '<th align="center" width="32">';
            if ($section['order'] != 1) {
                echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/up2.png"
                     alt="*" title="' . __('Edit') . '"
                     onclick="moveSection(' . $section['id'] . ', \'up\');" align="absmiddle" style="cursor: pointer" /> ';
            } else {
                echo '&nbsp;';
            }
            echo '</th>';
            echo '<th align="center" width="32">';
            if ($section['order'] != $section_number) {
                echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/down2.png"
                     alt="*" title="' . __('Edit') . '"
                     onclick="moveSection(' . $section['id'] . ', \'down\');" align="absmiddle" style="cursor: pointer" /> ';
            } else {
                echo '&nbsp;';
            }
            echo '</th>';
            echo '<th align="center" width="32">';
            echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/pencil.png"
                  alt="*" title="' . __('Edit') . '"
                  onclick="editSection(' . $section['id'] . ')" align="absmiddle" style="cursor: pointer" /> ';
            echo '</th>';
            echo '<th align="center" width="32">';
            echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/delete.png"
                  alt="*" title="' . __('Delete', 'formcreator') . '"
                  onclick="deleteSection(' . $section['id'] . ', \'' . addslashes($section['name']) . '\')"
                  align="absmiddle" style="cursor: pointer" /> ';
            echo '</th>';
            echo '</tr>';
            // Get questions
            $question = new PluginFormcreatorQuestion();
            $founded_questions = $question->find('plugin_formcreator_sections_id = ' . $section['id'], '`order`');
            $question_number = count($founded_questions);
            $i = 0;
            foreach ($founded_questions as $question) {
                $i++;
                $tab_questions[] = $question['id'];
                echo '<tr class="line' . $i % 2 . '" id="question_row_' . $question['id'] . '">';
                echo '<td onclick="editQuestion(' . $question['id'] . ', ' . $section['id'] . ')" style="cursor: pointer">';
                echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/ui-' . $question['fieldtype'] . '-field.png" alt="" title="" /> ';
                echo $question['name'];
                echo '</td>';
                echo '<td align="center">';
                $question_type = $question['fieldtype'] . 'Field';
                $question_types = PluginFormcreatorFields::getTypes();
                $classname = $question['fieldtype'] . 'Field';
                $fields = $classname::getPrefs();
                if ($fields['required'] == 0) {
                    echo '&nbsp;';
                } elseif ($question['required']) {
                    echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/required.png"
                        alt="*" title="' . __('Required', 'formcreator') . '"
                        onclick="setRequired(' . $question['id'] . ', 0)" align="absmiddle" style="cursor: pointer" /> ';
                } else {
                    echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/not-required.png"
                        alt="*" title="' . __('Required', 'formcreator') . '"
                        onclick="setRequired(' . $question['id'] . ', 1)" align="absmiddle" style="cursor: pointer" /> ';
                }
                echo '</td>';
                echo '<td align="center">';
                if ($question['order'] != 1) {
                    echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/up.png"
                        alt="*" title="' . __('Edit') . '"
                        onclick="moveQuestion(' . $question['id'] . ', \'up\');" align="absmiddle" style="cursor: pointer" /> ';
                } else {
                    echo '&nbsp;';
                }
                echo '</td>';
                echo '<td align="center">';
                if ($question['order'] != $question_number) {
                    echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/down.png"
                        alt="*" title="' . __('Edit') . '"
                        onclick="moveQuestion(' . $question['id'] . ', \'down\');" align="absmiddle" style="cursor: pointer" /> ';
                } else {
                    echo '&nbsp;';
                }
                echo '</td>';
                echo '<td align="center">';
                echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/pencil.png"
                     alt="*" title="' . __('Edit') . '"
                     onclick="editQuestion(' . $question['id'] . ', ' . $section['id'] . ')" align="absmiddle" style="cursor: pointer" /> ';
                echo '</td>';
                echo '<td align="center">';
                echo '<img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/pics/delete.png"
                     alt="*" title="' . __('Delete', 'formcreator') . '"
                     onclick="deleteQuestion(' . $question['id'] . ', \'' . addslashes($question['name']) . '\')" align="absmiddle" style="cursor: pointer" /> ';
                echo '</td>';
                echo '</tr>';
            }
            echo '<tr class="line' . ($i + 1) % 2 . '">';
            echo '<td colspan="6" id="add_question_td_' . $section['id'] . '" class="add_question_tds">';
            echo '<a href="javascript:addQuestion(' . $section['id'] . ');">
                   <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" />
                   ' . __('Add a question', 'formcreator') . '
               </a>';
            echo '</td>';
            echo '</tr>';
        }
        echo '<tr class="line1">';
        echo '<th colspan="6" id="add_section_th">';
        echo '<a href="javascript:addSection();" class="submit">
                <img src="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/pics/menu_add.png" alt="+" align="absmiddle" />
                ' . __('Add a section', 'formcreator') . '
            </a>';
        echo '</th>';
        echo '</tr>';
        echo "</table>";
        $js_tab_sections = "";
        $js_tab_questions = "";
        $js_line_questions = "";
        foreach ($tab_sections as $key) {
            $js_tab_sections .= "tab_sections[{$key}] = document.getElementById('section_row_{$key}').innerHTML;" . PHP_EOL;
            $js_tab_questions .= "tab_questions[{$key}] = document.getElementById('add_question_td_{$key}').innerHTML;" . PHP_EOL;
        }
        foreach ($tab_questions as $key) {
            $js_line_questions .= "line_questions[{$key}] = document.getElementById('question_row_{$key}').innerHTML;" . PHP_EOL;
        }
        echo '<script type="text/javascript">
               var modalWindow = new Ext.Window({
                  layout: "fit",
                  width: "964",
                  height: "600",
                  closeAction: "hide",
                  modal: "true",
                  autoScroll: true,
                  y: 500
               });


               // === QUESTIONS ===
               var tab_questions = [];
               ' . $js_tab_questions . '
               var line_questions = [];
               ' . $js_line_questions . '

               function addQuestion(section) {
                  modalWindow.show();
                  modalWindow.load({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/ajax/question.php",
                     params: {
                        section_id: section,
                        form_id: ' . $item->getId() . ',
                        _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                     },
                     timeout: 30,
                     scripts: true
                  });
               }

               function editQuestion(question, section) {
                  modalWindow.show();
                  modalWindow.load({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/ajax/question.php",
                     params: {
                        question_id: question,
                        section_id: section,
                        form_id: ' . $item->getId() . ',
                        _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                     },
                     timeout: 30,
                     scripts: true
                  });
               }

               function setRequired(question_id, value) {
                  Ext.Ajax.request({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/question.form.php",
                     success: reloadTab,
                     params: {
                        set_required: 1,
                        id: question_id,
                        value: value,
                        _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                     }
                  });
               }

               function moveQuestion(question_id, way) {
                  Ext.Ajax.request({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/question.form.php",
                     success: reloadTab,
                     params: {
                        move: 1,
                        id: question_id,
                        way: way,
                        _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                     }
                  });
               }

               function deleteQuestion(question_id, question_name) {
                  if(confirm("' . __('Are you sure you want to delete this question:', 'formcreator') . ' " + question_name)) {
                     Ext.Ajax.request({
                        url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/question.form.php",
                        success: reloadTab,
                        params: {
                           delete: 1,
                           id: question_id,
                           plugin_formcreator_forms_id: ' . $item->getId() . ',
                           _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                        }
                     });
                  }
               }

               // === SECTIONS ===
               var add_section_link = document.getElementById("add_section_th").innerHTML;

               var tab_sections = [];
               ' . $js_tab_sections . '

               function addSection() {
                  Ext.get("add_section_th").load({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/ajax/section.php",
                     scripts: true,
                     params: "form_id=' . $item->getId() . '"
                  });
               }

               function editSection(section) {
                  document.getElementById("section_row_" + section).innerHTML = "<th colspan=\\"6\\"></th>";
                  Ext.get("section_row_" + section + "").child("th").load({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/ajax/section.php",
                     scripts: true,
                     params: "section_id=" + section + "&form_id=' . $item->getId() . '"
                  });
               }

               function deleteSection(section_id, section_name) {
                  if(confirm("' . __('Are you sure you want to delete this section:', 'formcreator') . ' " + section_name)) {
                     Ext.Ajax.request({
                        url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/section.form.php",
                        success: reloadTab,
                        params: {
                           delete: 1,
                           id: section_id,
                           plugin_formcreator_forms_id: ' . $item->getId() . ',
                           _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                        }
                     });
                  }
               }

               function moveSection(section_id, way) {
                  Ext.Ajax.request({
                     url: "' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/section.form.php",
                     success: reloadTab,
                     params: {
                        move: 1,
                        id: section_id,
                        way: way,
                        _glpi_csrf_token: "' . Session::getNewCSRFToken() . '"
                     }
                  });
               }

               function resetAll() {
                  document.getElementById("add_section_th").innerHTML = add_section_link;
                  for (section_id in tab_sections) {
                     if(parseInt(section_id)) {
                        document.getElementById("section_row_" + section_id).innerHTML = tab_sections[section_id];
                        document.getElementById("add_question_td_" + section_id).innerHTML = tab_questions[section_id];
                     }
                  }
                  for (question_id in line_questions) {
                     if(parseInt(question_id)) {
                        document.getElementById("question_row_" + question_id).innerHTML = line_questions[question_id];
                     }
                  }
               }

            </script>';
    }
예제 #16
0
 static function getHomeHelpdeskListForm()
 {
     global $LANG, $CFG_GLPI;
     $form = new PluginFormcreatorForm();
     $listForm = $form->find("is_active = '1'");
     echo "<table style='float: right;'>";
     echo "<tr><td class='top' width='450px'>";
     echo '<table class="tab_cadrehov">';
     echo '<tr>';
     echo '<th>';
     echo '<div class="relative">' . $LANG['plugin_formcreator']["headings"][6] . '</div>';
     echo '</th>';
     echo '</tr>';
     $nbForm = 0;
     foreach ($listForm as $form_id => $value) {
         $question = new PluginFormcreatorQuestion();
         $listQuestion = $question->find("plugin_formcreator_forms_id = '" . $form_id . "'");
         if (!empty($listQuestion)) {
             if (Session::haveAccessToEntity($value['entities_id'], $value['is_recursive'])) {
                 $link = $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/form.helpdesk.php";
                 echo "<tr>";
                 echo '<td><a href=' . $link . '?form=' . $form_id . '>' . $value['name'] . '</a></td>';
                 echo "</tr>";
                 $nbForm++;
             }
         }
     }
     if (!$nbForm) {
         echo '<tr>';
         echo '<td class="center" colspan="3">' . $LANG['plugin_formcreator']["helpdesk"][1] . '</td>';
         echo '</tr>';
     }
     echo '</table>';
     echo "</td></tr>";
     echo "</table>";
 }
예제 #17
0
<?php

$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '../../../');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
$id = $_REQUEST['id'] + 1;
$formID = $_REQUEST['formID'];
PluginFormcreatorQuestion::getValueDynamic($formID, $id);
Html::ajaxFooter();
예제 #18
0
Session::checkLoginUser();
if (empty($_REQUEST["id"])) {
    $_REQUEST["id"] = "";
}
$form = new PluginFormcreatorSection();
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);
        $sectionID = $_POST["id"];
        //suppresion question
        $question = new PluginFormcreatorQuestion();
        $listQuestion = $question->find("plugin_formcreator_sections_id = '{$sectionID}'");
        foreach ($listQuestion as $question_id => $values) {
            $question->delete($values);
        }
        Html::back();
    } 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();
 private function parseTags($content, $form, $input)
 {
     $content = str_replace('##FULLFORM##', $form->getFullForm($input), $content);
     $section = new PluginFormcreatorSection();
     $founded = $section->find('plugin_formcreator_forms_id = ' . $form->getID(), '`order` ASC');
     $tab_section = array();
     foreach ($founded as $section_item) {
         $tab_section[] = $section_item['id'];
     }
     if (!empty($tab_section)) {
         $question = new PluginFormcreatorQuestion();
         $founded = $question->find('plugin_formcreator_sections_id IN (' . implode(', ', $tab_section) . ')', '`order` ASC');
         foreach ($founded as $question_line) {
             $id = $question_line['id'];
             $name = $question_line['name'];
             $value = isset($input['formcreator_field_' . $id]) ? $input['formcreator_field_' . $id] : '';
             $value = PluginFormcreatorFields::getValue($question_line, $value);
             $content = str_replace('##question_' . $id . '##', $name, $content);
             $content = str_replace('##answer_' . $id . '##', $value, $content);
         }
     }
     return $content;
 }
예제 #20
0
<?php

include '../../../inc/includes.php';
Session::checkLoginUser();
if (empty($_REQUEST["id"])) {
    $_REQUEST["id"] = "";
}
$form = new PluginFormcreatorQuestion();
if (isset($_POST["add"])) {
    $form->check(-1, 'w', $_POST);
    $result = PluginFormcreatorQuestion::getQuestionArray($_REQUEST);
    $newID = $form->add($result);
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $form->check($_POST["id"], 'd');
        $form->delete($_POST);
        Html::back();
    } 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');
예제 #21
0
<?php

$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '../../../');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
$valueId = $_REQUEST['valueId'];
$formID = $_REQUEST['formID'];
$valueIdSection = $_REQUEST['valueIdSection'] + 1;
PluginFormcreatorQuestion::getNextValueDynamicSection($formID, $valueId, $valueIdSection);
Html::ajaxFooter();
예제 #22
0
<?php

include "../../../inc/includes.php";
Session::checkRight("entity", UPDATE);
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $question = new PluginFormcreatorQuestion();
    // Add a new Question
    if (isset($_POST["add"])) {
        Session::checkRight("entity", UPDATE);
        if ($newid = $question->add($_POST)) {
            Session::addMessageAfterRedirect(__('The question have been successfully saved!', 'formcreator'), true, INFO);
            $_POST['id'] = $newid;
            $question->updateConditions($_POST);
        }
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Edit an existing Question
    } elseif (isset($_POST["update"])) {
        Session::checkRight("entity", UPDATE);
        if ($question->update($_POST)) {
            Session::addMessageAfterRedirect(__('The question have been successfully updated!', 'formcreator'), true, INFO);
            $question->updateConditions($_POST);
        }
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Delete a Question
    } elseif (isset($_POST["delete_question"])) {
        Session::checkRight("entity", UPDATE);
        $question->delete($_POST);
        // Set a Question required
    } elseif (isset($_POST["set_required"])) {
예제 #23
0
<?php

include "../../../inc/includes.php";
Session::checkRight("config", "w");
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $question = new PluginFormcreatorQuestion();
    // Add a new Question
    if (isset($_POST["add"])) {
        $question->check(-1, 'w', $_POST);
        if ($question->add($_POST)) {
            Session::addMessageAfterRedirect(__('The question have been successfully saved!', 'formcreator'), true, INFO);
        }
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Edit an existinf Question
    } elseif (isset($_POST["update"])) {
        $question->check($_POST['id'], 'w');
        if ($question->update($_POST)) {
            Session::addMessageAfterRedirect(__('The question have been successfully updated!', 'formcreator'), true, INFO);
        }
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Delete a Question
    } elseif (isset($_POST["delete"])) {
        $question->check($_POST['id'], 'd');
        $question->delete($_POST);
        // Set a Question required
    } elseif (isset($_POST["set_required"])) {
        global $DB;
        $question->check($_POST['id'], 'w');
        $table = getTableForItemtype('PluginFormcreatorQuestion');
예제 #24
0
<?php

$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '../../../');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
$id = $_REQUEST['id'] + 1;
$formID = $_REQUEST['formID'];
PluginFormcreatorQuestion::getValueSection($formID, $id);
Html::ajaxFooter();
    public static function show($field, $datas)
    {
        $value = !empty($datas['formcreator_field_' . $field['id']]) ? $datas['formcreator_field_' . $field['id']] : $field['default_values'];
        if ($field['required']) {
            $required = ' required';
        } else {
            $required = '';
        }
        $hide = $field['show_type'] == 'hide' ? ' style="display: none"' : '';
        echo '<div class="form-group' . $required . '" id="form-group-field' . $field['id'] . '"' . $hide . '>';
        echo '<label>';
        echo $field['name'];
        if ($field['required']) {
            echo ' <span class="red">*</span>';
        }
        echo '</label>';
        echo '<input type="text" class="form-control"
               name="formcreator_field_' . $field['id'] . '"
               id="formcreator_field_' . $field['id'] . '"
               value="' . $value . '" />';
        echo '<div class="help-block">' . html_entity_decode($field['description']) . '</div>';
        switch ($field['show_condition']) {
            case 'notequal':
                $condition = '!=';
                break;
            case 'lower':
                $condition = '<';
                break;
            case 'greater':
                $condition = '>';
                break;
            default:
                $condition = '==';
                break;
        }
        if ($field['show_type'] == 'hide') {
            $conditionnalField = new PluginFormcreatorQuestion();
            $conditionnalField->getFromDB($field['show_field']);
            switch ($conditionnalField->fields['fieldtype']) {
                case 'checkboxes':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]");

                  for(var i=0; inputElements[i]; ++i) {
                     inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  }

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
                    break;
                case 'multiselect':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]")[1];
                  inputElements.addEventListener("change", function(){showFormGroup' . $field['id'] . '()});

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].selected) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
                    break;
                case 'radios':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '");

                  for(var i=0; inputElements[i]; ++i) {
                     inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  }

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
                    break;
                default:
                    echo '<script type="text/javascript">
                  document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  function showFormGroup' . $field['id'] . '() {
                     var field_value = document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].value;
                     if(field_value ' . $condition . ' "' . $field['show_value'] . '") {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }
                  showFormGroup' . $field['id'] . '();
               </script>';
            }
        }
        echo '</div>' . PHP_EOL;
    }
예제 #26
0
<?php

$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '../../../');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
$id = $_REQUEST['id'] + 1;
PluginFormcreatorQuestion::getValue($id);
Html::ajaxFooter();
예제 #27
0
 /**
  * Check if a field should be shown or not
  *
  * @param   Integer     $id         ID of the current question
  * @param   Array       $values     Array of current fields values (id => value)
  * @return  boolean                 Should be shown or not
  */
 public static function isVisible($id, $values)
 {
     $question = new PluginFormcreatorQuestion();
     $question->getFromDB($id);
     $fields = $question->fields;
     $conditions = array();
     $return = false;
     // If the field is always shown
     if ($fields['show_rule'] == 'always') {
         return true;
     }
     // Get conditions to show or hide field
     $query = "SELECT `show_logic`, `show_field`, `show_condition`, `show_value`\n                FROM `glpi_plugin_formcreator_questions_conditions`\n                WHERE `plugin_formcreator_questions_id` = " . (int) $fields['id'];
     $result = $GLOBALS['DB']->query($query);
     while ($line = $GLOBALS['DB']->fetch_array($result)) {
         $conditions[] = array('multiple' => in_array($fields['fieldtype'], array('checkboxes', 'multiselect')), 'logic' => $line['show_logic'], 'field' => $line['show_field'], 'operator' => $line['show_condition'], 'value' => $line['show_value']);
     }
     foreach ($conditions as $condition) {
         if (!isset($values[$condition['field']])) {
             return false;
         }
         if (!self::isVisible($condition['field'], $values)) {
             return false;
         }
         switch ($condition['operator']) {
             case '!=':
                 if (empty($values[$condition['field']])) {
                     $value = true;
                 } else {
                     if (is_array($values[$condition['field']])) {
                         $value = !in_array($condition['value'], $values[$condition['field']]);
                     } elseif (!is_null(json_decode($values[$condition['field']]))) {
                         $value = !in_array($condition['value'], json_decode($values[$condition['field']]));
                     } else {
                         $value = $condition['value'] != $values[$condition['field']];
                     }
                 }
                 break;
             case '==':
                 if (empty($condition['value'])) {
                     $value = false;
                 } else {
                     if (is_array($values[$condition['field']])) {
                         $value = in_array($condition['value'], $values[$condition['field']]);
                     } elseif (!is_null(json_decode($values[$condition['field']]))) {
                         $value = in_array($condition['value'], json_decode($values[$condition['field']]));
                     } else {
                         $value = $condition['value'] == $values[$condition['field']];
                     }
                 }
                 break;
             default:
                 if (is_array($values[$condition['field']])) {
                     eval('$value = "' . $condition['value'] . '" ' . $condition['operator'] . ' Array(' . implode(',', $values[$condition['field']]) . ');');
                 } elseif (!is_null(json_decode($values[$condition['field']]))) {
                     eval('$value = "' . $condition['value'] . '" ' . $condition['operator'] . ' Array(' . implode(',', json_decode($values[$condition['field']])) . ');');
                 } else {
                     eval('$value = "' . $values[$condition['field']] . '" ' . $condition['operator'] . ' "' . $condition['value'] . '";');
                 }
         }
         switch ($condition['logic']) {
             case 'AND':
                 $return &= $value;
                 break;
             case 'OR':
                 $return |= $value;
                 break;
             case 'XOR':
                 $return ^= $value;
                 break;
             default:
                 $return = $value;
         }
     }
     // If the field is hidden by default, show it if condition is true
     if ($question->fields['show_rule'] == 'hidden') {
         return $return;
         // else show it if condition is false
     } else {
         return !$return;
     }
 }
예제 #28
0
 function getInputQuestion($id, $type, $data, $option)
 {
     global $LANG;
     $tab = PluginFormcreatorQuestion::_unserialize($data);
     $question_option = json_decode($option, true);
     $question_option_type = $question_option['type'];
     $question_option_regex = urldecode($question_option['value']);
     switch ($type) {
         case PluginFormcreatorQuestion::TEXT_FIELD:
             // Text
             switch ($question_option['type']) {
                 case 1:
                     echo '<input type="text" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" size="40"/>';
                     break;
                 case 2:
                     echo '<input type="text" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" size="40" onBlur="verifTextNum(this);"/>';
                     break;
                 case 3:
                     echo '<input type="text" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" size="40" onBlur="verifText(this);"/>';
                     break;
                 case 4:
                     echo '<input type="text" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" size="40" onBlur="verifNum(this);"/>';
                     break;
                 case 5:
                     echo '<input type="text" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" size="40" onBlur="verifRegex(this,' . $question_option_regex . ');"/>';
                     break;
                 case 6:
                     echo '<input type="text" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" size="40" onBlur="verifMail(this);"/>';
                     break;
                 case 7:
                     echo '<table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;"><tr><td id="ds_calclass"></td></tr></table>';
                     echo '<input type="text" size="9" id="question_' . $id . '" name="question_' . $id . '" value="' . $tab['value'] . '" readonly="readonly" size="40" onfocus="ds_sh(this);"/>';
                     break;
             }
             break;
         case PluginFormcreatorQuestion::SELECT_FIELD:
             // Select
             echo '<select name="question_' . $id . '">';
             foreach ($tab['value'] as $value_id => $value) {
                 echo '<option value="' . $value . '">' . $value . '</option>';
             }
             echo '</select>';
             break;
         case PluginFormcreatorQuestion::CHECKBOX_FIELD:
             // Checkbox
             foreach ($tab['value'] as $value_id => $value) {
                 echo '<input type="checkbox" name="question_' . $id . '[]" 
                                          value="' . $value . '"/>&nbsp;' . $value . '<br />';
             }
             break;
         case PluginFormcreatorQuestion::TEXTAREA_FIELD:
             // Textarea
             echo '<textarea id="question_' . $id . '" name="question_' . $id . '" cols="50" rows="8">' . $tab['value'] . '</textarea>';
             break;
         case PluginFormcreatorQuestion::UPLOAD_FIELD:
             // Upload
             echo '<input type="file" name="question_' . $id . '" />&nbsp;' . self::getMaxUploadSize();
             break;
         case PluginFormcreatorQuestion::VALIDATION_FIELD:
             // Validation
             echo '<table>';
             echo '<tr>';
             echo '<td>';
             echo __('Approver');
             echo "&nbsp;:</td><td>";
             User::dropdown(array('name' => 'users_id_validate_' . $id, 'entity' => $_SESSION["glpiactive_entity"], 'right' => 'validate_ticket'));
             echo '</td></tr>';
             echo '<tr>';
             echo '<td>';
             echo __('Request comment');
             echo '&nbsp;:</td>';
             echo '<td><textarea name="question_' . $id . '" cols="50" rows="8">' . $tab['value'] . '</textarea></td></tr>';
             echo '</table>';
             break;
         case PluginFormcreatorQuestion::MULTIPLICATION_ITEM_FIELD:
             // 2 textfields sum
             echo '<input type="text" name="question1_' . $id . '" size="5" onKeyUp="multiplication(question1_' . $id . ', question2_' . $id . ', somme_' . $id . ', question3_' . $id . ', ' . $id . ');"/>&nbsp;';
             echo '<select name="question2_' . $id . '" onchange="multiplication(question1_' . $id . ', question2_' . $id . ', somme_' . $id . ', question3_' . $id . ', ' . $id . ');">';
             echo '<option value=""></option>';
             foreach ($tab['value'] as $value_id => $value) {
                 $typeMat = $tab["typeMat"][$value_id];
                 echo '<option value="' . $value . '">' . $typeMat . '</option>';
             }
             echo '</select>';
             echo '<input type=hidden name="question3_' . $id . '">';
             echo '&nbsp;<input type="text" id="somme_' . $id . '" name="somme_' . $id . '" size="5" readonly/>&#8364;';
             break;
         case PluginFormcreatorQuestion::DYNAMIC_FIELD:
             // Select question dynamic
             foreach ($tab['value'] as $value_id => $value) {
                 $listing .= self::creationTabDyna($tab['question'][$value_id]);
                 if ($listing != "") {
                     $listing .= ":";
                 }
             }
             while ($listing[strlen($listing) - 1] == ":") {
                 $listing = substr($listing, 0, -1);
             }
             echo '<select id="question_' . $id . '" name="question_' . $id . '" onchange="choixSelectDyna(this.options[this.selectedIndex].value);">';
             foreach ($tab['value'] as $value_id => $value) {
                 $tableau = self::creationTabDyna($tab['question'][$value_id]);
                 if ($tableau != "") {
                     $tableau = "&&" . $tableau;
                 }
                 echo "<option id='dynaQuestion_" . $id . "_" . $value_id . "' value='" . $value . "&&" . $listing . $tableau . "'>" . $value . "</option>";
             }
             echo '</select>';
             break;
         case PluginFormcreatorQuestion::DYNAMIC_SECTION:
             // Select section dynamic
             $listing = "";
             foreach ($tab['value'] as $value_id => $value) {
                 if (isset($tab['section'][$value_id])) {
                     $listing .= self::creationTabDyna($tab['section'][$value_id]);
                     if ($listing != "") {
                         $listing .= ":";
                     }
                 }
             }
             if (strlen($listing) > 0) {
                 while ($listing[strlen($listing) - 1] == ":") {
                     $listing = substr($listing, 0, -1);
                 }
             }
             echo '<select id="question_' . $id . '" name="question_' . $id . '" onchange="choixSelectDyna(this.options[this.selectedIndex].value);">';
             foreach ($tab['value'] as $value_id => $value) {
                 if (isset($tab['section'][$value_id]) && $tab['section'][$value_id] != "") {
                     $tableau = self::creationTabDyna($tab['section'][$value_id]);
                     $tableau = "&&" . $tableau;
                 } else {
                     $tableau = "";
                 }
                 echo "<option id='dynaQuestion_" . $id . "_" . $value_id . "' value='" . $value . "&&" . $listing . $tableau . "'>" . $value . "</option>";
             }
             echo '</select>';
             break;
         case PluginFormcreatorQuestion::ITEM:
             // item listing
             echo '<select name="question_' . $id . '">';
             $retour = self::getTabItem($tab['value']);
             foreach ($retour as $key => $value) {
                 echo '<option value="' . $value["name"] . '">' . $value["name"] . '</option>';
             }
             echo '</select>';
             break;
     }
 }