upgrade
This commit is contained in:
19
main/survey/ch_comment.php
Normal file
19
main/survey/ch_comment.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_comment.
|
||||
*/
|
||||
class ch_comment extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param string $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = '')
|
||||
{
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$form->addTextarea($name, null);
|
||||
$form->setDefaults([$name => $answers]);
|
||||
}
|
||||
}
|
||||
45
main/survey/ch_dropdown.php
Normal file
45
main/survey/ch_dropdown.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_dropdown.
|
||||
*/
|
||||
class ch_dropdown extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $survey_data
|
||||
* @param $formData
|
||||
*/
|
||||
public function createForm($survey_data, $formData)
|
||||
{
|
||||
parent::createForm($survey_data, $formData);
|
||||
|
||||
if (is_array($formData['answers'])) {
|
||||
foreach ($formData['answers'] as $key => $value) {
|
||||
$this->getForm()->addText('answers['.$key.']', $key + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) {
|
||||
foreach ($formData['answersid'] as $value) {
|
||||
$this->getForm()->addHidden('answersid[]', $value);
|
||||
}
|
||||
}
|
||||
|
||||
parent::addRemoveButtons($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = [])
|
||||
{
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$data = [0 => '--'] + $questionData['options'];
|
||||
$form->addSelect($name, null, $data);
|
||||
if (!empty($answers)) {
|
||||
$form->setDefaults([$name => $answers]);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
main/survey/ch_multiplechoice.php
Normal file
58
main/survey/ch_multiplechoice.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_multiplechoice.
|
||||
*/
|
||||
class ch_multiplechoice extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $survey_data
|
||||
* @param array $formData
|
||||
*
|
||||
* @return FormValidator
|
||||
*/
|
||||
public function createForm($survey_data, $formData)
|
||||
{
|
||||
parent::createForm($survey_data, $formData);
|
||||
|
||||
$options = [
|
||||
'horizontal' => get_lang('Horizontal'),
|
||||
'vertical' => get_lang('Vertical'),
|
||||
];
|
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
|
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
|
||||
$this->getForm()->setDefaults($formData);
|
||||
|
||||
$config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'];
|
||||
$total = count($formData['answers']);
|
||||
|
||||
if (is_array($formData['answers'])) {
|
||||
foreach ($formData['answers'] as $key => $value) {
|
||||
$this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
|
||||
if ($total > 2) {
|
||||
$this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) {
|
||||
foreach ($formData['answersid'] as $value) {
|
||||
$this->getForm()->addHidden('answersid[]', $value);
|
||||
}
|
||||
}
|
||||
|
||||
parent::addRemoveButtons($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = [])
|
||||
{
|
||||
$question = new ch_yesno();
|
||||
$question->render($form, $questionData, $answers);
|
||||
}
|
||||
}
|
||||
125
main/survey/ch_multiplechoiceother.php
Normal file
125
main/survey/ch_multiplechoiceother.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
class ch_multiplechoiceother extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $survey_data
|
||||
* @param array $formData
|
||||
*
|
||||
* @return FormValidator
|
||||
*/
|
||||
public function createForm($survey_data, $formData)
|
||||
{
|
||||
parent::createForm($survey_data, $formData);
|
||||
|
||||
$options = [
|
||||
'horizontal' => get_lang('Horizontal'),
|
||||
'vertical' => get_lang('Vertical'),
|
||||
];
|
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
|
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
|
||||
$this->getForm()->setDefaults($formData);
|
||||
|
||||
$config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'];
|
||||
$total = count($formData['answers']);
|
||||
|
||||
if (is_array($formData['answers'])) {
|
||||
foreach ($formData['answers'] as $key => $value) {
|
||||
if ('other' === $value) {
|
||||
continue;
|
||||
}
|
||||
$this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
|
||||
if ($total > 2) {
|
||||
$this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) {
|
||||
$counter = 1;
|
||||
$total = count($formData['answersid']);
|
||||
foreach ($formData['answersid'] as $value) {
|
||||
if ($counter === $total) {
|
||||
break;
|
||||
}
|
||||
$this->getForm()->addHidden('answersid[]', $value);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
parent::addRemoveButtons($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = [])
|
||||
{
|
||||
$question = new ch_yesno();
|
||||
$otherId = 0;
|
||||
foreach ($questionData['options'] as $key => $option) {
|
||||
if ('other' === $option) {
|
||||
$otherId = $key;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($questionData['options'] as &$option) {
|
||||
if ('other' === $option) {
|
||||
$option = '<p>'.get_lang('SurveyOtherAnswerSpecify').'</p>';
|
||||
}
|
||||
}
|
||||
$questionId = $questionData['question_id'];
|
||||
|
||||
$display = 'display:none';
|
||||
$defaultOtherData = '';
|
||||
|
||||
if (!empty($answers)) {
|
||||
$answers = self::decodeOptionValue($answers);
|
||||
if (isset($answers[1])) {
|
||||
$display = '';
|
||||
$defaultOtherData = $answers[1];
|
||||
}
|
||||
|
||||
$answers = $answers[0];
|
||||
}
|
||||
|
||||
$question->render($form, $questionData, $answers);
|
||||
$form->addHtml(
|
||||
'<script>
|
||||
$(function() {
|
||||
$("input:radio[name=\"question'.$questionId.'\"]").change(function() {
|
||||
if ($(this).val() == "'.$otherId.'") {
|
||||
$("#other_div_'.$questionId.'").show();
|
||||
} else {
|
||||
$("#other_div_'.$questionId.'").hide();
|
||||
$("#other_question'.$questionId.'").val("");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>'
|
||||
);
|
||||
|
||||
$form->addHtml('<div id="other_div_'.$questionId.'" class="multiple_choice_other" style="'.$display.'">');
|
||||
$element = $form->addText(
|
||||
'other_question'.$questionId,
|
||||
get_lang('SurveyOtherAnswer'),
|
||||
false,
|
||||
['id' => 'other_question'.$questionId]
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
|
||||
if (!empty($answers) && !empty($defaultOtherData)) {
|
||||
$element->setValue($defaultOtherData);
|
||||
$element->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static function decodeOptionValue($value)
|
||||
{
|
||||
return explode('@:@', $value);
|
||||
}
|
||||
}
|
||||
79
main/survey/ch_multipleresponse.php
Normal file
79
main/survey/ch_multipleresponse.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_multipleresponse.
|
||||
*/
|
||||
class ch_multipleresponse extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $surveyData
|
||||
* @param array $formData
|
||||
*/
|
||||
public function createForm($surveyData, $formData)
|
||||
{
|
||||
parent::createForm($surveyData, $formData);
|
||||
$options = [
|
||||
'horizontal' => get_lang('Horizontal'),
|
||||
'vertical' => get_lang('Vertical'),
|
||||
];
|
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
|
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
|
||||
$this->getForm()->setDefaults($formData);
|
||||
|
||||
$config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'];
|
||||
if (is_array($formData['answers'])) {
|
||||
foreach ($formData['answers'] as $key => $value) {
|
||||
$this->getForm()->addHtmlEditor(
|
||||
'answers['.$key.']',
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
$config
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) {
|
||||
foreach ($formData['answersid'] as $value) {
|
||||
$this->getForm()->addHidden('answersid[]', $value);
|
||||
}
|
||||
}
|
||||
|
||||
parent::addRemoveButtons($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(
|
||||
FormValidator $form,
|
||||
$questionData = [],
|
||||
$answers = []
|
||||
) {
|
||||
$class = 'checkbox-inline';
|
||||
$labelClass = 'checkbox-inline';
|
||||
if ('vertical' == $questionData['display']) {
|
||||
$class = 'checkbox-vertical';
|
||||
}
|
||||
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$form->addCheckBoxGroup(
|
||||
$name,
|
||||
null,
|
||||
$questionData['options'],
|
||||
['checkbox-class' => $class, 'label-class' => $labelClass]
|
||||
);
|
||||
|
||||
$defaults = [];
|
||||
if (!empty($answers)) {
|
||||
foreach ($answers as $answer) {
|
||||
$defaults[$name.'['.$answer.']'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
}
|
||||
}
|
||||
25
main/survey/ch_open.php
Normal file
25
main/survey/ch_open.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_open.
|
||||
*/
|
||||
class ch_open extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param string $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = '')
|
||||
{
|
||||
if (is_array($answers)) {
|
||||
$content = implode('', $answers);
|
||||
} else {
|
||||
$content = $answers;
|
||||
}
|
||||
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$form->addTextarea($name, null);
|
||||
$form->setDefaults([$name => $content]);
|
||||
}
|
||||
}
|
||||
9
main/survey/ch_pagebreak.php
Normal file
9
main/survey/ch_pagebreak.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_pagebreak.
|
||||
*/
|
||||
class ch_pagebreak extends survey_question
|
||||
{
|
||||
}
|
||||
34
main/survey/ch_percentage.php
Normal file
34
main/survey/ch_percentage.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_percentage.
|
||||
*/
|
||||
class ch_percentage extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = '')
|
||||
{
|
||||
$options = [
|
||||
'--' => '--',
|
||||
];
|
||||
|
||||
foreach ($questionData['options'] as $key => &$value) {
|
||||
$options[$key] = $value;
|
||||
}
|
||||
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$form->addSelect(
|
||||
$name,
|
||||
null,
|
||||
$options
|
||||
);
|
||||
|
||||
if (!empty($answers)) {
|
||||
$form->setDefaults([$name => $answers]);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
main/survey/ch_personality.php
Normal file
96
main/survey/ch_personality.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_personality.
|
||||
*/
|
||||
class ch_personality extends survey_question
|
||||
{
|
||||
/**
|
||||
* This function creates the form elements for the multiple response questions.
|
||||
*
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
*
|
||||
* @version January 2007
|
||||
*/
|
||||
public function createForm($survey_data, $form_content)
|
||||
{
|
||||
parent::createForm($survey_data, $form_content);
|
||||
$this->html .= ' <tr>';
|
||||
$this->html .= ' <td colspan="2"><strong>'.get_lang('DisplayAnswersHorVert').'</strong></td>';
|
||||
$this->html .= ' </tr>';
|
||||
// Horizontal or vertical
|
||||
$this->html .= ' <tr>';
|
||||
$this->html .= ' <td align="right" valign="top"> </td>';
|
||||
$this->html .= ' <td>';
|
||||
$this->html .= ' <input name="horizontalvertical" type="radio" value="horizontal" ';
|
||||
if (empty($form_content['horizontalvertical']) || $form_content['horizontalvertical'] == 'horizontal') {
|
||||
$this->html .= 'checked="checked"';
|
||||
}
|
||||
$this->html .= '/>'.get_lang('Horizontal').'</label><br />';
|
||||
$this->html .= ' <input name="horizontalvertical" type="radio" value="vertical" ';
|
||||
|
||||
if (isset($form_content['horizontalvertical']) && $form_content['horizontalvertical'] == 'vertical') {
|
||||
$this->html .= 'checked="checked"';
|
||||
}
|
||||
|
||||
$this->html .= ' />'.get_lang('Vertical').'</label>';
|
||||
$this->html .= ' </td>';
|
||||
$this->html .= ' <td> </td>';
|
||||
$this->html .= ' </tr>';
|
||||
$this->html .= ' <tr>
|
||||
<td colspan=""> </td>
|
||||
</tr>';
|
||||
|
||||
// The options
|
||||
$this->html .= ' <tr>';
|
||||
$this->html .= ' <td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>';
|
||||
$this->html .= ' </tr>';
|
||||
$total_number_of_answers = count($form_content['answers']);
|
||||
|
||||
$question_values = [];
|
||||
|
||||
// Values of question options
|
||||
if (is_array($form_content['values'])) { // Check if data is correct
|
||||
foreach ($form_content['values'] as $key => &$value) {
|
||||
$question_values[] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
|
||||
}
|
||||
}
|
||||
$count = 0;
|
||||
if (is_array($form_content['answers'])) {
|
||||
foreach ($form_content['answers'] as $key => &$value) {
|
||||
$this->html .= '<tr>';
|
||||
$this->html .= '<td align="right"><label for="answers['.$key.']">'.($key + 1).'</label></td>';
|
||||
$this->html .= '<td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']).'</td>';
|
||||
$this->html .= '<td>';
|
||||
|
||||
if ($total_number_of_answers > 2) {
|
||||
$this->html .= $question_values[$count];
|
||||
}
|
||||
|
||||
if ($key < $total_number_of_answers - 1) {
|
||||
$this->html .= '<input type="image" style="width:22px" src="'.Display::returnIconPath('down.png').'" value="move_down['.$key.']" name="move_down['.$key.']"/>';
|
||||
}
|
||||
if ($key > 0) {
|
||||
$this->html .= '<input type="image" style="width:22px" src="'.Display::returnIconPath('up.png').'" value="move_up['.$key.']" name="move_up['.$key.']"/>';
|
||||
}
|
||||
if ($total_number_of_answers > 2) {
|
||||
$this->html .= '<input type="image" style="width:22px" src="'.Display::returnIconPath('delete.png').'" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
|
||||
}
|
||||
$this->html .= '</td>';
|
||||
$this->html .= '</tr>';
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = [])
|
||||
{
|
||||
$question = new ch_yesno();
|
||||
$question->render($form, $questionData, $answers);
|
||||
}
|
||||
}
|
||||
74
main/survey/ch_score.php
Normal file
74
main/survey/ch_score.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_score.
|
||||
*/
|
||||
class ch_score extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $survey_data
|
||||
* @param array $formData
|
||||
*/
|
||||
public function createForm($survey_data, $formData)
|
||||
{
|
||||
parent::createForm($survey_data, $formData);
|
||||
$this->getForm()->addText('maximum_score', get_lang('MaximumScore'));
|
||||
$config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'];
|
||||
if (is_array($formData['answers'])) {
|
||||
foreach ($formData['answers'] as $key => $value) {
|
||||
$this->getForm()->addHtmlEditor(
|
||||
'answers['.$key.']',
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
$config
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) {
|
||||
foreach ($formData['answersid'] as $value) {
|
||||
$this->getForm()->addHidden('answersid[]', $value);
|
||||
}
|
||||
}
|
||||
|
||||
parent::addRemoveButtons($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = [])
|
||||
{
|
||||
$defaults = [];
|
||||
foreach ($questionData['options'] as $key => &$value) {
|
||||
$options = [
|
||||
'--' => '--',
|
||||
];
|
||||
for ($i = 1; $i <= $questionData['maximum_score']; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
|
||||
$name = 'question'.$questionData['question_id'].'['.$key.']';
|
||||
|
||||
$form->addHidden('question_id', $questionData['question_id']);
|
||||
$form->addSelect(
|
||||
$name,
|
||||
$value,
|
||||
$options
|
||||
);
|
||||
|
||||
if (!empty($answers)) {
|
||||
if (in_array($key, array_keys($answers))) {
|
||||
$defaults[$name] = $answers[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($defaults)) {
|
||||
$form->setDefaults($defaults);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
main/survey/ch_selectivedisplay.php
Normal file
85
main/survey/ch_selectivedisplay.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
class ch_selectivedisplay extends ch_yesno
|
||||
{
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = null)
|
||||
{
|
||||
if (is_array($questionData['options'])) {
|
||||
$class = 'radio-inline';
|
||||
$labelClass = 'radio-inline';
|
||||
if ('vertical' === $questionData['display']) {
|
||||
$class = 'radio-vertical';
|
||||
}
|
||||
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$radioAttributes = [
|
||||
'radio-class' => $class,
|
||||
'label-class' => $labelClass,
|
||||
'class' => 'survey_selective_input',
|
||||
];
|
||||
|
||||
if (!empty($questionData['is_required'])) {
|
||||
$radioAttributes['required'] = 'required';
|
||||
}
|
||||
|
||||
$form->addRadio(
|
||||
$name,
|
||||
null,
|
||||
$questionData['options'],
|
||||
$radioAttributes
|
||||
);
|
||||
|
||||
if (!empty($answers)) {
|
||||
$form->setDefaults([$name => is_array($answers) ? current($answers) : $answers]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getJs()
|
||||
{
|
||||
return '<script>
|
||||
$(function() {
|
||||
var hideQuestion = false;
|
||||
$(".survey_question").each(function() {
|
||||
var questionClass = $(this).attr("class").trim();
|
||||
if (hideQuestion) {
|
||||
$(this).hide();
|
||||
if (questionClass === "survey_question ch_selectivedisplay") {
|
||||
$(this).show();
|
||||
}
|
||||
}
|
||||
if (questionClass === "survey_question ch_selectivedisplay") {
|
||||
hideQuestion = true;
|
||||
}
|
||||
});
|
||||
|
||||
$(".survey_selective_input").on("click", function() {
|
||||
var parent = $(this).parent().parent().parent().parent();
|
||||
var next = parent.nextAll();
|
||||
var visible = $(this).attr("data-order") == 1;
|
||||
|
||||
next.each(function() {
|
||||
if ($(this).attr("class") === "survey_question ch_selectivedisplay") {
|
||||
return false;
|
||||
}
|
||||
if ($(this).attr("class") === "start-survey") {
|
||||
return false;
|
||||
}
|
||||
if (visible) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
88
main/survey/ch_yesno.php
Normal file
88
main/survey/ch_yesno.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Class ch_yesno.
|
||||
*/
|
||||
class ch_yesno extends survey_question
|
||||
{
|
||||
/**
|
||||
* @param array $surveyData
|
||||
* @param array $formData
|
||||
*/
|
||||
public function createForm($surveyData, $formData)
|
||||
{
|
||||
parent::createForm($surveyData, $formData);
|
||||
|
||||
$options = [
|
||||
'horizontal' => get_lang('Horizontal'),
|
||||
'vertical' => get_lang('Vertical'),
|
||||
];
|
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
|
||||
$this->getForm()->setDefaults($formData);
|
||||
|
||||
// The options
|
||||
$config = [
|
||||
'ToolbarSet' => 'Survey',
|
||||
'Width' => '100%',
|
||||
'Height' => '120',
|
||||
];
|
||||
|
||||
$this->getForm()->addHtmlEditor(
|
||||
'answers[0]',
|
||||
get_lang('AnswerOptions'),
|
||||
true,
|
||||
false,
|
||||
$config
|
||||
);
|
||||
|
||||
$this->getForm()->addHtmlEditor(
|
||||
'answers[1]',
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
$config
|
||||
);
|
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) {
|
||||
foreach ($formData['answersid'] as $value) {
|
||||
$this->getForm()->addHidden('answersid[]', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = null)
|
||||
{
|
||||
if (is_array($questionData['options'])) {
|
||||
$class = 'radio-inline';
|
||||
$labelClass = 'radio-inline';
|
||||
if ('vertical' === $questionData['display']) {
|
||||
$class = 'radio-vertical';
|
||||
}
|
||||
|
||||
$name = 'question'.$questionData['question_id'];
|
||||
$radioAttributes = ['radio-class' => $class, 'label-class' => $labelClass];
|
||||
|
||||
if (!empty($questionData['is_required'])) {
|
||||
$radioAttributes['required'] = 'required';
|
||||
}
|
||||
|
||||
$form->addRadio(
|
||||
$name,
|
||||
null,
|
||||
$questionData['options'],
|
||||
$radioAttributes
|
||||
);
|
||||
|
||||
if (!empty($answers)) {
|
||||
$form->setDefaults([$name => is_array($answers) ? current($answers) : $answers]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
89
main/survey/copy_survey.php
Normal file
89
main/survey/copy_survey.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$current_course_tool = TOOL_COURSE_MAINTENANCE;
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
// Notice for unauthorized people.
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
|
||||
// The section (for the tabs)
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
|
||||
|
||||
if (empty($surveyId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$survey = SurveyManager::get_survey($surveyId);
|
||||
if (empty($survey)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$surveyTitle = str_replace(' ', '', strip_tags($survey['title'].' ('.$survey['code'].') '));
|
||||
|
||||
$form = new FormValidator('copy_survey', 'post', api_get_self().'?survey_id='.$surveyId.'&'.api_get_cidreq());
|
||||
$form->addElement(
|
||||
'text',
|
||||
'survey_title',
|
||||
get_lang('Survey'),
|
||||
['value' => $surveyTitle, 'disabled' => 'disabled']
|
||||
);
|
||||
$form->addSelectAjax(
|
||||
'destination_course',
|
||||
get_lang('SelectDestinationCourse'),
|
||||
null,
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_my_courses_and_sessions&'.api_get_cidreq(),
|
||||
]
|
||||
);
|
||||
|
||||
$form->addButtonCopy(get_lang('CopySurvey'));
|
||||
|
||||
// Add Security token
|
||||
$token = Security::get_existing_token();
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
|
||||
// If a CourseSelectForm is posted or we should copy all resources, then copy them
|
||||
if ($form->validate() && Security::check_token('post')) {
|
||||
// Clear token
|
||||
Security::clear_token();
|
||||
$values = $form->getSubmitValues();
|
||||
$courseKey = $values['destination_course'];
|
||||
$courseParts = explode('_', $courseKey);
|
||||
$courseId = $courseParts[0];
|
||||
$sessionId = $courseParts[1];
|
||||
|
||||
// Copy the survey to the target course
|
||||
$surveyCopyId = SurveyManager::copySurveySession($surveyId, $courseId, $sessionId);
|
||||
if ($surveyCopyId) {
|
||||
// Empty the copied survey
|
||||
SurveyManager::emptySurveyFromId($surveyCopyId);
|
||||
Display::addFlash(Display::return_message(get_lang('SurveyCopied')));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('ThereWasAnError'), 'warning'));
|
||||
}
|
||||
|
||||
header('Location: '.api_get_self().'?'.api_get_cidreq().'&survey_id='.$surveyId);
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::display_header(get_lang('CopySurvey'));
|
||||
echo Display::page_header(get_lang('CopySurvey'));
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
187
main/survey/create_meeting.php
Normal file
187
main/survey/create_meeting.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_css_asset('jt.timepicker/jquery.timepicker.css');
|
||||
$htmlHeadXtra[] = api_get_asset('jt.timepicker/jquery.timepicker.js');
|
||||
$htmlHeadXtra[] = api_get_asset('datepair.js/dist/datepair.js');
|
||||
$htmlHeadXtra[] = api_get_asset('datepair.js/dist/jquery.datepair.js');
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
|
||||
$courseInfo = api_get_course_info();
|
||||
|
||||
$tool_name = get_lang('CreateMeeting');
|
||||
|
||||
$form = new FormValidator(
|
||||
'survey',
|
||||
'post',
|
||||
api_get_self().'?action=add&'.api_get_cidreq()
|
||||
);
|
||||
|
||||
$form->addElement('header', $tool_name);
|
||||
$form->addHidden('anonymous', 0);
|
||||
$form->addHidden('survey_language', $courseInfo['language']);
|
||||
$form->addHidden('survey_subtitle', '');
|
||||
$form->addHidden('survey_thanks', '');
|
||||
$form->addHidden('visible_results', '0');
|
||||
$form->addHidden('survey_type', 3);
|
||||
|
||||
$text = $form->addText(
|
||||
'survey_title',
|
||||
get_lang('Title')
|
||||
);
|
||||
|
||||
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
|
||||
|
||||
if ($allowSurveyAvailabilityDatetime) {
|
||||
$startDateElement = $form->addDateTimePicker('start_date', get_lang('StartDate'));
|
||||
$endDateElement = $form->addDateTimePicker('end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'datetime');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'datetime');
|
||||
} else {
|
||||
$startDateElement = $form->addElement('date_picker', 'start_date', get_lang('StartDate'));
|
||||
$endDateElement = $form->addElement('date_picker', 'end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
|
||||
}
|
||||
|
||||
$form->addRule(
|
||||
['start_date', 'end_date'],
|
||||
get_lang('StartDateShouldBeBeforeEndDate'),
|
||||
'date_compare',
|
||||
'lte'
|
||||
);
|
||||
|
||||
$form->setRequired($startDateElement);
|
||||
$form->setRequired($endDateElement);
|
||||
|
||||
$form->addHtmlEditor('survey_introduction', get_lang('Description'), false);
|
||||
$form->setRequired($text);
|
||||
|
||||
$hideList = '';
|
||||
$maxEvents = 20;
|
||||
for ($i = 1; $i <= $maxEvents; $i++) {
|
||||
$name = 'time_'.$i;
|
||||
$form->addDateTimeRangePicker($name, get_lang('Date'));
|
||||
if ($i > 3) {
|
||||
$hideList .= "$('#".$name."_date_time_wrapper').hide();";
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHtml('<script>
|
||||
$(function() {
|
||||
'.$hideList.'
|
||||
var number = 3;
|
||||
$("#add_button").on("click", function() {
|
||||
number++;
|
||||
$("#time_" + number + "_date_time_wrapper").show();
|
||||
});
|
||||
|
||||
$("#remove_button").on("click", function() {
|
||||
if (number > 1) {
|
||||
$("#time_" + number + "_date_time_wrapper").hide();
|
||||
number--;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>');
|
||||
|
||||
$form->addLabel(
|
||||
'',
|
||||
Display::url(get_lang('Add'), 'javascript:void(0)', ['id' => 'add_button', 'class' => 'btn btn-default'])
|
||||
.' '.
|
||||
Display::url(
|
||||
get_lang('Remove'),
|
||||
'javascript:void(0)',
|
||||
['id' => 'remove_button', 'class' => 'btn btn-danger']
|
||||
)
|
||||
);
|
||||
|
||||
$form->addButtonCreate(get_lang('CreateSurvey'), 'submit_survey');
|
||||
|
||||
$defaults = [];
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
// Exporting the values
|
||||
$values = $form->getSubmitValues();
|
||||
$values['survey_code'] = SurveyManager::generateSurveyCode($values['survey_title']);
|
||||
// Storing the survey
|
||||
$surveyData = SurveyManager::store_survey($values);
|
||||
|
||||
$dates = [];
|
||||
for ($i = 1; $i <= $maxEvents; $i++) {
|
||||
$name = 'time_'.$i;
|
||||
if (isset($values[$name]) && !empty($values[$name])) {
|
||||
$date = $values[$name];
|
||||
|
||||
if (empty($date)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $name.'_time_range_start';
|
||||
$end = $name.'_time_range_end';
|
||||
|
||||
$start = $values[$start];
|
||||
$end = $values[$end];
|
||||
|
||||
$start = api_get_utc_datetime($values[$name].' '.$start, true);
|
||||
$end = api_get_utc_datetime($values[$name].' '.$end, true);
|
||||
|
||||
if (!empty($start) && !empty($start)) {
|
||||
$row = [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
];
|
||||
$dates[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$questionTable = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$counter = 1;
|
||||
if (!empty($surveyData['id'])) {
|
||||
foreach ($dates as $date) {
|
||||
$params = [
|
||||
'c_id' => api_get_course_int_id(),
|
||||
'survey_id' => $surveyData['id'],
|
||||
'survey_question' => $date['start'].'@@'.$date['end'],
|
||||
'survey_question_comment' => '',
|
||||
'type' => 'doodle',
|
||||
'display' => 'horizontal',
|
||||
'sort' => $counter,
|
||||
'shared_question_id' => '0',
|
||||
'max_value' => 0,
|
||||
];
|
||||
$questionId = Database::insert($questionTable, $params);
|
||||
if ($questionId) {
|
||||
$sql = "UPDATE $questionTable SET question_id = $questionId
|
||||
WHERE iid = $questionId";
|
||||
Database::query($sql);
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Redirecting to the survey page (whilst showing the return message)
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
|
||||
exit;
|
||||
} else {
|
||||
// Displaying the header
|
||||
Display::display_header($tool_name);
|
||||
$form->display();
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
400
main/survey/create_new_survey.php
Normal file
400
main/survey/create_new_survey.php
Normal file
@@ -0,0 +1,400 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
|
||||
* refactoring and rewriting large parts (if not all) of the code
|
||||
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality
|
||||
* Test modification and rewriting large parts of the code
|
||||
*
|
||||
* @todo only the available platform languages should be used => need an
|
||||
* api get_languages and and api_get_available_languages (or a parameter)
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$_course = api_get_course_info();
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
|
||||
|
||||
// Database table definitions
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$table_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
|
||||
|
||||
/** @todo this has to be moved to a more appropriate place (after the display_header of the code) */
|
||||
// If user is not teacher or if he's a coach trying to access an element out of his session
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
if (!api_is_session_general_coach() ||
|
||||
(!empty($_GET['survey_id']) &&
|
||||
!api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Getting the survey information
|
||||
$survey_id = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null;
|
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
|
||||
$survey_data = SurveyManager::get_survey($survey_id);
|
||||
|
||||
// Additional information
|
||||
$course_id = api_get_course_id();
|
||||
$session_id = api_get_session_id();
|
||||
$gradebook_link_type = 8;
|
||||
$urlname = isset($survey_data['title']) ? strip_tags($survey_data['title'], '<span>') : null;
|
||||
|
||||
// Breadcrumbs
|
||||
if ($action == 'add') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$tool_name = get_lang('CreateNewSurvey');
|
||||
}
|
||||
if ($action == 'edit' && is_numeric($survey_id)) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
|
||||
'name' => Security::remove_XSS($urlname),
|
||||
];
|
||||
$tool_name = get_lang('EditSurvey');
|
||||
}
|
||||
$gradebook_link_id = null;
|
||||
// Getting the default values
|
||||
if ($action == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
|
||||
$defaults = $survey_data;
|
||||
$defaults['survey_id'] = $survey_id;
|
||||
$defaults['anonymous'] = $survey_data['anonymous'];
|
||||
|
||||
if ($allowSurveyAvailabilityDatetime) {
|
||||
$defaults['avail_from'] = api_get_local_time($defaults['avail_from']);
|
||||
|
||||
if (!empty($defaults['avail_till'])) {
|
||||
$defaults['avail_till'] = api_get_local_time($defaults['avail_till']);
|
||||
} else {
|
||||
$defaults['end_date'] = null;
|
||||
}
|
||||
$defaults['start_date'] = $defaults['avail_from'];
|
||||
}
|
||||
|
||||
$link_info = GradebookUtils::isResourceInCourseGradebook(
|
||||
$course_id,
|
||||
$gradebook_link_type,
|
||||
$survey_id,
|
||||
$session_id
|
||||
);
|
||||
|
||||
if ($link_info) {
|
||||
$gradebook_link_id = $link_info['id'];
|
||||
$defaults['category_id'] = $link_info['category_id'];
|
||||
$gradebook_link_id = (int) $gradebook_link_id;
|
||||
$sql = "SELECT weight FROM $table_gradebook_link WHERE id = $gradebook_link_id";
|
||||
$result = Database::query($sql);
|
||||
$gradeBookData = Database::fetch_array($result);
|
||||
if ($gradeBookData) {
|
||||
$defaults['survey_qualify_gradebook'] = $gradebook_link_id;
|
||||
$defaults['survey_weight'] = number_format($gradeBookData['weight'], 2, '.', '');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$defaults['survey_language'] = $_course['language'];
|
||||
$defaults['start_date'] = date(
|
||||
$allowSurveyAvailabilityDatetime ? 'Y-m-d 00:00:00' : 'Y-m-d',
|
||||
api_strtotime(api_get_local_time())
|
||||
);
|
||||
$startdateandxdays = time() + 864000; // today + 10 days
|
||||
$defaults['end_date'] = date(
|
||||
$allowSurveyAvailabilityDatetime ? 'Y-m-d 23:59:59' : 'Y-m-d',
|
||||
$startdateandxdays
|
||||
);
|
||||
$defaults['anonymous'] = 0;
|
||||
}
|
||||
|
||||
// Initialize the object
|
||||
$form = new FormValidator(
|
||||
'survey',
|
||||
'post',
|
||||
api_get_self().'?action='.$action.'&survey_id='.$survey_id.'&'.api_get_cidreq()
|
||||
);
|
||||
|
||||
$form->addElement('header', $tool_name);
|
||||
|
||||
// Setting the form elements
|
||||
if ('edit' == $action && isset($survey_id) && is_numeric($survey_id)) {
|
||||
$form->addElement('hidden', 'survey_id');
|
||||
}
|
||||
|
||||
$survey_code = $form->addElement(
|
||||
'text',
|
||||
'survey_code',
|
||||
get_lang('SurveyCode'),
|
||||
['size' => '20', 'maxlength' => '20', 'autofocus' => 'autofocus']
|
||||
);
|
||||
|
||||
if ('edit' == $action) {
|
||||
$survey_code->freeze();
|
||||
$form->applyFilter('survey_code', 'api_strtoupper');
|
||||
}
|
||||
|
||||
$form->addHtmlEditor(
|
||||
'survey_title',
|
||||
get_lang('SurveyTitle'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200']
|
||||
);
|
||||
$form->addHtmlEditor(
|
||||
'survey_subtitle',
|
||||
get_lang('SurveySubTitle'),
|
||||
false,
|
||||
false,
|
||||
[
|
||||
'ToolbarSet' => 'Survey',
|
||||
'Width' => '100%',
|
||||
'Height' => '100',
|
||||
'ToolbarStartExpanded' => false,
|
||||
]
|
||||
);
|
||||
|
||||
// Pass the language of the survey in the form
|
||||
$form->addElement('hidden', 'survey_language');
|
||||
|
||||
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
|
||||
|
||||
if ($allowSurveyAvailabilityDatetime) {
|
||||
$startDateElement = $form->addDateTimePicker('start_date', get_lang('StartDate'));
|
||||
$endDateElement = $form->addDateTimePicker('end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'datetime');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'datetime');
|
||||
} else {
|
||||
$startDateElement = $form->addElement('date_picker', 'start_date', get_lang('StartDate'));
|
||||
$endDateElement = $form->addElement('date_picker', 'end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
|
||||
}
|
||||
|
||||
$form->setRequired($startDateElement);
|
||||
|
||||
$form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
|
||||
$visibleResults = [
|
||||
SURVEY_VISIBLE_TUTOR => get_lang('Coach'),
|
||||
SURVEY_VISIBLE_TUTOR_STUDENT => get_lang('CoachAndStudent'),
|
||||
SURVEY_VISIBLE_PUBLIC => get_lang('Everyone'),
|
||||
];
|
||||
|
||||
if (api_get_configuration_value('hide_survey_reporting_button')) {
|
||||
$form->addLabel(get_lang('ResultsVisibility'), get_lang('FeatureDisabledByAdministrator'));
|
||||
} else {
|
||||
$form->addElement('select', 'visible_results', get_lang('ResultsVisibility'), $visibleResults);
|
||||
}
|
||||
//$defaults['visible_results'] = 0;
|
||||
$form->addHtmlEditor(
|
||||
'survey_introduction',
|
||||
get_lang('SurveyIntroduction'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false]
|
||||
);
|
||||
$form->addHtmlEditor(
|
||||
'survey_thanks',
|
||||
get_lang('SurveyThanks'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false]
|
||||
);
|
||||
|
||||
$extraField = new ExtraField('survey');
|
||||
$extraField->addElements($form, $survey_id, ['group_id']);
|
||||
|
||||
if ($extraField->get_handler_field_info_by_field_variable('group_id')) {
|
||||
$extraFieldValue = new ExtraFieldValue('survey');
|
||||
$groupData = $extraFieldValue->get_values_by_handler_and_field_variable($survey_id, 'group_id');
|
||||
$groupValue = [];
|
||||
if ($groupData && !empty($groupData['value'])) {
|
||||
$groupInfo = GroupManager::get_group_properties($groupData['value']);
|
||||
$groupValue = [$groupInfo['iid'] => $groupInfo['name']];
|
||||
}
|
||||
|
||||
$form->addSelectAjax(
|
||||
'extra_group_id',
|
||||
get_lang('Group'),
|
||||
$groupValue,
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'group.ajax.php?a=search&'.api_get_cidreq(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Additional Parameters
|
||||
$form->addButtonAdvancedSettings('advanced_params');
|
||||
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
|
||||
|
||||
if (Gradebook::is_active()) {
|
||||
// An option: Qualify the fact that survey has been answered in the gradebook
|
||||
$form->addElement(
|
||||
'checkbox',
|
||||
'survey_qualify_gradebook',
|
||||
null,
|
||||
get_lang('QualifyInGradebook'),
|
||||
'onclick="javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }"'
|
||||
);
|
||||
$form->addElement(
|
||||
'html',
|
||||
'<div id="gradebook_options"'.($gradebook_link_id ? '' : ' style="display:none"').'>'
|
||||
);
|
||||
$form->addElement(
|
||||
'text',
|
||||
'survey_weight',
|
||||
get_lang('QualifyWeight'),
|
||||
'value="0.00" style="width: 40px;" onfocus="javascript: this.select();"'
|
||||
);
|
||||
$form->applyFilter('survey_weight', 'html_filter');
|
||||
|
||||
// Loading Gradebook select
|
||||
GradebookUtils::load_gradebook_select_in_tool($form);
|
||||
|
||||
if ($action == 'edit') {
|
||||
$element = $form->getElement('category_id');
|
||||
$element->freeze();
|
||||
}
|
||||
$form->addElement('html', '</div>');
|
||||
}
|
||||
|
||||
// Personality/Conditional Test Options
|
||||
$surveytypes[0] = get_lang('Normal');
|
||||
$surveytypes[1] = get_lang('Conditional');
|
||||
|
||||
if ($action === 'add') {
|
||||
$form->addElement('hidden', 'survey_type', 0);
|
||||
$survey_tree = new SurveyTree();
|
||||
$list_surveys = $survey_tree->createList($survey_tree->surveylist);
|
||||
$list_surveys[0] = '';
|
||||
$form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
|
||||
$defaults['parent_id'] = 0;
|
||||
}
|
||||
|
||||
$form->addElement('checkbox', 'one_question_per_page', null, get_lang('OneQuestionPerPage'));
|
||||
$form->addElement('checkbox', 'shuffle', null, get_lang('ActivateShuffle'));
|
||||
|
||||
$input_name_list = null;
|
||||
|
||||
if ($action === 'edit' && !empty($survey_id)) {
|
||||
if ($survey_data['anonymous'] == 0) {
|
||||
$form->addElement(
|
||||
'checkbox',
|
||||
'show_form_profile',
|
||||
null,
|
||||
get_lang('ShowFormProfile'),
|
||||
'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'
|
||||
);
|
||||
|
||||
if ($survey_data['show_form_profile'] == 1) {
|
||||
$form->addElement('html', '<div id="options_field" style="display:block">');
|
||||
} else {
|
||||
$form->addElement('html', '<div id="options_field" style="display:none">');
|
||||
}
|
||||
|
||||
$field_list = SurveyUtil::make_field_list();
|
||||
|
||||
if (is_array($field_list)) {
|
||||
// TODO hide and show the list in a fancy DIV
|
||||
foreach ($field_list as $key => &$field) {
|
||||
if ($field['visibility'] == 1) {
|
||||
$form->addElement('checkbox', 'profile_'.$key, ' ', ' '.$field['name']);
|
||||
$input_name_list .= 'profile_'.$key.',';
|
||||
}
|
||||
}
|
||||
|
||||
// Necessary to know the fields
|
||||
$form->addElement('hidden', 'input_name_list', $input_name_list);
|
||||
|
||||
// Set defaults form fields
|
||||
if ($survey_data['form_fields']) {
|
||||
$form_fields = explode('@', $survey_data['form_fields']);
|
||||
foreach ($form_fields as &$field) {
|
||||
$field_value = explode(':', $field);
|
||||
if ($field_value[0] != '' && $field_value[1] != '') {
|
||||
$defaults[$field_value[0]] = $field_value[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$form->addElement('html', '</div>');
|
||||
}
|
||||
}
|
||||
|
||||
Skill::addSkillsToForm($form, api_get_course_int_id(), api_get_session_id(), ITEM_TYPE_SURVEY, $survey_id);
|
||||
|
||||
$form->addElement('html', '</div><br />');
|
||||
|
||||
if (isset($_GET['survey_id']) && $action == 'edit') {
|
||||
$form->addButtonUpdate(get_lang('ModifySurvey'), 'submit_survey');
|
||||
} else {
|
||||
$form->addButtonCreate(get_lang('CreateSurvey'), 'submit_survey');
|
||||
}
|
||||
|
||||
// Setting the rules
|
||||
if ($action == 'add') {
|
||||
$form->addRule('survey_code', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('survey_code', '', 'maxlength', 20);
|
||||
}
|
||||
$form->addRule('survey_title', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), $allowSurveyAvailabilityDatetime ? 'datetime' : 'date');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), $allowSurveyAvailabilityDatetime ? 'datetime' : 'date');
|
||||
|
||||
if (!empty($endDateElement->getCleanValue())) {
|
||||
$form->addRule(
|
||||
['start_date', 'end_date'],
|
||||
get_lang('StartDateShouldBeBeforeEndDate'),
|
||||
'date_compare',
|
||||
'lte'
|
||||
);
|
||||
}
|
||||
|
||||
// Setting the default values
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
// Exporting the values
|
||||
$values = $form->getSubmitValues();
|
||||
// Storing the survey
|
||||
$return = SurveyManager::store_survey($values);
|
||||
Skill::saveSkills($form, ITEM_TYPE_SURVEY, $return['id']);
|
||||
|
||||
$values['item_id'] = $return['id'];
|
||||
$extraFieldValue = new ExtraFieldValue('survey');
|
||||
$extraFieldValue->saveFieldValues($values);
|
||||
|
||||
// Redirecting to the survey page (whilst showing the return message)
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&'.api_get_cidreq());
|
||||
exit;
|
||||
} else {
|
||||
// Displaying the header
|
||||
Display::display_header($tool_name);
|
||||
$actionLeft = null;
|
||||
//if is called from learning path
|
||||
if (isset($_GET['lp_id'])) {
|
||||
$lpId = (int) $_GET['lp_id'];
|
||||
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.$lpId.'#resource_tab-6';
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'back.png',
|
||||
get_lang("BackTo").' '.get_lang("LearningPaths"),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$url
|
||||
);
|
||||
echo Display::toolbarAction('toolbar-forum', [$actionLeft]);
|
||||
}
|
||||
$form->display();
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
256
main/survey/edit_meeting.php
Normal file
256
main/survey/edit_meeting.php
Normal file
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
if (!api_is_session_general_coach() ||
|
||||
(!empty($_GET['survey_id']) &&
|
||||
!api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_css_asset('jt.timepicker/jquery.timepicker.css');
|
||||
$htmlHeadXtra[] = api_get_asset('jt.timepicker/jquery.timepicker.js');
|
||||
$htmlHeadXtra[] = api_get_asset('datepair.js/dist/datepair.js');
|
||||
$htmlHeadXtra[] = api_get_asset('datepair.js/dist/jquery.datepair.js');
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
|
||||
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null;
|
||||
$surveyData = SurveyManager::get_survey($surveyId);
|
||||
|
||||
if (empty($surveyData)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$courseInfo = api_get_course_info();
|
||||
|
||||
$tool_name = get_lang('Edit');
|
||||
|
||||
$form = new FormValidator(
|
||||
'survey',
|
||||
'post',
|
||||
api_get_self().'?action=edit&'.api_get_cidreq().'&survey_id='.$surveyId
|
||||
);
|
||||
|
||||
$form->addElement('header', $tool_name);
|
||||
$form->addHidden('anonymous', 0);
|
||||
$form->addHidden('survey_language', $courseInfo['language']);
|
||||
$form->addHidden('survey_subtitle', '');
|
||||
$form->addHidden('survey_thanks', '');
|
||||
$form->addHidden('visible_results', '0');
|
||||
$form->addHidden('survey_type', 3);
|
||||
|
||||
$text = $form->addText(
|
||||
'survey_title',
|
||||
get_lang('Title')
|
||||
);
|
||||
|
||||
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
|
||||
|
||||
if ($allowSurveyAvailabilityDatetime) {
|
||||
$form->addDateTimePicker('start_date', get_lang('StartDate'));
|
||||
$form->addDateTimePicker('end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'datetime');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'datetime');
|
||||
} else {
|
||||
$form->addElement('date_picker', 'start_date', get_lang('StartDate'));
|
||||
$form->addElement('date_picker', 'end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
|
||||
}
|
||||
|
||||
$form->addRule(
|
||||
['start_date', 'end_date'],
|
||||
get_lang('StartDateShouldBeBeforeEndDate'),
|
||||
'date_compare',
|
||||
'lte'
|
||||
);
|
||||
|
||||
$form->addHtmlEditor('survey_introduction', get_lang('Description'), false);
|
||||
$form->setRequired($text);
|
||||
|
||||
$questions = SurveyManager::get_questions($surveyData['iid']);
|
||||
$currentQuestionsCount = count($questions);
|
||||
$counter = 1;
|
||||
foreach ($questions as $question) {
|
||||
$name = 'time_'.$counter;
|
||||
$parts = explode('@@', $question['question']);
|
||||
$surveyData[$name] = api_get_local_time($parts[0]).'@@'.api_get_local_time($parts[1]);
|
||||
|
||||
$form->addDateTimeRangePicker($name, get_lang('Date'));
|
||||
$form->addHidden($name.'_question_id', $question['question_id']);
|
||||
$counter++;
|
||||
}
|
||||
$currentQuestionsCount++;
|
||||
|
||||
$hideList = '';
|
||||
$maxEvents = $currentQuestionsCount + 10;
|
||||
for ($i = $currentQuestionsCount; $i <= $maxEvents; $i++) {
|
||||
$name = 'time_'.$i;
|
||||
$form->addDateTimeRangePicker($name, get_lang('Date'));
|
||||
$hideList .= "$('#".$name."_date_time_wrapper').hide();";
|
||||
}
|
||||
|
||||
$form->addHtml('<script>
|
||||
$(function() {
|
||||
'.$hideList.'
|
||||
var number = "'.--$currentQuestionsCount.'";
|
||||
$("#add_button").on("click", function() {
|
||||
number++;
|
||||
$("#time_" + number + "_date_time_wrapper").show();
|
||||
$("#time_" + number + "_time_range_start").val("");
|
||||
$("#time_" + number + "_time_range_end").val("");
|
||||
$("#time_" + number + "_alt").val("");
|
||||
});
|
||||
|
||||
$("#remove_button").on("click", function() {
|
||||
if (number > 1) {
|
||||
console.log("#time_" + number + "_time_range_start");
|
||||
$("#time_" + number + "_date_time_wrapper").hide();
|
||||
$("#time_" + number).val("delete");
|
||||
|
||||
$("#time_" + number + "_alt").val("delete");
|
||||
$("#time_" + number + "_time_range_start").val("delete");
|
||||
number--;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>');
|
||||
|
||||
$form->addLabel(
|
||||
'',
|
||||
Display::url(get_lang('Add'), 'javascript:void(0)', ['id' => 'add_button', 'class' => 'btn btn-default'])
|
||||
.' '.
|
||||
Display::url(
|
||||
get_lang('Remove'),
|
||||
'javascript:void(0)',
|
||||
['id' => 'remove_button', 'class' => 'btn btn-danger']
|
||||
)
|
||||
);
|
||||
|
||||
$form->addButtonUpdate(get_lang('Edit'), 'submit_survey');
|
||||
$surveyData['start_date'] = date(
|
||||
$allowSurveyAvailabilityDatetime ? 'Y-m-d H:i:s' : 'Y-m-d',
|
||||
api_strtotime(api_get_local_time($surveyData['start_date']))
|
||||
);
|
||||
$surveyData['end_date'] = date(
|
||||
$allowSurveyAvailabilityDatetime ? 'Y-m-d H:i:s' : 'Y-m-d',
|
||||
api_strtotime(api_get_local_time($surveyData['end_date']))
|
||||
);
|
||||
$form->setDefaults($surveyData);
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
// Exporting the values
|
||||
$values = $form->getSubmitValues();
|
||||
|
||||
$values['survey_id'] = $surveyId;
|
||||
$values['survey_code'] = SurveyManager::generateSurveyCode($values['survey_title']);
|
||||
// Storing the survey
|
||||
SurveyManager::store_survey($values);
|
||||
|
||||
$dates = [];
|
||||
$deleteItems = [];
|
||||
|
||||
for ($i = 1; $i <= $maxEvents; $i++) {
|
||||
$name = 'time_'.$i;
|
||||
|
||||
if (isset($values[$name]) && !empty($values[$name])) {
|
||||
$id = '';
|
||||
if (isset($values[$name.'_question_id'])) {
|
||||
$id = $values[$name.'_question_id'];
|
||||
}
|
||||
|
||||
$date = $values[$name];
|
||||
|
||||
if ('delete' === $date && !empty($id)) {
|
||||
$deleteItems[] = $id;
|
||||
}
|
||||
|
||||
if (empty($date)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $name.'_time_range_start';
|
||||
$end = $name.'_time_range_end';
|
||||
|
||||
$start = $values[$start];
|
||||
$end = $values[$end];
|
||||
|
||||
$part = explode('@@', $values[$name]);
|
||||
$firstDate = substr($part[0], 0, 10);
|
||||
|
||||
$start = api_get_utc_datetime($firstDate.' '.$start);
|
||||
$end = api_get_utc_datetime($firstDate.' '.$end);
|
||||
|
||||
if (!empty($start) && !empty($start)) {
|
||||
$row = [
|
||||
'id' => $id,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
];
|
||||
$dates[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$questionTable = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$counter = 1;
|
||||
if (!empty($surveyData['iid'])) {
|
||||
foreach ($dates as $date) {
|
||||
$formattedDate = $date['start'].'@@'.$date['end'];
|
||||
if (!empty($date['id'])) {
|
||||
$questionId = $date['id'];
|
||||
$sql = "UPDATE $questionTable SET survey_question = '$formattedDate'
|
||||
WHERE iid = $questionId";
|
||||
Database::query($sql);
|
||||
} else {
|
||||
$params = [
|
||||
'c_id' => api_get_course_int_id(),
|
||||
'survey_id' => $surveyData['iid'],
|
||||
'survey_question' => $formattedDate,
|
||||
'survey_question_comment' => '',
|
||||
'type' => 'doodle',
|
||||
'display' => 'horizontal',
|
||||
'sort' => $counter,
|
||||
'shared_question_id' => '0',
|
||||
'max_value' => 0,
|
||||
];
|
||||
$questionId = Database::insert($questionTable, $params);
|
||||
if ($questionId) {
|
||||
$sql = "UPDATE $questionTable SET question_id = $questionId
|
||||
WHERE iid = $questionId";
|
||||
Database::query($sql);
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($deleteItems as $deleteId) {
|
||||
SurveyManager::delete_survey_question($surveyData['iid'], $deleteId);
|
||||
}
|
||||
}
|
||||
|
||||
// Redirecting to the survey page (whilst showing the return message)
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
|
||||
exit;
|
||||
} else {
|
||||
// Displaying the header
|
||||
Display::display_header($tool_name);
|
||||
$form->display();
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
1574
main/survey/fillsurvey.php
Normal file
1574
main/survey/fillsurvey.php
Normal file
File diff suppressed because it is too large
Load Diff
51
main/survey/generate_link.php
Normal file
51
main/survey/generate_link.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
if (!api_is_allowed_to_edit(false, true)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$survey_id = isset($_REQUEST['survey_id']) ? (int) $_REQUEST['survey_id'] : null;
|
||||
|
||||
if (empty($survey_id)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$survey_data = SurveyManager::get_survey($survey_id);
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
|
||||
'name' => strip_tags($survey_data['title']),
|
||||
];
|
||||
|
||||
Display::display_header(get_lang('Survey'), 'Survey');
|
||||
|
||||
if (!SurveyManager::survey_generation_hash_available()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$link = SurveyManager::generate_survey_link(
|
||||
$survey_id,
|
||||
api_get_course_int_id(),
|
||||
api_get_session_id(),
|
||||
api_get_group_id()
|
||||
);
|
||||
echo '<div class="row">';
|
||||
echo '<div class="col-md-12">';
|
||||
echo Display::url(get_lang('GoToSurvey'), $link, ['class' => 'btn btn-primary btn-large']);
|
||||
echo '</div>';
|
||||
echo '<div class="col-md-12">';
|
||||
echo get_lang('GenerateSurveyAccessLinkExplanation');
|
||||
|
||||
echo '<pre>';
|
||||
echo $link;
|
||||
echo '</pre>';
|
||||
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
6
main/survey/index.php
Normal file
6
main/survey/index.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
|
||||
exit;
|
||||
49
main/survey/link.php
Normal file
49
main/survey/link.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$surveyId = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : 0;
|
||||
$sessionId = isset($_REQUEST['s']) ? (int) $_REQUEST['s'] : 0;
|
||||
$courseId = isset($_REQUEST['c']) ? (int) $_REQUEST['c'] : 0;
|
||||
|
||||
if (empty($surveyId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
if (!SurveyManager::survey_generation_hash_available()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$hashIsValid = SurveyManager::validate_survey_hash(
|
||||
$surveyId,
|
||||
$courseId,
|
||||
$sessionId,
|
||||
$_REQUEST['g'],
|
||||
$_REQUEST['h']
|
||||
);
|
||||
if ($hashIsValid && $courseInfo) {
|
||||
$survey_data = SurveyManager::get_survey(
|
||||
$surveyId,
|
||||
null,
|
||||
$courseInfo['code']
|
||||
);
|
||||
|
||||
$invitation_code = api_get_unique_id();
|
||||
$params = [
|
||||
'c_id' => $courseId,
|
||||
'session_id' => $sessionId,
|
||||
'user' => $invitation_code,
|
||||
'survey_code' => $survey_data['code'],
|
||||
'invitation_code' => $invitation_code,
|
||||
'invitation_date' => api_get_utc_datetime(),
|
||||
];
|
||||
$invitation_id = SurveyUtil::save_invitation($params);
|
||||
|
||||
if ($invitation_id) {
|
||||
$link = SurveyUtil::generateFillSurveyLink($invitation_code, $courseInfo['code'], $sessionId);
|
||||
header('Location: '.$link);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
288
main/survey/meeting.php
Normal file
288
main/survey/meeting.php
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
$sessionId = api_get_session_id();
|
||||
$courseId = api_get_course_int_id();
|
||||
$userId = api_get_user_id();
|
||||
$courseInfo = api_get_course_info();
|
||||
|
||||
$surveyId = isset($_REQUEST['survey_id']) ? (int) $_REQUEST['survey_id'] : 0;
|
||||
$invitationcode = isset($_REQUEST['invitationcode']) ? Database::escape_string($_REQUEST['invitationcode']) : 0;
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
|
||||
|
||||
if (!empty($invitationcode) || !api_is_allowed_to_edit()) {
|
||||
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
|
||||
$sql = "SELECT * FROM $table_survey_invitation
|
||||
WHERE
|
||||
c_id = $courseId AND
|
||||
invitation_code = '".Database::escape_string($invitationcode)."'";
|
||||
$result = Database::query($sql);
|
||||
if (Database::num_rows($result) < 1) {
|
||||
api_not_allowed(true, get_lang('WrongInvitationCode'));
|
||||
}
|
||||
|
||||
$survey_invitation = Database::fetch_array($result, 'ASSOC');
|
||||
$sql = "SELECT * FROM $table_survey
|
||||
WHERE
|
||||
c_id = $courseId AND
|
||||
code = '".Database::escape_string($survey_invitation['survey_code'])."'";
|
||||
$sql .= api_get_session_condition($sessionId);
|
||||
$result = Database::query($sql);
|
||||
$result = Database::fetch_array($result, 'ASSOC');
|
||||
$surveyId = $result['iid'];
|
||||
}
|
||||
|
||||
$surveyData = SurveyManager::get_survey($surveyId);
|
||||
|
||||
if (empty($surveyData)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
SurveyManager::checkTimeAvailability($surveyData);
|
||||
}
|
||||
|
||||
$invitations = SurveyUtil::get_invited_users($surveyData['code']);
|
||||
$students = isset($invitations['course_users']) ? $invitations['course_users'] : [];
|
||||
|
||||
$content = Display::page_header($surveyData['title']);
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).
|
||||
'survey/survey_list.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId,
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
|
||||
$questions = SurveyManager::get_questions($surveyData['iid']);
|
||||
|
||||
$url = api_get_self().'?survey_id='.$surveyId.'&invitationcode='.$invitationcode.'&'.api_get_cidreq();
|
||||
$urlEdit = $url.'&action=edit';
|
||||
|
||||
if (isset($_POST) && !empty($_POST)) {
|
||||
$options = isset($_POST['options']) ? array_keys($_POST['options']) : [];
|
||||
|
||||
foreach ($questions as $item) {
|
||||
$questionId = $item['question_id'];
|
||||
SurveyUtil::remove_answer(
|
||||
$userId,
|
||||
$surveyId,
|
||||
$questionId,
|
||||
$courseId
|
||||
);
|
||||
}
|
||||
|
||||
$status = 1;
|
||||
if (!empty($options)) {
|
||||
foreach ($options as $selectedQuestionId) {
|
||||
SurveyUtil::store_answer(
|
||||
$userId,
|
||||
$surveyId,
|
||||
$selectedQuestionId,
|
||||
1,
|
||||
$status,
|
||||
$surveyData
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach ($questions as $item) {
|
||||
$questionId = $item['question_id'];
|
||||
SurveyUtil::store_answer(
|
||||
$userId,
|
||||
$surveyId,
|
||||
$questionId,
|
||||
1,
|
||||
0,
|
||||
$surveyData
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SurveyManager::update_survey_answered(
|
||||
$surveyData,
|
||||
$survey_invitation['user'],
|
||||
$survey_invitation['survey_code']
|
||||
);
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Saved')));
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
|
||||
$template = new Template();
|
||||
|
||||
$table = new HTML_Table(['class' => 'table']);
|
||||
|
||||
$row = 0;
|
||||
$column = 1;
|
||||
$answerList = [];
|
||||
foreach ($questions as $item) {
|
||||
$answers = SurveyUtil::get_answers_of_question_by_user($surveyId, $item['question_id']);
|
||||
foreach ($answers as $tempUserId => &$value) {
|
||||
$value = $value[0];
|
||||
$value = explode('*', $value);
|
||||
$value = isset($value[1]) ? $value[1] : 0;
|
||||
}
|
||||
$answerList[$item['question_id']] = $answers;
|
||||
$parts = explode('@@', $item['question']);
|
||||
$startDateTime = api_get_local_time($parts[0]);
|
||||
$endDateTime = api_get_local_time($parts[1]);
|
||||
|
||||
$date = explode(' ', $startDateTime);
|
||||
$endDate = explode(' ', $endDateTime);
|
||||
$mainDate = $date[0];
|
||||
|
||||
$startTime = isset($date[1]) && !empty($date[1]) ? sprintf(get_lang('FromTimeX'), $date[1]) : '';
|
||||
$endTime = isset($endDate[1]) && !empty($endDate[1]) ? sprintf(get_lang('ToTimeX'), $endDate[1]) : '';
|
||||
|
||||
if (isset($date[1]) && isset($endDate[1])) {
|
||||
if ($date[1] === $endDate[1]) {
|
||||
$startTime = '';
|
||||
$endTime = '';
|
||||
}
|
||||
}
|
||||
|
||||
$mainDate = api_format_date($mainDate, DATE_FORMAT_SHORT);
|
||||
$table->setHeaderContents($row, $column, "<h4>$mainDate</h4> $startTime <br >$endTime");
|
||||
$column++;
|
||||
}
|
||||
|
||||
$row = 1;
|
||||
$column = 0;
|
||||
|
||||
// Total counter
|
||||
$table->setHeaderContents(
|
||||
$row,
|
||||
0,
|
||||
get_lang('NumberOfUsers').': '.count($students)
|
||||
);
|
||||
|
||||
foreach ($questions as $item) {
|
||||
$questionId = $item['question_id'];
|
||||
$count = 0;
|
||||
$questionsWithAnswer = 0;
|
||||
if (isset($answerList[$questionId])) {
|
||||
foreach ($answerList[$questionId] as $userAnswer) {
|
||||
if ((int) $userAnswer === 1) {
|
||||
$questionsWithAnswer++;
|
||||
}
|
||||
}
|
||||
$count = '<p style="color:cornflowerblue" >
|
||||
<span class="fa fa-check fa-2x"></span>'.$questionsWithAnswer.'</p>';
|
||||
}
|
||||
$table->setHeaderContents(
|
||||
$row,
|
||||
++$column,
|
||||
$count
|
||||
);
|
||||
}
|
||||
|
||||
$row = 2;
|
||||
$column = 0;
|
||||
$availableIcon = Display::return_icon('bullet_green.png', get_lang('Available'));
|
||||
$notAvailableIcon = Display::return_icon('bullet_red.png', get_lang('NotAvailable'));
|
||||
|
||||
foreach ($students as $studentId) {
|
||||
$userInfo = api_get_user_info($studentId);
|
||||
$name = $userInfo['complete_name'];
|
||||
if ($userId == $studentId) {
|
||||
if ($action !== 'edit') {
|
||||
$name .= Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
$urlEdit
|
||||
);
|
||||
}
|
||||
$rowColumn = 1;
|
||||
foreach ($questions as $item) {
|
||||
$checked = '';
|
||||
$html = '';
|
||||
if (isset($answerList[$item['question_id']][$studentId])) {
|
||||
$checked = $availableIcon;
|
||||
if (empty($answerList[$item['question_id']][$studentId])) {
|
||||
$checked = $notAvailableIcon;
|
||||
}
|
||||
if ($action === 'edit') {
|
||||
$checked = '';
|
||||
if ($answerList[$item['question_id']][$studentId] == 1) {
|
||||
$checked = 'checked';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === 'edit') {
|
||||
$html = '<div class="alert alert-info"><input
|
||||
id="'.$item['question_id'].'"
|
||||
name="options['.$item['question_id'].']"
|
||||
class="question" '.$checked.'
|
||||
type="checkbox"
|
||||
/></div>';
|
||||
} else {
|
||||
$html = $checked;
|
||||
}
|
||||
|
||||
$table->setHeaderContents(
|
||||
$row,
|
||||
$rowColumn,
|
||||
$html
|
||||
);
|
||||
$rowColumn++;
|
||||
}
|
||||
} else {
|
||||
$rowColumn = 1;
|
||||
foreach ($questions as $item) {
|
||||
$checked = '';
|
||||
if (isset($answerList[$item['question_id']][$studentId])) {
|
||||
$checked = $availableIcon;
|
||||
if (empty($answerList[$item['question_id']][$studentId])) {
|
||||
$checked = $notAvailableIcon;
|
||||
}
|
||||
}
|
||||
$table->setHeaderContents(
|
||||
$row,
|
||||
$rowColumn,
|
||||
$checked
|
||||
);
|
||||
$rowColumn++;
|
||||
}
|
||||
}
|
||||
$column = 0;
|
||||
$table->setCellContents($row, $column, $name);
|
||||
$row++;
|
||||
}
|
||||
if ($action === 'edit') {
|
||||
$content .= '<form name="meeting" action="'.$urlEdit.'" method="post">';
|
||||
}
|
||||
|
||||
$content .= $table->toHtml();
|
||||
|
||||
if ($action === 'edit') {
|
||||
$content .= '<div class="pull-right">
|
||||
<button name="submit" type="submit" class="btn btn-primary btn-lg">'.get_lang('Save').'</button></div>';
|
||||
$content .= '</form>';
|
||||
}
|
||||
|
||||
$actions = '';
|
||||
if (api_is_allowed_to_edit()) {
|
||||
$actions .= Display::url(
|
||||
Display::return_icon('edit.png', get_lang('EditSurvey'), '', ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'survey/edit_meeting.php?'.api_get_cidreq().'&action=edit&survey_id='.$surveyId
|
||||
);
|
||||
$actions .= Display::url(
|
||||
Display::return_icon('delete.png', get_lang('DeleteSurvey'), '', ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&action=delete&survey_id='.$surveyId,
|
||||
['onclick' => 'javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;']
|
||||
);
|
||||
$actions .= Display::url(
|
||||
Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&survey_id='.$surveyId
|
||||
);
|
||||
}
|
||||
|
||||
$template->assign('actions', Display::toolbarAction('toolbar', [$actions]));
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
64
main/survey/pending.php
Normal file
64
main/survey/pending.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
use Chamilo\CourseBundle\Entity\CSurvey;
|
||||
use Chamilo\CourseBundle\Entity\CSurveyInvitation;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_block_anonymous_users();
|
||||
|
||||
$em = Database::getManager();
|
||||
|
||||
$currentUser = api_get_user_entity(api_get_user_id());
|
||||
$avatarPath = UserManager::getUserPicture($currentUser->getId());
|
||||
$pending = SurveyUtil::getUserPendingInvitations($currentUser->getId());
|
||||
|
||||
$surveysData = [];
|
||||
|
||||
foreach ($pending as $i => $item) {
|
||||
if (is_a($item, 'Chamilo\CourseBundle\Entity\CSurveyInvitation')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var CSurvey $survey */
|
||||
$survey = $item;
|
||||
/** @var CSurveyInvitation invitation */
|
||||
$invitation = $pending[$i + 1];
|
||||
/** @var Course $course */
|
||||
$course = $em->find('ChamiloCoreBundle:Course', $survey->getCId());
|
||||
/** @var Session $session */
|
||||
$session = $em->find('ChamiloCoreBundle:Session', $survey->getSessionId());
|
||||
|
||||
$course = $course ? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()] : null;
|
||||
$session = $session ? ['id' => $session->getId(), 'name' => $session->getName()] : null;
|
||||
|
||||
$surveysData[$survey->getSurveyId()] = [
|
||||
'title' => $survey->getTitle(),
|
||||
'avail_from' => $survey->getAvailFrom(),
|
||||
'avail_till' => $survey->getAvailTill(),
|
||||
'course' => $course,
|
||||
'session' => $session,
|
||||
'link' => SurveyUtil::generateFillSurveyLink(
|
||||
$invitation->getInvitationCode(),
|
||||
api_get_course_info_by_id($course['id']),
|
||||
$survey->getSessionId()
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
$toolName = get_lang('PendingSurveys');
|
||||
|
||||
$template = new Template($toolName);
|
||||
$template->assign('user', $currentUser);
|
||||
$template->assign('user_avatar', $avatarPath);
|
||||
$template->assign('surveys', $surveysData);
|
||||
$layout = $template->get_template('survey/pending.tpl');
|
||||
$content = $template->fetch($layout);
|
||||
$template->assign('header', $toolName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
286
main/survey/preview.php
Normal file
286
main/survey/preview.php
Normal file
@@ -0,0 +1,286 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$surveyId = (int) $_GET['survey_id'];
|
||||
|
||||
if (empty($surveyId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Getting the survey information
|
||||
$survey_data = SurveyManager::get_survey($surveyId);
|
||||
|
||||
if (empty($survey_data)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
|
||||
|
||||
$course_id = api_get_course_int_id();
|
||||
$courseInfo = api_get_course_info();
|
||||
$allowRequiredSurveyQuestions = api_get_configuration_value('allow_required_survey_questions');
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'&'.api_get_cidreq(),
|
||||
'name' => strip_tags($survey_data['title'], '<span>'),
|
||||
];
|
||||
|
||||
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
|
||||
$htmlHeadXtra[] = ch_selectivedisplay::getJs();
|
||||
$htmlHeadXtra[] = survey_question::getJs();
|
||||
$show = 0;
|
||||
Display::display_header(get_lang('SurveyPreview'));
|
||||
|
||||
// We exit here is the first or last question is a pagebreak (which causes errors)
|
||||
SurveyUtil::check_first_last_question($surveyId, false);
|
||||
|
||||
// Survey information
|
||||
echo '<div class="page-header"><h2>'.Security::remove_XSS($survey_data['survey_title']).'</h2></div>';
|
||||
if (!empty($survey_data['survey_subtitle'])) {
|
||||
echo '<div id="survey_subtitle">'.Security::remove_XSS($survey_data['survey_subtitle']).'</div>';
|
||||
}
|
||||
|
||||
// Displaying the survey introduction
|
||||
if (!isset($_GET['show'])) {
|
||||
if (!empty($survey_data['survey_introduction'])) {
|
||||
echo '<div class="survey_content">'.Security::remove_XSS($survey_data['survey_introduction']).'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the survey thanks message
|
||||
if (isset($_POST['finish_survey'])) {
|
||||
echo Display::return_message(get_lang('SurveyFinished'), 'confirm');
|
||||
echo Security::remove_XSS($survey_data['survey_thanks']);
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
$questions = [];
|
||||
$pageBreakText = [];
|
||||
if (isset($_GET['show'])) {
|
||||
// Getting all the questions for this page and add them to a
|
||||
// multidimensional array where the first index is the page.
|
||||
// as long as there is no pagebreak fount we keep adding questions to the page
|
||||
$paged_questions = [];
|
||||
$counter = 0;
|
||||
$sql = "SELECT * FROM $table_survey_question
|
||||
WHERE
|
||||
survey_question NOT LIKE '%{{%' AND
|
||||
c_id = $course_id AND
|
||||
survey_id = $surveyId
|
||||
ORDER BY sort ASC";
|
||||
$result = Database::query($sql);
|
||||
$questions_exists = true;
|
||||
if (Database::num_rows($result)) {
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
if (1 == $survey_data['one_question_per_page']) {
|
||||
if ('pagebreak' !== $row['type']) {
|
||||
$paged_questions[$counter][] = $row['question_id'];
|
||||
$counter++;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ('pagebreak' === $row['type']) {
|
||||
$counter++;
|
||||
$pageBreakText[$counter] = $row['survey_question'];
|
||||
} else {
|
||||
$paged_questions[$counter][] = $row['question_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$questions_exists = false;
|
||||
}
|
||||
|
||||
if (array_key_exists($_GET['show'], $paged_questions)) {
|
||||
$select = '';
|
||||
if (true === api_get_configuration_value('survey_question_dependency')) {
|
||||
$select = ' survey_question.parent_id, survey_question.parent_option_id, ';
|
||||
}
|
||||
$sql = "SELECT
|
||||
survey_question.question_id,
|
||||
survey_question.survey_id,
|
||||
survey_question.survey_question,
|
||||
survey_question.display,
|
||||
survey_question.sort,
|
||||
survey_question.type,
|
||||
survey_question.max_value,
|
||||
survey_question_option.question_option_id,
|
||||
survey_question_option.option_text,
|
||||
$select
|
||||
survey_question_option.sort as option_sort
|
||||
".($allowRequiredSurveyQuestions ? ', survey_question.is_required' : '')."
|
||||
FROM $table_survey_question survey_question
|
||||
LEFT JOIN $table_survey_question_option survey_question_option
|
||||
ON
|
||||
survey_question.question_id = survey_question_option.question_id AND
|
||||
survey_question_option.c_id = survey_question.c_id
|
||||
WHERE
|
||||
survey_question.survey_id = '".$surveyId."' AND
|
||||
survey_question.question_id IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND
|
||||
survey_question.c_id = $course_id AND
|
||||
survey_question NOT LIKE '%{{%'
|
||||
ORDER BY survey_question.sort, survey_question_option.sort ASC";
|
||||
|
||||
$result = Database::query($sql);
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
// If the type is not a pagebreak we store it in the $questions array
|
||||
if ('pagebreak' !== $row['type']) {
|
||||
$sort = $row['sort'];
|
||||
$questions[$sort]['question_id'] = $row['question_id'];
|
||||
$questions[$sort]['survey_id'] = $row['survey_id'];
|
||||
$questions[$sort]['survey_question'] = Security::remove_XSS($row['survey_question']);
|
||||
$questions[$sort]['display'] = $row['display'];
|
||||
$questions[$sort]['type'] = $row['type'];
|
||||
$questions[$sort]['options'][$row['question_option_id']] = Security::remove_XSS($row['option_text']);
|
||||
$questions[$sort]['maximum_score'] = $row['max_value'];
|
||||
$questions[$sort]['parent_id'] = isset($row['parent_id']) ? $row['parent_id'] : 0;
|
||||
$questions[$sort]['parent_option_id'] = isset($row['parent_option_id']) ? $row['parent_option_id'] : 0;
|
||||
$questions[$row['sort']]['is_required'] = $allowRequiredSurveyQuestions && $row['is_required'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$numberOfPages = SurveyManager::getCountPages($survey_data);
|
||||
|
||||
// Displaying the form with the questions
|
||||
if (isset($_GET['show'])) {
|
||||
$show = (int) $_GET['show'] + 1;
|
||||
}
|
||||
$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
|
||||
|
||||
$url = api_get_self().'?survey_id='.$surveyId.'&show='.$show.'&'.api_get_cidreq();
|
||||
|
||||
$form = new FormValidator(
|
||||
'question-survey',
|
||||
'post',
|
||||
$url,
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if (is_array($questions) && count($questions) > 0) {
|
||||
$counter = 1;
|
||||
if (!empty($originalShow)) {
|
||||
$before = 0;
|
||||
foreach ($paged_questions as $keyQuestion => $list) {
|
||||
if ($originalShow > $keyQuestion) {
|
||||
$before += count($list);
|
||||
}
|
||||
}
|
||||
$counter = $before + 1;
|
||||
}
|
||||
|
||||
$showNumber = true;
|
||||
if (SurveyManager::hasDependency($survey_data)) {
|
||||
$showNumber = false;
|
||||
}
|
||||
|
||||
$js = '';
|
||||
|
||||
if (isset($pageBreakText[$originalShow]) && !empty(strip_tags($pageBreakText[$originalShow]))) {
|
||||
// Only show page-break texts if there is something there, apart from
|
||||
// HTML tags
|
||||
$form->addHtml(
|
||||
'<div>'.
|
||||
Security::remove_XSS($pageBreakText[$originalShow]).
|
||||
'</div>'
|
||||
);
|
||||
$form->addHtml('<br />');
|
||||
}
|
||||
|
||||
foreach ($questions as $key => &$question) {
|
||||
$ch_type = 'ch_'.$question['type'];
|
||||
$display = survey_question::createQuestion($question['type']);
|
||||
$parent = $question['parent_id'];
|
||||
$parentClass = '';
|
||||
|
||||
if (!empty($parent)) {
|
||||
$parentClass = ' with_parent with_parent_'.$question['question_id'];
|
||||
$parents = survey_question::getParents($question['question_id']);
|
||||
if (!empty($parents)) {
|
||||
foreach ($parents as $parentId) {
|
||||
$parentClass .= ' with_parent_only_hide_'.$parentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$js .= survey_question::getQuestionJs($question);
|
||||
|
||||
$form->addHtml('<div class="survey_question '.$ch_type.' '.$parentClass.'">');
|
||||
if ($showNumber) {
|
||||
$form->addHtml('<div style="float:left; font-weight: bold; margin-right: 5px;"> '.$counter.'. </div>');
|
||||
}
|
||||
$form->addHtml('<div>'.Security::remove_XSS($question['survey_question']).'</div>');
|
||||
$display->render($form, $question);
|
||||
$form->addHtml('</div>');
|
||||
$counter++;
|
||||
}
|
||||
$form->addHtml($js);
|
||||
}
|
||||
$form->addHtml('<div class="start-survey">');
|
||||
|
||||
if ($show < $numberOfPages) {
|
||||
if ($show == 0) {
|
||||
$form->addButton(
|
||||
'next_survey_page',
|
||||
get_lang('StartSurvey'),
|
||||
'arrow-right',
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
$form->addButton(
|
||||
'next_survey_page',
|
||||
get_lang('NextQuestion'),
|
||||
'arrow-right',
|
||||
'success'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['show'])) {
|
||||
if ($show >= $numberOfPages || count($questions) == 0) {
|
||||
if ($questions_exists == false) {
|
||||
echo '<p>'.get_lang('ThereAreNotQuestionsForthisSurvey').'</p>';
|
||||
}
|
||||
$form->addButton(
|
||||
'finish_survey',
|
||||
get_lang('FinishSurvey'),
|
||||
'arrow-right',
|
||||
'success'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHtml('</div>');
|
||||
$form->display();
|
||||
|
||||
echo Display::toolbarButton(
|
||||
get_lang('ReturnToCourseHomepage'),
|
||||
api_get_course_url($courseInfo['code']),
|
||||
'home'
|
||||
);
|
||||
|
||||
Display::display_footer();
|
||||
155
main/survey/question.php
Normal file
155
main/survey/question.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
|
||||
* refactoring and rewriting large parts of the code
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
$("button").click(function() {
|
||||
$("#is_executable").attr("value",$(this).attr("name"));
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
|
||||
|
||||
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
|
||||
if (!api_is_allowed_to_edit(false, true)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
|
||||
// Getting the survey information
|
||||
$surveyData = SurveyManager::get_survey($surveyId);
|
||||
if (empty($surveyData)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Is valid request
|
||||
$is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null;
|
||||
|
||||
// Database table definitions
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
|
||||
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$course_id = api_get_course_int_id();
|
||||
$urlname = api_substr(api_html_entity_decode($surveyData['title'], ENT_QUOTES), 0, 40);
|
||||
if (api_strlen(strip_tags($surveyData['title'])) > 40) {
|
||||
$urlname .= '...';
|
||||
}
|
||||
|
||||
if (1 == $surveyData['survey_type']) {
|
||||
$sql = 'SELECT id FROM '.Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP).'
|
||||
WHERE
|
||||
c_id = '.$course_id.' AND
|
||||
survey_id = '.$surveyId.' LIMIT 1';
|
||||
$rs = Database::query($sql);
|
||||
if (0 === Database::num_rows($rs)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('YouNeedToCreateGroups'))
|
||||
);
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId,
|
||||
'name' => strip_tags($urlname),
|
||||
];
|
||||
|
||||
// Tool name
|
||||
if ($_GET['action'] === 'add') {
|
||||
$tool_name = get_lang('AddQuestion');
|
||||
}
|
||||
if ($_GET['action'] === 'edit') {
|
||||
$tool_name = get_lang('EditQuestion');
|
||||
}
|
||||
|
||||
// The possible question types
|
||||
$possible_types = [
|
||||
'personality',
|
||||
'yesno',
|
||||
'multiplechoice',
|
||||
'multipleresponse',
|
||||
'open',
|
||||
'dropdown',
|
||||
'comment',
|
||||
'pagebreak',
|
||||
'percentage',
|
||||
'score',
|
||||
'selectivedisplay',
|
||||
'multiplechoiceother',
|
||||
];
|
||||
|
||||
// Actions
|
||||
$actions = '<div class="actions">';
|
||||
$actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'">'.
|
||||
Display::return_icon('back.png', get_lang('BackToSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
$actions .= '</div>';
|
||||
// Checking if it is a valid type
|
||||
if (!in_array($_GET['type'], $possible_types)) {
|
||||
api_not_allowed(true, Display::return_message(get_lang('TypeDoesNotExist'), 'error', false));
|
||||
}
|
||||
|
||||
// Displaying the form for adding or editing the question
|
||||
$ch_type = 'ch_'.$_GET['type'];
|
||||
/** @var survey_question $surveyQuestion */
|
||||
$surveyQuestion = new $ch_type();
|
||||
|
||||
// The defaults values for the form
|
||||
$formData = [];
|
||||
$formData['answers'] = ['', ''];
|
||||
|
||||
switch ($_GET['type']) {
|
||||
case 'selectivedisplay':
|
||||
case 'yesno':
|
||||
$formData['answers'][0] = get_lang('Yes');
|
||||
$formData['answers'][1] = get_lang('No');
|
||||
break;
|
||||
case 'personality':
|
||||
$formData['answers'][0] = 1;
|
||||
$formData['answers'][1] = 2;
|
||||
$formData['answers'][2] = 3;
|
||||
$formData['answers'][3] = 4;
|
||||
$formData['answers'][4] = 5;
|
||||
|
||||
$formData['values'][0] = 0;
|
||||
$formData['values'][1] = 0;
|
||||
$formData['values'][2] = 1;
|
||||
$formData['values'][3] = 2;
|
||||
$formData['values'][4] = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
// We are editing a question
|
||||
if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
|
||||
$formData = SurveyManager::get_question($_GET['question_id']);
|
||||
}
|
||||
|
||||
$formData = $surveyQuestion->preSave($formData);
|
||||
$surveyQuestion->createForm($surveyData, $formData);
|
||||
$surveyQuestion->getForm()->setDefaults($formData);
|
||||
$surveyQuestion->renderForm();
|
||||
|
||||
if ($surveyQuestion->getForm()->validate()) {
|
||||
$values = $surveyQuestion->getForm()->getSubmitValues();
|
||||
$surveyQuestion->save($surveyData, $values, $formData);
|
||||
}
|
||||
|
||||
Display::display_header($tool_name, 'Survey');
|
||||
echo $surveyQuestion->getForm()->returnForm();
|
||||
Display::display_footer();
|
||||
363
main/survey/reporting.php
Normal file
363
main/survey/reporting.php
Normal file
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup,
|
||||
* refactoring and rewriting large parts of the code
|
||||
*
|
||||
* @todo The question has to be more clearly indicated (same style as when filling the survey)
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
$survey_id = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
|
||||
$userId = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : 'overview';
|
||||
$lpItemId = isset($_GET['lp_item_id']) ? (int) $_GET['lp_item_id'] : 0;
|
||||
$survey_data = SurveyManager::get_survey($survey_id);
|
||||
|
||||
if (empty($survey_data)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (0 == $survey_data['anonymous']) {
|
||||
$people_filled_full_data = true;
|
||||
} else {
|
||||
$people_filled_full_data = false;
|
||||
}
|
||||
$people_filled = SurveyManager::get_people_who_filled_survey($survey_id, $people_filled_full_data);
|
||||
|
||||
// Checking the parameters
|
||||
SurveyUtil::check_parameters($people_filled);
|
||||
|
||||
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
|
||||
api_get_user_id(),
|
||||
api_get_course_info()
|
||||
);
|
||||
|
||||
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
|
||||
if ($isDrhOfCourse || !api_is_allowed_to_edit(false, true)) {
|
||||
// Show error message if the survey can be seen only by tutors
|
||||
if (SURVEY_VISIBLE_TUTOR == $survey_data['visible_results']) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
Display::display_header(get_lang('ToolSurvey'));
|
||||
SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo use Export::arrayToCsv($data, $filename = 'export')
|
||||
*/
|
||||
$exportReport = isset($_REQUEST['export_report']) ? $_REQUEST['export_report'] : '';
|
||||
$format = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : '';
|
||||
|
||||
if (!empty($exportReport) && !empty($format)) {
|
||||
$compact = false;
|
||||
switch ($format) {
|
||||
case 'xls':
|
||||
$filename = 'survey_results_'.$survey_id.'.xlsx';
|
||||
|
||||
SurveyUtil::export_complete_report_xls($survey_data, $filename, $userId, false, $lpItemId);
|
||||
exit;
|
||||
break;
|
||||
case 'csv-compact':
|
||||
$compact = true;
|
||||
// no break
|
||||
case 'csv':
|
||||
default:
|
||||
$data = SurveyUtil::export_complete_report($survey_data, $userId, $compact, $lpItemId);
|
||||
$filename = 'survey_results_'.$survey_id.($compact ? '_compact' : '').'.csv';
|
||||
header('Content-type: application/octet-stream');
|
||||
header('Content-Type: application/force-download');
|
||||
|
||||
if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
|
||||
header('Content-Disposition: filename= '.$filename);
|
||||
} else {
|
||||
header('Content-Disposition: attachment; filename= '.$filename);
|
||||
}
|
||||
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
|
||||
header('Pragma: ');
|
||||
header('Cache-Control: ');
|
||||
header('Cache-Control: public'); // IE cannot download from sessions without a cache
|
||||
}
|
||||
header('Content-Description: '.$filename);
|
||||
header('Content-transfer-encoding: binary');
|
||||
echo $data;
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$urlname = strip_tags(
|
||||
api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
|
||||
);
|
||||
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
|
||||
$urlname .= '...';
|
||||
}
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
|
||||
'name' => $urlname,
|
||||
];
|
||||
|
||||
$actions = '';
|
||||
if ($action === 'overview') {
|
||||
$tool_name = get_lang('Reporting');
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
|
||||
'name' => get_lang('Reporting'),
|
||||
];
|
||||
switch ($action) {
|
||||
case 'questionreport':
|
||||
$singlePage = isset($_GET['single_page']) ? (int) $_GET['single_page'] : 0;
|
||||
$tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion');
|
||||
break;
|
||||
case 'userreport':
|
||||
$tool_name = get_lang('DetailedReportByUser');
|
||||
break;
|
||||
case 'comparativereport':
|
||||
$tool_name = get_lang('ComparativeReport');
|
||||
break;
|
||||
case 'completereport':
|
||||
$tool_name = get_lang('CompleteReport');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_asset('jspdf/dist/jspdf.umd.min.js');
|
||||
$htmlHeadXtra[] = api_get_asset('svgtopdf/svg2pdf.js');
|
||||
$htmlHeadXtra[] = api_get_asset('html2canvas/html2canvas.js');
|
||||
$htmlHeadXtra[] = api_get_js('d3/d3.v3.5.4.min.js');
|
||||
$htmlHeadXtra[] = api_get_js('dimple.v2.1.2.min.js');
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
|
||||
function formExportSubmit(formId) {
|
||||
$("#"+formId).submit();
|
||||
}
|
||||
async function exportToPdf() {
|
||||
window.scrollTo(0, 0);
|
||||
|
||||
$("#dialog-confirm").dialog({
|
||||
autoOpen: false,
|
||||
show: "blind",
|
||||
resizable: false,
|
||||
height: 100,
|
||||
modal: true
|
||||
});
|
||||
$("#dialog-confirm").dialog("open");
|
||||
|
||||
window.jsPDF = window.jspdf.jsPDF;
|
||||
$(".question-item img, #pdf_table img").hide();
|
||||
$(".question-item video, #pdf_table video").hide();
|
||||
$(".question-item audio, #pdf_table audio").hide();
|
||||
|
||||
var doc = document.getElementById("question_results");
|
||||
var pdf = new jsPDF("p", "pt", "a4");
|
||||
//A4 height = 842 pts ; A4 width = 595 pts
|
||||
|
||||
// Adding title
|
||||
pdf.setFontSize(16);
|
||||
pdf.text(40, 40, "'.get_lang('Reporting').'");
|
||||
|
||||
const table = document.getElementById("pdf_table");
|
||||
var headerY = 0;
|
||||
var canvas = await html2canvas(table);
|
||||
var pageData = canvas.toDataURL("image/jpeg", 1);
|
||||
headerY = 515/canvas.width * canvas.height;
|
||||
pdf.addImage(pageData, "JPEG", 35, 60, 515, headerY);
|
||||
|
||||
var divs = doc.getElementsByClassName("question-item");
|
||||
var currentHeight = 60 + headerY;
|
||||
var maxHeightPerPage = 842;
|
||||
var pages = [];
|
||||
var page = 1;
|
||||
for (var i = 0; i < divs.length; i += 1) {
|
||||
// Two parameters after addImage control the size of the added image,
|
||||
// where the page height is compressed according to the width-height ratio column of a4 paper.
|
||||
if (!pages[page]) {
|
||||
pages[page] = 0;
|
||||
}
|
||||
|
||||
var positionY = 150;
|
||||
var diff = 250;
|
||||
pages[page] += 1;
|
||||
if (page > 1) {
|
||||
headerY = 0;
|
||||
positionY = 60;
|
||||
diff = 220;
|
||||
}
|
||||
if (pages[page] > 1) {
|
||||
positionY = pages[page] * diff + 5;
|
||||
}
|
||||
|
||||
const title = $(divs[i]).find(".title-question");
|
||||
pdf.setFontSize(10);
|
||||
const lines = pdf.splitTextToSize(title.text(), 515);
|
||||
pdf.text(40, positionY, lines);
|
||||
|
||||
var svg = divs[i].querySelector("svg");
|
||||
if (svg) {
|
||||
svg2pdf(svg, pdf, {
|
||||
xOffset: 150,
|
||||
yOffset: positionY + (lines.length * 1),
|
||||
scale: 0.4,
|
||||
});
|
||||
}
|
||||
var tables = divs[i].getElementsByClassName("display-survey");
|
||||
var config= {};
|
||||
for (var j = 0; j < tables.length; j += 1) {
|
||||
const canvas = await html2canvas(tables[j], config);
|
||||
var pageData = canvas.toDataURL("image/jpeg", 0.7);
|
||||
if (pageData) {
|
||||
pdf.addImage(pageData, "JPEG", 40, positionY + 180, 500, 500 / canvas.width * canvas.height);
|
||||
}
|
||||
}
|
||||
|
||||
var tables = divs[i].getElementsByClassName("open-question");
|
||||
for (var j = 0; j < tables.length; j += 1) {
|
||||
const canvas = await html2canvas(tables[j]);
|
||||
var canvasWidth = canvas.width;
|
||||
var canvasHeight = canvas.height;
|
||||
var imgWidth = 515;
|
||||
var imgHeight = canvasHeight;
|
||||
var y = j === 0 ? currentHeight + 60 : currentHeight;
|
||||
var renderedHeight = 0;
|
||||
|
||||
while (renderedHeight < imgHeight) {
|
||||
var remainingHeight = imgHeight - renderedHeight;
|
||||
var heightToDraw = Math.min(remainingHeight, maxHeightPerPage - y);
|
||||
var sourceHeight = heightToDraw * (canvasWidth / imgWidth);
|
||||
|
||||
// New canvas for cropping image
|
||||
var sectionCanvas = document.createElement("canvas");
|
||||
sectionCanvas.width = canvasWidth;
|
||||
sectionCanvas.height = sourceHeight;
|
||||
var ctx = sectionCanvas.getContext("2d");
|
||||
|
||||
// Draw the image section on new canvas
|
||||
ctx.drawImage(canvas, 0, renderedHeight, canvasWidth, sourceHeight, 0, 0, canvasWidth, sourceHeight);
|
||||
|
||||
var sectionImgData = sectionCanvas.toDataURL("image/jpeg", 0.7);
|
||||
|
||||
pdf.addImage(sectionImgData, "JPEG", 40, y, imgWidth, heightToDraw);
|
||||
|
||||
renderedHeight += sourceHeight;
|
||||
y = heightToDraw + y;
|
||||
|
||||
if (renderedHeight < imgHeight && remainingHeight > maxHeightPerPage - y) {
|
||||
pdf.addPage();
|
||||
page++;
|
||||
y = 40;
|
||||
currentHeight = 40;
|
||||
}
|
||||
}
|
||||
|
||||
if (renderedHeight >= imgHeight) {
|
||||
currentHeight = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > 0 && (i -1) % 2 === 0 && (i+1 !== divs.length)) {
|
||||
pdf.addPage();
|
||||
page++;
|
||||
}
|
||||
}
|
||||
|
||||
$(".question-item img, #pdf_table img").show();
|
||||
$(".question-item video, #pdf_table video").show();
|
||||
$(".question-item audio, #pdf_table audio").show();
|
||||
|
||||
pdf.save("reporting.pdf", {returnPromise: true}).then(function (response) {
|
||||
$( "#dialog-confirm" ).dialog("close");
|
||||
});
|
||||
}
|
||||
</script>';
|
||||
|
||||
Display::display_header($tool_name, 'Survey');
|
||||
echo '<div id="dialog-confirm" style="display: none;"> '.
|
||||
Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin').
|
||||
get_lang('PleaseWait').
|
||||
'</div>';
|
||||
SurveyUtil::handle_reporting_actions($survey_data, $people_filled);
|
||||
|
||||
// Content
|
||||
if ($action === 'overview') {
|
||||
$html = null;
|
||||
$url = api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&';
|
||||
|
||||
$html .= '<div class="survey-reports">';
|
||||
$html .= '<div class="list-group">';
|
||||
$html .= Display::url(
|
||||
Display::return_icon(
|
||||
'survey_reporting_overall.png',
|
||||
get_lang('QuestionsOverallReport'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
).'<h4>'.get_lang('QuestionsOverallReport').'</h4><p>'.get_lang('QuestionsOverallReportDetail').'</p>',
|
||||
$url.'action=questionreport&survey_id='.$survey_id.'&single_page=1',
|
||||
['class' => 'list-group-item']
|
||||
);
|
||||
|
||||
$html .= Display::url(
|
||||
Display::return_icon(
|
||||
'survey_reporting_question.png',
|
||||
get_lang('DetailedReportByQuestion'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
).'<h4>'.get_lang('DetailedReportByQuestion').'</h4><p>'.get_lang('DetailedReportByQuestionDetail').'</p>',
|
||||
$url.'action=questionreport&survey_id='.$survey_id,
|
||||
['class' => 'list-group-item']
|
||||
);
|
||||
|
||||
$html .= Display::url(
|
||||
Display::return_icon(
|
||||
'survey_reporting_user.png',
|
||||
get_lang('DetailedReportByUser'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
).'<h4>'.get_lang('DetailedReportByUser').'</h4><p>'.get_lang('DetailedReportByUserDetail').'</p>',
|
||||
$url.'action=userreport&survey_id='.$survey_id,
|
||||
['class' => 'list-group-item']
|
||||
);
|
||||
|
||||
$html .= Display::url(
|
||||
Display::return_icon(
|
||||
'survey_reporting_comparative.png',
|
||||
get_lang('ComparativeReport'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
).'<h4>'.get_lang('ComparativeReport').'</h4><p>'.get_lang('ComparativeReportDetail').'</p>',
|
||||
$url.'action=comparativereport&survey_id='.$survey_id,
|
||||
['class' => 'list-group-item']
|
||||
);
|
||||
|
||||
$html .= Display::url(
|
||||
Display::return_icon(
|
||||
'survey_reporting_complete.png',
|
||||
get_lang('CompleteReport'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
).'<h4>'.get_lang('CompleteReport').'</h4><p>'.get_lang('CompleteReportDetail').'</p>',
|
||||
$url.'action=completereport&survey_id='.$survey_id,
|
||||
['class' => 'list-group-item']
|
||||
);
|
||||
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
echo $html;
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
111
main/survey/survey.download.inc.php
Normal file
111
main/survey/survey.download.inc.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Arnaud Ligot <arnaud@cblue.be>
|
||||
*
|
||||
* A small peace of code to enable user to access images included into survey
|
||||
* which are accessible by non authenticated users. This file is included
|
||||
* by document/download.php
|
||||
*/
|
||||
function check_download_survey($course, $invitation, $doc_url)
|
||||
{
|
||||
// Getting all the course information
|
||||
$_course = api_get_course_info($course);
|
||||
$course_id = $_course['real_id'];
|
||||
|
||||
// Database table definitions
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
|
||||
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
|
||||
|
||||
// Now we check if the invitationcode is valid
|
||||
$sql = "SELECT * FROM $table_survey_invitation
|
||||
WHERE
|
||||
c_id = $course_id AND
|
||||
invitation_code = '".Database::escape_string($invitation)."'";
|
||||
$result = Database::query($sql);
|
||||
if (Database::num_rows($result) < 1) {
|
||||
echo Display::return_message(get_lang('WrongInvitationCode'), 'error', false);
|
||||
exit;
|
||||
}
|
||||
$survey_invitation = Database::fetch_assoc($result);
|
||||
|
||||
// Now we check if the user already filled the survey
|
||||
/*if ($survey_invitation['answered'] == 1) {
|
||||
echo Display::return_message(get_lang('YouAlreadyFilledThisSurvey'), 'error', false);
|
||||
exit;
|
||||
}*/
|
||||
|
||||
// Very basic security check: check if a text field from
|
||||
// a survey/answer/option contains the name of the document requested
|
||||
// Fetch survey ID
|
||||
// If this is the case there will be a language choice
|
||||
$sql = "SELECT * FROM $table_survey
|
||||
WHERE
|
||||
c_id = $course_id AND
|
||||
code='".Database::escape_string($survey_invitation['survey_code'])."'";
|
||||
$result = Database::query($sql);
|
||||
if (Database::num_rows($result) > 1) {
|
||||
if ($_POST['language']) {
|
||||
$survey_invitation['survey_id'] = $_POST['language'];
|
||||
} else {
|
||||
echo '<form
|
||||
id="language"
|
||||
name="language"
|
||||
method="POST"
|
||||
action="'.api_get_self().'?course='.Security::remove_XSS($_GET['course']).'&invitationcode='.Security::remove_XSS($_GET['invitationcode']).'">';
|
||||
echo ' <select name="language">';
|
||||
while ($row = Database::fetch_assoc($result)) {
|
||||
echo '<option value="'.$row['survey_id'].'">'.$row['lang'].'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo ' <input type="submit" name="Submit" value="'.get_lang('Ok').'" />';
|
||||
echo '</form>';
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$row = Database::fetch_assoc($result);
|
||||
$survey_invitation['survey_id'] = $row['survey_id'];
|
||||
}
|
||||
|
||||
$doc_url = Database::escape_string($doc_url);
|
||||
$survey_invitation['survey_id'] = Database::escape_string($survey_invitation['survey_id']);
|
||||
|
||||
$sql = "SELECT count(*)
|
||||
FROM $table_survey
|
||||
WHERE
|
||||
c_id = $course_id AND
|
||||
survey_id = ".$survey_invitation['survey_id']." AND (
|
||||
title LIKE '%$doc_url%'
|
||||
or subtitle LIKE '%$doc_url%'
|
||||
or intro LIKE '%$doc_url%'
|
||||
or surveythanks LIKE '%$doc_url%'
|
||||
)
|
||||
UNION
|
||||
SELECT count(*)
|
||||
FROM $table_survey_question
|
||||
WHERE
|
||||
c_id = $course_id AND
|
||||
survey_id = ".$survey_invitation['survey_id']." AND (
|
||||
survey_question LIKE '%$doc_url%' OR
|
||||
survey_question_comment LIKE '%$doc_url%'
|
||||
)
|
||||
UNION
|
||||
SELECT count(*)
|
||||
FROM $table_survey_question_option
|
||||
WHERE
|
||||
c_id = $course_id AND
|
||||
survey_id = ".$survey_invitation['survey_id']." AND (
|
||||
option_text LIKE '%$doc_url%'
|
||||
)";
|
||||
$result = Database::query($sql);
|
||||
if (Database::num_rows($result) == 0) {
|
||||
echo Display::return_message(get_lang('WrongInvitationCode'), 'error', false);
|
||||
exit;
|
||||
}
|
||||
|
||||
return $_course;
|
||||
}
|
||||
3156
main/survey/survey.lib.php
Normal file
3156
main/survey/survey.lib.php
Normal file
File diff suppressed because it is too large
Load Diff
459
main/survey/survey.php
Normal file
459
main/survey/survey.php
Normal file
@@ -0,0 +1,459 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University:
|
||||
* cleanup, refactoring and rewriting large parts of the code
|
||||
* @author Julio Montoya
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
$current_course_tool = TOOL_SURVEY;
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
|
||||
// Coach can't view this page
|
||||
$extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
|
||||
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), api_get_course_info());
|
||||
|
||||
if ($isDrhOfCourse) {
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
|
||||
exit;
|
||||
}
|
||||
if (!api_is_allowed_to_edit(false, true) ||
|
||||
(api_is_session_general_coach() && 'false' == $extend_rights_for_coachs)
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Database table definitions
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
|
||||
$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
|
||||
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
|
||||
$survey_id = (int) $_GET['survey_id'];
|
||||
$course_id = api_get_course_int_id();
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
|
||||
Session::erase('answer_count');
|
||||
Session::erase('answer_list');
|
||||
|
||||
// Getting the survey information
|
||||
if (!empty($_GET['survey_id'])) {
|
||||
$course_code = api_get_course_id();
|
||||
if (-1 != $course_code) {
|
||||
$survey_data = SurveyManager::get_survey($survey_id);
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$tool_name = strip_tags($survey_data['title'], '<span>');
|
||||
$is_survey_type_1 = 1 == $survey_data['survey_type'];
|
||||
|
||||
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
|
||||
$tool_name .= '...';
|
||||
}
|
||||
|
||||
if ($is_survey_type_1 && ($action === 'addgroup' || $action === 'deletegroup')) {
|
||||
$_POST['name'] = trim($_POST['name']);
|
||||
if ('addgroup' == $action) {
|
||||
if (!empty($_POST['group_id'])) {
|
||||
Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
|
||||
WHERE c_id = '.$course_id.' AND id = \''.Database::escape_string($_POST['group_id']).'\'');
|
||||
$sendmsg = 'GroupUpdatedSuccessfully';
|
||||
} elseif (!empty($_POST['name'])) {
|
||||
Database::query('INSERT INTO '.$table_survey_question_group.' (c_id, name,description,survey_id) values ('.$course_id.', \''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($survey_id).'\') ');
|
||||
$sendmsg = 'GroupCreatedSuccessfully';
|
||||
} else {
|
||||
$sendmsg = 'GroupNeedName';
|
||||
}
|
||||
}
|
||||
|
||||
if ('deletegroup' == $action) {
|
||||
$sql = 'DELETE FROM '.$table_survey_question_group.'
|
||||
WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' AND survey_id = '.$survey_id;
|
||||
Database::query($sql);
|
||||
$sendmsg = 'GroupDeletedSuccessfully';
|
||||
}
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Action handling
|
||||
$my_question_id_survey = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null;
|
||||
$my_survey_id_survey = (int) $_GET['survey_id'];
|
||||
$message_information = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
|
||||
|
||||
if (!empty($action)) {
|
||||
switch ($action) {
|
||||
case 'copyquestion':
|
||||
$copied = SurveyManager::copyQuestion($_GET['question_id']);
|
||||
if (false !== $copied) {
|
||||
$sendmsg = 'QuestionAdded';
|
||||
} else {
|
||||
$sendmsg = 'ErrorOccurred';
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
$result = SurveyManager::delete_survey_question(
|
||||
$my_survey_id_survey,
|
||||
$my_question_id_survey,
|
||||
$survey_data['is_shared']
|
||||
);
|
||||
if (false == $result) {
|
||||
$sendmsg = 'ErrorOccured';
|
||||
} else {
|
||||
$sendmsg = 'Deleted';
|
||||
}
|
||||
break;
|
||||
case 'moveup':
|
||||
case 'movedown':
|
||||
SurveyManager::move_survey_question(
|
||||
$action,
|
||||
$my_question_id_survey,
|
||||
$my_survey_id_survey
|
||||
);
|
||||
$sendmsg = 'SurveyQuestionMoved';
|
||||
break;
|
||||
}
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
|
||||
exit;
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
|
||||
|
||||
// Displaying the header
|
||||
Display::display_header($tool_name, 'Survey');
|
||||
|
||||
// Show error/success messages, if any
|
||||
if (!$is_survey_type_1 && !empty($_GET['sendmsg'])) {
|
||||
$messageType = 'confirmation';
|
||||
if (in_array($_GET['sendmsg'], ['ErrorOccurred'])) {
|
||||
$messageType = 'error';
|
||||
}
|
||||
echo Display::return_message(
|
||||
get_lang($_GET['sendmsg']),
|
||||
'confirmation',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($survey_data['survey_version'])) {
|
||||
echo '<b>'.get_lang('Version').': '.$survey_data['survey_version'].'</b>';
|
||||
}
|
||||
|
||||
// We exit here is the first or last question is a pagebreak (which causes errors)
|
||||
SurveyUtil::check_first_last_question($_GET['survey_id']);
|
||||
|
||||
// Action links
|
||||
$survey_actions = '';
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
$survey_actions = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq(
|
||||
).'&action=edit&survey_id='.$survey_id.'">'.
|
||||
Display::return_icon('settings.png', get_lang('EditSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&action=delete&survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;">'.
|
||||
Display::return_icon('delete.png', get_lang('DeleteSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/preview.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
|
||||
Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
|
||||
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
|
||||
Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
if (!api_get_configuration_value('hide_survey_reporting_button')) {
|
||||
$survey_actions .= Display::url(
|
||||
Display::return_icon('statistics.png', get_lang('Reporting'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&survey_id='.$survey_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$survey_actions .= SurveyUtil::getAdditionalTeacherActions($survey_id, ICON_SIZE_MEDIUM);
|
||||
|
||||
echo '<div class="actions">'.$survey_actions.'</div>';
|
||||
|
||||
$urlQuestion = api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=add';
|
||||
if ($survey_data['survey_type'] == 0) {
|
||||
echo '<div class="well">';
|
||||
echo Display::url(
|
||||
Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=yesno&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('mcua.png', get_lang('UniqueSelect'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=multiplechoice&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('mcma.png', get_lang('MultipleResponse'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=multipleresponse&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('open_answer.png', get_lang('Open'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=open&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('dropdown.png', get_lang('Dropdown'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=dropdown&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('percentagequestion.png', get_lang('Percentage'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=percentage&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('scorequestion.png', get_lang('Score'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=score&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('commentquestion.png', get_lang('Comment'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=comment&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('mcua.png', get_lang('SurveyMultipleChoiceWithOther'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=multiplechoiceother&survey_id='.$survey_id
|
||||
);
|
||||
if ($survey_data['one_question_per_page'] == 0) {
|
||||
echo Display::url(
|
||||
Display::return_icon('yesno.png', get_lang('SurveyQuestionSelectiveDisplay'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=selectivedisplay&survey_id='.$survey_id
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('page_end.png', get_lang('Pagebreak'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=pagebreak&survey_id='.$survey_id
|
||||
);
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
echo '<div class="well">';
|
||||
echo Display::url(
|
||||
Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
|
||||
$urlQuestion.'&type=personality&survey_id='.$survey_id
|
||||
);
|
||||
echo '</a></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the table header with all the questions
|
||||
echo '<table class="table table-bordered data_table">';
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
echo ' <th width="5%">'.get_lang('NumberAbbreviation').'</th>';
|
||||
echo ' <th width="50%">'.get_lang('Title').'</th>';
|
||||
echo ' <th width="15%">'.get_lang('Type').'</th>';
|
||||
echo ' <th width="15%" >'.get_lang('NumberOfOptions').'</th>';
|
||||
echo ' <th width="15%">'.get_lang('Modify').'</th>';
|
||||
if ($is_survey_type_1) {
|
||||
echo '<th width="100">'.get_lang('Condition').'</th>';
|
||||
echo '<th width="40">'.get_lang('Group').'</th>';
|
||||
}
|
||||
echo ' </tr>';
|
||||
echo '</thead>';
|
||||
|
||||
// Displaying the table contents with all the questions
|
||||
$question_counter = 1;
|
||||
$sql = "SELECT * FROM $table_survey_question_group
|
||||
WHERE c_id = $course_id AND survey_id = $survey_id
|
||||
ORDER BY id";
|
||||
$result = Database::query($sql);
|
||||
$groups = [];
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
$groups[$row['id']] = $row['name'];
|
||||
}
|
||||
$sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options
|
||||
FROM $table_survey_question survey_question
|
||||
LEFT JOIN $table_survey_question_option survey_question_option
|
||||
ON
|
||||
survey_question.question_id = survey_question_option.question_id AND
|
||||
survey_question_option.c_id = $course_id
|
||||
WHERE
|
||||
survey_question.survey_id = $survey_id AND
|
||||
survey_question.c_id = $course_id
|
||||
GROUP BY survey_question.question_id
|
||||
ORDER BY survey_question.sort ASC";
|
||||
|
||||
$result = Database::query($sql);
|
||||
$question_counter_max = Database::num_rows($result);
|
||||
$questionsGroupClass = '';
|
||||
while ($row = Database::fetch_array($result, 'ASSOC')) {
|
||||
$breakClass = '';
|
||||
// Visually impact questions between page breaks by changing the bg color
|
||||
if ($row['type'] == 'pagebreak') {
|
||||
$breakClass = ' highlight';
|
||||
if (empty($questionsGroupClass)) {
|
||||
$questionsGroupClass = 'row_even';
|
||||
} else {
|
||||
$questionsGroupClass = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight the question that was just updated and scrool to it
|
||||
if ($row['question_id'] == $my_question_id_survey) {
|
||||
echo '<tr class="'.$questionsGroupClass.$breakClass.'" style="background-color:#A9DFBF;" >';
|
||||
echo '<a name="tocupdatelink" id="tocupdatelink" ></a>';
|
||||
echo '<script>';
|
||||
echo '$(document).ready(function() {';
|
||||
echo "var element_to_scroll_to = document.getElementById('tocupdatelink');";
|
||||
echo 'element_to_scroll_to.scrollIntoView();';
|
||||
echo '});';
|
||||
echo '</script>';
|
||||
} else {
|
||||
echo '<tr class="'.$questionsGroupClass.$breakClass.'">';
|
||||
}
|
||||
echo ' <td>'.$question_counter.'</td>';
|
||||
echo ' <td>';
|
||||
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
if (api_strlen($row['survey_question']) > 100) {
|
||||
echo Security::remove_XSS(api_substr(strip_tags($row['survey_question']), 0, 100)).' ... ';
|
||||
} else {
|
||||
echo Security::remove_XSS($row['survey_question']);
|
||||
}
|
||||
} else {
|
||||
$parts = explode('@@', $row['survey_question']);
|
||||
echo api_get_local_time($parts[0]).' - '.api_get_local_time($parts[1]);
|
||||
}
|
||||
|
||||
if ($row['type'] === 'yesno') {
|
||||
$tool_name = get_lang('YesNo');
|
||||
} elseif ($row['type'] === 'multiplechoice') {
|
||||
$tool_name = get_lang('UniqueSelect');
|
||||
} elseif ($row['type'] === 'multipleresponse') {
|
||||
$tool_name = get_lang('MultipleChoiceMultipleAnswers');
|
||||
} elseif ($row['type'] === 'selectivedisplay') {
|
||||
$tool_name = get_lang('SurveyQuestionSelectiveDisplay');
|
||||
} else {
|
||||
$tool_name = get_lang(api_ucfirst(Security::remove_XSS($row['type'])));
|
||||
}
|
||||
|
||||
echo '</td>';
|
||||
echo '<td>'.$tool_name.'</td>';
|
||||
echo '<td>'.$row['number_of_options'].'</td>';
|
||||
echo '<td>';
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=edit&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
|
||||
}
|
||||
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=copyquestion&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
|
||||
Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>';
|
||||
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=delete&survey_id='.$survey_id.'&question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?', ENT_QUOTES, $charset)).'\')) return false;">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
|
||||
if ($survey_data['survey_type'] != 3) {
|
||||
if ($question_counter > 1) {
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq(
|
||||
).'&action=moveup&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
|
||||
Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL).'</a>';
|
||||
} else {
|
||||
Display::display_icon('up_na.png', ' ', '', ICON_SIZE_SMALL);
|
||||
}
|
||||
if ($question_counter < $question_counter_max) {
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq(
|
||||
).'&action=movedown&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
|
||||
Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL).'</a>';
|
||||
} else {
|
||||
Display::display_icon('down_na.png', ' ', '', ICON_SIZE_SMALL);
|
||||
}
|
||||
}
|
||||
echo ' </td>';
|
||||
$question_counter++;
|
||||
|
||||
if ($is_survey_type_1) {
|
||||
echo '<td>'.(($row['survey_group_pri'] == 0) ? get_lang('Secondary') : get_lang('Primary')).'</td>';
|
||||
echo '<td>'.(($row['survey_group_pri'] == 0) ? $groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']] : $groups[$row['survey_group_pri']]).'</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo '</table>';
|
||||
|
||||
if ($is_survey_type_1) {
|
||||
echo '<br /><br /><b>'.get_lang('ManageGroups').'</b><br /><br />';
|
||||
if (in_array(
|
||||
$_GET['sendmsg'],
|
||||
['GroupUpdatedSuccessfully', 'GroupDeletedSuccessfully', 'GroupCreatedSuccessfully']
|
||||
)
|
||||
) {
|
||||
echo Display::return_message(
|
||||
get_lang($_GET['sendmsg']),
|
||||
'confirmation',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array($_GET['sendmsg'], ['GroupNeedName'])) {
|
||||
echo Display::return_message(
|
||||
get_lang($_GET['sendmsg']),
|
||||
'warning',
|
||||
false
|
||||
);
|
||||
}
|
||||
echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
|
||||
echo '<form action="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
|
||||
if ('editgroup' == $_GET['action']) {
|
||||
$sql = 'SELECT name,description FROM '.$table_survey_question_group.'
|
||||
WHERE id = '.intval($_GET['gid']).' AND survey_id = '.intval($survey_id).' limit 1';
|
||||
$rs = Database::query($sql);
|
||||
$editedrow = Database::fetch_array($rs, 'ASSOC');
|
||||
echo '<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>';
|
||||
echo '<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
|
||||
echo '<input type="hidden" name="group_id" value="'.Security::remove_XSS($_GET['gid']).'">';
|
||||
echo '<input type="submit" value="'.get_lang('Save').'"'.'<input type="button" value="'.get_lang('Cancel').'" onclick="window.location.href = \'survey.php?survey_id='.Security::remove_XSS($survey_id).'\';" />';
|
||||
} else {
|
||||
echo '<input type="text" maxlength="20" name="name" value="" size="10">';
|
||||
echo '<input type="text" maxlength="250" name="description" value="" size="80">';
|
||||
echo '<input type="submit" value="'.get_lang('Create').'"';
|
||||
}
|
||||
echo '</form><br />';
|
||||
|
||||
echo '<table class="data_table">';
|
||||
echo ' <tr class="row_odd">';
|
||||
echo ' <th width="200">'.get_lang('Name').'</th>';
|
||||
echo ' <th>'.get_lang('Description').'</th>';
|
||||
echo ' <th width="100">'.get_lang('Modify').'</th>';
|
||||
echo ' </tr>';
|
||||
|
||||
$sql = 'SELECT id,name,description
|
||||
FROM '.$table_survey_question_group.'
|
||||
WHERE
|
||||
c_id = '.$course_id.' AND
|
||||
survey_id = '.intval($survey_id).'
|
||||
ORDER BY name';
|
||||
|
||||
$rs = Database::query($sql);
|
||||
while ($row = Database::fetch_array($rs, 'ASSOC')) {
|
||||
$grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
|
||||
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a> '.
|
||||
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'), $row['name']).'?', ENT_QUOTES)).'\')) return false;">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'</td></tr>';
|
||||
}
|
||||
echo $grouplist.'</table>';
|
||||
}
|
||||
|
||||
Session::erase('answer_count');
|
||||
|
||||
Display::display_footer();
|
||||
4643
main/survey/surveyUtil.class.php
Normal file
4643
main/survey/surveyUtil.class.php
Normal file
File diff suppressed because it is too large
Load Diff
216
main/survey/survey_invitation.php
Normal file
216
main/survey/survey_invitation.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
|
||||
*
|
||||
* @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
|
||||
*
|
||||
* @todo the answered column
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
|
||||
if (!api_is_allowed_to_edit(false, true)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Database table definitions
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
|
||||
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
|
||||
$tool_name = get_lang('SurveyInvitations');
|
||||
$courseInfo = api_get_course_info();
|
||||
|
||||
// Getting the survey information
|
||||
$survey_id = Security::remove_XSS($_GET['survey_id']);
|
||||
$survey_data = SurveyManager::get_survey($survey_id);
|
||||
if (empty($survey_data)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$view = isset($_GET['view']) ? $_GET['view'] : 'invited';
|
||||
|
||||
$urlname = strip_tags(
|
||||
api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)
|
||||
);
|
||||
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
|
||||
$urlname .= '...';
|
||||
}
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id,
|
||||
'name' => $urlname,
|
||||
];
|
||||
|
||||
// Displaying the header
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$course_id = api_get_course_int_id();
|
||||
$sessionId = api_get_session_id();
|
||||
|
||||
$sentInvitations = SurveyUtil::getSentInvitations($survey_data['code'], $course_id, $sessionId);
|
||||
|
||||
// Getting all the people who have filled this survey
|
||||
$answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
|
||||
|
||||
$invitationsCount = count($sentInvitations);
|
||||
$answeredCount = count($answered_data);
|
||||
$unasnweredCount = count($sentInvitations) - count($answered_data);
|
||||
|
||||
if ($survey_data['anonymous'] == 1 && !api_get_configuration_value('survey_anonymous_show_answered')) {
|
||||
echo Display::return_message(
|
||||
get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.$answeredCount.' '.get_lang('PeopleAnswered')
|
||||
);
|
||||
$answered_data = [];
|
||||
}
|
||||
if ($survey_data['anonymous'] == 1) {
|
||||
if ($answeredCount < 2) {
|
||||
$answeredCount = 0;
|
||||
$unasnweredCount = $invitationsCount;
|
||||
}
|
||||
}
|
||||
$url = api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq();
|
||||
|
||||
echo '<ul class="nav nav-tabs">';
|
||||
|
||||
if ($view == 'invited') {
|
||||
echo '<li role="presentation" class="active"><a href="#">'.get_lang('ViewInvited');
|
||||
} else {
|
||||
echo '<li role="presentation"><a href="'.$url.'&view=invited">'.
|
||||
get_lang('ViewInvited');
|
||||
}
|
||||
echo ' <span class="badge badge-default">'.$invitationsCount.'</span>';
|
||||
echo '</a></li>';
|
||||
if ($view == 'answered') {
|
||||
echo '<li role="presentation" class="active"><a href="#">'.get_lang('ViewAnswered');
|
||||
} else {
|
||||
echo '<li role="presentation"><a href="'.$url.'&view=answered">'.
|
||||
get_lang('ViewAnswered');
|
||||
}
|
||||
echo ' <span class="badge badge-default">'.$answeredCount.'</span>';
|
||||
echo '</a></li>';
|
||||
|
||||
if ($view == 'unanswered') {
|
||||
echo '<li role="presentation" class="active"><a href="#">'.get_lang('ViewUnanswered');
|
||||
} else {
|
||||
echo '<li role="presentation"><a href="'.$url.'&view=unanswered">'.
|
||||
get_lang('ViewUnanswered');
|
||||
}
|
||||
echo ' <span class="badge badge-default">'.$unasnweredCount.'</span>';
|
||||
echo '</a></li>';
|
||||
echo '</ul>';
|
||||
|
||||
// Table header
|
||||
echo '<table class="table table-hover table-striped data_table" style="margin-top: 5px;">';
|
||||
echo ' <tr>';
|
||||
echo ' <th>'.get_lang('User').'</th>';
|
||||
echo ' <th>'.get_lang('InvitationDate').'</th>';
|
||||
|
||||
switch ($view) {
|
||||
case 'unanswered':
|
||||
echo ' <th>'.get_lang('SurveyInviteLink').'</th>';
|
||||
break;
|
||||
default:
|
||||
echo ' <th>'.get_lang('Answered').'</th>';
|
||||
break;
|
||||
}
|
||||
|
||||
echo ' </tr>';
|
||||
|
||||
$surveyAnonymousShowAnswered = api_get_configuration_value('survey_anonymous_show_answered');
|
||||
$hideSurveyReportingButton = api_get_configuration_value('hide_survey_reporting_button');
|
||||
|
||||
foreach ($sentInvitations as $row) {
|
||||
$id = $row['iid'];
|
||||
if ($view == 'invited' ||
|
||||
($view == 'answered' && in_array($row['user'], $answered_data) && $answeredCount > 1) ||
|
||||
($view == 'unanswered' && !in_array($row['user'], $answered_data) && $answeredCount > 1)
|
||||
) {
|
||||
echo '<tr>';
|
||||
if (is_numeric($row['user'])) {
|
||||
$userInfo = api_get_user_info($row['user']);
|
||||
echo '<td>';
|
||||
echo UserManager::getUserProfileLink($userInfo);
|
||||
echo '</td>';
|
||||
} else {
|
||||
echo '<td>'.$row['user'].'</td>';
|
||||
}
|
||||
echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
|
||||
|
||||
if (in_array($row['user'], $answered_data)) {
|
||||
if (!$surveyAnonymousShowAnswered && !$hideSurveyReportingButton) {
|
||||
echo '<td>';
|
||||
echo '<a href="'.
|
||||
api_get_path(WEB_CODE_PATH).
|
||||
'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'&'.api_get_cidreq().'">'.
|
||||
get_lang('ViewAnswers').'</a>';
|
||||
echo '</td>';
|
||||
} else {
|
||||
if ($survey_data['anonymous'] == 1 && $answeredCount > 1) {
|
||||
echo '<td>'.get_lang('Answered').'</td>';
|
||||
} else {
|
||||
echo '<td>-</td>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($view == 'unanswered') {
|
||||
echo ' <td>';
|
||||
$code = $row['invitation_code'];
|
||||
|
||||
$link = SurveyUtil::generateFillSurveyLink($code, $courseInfo, $sessionId);
|
||||
$link = Display::input('text', 'copy_'.$id, $link, ['id' => 'copy_'.$id, 'class' => '']);
|
||||
$link .= ' '.Display::url(
|
||||
Display::returnFontAwesomeIcon('copy').get_lang('CopyTextToClipboard'),
|
||||
'javascript:void()',
|
||||
['onclick' => "copyTextToClipBoard('copy_".$id."')", 'class' => 'btn btn-primary btn-sm']
|
||||
);
|
||||
|
||||
echo $link;
|
||||
echo ' </td>';
|
||||
} else {
|
||||
echo '<td>-</td>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
} elseif ($view === 'unanswered' && $answeredCount == 0) {
|
||||
echo '<tr>';
|
||||
if (is_numeric($row['user'])) {
|
||||
$userInfo = api_get_user_info($row['user']);
|
||||
echo '<td>';
|
||||
echo UserManager::getUserProfileLink($userInfo);
|
||||
echo '</td>';
|
||||
} else {
|
||||
echo '<td>'.$row['user'].'</td>';
|
||||
}
|
||||
echo ' <td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
|
||||
echo ' <td>';
|
||||
$code = $row['invitation_code'];
|
||||
|
||||
$link = SurveyUtil::generateFillSurveyLink($code, $courseInfo, $sessionId);
|
||||
$link = Display::input('text', 'copy_'.$id, $link, ['id' => 'copy_'.$id, 'class' => '']);
|
||||
$link .= ' '.Display::url(
|
||||
Display::returnFontAwesomeIcon('copy').get_lang('CopyTextToClipboard'),
|
||||
'javascript:void()',
|
||||
['onclick' => "copyTextToClipBoard('copy_".$id."')", 'class' => 'btn btn-primary btn-sm']
|
||||
);
|
||||
|
||||
echo $link;
|
||||
echo ' </td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// Closing the table
|
||||
echo '</table>';
|
||||
|
||||
Display::display_footer();
|
||||
261
main/survey/survey_invite.php
Normal file
261
main/survey/survey_invite.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
|
||||
* @author Julio Montoya Chamilo: cleanup, refactoring, security improvements
|
||||
*
|
||||
* @todo checking if the additional emails are valid (or add a rule for this)
|
||||
* @todo check if the mailtext contains the **link** part, if not, add the link to the end
|
||||
* @todo add rules: title and text cannot be empty
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
if (!api_is_allowed_to_edit(false, true)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$course_id = api_get_course_int_id();
|
||||
$_course = api_get_course_info();
|
||||
|
||||
// Getting the survey information
|
||||
$survey_id = (int) $_GET['survey_id'];
|
||||
$survey_data = SurveyManager::get_survey($survey_id);
|
||||
if (empty($survey_data)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Database table definitions
|
||||
$table_survey = Database::get_course_table(TABLE_SURVEY);
|
||||
|
||||
$urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
|
||||
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
|
||||
$urlname .= '...';
|
||||
}
|
||||
|
||||
// Breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
if (api_is_course_admin()) {
|
||||
if ($survey_data['survey_type'] == 3) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/meeting.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
|
||||
'name' => $urlname,
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
|
||||
'name' => $urlname,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
|
||||
'name' => $urlname,
|
||||
];
|
||||
}
|
||||
$tool_name = get_lang('SurveyPublication');
|
||||
Display::display_header($tool_name, 'Survey');
|
||||
|
||||
echo '<script>
|
||||
$(function() {
|
||||
$("#check_mail").change(function() {
|
||||
$("#mail_text_wrapper").toggle();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
// Checking if there is another survey with this code.
|
||||
// If this is the case there will be a language choice
|
||||
$sql = "SELECT * FROM $table_survey
|
||||
WHERE c_id = $course_id AND code='".Database::escape_string($survey_data['code'])."'";
|
||||
$result = Database::query($sql);
|
||||
if (Database::num_rows($result) > 1) {
|
||||
echo Display::return_message(get_lang('IdenticalSurveycodeWarning'), 'warning');
|
||||
}
|
||||
|
||||
// Invited / answered message
|
||||
if ($survey_data['invited'] > 0 && !isset($_POST['submit'])) {
|
||||
$message = Display::url(
|
||||
$survey_data['answered'],
|
||||
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq()
|
||||
);
|
||||
$message .= ' '.get_lang('HaveAnswered').' ';
|
||||
$message .= Display::url(
|
||||
$survey_data['invited'],
|
||||
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq());
|
||||
$message .= ' '.get_lang('WereInvited');
|
||||
echo Display::return_message($message, 'normal', false);
|
||||
}
|
||||
|
||||
// Building the form for publishing the survey
|
||||
$form = new FormValidator(
|
||||
'publish_form',
|
||||
'post',
|
||||
api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq()
|
||||
);
|
||||
$form->addHeader($tool_name);
|
||||
$sessionId = api_get_session_id();
|
||||
|
||||
CourseManager::addUserGroupMultiSelect($form, [], true);
|
||||
|
||||
// Additional users
|
||||
$form->addElement(
|
||||
'textarea',
|
||||
'additional_users',
|
||||
[get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')],
|
||||
['rows' => 5]
|
||||
);
|
||||
|
||||
$form->addElement('html', '<div id="check_mail">');
|
||||
$form->addElement('checkbox', 'send_mail', '', get_lang('SendMail'));
|
||||
$form->addElement('html', '</div>');
|
||||
$form->addElement('html', '<div id="mail_text_wrapper">');
|
||||
|
||||
// The title of the mail
|
||||
$form->addText('mail_title', get_lang('MailTitle'), false);
|
||||
// The text of the mail
|
||||
$form->addHtmlEditor(
|
||||
'mail_text',
|
||||
[get_lang('MailText'), get_lang('UseLinkSyntax')],
|
||||
false,
|
||||
['ToolbarSet' => 'Survey', 'Height' => '150']
|
||||
);
|
||||
$form->addElement('html', '</div>');
|
||||
// You cab send a reminder to unanswered people if the survey is not anonymous
|
||||
if ($survey_data['anonymous'] != 1 || api_get_configuration_value('survey_anonymous_show_answered')) {
|
||||
$form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered'));
|
||||
}
|
||||
// Allow resending to all selected users
|
||||
$form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers'));
|
||||
$form->addElement('checkbox', 'hide_link', '', get_lang('HideSurveyInvitationLink'));
|
||||
|
||||
// Submit button
|
||||
$form->addButtonSave(get_lang('PublishSurvey'));
|
||||
|
||||
// Show the URL that can be used by users to fill a survey without invitation
|
||||
$auto_survey_link = SurveyUtil::generateFillSurveyLink(
|
||||
'auto',
|
||||
$_course,
|
||||
$survey_data['session_id'],
|
||||
$survey_data['survey_code']
|
||||
);
|
||||
|
||||
$form->addElement('label', null, get_lang('AutoInviteLink'));
|
||||
$form->addElement('label', null, $auto_survey_link);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$resendAll = isset($values['resend_to_all']) ? $values['resend_to_all'] : '';
|
||||
$sendMail = isset($values['send_mail']) ? $values['send_mail'] : '';
|
||||
$remindUnAnswered = isset($values['remindUnAnswered']) ? $values['remindUnAnswered'] : '';
|
||||
$users = isset($values['users']) ? $values['users'] : [];
|
||||
$hideLink = isset($values['hide_link']) && $values['hide_link'] ? true : false;
|
||||
|
||||
if ($sendMail) {
|
||||
if (empty($values['mail_title']) || empty($values['mail_text'])) {
|
||||
echo Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error');
|
||||
// Getting the invited users
|
||||
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
|
||||
|
||||
// Getting the survey mail text
|
||||
if (!empty($survey_data['reminder_mail'])) {
|
||||
$defaults['mail_text'] = $survey_data['reminder_mail'];
|
||||
} else {
|
||||
$defaults['mail_text'] = $survey_data['invite_mail'];
|
||||
}
|
||||
$defaults['mail_title'] = $survey_data['mail_subject'];
|
||||
$defaults['send_mail'] = 1;
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$survey = Database::getManager()->getRepository('ChamiloCourseBundle:CSurvey')->find($survey_data['survey_id']);
|
||||
|
||||
// Save the invitation mail
|
||||
SurveyUtil::saveInviteMail(
|
||||
$survey,
|
||||
$values['mail_text'],
|
||||
$values['mail_title'],
|
||||
!empty($survey_data['invite_mail'])
|
||||
);
|
||||
|
||||
// Saving the invitations for the course users
|
||||
$count_course_users = SurveyUtil::saveInvitations(
|
||||
$survey_data['survey_id'],
|
||||
$users,
|
||||
$values['mail_title'],
|
||||
$values['mail_text'],
|
||||
$resendAll,
|
||||
$sendMail,
|
||||
$remindUnAnswered,
|
||||
false,
|
||||
$hideLink
|
||||
);
|
||||
|
||||
// Saving the invitations for the additional users
|
||||
$values['additional_users'] = $values['additional_users'].';'; // This is for the case when you enter only one email
|
||||
$temp = str_replace(',', ';', $values['additional_users']); // This is to allow , and ; as email separators
|
||||
$additional_users = explode(';', $temp);
|
||||
for ($i = 0; $i < count($additional_users); $i++) {
|
||||
$additional_users[$i] = trim($additional_users[$i]);
|
||||
}
|
||||
|
||||
$counter_additional_users = SurveyUtil::saveInvitations(
|
||||
$survey_data['survey_id'],
|
||||
$additional_users,
|
||||
$values['mail_title'],
|
||||
$values['mail_text'],
|
||||
$resendAll,
|
||||
$sendMail,
|
||||
$remindUnAnswered,
|
||||
true
|
||||
);
|
||||
|
||||
// Updating the invited field in the survey table
|
||||
// Counting the number of people that are invited
|
||||
$total_invited = SurveyUtil::update_count_invited($survey_data['code']);
|
||||
$total_count = $count_course_users + $counter_additional_users;
|
||||
$invitationUrl = api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq();
|
||||
if ($total_invited > 0) {
|
||||
$message = '<a href="'.$invitationUrl.'&view=answered">'.
|
||||
$survey_data['answered'].'</a> ';
|
||||
$message .= get_lang('HaveAnswered').' ';
|
||||
$message .= '<a href="'.$invitationUrl.'&view=invited">'.
|
||||
$total_invited.'</a> ';
|
||||
$message .= get_lang('WereInvited');
|
||||
echo Display::return_message($message, 'normal', false);
|
||||
if ($sendMail) {
|
||||
echo Display::return_message($total_count.' '.get_lang('InvitationsSend'), 'success', false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Getting the invited users
|
||||
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
|
||||
if (isset($defaults['additional_users']) && is_array($defaults['additional_users'])) {
|
||||
$defaults['additional_users'] = implode('; ', $defaults['additional_users']);
|
||||
}
|
||||
|
||||
// Getting the survey mail text
|
||||
if (!empty($survey_data['reminder_mail'])) {
|
||||
$defaults['mail_text'] = $survey_data['reminder_mail'];
|
||||
} else {
|
||||
$defaults['mail_text'] = $survey_data['invite_mail'];
|
||||
}
|
||||
$defaults['mail_title'] = $survey_data['mail_subject'];
|
||||
$defaults['send_mail'] = 1;
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
}
|
||||
Display::display_footer();
|
||||
988
main/survey/survey_list.php
Normal file
988
main/survey/survey_list.php
Normal file
@@ -0,0 +1,988 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of
|
||||
* the code
|
||||
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts
|
||||
* of the code
|
||||
*
|
||||
* @todo use quickforms for the forms
|
||||
*/
|
||||
if (!isset($_GET['cidReq'])) {
|
||||
$_GET['cidReq'] = 'none'; // Prevent sql errors
|
||||
$cidReset = true;
|
||||
}
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_COURSES;
|
||||
$current_course_tool = TOOL_SURVEY;
|
||||
$currentUserId = api_get_user_id();
|
||||
|
||||
api_protect_course_script(true);
|
||||
$action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : '';
|
||||
$type = $_REQUEST['type'] ?? 'by_class';
|
||||
Event::event_access_tool(TOOL_SURVEY);
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_SURVEY,
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
/** @todo
|
||||
* This has to be moved to a more appropriate place (after the display_header
|
||||
* of the code)
|
||||
*/
|
||||
$courseInfo = api_get_course_info();
|
||||
$sessionId = api_get_session_id();
|
||||
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
|
||||
$currentUserId,
|
||||
$courseInfo
|
||||
);
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
'.api_get_language_translate_html().'
|
||||
|
||||
$(function() {
|
||||
$("#dialog:ui-dialog").dialog("destroy");
|
||||
$("#dialog-confirm").dialog({
|
||||
autoOpen: false,
|
||||
show: "blind",
|
||||
resizable: false,
|
||||
height:300,
|
||||
modal: true
|
||||
});
|
||||
|
||||
$("#dialog-copy-confirm").dialog({
|
||||
autoOpen: false,
|
||||
show: "blind",
|
||||
resizable: false,
|
||||
height:300,
|
||||
modal: true
|
||||
});
|
||||
|
||||
$(".multiplicate_popup").click(function() {
|
||||
var targetUrl = $(this).attr("href");
|
||||
$( "#dialog-confirm" ).dialog({
|
||||
width:400,
|
||||
height:300,
|
||||
buttons: {
|
||||
"'.addslashes(get_lang('MultiplicateQuestions')).'": function() {
|
||||
var type = $("input[name=type]:checked").val();
|
||||
location.href = targetUrl+"&type="+type;
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
}
|
||||
});
|
||||
$("#dialog-confirm").dialog("open");
|
||||
return false;
|
||||
});
|
||||
|
||||
$(".copy_survey_popup").click(function() {
|
||||
var targetUrl = $(this).attr("href");
|
||||
$( "#dialog-copy-confirm" ).dialog({
|
||||
width:800,
|
||||
height:200,
|
||||
buttons: {
|
||||
"'.addslashes(get_lang('CopySurvey')).'": function() {
|
||||
var surveyCode = $("input[name=survey_code]").val();
|
||||
location.href = targetUrl+"&survey_code="+surveyCode;
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
}
|
||||
});
|
||||
$("#dialog-copy-confirm").dialog({
|
||||
open: function( event, ui ) {
|
||||
var timestampMiliseconds= new Date().getTime();
|
||||
var timestampSeconds = Math.floor(timestampMiliseconds / 1000);
|
||||
$("input[name=survey_code]").val(timestampSeconds);
|
||||
}
|
||||
});
|
||||
$("#dialog-copy-confirm").dialog("open");
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
if ($isDrhOfCourse) {
|
||||
Display::display_header(get_lang('SurveyList'));
|
||||
Display::display_introduction_section('survey', 'left');
|
||||
SurveyUtil::displaySurveyListForDrh();
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!api_is_allowed_to_edit(false, true)) {
|
||||
// Coach can see this
|
||||
Display::display_header(get_lang('SurveyList'));
|
||||
Display::display_introduction_section('survey', 'left');
|
||||
SurveyUtil::getSurveyList($currentUserId);
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
$extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
|
||||
|
||||
Session::erase('answer_count');
|
||||
Session::erase('answer_list');
|
||||
$tool_name = get_lang('SurveyList');
|
||||
// Language variables
|
||||
if (isset($_GET['search']) && 'advanced' === $_GET['search']) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
|
||||
'name' => get_lang('SurveyList'),
|
||||
];
|
||||
$tool_name = get_lang('SearchASurvey');
|
||||
}
|
||||
|
||||
$listUrl = api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq();
|
||||
$surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : 0;
|
||||
$surveyCode = isset($_GET['survey_code']) ? $_GET['survey_code'] : '';
|
||||
$surveyCode = Security::remove_XSS($surveyCode);
|
||||
|
||||
// Action handling: performing the same action on multiple surveys
|
||||
if (isset($_POST['action']) && $_POST['action'] && isset($_POST['id']) && is_array($_POST['id'])) {
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'export_by_class':
|
||||
$surveyList = [];
|
||||
$course_id = api_get_course_int_id();
|
||||
$extraFieldValue = new ExtraFieldValue('survey');
|
||||
|
||||
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
|
||||
$table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
|
||||
|
||||
$userGroup = new UserGroup();
|
||||
$options = [];
|
||||
$options['where'] = [' usergroup.course_id = ? ' => $course_id];
|
||||
$classes = $userGroup->getUserGroupInCourse($options, 0);
|
||||
|
||||
$usersInClassFullList = [];
|
||||
foreach ($classes as $class) {
|
||||
$usersInClassFullList[$class['id']] = $userGroup->getUserListByUserGroup($class['id'], 'u.lastname ASC');
|
||||
}
|
||||
|
||||
$debug = false;
|
||||
foreach ($_POST['id'] as $value) {
|
||||
$surveyData = SurveyManager::get_survey($value);
|
||||
$surveyId = $surveyData['survey_id'];
|
||||
if (empty($surveyData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$questions = SurveyManager::get_questions($surveyId);
|
||||
if (empty($questions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$surveyData['title'] = api_html_entity_decode(trim(strip_tags($surveyData['title'])));
|
||||
$groupData = $extraFieldValue->get_values_by_handler_and_field_variable(
|
||||
$surveyId,
|
||||
'group_id'
|
||||
);
|
||||
$groupTitle = '';
|
||||
if ($groupData && !empty($groupData['value'])) {
|
||||
$groupInfo = GroupManager::get_group_properties($groupData['value']);
|
||||
if ($groupInfo['name']) {
|
||||
$groupTitle = api_html_entity_decode($groupInfo['name']);
|
||||
}
|
||||
}
|
||||
$surveyData['group_title'] = $groupTitle;
|
||||
|
||||
$firstUser = '';
|
||||
$table = Database::get_course_table(TABLE_SURVEY_INVITATION);
|
||||
$sql = "SELECT * FROM $table
|
||||
WHERE
|
||||
answered = 1 AND
|
||||
c_id = $course_id AND
|
||||
session_id = $sessionId AND
|
||||
survey_code = '".Database::escape_string($surveyData['code'])."'
|
||||
";
|
||||
$result = Database::query($sql);
|
||||
$usersWithInvitation = [];
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
if (isset($usersWithInvitation[$row['user']])) {
|
||||
continue;
|
||||
}
|
||||
$userInfo = api_get_user_info($row['user']);
|
||||
$usersWithInvitation[$row['user']] = $userInfo;
|
||||
}
|
||||
|
||||
// No invitations.
|
||||
if (empty($usersWithInvitation)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
survey_question.question_id,
|
||||
survey_question.survey_id,
|
||||
survey_question.survey_question,
|
||||
survey_question.display,
|
||||
survey_question.max_value,
|
||||
survey_question.sort,
|
||||
survey_question.type,
|
||||
survey_question_option.question_option_id,
|
||||
survey_question_option.option_text,
|
||||
survey_question_option.sort as option_sort
|
||||
FROM $table_survey_question survey_question
|
||||
LEFT JOIN $table_survey_question_option survey_question_option
|
||||
ON
|
||||
survey_question.question_id = survey_question_option.question_id AND
|
||||
survey_question_option.c_id = $course_id
|
||||
WHERE
|
||||
survey_question NOT LIKE '%{{%' AND
|
||||
survey_question.survey_id = '".$surveyId."' AND
|
||||
survey_question.c_id = $course_id
|
||||
ORDER BY survey_question.sort, survey_question_option.sort ASC";
|
||||
$result = Database::query($sql);
|
||||
$questionsOptions = [];
|
||||
while ($row = Database::fetch_array($result, 'ASSOC')) {
|
||||
if ($row['type'] !== 'pagebreak') {
|
||||
$questionsOptions[$row['sort']]['question_id'] = $row['question_id'];
|
||||
$questionsOptions[$row['sort']]['survey_id'] = $row['survey_id'];
|
||||
$questionsOptions[$row['sort']]['survey_question'] = $row['survey_question'];
|
||||
$questionsOptions[$row['sort']]['display'] = $row['display'];
|
||||
$questionsOptions[$row['sort']]['type'] = $row['type'];
|
||||
$questionsOptions[$row['sort']]['maximum_score'] = $row['max_value'];
|
||||
$questionsOptions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text'];
|
||||
}
|
||||
}
|
||||
|
||||
// No questions.
|
||||
if (empty($questionsOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM $table_survey_answer
|
||||
WHERE c_id = $course_id AND survey_id = $surveyId ";
|
||||
$userAnswers = [];
|
||||
$all_answers = [];
|
||||
$result = Database::query($sql);
|
||||
while ($answers_of_user = Database::fetch_array($result, 'ASSOC')) {
|
||||
$userAnswers[$answers_of_user['user']][$surveyId][$answers_of_user['question_id']][] = $answers_of_user['option_id'];
|
||||
$all_answers[$answers_of_user['user']][$answers_of_user['question_id']][] = $answers_of_user;
|
||||
}
|
||||
|
||||
if (empty($userAnswers)) {
|
||||
continue;
|
||||
}
|
||||
//echo '<pre>';
|
||||
foreach ($questionsOptions as $question) {
|
||||
foreach ($usersWithInvitation as $userData) {
|
||||
$userIdItem = $userData['user_id'];
|
||||
// If the question type is a scoring then we have to format the answers differently.
|
||||
switch ($question['type']) {
|
||||
/*case 'score':
|
||||
$finalAnswer = [];
|
||||
if (is_array($question) && is_array($all_answers)) {
|
||||
foreach ($all_answers[$question['question_id']] as $key => &$answer_array) {
|
||||
$finalAnswer[$answer_array['option_id']] = $answer_array['value'];
|
||||
}
|
||||
}
|
||||
break;*/
|
||||
case 'multipleresponse':
|
||||
$finalAnswer = $userAnswers[$userIdItem][$surveyId][$question['question_id']] ?? '';
|
||||
if (is_array($finalAnswer)) {
|
||||
$items = [];
|
||||
foreach ($finalAnswer as $option) {
|
||||
foreach ($question['options'] as $optionId => $text) {
|
||||
if ($option == $optionId) {
|
||||
$items[] = api_html_entity_decode(strip_tags($text));
|
||||
}
|
||||
}
|
||||
}
|
||||
$finalAnswer = implode(' - ', $items);
|
||||
}
|
||||
break;
|
||||
/*case 'dropdown':
|
||||
$finalAnswer = '';
|
||||
if (isset($all_answers[$userIdItem][$question['question_id']])) {
|
||||
$optionAnswer = [];
|
||||
foreach ($all_answers[$userIdItem][$question['question_id']] as $option) {
|
||||
if ($userIdItem == 3368) {
|
||||
//var_dump($question['options'], $option);
|
||||
}
|
||||
foreach ($question['options'] as $optionId => $text) {
|
||||
if ($option['option_id'] == $optionId) {
|
||||
$optionAnswer[] = api_html_entity_decode(strip_tags($text));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$finalAnswer = implode(' - ', $optionAnswer);
|
||||
}
|
||||
if (empty($finalAnswer)) {
|
||||
//$finalAnswer = "ju $surveyId user $userIdItem";
|
||||
}
|
||||
if ($userIdItem == 3368) {
|
||||
//var_dump($surveyId, $question, $finalAnswer);
|
||||
//var_dump($all_answers[$userIdItem][$question['question_id']]);
|
||||
}
|
||||
|
||||
break;*/
|
||||
default:
|
||||
$finalAnswer = '';
|
||||
if (isset($all_answers[$userIdItem][$question['question_id']])) {
|
||||
$finalAnswer = $all_answers[$userIdItem][$question['question_id']][0]['option_id'];
|
||||
foreach ($question['options'] as $optionId => $text) {
|
||||
if ($finalAnswer == $optionId) {
|
||||
$finalAnswer = api_html_entity_decode(strip_tags($text));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($userIdItem == 3368) {
|
||||
//error_log("$surveyId : $finalAnswer");
|
||||
//error_log(print_r($all_answers[$userIdItem][$question['question_id']]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
$userAnswers[$userIdItem][$surveyId][$question['question_id']] = $finalAnswer;
|
||||
}
|
||||
}
|
||||
|
||||
$surveyData['users_with_invitation'] = $usersWithInvitation;
|
||||
$surveyData['user_answers'] = $userAnswers;
|
||||
$surveyData['questions'] = $questions;
|
||||
$surveyList[] = $surveyData;
|
||||
}
|
||||
|
||||
@$spreadsheet = new PHPExcel();
|
||||
$counter = 0;
|
||||
foreach ($classes as $class) {
|
||||
$classId = $class['id'];
|
||||
$usersInClass = $usersInClassFullList[$classId];
|
||||
if ($classId == 47) {
|
||||
//error_log(count($usersInClass));
|
||||
}
|
||||
if (empty($usersInClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$page = @$spreadsheet->createSheet($counter);
|
||||
@$page->setTitle($class['name']);
|
||||
$firstColumn = 3;
|
||||
$column = 3;
|
||||
$columnQuestion = 3;
|
||||
@$page->setCellValueByColumnAndRow(
|
||||
0,
|
||||
1,
|
||||
$class['name']
|
||||
);
|
||||
|
||||
$columnsWithData = [0, 1, 2];
|
||||
$previousSurveyQuestionsCount = 0;
|
||||
$skipThisClass = true;
|
||||
foreach ($surveyList as $survey) {
|
||||
$surveyId = $survey['survey_id'];
|
||||
$questions = $survey['questions'];
|
||||
$questionsOriginal = $survey['questions'];
|
||||
$usersWithInvitation = $survey['users_with_invitation'];
|
||||
if ($classId == 47) {
|
||||
/*error_log("s: $surveyId");
|
||||
error_log(count($usersWithInvitation));
|
||||
error_log(implode(',', array_column($usersWithInvitation, 'complete_name')));*/
|
||||
}
|
||||
if (empty($usersWithInvitation)) {
|
||||
continue;
|
||||
}
|
||||
$rowStudent = 3;
|
||||
$usersToShow = [];
|
||||
$previousSurveyCount = 0;
|
||||
$questionsInSurvey = 0;
|
||||
$userInvitationWithData = [];
|
||||
foreach ($usersInClass as $userInClass) {
|
||||
$userId = $userInClass['id'];
|
||||
$completeName = $userInClass['firstname'].' '.$userInClass['lastname'];
|
||||
if (empty($previousSurveyQuestionsCount)) {
|
||||
$userColumn = 3;
|
||||
} else {
|
||||
$userColumn = $previousSurveyQuestionsCount;
|
||||
}
|
||||
$questionsInSurvey = 0;
|
||||
$questionFound = false;
|
||||
foreach ($questions as $question) {
|
||||
if (isset($question['answers'])) {
|
||||
$question['answers'] = array_map('strip_tags', (array_map('trim', $question['answers'])));
|
||||
}
|
||||
$questionTitle = str_replace(
|
||||
'{{student_full_name}}',
|
||||
$completeName,
|
||||
$question['question']
|
||||
);
|
||||
if (strpos($question['question'], '{{')) {
|
||||
$questionsInSurvey++;
|
||||
foreach ($usersWithInvitation as $userAnswer) {
|
||||
$userWithInvitationId = $userAnswer['user_id'];
|
||||
$addColumn = false;
|
||||
foreach ($questions as $questionData) {
|
||||
if (strpos($questionData['question'], '{{') === false) {
|
||||
if ($questionTitle === $questionData['question']) {
|
||||
if (isset($survey['user_answers'][$userWithInvitationId][$surveyId])) {
|
||||
foreach ($survey['user_answers'][$userWithInvitationId][$surveyId] as $questionId => $answerData) {
|
||||
if ($questionData['question_id'] == $questionId) {
|
||||
if (is_array($answerData)) {
|
||||
$answerData = implode(', ', $answerData);
|
||||
}
|
||||
$answerDataOriginal = $answerData;
|
||||
$answerData = $answerDataOriginal = strip_tags(trim($answerData));
|
||||
$answerDataMissing = '';
|
||||
|
||||
if (isset($question['answers']) && !in_array($answerData, $question['answers'])) {
|
||||
//$answerDataMissing = 'Answer not found in list';
|
||||
$answerData = '';
|
||||
}
|
||||
if ($debug) {
|
||||
$answerData = "$answerData - $answerDataOriginal - $answerDataMissing - s: $surveyId u inv: {$userAnswer['lastname']} col: $userColumn prev: $previousSurveyQuestionsCount";
|
||||
}
|
||||
// Check if answer exists in the question list.
|
||||
$cell = @$page->setCellValueByColumnAndRow(
|
||||
$userColumn,
|
||||
$rowStudent,
|
||||
$answerData,
|
||||
true
|
||||
);
|
||||
$colCode = $cell->getColumn();
|
||||
$userInvitationWithData[$userAnswer['user_id']] = true;
|
||||
$addColumn = true;
|
||||
if (!in_array($userColumn, $columnsWithData)) {
|
||||
$columnsWithData[] = $userColumn;
|
||||
}
|
||||
$skipThisClass = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($addColumn) {
|
||||
$userColumn++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$rowStudent++;
|
||||
}
|
||||
|
||||
if ($classId == 47) {
|
||||
//error_log(count($userInvitationWithData));
|
||||
}
|
||||
if (empty($userInvitationWithData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($previousSurveyQuestionsCount)) {
|
||||
$previousSurveyQuestionsCount = 3;
|
||||
}
|
||||
|
||||
//$previousSurveyQuestionsCount += $questionsInSurvey;
|
||||
|
||||
$questionsInSurvey = 0;
|
||||
foreach ($questions as $question) {
|
||||
$questionTitle = $question['question'];
|
||||
if (strpos($question['question'], '{{')) {
|
||||
$firstColumn = $column;
|
||||
$questionTitle = api_html_entity_decode(
|
||||
trim(strip_tags(str_replace('{{student_full_name}}', '', $question['question'])))
|
||||
);
|
||||
// Add question title.
|
||||
$cell = @$page->setCellValueByColumnAndRow(
|
||||
$column,
|
||||
1,
|
||||
$questionTitle,
|
||||
true
|
||||
);
|
||||
$cell->getStyle()->getAlignment()->setHorizontal(
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_CENTER
|
||||
);
|
||||
$coordinate = $page->getCellByColumnAndRow($column, 1)->getCoordinate();
|
||||
$firstCoordinate = $coordinate;
|
||||
$questionId = $question['question_id'];
|
||||
if ($classId == 47) {
|
||||
/*echo '<pre>---';
|
||||
var_dump($column);
|
||||
var_dump($question['question']);
|
||||
var_dump(count($usersWithInvitation));*/
|
||||
}
|
||||
foreach ($usersWithInvitation as $userAnswer) {
|
||||
$userId = $userAnswer['user_id'];
|
||||
$title = $survey['group_title'].' - '.$userAnswer['complete_name'];
|
||||
|
||||
$cell = @$page->setCellValueByColumnAndRow(
|
||||
$column,
|
||||
1,
|
||||
$questionTitle,
|
||||
true
|
||||
);
|
||||
|
||||
if ($debug) {
|
||||
$title = 's:'.$surveyId.' - q '.$question['question_id'].' prev:'.$previousSurveyQuestionsCount.' '.$userAnswer['lastname'];
|
||||
}
|
||||
$cell = @$page->setCellValueByColumnAndRow(
|
||||
$column,
|
||||
2,
|
||||
$title,
|
||||
true
|
||||
);
|
||||
$cell->getStyle()->getAlignment()->setTextRotation(90);
|
||||
$spreadsheet->getActiveSheet()->getRowDimension(2)->setRowHeight(250);
|
||||
|
||||
$lastColumn = $column;
|
||||
$column++;
|
||||
$questionsInSurvey++;
|
||||
$coordinate = $page->getCellByColumnAndRow($lastColumn, 1)->getCoordinate();
|
||||
$lastCoordinate = $coordinate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$previousSurveyQuestionsCount += $questionsInSurvey;
|
||||
// Remove cols with no data.
|
||||
$less = 0;
|
||||
$index = 0;
|
||||
}
|
||||
|
||||
if ($skipThisClass) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove cols with no data.
|
||||
$less = 0;
|
||||
$index = 0;
|
||||
foreach ($page->getColumnIterator('A') as $col) {
|
||||
if (!in_array($index, $columnsWithData)) {
|
||||
if (!$debug) {
|
||||
$page->removeColumnByIndex($index - $less);
|
||||
}
|
||||
$less++;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
$counterColumn = 2;
|
||||
$categories = [];
|
||||
$letterList = [];
|
||||
$highestRow = $page->getHighestRow(0); // Name list
|
||||
// Sets $page->getColumnIterator('C')
|
||||
$dimension = $page->getColumnDimension('C');
|
||||
foreach ($page->getColumnIterator('C') as $col) {
|
||||
$index = $col->getColumnIndex();
|
||||
$cell = $page->getCellByColumnAndRow($counterColumn, 1);
|
||||
$coordinate = $page->getCellByColumnAndRow($counterColumn, 1)->getCoordinate();
|
||||
$value = $cell->getValue();
|
||||
if (!empty($value)) {
|
||||
$categories[$value][] = [
|
||||
'col' => $index,
|
||||
'row' => $highestRow,
|
||||
];
|
||||
$letterList[] = $index;
|
||||
}
|
||||
$counterColumn++;
|
||||
}
|
||||
|
||||
if (!empty($categories)) {
|
||||
$maxColumn = $counterColumn;
|
||||
$newCounter = 2;
|
||||
$newOrder = [];
|
||||
foreach ($categories as $category => $categoryList) {
|
||||
foreach ($categoryList as $categoryData) {
|
||||
$col = $categoryData['col']; // D
|
||||
$row = $categoryData['row']; // 15
|
||||
if (!$debug) {
|
||||
$data = $page->rangeToArray($col.'1:'.$col.$row);
|
||||
$newOrder[] = ['data' => $data, 'col' => $col];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($newOrder as $index => $order) {
|
||||
$data = $order['data'];
|
||||
$col = $order['col'];
|
||||
if (!$debug) {
|
||||
$page->fromArray($data, '@', $letterList[$index].'1', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge similar cols.
|
||||
$counterColumn = 3;
|
||||
$oldValue = '';
|
||||
$data = [];
|
||||
foreach ($page->getColumnIterator('C') as $col) {
|
||||
$index = $col->getColumnIndex();
|
||||
$cell = $page->getCellByColumnAndRow($counterColumn, 1);
|
||||
$cell->getStyle()->getAlignment()->setHorizontal(
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_CENTER
|
||||
);
|
||||
$coordinate = $page->getCellByColumnAndRow($counterColumn, 1)->getCoordinate();
|
||||
$value = $cell->getValue();
|
||||
if (!empty($value)) {
|
||||
if (!isset($data[$value])) {
|
||||
$data[$value]['start'] = $coordinate;
|
||||
$data[$value]['end'] = $coordinate;
|
||||
} else {
|
||||
$data[$value]['end'] = $coordinate;
|
||||
}
|
||||
}
|
||||
$counterColumn++;
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $colInfo) {
|
||||
if (!$debug) {
|
||||
$page->mergeCells($colInfo['start'].':'.$colInfo['end']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$row = 3;
|
||||
foreach ($usersInClass as $user) {
|
||||
$columnUser = 0;
|
||||
$lastname = $user['lastname'];
|
||||
if ($debug) {
|
||||
$lastname = $user['id'].': '.$user['lastname'];
|
||||
}
|
||||
@$page->setCellValueByColumnAndRow($columnUser++, $row, $lastname);
|
||||
@$page->setCellValueByColumnAndRow($columnUser++, $row, $user['firstname']);
|
||||
$row++;
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
|
||||
//exit;
|
||||
$page = @$spreadsheet->createSheet($counter);
|
||||
@$page->setTitle(get_lang('Questions'));
|
||||
$row = 1;
|
||||
|
||||
if (!$debug) {
|
||||
foreach ($surveyList as $survey) {
|
||||
$questions = $survey['questions'];
|
||||
$questionsOriginal = $survey['questions'];
|
||||
$usersWithInvitation = $survey['users_with_invitation'];
|
||||
$goodQuestionList = [];
|
||||
foreach ($questions as $question) {
|
||||
if (false === strpos($question['question'], '{{')) {
|
||||
$questionTitle = strip_tags($question['question']);
|
||||
$questionId = $question['question_id'];
|
||||
$firstColumn = 3;
|
||||
$column = 3;
|
||||
$columnQuestion = 3;
|
||||
foreach ($usersWithInvitation as $userAnswer) {
|
||||
$myUserId = $userAnswer['id'];
|
||||
$columnUser = 0;
|
||||
$cell = @$page->setCellValueByColumnAndRow($columnUser++, $row, $questionTitle, true);
|
||||
$page->getColumnDimensionByColumn($cell->getColumn())->setAutoSize(0);
|
||||
$page->getColumnDimensionByColumn($cell->getColumn())->setWidth(50);
|
||||
|
||||
$cell2 = @$page->setCellValueByColumnAndRow(
|
||||
$columnUser++,
|
||||
$row,
|
||||
$survey['group_title'].' - '.$userAnswer['complete_name'],
|
||||
true
|
||||
);
|
||||
$data = '';
|
||||
if (isset($survey['user_answers'][$myUserId]) &&
|
||||
isset($survey['user_answers'][$myUserId][$survey['survey_id']][$questionId])
|
||||
) {
|
||||
$data = $survey['user_answers'][$myUserId][$survey['survey_id']][$questionId];
|
||||
}
|
||||
// Question answer.
|
||||
$cell = @$page->setCellValueByColumnAndRow($columnUser++, $row, $data, true);
|
||||
$row++;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
$file = api_get_path(SYS_ARCHIVE_PATH).uniqid('report', true);
|
||||
@$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
|
||||
@$writer->save($file);
|
||||
|
||||
DocumentManager::file_send_for_download($file, true, get_lang('Report').'.xlsx');
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
$exportList = [];
|
||||
foreach ($_POST['id'] as $value) {
|
||||
$surveyData = SurveyManager::get_survey($value);
|
||||
if (empty($surveyData)) {
|
||||
continue;
|
||||
}
|
||||
$surveyData['title'] = trim(strip_tags($surveyData['title']));
|
||||
|
||||
switch ($action) {
|
||||
case 'export_all':
|
||||
$filename = $surveyData['code'].'.xlsx';
|
||||
$exportList[] = @SurveyUtil::export_complete_report_xls($surveyData, $filename, 0, true);
|
||||
break;
|
||||
case 'send_to_tutors':
|
||||
$result = SurveyManager::sendToTutors($value);
|
||||
if ($result) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('InvitationHasBeenSent').': '.$surveyData['title'],
|
||||
'confirmation',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('InvitationHasBeenNotSent').': '.$surveyData['title'],
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'multiplicate_by_class':
|
||||
case 'multiplicate_by_user':
|
||||
$type = 'multiplicate_by_class' === $action ? 'by_class' : 'by_user';
|
||||
$result = SurveyManager::multiplicateQuestions($surveyData, $type);
|
||||
$title = $surveyData['title'];
|
||||
if ($result) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('SurveyXMultiplicated'), $title),
|
||||
'confirmation',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('SurveyXNotMultiplicated'), $title),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
// if the survey is shared => also delete the shared content
|
||||
if (is_numeric($surveyData['survey_share'])) {
|
||||
SurveyManager::delete_survey($surveyData['survey_share'], true);
|
||||
}
|
||||
|
||||
SurveyManager::delete_survey($value);
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('SurveysDeleted').': '.$surveyData['title'], 'confirmation', false)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === 'export_all') {
|
||||
$tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'.zip';
|
||||
$zip = new PclZip($tempZipFile);
|
||||
foreach ($exportList as $file) {
|
||||
$zip->add($file, PCLZIP_OPT_REMOVE_ALL_PATH);
|
||||
}
|
||||
|
||||
DocumentManager::file_send_for_download(
|
||||
$tempZipFile,
|
||||
true,
|
||||
get_lang('SurveysWordInASCII').'-'.api_get_course_id().'-'.api_get_local_time().'.zip'
|
||||
);
|
||||
unlink($tempZipFile);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'send_to_tutors':
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$result = SurveyManager::sendToTutors($surveyId);
|
||||
if ($result) {
|
||||
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
|
||||
}
|
||||
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'multiplicate':
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$surveyData = SurveyManager::get_survey($surveyId);
|
||||
if (!empty($surveyData)) {
|
||||
SurveyManager::multiplicateQuestions($surveyData, $type);
|
||||
Display::cleanFlashMessages();
|
||||
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'remove_multiplicate':
|
||||
if (!api_is_allowed_to_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$surveyData = SurveyManager::get_survey($surveyId);
|
||||
if (!empty($surveyData)) {
|
||||
SurveyManager::removeMultiplicateQuestions($surveyData);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'copy_survey':
|
||||
if (!empty($surveyId) && api_is_allowed_to_edit()) {
|
||||
if (!empty($surveyCode)) {
|
||||
if (SurveyManager::checkUniqueCode($surveyCode)) {
|
||||
SurveyManager::copy_survey($surveyId, null, null, $surveyCode);
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('CodeAlreadyExists'), 'warning', false));
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
SurveyManager::copy_survey($surveyId);
|
||||
}
|
||||
Display::addFlash(Display::return_message(get_lang('SurveyCopied'), 'confirmation', false));
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (!empty($surveyId)) {
|
||||
// Getting the information of the survey (used for when the survey is shared)
|
||||
$survey_data = SurveyManager::get_survey($surveyId);
|
||||
if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
|
||||
// The coach can't delete a survey not belonging to his session
|
||||
api_not_allowed();
|
||||
}
|
||||
// If the survey is shared => also delete the shared content
|
||||
if (isset($survey_data['survey_share']) &&
|
||||
is_numeric($survey_data['survey_share'])
|
||||
) {
|
||||
SurveyManager::delete_survey($survey_data['survey_share'], true);
|
||||
}
|
||||
|
||||
$return = SurveyManager::delete_survey($surveyId);
|
||||
|
||||
if ($return) {
|
||||
Display::addFlash(Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case 'empty':
|
||||
$mysession = api_get_session_id();
|
||||
if (0 != $mysession) {
|
||||
if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
|
||||
api_is_element_in_the_session(TOOL_SURVEY, $surveyId))) {
|
||||
// The coach can't empty a survey not belonging to his session
|
||||
api_not_allowed();
|
||||
}
|
||||
} else {
|
||||
if (!(api_is_course_admin() || api_is_platform_admin())) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
$return = SurveyManager::empty_survey($surveyId);
|
||||
if ($return) {
|
||||
Display::addFlash(Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
Display::display_header($tool_name, 'Survey');
|
||||
Display::display_introduction_section('survey', 'left');
|
||||
|
||||
// Action handling: searching
|
||||
if (isset($_GET['search']) && 'advanced' === $_GET['search']) {
|
||||
SurveyUtil::display_survey_search_form();
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
if (!api_is_session_general_coach() || 'true' === $extend_rights_for_coachs) {
|
||||
// Action links
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&action=add">'.
|
||||
Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM).'</a> ';
|
||||
$url = api_get_path(WEB_CODE_PATH).'survey/create_meeting.php?'.api_get_cidreq();
|
||||
echo Display::url(
|
||||
Display::return_icon('add_doodle.png', get_lang('CreateNewSurveyDoodle'), '', ICON_SIZE_MEDIUM),
|
||||
$url
|
||||
);
|
||||
}
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&search=advanced">'.
|
||||
Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
|
||||
if (api_is_session_general_coach() && 'false' === $extend_rights_for_coachs) {
|
||||
SurveyUtil::display_survey_list_for_coach();
|
||||
} else {
|
||||
SurveyUtil::display_survey_list();
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
|
||||
/* Bypass functions to make direct use from SortableTable possible */
|
||||
function get_number_of_surveys()
|
||||
{
|
||||
return SurveyUtil::get_number_of_surveys();
|
||||
}
|
||||
|
||||
function get_survey_data($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
|
||||
}
|
||||
|
||||
function modify_filter($survey_id)
|
||||
{
|
||||
return SurveyUtil::modify_filter($survey_id, false);
|
||||
}
|
||||
|
||||
function modify_filter_drh($survey_id)
|
||||
{
|
||||
return SurveyUtil::modify_filter($survey_id, true);
|
||||
}
|
||||
|
||||
function get_number_of_surveys_for_coach()
|
||||
{
|
||||
return SurveyUtil::get_number_of_surveys_for_coach();
|
||||
}
|
||||
|
||||
function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
|
||||
}
|
||||
|
||||
function modify_filter_for_coach($survey_id)
|
||||
{
|
||||
return SurveyUtil::modify_filter_for_coach($survey_id);
|
||||
}
|
||||
|
||||
function anonymous_filter($anonymous)
|
||||
{
|
||||
return SurveyUtil::anonymous_filter($anonymous);
|
||||
}
|
||||
|
||||
function get_survey_data_drh($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction, true);
|
||||
}
|
||||
715
main/survey/survey_question.php
Normal file
715
main/survey/survey_question.php
Normal file
@@ -0,0 +1,715 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* Class survey_question.
|
||||
*/
|
||||
class survey_question
|
||||
{
|
||||
public $buttonList = [];
|
||||
/** @var FormValidator */
|
||||
private $form;
|
||||
|
||||
/**
|
||||
* @param array $surveyData
|
||||
*/
|
||||
public function addParentMenu($formData, FormValidator $form, $surveyData)
|
||||
{
|
||||
$surveyId = $surveyData['survey_id'];
|
||||
$questionId = isset($formData['question_id']) ? $formData['question_id'] : 0;
|
||||
$parentId = isset($formData['parent_id']) ? $formData['parent_id'] : 0;
|
||||
$optionId = isset($formData['parent_option_id']) ? $formData['parent_option_id'] : 0;
|
||||
$questions = SurveyManager::get_questions($surveyId);
|
||||
|
||||
$newQuestionList = [];
|
||||
$allowTypes = ['yesno', 'multiplechoice', 'multipleresponse'];
|
||||
foreach ($questions as $question) {
|
||||
if (in_array($question['type'], $allowTypes)) {
|
||||
$newQuestionList[$question['sort']] = $question;
|
||||
}
|
||||
}
|
||||
ksort($newQuestionList);
|
||||
|
||||
$options = [];
|
||||
foreach ($newQuestionList as $question) {
|
||||
if (!empty($questionId)) {
|
||||
if ($question['question_id'] == $questionId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$options[$question['question_id']] = strip_tags($question['question']);
|
||||
}
|
||||
$form->addSelect(
|
||||
'parent_id',
|
||||
get_lang('Parent'),
|
||||
$options,
|
||||
['id' => 'parent_id', 'placeholder' => get_lang('SelectAnOption')]
|
||||
);
|
||||
$url = api_get_path(WEB_AJAX_PATH).
|
||||
'survey.ajax.php?'.api_get_cidreq().'&a=load_question_options&survey_id='.$surveyId;
|
||||
$form->addHtml('
|
||||
<script>
|
||||
$(function() {
|
||||
$("#parent_id").on("change", function() {
|
||||
var questionId = $(this).val()
|
||||
var $select = $("#parent_option_id");
|
||||
$select.empty();
|
||||
|
||||
if (questionId === "") {
|
||||
$("#option_list").hide();
|
||||
} else {
|
||||
$.getJSON({
|
||||
url: "'.$url.'" + "&question_id=" + questionId,
|
||||
success: function(data) {
|
||||
$("#option_list").show();
|
||||
$.each(data, function(key, value) {
|
||||
$("<option>").val(key).text(value).appendTo($select);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
');
|
||||
|
||||
$style = 'display:none';
|
||||
$options = [];
|
||||
if (!empty($optionId) && !empty($parentId)) {
|
||||
$parentData = SurveyManager::get_question($parentId);
|
||||
$style = '';
|
||||
foreach ($parentData['answer_data'] as $answer) {
|
||||
$options[$answer['iid']] = strip_tags($answer['data']);
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHtml('<div id="option_list" style="'.$style.'">');
|
||||
$form->addSelect(
|
||||
'parent_option_id',
|
||||
get_lang('Option'),
|
||||
$options,
|
||||
['id' => 'parent_option_id', 'disable_js' => true]
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return survey_question
|
||||
*/
|
||||
public static function createQuestion($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'comment':
|
||||
return new ch_comment();
|
||||
case 'dropdown':
|
||||
return new ch_dropdown();
|
||||
case 'multiplechoice':
|
||||
return new ch_multiplechoice();
|
||||
case 'multipleresponse':
|
||||
return new ch_multipleresponse();
|
||||
case 'open':
|
||||
return new ch_open();
|
||||
case 'pagebreak':
|
||||
return new ch_pagebreak();
|
||||
case 'percentage':
|
||||
return new ch_percentage();
|
||||
case 'personality':
|
||||
return new ch_personality();
|
||||
case 'score':
|
||||
return new ch_score();
|
||||
case 'yesno':
|
||||
return new ch_yesno();
|
||||
case 'selectivedisplay':
|
||||
return new ch_selectivedisplay();
|
||||
case 'multiplechoiceother':
|
||||
return new ch_multiplechoiceother();
|
||||
default:
|
||||
api_not_allowed(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic part of any survey question: the question field.
|
||||
*
|
||||
* @param array $surveyData
|
||||
* @param array $formData
|
||||
*
|
||||
* @return FormValidator
|
||||
*/
|
||||
public function createForm($surveyData, $formData)
|
||||
{
|
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
|
||||
$questionId = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null;
|
||||
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null;
|
||||
$type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null;
|
||||
|
||||
$actionHeader = get_lang('EditQuestion').': ';
|
||||
if ($action === 'add') {
|
||||
$actionHeader = get_lang('AddQuestion').': ';
|
||||
}
|
||||
|
||||
$questionComment = '';
|
||||
$allowParent = false;
|
||||
switch ($type) {
|
||||
case 'open':
|
||||
$toolName = get_lang('Open');
|
||||
$questionComment = get_lang('QuestionTags');
|
||||
$allowParent = true;
|
||||
break;
|
||||
case 'yesno':
|
||||
$toolName = get_lang('YesNo');
|
||||
$allowParent = true;
|
||||
break;
|
||||
case 'multiplechoice':
|
||||
$toolName = get_lang('UniqueSelect');
|
||||
$allowParent = true;
|
||||
break;
|
||||
case 'multipleresponse':
|
||||
$toolName = get_lang('MultipleResponse');
|
||||
$allowParent = true;
|
||||
break;
|
||||
case 'selectivedisplay':
|
||||
$toolName = get_lang('SurveyQuestionSelectiveDisplay');
|
||||
$questionComment = get_lang('SurveyQuestionSelectiveDisplayComment');
|
||||
$allowParent = true;
|
||||
break;
|
||||
case 'multiplechoiceother':
|
||||
$toolName = get_lang('SurveyQuestionMultipleChoiceWithOther');
|
||||
$questionComment = get_lang('SurveyQuestionMultipleChoiceWithOtherComment');
|
||||
$allowParent = true;
|
||||
break;
|
||||
case 'pagebreak':
|
||||
$toolName = get_lang(api_ucfirst($type));
|
||||
$allowParent = false;
|
||||
break;
|
||||
default:
|
||||
$toolName = get_lang(api_ucfirst($type));
|
||||
$allowParent = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (false === api_get_configuration_value('survey_question_dependency')) {
|
||||
$allowParent = false;
|
||||
}
|
||||
|
||||
$icon = Display::return_icon(
|
||||
SurveyManager::icon_question($type),
|
||||
$toolName,
|
||||
['align' => 'middle', 'height' => '22px']
|
||||
).' ';
|
||||
|
||||
$toolName = $icon.$actionHeader.$toolName;
|
||||
$sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null;
|
||||
|
||||
$url = api_get_self().'?action='.$action.'&type='.$type.'&survey_id='.$surveyId.'&question_id='.$questionId.'&'.api_get_cidreq();
|
||||
$form = new FormValidator('question_form', 'post', $url);
|
||||
$form->addHeader($toolName);
|
||||
if (!empty($questionComment)) {
|
||||
$form->addHtml(Display::return_message($questionComment, 'info', false));
|
||||
}
|
||||
$form->addHidden('survey_id', $surveyId);
|
||||
$form->addHidden('question_id', $questionId);
|
||||
$form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId));
|
||||
$form->addHidden('type', $type);
|
||||
|
||||
$config = [
|
||||
'ToolbarSet' => 'SurveyQuestion',
|
||||
'Width' => '100%',
|
||||
'Height' => '120',
|
||||
];
|
||||
$form->addHtmlEditor(
|
||||
'question',
|
||||
get_lang('Question'),
|
||||
true,
|
||||
false,
|
||||
$config
|
||||
);
|
||||
|
||||
if (api_get_configuration_value('allow_required_survey_questions') &&
|
||||
in_array($_GET['type'], ['yesno', 'multiplechoice'])) {
|
||||
$form->addCheckBox('is_required', get_lang('IsMandatory'), get_lang('Yes'));
|
||||
}
|
||||
|
||||
if ($allowParent) {
|
||||
$this->addParentMenu($formData, $form, $surveyData);
|
||||
}
|
||||
|
||||
if (1 == $surveyData['survey_type']) {
|
||||
$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
|
||||
$sql = 'SELECT id, name FROM '.$table_survey_question_group.'
|
||||
WHERE survey_id = '.$surveyId.'
|
||||
ORDER BY name';
|
||||
$rs = Database::query($sql);
|
||||
$glist = null;
|
||||
while ($row = Database::fetch_array($rs, 'NUM')) {
|
||||
$glist .= '<option value="'.$row[0].'" >'.$row[1].'</option>';
|
||||
}
|
||||
|
||||
$grouplist = $grouplist1 = $grouplist2 = $glist;
|
||||
if (!empty($formData['assigned'])) {
|
||||
$grouplist = str_replace(
|
||||
'<option value="'.$formData['assigned'].'"',
|
||||
'<option value="'.$formData['assigned'].'" selected',
|
||||
$glist
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($formData['assigned1'])) {
|
||||
$grouplist1 = str_replace(
|
||||
'<option value="'.$formData['assigned1'].'"',
|
||||
'<option value="'.$formData['assigned1'].'" selected',
|
||||
$glist
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($formData['assigned2'])) {
|
||||
$grouplist2 = str_replace(
|
||||
'<option value="'.$formData['assigned2'].'"',
|
||||
'<option value="'.$formData['assigned2'].'" selected',
|
||||
$glist
|
||||
);
|
||||
}
|
||||
|
||||
$this->html .= '<tr><td colspan="">
|
||||
<fieldset style="border:1px solid black">
|
||||
<legend>'.get_lang('Condition').'</legend>
|
||||
<b>'.get_lang('Primary').'</b><br />
|
||||
<input type="radio" name="choose" value="1" '.(($formData['choose'] == 1) ? 'checked' : '').'>
|
||||
<select name="assigned">'.$grouplist.'</select><br />';
|
||||
$this->html .= '
|
||||
<b>'.get_lang('Secondary').'</b><br />
|
||||
<input type="radio" name="choose" value="2" '.(($formData['choose'] == 2) ? 'checked' : '').'>
|
||||
<select name="assigned1">'.$grouplist1.'</select>
|
||||
<select name="assigned2">'.$grouplist2.'</select>
|
||||
</fieldset><br />';
|
||||
}
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds submit button.
|
||||
*/
|
||||
public function renderForm()
|
||||
{
|
||||
if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
|
||||
/**
|
||||
* Prevent the edition of already-answered questions to avoid
|
||||
* inconsistent answers. Use the configuration option
|
||||
* survey_allow_answered_question_edit to change this behaviour.
|
||||
*/
|
||||
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
|
||||
$answersChecker = SurveyUtil::checkIfSurveyHasAnswers($surveyId);
|
||||
$allowQuestionEdit = api_get_configuration_value('survey_allow_answered_question_edit') == true;
|
||||
if ($allowQuestionEdit or !$answersChecker) {
|
||||
$this->buttonList[] = $this->getForm()->addButtonUpdate(get_lang('ModifyQuestionSurvey'), 'save', true);
|
||||
} else {
|
||||
$this->getForm()->addHtml('
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"></label>
|
||||
<div class="col-sm-8">
|
||||
<div class="alert alert-info">'.
|
||||
get_lang('YouCantNotEditThisQuestionBecauseAlreadyExistAnswers').'</div>
|
||||
</div>
|
||||
<div class="col-sm-2"></div>
|
||||
</div>
|
||||
');
|
||||
}
|
||||
} else {
|
||||
$this->buttonList[] = $this->getForm()->addButtonSave(get_lang('CreateQuestionSurvey'), 'save', true);
|
||||
}
|
||||
|
||||
$this->getForm()->addGroup($this->buttonList, 'buttons');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormValidator
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormValidator $form
|
||||
*/
|
||||
public function setForm($form)
|
||||
{
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $formData
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function preSave($formData)
|
||||
{
|
||||
$counter = Session::read('answer_count');
|
||||
$answerList = Session::read('answer_list');
|
||||
|
||||
if (empty($answerList)) {
|
||||
$answerList = isset($formData['answers']) ? $formData['answers'] : [];
|
||||
Session::write('answer_list', $answerList);
|
||||
}
|
||||
|
||||
if (isset($_POST['answers'])) {
|
||||
$formData['answers'] = $_POST['answers'];
|
||||
}
|
||||
|
||||
if (empty($counter)) {
|
||||
$counter = count($answerList) - 1;
|
||||
Session::write('answer_count', $counter);
|
||||
}
|
||||
|
||||
// Moving an answer up
|
||||
if (isset($_POST['move_up']) && $_POST['move_up']) {
|
||||
foreach ($_POST['move_up'] as $key => &$value) {
|
||||
$id1 = $key;
|
||||
$content1 = $formData['answers'][$id1];
|
||||
$id2 = $key - 1;
|
||||
$content2 = $formData['answers'][$id2];
|
||||
$formData['answers'][$id1] = $content2;
|
||||
$formData['answers'][$id2] = $content1;
|
||||
}
|
||||
}
|
||||
|
||||
// Moving an answer down
|
||||
if (isset($_POST['move_down']) && $_POST['move_down']) {
|
||||
foreach ($_POST['move_down'] as $key => &$value) {
|
||||
$id1 = $key;
|
||||
$content1 = $formData['answers'][$id1];
|
||||
$id2 = $key + 1;
|
||||
$content2 = $formData['answers'][$id2];
|
||||
$formData['answers'][$id1] = $content2;
|
||||
$formData['answers'][$id2] = $content1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deleting a specific answer is only saved in the session until the
|
||||
* "Save question" button is pressed. This means all options are kept
|
||||
* in the survey_question_option table until the question is saved.
|
||||
*/
|
||||
if (isset($_POST['delete_answer'])) {
|
||||
$deleted = false;
|
||||
foreach ($_POST['delete_answer'] as $key => &$value) {
|
||||
$deleted = $key;
|
||||
$counter--;
|
||||
Session::write('answer_count', $counter);
|
||||
}
|
||||
|
||||
$newAnswers = [];
|
||||
$newAnswersId = [];
|
||||
foreach ($formData['answers'] as $key => &$value) {
|
||||
if ($key > $deleted) {
|
||||
// swap with previous (deleted) option slot
|
||||
$newAnswers[$key - 1] = $formData['answers'][$key];
|
||||
$newAnswersId[$key - 1] = $formData['answersid'][$key];
|
||||
unset($formData['answers'][$key]);
|
||||
unset($formData['answersid'][$key]);
|
||||
} elseif ($key === $deleted) {
|
||||
// delete option
|
||||
unset($formData['answers'][$deleted]);
|
||||
unset($formData['answersid'][$deleted]);
|
||||
} else {
|
||||
// keep as is
|
||||
$newAnswers[$key] = $value;
|
||||
$newAnswersId[$key] = $formData['answersid'][$key];
|
||||
}
|
||||
}
|
||||
unset($formData['answers']);
|
||||
unset($formData['answersid']);
|
||||
$formData['answers'] = $newAnswers;
|
||||
$formData['answersid'] = $newAnswersId;
|
||||
}
|
||||
|
||||
// Adding an answer
|
||||
if (isset($_POST['buttons']) && isset($_POST['buttons']['add_answer'])) {
|
||||
if (isset($_REQUEST['type']) && 'multiplechoiceother' === $_REQUEST['type'] && $counter > 2) {
|
||||
$counter--;
|
||||
}
|
||||
$counter++;
|
||||
Session::write('answer_count', $counter);
|
||||
}
|
||||
|
||||
// Removing an answer
|
||||
if (isset($_POST['buttons']) && isset($_POST['buttons']['remove_answer'])) {
|
||||
$counter--;
|
||||
Session::write('answer_count', $counter);
|
||||
foreach ($formData['answers'] as $index => &$data) {
|
||||
if ($index > $counter) {
|
||||
unset($formData['answers'][$index]);
|
||||
unset($formData['answersid'][$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_POST['delete_answer'])) {
|
||||
// Make sure we have an array of answers
|
||||
if (!isset($formData['answers'])) {
|
||||
$formData['answers'] = [];
|
||||
}
|
||||
// Check if no deleted answer remains at the end of the answers
|
||||
// array and add empty answers if the array is too short
|
||||
foreach ($formData['answers'] as $index => $data) {
|
||||
if ($index > $counter) {
|
||||
unset($formData['answers'][$index]);
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i <= $counter; $i++) {
|
||||
if (!isset($formData['answers'][$i])) {
|
||||
$formData['answers'][$i] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formData['answers'] = isset($formData['answers']) ? $formData['answers'] : [];
|
||||
Session::write('answer_list', $formData['answers']);
|
||||
|
||||
if (!isset($formData['is_required']) && api_get_configuration_value('survey_mark_question_as_required')) {
|
||||
$formData['is_required'] = true;
|
||||
}
|
||||
|
||||
return $formData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $surveyData
|
||||
* @param array $formData
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function save($surveyData, $formData, $dataFromDatabase = [])
|
||||
{
|
||||
// Saving a question
|
||||
if (isset($_POST['buttons']) && isset($_POST['buttons']['save'])) {
|
||||
Session::erase('answer_count');
|
||||
Session::erase('answer_list');
|
||||
$message = SurveyManager::save_question($surveyData, $formData, true, $dataFromDatabase);
|
||||
|
||||
if ($message === 'QuestionAdded' || $message === 'QuestionUpdated') {
|
||||
$url = api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.intval($_GET['survey_id']).'&message='.$message.'&'.api_get_cidreq();
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
return $formData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two buttons. One to add an option, one to remove an option.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function addRemoveButtons($data)
|
||||
{
|
||||
$this->buttonList['remove_answer'] = $this->getForm()->createElement(
|
||||
'button',
|
||||
'remove_answer',
|
||||
get_lang('RemoveAnswer'),
|
||||
'minus',
|
||||
'default'
|
||||
);
|
||||
|
||||
if (count($data['answers']) <= 2) {
|
||||
$this->buttonList['remove_answer']->updateAttributes(
|
||||
['disabled' => 'disabled']
|
||||
);
|
||||
}
|
||||
|
||||
$this->buttonList['add_answer'] = $this->getForm()->createElement(
|
||||
'button',
|
||||
'add_answer',
|
||||
get_lang('AddAnswer'),
|
||||
'plus',
|
||||
'default'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JS for questions that can depend on a previous question
|
||||
* (and that hides those questions until something changes in the previous
|
||||
* question).
|
||||
*
|
||||
* @return string HTML code
|
||||
*/
|
||||
public static function getJs()
|
||||
{
|
||||
return '
|
||||
<style>
|
||||
.with_parent {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
$(function() {
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the question parents recursively, if any. This function depends on
|
||||
* the existence of a parent_id field, which depends on the
|
||||
* 'survey_question_dependency' setting and its corresponding SQL
|
||||
* requirements.
|
||||
*
|
||||
* @param int $questionId The c_survey_question.question.id
|
||||
* @param array $list An array of parents to be extended by this method
|
||||
*
|
||||
* @return array The completed array of parents
|
||||
*/
|
||||
public static function getParents($questionId, $list = [])
|
||||
{
|
||||
if (true !== api_get_configuration_value('survey_question_dependency')) {
|
||||
return $list;
|
||||
}
|
||||
$courseId = api_get_course_int_id();
|
||||
$questionId = (int) $questionId;
|
||||
|
||||
$table = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$sql = "SELECT parent_id FROM $table
|
||||
WHERE c_id = $courseId AND question_id = $questionId ";
|
||||
$result = Database::query($sql);
|
||||
$row = Database::fetch_array($result, 'ASSOC');
|
||||
if ($row && !empty($row['parent_id'])) {
|
||||
$list[] = $row['parent_id'];
|
||||
$list = self::getParents($row['parent_id'], $list);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the JS code for the given parent question so that it shows
|
||||
* the children questions when a specific answer of the parent is selected.
|
||||
*
|
||||
* @param array $question An array with the question details
|
||||
*
|
||||
* @return string JS code to add to the HTML survey question page
|
||||
*/
|
||||
public static function getQuestionJs($question)
|
||||
{
|
||||
if (empty($question)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$list = self::getDependency($question);
|
||||
|
||||
if (empty($list)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$type = $question['type'];
|
||||
$questionId = $question['question_id'];
|
||||
$newList = [];
|
||||
foreach ($list as $child) {
|
||||
$childQuestionId = $child['question_id'];
|
||||
$optionId = $child['parent_option_id'];
|
||||
$newList[$optionId][] = $childQuestionId;
|
||||
}
|
||||
|
||||
if ('multipleresponse' === $type) {
|
||||
$multiple = '';
|
||||
foreach ($newList as $optionId => $child) {
|
||||
$multiple .= '
|
||||
$(\'input[name="question'.$questionId.'['.$optionId.']"]\').on("change", function() {
|
||||
var isChecked= $(this).is(\':checked\');
|
||||
var checkedValue = $(this).val();
|
||||
if (isChecked) {
|
||||
$.each(list, function(index, value) {
|
||||
$(".with_parent_" + value).find("input").prop("checked", false);
|
||||
});
|
||||
|
||||
var questionId = $(this).val();
|
||||
var questionToShow = list[questionId];
|
||||
$(".with_parent_" + questionToShow).show();
|
||||
} else {
|
||||
var checkedValue = list[checkedValue];
|
||||
}
|
||||
});
|
||||
';
|
||||
}
|
||||
|
||||
$js = '
|
||||
<script>
|
||||
$(function() {
|
||||
var list = '.json_encode($newList).';
|
||||
'.$multiple.'
|
||||
});
|
||||
</script>';
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
$js = '
|
||||
<script>
|
||||
$(function() {
|
||||
var list = '.json_encode($newList).';
|
||||
$("input[name=question'.$questionId.']").on("click", function() {
|
||||
$.each(list, function(index, value) {
|
||||
$.each(value, function(index, itemValue) {
|
||||
$(".with_parent_" + itemValue).hide();
|
||||
$(".with_parent_" + itemValue).find("input").prop("checked", false);
|
||||
$(".with_parent_only_hide_" + itemValue).hide();
|
||||
});
|
||||
});
|
||||
|
||||
var questionId = $(this).val();
|
||||
var questionToShowList = list[questionId];
|
||||
$.each(questionToShowList, function(index, value) {
|
||||
$(".with_parent_" + value).show();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the (children) questions that have the given question as parent.
|
||||
*
|
||||
* @param array $question An array describing the parent question
|
||||
*
|
||||
* @return array The questions that have the given question as parent
|
||||
*/
|
||||
public static function getDependency($question)
|
||||
{
|
||||
if (true !== api_get_configuration_value('survey_question_dependency')) {
|
||||
return [];
|
||||
}
|
||||
$table = Database::get_course_table(TABLE_SURVEY_QUESTION);
|
||||
$questionId = $question['question_id'];
|
||||
$courseId = api_get_course_int_id();
|
||||
|
||||
// Getting the information of the question
|
||||
$sql = "SELECT * FROM $table
|
||||
WHERE c_id = $courseId AND parent_id = $questionId ";
|
||||
$result = Database::query($sql);
|
||||
$row = Database::store_result($result, 'ASSOC');
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not implemented at this level (returns null).
|
||||
*
|
||||
* @param array $questionData
|
||||
* @param array $answers
|
||||
*/
|
||||
public function render(FormValidator $form, $questionData = [], $answers = [])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user