Improving course setting creation/edition. Now the infocours.php creates a key in the database if the setting does not exists.

1.9.x
Julio Montoya 12 years ago
parent 60b4384147
commit cbadd79ee1
  1. 102
      main/course_info/infocours.php
  2. 87
      main/inc/lib/course.lib.php

@ -49,7 +49,7 @@ function is_settings_editable() {
/* MAIN CODE */
if (!$is_allowedToEdit) {
api_not_allowed(true);
api_not_allowed(true);
}
$show_delete_watermark_text_message = false;
@ -66,7 +66,9 @@ $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
// Get all course categories
$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' OR code = '".Database::escape_string($_course['categoryCode'])."' ORDER BY tree_pos";
$sql = "SELECT code,name FROM ".$table_course_category."
WHERE auth_course_child ='TRUE' OR code = '".Database::escape_string($_course['categoryCode'])."'
ORDER BY tree_pos";
$res = Database::query($sql);
$s_select_course_tutor_name = "SELECT tutor_name FROM $tbl_course WHERE code='$course_code'";
@ -74,11 +76,15 @@ $q_tutor = Database::query($s_select_course_tutor_name);
$s_tutor = Database::result($q_tutor, 0, 'tutor_name');
$target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
$s_sql_course_titular = "SELECT DISTINCT username, lastname, firstname FROM $tbl_user as user, $tbl_course_user as course_rel_user WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."' ORDER BY ".$target_name." ASC";
$s_sql_course_titular = "SELECT DISTINCT username, lastname, firstname
FROM $tbl_user as user, $tbl_course_user as course_rel_user
WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."'
ORDER BY ".$target_name." ASC";
$q_result_titulars = Database::query($s_sql_course_titular);
if (Database::num_rows($q_result_titulars) == 0) {
$sql = "SELECT username, lastname, firstname FROM $tbl_user as user, $tbl_admin as admin WHERE admin.user_id=user.user_id ORDER BY ".$target_name." ASC";
$sql = "SELECT username, lastname, firstname FROM $tbl_user as user, $tbl_admin as admin
WHERE admin.user_id=user.user_id ORDER BY ".$target_name." ASC";
$q_result_titulars = Database::query($sql);
}
@ -127,7 +133,7 @@ if ($form->validate() && is_settings_editable()) {
$course_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository; // course path
if (file_exists($course_path.'/course-pic85x85.png')) {
$course_web_path = api_get_path(WEB_COURSE_PATH).$currentCourseRepository; // course web path
$course_medium_image = $course_web_path.'/course-pic85x85.png?'.rand(1,1000); // redimensioned image 85x85
$course_medium_image = $course_web_path.'/course-pic85x85.png?'.rand(1, 1000); // redimensioned image 85x85
$image_html = '<div class="row"><div class="formw"><img src="'.$course_medium_image.'" /></div></div>';
}
$form->addElement('html', $image_html);
@ -137,19 +143,6 @@ $form->add_textfield('title', get_lang('Title'), true, array('class' => 'span6')
$form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
//$form->add_textfield('tutor_name', get_lang('Professors'), true, array ('size' => '60'));
//the teacher doesn't need to change the trainer only the admin can do that
/*
$prof = &$form->addElement('select', 'tutor_name', get_lang('Teacher'), $a_profs, array('style'=>'width:350px', 'class'=>'chzn-select', 'id'=>'tutor_name'));
$form->applyFilter('tutor_name', 'html_filter');
$prof -> setSelected($s_selected_tutor);
* /
/*$visual_code=$form->addElement('text', 'visual_code', get_lang('Code'));
$visual_code->freeze();
$form->applyFilter('visual_code', 'strtoupper');*/
$form->addElement('select', 'category_code', get_lang('Fac'), $categories, array('style'=>'width:350px', 'class'=>'chzn-select', 'id'=>'category_code'));
$form->addElement('select_language', 'course_language', array(get_lang('Ln'), get_lang('TipLang')));
@ -159,8 +152,6 @@ $form->applyFilter('department_name', 'trim');
$form->add_textfield('department_url', get_lang('DepartmentUrl'), false, array('class' => 'span5'));
$form->applyFilter('department_url', 'html_filter');
//$form->addRule('tutor_name', get_lang('ThisFieldIsRequired'), 'required');
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'));
@ -182,7 +173,7 @@ $group = array();
$group[]=$form->createElement('select_theme', 'course_theme', null, array('class'=>' ', 'id'=>'course_theme_id'));
$form->addGroup($group, '', array(get_lang("Stylesheets")), '');
$form->addElement('label', get_lang('DocumentQuota'), format_file_size(DocumentManager::get_course_quota()));
$form->addElement('label', get_lang('DocumentQuota'), format_file_size(DocumentManager::get_course_quota()));
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
@ -224,6 +215,20 @@ $form->addElement('textarea', 'legal', get_lang('CourseLegalAgreement'), array('
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
// Documents
$form->addElement('html', '<div> <h3>'.Display::return_icon('folder.png', Security::remove_XSS(get_lang('Documents')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('Documents')).'</h3><div>');
$group = array(
$form->createElement('radio', 'documents_default_visibility', get_lang('DocumentsDefaultVisibility'), get_lang('DocumentsDefaultVisibility'), 1),
$form->createElement('radio', 'documents_default_visibility', null, get_lang('Visible'), 'visible'),
$form->createElement('radio', 'documents_default_visibility', null, get_lang('Invisible'), 'invisible')
);
$form->addGroup($group, '', array(get_lang("DocumentsDefaultVisibility")), '');
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
// EMAIL NOTIFICATIONS
$form->addElement('html', '<div> <h3>'.Display::return_icon('mail.png', Security::remove_XSS(get_lang('EmailNotifications')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('EmailNotifications')).'</h3><div>');
@ -243,7 +248,6 @@ $group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', get_lan
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
$form->addGroup($group, '', array(get_lang("WorkEmailAlert")), '');
$group = array();
$group[]=$form->createElement('radio', 'email_alert_on_new_doc_dropbox', get_lang('DropboxEmailAlert'), get_lang('DropboxEmailAlertActivate'), 1);
$group[]=$form->createElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0);
@ -253,8 +257,6 @@ $group = array();
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_quiz', get_lang('QuizEmailAlert'), get_lang('QuizEmailAlertActivate'), 1);
$group[]=$form->createElement('radio', 'email_alert_manager_on_new_quiz', null, get_lang('QuizEmailAlertDeactivate'), 0);
$form->addGroup($group, '', array(get_lang("QuizEmailAlert")), '');
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
@ -285,7 +287,6 @@ $form->addGroup($group, '', array(get_lang("AllowUserViewUserList")), '');
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
// CHAT SETTINGS
$form->addElement('html', '<div><h3>'.Display::return_icon('chat.png', Security::remove_XSS(get_lang('ConfigChat')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('ConfigChat')).'</h3><div>');
@ -297,7 +298,6 @@ $form->addGroup($group, '', array(get_lang("AllowOpenchatWindow")), '');
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
// LEARNING PATH
$form->addElement('html', '<div><h3>'.Display::return_icon('scorms.png', get_lang('ConfigLearnpath'),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('ConfigLearnpath')).'</h3><div>');
@ -314,7 +314,6 @@ if (api_get_setting('allow_course_theme') == 'true') {
$group[]=$form->createElement('radio', 'allow_learning_path_theme', get_lang('AllowLearningPathTheme'), get_lang('AllowLearningPathThemeAllow'), 1);
$group[]=$form->createElement('radio', 'allow_learning_path_theme', null, get_lang('AllowLearningPathThemeDisallow'), 0);
$form->addGroup($group, '', array(get_lang("AllowLearningPathTheme")), '');
}
if (is_settings_editable()) {
@ -339,12 +338,9 @@ $group[]=$form->createElement('radio', 'display_info_advance_inside_homecourse',
$form->addGroup($group, '', array(get_lang("InfoAboutAdvanceInsideHomeCourse")), '');
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
// Certificate settings
if (api_get_setting('allow_public_certificates')=='true') {
$form->addElement('html', '<div><h3>'.Display::return_icon('certificate.png', Security::remove_XSS(get_lang('Certificates')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('Certificates')).'</h3><div>');
$group = array();
@ -356,7 +352,6 @@ if (api_get_setting('allow_public_certificates')=='true') {
$form->addElement('html', '</div></div>');
}
// Plugin course settings
$app_plugin = new AppPlugin();
@ -379,39 +374,13 @@ $values['visibility'] = $_course['visibility'];
$values['subscribe'] = $course_access_settings['subscribe'];
$values['unsubscribe'] = $course_access_settings['unsubscribe'];
$values['course_registration_password'] = $all_course_information['registration_code'];
$values['legal'] = $all_course_information['legal'];
$values['activate_legal'] = $all_course_information['activate_legal'];
// Get send_mail_setting (auth)from table
$values['email_alert_to_teacher_on_new_user_in_course']= api_get_course_setting('email_alert_to_teacher_on_new_user_in_course');
// Get send_mail_setting (work)from table
$values['email_alert_manager_on_new_doc'] = api_get_course_setting('email_alert_manager_on_new_doc');
// Get send_mail_setting (dropbox) from table
$values['email_alert_on_new_doc_dropbox'] = api_get_course_setting('email_alert_on_new_doc_dropbox');
// Get send_mail_setting (work)from table
$values['email_alert_manager_on_new_quiz'] = api_get_course_setting('email_alert_manager_on_new_quiz');
// Get allow_user_edit_agenda from table
$values['allow_user_edit_agenda'] = api_get_course_setting('allow_user_edit_agenda');
// Get allow_user_edit_announcement from table
$values['allow_user_edit_announcement'] = api_get_course_setting('allow_user_edit_announcement');
// Get allow_user_image_forum from table
$values['allow_user_image_forum'] = api_get_course_setting('allow_user_image_forum');
// Get allow_open_chat_window from table
$values['allow_open_chat_window'] = api_get_course_setting('allow_open_chat_window');
// Get course_theme from table
$values['course_theme'] = api_get_course_setting('course_theme');
// Get allow_learning_path_theme from table
$values['allow_learning_path_theme'] = api_get_course_setting('allow_learning_path_theme');
//Get allow show user list
$values['allow_user_view_user_list'] = api_get_course_setting('allow_user_view_user_list');
//Get allow show user list
$values['display_info_advance_inside_homecourse'] = api_get_course_setting('display_info_advance_inside_homecourse');
$values['email_alert_students_on_new_homework'] = api_get_course_setting('email_alert_students_on_new_homework');
$values['enable_lp_auto_launch'] = api_get_course_setting('enable_lp_auto_launch');
$values['pdf_export_watermark_text'] = api_get_course_setting('pdf_export_watermark_text');
$values['allow_public_certificates'] = api_get_course_setting('allow_public_certificates');
$courseSettings = CourseManager::getCourseSettingVariables();
foreach ($courseSettings as $setting) {
$values[$setting] = api_get_course_setting($setting);
}
$app_plugin->set_course_settings_defaults($values);
@ -452,14 +421,13 @@ if ($form->validate() && is_settings_editable()) {
WHERE code = '".$course_code."'";
Database::query($sql);
// Update course_settings table - this assumes those records exist, otherwise triggers an error
$table_course_setting = Database::get_course_table(TABLE_COURSE_SETTING);
foreach ($update_values as $key =>$value) {
//We do not update variables that were already saved in the TABLE_MAIN_COURSE table
if (!in_array($key, $update_in_course_table)) {
Database::update($table_course_setting, array('value' => $update_values[$key]), array('variable = ? AND c_id = ?' => array($key, api_get_course_int_id())));
// Insert/Updates course_settings table
foreach ($courseSettings as $setting) {
if (isset($update_values[$setting])) {
CourseManager::saveCourseConfigurationSetting($setting, $update_values[$setting], api_get_course_int_id());
}
}
$app_plugin->save_course_settings($update_values);
$cidReset = true;
$cidReq = $course_code;

@ -4085,4 +4085,91 @@ class CourseManager {
}
}
}
/**
* Course available settings variables see c_course_setting table
* @return array
*/
public static function getCourseSettingVariables()
{
return array(
// Get allow_learning_path_theme from table
'allow_learning_path_theme',
// Get allow_open_chat_window from table
'allow_open_chat_window',
'allow_public_certificates',
// Get allow_user_edit_agenda from table
'allow_user_edit_agenda',
// Get allow_user_edit_announcement from table
'allow_user_edit_announcement',
// Get allow_user_image_forum from table
'allow_user_image_forum',
//Get allow show user list
'allow_user_view_user_list',
// Get course_theme from table
'course_theme',
//Get allow show user list
'display_info_advance_inside_homecourse',
'documents_default_visibility',
// Get send_mail_setting (work)from table
'email_alert_manager_on_new_doc',
// Get send_mail_setting (work)from table
'email_alert_manager_on_new_quiz',
// Get send_mail_setting (dropbox) from table
'email_alert_on_new_doc_dropbox',
'email_alert_students_on_new_homework',
// Get send_mail_setting (auth)from table
'email_alert_to_teacher_on_new_user_in_course',
'enable_lp_auto_launch',
'pdf_export_watermark_text'
);
}
/**
* @param string $variable
* @param string $value
* @param int $courseId
* @return bool
*/
public static function saveCourseConfigurationSetting($variable, $value, $courseId)
{
$settingList = self::getCourseSettingVariables();
if (!in_array($variable, $settingList)) {
return false;
}
$courseSettingTable = Database::get_course_table(TABLE_COURSE_SETTING);
if (self::hasCourseSetting($variable, $courseId)) {
// Update
Database::update(
$courseSettingTable,
array('value' => $value),
array('variable = ? AND c_id = ?' => array($variable, $courseId))
);
} else {
// Create
Database::insert(
$courseSettingTable,
array('value' => $value, 'c_id' => $courseId, 'variable' => $variable)
);
}
return true;
}
/**
* Check if course setting exists
* @param string $variable
* @param int $courseId
* @return bool
*/
public static function hasCourseSetting($variable, $courseId)
{
$courseSetting = Database::get_course_table(TABLE_COURSE_SETTING);
$courseId = intval($courseId);
$variable = Database::escape_string($variable);
$sql = "SELECT variable FROM $courseSetting WHERE c_id = $courseId AND variable = '$variable'";
$result = Database::query($sql);
return Database::num_rows($result) > 0;
}
}

Loading…
Cancel
Save