Add auto launch settings for documents and exercises see BT#14251

- configuration "allow_exercise_auto_launch" requires DB change
pull/2539/head
jmontoyaa 7 years ago
parent a9a8d507be
commit 90ea4936eb
  1. 93
      main/course_home/course_home.php
  2. 114
      main/course_info/infocours.php
  3. 32
      main/exercise/exercise.class.php
  4. 43
      main/exercise/exercise.php
  5. 2
      main/inc/lib/add_course.lib.inc.php
  6. 2
      main/inc/lib/course.lib.php
  7. 4
      main/install/configuration.dist.php

@ -169,13 +169,17 @@ if (!isset($coursesAlreadyVisited[$course_code])) {
}
/*Auto launch code */
$show_autolaunch_lp_warning = false;
$auto_launch = api_get_course_setting('enable_lp_auto_launch');
$autoLaunchWarning = '';
$showAutoLaunchLpWarning = false;
$course_id = api_get_course_int_id();
$lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
$session_id = api_get_session_id();
if (!empty($auto_launch)) {
if ($auto_launch == 2) { //LP list
if (!empty($lpAutoLaunch)) {
if ($lpAutoLaunch == 2) {
// LP list
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$show_autolaunch_lp_warning = true;
$showAutoLaunchLpWarning = true;
} else {
$session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
if (!isset($_SESSION[$session_key])) {
@ -188,7 +192,6 @@ if (!empty($auto_launch)) {
}
} else {
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$course_id = api_get_course_int_id();
$condition = '';
if (!empty($session_id)) {
$condition = api_get_session_condition($session_id);
@ -210,7 +213,7 @@ if (!empty($auto_launch)) {
$lp_data = Database::fetch_array($result, 'ASSOC');
if (!empty($lp_data['id'])) {
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
$show_autolaunch_lp_warning = true;
$showAutoLaunchLpWarning = true;
} else {
$session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
if (!isset($_SESSION[$session_key])) {
@ -227,22 +230,76 @@ if (!empty($auto_launch)) {
}
}
if ($showAutoLaunchLpWarning) {
$autoLaunchWarning = get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP');
}
$forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
if ($forumAutoLaunch == 1) {
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
Display::addFlash(Display::return_message(
get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool'),
'warning'
));
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool');
}
} else {
//$forumKey = 'forum_auto_launch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
//if (!isset($_SESSION[$forumKey])) {
//redirecting to the LP
$url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
// $_SESSION[$forumKey] = true;
header("Location: $url");
exit;
//}
}
}
if (api_get_configuration_value('allow_exercise_auto_launch')) {
$exerciseAutoLaunch = (int)api_get_course_setting('enable_exercise_auto_launch');
if ($exerciseAutoLaunch == 2) {
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang(
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
);
}
} else {
// Redirecting to the document
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&id_session='.$session_id;
header("Location: $url");
exit;
}
} elseif ($exerciseAutoLaunch == 1) {
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang(
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
);
}
} else {
// Redirecting to an exercise
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$sessionCondition = api_get_session_condition($session_id, true);
$sql = "SELECT iid FROM $table
WHERE c_id = $course_id AND autolaunch = 1 $sessionCondition
LIMIT 1";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result, 'ASSOC');
$exerciseId = $row['iid'];
$url = api_get_path(WEB_CODE_PATH).
'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&id_session='.$session_id;
header("Location: $url");
exit;
}
}
}
}
$documentAutoLaunch = api_get_course_setting('enable_document_auto_launch');
if ($documentAutoLaunch == 1) {
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
if (empty($autoLaunchWarning)) {
$autoLaunchWarning = get_lang('TheDocumentAutoLaunchSettingIsOnStudentsWillBeRedirectToTheDocumentTool');
}
} else {
// Redirecting to the document
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id_session='.$session_id;
header("Location: $url");
exit;
}
}
@ -266,9 +323,9 @@ $content = Display::return_introduction_section(
the setting homepage_view is adjustable through
the platform administration section */
if ($show_autolaunch_lp_warning) {
if (!empty($autoLaunchWarning)) {
$show_message .= Display::return_message(
get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
$autoLaunchWarning,
'warning'
);
}

@ -283,6 +283,19 @@ $group = [
];
$form->addGroup($group, '', [get_lang('ShowSystemFolders')]);
$group = [];
$group[] = $form->createElement(
'radio',
'enable_document_auto_launch',
get_lang('DocumentAutoLaunch'),
get_lang('RedirectToTheDocumentList'),
1
);
$group[] = $form->createElement('radio', 'enable_document_auto_launch', null, get_lang('Deactivate'), 0);
$form->addGroup($group, '', [get_lang('DocumentAutoLaunch')]);
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
$form->addHtml('
</div>
@ -476,7 +489,7 @@ $group = [];
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', get_lang('LPAutoLaunch'), get_lang('RedirectToALearningPath'), 1);
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', get_lang('LPAutoLaunch'), get_lang('RedirectToTheLearningPathList'), 2);
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0);
$form->addGroup($group, '', [get_lang("LPAutoLaunch")]);
$form->addGroup($group, '', [get_lang('LPAutoLaunch')]);
if (api_get_setting('allow_course_theme') == 'true') {
// Allow theme into Learning path
@ -554,6 +567,73 @@ $form->addHtml('
');
$form->addHtml('</div>');
// Exercise
if (api_get_configuration_value('allow_exercise_auto_launch')) {
$form->addHtml('<div class="panel panel-default">');
$form->addHtml(
'
<div class="panel-heading" role="tab" id="heading-exercise">
<h4 class="panel-title">
<a class="collapsed"
role="button" data-toggle="collapse"
data-parent="#accordion"
href="#collapse-exercise" aria-expanded="false" aria-controls="collapse-exercise">
'
);
$form->addHtml(
Display::return_icon('quiz.png', get_lang('Exercise')).' '.get_lang('Exercise')
);
$form->addHtml(
'
</a>
</h4>
</div>
'
);
$form->addHtml(
'
<div id="collapse-exercise" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-exercise">
<div class="panel-body">
'
);
// Auto launch exercise
$group = [];
$group[] = $form->createElement(
'radio',
'enable_exercise_auto_launch',
get_lang('ExerciseAutoLaunch'),
get_lang('RedirectToExercise'),
1
);
$group[] = $form->createElement(
'radio',
'enable_exercise_auto_launch',
get_lang('ExerciseAutoLaunch'),
get_lang('RedirectToTheExerciseList'),
2
);
$group[] = $form->createElement('radio', 'enable_exercise_auto_launch', null, get_lang('Deactivate'), 0);
$form->addGroup($group, '', [get_lang('ExerciseAutoLaunch')]);
if (is_settings_editable()) {
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
} else {
// Is it allowed to edit the course settings?
if (!is_settings_editable()) {
$disabled_output = "disabled";
}
$form->freeze();
}
$form->addHtml(
'
</div>
</div>
'
);
$form->addHtml('</div>');
}
// THEMATIC ADVANCE SETTINGS
$form->addHtml('<div class="panel panel-default">');
$form->addHtml('
@ -578,10 +658,34 @@ $form->addHtml('
');
$group = [];
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', get_lang('InfoAboutAdvanceInsideHomeCourse'), get_lang('DisplayAboutLastDoneAdvance'), 1);
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDone'), 2);
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'), 3);
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DoNotDisplayAnyAdvance'), 0);
$group[] = $form->createElement(
'radio',
'display_info_advance_inside_homecourse',
get_lang('InfoAboutAdvanceInsideHomeCourse'),
get_lang('DisplayAboutLastDoneAdvance'),
1
);
$group[] = $form->createElement(
'radio',
'display_info_advance_inside_homecourse',
null,
get_lang('DisplayAboutNextAdvanceNotDone'),
2
);
$group[] = $form->createElement(
'radio',
'display_info_advance_inside_homecourse',
null,
get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'),
3
);
$group[] = $form->createElement(
'radio',
'display_info_advance_inside_homecourse',
null,
get_lang('DoNotDisplayAnyAdvance'),
0
);
$form->addGroup($group, '', [get_lang("InfoAboutAdvanceInsideHomeCourse")]);
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
$form->addHtml('

@ -83,6 +83,7 @@ class Exercise
public $showPreviousButton;
public $notifications;
public $export = false;
public $autolaunch;
/**
* Constructor of the class.
@ -192,6 +193,7 @@ class Exercise
$this->globalCategoryId = isset($object->global_category_id) ? $object->global_category_id : null;
$this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null;
$this->hideQuestionTitle = isset($object->hide_question_title) ? (int) $object->hide_question_title : 0;
$this->autolaunch = isset($object->autolaunch) ? (int) $object->autolaunch : 0;
$this->notifications = [];
if (!empty($object->notifications)) {
@ -8292,4 +8294,34 @@ class Exercise
{
return strip_tags(api_html_entity_decode($this->title));
}
/**
* @return int
*/
public function getAutoLaunch()
{
return $this->autolaunch;
}
/**
* Clean auto launch settings for all exercise in course/course-session
*/
public function enableAutoLaunch()
{
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "UPDATE $table SET autolaunch = 1
WHERE iid = ".$this->iId;
Database::query($sql);
}
/**
* Clean auto launch settings for all exercise in course/course-session
*/
public function cleanCourseLaunchSettings()
{
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "UPDATE $table SET autolaunch = 0
WHERE c_id = ".$this->course_id." AND session_id = ".$this->sessionId;
Database::query($sql);
}
}

@ -79,11 +79,9 @@ Session::erase('duration_time');
//General POST/GET/SESSION/COOKIES parameters recovery
$origin = api_get_origin();
$choice = isset($_REQUEST['choice']) ? Security::remove_XSS($_REQUEST['choice']) : null;
$hpchoice = isset($_REQUEST['hpchoice']) ? Security::remove_XSS($_REQUEST['hpchoice']) : null;
$exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null;
$file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) : null;
$learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : null;
@ -99,6 +97,13 @@ if (api_is_in_gradebook()) {
];
}
$autoLaunchAvailable = false;
if (api_get_course_setting('enable_exercise_auto_launch') == 1 &&
api_get_configuration_value('allow_exercise_auto_launch')
) {
$autoLaunchAvailable = true;
}
$nameTools = get_lang('Exercises');
$errorXmlExport = null;
if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
@ -205,6 +210,14 @@ if ($is_allowedToEdit) {
if ($objExerciseTmp->read($exerciseId)) {
if ($check) {
switch ($choice) {
case 'enable_launch':
$objExerciseTmp->cleanCourseLaunchSettings();
$objExerciseTmp->enableAutoLaunch();
Display::addFlash(Display::return_message(get_lang('Updated')));
break;
case 'disable_launch':
$objExerciseTmp->cleanCourseLaunchSettings();
break;
case 'delete':
// deletes an exercise
if ($exercise_action_locked == false) {
@ -756,6 +769,32 @@ if (!empty($exerciseList)) {
$actions .= '<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
// Auto launch
if ($autoLaunchAvailable) {
$autoLaunch = $exercise->getAutoLaunch();
if (empty($autoLaunch)) {
$actions .= Display::url(
Display::return_icon(
'launch_na.png',
get_lang('Enable'),
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=enable_launch&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
);
} else {
$actions .= Display::url(
Display::return_icon(
'launch.png',
get_lang('Disable'),
'',
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq().'&choice=disable_launch&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
);
}
}
// Export
$actions .= Display::url(
Display::return_icon('cd.png', get_lang('CopyExercise')),

@ -652,6 +652,8 @@ class AddCourse
'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'],
'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'],
'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'],
'enable_exercise_auto_launch' => ['default' => 0, 'category' => 'exercise'],
'enable_document_auto_launch' => ['default' => 0, 'category' => 'document'],
'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'],
'allow_public_certificates' => [
'default' => api_get_setting('allow_public_certificates') === 'true' ? 1 : '',

@ -5559,6 +5559,8 @@ class CourseManager
// Get send_mail_setting (auth)from table
'email_alert_to_teacher_on_new_user_in_course',
'enable_lp_auto_launch',
'enable_exercise_auto_launch',
'enable_document_auto_launch',
'pdf_export_watermark_text',
'show_system_folders',
'exercise_invisible_in_session',

@ -826,6 +826,10 @@ INSERT INTO settings_current(variable, subkey, type, category, selected_value, t
// Allow LP export to chamilo format (CourseBackup)
//$_configuration['allow_lp_chamilo_export'] = false;
// Allow exercise auto launch
//$_configuration['allow_exercise_auto_launch'] = false;
// ALTER TABLE c_quiz ADD autolaunch TINYINT(1) DEFAULT 0;
// ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email

Loading…
Cancel
Save