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