Update from 1.11.x add "survey meeting"

pull/2744/head
Julio Montoya 6 years ago
parent 784db9d0e0
commit 540e0a04b0
  1. 2
      main/inc/lib/formvalidator/Element/DateTimePicker.php
  2. 12
      main/inc/lib/formvalidator/FormValidator.class.php
  3. 4
      main/survey/create_new_survey.php
  4. 42
      main/survey/fillsurvey.php
  5. 81
      main/survey/preview.php
  6. 14
      main/survey/question.php
  7. 3
      main/survey/reporting.php

@ -45,7 +45,7 @@ class DateTimePicker extends HTML_QuickForm_text
$resetFieldX = sprintf(get_lang('ResetFieldX'), $label);
return '
<div class="input-group">
<div class="input-group" id="date_time_wrapper_'.$id.'">
<span class="input-group-addon cursor-pointer">
<input '.$this->_getAttrString($this->_attributes).'>
</span>

@ -282,6 +282,18 @@ EOT;
return $this->addElement('DateTimePicker', $name, $label, $attributes);
}
/**
* @param string $name
* @param string $label
* @param array $attributes
*
* @return HTML_QuickForm_element
*/
public function addDateTimeRangePicker($name, $label, $attributes = [])
{
return $this->addElement('DateTimeRangePicker', $name, $label, $attributes);
}
/**
* @param string $name
* @param string $value

@ -22,6 +22,10 @@ $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) */

@ -97,7 +97,7 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
// Survey_code of the survey
$surveyCode = $_GET['scode'];
if ($isAnonymous) {
$autoInvitationcode = "auto-ANONY_".md5(time())."-$surveyCode";
$autoInvitationcode = 'auto-ANONY_'.md5(time())."-$surveyCode";
} else {
// New invitation code from userid
$autoInvitationcode = "auto-$userid-$surveyCode";
@ -204,6 +204,14 @@ if (empty($survey_data)) {
}
$survey_data['survey_id'] = $survey_invitation['survey_id'];
if ($survey_data['survey_type'] == '3') {
header('Location: '.
api_get_path(WEB_CODE_PATH).
'survey/meeting.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId.'&invitationcode='.Security::remove_XSS($invitationcode)
);
exit;
}
// Storing the answers
if (count($_POST) > 0) {
if ($survey_data['survey_type'] === '0') {
@ -653,6 +661,7 @@ if (
if (empty($paged_questions)) {
$sql = "SELECT * FROM $table_survey_question
WHERE
survey_question NOT LIKE '%{{%' AND
c_id = $course_id AND
survey_id = '".intval($survey_invitation['survey_id'])."'
ORDER BY sort ASC";
@ -733,6 +742,7 @@ if (
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 = '".intval($survey_invitation['survey_id'])."' AND
survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
survey_question.c_id = $course_id
@ -764,7 +774,7 @@ if (
}
}
} elseif ($survey_data['survey_type'] === '1') {
$my_survey_id = intval($survey_invitation['survey_id']);
$my_survey_id = (int) $survey_invitation['survey_id'];
$current_user = Database::escape_string($survey_invitation['user']);
if (isset($_POST['personality'])) {
@ -777,7 +787,10 @@ if (
$answer_list = [];
// Get current user results
$results = [];
$sql = "SELECT survey_group_pri, user, SUM(value) as value
$sql = "SELECT
survey_group_pri,
user,
SUM(value) as value
FROM $table_survey_answer as survey_answer
INNER JOIN $table_survey_question as survey_question
ON (survey_question.question_id = survey_answer.question_id)
@ -796,7 +809,6 @@ if (
$answer_list['group'] = $row['survey_group_pri'];
$results[] = $answer_list;
}
//echo '<br />'; print_r($results); echo '<br />';
// Get the total score for each group of questions
$totals = [];
@ -1014,6 +1026,7 @@ if (
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 = '".$my_survey_id."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
@ -1124,6 +1137,7 @@ if (
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 = '".intval($survey_invitation['survey_id'])."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".$imploded.")
@ -1170,7 +1184,7 @@ if (
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
type = '".Database::escape_string('pagebreak')."' AND
type = 'pagebreak' AND
survey_id='".intval($survey_invitation['survey_id'])."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
@ -1222,12 +1236,27 @@ $form = new FormValidator(
$form->addHidden('language', $p_l);
if (isset($questions) && is_array($questions)) {
$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
$questionCounter = 1;
if (!empty($originalShow)) {
$before = 0;
foreach ($paged_questions as $keyQuestion => $list) {
if ($originalShow > $keyQuestion) {
$before += count($list);
}
}
$questionCounter = $before + 1;
}
foreach ($questions as $key => &$question) {
$ch_type = 'ch_'.$question['type'];
//$questionNumber = $question['sort'];
$questionNumber = $questionCounter;
$display = new $ch_type();
// @todo move this in a function.
$form->addHtml('<div class="survey_question '.$ch_type.'">');
$form->addHtml('<h5 class="title">'.$question['sort'].'. '.strip_tags($question['survey_question']).'</h5>');
$form->addHtml('<h5 class="title">'.$questionNumber.'. '.strip_tags($question['survey_question']).'</h5>');
$userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']);
$finalAnswer = null;
@ -1254,6 +1283,7 @@ if (isset($questions) && is_array($questions)) {
}
$display->render($form, $question, $finalAnswer);
$form->addHtml('</div>');
$questionCounter++;
}
}

@ -5,8 +5,8 @@
* @package chamilo.survey
*
* @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 Armas <gugli100@gmail.com>, Chamilo: Personality Test modifications
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting code
* @author Julio Montoya <gugli100@gmail.com>, Chamilo: Personality Test modifications
*
* @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
*/
@ -25,7 +25,7 @@ $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
$course_id = api_get_course_int_id();
$courseInfo = $course_id ? api_get_course_info_by_id($course_id) : [];
$userId = api_get_user_id();
$surveyId = intval($_GET['survey_id']);
$surveyId = (int) $_GET['survey_id'];
$userInvited = 0;
$userAnonymous = 0;
@ -49,12 +49,10 @@ if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])) {
true,
Display::return_message(get_lang('InvallidSurvey'), 'error', false)
);
exit;
}
// Getting the survey information
$survey_id = intval($_GET['survey_id']);
$survey_data = SurveyManager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($surveyId);
if (empty($survey_data)) {
api_not_allowed(
@ -71,12 +69,12 @@ if (api_is_allowed_to_edit()) {
'name' => get_lang('SurveyList'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'&'.api_get_cidreq(),
'name' => $urlname,
];
}
$courseCode = isset($_GET['cidReq']) ? $_GET['cidReq'] : null;
$surveyAnonymous = SurveyManager::get_survey($survey_id, 0, $courseCode);
$surveyAnonymous = SurveyManager::get_survey($surveyId, 0, $courseCode);
$surveyAnonymous = $surveyAnonymous['anonymous'];
if ($surveyAnonymous == 0 && api_is_anonymous()) {
api_not_allowed(true);
@ -89,7 +87,7 @@ if ($surveyAnonymous == 0 && api_is_anonymous()) {
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($survey_id, false);
SurveyUtil::check_first_last_question($surveyId, false);
$counter_question = 0;
// Only a course admin is allowed to preview a survey: you are a course admin
if (api_is_course_admin() ||
@ -127,7 +125,10 @@ if (api_is_course_admin() ||
$paged_questions = [];
$counter = 0;
$sql = "SELECT * FROM $table_survey_question
WHERE c_id = $course_id AND survey_id = '".$survey_id."'
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;
@ -143,6 +144,16 @@ if (api_is_course_admin() ||
$questions_exists = false;
}
$sql = "SELECT count(survey_question.question_id) as count
FROM $table_survey_question survey_question
WHERE
survey_question.survey_id = '".$surveyId."' AND
survey_question.c_id = $course_id AND
survey_question LIKE '%{{%' ";
$result = Database::query($sql);
$sourceQuestions = Database::fetch_array($result, 'ASSOC');
$sourceQuestions = $sourceQuestions['count'];
if (array_key_exists($_GET['show'], $paged_questions)) {
$sql = "SELECT
survey_question.question_id,
@ -161,24 +172,27 @@ if (api_is_course_admin() ||
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.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
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);
$question_counter_max = Database::num_rows($result);
$limit = 0;
while ($row = Database::fetch_array($result)) {
// If the type is not a pagebreak we store it in the $questions array
if ($row['type'] != 'pagebreak') {
$questions[$row['sort']]['question_id'] = $row['question_id'];
$questions[$row['sort']]['survey_id'] = $row['survey_id'];
$questions[$row['sort']]['survey_question'] = $row['survey_question'];
$questions[$row['sort']]['display'] = $row['display'];
$questions[$row['sort']]['type'] = $row['type'];
$questions[$row['sort']]['options'][intval($row['option_sort'])] = $row['option_text'];
$questions[$row['sort']]['maximum_score'] = $row['max_value'];
$sort = $row['sort'];
$questions[$sort]['question_id'] = $row['question_id'];
$questions[$sort]['survey_id'] = $row['survey_id'];
$questions[$sort]['survey_question'] = $row['survey_question'];
$questions[$sort]['display'] = $row['display'];
$questions[$sort]['type'] = $row['type'];
$questions[$sort]['options'][intval($row['option_sort'])] = $row['option_text'];
$questions[$sort]['maximum_score'] = $row['max_value'];
} else {
// If the type is a pagebreak we are finished loading the questions for this page
break;
@ -188,23 +202,29 @@ if (api_is_course_admin() ||
}
}
$before = 0;
if (isset($_GET['show']) && isset($paged_questions[$_GET['show'] - 1])) {
$before = count($paged_questions[$_GET['show'] - 1]);
}
// Selecting the maximum number of pages
$sql = "SELECT * FROM $table_survey_question
WHERE
survey_question NOT LIKE '%{{%' AND
c_id = $course_id AND
type = '".Database::escape_string('pagebreak')."' AND
survey_id = '".$survey_id."'";
type = 'pagebreak' AND
survey_id = '".$surveyId."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
// Displaying the form with the questions
$show = 0;
if (isset($_GET['show'])) {
$show = (int) $_GET['show'] + 1;
} else {
$show = 0;
}
$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
$url = api_get_self().'?survey_id='.$survey_id.'&show='.$show;
$url = api_get_self().'?survey_id='.$surveyId.'&show='.$show.'&'.api_get_cidreq();
$form = new FormValidator(
'question-survey',
'post',
@ -215,14 +235,25 @@ if (api_is_course_admin() ||
);
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;
}
foreach ($questions as $key => &$question) {
$ch_type = 'ch_'.$question['type'];
/** @var survey_question $display */
$display = new $ch_type();
$form->addHtml('<div class="survey_question '.$ch_type.'">');
$form->addHtml('<h5 class="title">'.$key.'. '.strip_tags($question['survey_question']).'</h5>');
$form->addHtml('<h5 class="title">'.$counter.'. '.strip_tags($question['survey_question']).'</h5>');
$display->render($form, $question);
$form->addHtml('</div>');
$counter++;
}
}
$form->addHtml('<div class="start-survey">');

@ -115,12 +115,12 @@ $surveyQuestion = new $ch_type();
$formData = [];
$formData['answers'] = ['', ''];
if ($_GET['type'] == 'yesno') {
switch ($_GET['type']) {
case 'yesno':
$formData['answers'][0] = get_lang('Yes');
$formData['answers'][1] = get_lang('No');
}
if ($_GET['type'] == 'personality') {
break;
case 'personality':
$formData['answers'][0] = 1;
$formData['answers'][1] = 2;
$formData['answers'][2] = 3;
@ -132,6 +132,10 @@ if ($_GET['type'] == 'personality') {
$formData['values'][2] = 1;
$formData['values'][3] = 2;
$formData['values'][4] = 3;
break;
case 'open':
Display::addFlash(Display::return_message(get_lang('QuestionTags')));
break;
}
// We are editing a question
@ -150,7 +154,5 @@ if ($surveyQuestion->getForm()->validate()) {
}
Display::display_header($tool_name, 'Survey');
echo $surveyQuestion->getForm()->returnForm();
Display :: display_footer();

@ -45,7 +45,6 @@ if (!api_is_allowed_to_edit(false, true) || $isDrhOfCourse) {
// Show error message if the survey can be seen only by tutors
if ($survey_data['visible_results'] == SURVEY_VISIBLE_TUTOR) {
api_not_allowed(true);
exit;
}
Display::display_header(get_lang('ToolSurvey'));
@ -62,7 +61,7 @@ $format = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : '';
if (!empty($exportReport) && !empty($format)) {
switch ($format) {
case 'xls':
$filename = 'survey_results_'.$survey_id.'.xlsx';
$filename = 'survey_results_'.$survey_id;
$data = SurveyUtil::export_complete_report_xls(
$survey_data,
$filename,

Loading…
Cancel
Save