/** * 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; }
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; }
/** * 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"> </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 ' '; } 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 ' '; } 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 ' '; } 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 ' '; } 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 ' '; } 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; } }
/** * 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; }
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); } }
$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); } $form->redirectToList(); } else { if (isset($_POST["restore"])) { $form->check($_POST["id"], 'd'); $form->restore($_POST); $form->redirectToList();
static function getSelectSectionDynamic($formID, $sectionName = 'plugin_formcreator_section_id', $selected = '') { $section = new PluginFormcreatorSection(); $listSection = $section->find("plugin_formcreator_forms_id = '{$formID}' ORDER BY position"); //fonction qui permet de savoir s'il s'agit d'une question ou section pour le selected if (preg_match("/sec_/", $selected)) { $select_choix = 1; } else { $select_choix = 0; } echo '<select name="' . $sectionName . '">'; echo '<option value="-1"></option>'; foreach ($listSection as $section_id => $values) { if ($selected == "sec_" . $section_id) { echo '<option value="sec_' . $section_id . '" selected="selected">' . $values['name'] . '</option>'; } else { echo '<option value="sec_' . $section_id . '">' . $values['name'] . '</option>'; } } echo '<option value="-1">------</option>'; $question = new self(); $listQuestion = $question->find("plugin_formcreator_forms_id = '{$formID}' ORDER BY plugin_formcreator_sections_id,position"); foreach ($listQuestion as $question_id => $values) { if ($selected == $question_id && $select_choix == 0) { echo '<option value="' . $question_id . '" selected="selected">' . $values['name'] . '</option>'; } else { echo '<option value="' . $question_id . '">' . $values['name'] . '</option>'; } } echo '</select>'; }
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; }
/** * 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"> </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 ' '; } 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 ' '; } 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 ' '; } 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 ' '; } 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 ' '; } 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>'; }
function getSectionByForm($formID) { $section = new PluginFormcreatorSection(); $listeSection = $section->find("plugin_formcreator_forms_id = '{$formID}'"); return $listeSection; }