Merge branch '1.11.x' of https://github.com/chamilo/chamilo-lms into 1.11.x
commit
dd1a76e753
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 4.1 KiB |
@ -0,0 +1,46 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
require_once __DIR__.'/../global.inc.php'; |
||||
|
||||
$action = isset($_GET['a']) ? $_GET['a'] : null; |
||||
|
||||
$current_user_id = api_get_user_id(); |
||||
$courseId = api_get_course_int_id(); |
||||
|
||||
switch ($action) { |
||||
case 'save_question': |
||||
if (api_is_anonymous()) { |
||||
echo ''; |
||||
break; |
||||
} |
||||
$surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : null; |
||||
$questionId = isset($_GET['question_id']) ? $_GET['question_id'] : null; |
||||
$status = isset($_GET['status']) ? (int) $_GET['status'] : null; |
||||
$userId = api_get_user_id(); |
||||
|
||||
$surveyData = SurveyManager::get_survey($surveyId); |
||||
|
||||
if (empty($surveyData)) { |
||||
exit; |
||||
} |
||||
|
||||
SurveyUtil::remove_answer( |
||||
$userId, |
||||
$surveyId, |
||||
$questionId, |
||||
$courseId |
||||
); |
||||
|
||||
SurveyUtil::store_answer( |
||||
$userId, |
||||
$surveyId, |
||||
$questionId, |
||||
1, |
||||
$status, |
||||
$surveyData |
||||
); |
||||
|
||||
break; |
||||
} |
||||
exit; |
||||
@ -0,0 +1,157 @@ |
||||
<?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); |
||||
} |
||||
|
||||
$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); |
||||
|
||||
// Setting the form elements |
||||
/*if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) { |
||||
$form->addElement('hidden', 'survey_id'); |
||||
}*/ |
||||
|
||||
$text = $form->addElement( |
||||
'text', |
||||
'survey_title', |
||||
get_lang('Title'), |
||||
null, |
||||
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200'] |
||||
); |
||||
|
||||
$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'); |
||||
$form->addRule( |
||||
['start_date', 'end_date'], |
||||
get_lang('StartDateShouldBeBeforeEndDate'), |
||||
'date_compare', |
||||
'lte' |
||||
); |
||||
|
||||
$form->addHtmlEditor('survey_introduction', get_lang('Description'), false); |
||||
$form->setRequired($text); |
||||
|
||||
$hideList = ''; |
||||
$maxEvents = 20; |
||||
for ($i = 1; $i <= $maxEvents; $i++) { |
||||
$name = 'time_'.$i; |
||||
$form->addDateTimePicker($name, get_lang('Time')); |
||||
if ($i > 3) { |
||||
$hideList .= "$('#date_time_wrapper_$name').parent().parent().hide();"; |
||||
} |
||||
} |
||||
|
||||
$form->addHtml('<script> |
||||
$(function() { |
||||
'.$hideList.' |
||||
var number = 3; |
||||
|
||||
$("#add_button").on("click", function() { |
||||
number++; |
||||
$("#date_time_wrapper_time_" + number).parent().parent().show(); |
||||
|
||||
}); |
||||
|
||||
$("#remove_button").on("click", function() { |
||||
if (number >= 1) { |
||||
number--; |
||||
$("#date_time_wrapper_time_" + number).parent().parent().hide(); |
||||
} |
||||
}); |
||||
}); |
||||
</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])) { |
||||
$dates[] = $values[$name]; |
||||
} |
||||
} |
||||
$questionTable = Database::get_course_table(TABLE_SURVEY_QUESTION); |
||||
$counter = 1; |
||||
if (!empty($surveyData['id'])) { |
||||
foreach ($dates as $date) { |
||||
//SurveyManager::save_question(); |
||||
$params = [ |
||||
'c_id' => api_get_course_int_id(), |
||||
'survey_id' => $surveyData['id'], |
||||
'survey_question' => $date, |
||||
'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(); |
||||
@ -0,0 +1,164 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
$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; |
||||
|
||||
if (!api_is_allowed_to_edit() || !empty($invitationcode)) { |
||||
$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']; |
||||
} |
||||
|
||||
// getting all the students of the course |
||||
if (empty($sessionId)) { |
||||
// Registered students in a course outside session. |
||||
$students = CourseManager:: get_student_list_from_course_code( |
||||
api_get_course_id(), |
||||
false, |
||||
0, |
||||
null, |
||||
null, |
||||
true |
||||
); |
||||
} else { |
||||
// Registered students in session. |
||||
$students = CourseManager:: get_student_list_from_course_code( |
||||
api_get_course_id(), |
||||
true, |
||||
$sessionId |
||||
); |
||||
} |
||||
|
||||
$surveyData = SurveyManager::get_survey($surveyId); |
||||
|
||||
if (empty($surveyData)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$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'), |
||||
]; |
||||
|
||||
$template = new Template(); |
||||
|
||||
$questions = SurveyManager::get_questions($surveyData['iid']); |
||||
|
||||
$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; |
||||
$table->setHeaderContents($row, $column, api_get_local_time($item['question'])); |
||||
$column++; |
||||
} |
||||
|
||||
$row = 1; |
||||
$column = 0; |
||||
foreach ($students as $student) { |
||||
$name = api_get_person_name($student['firstname'], $student['lastname']); |
||||
$studentId = $student['user_id']; |
||||
if ($userId == $studentId) { |
||||
$rowColumn = 1; |
||||
foreach ($questions as $item) { |
||||
$checked = ''; |
||||
if (isset($answerList[$item['question_id']][$studentId])) { |
||||
$checked = 'checked'; |
||||
} |
||||
|
||||
$table->setHeaderContents( |
||||
$row, |
||||
$rowColumn, |
||||
'<input id="'.$item['question_id'].'" class="question" '.$checked.' type="checkbox"/>' |
||||
); |
||||
$rowColumn++; |
||||
} |
||||
} else { |
||||
$rowColumn = 1; |
||||
foreach ($questions as $item) { |
||||
$checked = ''; |
||||
if (isset($answerList[$item['question_id']][$studentId])) { |
||||
$checked = Display::return_icon('check-circle.png'); |
||||
} |
||||
$table->setHeaderContents( |
||||
$row, |
||||
$rowColumn, |
||||
$checked |
||||
); |
||||
$rowColumn++; |
||||
} |
||||
} |
||||
$column = 0; |
||||
$table->setCellContents($row, $column, $name); |
||||
$class = 'class="row_odd"'; |
||||
if ($row % 2) { |
||||
$class = 'class="row_even"'; |
||||
} |
||||
//$table->setRowAttributes($row, $class, true); |
||||
//$column++; |
||||
$row++; |
||||
} |
||||
|
||||
$content .= $table->toHtml(); |
||||
|
||||
$ajaxUrl = api_get_path(WEB_AJAX_PATH).'survey.ajax.php?a=save_question&'.api_get_cidreq().'&survey_id='.$surveyId.'&question_id='; |
||||
|
||||
$content .= '<script> |
||||
$(function() { |
||||
$(".question").on("change", function() { |
||||
var questionId = $(this).attr("id"); |
||||
|
||||
var status = 0; |
||||
if ($(this).prop("checked")) { |
||||
status = 1; |
||||
} |
||||
|
||||
$.ajax({ |
||||
url: "'.$ajaxUrl.'" + questionId + "&status=" + status, |
||||
success: function (data) { |
||||
return; |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
}); |
||||
</script>'; |
||||
|
||||
$template->assign('content', $content); |
||||
$template->display_one_col_template(); |
||||
Loading…
Reference in new issue