static function getMenuContent()
 {
     global $CFG_GLPI;
     $menu = parent::getMenuContent();
     $image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
               title="' . __('Forms waiting for validation', 'formcreator') . '"
               alt="' . __('Forms waiting for validation', 'formcreator') . '">';
     if (PluginFormcreatorForm::canCreate()) {
         $menu['links']['add'] = PluginFormcreatorForm::getFormURL(false);
     }
     $menu['links']['config'] = PluginFormcreatorForm::getSearchURL(false);
     $menu['links'][$image] = PluginFormcreatorFormanswer::getSearchURL(false);
     return $menu;
 }
<?php

require_once '../../../inc/includes.php';
// Check if plugin is activated...
$plugin = new Plugin();
if (!$plugin->isInstalled('formcreator') || !$plugin->isActivated('formcreator')) {
    Html::displayNotFoundError();
}
if (PluginFormcreatorFormanswer::canView()) {
    if ($_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
        Html::helpHeader(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF']);
    } else {
        Html::header(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF'], 'helpdesk', 'PluginFormcreatorFormlist');
    }
    Search::show('PluginFormcreatorFormanswer');
    Html::footer();
} else {
    Html::displayRightError();
}
Beispiel #3
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);
     }
 }
 /**
  * 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;
 }
Beispiel #5
0
function plugin_formcreator_AssignToTicket($types)
{
    $types['PluginFormcreatorFormanswer'] = PluginFormcreatorFormanswer::getTypeName();
    return $types;
}
<?php

include "../../../inc/includes.php";
Session::redirectIfNotLoggedIn();
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $formanswer = new PluginFormcreatorFormanswer();
    // Edit an existing target ticket
    if (isset($_POST['update'])) {
        $formanswer->update($_POST);
        Html::back();
    } elseif (isset($_POST['refuse_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'refused';
        $_POST['save_formanswer'] = true;
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
    } elseif (isset($_POST['accept_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'accepted';
        $_POST['save_formanswer'] = true;
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
    } elseif (isset($_POST['save_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'waiting';
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
        // Show target ticket form
    } else {
<?php

include "../../../inc/includes.php";
Session::redirectIfNotLoggedIn();
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $formanswer = new PluginFormcreatorFormanswer();
    // Edit an existing target ticket
    if (isset($_POST['update'])) {
        $formanswer->update($_POST);
        Html::back();
    } elseif (isset($_POST['refuse_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'refused';
        $_POST['save_formanswer'] = true;
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
    } elseif (isset($_POST['accept_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'accepted';
        $_POST['save_formanswer'] = true;
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
    } elseif (isset($_POST['save_formanswer'])) {
        $_POST['plugin_formcreator_forms_id'] = (int) $_POST['formcreator_form'];
        $_POST['status'] = 'waiting';
        $formanswer->saveAnswers($_POST);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/formanswer.php');
        // Show target ticket form
    } else {