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