infocours.php 26 KB

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