Example #1
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;
 }
Example #2
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;
     }
 }
Example #3
0
<?php

include '../../../inc/includes.php';
Session::checkRight("config", "w");
if (empty($_REQUEST['section_id'])) {
    $section_id = 0;
    $name = '';
} else {
    $section_id = (int) $_REQUEST['section_id'];
    $section = new PluginFormcreatorSection();
    $section->getFromDB($section_id);
    $name = $section->fields['name'];
}
echo '<form name="form_section" method="post" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/section.form.php" onsubmit="return validateForm(this);">';
echo '<table class="tab_cadre_fixe">';
echo '<tr>';
echo '<th colspan="2">';
if (0 == $section_id) {
    echo __('Add a section', 'formcreator');
} else {
    echo __('Edit a section', 'formcreator');
}
echo '</th>';
echo '</tr>';
echo '<tr class="line0">';
echo '<td width="20%">' . __('Title') . ' <span style="color:red;">*</span></td>';
echo '<td width="70%"><input type="text" name="name" style="width:100%;" value="' . $name . '" class="required"></td>';
echo '</tr>';
echo '<tr class="line1">';
echo '<td colspan="2" class="center">';
echo '<input type="hidden" name="id" value="' . $section_id . '" />';
Example #4
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);
     }
 }
 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;
 }
 /**
  * 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;
 }
Example #7
0
 function createDefaultSection($formID, $targetID)
 {
     global $LANG;
     $section = new PluginFormcreatorSection();
     $defaultSection['name'] = $LANG['plugin_formcreator']["default"]["section"][0];
     $defaultSection['content'] = $LANG['plugin_formcreator']["default"]["section"][1];
     $defaultSection['plugin_formcreator_forms_id'] = $formID;
     $defaultSection['plugin_formcreator_targets_id'] = $targetID;
     $section->add($defaultSection);
 }
Example #8
0
<?php

include '../../../inc/includes.php';
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"])) {
<?php

include "../../../inc/includes.php";
Session::checkRight("config", "w");
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $section = new PluginFormcreatorSection();
    // Add a new Section
    if (isset($_POST["add"])) {
        $section->check(-1, 'w', $_POST);
        $section->add($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Edit an existing Section
    } elseif (isset($_POST["update"])) {
        $section->check($_POST['id'], 'w');
        $section->update($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Delete a Section
    } elseif (isset($_POST["delete"])) {
        $section->check($_POST['id'], 'd');
        $section->delete($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Move a Section
    } elseif (isset($_POST["move"])) {
        global $DB;
        $section->check($_POST['id'], 'd');
        $table = getTableForItemtype('PluginFormcreatorSection');
        $result = $DB->query("SELECT `order`, `plugin_formcreator_forms_id` FROM {$table} WHERE id = " . $_POST['id']);
        list($order, $form_id) = $DB->fetch_array($result);
        if ($_POST["way"] == 'up') {
Example #10
0
 function showFormEdit($params, $options = array())
 {
     //question modification
     global $LANG, $CFG_GLPI;
     if ($params['id'] > 0) {
         $this->check($params['id'], 'r');
     } else {
         // Create item
         $this->check(-1, 'w');
     }
     echo "<script type='text/javascript'>";
     echo 'var addQuestion = document.getElementById("viewaddquestion");';
     echo 'if(addQuestion != "undefined") {';
     echo 'document.getElementById("viewaddquestion").innerHTML = "";';
     echo '}';
     echo "</script>";
     $paramsType = array('type' => __CLASS__, 'value' => '__VALUE__', 'id' => $this->fields['plugin_formcreator_forms_id']);
     Ajax::updateItemOnSelectEvent('typeQuestion', "viewValues", $CFG_GLPI["root_doc"] . "/plugins/formcreator/ajax/viewformtypequestion.php", $paramsType);
     echo "<form method='POST' \n      action='" . $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/question.form.php'>";
     echo "<input type='hidden' name='plugin_formcreator_forms_id' \n            value='" . $this->fields['plugin_formcreator_forms_id'] . "' />";
     echo "<input type='hidden' name='id' \n            value='" . $this->fields['id'] . "' />";
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe fix_tab_height'>";
     echo "<tr>";
     echo "<th colspan='3'>" . $LANG['plugin_formcreator']["question"][8] . "</th>";
     echo "<th colspan='3'>&nbsp;</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Type') . "&nbsp;:</td><td>";
     echo "<select name='type' id='typeQuestion'>";
     echo "<option value='-1'>----</option>";
     for ($i = 1; $i <= 10; $i++) {
         if ($i == $this->fields['type']) {
             echo "<option value='" . $i . "' selected='selected'>\n                        " . $LANG['plugin_formcreator']["type_question"][$i] . "</option>";
         } else {
             echo "<option value='" . $i . "'>\n                        " . $LANG['plugin_formcreator']["type_question"][$i] . "</option>";
         }
     }
     echo "</select>";
     echo "</td>";
     echo "<td>" . $LANG['plugin_formcreator']["question"][2] . "&nbsp;:</td>";
     echo "<td>";
     echo '<input type="text" id="name_question" name="name" value="' . $this->fields['name'] . '" size="54"/>';
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     echo $LANG['plugin_formcreator']["section"][3] . " :";
     echo "</td>";
     echo "<td>";
     PluginFormcreatorSection::getSelectSection($this->fields['plugin_formcreator_forms_id'], 'plugin_formcreator_sections_id', $this->fields['plugin_formcreator_sections_id']);
     echo '&nbsp;<a href="' . $CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $this->fields['plugin_formcreator_forms_id'] . '&itemtype=PluginFormcreatorForm&glpi_tab=PluginFormcreatorSection$1">
           <img style="cursor:pointer; 
           margin-left:2px;" src="../../../pics/add_dropdown.png" 
           title="' . $LANG['plugin_formcreator']["section"][0] . '" alt=""/></a>';
     echo "</td>";
     echo "<td>" . __('Description') . "&nbsp;:</td>";
     echo "<td>";
     echo "<textarea name='content' cols='55' rows='6'>";
     echo $this->fields["content"];
     echo "</textarea>";
     echo "</td>";
     echo '<td>';
     echo $LANG['plugin_formcreator']["bbcode"][0] . '<br/>' . $LANG['plugin_formcreator']["bbcode"][1] . '<br/>' . $LANG['plugin_formcreator']["bbcode"][2] . '<br/>' . $LANG['plugin_formcreator']["bbcode"][3] . '<br/>' . $LANG['plugin_formcreator']["bbcode"][4];
     echo '</td>';
     echo "</tr><tr>";
     echo '<td>' . $LANG['plugin_formcreator']["question"][11] . ' :</td>';
     echo '<td><input type="text" name="position" 
                        value="' . $this->fields['position'] . '" size="3" /></td>';
     echo "<td colspan='2'>";
     $datas = self::_unserialize($this->fields['data']);
     echo "<div id='viewValues'>";
     self::getEditValue($this->fields['type'], $datas, $this->fields['option'], $this->fields['plugin_formcreator_forms_id']);
     echo "</div>";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='center' colspan='2'>";
     echo "<input class='submit' type='submit' value='" . __('Update') . "' name='update'>";
     echo "</td>";
     echo "<td class='center' colspan='2'>";
     echo "<input class='submit' type='submit' value='" . __('Purge') . "' name='delete'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "</div>";
     Html::closeForm();
 }
Example #11
0
    $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);
        }
        $form->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $form->check($_POST["id"], 'd');
            $form->restore($_POST);
 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">&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>';
    }
<?php

include "../../../inc/includes.php";
Session::checkRight("entity", UPDATE);
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $section = new PluginFormcreatorSection();
    // Add a new Section
    if (isset($_POST["add"])) {
        Session::checkRight("entity", UPDATE);
        $section->add($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Edit an existing Section
    } elseif (isset($_POST["update"])) {
        Session::checkRight("entity", UPDATE);
        $section->update($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Delete a Section
    } elseif (isset($_POST["delete_section"])) {
        Session::checkRight("entity", UPDATE);
        $section->delete($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
        // Move a Section
    } elseif (isset($_POST["move"])) {
        global $DB;
        Session::checkRight("entity", UPDATE);
        $table = getTableForItemtype('PluginFormcreatorSection');
        $result = $DB->query("SELECT `order`, `plugin_formcreator_forms_id` FROM {$table} WHERE id = " . $_POST['id']);
        list($order, $form_id) = $DB->fetch_array($result);
        if ($_POST["way"] == 'up') {
Example #15
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/>";
 }
Example #16
0
 function getSectionByForm($formID)
 {
     $section = new PluginFormcreatorSection();
     $listeSection = $section->find("plugin_formcreator_forms_id = '{$formID}'");
     return $listeSection;
 }