infocours.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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. *
  9. * @todo Take those config settings into account in this script
  10. *
  11. * @author Patrick Cool <patrick.cool@UGent.be>
  12. * @author Roan Embrechts, refactoring and improved course visibility|subscribe|unsubscribe options
  13. * @author Julio Montoya <gugli100@gmail.com> Jquery support + lots of fixes
  14. *
  15. * @package chamilo.course_info
  16. */
  17. require_once __DIR__.'/../inc/global.inc.php';
  18. $current_course_tool = TOOL_COURSE_SETTING;
  19. $this_section = SECTION_COURSES;
  20. $nameTools = get_lang('ModifInfo');
  21. api_protect_course_script(true);
  22. api_block_anonymous_users();
  23. $_course = api_get_course_info();
  24. /* Constants and variables */
  25. define('MODULE_HELP_NAME', 'Settings');
  26. define('COURSE_CHANGE_PROPERTIES', 'COURSE_CHANGE_PROPERTIES');
  27. $currentCourseRepository = $_course['path'];
  28. $is_allowedToEdit = api_is_course_admin() || api_is_platform_admin();
  29. $course_code = api_get_course_id();
  30. $courseId = api_get_course_int_id();
  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. $htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
  40. $htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
  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. $categories = CourseCategory::getCategoriesCanBeAddedInCourse($_course['categoryCode']);
  49. // Build the form
  50. $form = new FormValidator(
  51. 'update_course',
  52. 'post',
  53. api_get_self().'?'.api_get_cidreq()
  54. );
  55. $form->addHtml('<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">');
  56. // COURSE SETTINGS
  57. $form->addHtml('<div class="panel panel-default">');
  58. $form->addHtml('
  59. <div class="panel-heading" role="tab" id="heading-course-settings">
  60. <h4 class="panel-title">
  61. <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-course-settings"
  62. aria-expanded="true" aria-controls="collapse-course-settings">
  63. ');
  64. $form->addHtml(
  65. Display::return_icon('settings.png', get_lang('CourseSettings')).' '.get_lang('CourseSettings')
  66. );
  67. $form->addHtml('
  68. </a>
  69. </h4>
  70. </div>
  71. ');
  72. $form->addHtml('
  73. <div id="collapse-course-settings" class="panel-collapse collapse in" role="tabpanel"
  74. aria-labelledby="heading-course-settings">
  75. <div class="panel-body">
  76. ');
  77. $image = '';
  78. // Display course picture
  79. $course_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository; // course path
  80. if (file_exists($course_path.'/course-pic85x85.png')) {
  81. $course_web_path = api_get_path(WEB_COURSE_PATH).$currentCourseRepository; // course web path
  82. $course_medium_image = $course_web_path.'/course-pic85x85.png?'.rand(1, 1000); // redimensioned image 85x85
  83. $image = '<div class="row"><label class="col-md-2 control-label">'.get_lang('Image').'</label>
  84. <div class="col-md-8"><img src="'.$course_medium_image.'" /></div></div>';
  85. }
  86. $form->addHtml($image);
  87. $form->addText('title', get_lang('Title'), true);
  88. $form->applyFilter('title', 'html_filter');
  89. $form->applyFilter('title', 'trim');
  90. $form->addElement(
  91. 'select',
  92. 'category_code',
  93. get_lang('Fac'),
  94. $categories,
  95. ['style' => 'width:350px', 'id' => 'category_code']
  96. );
  97. $form->addSelectLanguage(
  98. 'course_language',
  99. [get_lang('Ln'), get_lang('TipLang')]
  100. );
  101. $group = [
  102. $form->createElement('radio', 'show_course_in_user_language', null, get_lang('Yes'), 1),
  103. $form->createElement('radio', 'show_course_in_user_language', null, get_lang('No'), 2),
  104. ];
  105. $form->addGroup($group, '', [get_lang('ShowCourseInUserLanguage')]);
  106. $form->addText('department_name', get_lang('Department'), false);
  107. $form->applyFilter('department_name', 'html_filter');
  108. $form->applyFilter('department_name', 'trim');
  109. $form->addText('department_url', get_lang('DepartmentUrl'), false);
  110. $form->applyFilter('department_url', 'html_filter');
  111. // Extra fields
  112. $extra_field = new ExtraField('course');
  113. $extraFieldAdminPermissions = false;
  114. $showOnlyTheseFields = ['tags', 'video_url', 'course_hours_duration', 'max_subscribed_students'];
  115. $extra = $extra_field->addElements(
  116. $form,
  117. $courseId,
  118. [],
  119. false,
  120. false,
  121. $showOnlyTheseFields
  122. );
  123. //Tags ExtraField
  124. $htmlHeadXtra[] = '
  125. <script>
  126. $(function() {
  127. '.$extra['jquery_ready_content'].'
  128. });
  129. </script>';
  130. // Picture
  131. $form->addFile(
  132. 'picture',
  133. get_lang('AddPicture'),
  134. ['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true]
  135. );
  136. $allowed_picture_types = api_get_supported_image_extensions(false);
  137. $form->addRule(
  138. 'picture',
  139. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  140. 'filetype',
  141. $allowed_picture_types
  142. );
  143. $form->addElement('checkbox', 'delete_picture', null, get_lang('DeletePicture'));
  144. if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
  145. $url = PDF::get_watermark($course_code);
  146. $form->addText('pdf_export_watermark_text', get_lang('PDFExportWatermarkTextTitle'), false, ['size' => '60']);
  147. $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
  148. if ($url != false) {
  149. $delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.png', get_lang('DelImage')).'</a>';
  150. $form->addElement(
  151. 'html',
  152. '<div class="row"><div class="formw"><a href="'.$url.'">'.$url.' '.$delete_url.'</a></div></div>'
  153. );
  154. }
  155. $form->addRule(
  156. 'pdf_export_watermark_path',
  157. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  158. 'filetype',
  159. $allowed_picture_types
  160. );
  161. }
  162. if (api_get_setting('allow_course_theme') == 'true') {
  163. $group = [];
  164. $group[] = $form->createElement(
  165. 'SelectTheme',
  166. 'course_theme',
  167. null,
  168. ['id' => 'course_theme_id']
  169. );
  170. $form->addGroup($group, '', [get_lang('Stylesheets')]);
  171. }
  172. $form->addElement('label', get_lang('DocumentQuota'), format_file_size(DocumentManager::get_course_quota()));
  173. $scoreModels = ExerciseLib::getScoreModels();
  174. if (!empty($scoreModels)) {
  175. $options = ['' => get_lang('None')];
  176. foreach ($scoreModels['models'] as $item) {
  177. $options[$item['id']] = get_lang($item['name']);
  178. }
  179. $form->addSelect('score_model_id', get_lang('ScoreModel'), $options);
  180. }
  181. $form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
  182. $form->addHtml('
  183. </div>
  184. </div>
  185. ');
  186. $form->addHtml('</div>');
  187. // COURSE ACCESS
  188. $group = [];
  189. $group[] = $form->createElement(
  190. 'radio',
  191. 'visibility',
  192. get_lang('CourseAccess'),
  193. get_lang('OpenToTheWorld'),
  194. COURSE_VISIBILITY_OPEN_WORLD
  195. );
  196. $group[] = $form->createElement(
  197. 'radio',
  198. 'visibility',
  199. null,
  200. get_lang('OpenToThePlatform'),
  201. COURSE_VISIBILITY_OPEN_PLATFORM
  202. );
  203. $group[] = $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  204. $group[] = $form->createElement(
  205. 'radio',
  206. 'visibility',
  207. null,
  208. get_lang('CourseVisibilityClosed'),
  209. COURSE_VISIBILITY_CLOSED
  210. );
  211. // The "hidden" visibility is only available to portal admins
  212. if (api_is_platform_admin()) {
  213. $group[] = $form->createElement(
  214. 'radio',
  215. 'visibility',
  216. null,
  217. get_lang('CourseVisibilityHidden'),
  218. COURSE_VISIBILITY_HIDDEN
  219. );
  220. }
  221. $groupElement = $form->addGroup(
  222. $group,
  223. '',
  224. [get_lang('CourseAccess'), get_lang('CourseAccessConfigTip')],
  225. null,
  226. null,
  227. true
  228. );
  229. $url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1";
  230. $url = Display::url($url, $url);
  231. $label = $form->addLabel(get_lang('DirectLink'), sprintf(get_lang('CourseSettingsRegisterDirectLink'), $url), true);
  232. $group2 = [];
  233. $group2[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  234. $group2[] = $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  235. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  236. $group3[] = $form->createElement(
  237. 'radio',
  238. 'unsubscribe',
  239. get_lang('Unsubscription'),
  240. get_lang('AllowedToUnsubscribe'),
  241. 1
  242. );
  243. $group3[] = $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  244. $text = $form->createElement(
  245. 'text',
  246. 'course_registration_password',
  247. get_lang('CourseRegistrationPassword'),
  248. false,
  249. ['size' => '60']
  250. );
  251. $checkBoxActiveLegal = $form->createElement(
  252. 'checkbox',
  253. 'activate_legal',
  254. [null, get_lang('ShowALegalNoticeWhenEnteringTheCourse')],
  255. get_lang('ActivateLegal')
  256. );
  257. $textAreaLegal = $form->createElement('textarea', 'legal', get_lang('CourseLegalAgreement'), ['rows' => 8]);
  258. $elements = [
  259. $groupElement,
  260. $label,
  261. get_lang('Subscription') => $group2,
  262. get_lang('Unsubscription') => $group3,
  263. $text,
  264. $checkBoxActiveLegal,
  265. $textAreaLegal,
  266. $myButton,
  267. ];
  268. $form->addPanelOption(
  269. 'course-access',
  270. Display::return_icon('course.png', get_lang('CourseAccess')).' '.get_lang('CourseAccess'),
  271. $elements
  272. );
  273. // Documents
  274. $globalGroup = [];
  275. if (api_get_setting('documents_default_visibility_defined_in_course') == 'true') {
  276. $group = [
  277. $form->createElement('radio', 'documents_default_visibility', null, get_lang('Visible'), 'visible'),
  278. $form->createElement('radio', 'documents_default_visibility', null, get_lang('Invisible'), 'invisible'),
  279. ];
  280. $globalGroup[get_lang('DocumentsDefaultVisibility')] = $group;
  281. }
  282. $group = [
  283. $form->createElement('radio', 'show_system_folders', null, get_lang('Yes'), 1),
  284. $form->createElement('radio', 'show_system_folders', null, get_lang('No'), 2),
  285. ];
  286. $globalGroup[get_lang('ShowSystemFolders')] = $group;
  287. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  288. $group = [];
  289. $group[] = $form->createElement(
  290. 'radio',
  291. 'enable_document_auto_launch',
  292. get_lang('DocumentAutoLaunch'),
  293. get_lang('RedirectToTheDocumentList'),
  294. 1
  295. );
  296. $group[] = $form->createElement('radio', 'enable_document_auto_launch', null, get_lang('Deactivate'), 0);
  297. $globalGroup[get_lang('DocumentAutoLaunch')] = $group;
  298. $globalGroup[] = $myButton;
  299. $form->addPanelOption(
  300. 'documents',
  301. Display::return_icon('folder.png', get_lang('Documents')).' '.get_lang('Documents'),
  302. $globalGroup
  303. );
  304. // EMAIL NOTIFICATIONS
  305. $form->addHtml('<div class="panel panel-default">');
  306. $form->addHtml('
  307. <div class="panel-heading" role="tab" id="heading-email-notifications">
  308. <h4 class="panel-title">
  309. <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion"
  310. href="#collapse-email-notifications" aria-expanded="false" aria-controls="collapse-email-notifications">
  311. ');
  312. $form->addHtml(
  313. Display::return_icon('mail.png', get_lang('EmailNotifications')).' '.get_lang('EmailNotifications')
  314. );
  315. $form->addHtml('
  316. </a>
  317. </h4>
  318. </div>
  319. ');
  320. $form->addHtml('
  321. <div id="collapse-email-notifications" class="panel-collapse collapse" role="tabpanel"
  322. aria-labelledby="heading-email-notifications">
  323. <div class="panel-body">
  324. ');
  325. $group = [];
  326. $group[] = $form->createElement(
  327. 'radio',
  328. 'email_alert_to_teacher_on_new_user_in_course',
  329. get_lang('NewUserEmailAlert'),
  330. get_lang('NewUserEmailAlertEnable'),
  331. 1
  332. );
  333. $group[] = $form->createElement(
  334. 'radio',
  335. 'email_alert_to_teacher_on_new_user_in_course',
  336. null,
  337. get_lang('NewUserEmailAlertToTeacharAndTutor'),
  338. 2
  339. );
  340. $group[] = $form->createElement(
  341. 'radio',
  342. 'email_alert_to_teacher_on_new_user_in_course',
  343. null,
  344. get_lang('NewUserEmailAlertDisable'),
  345. 0
  346. );
  347. $form->addGroup($group, '', [get_lang("NewUserEmailAlert")]);
  348. $group = [];
  349. $group[] = $form->createElement(
  350. 'radio',
  351. 'email_alert_students_on_new_homework',
  352. get_lang('NewHomeworkEmailAlert'),
  353. get_lang('NewHomeworkEmailAlertEnable'),
  354. 1
  355. );
  356. $group[] = $form->createElement(
  357. 'radio',
  358. 'email_alert_students_on_new_homework',
  359. null,
  360. get_lang('NewHomeworkEmailAlertToHrmEnable'),
  361. 2
  362. );
  363. $group[] = $form->createElement(
  364. 'radio',
  365. 'email_alert_students_on_new_homework',
  366. null,
  367. get_lang('NewHomeworkEmailAlertDisable'),
  368. 0
  369. );
  370. $form->addGroup($group, '', [get_lang("NewHomeworkEmailAlert")]);
  371. $group = [];
  372. $group[] = $form->createElement(
  373. 'radio',
  374. 'email_alert_manager_on_new_doc',
  375. get_lang('WorkEmailAlert'),
  376. get_lang('WorkEmailAlertActivate'),
  377. 1
  378. );
  379. $group[] = $form->createElement(
  380. 'radio',
  381. 'email_alert_manager_on_new_doc',
  382. null,
  383. get_lang('WorkEmailAlertActivateOnlyForTeachers'),
  384. 3
  385. );
  386. $group[] = $form->createElement(
  387. 'radio',
  388. 'email_alert_manager_on_new_doc',
  389. null,
  390. get_lang('WorkEmailAlertActivateOnlyForStudents'),
  391. 2
  392. );
  393. $group[] = $form->createElement(
  394. 'radio',
  395. 'email_alert_manager_on_new_doc',
  396. null,
  397. get_lang('WorkEmailAlertDeactivate'),
  398. 0
  399. );
  400. $form->addGroup($group, '', [get_lang("WorkEmailAlert")]);
  401. $group = [];
  402. $group[] = $form->createElement(
  403. 'radio',
  404. 'email_alert_on_new_doc_dropbox',
  405. get_lang('DropboxEmailAlert'),
  406. get_lang('DropboxEmailAlertActivate'),
  407. 1
  408. );
  409. $group[] = $form->createElement(
  410. 'radio',
  411. 'email_alert_on_new_doc_dropbox',
  412. null,
  413. get_lang('DropboxEmailAlertDeactivate'),
  414. 0
  415. );
  416. $form->addGroup($group, '', [get_lang("DropboxEmailAlert")]);
  417. // Exercises notifications
  418. $emailAlerts = ExerciseLib::getNotificationSettings();
  419. $group = [];
  420. foreach ($emailAlerts as $itemId => $label) {
  421. $group[] = $form->createElement(
  422. 'checkbox',
  423. 'email_alert_manager_on_new_quiz[]',
  424. null,
  425. $label,
  426. ['value' => $itemId]
  427. );
  428. }
  429. $form->addGroup($group, '', [get_lang('Exercises')]);
  430. $group = [];
  431. $group[] = $form->createElement(
  432. 'radio',
  433. 'email_to_teachers_on_new_work_feedback',
  434. get_lang('EmailToTeachersWhenNewWorkFeedback'),
  435. get_lang('Yes'),
  436. 1
  437. );
  438. $group[] = $form->createElement(
  439. 'radio',
  440. 'email_to_teachers_on_new_work_feedback',
  441. null,
  442. get_lang('No'),
  443. 2
  444. );
  445. $form->addGroup($group, '', [get_lang("EmailToTeachersWhenNewWorkFeedback")]);
  446. $form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
  447. $form->addHtml('
  448. </div>
  449. </div>
  450. ');
  451. $form->addHtml('</div>');
  452. // USER RIGHTS
  453. $group = [];
  454. $group[] = $form->createElement(
  455. 'radio',
  456. 'allow_user_edit_agenda',
  457. get_lang('AllowUserEditAgenda'),
  458. get_lang('AllowUserEditAgendaActivate'),
  459. 1
  460. );
  461. $group[] = $form->createElement('radio', 'allow_user_edit_agenda', null, get_lang('AllowUserEditAgendaDeactivate'), 0);
  462. $group2 = [];
  463. $group2[] = $form->createElement(
  464. 'radio',
  465. 'allow_user_edit_announcement',
  466. get_lang('AllowUserEditAnnouncement'),
  467. get_lang('AllowUserEditAnnouncementActivate'),
  468. 1
  469. );
  470. $group2[] = $form->createElement(
  471. 'radio',
  472. 'allow_user_edit_announcement',
  473. null,
  474. get_lang('AllowUserEditAnnouncementDeactivate'),
  475. 0
  476. );
  477. $group3 = [];
  478. $group3[] = $form->createElement(
  479. 'radio',
  480. 'allow_user_image_forum',
  481. get_lang('AllowUserImageForum'),
  482. get_lang('AllowUserImageForumActivate'),
  483. 1
  484. );
  485. $group3[] = $form->createElement('radio', 'allow_user_image_forum', null, get_lang('AllowUserImageForumDeactivate'), 0);
  486. $group4 = [];
  487. $group4[] = $form->createElement(
  488. 'radio',
  489. 'allow_user_view_user_list',
  490. get_lang('AllowUserViewUserList'),
  491. get_lang('AllowUserViewUserListActivate'),
  492. 1
  493. );
  494. $group4[] = $form->createElement(
  495. 'radio',
  496. 'allow_user_view_user_list',
  497. null,
  498. get_lang('AllowUserViewUserListDeactivate'),
  499. 0
  500. );
  501. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  502. $globalGroup = [
  503. get_lang('AllowUserEditAgenda') => $group,
  504. get_lang('AllowUserEditAnnouncement') => $group2,
  505. get_lang('AllowUserImageForum') => $group3,
  506. get_lang('AllowUserViewUserList') => $group4,
  507. '' => $myButton,
  508. ];
  509. $form->addPanelOption(
  510. 'users',
  511. Display::return_icon('user.png', get_lang('UserRights')).' '.get_lang('UserRights'),
  512. $globalGroup
  513. );
  514. // CHAT SETTINGS
  515. $group = [];
  516. $group[] = $form->createElement(
  517. 'radio',
  518. 'allow_open_chat_window',
  519. get_lang('AllowOpenchatWindow'),
  520. get_lang('AllowOpenChatWindowActivate'),
  521. 1
  522. );
  523. $group[] = $form->createElement('radio', 'allow_open_chat_window', null, get_lang('AllowOpenChatWindowDeactivate'), 0);
  524. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  525. $globalGroup = [
  526. get_lang('AllowOpenchatWindow') => $group,
  527. '' => $myButton,
  528. ];
  529. $form->addPanelOption(
  530. 'chat',
  531. Display::return_icon('chat.png', get_lang('ConfigChat'), '', ICON_SIZE_SMALL).' '.get_lang('ConfigChat'),
  532. $globalGroup
  533. );
  534. // LEARNING PATH
  535. $form->addHtml('<div class="panel panel-default">');
  536. $form->addHtml('
  537. <div class="panel-heading" role="tab" id="heading-learning-path">
  538. <h4 class="panel-title">
  539. <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion"
  540. href="#collapse-learning-path" aria-expanded="false" aria-controls="collapse-learning-path">
  541. ');
  542. $form->addHtml(
  543. Display::return_icon('scorms.png', get_lang('ConfigLearnpath')).' '.get_lang('ConfigLearnpath')
  544. );
  545. $form->addHtml('
  546. </a>
  547. </h4>
  548. </div>
  549. ');
  550. $form->addHtml('
  551. <div id="collapse-learning-path" class="panel-collapse collapse" role="tabpanel"
  552. aria-labelledby="heading-learning-path">
  553. <div class="panel-body">
  554. ');
  555. // Auto launch LP
  556. $group = [];
  557. $group[] = $form->createElement(
  558. 'radio',
  559. 'enable_lp_auto_launch',
  560. get_lang('LPAutoLaunch'),
  561. get_lang('RedirectToALearningPath'),
  562. 1
  563. );
  564. $group[] = $form->createElement(
  565. 'radio',
  566. 'enable_lp_auto_launch',
  567. get_lang('LPAutoLaunch'),
  568. get_lang('RedirectToTheLearningPathList'),
  569. 2
  570. );
  571. $group[] = $form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0);
  572. $form->addGroup($group, '', [get_lang('LPAutoLaunch')]);
  573. if (api_get_setting('allow_course_theme') == 'true') {
  574. // Allow theme into Learning path
  575. $group = [];
  576. $group[] = $form->createElement(
  577. 'radio',
  578. 'allow_learning_path_theme',
  579. get_lang('AllowLearningPathTheme'),
  580. get_lang('AllowLearningPathThemeAllow'),
  581. 1
  582. );
  583. $group[] = $form->createElement(
  584. 'radio',
  585. 'allow_learning_path_theme',
  586. null,
  587. get_lang('AllowLearningPathThemeDisallow'),
  588. 0
  589. );
  590. $form->addGroup($group, '', [get_lang("AllowLearningPathTheme")]);
  591. }
  592. $allowLPReturnLink = api_get_setting('allow_lp_return_link');
  593. if ($allowLPReturnLink === 'true') {
  594. $group = [
  595. $form->createElement(
  596. 'radio',
  597. 'lp_return_link',
  598. get_lang('LpReturnLink'),
  599. get_lang('RedirectToTheLearningPathList'),
  600. 1
  601. ),
  602. $form->createElement(
  603. 'radio',
  604. 'lp_return_link',
  605. null,
  606. get_lang('RedirectToCourseHome'),
  607. 0
  608. ),
  609. $form->createElement(
  610. 'radio',
  611. 'lp_return_link',
  612. null,
  613. get_lang('MyCourses'),
  614. 2
  615. ),
  616. ];
  617. $form->addGroup($group, '', [get_lang("LpReturnLink")]);
  618. }
  619. $exerciseInvisible = api_get_setting('exercise_invisible_in_session');
  620. $configureExerciseVisibility = api_get_setting('configure_exercise_visibility_in_course');
  621. if ($exerciseInvisible === 'true' &&
  622. $configureExerciseVisibility === 'true'
  623. ) {
  624. $group = [
  625. $form->createElement(
  626. 'radio',
  627. 'exercise_invisible_in_session',
  628. get_lang('ExerciseInvisibleInSession'),
  629. get_lang('Yes'),
  630. 1
  631. ),
  632. $form->createElement(
  633. 'radio',
  634. 'exercise_invisible_in_session',
  635. null,
  636. get_lang('No'),
  637. 0
  638. ),
  639. ];
  640. $form->addGroup($group, '', [get_lang("ExerciseInvisibleInSession")]);
  641. }
  642. if (is_settings_editable()) {
  643. $form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
  644. } else {
  645. // Is it allowed to edit the course settings?
  646. if (!is_settings_editable()) {
  647. $disabled_output = "disabled";
  648. }
  649. $form->freeze();
  650. }
  651. $form->addHtml('
  652. </div>
  653. </div>
  654. ');
  655. $form->addHtml('</div>');
  656. // Exercise
  657. $form->addHtml('<div class="panel panel-default">');
  658. $form->addHtml('
  659. <div class="panel-heading" role="tab" id="heading-exercise">
  660. <h4 class="panel-title">
  661. <a class="collapsed"
  662. role="button" data-toggle="collapse"
  663. data-parent="#accordion"
  664. href="#collapse-exercise" aria-expanded="false" aria-controls="collapse-exercise">
  665. ');
  666. $form->addHtml(
  667. Display::return_icon('quiz.png', get_lang('Exercises')).' '.get_lang('Exercises')
  668. );
  669. $form->addHtml('
  670. </a>
  671. </h4>
  672. </div>
  673. ');
  674. $form->addHtml('
  675. <div id="collapse-exercise" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-exercise">
  676. <div class="panel-body">
  677. ');
  678. if (api_get_configuration_value('allow_exercise_auto_launch')) {
  679. // Auto launch exercise
  680. $group = [];
  681. $group[] = $form->createElement(
  682. 'radio',
  683. 'enable_exercise_auto_launch',
  684. get_lang('ExerciseAutoLaunch'),
  685. get_lang('RedirectToExercise'),
  686. 1
  687. );
  688. $group[] = $form->createElement(
  689. 'radio',
  690. 'enable_exercise_auto_launch',
  691. get_lang('ExerciseAutoLaunch'),
  692. get_lang('RedirectToTheExerciseList'),
  693. 2
  694. );
  695. $group[] = $form->createElement('radio', 'enable_exercise_auto_launch', null, get_lang('Deactivate'), 0);
  696. $form->addGroup($group, '', [get_lang('ExerciseAutoLaunch')]);
  697. }
  698. $form->addElement(
  699. 'number',
  700. 'quiz_question_limit_per_day',
  701. [get_lang('QuizQuestionsLimitPerDay'), get_lang('QuizQuestionsLimitPerDayComment')],
  702. ['step' => 1, 'min' => 0]
  703. );
  704. if (is_settings_editable()) {
  705. $form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
  706. } else {
  707. // Is it allowed to edit the course settings?
  708. if (!is_settings_editable()) {
  709. $disabled_output = "disabled";
  710. }
  711. $form->freeze();
  712. }
  713. $form->addHtml('
  714. </div>
  715. </div>
  716. ');
  717. $form->addHtml('</div>');
  718. // THEMATIC ADVANCE SETTINGS
  719. $group = [];
  720. $group[] = $form->createElement(
  721. 'radio',
  722. 'display_info_advance_inside_homecourse',
  723. get_lang('InfoAboutAdvanceInsideHomeCourse'),
  724. get_lang('DisplayAboutLastDoneAdvance'),
  725. 1
  726. );
  727. $group[] = $form->createElement(
  728. 'radio',
  729. 'display_info_advance_inside_homecourse',
  730. null,
  731. get_lang('DisplayAboutNextAdvanceNotDone'),
  732. 2
  733. );
  734. $group[] = $form->createElement(
  735. 'radio',
  736. 'display_info_advance_inside_homecourse',
  737. null,
  738. get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'),
  739. 3
  740. );
  741. $group[] = $form->createElement(
  742. 'radio',
  743. 'display_info_advance_inside_homecourse',
  744. null,
  745. get_lang('DoNotDisplayAnyAdvance'),
  746. 0
  747. );
  748. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  749. $globalGroup = [
  750. get_lang('InfoAboutAdvanceInsideHomeCourse') => $group,
  751. '' => $myButton,
  752. ];
  753. $form->addPanelOption(
  754. 'thematic',
  755. Display::return_icon(
  756. 'course_progress.png',
  757. get_lang('ThematicAdvanceConfiguration')
  758. )
  759. .' '
  760. .get_lang('ThematicAdvanceConfiguration'),
  761. $globalGroup
  762. );
  763. // Certificate settings
  764. if (api_get_setting('allow_public_certificates') === 'true') {
  765. $group = [];
  766. $group[] = $form->createElement(
  767. 'radio',
  768. 'allow_public_certificates',
  769. get_lang('AllowPublicCertificates'),
  770. get_lang('Yes'),
  771. 1
  772. );
  773. $group[] = $form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0);
  774. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  775. $globalGroup = [
  776. get_lang('AllowPublicCertificates') => $group,
  777. '' => $myButton,
  778. ];
  779. $form->addPanelOption(
  780. 'certificate',
  781. Display::return_icon('certificate.png', get_lang('Certificates')).' '.get_lang('Certificates'),
  782. $globalGroup
  783. );
  784. }
  785. // Forum settings
  786. $group = [
  787. $form->createElement('radio', 'enable_forum_auto_launch', null, get_lang('RedirectToForumList'), 1),
  788. $form->createElement('radio', 'enable_forum_auto_launch', null, get_lang('Disabled'), 2),
  789. ];
  790. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  791. // Forum settings
  792. $groupNotification = [
  793. $form->createElement('radio', 'hide_forum_notifications', null, get_lang('Yes'), 1),
  794. $form->createElement('radio', 'hide_forum_notifications', null, get_lang('No'), 2),
  795. ];
  796. $globalGroup = [
  797. get_lang('EnableForumAutoLaunch') => $group,
  798. get_lang('HideForumNotifications') => $groupNotification,
  799. '' => $myButton,
  800. ];
  801. $form->addPanelOption(
  802. 'forum',
  803. Display::return_icon('forum.png', get_lang('Forum')).' '.get_lang('Forum'),
  804. $globalGroup
  805. );
  806. // Student publication
  807. $group = [
  808. $form->createElement('radio', 'show_score', null, get_lang('NewVisible'), 0),
  809. $form->createElement('radio', 'show_score', null, get_lang('NewUnvisible'), 1),
  810. ];
  811. $group2 = [
  812. $form->createElement('radio', 'student_delete_own_publication', null, get_lang('Yes'), 1),
  813. $form->createElement('radio', 'student_delete_own_publication', null, get_lang('No'), 0),
  814. ];
  815. $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
  816. $globalGroup = [
  817. get_lang('DefaultUpload') => $group,
  818. get_lang('StudentAllowedToDeleteOwnPublication') => $group2,
  819. '' => $myButton,
  820. ];
  821. $form->addPanelOption(
  822. 'student-publication',
  823. Display::return_icon('work.png', get_lang('StudentPublications')).' '.get_lang('StudentPublications'),
  824. $globalGroup
  825. );
  826. // Plugin course settings
  827. $appPlugin = new AppPlugin();
  828. $appPlugin->add_course_settings_form($form);
  829. $form->addHtml('</div>');
  830. // Get all the course information
  831. $all_course_information = CourseManager::get_course_information($_course['sysCode']);
  832. // Set the default values of the form
  833. $values = [];
  834. $values['title'] = $_course['name'];
  835. $values['category_code'] = $_course['categoryCode'];
  836. $values['course_language'] = $_course['language'];
  837. $values['department_name'] = $_course['extLink']['name'];
  838. $values['department_url'] = $_course['extLink']['url'];
  839. $values['visibility'] = $_course['visibility'];
  840. $values['subscribe'] = $_course['subscribe'];
  841. $values['unsubscribe'] = $_course['unsubscribe'];
  842. $values['course_registration_password'] = $all_course_information['registration_code'];
  843. $values['legal'] = $all_course_information['legal'];
  844. $values['activate_legal'] = $all_course_information['activate_legal'];
  845. $values['show_score'] = $all_course_information['show_score'];
  846. $courseSettings = CourseManager::getCourseSettingVariables($appPlugin);
  847. foreach ($courseSettings as $setting) {
  848. $result = api_get_course_setting($setting);
  849. if ($result != '-1') {
  850. $values[$setting] = $result;
  851. }
  852. }
  853. // make sure new settings have a clear default value
  854. if (!isset($values['student_delete_own_publication'])) {
  855. $values['student_delete_own_publication'] = 0;
  856. }
  857. $form->setDefaults($values);
  858. // Validate form
  859. if ($form->validate() && is_settings_editable()) {
  860. $updateValues = $form->getSubmitValues();
  861. // update course picture
  862. $picture = $_FILES['picture'];
  863. if (!empty($picture['name'])) {
  864. $picture_uri = CourseManager::update_course_picture(
  865. $_course,
  866. $picture['name'],
  867. $picture['tmp_name'],
  868. $updateValues['picture_crop_result']
  869. );
  870. }
  871. $visibility = $updateValues['visibility'];
  872. $deletePicture = isset($updateValues['delete_picture']) ? $updateValues['delete_picture'] : '';
  873. if ($deletePicture) {
  874. CourseManager::deleteCoursePicture($course_code);
  875. }
  876. global $_configuration;
  877. $urlId = api_get_current_access_url_id();
  878. if (isset($_configuration[$urlId]) &&
  879. isset($_configuration[$urlId]['hosting_limit_active_courses']) &&
  880. $_configuration[$urlId]['hosting_limit_active_courses'] > 0
  881. ) {
  882. $courseInfo = api_get_course_info_by_id($courseId);
  883. // Check if
  884. if ($courseInfo['visibility'] == COURSE_VISIBILITY_HIDDEN &&
  885. $visibility != $courseInfo['visibility']
  886. ) {
  887. $num = CourseManager::countActiveCourses($urlId);
  888. if ($num >= $_configuration[$urlId]['hosting_limit_active_courses']) {
  889. api_warn_hosting_contact('hosting_limit_active_courses');
  890. Display::addFlash(
  891. Display::return_message(get_lang('PortalActiveCoursesLimitReached'))
  892. );
  893. $url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.api_get_cidreq();
  894. header("Location: $url");
  895. exit;
  896. }
  897. }
  898. }
  899. $pdf_export_watermark_path = isset($_FILES['pdf_export_watermark_path'])
  900. ? $_FILES['pdf_export_watermark_path']
  901. : null;
  902. if (!empty($pdf_export_watermark_path['name'])) {
  903. $pdf_export_watermark_path_result = PDF::upload_watermark(
  904. $pdf_export_watermark_path['name'],
  905. $pdf_export_watermark_path['tmp_name'],
  906. $course_code
  907. );
  908. unset($updateValues['pdf_export_watermark_path']);
  909. }
  910. $activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : 0;
  911. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  912. $params = [
  913. 'title' => $updateValues['title'],
  914. 'course_language' => $updateValues['course_language'],
  915. 'category_code' => $updateValues['category_code'],
  916. 'department_name' => $updateValues['department_name'],
  917. 'department_url' => $updateValues['department_url'],
  918. 'visibility' => $updateValues['visibility'],
  919. 'subscribe' => $updateValues['subscribe'],
  920. 'unsubscribe' => $updateValues['unsubscribe'],
  921. 'legal' => $updateValues['legal'],
  922. 'activate_legal' => $activeLegal,
  923. 'registration_code' => $updateValues['course_registration_password'],
  924. 'show_score' => $updateValues['show_score'],
  925. ];
  926. Database::update($table_course, $params, ['id = ?' => $courseId]);
  927. // Insert/Updates course_settings table
  928. foreach ($courseSettings as $setting) {
  929. $value = isset($updateValues[$setting]) ? $updateValues[$setting] : null;
  930. CourseManager::saveCourseConfigurationSetting(
  931. $appPlugin,
  932. $setting,
  933. $value,
  934. api_get_course_int_id()
  935. );
  936. }
  937. // update the extra fields
  938. $courseFieldValue = new ExtraFieldValue('course');
  939. $courseFieldValue->saveFieldValues($updateValues);
  940. $appPlugin->saveCourseSettingsHook($updateValues);
  941. $courseParams = api_get_cidreq();
  942. $cidReset = true;
  943. $cidReq = $course_code;
  944. Display::addFlash(Display::return_message(get_lang('Updated')));
  945. require '../inc/local.inc.php';
  946. $url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.$courseParams;
  947. header("Location: $url");
  948. exit;
  949. }
  950. if ($show_delete_watermark_text_message) {
  951. Display::addFlash(
  952. Display::return_message(get_lang('FileDeleted'), 'normal')
  953. );
  954. }
  955. /* Header */
  956. Display::display_header($nameTools, MODULE_HELP_NAME);
  957. // Display the form
  958. echo '<div id="course_settings">';
  959. $form->display();
  960. echo '</div>';
  961. Display::display_footer();