infocours.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code to display the course settings form (for the course admin)
  5. * and activate the changes.
  6. *
  7. * @author Patrick Cool <patrick.cool@UGent.be>
  8. * @author Roan Embrechts, refactoring and improved course visibility|subscribe|unsubscribe options
  9. * @author Julio Montoya <gugli100@gmail.com> Jquery support + lots of fixes
  10. * @package chamilo.course_info
  11. */
  12. /* INIT SECTION */
  13. use \ChamiloSession as Session;
  14. // Language files that need to be included
  15. $language_file = array('create_course', 'course_info', 'admin', 'gradebook', 'document');
  16. require_once '../inc/global.inc.php';
  17. $current_course_tool = TOOL_COURSE_SETTING;
  18. $this_section = SECTION_COURSES;
  19. $nameTools = get_lang('ModifInfo');
  20. api_protect_course_script(true);
  21. api_block_anonymous_users();
  22. /* Constants and variables */
  23. define('MODULE_HELP_NAME', 'Settings');
  24. define('COURSE_CHANGE_PROPERTIES', 'COURSE_CHANGE_PROPERTIES');
  25. $currentCourseRepository = $_course['path'];
  26. $is_allowedToEdit = api_is_course_admin() || api_is_platform_admin();
  27. $course_code = api_get_course_id();
  28. $_course = api_get_course_info($course_code);
  29. $courseId = api_get_course_int_id();
  30. $course_access_settings = CourseManager :: get_access_settings($course_code);
  31. //LOGIC FUNCTIONS
  32. function is_settings_editable() {
  33. //@todo check this setting This course_info_is_editable is defined where?
  34. //return isset($GLOBALS['course_info_is_editable']) && $GLOBALS['course_info_is_editable'];
  35. return true;
  36. }
  37. /* MAIN CODE */
  38. if (!$is_allowedToEdit) {
  39. api_not_allowed(true);
  40. }
  41. $show_delete_watermark_text_message = false;
  42. if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
  43. if (isset($_GET['delete_watermark'])) {
  44. PDF::delete_watermark($course_code);
  45. $show_delete_watermark_text_message = true;
  46. }
  47. }
  48. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  49. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  50. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  51. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  52. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  53. // Get all course categories
  54. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' OR code = '".Database::escape_string($_course['categoryCode'])."' ORDER BY tree_pos";
  55. $res = Database::query($sql);
  56. $s_select_course_tutor_name = "SELECT tutor_name FROM $tbl_course WHERE code='$course_code'";
  57. $q_tutor = Database::query($s_select_course_tutor_name);
  58. $s_tutor = Database::result($q_tutor, 0, 'tutor_name');
  59. $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
  60. $s_sql_course_titular = "
  61. SELECT DISTINCT username, lastname, firstname
  62. FROM $tbl_user as user, $tbl_course_user as course_rel_user
  63. WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND c_id ='".$courseId."'
  64. ORDER BY ".$target_name." ASC";
  65. $q_result_titulars = Database::query($s_sql_course_titular);
  66. if (Database::num_rows($q_result_titulars) == 0) {
  67. $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";
  68. $q_result_titulars = Database::query($sql);
  69. }
  70. $a_profs[0] = '-- '.get_lang('NoManager').' --';
  71. while ($a_titulars = Database::fetch_array($q_result_titulars)) {
  72. $s_username = $a_titulars['username'];
  73. $s_lastname = $a_titulars['lastname'];
  74. $s_firstname = $a_titulars['firstname'];
  75. if (api_get_person_name($s_firstname, $s_lastname) == $s_tutor) {
  76. $s_selected_tutor = api_get_person_name($s_firstname, $s_lastname);
  77. }
  78. $s_disabled_select_titular = '';
  79. if (!api_is_course_admin()) {
  80. $s_disabled_select_titular = 'disabled=disabled';
  81. }
  82. $a_profs[api_get_person_name($s_firstname, $s_lastname)] = api_get_person_name($s_lastname, $s_firstname).' ('.$s_username.')';
  83. }
  84. $categories[''] = '-';
  85. while ($cat = Database::fetch_array($res)) {
  86. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  87. ksort($categories);
  88. }
  89. $linebreak = '<div class="row"><div class="label"></div><div class="formw" style="border-bottom:1px dashed grey"></div></div>';
  90. // Build the form
  91. $form = new FormValidator('update_course', 'post', api_get_self().'?'.api_get_cidreq());
  92. // COURSE SETTINGS
  93. $form->addElement('html', '<div><h3>'.Display::return_icon('settings.png', Security::remove_XSS(get_lang('CourseSettings')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('CourseSettings')).'</h3><div>');
  94. $image_html = '';
  95. // Sending image
  96. if ($form->validate() && is_settings_editable()) {
  97. // update course picture
  98. $picture = $_FILES['picture'];
  99. if (!empty($picture['name'])) {
  100. $picture_uri = CourseManager::update_course_picture($course_code, $picture['name'], $picture['tmp_name']);
  101. }
  102. }
  103. // Display course picture
  104. $course_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository; // course path
  105. if (file_exists($course_path.'/course-pic85x85.png')) {
  106. $course_web_path = api_get_path(WEB_COURSE_PATH).$currentCourseRepository; // course web path
  107. $course_medium_image = $course_web_path.'/course-pic85x85.png?'.rand(1,1000); // redimensioned image 85x85
  108. $image_html = '<div class="row"><div class="formw"><img src="'.$course_medium_image.'" /></div></div>';
  109. }
  110. $form->addElement('html', $image_html);
  111. $form->add_textfield('title', get_lang('Title'), true, array('class' => 'span6'));
  112. $form->applyFilter('title', 'html_filter');
  113. $form->applyFilter('title', 'trim');
  114. //$form->add_textfield('tutor_name', get_lang('Professors'), true, array ('size' => '60'));
  115. //the teacher doesn't need to change the trainer only the admin can do that
  116. /*
  117. $prof = &$form->addElement('select', 'tutor_name', get_lang('Teacher'), $a_profs, array('style'=>'width:350px', 'class'=>'chzn-select', 'id'=>'tutor_name'));
  118. $form->applyFilter('tutor_name', 'html_filter');
  119. $prof -> setSelected($s_selected_tutor);
  120. * /
  121. /*$visual_code=$form->addElement('text', 'visual_code', get_lang('Code'));
  122. $visual_code->freeze();
  123. $form->applyFilter('visual_code', 'strtoupper');*/
  124. $form->addElement('select', 'category_code', get_lang('Fac'), $categories, array('style'=>'width:350px', 'class'=>'chzn-select', 'id'=>'category_code'));
  125. $form->addElement('select_language', 'course_language', array(get_lang('Ln'), get_lang('TipLang')));
  126. $form->add_textfield('department_name', get_lang('Department'), false, array('class' => 'span5'));
  127. $form->applyFilter('department_name', 'html_filter');
  128. $form->applyFilter('department_name', 'trim');
  129. $form->add_textfield('department_url', get_lang('DepartmentUrl'), false, array('class' => 'span5'));
  130. $form->applyFilter('department_url', 'html_filter');
  131. //$form->addRule('tutor_name', get_lang('ThisFieldIsRequired'), 'required');
  132. // Picture
  133. $form->addElement('file', 'picture', get_lang('AddPicture'));
  134. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  135. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  136. if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
  137. $url = PDF::get_watermark($course_code);
  138. $form->add_textfield('pdf_export_watermark_text', get_lang('PDFExportWatermarkTextTitle'), false, array('size' => '60'));
  139. $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
  140. if ($url != false) {
  141. $delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.png',get_lang('DelImage')).'</a>';
  142. $form->addElement('html', '<div class="row"><div class="formw"><a href="'.$url.'">'.$url.' '.$delete_url.'</a></div></div>');
  143. }
  144. $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  145. }
  146. $group = array();
  147. $group[]=$form->createElement('select_theme', 'course_theme', null, array('class'=>' ', 'id'=>'course_theme_id'));
  148. $form->addGroup($group, '', array(get_lang("Stylesheets")), '');
  149. $form->addElement('label', get_lang('DocumentQuota'), Text::format_file_size(DocumentManager::get_course_quota()));
  150. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  151. $form->addElement('html', '</div></div>');
  152. // COURSE ACCESS
  153. $form->addElement('html', '<div> <h3>'.Display::return_icon('course.png', Security::remove_XSS(get_lang('CourseAccess')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('CourseAccess')).'</h3><div>');
  154. $group = array();
  155. $group[]= $form->createElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  156. $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  157. $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  158. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  159. // The "hidden" visibility is only available to portal admins
  160. if (api_is_platform_admin()) {
  161. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
  162. }
  163. $form->addGroup($group, '', array(get_lang("CourseAccess"), get_lang("CourseAccessConfigTip")), '');
  164. $url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1";
  165. $url = Display::url($url, $url);
  166. $form->addElement('label', get_lang('DirectLink'), sprintf(get_lang('CourseSettingsRegisterDirectLink'), $url));
  167. $group = array();
  168. $group[]=$form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  169. $group[]=$form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  170. $form->addGroup($group, '', array(get_lang("Subscription")), '');
  171. $group = array();
  172. $group[]=$form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  173. $group[]=$form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  174. $form->addGroup($group, '', array(get_lang("Unsubscription")), '');
  175. $form->add_textfield('course_registration_password', get_lang('CourseRegistrationPassword'), false, array('size' => '60'));
  176. $form->addElement('checkbox', 'activate_legal', array(null, get_lang('ShowALegalNoticeWhenEnteringTheCourse')), get_lang('ActivateLegal'));
  177. $form->addElement('textarea', 'legal', get_lang('CourseLegalAgreement'), array('class'=>'span6', 'rows' => 8));
  178. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  179. $form->addElement('html', '</div></div>');
  180. // EMAIL NOTIFICATIONS
  181. $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>');
  182. $group = array();
  183. $group[]=$form->createElement('radio', 'email_alert_to_teacher_on_new_user_in_course', get_lang('NewUserEmailAlert'), get_lang('NewUserEmailAlertEnable'), 1);
  184. $group[]=$form->createElement('radio', 'email_alert_to_teacher_on_new_user_in_course', null, get_lang('NewUserEmailAlertToTeacharAndTutor'), 2);
  185. $group[]=$form->createElement('radio', 'email_alert_to_teacher_on_new_user_in_course', null, get_lang('NewUserEmailAlertDisable'), 0);
  186. $form->addGroup($group, '', array(Display::return_icon('user.png', get_lang('NewUserEmailAlert'))));
  187. $group = array();
  188. $group[]=$form->createElement('radio', 'email_alert_students_on_new_homework', get_lang('NewHomeworkEmailAlert'), get_lang('NewHomeworkEmailAlertEnable'), 1);
  189. $group[]=$form->createElement('radio', 'email_alert_students_on_new_homework', null, get_lang('NewHomeworkEmailAlertDisable'), 0);
  190. $form->addGroup($group, '', array(Display::return_icon('work.png', get_lang("NewHomeworkEmailAlert"))));
  191. $group = array();
  192. $group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', get_lang('WorkEmailAlert'), get_lang('WorkEmailAlertActivate'), 1);
  193. $group[]=$form->createElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
  194. $form->addGroup($group, '', array(Display::return_icon('work.png', get_lang("WorkEmailAlert"))));
  195. $group = array();
  196. $group[]=$form->createElement('radio', 'email_alert_on_new_doc_dropbox', get_lang('DropboxEmailAlert'), get_lang('DropboxEmailAlertActivate'), 1);
  197. $group[]=$form->createElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0);
  198. $form->addGroup($group, '', array(Display::return_icon('dropbox.png', get_lang("DropboxEmailAlert"))));
  199. $group = array();
  200. $group[]=$form->createElement('radio', 'email_alert_manager_on_new_quiz', get_lang('QuizEmailAlert'), get_lang('QuizEmailAlertActivate'), 1);
  201. $group[]=$form->createElement('radio', 'email_alert_manager_on_new_quiz', null, get_lang('QuizEmailAlertDeactivate'), 0);
  202. $form->addGroup($group, '', array(Display::return_icon('quiz.png', get_lang("QuizEmailAlert"))));
  203. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  204. $form->addElement('html', '</div></div>');
  205. // USER RIGHTS
  206. $form->addElement('html', '<div><h3>'.Display::return_icon('user.png', Security::remove_XSS(get_lang('UserRights')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('UserRights')).'</h3><div>');
  207. $group = array();
  208. $group[]=$form->createElement('radio', 'allow_user_edit_agenda', get_lang('AllowUserEditAgenda'), get_lang('AllowUserEditAgendaActivate'), 1);
  209. $group[]=$form->createElement('radio', 'allow_user_edit_agenda', null, get_lang('AllowUserEditAgendaDeactivate'), 0);
  210. $form->addGroup($group, '', array(get_lang("AllowUserEditAgenda")), '');
  211. $group = array();
  212. $group[]=$form->createElement('radio', 'allow_user_edit_announcement', get_lang('AllowUserEditAnnouncement'), get_lang('AllowUserEditAnnouncementActivate'), 1);
  213. $group[]=$form->createElement('radio', 'allow_user_edit_announcement', null, get_lang('AllowUserEditAnnouncementDeactivate'), 0);
  214. $form->addGroup($group, '', array(get_lang("AllowUserEditAnnouncement")), '');
  215. $group = array();
  216. $group[]=$form->createElement('radio', 'allow_user_image_forum', get_lang('AllowUserImageForum'), get_lang('AllowUserImageForumActivate'), 1);
  217. $group[]=$form->createElement('radio', 'allow_user_image_forum', null, get_lang('AllowUserImageForumDeactivate'), 0);
  218. $form->addGroup($group, '', array(get_lang("AllowUserImageForum")), '');
  219. $group = array();
  220. $group[]=$form->createElement('radio', 'allow_user_view_user_list', get_lang('AllowUserViewUserList'), get_lang('AllowUserViewUserListActivate'), 1);
  221. $group[]=$form->createElement('radio', 'allow_user_view_user_list', null, get_lang('AllowUserViewUserListDeactivate'), 0);
  222. $form->addGroup($group, '', array(get_lang("AllowUserViewUserList")), '');
  223. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  224. $form->addElement('html', '</div></div>');
  225. // CHAT SETTINGS
  226. $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>');
  227. $group = array();
  228. $group[]=$form->createElement('radio', 'allow_open_chat_window', get_lang('AllowOpenchatWindow'), get_lang('AllowOpenChatWindowActivate'), 1);
  229. $group[]=$form->createElement('radio', 'allow_open_chat_window', null, get_lang('AllowOpenChatWindowDeactivate'), 0);
  230. $form->addGroup($group, '', array(get_lang("AllowOpenchatWindow")), '');
  231. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  232. $form->addElement('html', '</div></div>');
  233. // LEARNING PATH
  234. $form->addElement('html', '<div><h3>'.Display::return_icon('scorms.png', get_lang('ConfigLearnpath'),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('ConfigLearnpath')).'</h3><div>');
  235. //Auto launch LP
  236. $group = array();
  237. $group[]=$form->createElement('radio', 'enable_lp_auto_launch', get_lang('LPAutoLaunch'), get_lang('RedirectToALearningPath'), 1);
  238. $group[]=$form->createElement('radio', 'enable_lp_auto_launch', get_lang('LPAutoLaunch'), get_lang('RedirectToTheLearningPathList'), 2);
  239. $group[]=$form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0);
  240. $form->addGroup($group, '', array(get_lang("LPAutoLaunch")), '');
  241. if (api_get_setting('allow_course_theme') == 'true') {
  242. // Allow theme into Learning path
  243. $group = array();
  244. $group[]=$form->createElement('radio', 'allow_learning_path_theme', get_lang('AllowLearningPathTheme'), get_lang('AllowLearningPathThemeAllow'), 1);
  245. $group[]=$form->createElement('radio', 'allow_learning_path_theme', null, get_lang('AllowLearningPathThemeDisallow'), 0);
  246. $form->addGroup($group, '', array(get_lang("AllowLearningPathTheme")), '');
  247. }
  248. if (is_settings_editable()) {
  249. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  250. } else {
  251. // Is it allowed to edit the course settings?
  252. if (!is_settings_editable()) {
  253. $disabled_output = "disabled";
  254. }
  255. $form->freeze();
  256. }
  257. $form->addElement('html', '</div></div>');
  258. //Exercise
  259. $form->addElement('html', '<div><h3>'.Display::return_icon('quiz.png', Security::remove_XSS(get_lang('Exercises')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('Exercises')).'</h3><div>');
  260. $group = array();
  261. $group[]=$form->createElement('radio', 'allow_fast_exercise_edition', get_lang('AllowFastExerciseEdition'), get_lang('Yes'), 1);
  262. $group[]=$form->createElement('radio', 'allow_fast_exercise_edition', get_lang('AllowFastExerciseEdition'), get_lang('No'), 0);
  263. $form->addGroup($group, '', array(get_lang("AllowFastExerciseEdition")), '');
  264. //Auto-launch Exercise LP
  265. $group = array();
  266. $group[]=$form->createElement('radio', 'enable_exercise_auto_launch', get_lang('ExerciseAutoLaunch'), get_lang('RedirectToExercise'), 1);
  267. $group[]=$form->createElement('radio', 'enable_exercise_auto_launch', get_lang('ExerciseAutoLaunch'), get_lang('RedirectToTheExerciseList'), 2);
  268. $group[]=$form->createElement('radio', 'enable_exercise_auto_launch', null, get_lang('Deactivate'), 0);
  269. $form->addGroup($group, '', array(get_lang("ExerciseAutoLaunch")), '');
  270. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  271. $form->addElement('html', '</div></div>');
  272. // THEMATIC ADVANCE SETTINGS
  273. $form->addElement('html', '<div><h3>'.Display::return_icon('course_progress.png', Security::remove_XSS(get_lang('ThematicAdvanceConfiguration')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('ThematicAdvanceConfiguration')).'</h3><div>');
  274. $group = array();
  275. $group[]=$form->createElement('radio', 'display_info_advance_inside_homecourse', get_lang('InfoAboutAdvanceInsideHomeCourse'), get_lang('DisplayAboutLastDoneAdvance'), 1);
  276. $group[]=$form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDone'), 2);
  277. $group[]=$form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'), 3);
  278. $group[]=$form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DoNotDisplayAnyAdvance'), 0);
  279. $form->addGroup($group, '', array(get_lang("InfoAboutAdvanceInsideHomeCourse")), '');
  280. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  281. $form->addElement('html', '</div></div>');
  282. // Certificate settings
  283. if (api_get_setting('allow_public_certificates')=='true') {
  284. $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>');
  285. $group = array();
  286. $group[]=$form->createElement('radio', 'allow_public_certificates', get_lang('AllowPublicCertificates'), get_lang('Yes'), 1);
  287. $group[]=$form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0);
  288. $form->addGroup($group, '', array(get_lang("AllowPublicCertificates")), '');
  289. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  290. $form->addElement('html', '</div></div>');
  291. }
  292. // Plugin course settings
  293. $app_plugin = new AppPlugin();
  294. $app_plugin->add_course_settings_form($form);
  295. // Get all the course information
  296. $all_course_information = CourseManager::get_course_information($_course['sysCode']);
  297. // Set the default values of the form
  298. $values = array();
  299. $values['title'] = $_course['name'];
  300. $values['category_code'] = $_course['categoryCode'];
  301. $values['course_language'] = $_course['language'];
  302. $values['department_name'] = $_course['extLink']['name'];
  303. $values['department_url'] = $_course['extLink']['url'];
  304. $values['visibility'] = $_course['visibility'];
  305. $values['subscribe'] = $course_access_settings['subscribe'];
  306. $values['unsubscribe'] = $course_access_settings['unsubscribe'];
  307. $values['course_registration_password'] = $all_course_information['registration_code'];
  308. $values['legal'] = $all_course_information['legal'];
  309. $values['activate_legal'] = $all_course_information['activate_legal'];
  310. // Get send_mail_setting (auth)from table
  311. $values['email_alert_to_teacher_on_new_user_in_course'] = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course');
  312. // Get send_mail_setting (work)from table
  313. $values['email_alert_manager_on_new_doc'] = api_get_course_setting('email_alert_manager_on_new_doc');
  314. // Get send_mail_setting (dropbox) from table
  315. $values['email_alert_on_new_doc_dropbox'] = api_get_course_setting('email_alert_on_new_doc_dropbox');
  316. // Get send_mail_setting (work)from table
  317. $values['email_alert_manager_on_new_quiz'] = api_get_course_setting('email_alert_manager_on_new_quiz');
  318. // Get allow_user_edit_agenda from table
  319. $values['allow_user_edit_agenda'] = api_get_course_setting('allow_user_edit_agenda');
  320. // Get allow_user_edit_announcement from table
  321. $values['allow_user_edit_announcement'] = api_get_course_setting('allow_user_edit_announcement');
  322. // Get allow_user_image_forum from table
  323. $values['allow_user_image_forum'] = api_get_course_setting('allow_user_image_forum');
  324. // Get allow_open_chat_window from table
  325. $values['allow_open_chat_window'] = api_get_course_setting('allow_open_chat_window');
  326. // Get course_theme from table
  327. $values['course_theme'] = api_get_course_setting('course_theme');
  328. // Get allow_learning_path_theme from table
  329. $values['allow_learning_path_theme'] = api_get_course_setting('allow_learning_path_theme');
  330. //Get allow show user list
  331. $values['allow_user_view_user_list'] = api_get_course_setting('allow_user_view_user_list');
  332. //Get allow show user list
  333. $values['display_info_advance_inside_homecourse'] = api_get_course_setting('display_info_advance_inside_homecourse');
  334. $values['email_alert_students_on_new_homework'] = api_get_course_setting('email_alert_students_on_new_homework');
  335. $values['enable_lp_auto_launch'] = api_get_course_setting('enable_lp_auto_launch');
  336. $values['pdf_export_watermark_text'] = api_get_course_setting('pdf_export_watermark_text');
  337. $values['allow_public_certificates'] = api_get_course_setting('allow_public_certificates');
  338. $values['allow_fast_exercise_edition'] = api_get_course_setting('allow_fast_exercise_edition') == 1 ? 1 : 0;
  339. $values['enable_exercise_auto_launch'] = api_get_course_setting('enable_exercise_auto_launch') == -1 ? 0 : api_get_course_setting('enable_exercise_auto_launch') ;
  340. $app_plugin->set_course_settings_defaults($values);
  341. $form->setDefaults($values);
  342. // Validate form
  343. if ($form->validate() && is_settings_editable()) {
  344. $update_values = $form->exportValues();
  345. $pdf_export_watermark_path = isset($_FILES['pdf_export_watermark_path']) ? $_FILES['pdf_export_watermark_path'] : null;
  346. if (!empty($pdf_export_watermark_path['name'])) {
  347. $pdf_export_watermark_path_result = PDF::upload_watermark($pdf_export_watermark_path['name'], $pdf_export_watermark_path['tmp_name'], $course_code);
  348. unset($update_values['pdf_export_watermark_path']);
  349. }
  350. //Variables that will be saved in the TABLE_MAIN_COURSE table
  351. $update_in_course_table = array(
  352. 'title', 'course_language','category_code','department_name', 'department_url','visibility',
  353. 'subscribe', 'unsubscribe','tutor_name','course_registration_password', 'legal', 'activate_legal'
  354. );
  355. foreach ($update_values as $index => $value) {
  356. $update_values[$index] = Database::escape_string($value);
  357. }
  358. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  359. $sql = "UPDATE $table_course SET
  360. title = '".$update_values['title']."',
  361. course_language = '".$update_values['course_language']."',
  362. category_code = '".$update_values['category_code']."',
  363. department_name = '".$update_values['department_name']."',
  364. department_url = '".$update_values['department_url']."',
  365. visibility = '".$update_values['visibility']."',
  366. subscribe = '".$update_values['subscribe']."',
  367. unsubscribe = '".$update_values['unsubscribe']."',
  368. legal = '".$update_values['legal']."',".
  369. (isset($update_values['activate_legal'])?" activate_legal = '".$update_values['activate_legal']."',":'').
  370. " registration_code = '".$update_values['course_registration_password']."'
  371. WHERE code = '".$course_code."'";
  372. Database::query($sql);
  373. // Update course_settings table - this assumes those records exist, otherwise triggers an error
  374. $table_course_setting = Database::get_course_table(TABLE_COURSE_SETTING);
  375. foreach ($update_values as $key => $value) {
  376. //We do not update variables that were already saved in the TABLE_MAIN_COURSE table
  377. if (!in_array($key, $update_in_course_table)) {
  378. $data = api_get_course_setting($key);
  379. //Setting does not exist we create one!
  380. if ($data == -1 && isset($values[$key])) {
  381. // @todo create a api_set_course_setting
  382. //api_set_course_setting()
  383. //api_set_setting($key, $update_values[$key], null, null, api_get_current_access_url_id());
  384. $params = array(
  385. 'c_id' => api_get_course_int_id(),
  386. 'variable' => $key,
  387. 'value' => $update_values[$key]
  388. );
  389. Database::insert($table_course_setting, $params);
  390. } else {
  391. Database::update($table_course_setting, array('value' => $update_values[$key]), array('variable = ? AND c_id = ?' => array($key, api_get_course_int_id())));
  392. }
  393. }
  394. }
  395. $app_plugin->save_course_settings($update_values);
  396. $courseInfo = api_get_course_info($course_code);
  397. Session::write('_course', $courseInfo);
  398. header('Location: infocours.php?action=show_message&cidReq='.$course_code);
  399. exit;
  400. }
  401. /* Header */
  402. Display :: display_header($nameTools, MODULE_HELP_NAME);
  403. if ($show_delete_watermark_text_message) {
  404. Display :: display_normal_message(get_lang('FileDeleted'));
  405. }
  406. //api_display_tool_title($nameTools);
  407. if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
  408. Display :: display_normal_message(get_lang('ModifDone'));
  409. }
  410. echo '<script>
  411. $(function() {
  412. $("#course_settings").accordion({
  413. autoHeight: false,
  414. header: "div > h3"
  415. });
  416. });
  417. </script>';
  418. // Display the form
  419. echo '<div id="course_settings">';
  420. $form->display();
  421. echo '</div>';
  422. Display::display_footer();