infocours.php 25 KB

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