function displayAnswers($questions_id) { $psQuestion = new PluginSurveyticketQuestion(); $psAnswer = new PluginSurveyticketAnswer(); $a_answers = $psAnswer->find("`plugin_surveyticket_questions_id`='" . $questions_id . "'"); $psQuestion->getFromDB($questions_id); switch ($psQuestion->fields['type']) { case 'dropdown': echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; echo "<select name='question" . $questions_id . "' id='question" . $questions_id . "' >"; echo "<option>" . Dropdown::EMPTY_VALUE . "</option>"; foreach ($a_answers as $data_answer) { echo "<option value='" . $data_answer['id'] . "'>" . $psAnswer->getAnswer($data_answer) . "</option>"; } echo "</select>"; echo "</td>"; echo "</tr>"; break; case 'checkbox': $i = 0; foreach ($a_answers as $data_answer) { echo "<tr class='tab_bg_1'>"; echo "<td width='40' align='center'>"; echo "<input type='checkbox' name='question" . $questions_id . "[]' id='question" . $questions_id . "-" . $i . "' \n value='" . $data_answer['id'] . "' />"; echo "</td>"; echo "<td>"; echo $psAnswer->getAnswer($data_answer); echo "</td>"; $this->displayAnswertype($data_answer['answertype'], "text-" . $questions_id . "-" . $data_answer['id']); echo "</tr>"; $i++; } break; case 'radio': case 'yesno': $i = 0; foreach ($a_answers as $data_answer) { echo "<tr class='tab_bg_1'>"; echo "<td width='40' align='center'>"; echo "<input type='radio' name='question" . $questions_id . "' id='question" . $questions_id . "-" . $i . "' \n value='" . $data_answer['id'] . "' />"; echo "</td>"; echo "<td>"; echo $psAnswer->getAnswer($data_answer); echo "</td>"; $this->displayAnswertype($data_answer['answertype'], "text-" . $questions_id . "-" . $data_answer['id']); echo "</tr>"; $i++; } break; case 'date': echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; $data_answer = current($a_answers); Html::showDateTimeField("question" . $questions_id, array('rand' => "question" . $questions_id)); echo '<input type="hidden" name="realquestion' . $questions_id . '" id="realquestion' . $questions_id . '" value="' . $data_answer['id'] . '" />'; echo "</td>"; echo "</tr>"; break; case 'input': echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; $data_answer = current($a_answers); echo '<input type="text" name="question' . $questions_id . '" id="question' . $questions_id . '" value="" size="71" />'; echo '<input type="hidden" name="realquestion' . $questions_id . '" id="realquestion' . $questions_id . '" value="' . $data_answer['id'] . '" />'; echo "</td>"; echo "</tr>"; break; } return count($a_answers); }
function showQuestions($items_id) { global $CFG_GLPI; $psQuestion = new PluginSurveyticketQuestion(); echo "<form method='post' name='form_addquestion' action='" . $CFG_GLPI['root_doc'] . "/plugins/surveyticket/front/surveyquestion.form.php'>"; echo "<table class='tab_cadre' width='700'>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . _n('Question', 'Questions', 1, 'surveyticket') . " :</td>"; echo "<td>"; $a_questions = $this->find("`plugin_surveyticket_surveys_id`='" . $items_id . "'", "`order`"); $a_used = array(); foreach ($a_questions as $data) { $a_used[] = $data['plugin_surveyticket_questions_id']; } Dropdown::show("PluginSurveyticketQuestion", array("name" => "plugin_surveyticket_questions_id", "used" => $a_used)); echo "</td>"; echo "<td>" . __('Position') . " :</td>"; echo "<td>"; Dropdown::showInteger("order", "0", 0, 20); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td class='tab_bg_2 top' colspan='4'>"; echo "<input type='hidden' name='plugin_surveyticket_surveys_id' value='" . $items_id . "'>"; echo "<div class='center'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</div></td></tr>"; echo "</table>"; Html::closeForm(); // list questions echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th>"; echo _n('Question', 'Questions', 1, 'surveyticket'); echo "</th>"; echo "<th>"; echo __('Type'); echo "</th>"; echo "<th>"; echo __('Position'); echo "</th>"; echo "<th>"; echo "</th>"; echo "</tr>"; foreach ($a_questions as $data) { echo "<tr class='tab_bg_1'>"; echo "<td>"; $psQuestion->getFromDB($data['plugin_surveyticket_questions_id']); echo $psQuestion->getLink(1); echo "</td>"; echo "<td>"; echo PluginSurveyticketQuestion::getQuestionTypeName($psQuestion->fields['type']); echo "</td>"; echo "<td>"; echo $data['order']; echo "</td>"; echo "<td align='center'>"; echo "<form method='post' name='form_addquestion' action='" . $CFG_GLPI['root_doc'] . "/plugins/surveyticket/front/surveyquestion.form.php'>"; echo "<input type='hidden' name='id' value='" . $data['id'] . "'>"; echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>"; Html::closeForm(); echo "</td>"; echo "</tr>"; } echo "</table>"; }
function plugin_surveyticket_post_init() { if (strpos($_SERVER['PHP_SELF'], "ticket.form.php") && !isset($_GET['id']) && (!isset($_POST['id']) || $_POST['id'] == 0) || strpos($_SERVER['PHP_SELF'], "helpdesk.public.php") && isset($_GET['create_ticket']) || strpos($_SERVER['PHP_SELF'], "tracking.injector.php")) { if (isset($_POST)) { $psQuestion = new PluginSurveyticketQuestion(); $psAnswer = new PluginSurveyticketAnswer(); //print_r($_POST);exit; $description = ''; foreach ($_POST as $question => $answer) { if (strstr($question, "question") && !strstr($question, "realquestion")) { $psQuestion->getFromDB(str_replace("question", "", $question)); if (is_array($answer)) { // Checkbox $description .= _n('Question', 'Questions', 1, 'surveyticket') . " : " . $psQuestion->fields['name'] . "\n"; foreach ($answer as $answers_id) { if ($psAnswer->getFromDB($answers_id)) { $description .= _n('Answer', 'Answers', 1, 'surveyticket') . " : " . $psAnswer->fields['name'] . "\n"; $qid = str_replace("question", "", $question); if (isset($_POST["text-" . $qid . "-" . $answers_id]) and $_POST["text-" . $qid . "-" . $answers_id] != '') { $description .= "Texte : " . $_POST["text-" . $qid . "-" . $answers_id] . "\n"; } } } $description .= "\n"; unset($_POST[$question]); } else { $real = 0; if (isset($_POST['realquestion' . str_replace("question", "", $question)])) { $realanswer = $answer; $answer = $_POST['realquestion' . str_replace("question", "", $question)]; $real = 1; } if ($psAnswer->getFromDB($answer)) { $description .= _n('Question', 'Questions', 1, 'surveyticket') . " : " . $psQuestion->fields['name'] . "\n"; if ($real == 1) { $description .= _n('Answer', 'Answers', 1, 'surveyticket') . " : " . $realanswer . "\n"; } else { $description .= _n('Answer', 'Answers', 1, 'surveyticket') . " : " . $psAnswer->fields['name'] . "\n"; } $qid = str_replace("question", "", $question); if (isset($_POST["text-" . $qid . "-" . $answer]) and $_POST["text-" . $qid . "-" . $answer] != '') { $description .= "Texte : " . $_POST["text-" . $qid . "-" . $answer] . "\n"; } $description .= "\n"; unset($_POST[$question]); } } } } if ($description != '') { $_POST['content'] = addslashes($description); } } if (!isset($_POST['add'])) { if (strpos($_SERVER['PHP_SELF'], "ticket.form.php")) { Html::header(__('New ticket'), '', "maintain", "ticket"); PluginSurveyticketSurvey::getCentral(); Html::footer(); exit; } else { if (strpos($_SERVER['PHP_SELF'], "helpdesk.public.php") || strpos($_SERVER['PHP_SELF'], "tracking.injector.php")) { Html::helpHeader(__('Simplified interface'), '', $_SESSION["glpiname"]); PluginSurveyticketSurvey::getHelpdesk(); Html::helpFooter(); exit; } } } } }
function showForm($items_id, $options = array()) { if ($items_id != '') { $this->getFromDB($items_id); } else { $this->getEmpty(); if (isset($_SESSION['glpi_plugins_surveyticket']['questions_id'])) { $this->fields['plugin_surveyticket_questions_id'] = $_SESSION['glpi_plugins_surveyticket']['questions_id']; } } $this->initForm($items_id, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<td>" . _n('Answer', 'Answers', 1, 'surveyticket') . " :</td>"; echo "<td colspan='3'>"; $psQuestion = new PluginSurveyticketQuestion(); $psQuestion->getFromDB($this->fields['plugin_surveyticket_questions_id']); echo $psQuestion->getLink(); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Label') . " :</td>"; echo "<td>"; if ($psQuestion->fields['type'] == 'date') { echo '<i>' . __('date') . '</i>'; } else { if ($psQuestion->fields['type'] == 'input') { echo '<i>' . __('Short text', 'surveyticket') . '</i>'; } else { echo '<textarea maxlength="255" cols="70" rows="3" name="name">' . $this->fields["name"] . '</textarea>'; } } echo "</td>"; echo "<td>"; $psQuestion = new PluginSurveyticketQuestion(); $psQuestion->getFromDB($_SESSION['glpi_plugins_surveyticket']['questions_id']); if ($psQuestion->fields['type'] != 'date' && $psQuestion->fields['type'] != 'input') { echo __('+ field', 'surveyticket') . " :"; } echo "</td>"; echo "<td>"; $texttype = array(); $texttype[''] = Dropdown::EMPTY_VALUE; $texttype['shorttext'] = __('Text') . " - court"; $texttype['longtext'] = __('Text') . " - long"; $texttype['date'] = __('Date'); $texttype['number'] = __('Number'); if ($psQuestion->fields['type'] != 'date' && $psQuestion->fields['type'] != 'input') { Dropdown::showFromArray("answertype", $texttype, array('value' => $this->fields['answertype'])); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Linked to question', 'surveyticket') . " :</td>"; echo "<td colspan='3'>"; Dropdown::show("PluginSurveyticketQuestion", array('name' => 'plugin_surveyticket_questions_id', 'value' => $this->fields['plugin_surveyticket_questions_id'])); echo "</td>"; echo "</tr>"; if ($psQuestion->fields['type'] != "checkbox") { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Go to question', 'surveyticket') . " :</td>"; echo "<td colspan='3'>"; Dropdown::show("PluginSurveyticketQuestion", array('name' => 'link', 'value' => $this->fields['link'], 'used' => array($psQuestion->getID()))); echo "</td>"; echo "</tr>"; } $this->showFormButtons($options); return true; }