infocours.php 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * Code to display the course settings form (for the course admin)
  6. * and activate the changes.
  7. *
  8. * See ./inc/conf/course_info.conf.php for settings
  9. *
  10. * @todo Take those config settings into account in this script
  11. *
  12. * @author Patrick Cool <patrick.cool@UGent.be>
  13. * @author Roan Embrechts, refactoring and improved course visibility|subscribe|unsubscribe options
  14. * @author Julio Montoya <gugli100@gmail.com> Jquery support + lots of fixes
  15. */
  16. require_once __DIR__.'/../inc/global.inc.php';
  17. $current_course_tool = TOOL_COURSE_SETTING;
  18. $this_section = SECTION_COURSES;
  19. $nameTools = get_lang('Settings');
  20. api_protect_course_script(true);
  21. api_block_anonymous_users();
  22. $_course = api_get_course_info();
  23. $courseEntity = api_get_course_entity();
  24. $currentCourseRepository = $_course['path'];
  25. $isAllowToEdit = api_is_course_admin() || api_is_platform_admin();
  26. $course_code = api_get_course_id();
  27. $courseId = api_get_course_int_id();
  28. $repo = Container::getCourseRepository();
  29. $em = $repo->getEntityManager();
  30. $isEditable = true;
  31. if (!$isAllowToEdit) {
  32. api_not_allowed(true);
  33. }
  34. $router = Container::getRouter();
  35. $translator = Container::getTranslator();
  36. $show_delete_watermark_text_message = false;
  37. if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
  38. if (isset($_GET['delete_watermark'])) {
  39. PDF::delete_watermark($course_code);
  40. $show_delete_watermark_text_message = true;
  41. }
  42. }
  43. $categories = CourseCategory::getCategoriesCanBeAddedInCourse($_course['categoryCode']);
  44. $formOptionsArray = [];
  45. // Build the form
  46. $form = new FormValidator(
  47. 'update_course',
  48. 'post',
  49. api_get_self().'?'.api_get_cidreq()
  50. );
  51. // COURSE SETTINGS
  52. function card_settings_open($id, $title, $open = false, $icon, $parent)
  53. {
  54. $html = '<div class="card">';
  55. $html .= '<div class="card-header" id="card_'.$id.'">';
  56. $html .= '<h5 class="card-title">';
  57. $html .= '<a role="button" class="'.(($open) ? 'collapse' : ' ').'" data-toggle="collapse" data-target="#collapse_'.$id.'" aria-expanded="true" aria-controls="collapse_'.$id.'">';
  58. if ($icon) {
  59. $html .= Display::return_icon($icon, null, null, ICON_SIZE_SMALL);
  60. }
  61. $html .= $title;
  62. $html .= '</a></h5></div>';
  63. $html .= '<div id="collapse_'.$id.'" class="collapse show" aria-labelledby="heading_'.$id.'" data-parent="#'.$parent.'">';
  64. $html .= '<div class="card-body">';
  65. return $html;
  66. }
  67. function card_settings_close()
  68. {
  69. $html = '</div></div></div>';
  70. return $html;
  71. }
  72. $form->addHtml(card_settings_open('course_settings', get_lang('Course settings'), true, 'settings.png', 'accordionSettings'));
  73. $image = '';
  74. // Display course picture
  75. $course_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository; // course path
  76. $illustration = $courseEntity->getResourceNodeIllustration();
  77. if (!empty($illustration)) {
  78. $course_medium_image = Container::getRouter()->generate(
  79. 'core_tool_resource',
  80. ['id' => $illustration->getId()]
  81. );
  82. $image = '<div class="row"><label class="col-md-2 control-label">'.get_lang('Image').'</label>
  83. <div class="col-md-8"><img class="img-thumbnail" src="'.$course_medium_image.'" /></div></div>';
  84. }
  85. $form->addText('title', get_lang('Title'), true);
  86. $form->applyFilter('title', 'html_filter');
  87. $form->applyFilter('title', 'trim');
  88. $form->addElement(
  89. 'select',
  90. 'category_code',
  91. get_lang('Category'),
  92. $categories,
  93. ['style' => 'width:350px', 'id' => 'category_code']
  94. );
  95. $form->addSelectLanguage(
  96. 'course_language',
  97. [get_lang('Language'), get_lang('This language will be valid for every visitor of your courses portal')]
  98. );
  99. $group = [
  100. $form->createElement('radio', 'show_course_in_user_language', null, get_lang('Yes'), 1),
  101. $form->createElement('radio', 'show_course_in_user_language', null, get_lang('No'), 2),
  102. ];
  103. $form->addGroup($group, '', [get_lang('Show course in user\'s language')]);
  104. $form->addText('department_name', get_lang('Department'), false);
  105. $form->applyFilter('department_name', 'html_filter');
  106. $form->applyFilter('department_name', 'trim');
  107. $form->addText('department_url', get_lang('Department URL'), false);
  108. $form->applyFilter('department_url', 'html_filter');
  109. // Extra fields
  110. $extra_field = new ExtraField('course');
  111. $extraFieldAdminPermissions = false;
  112. $showOnlyTheseFields = ['tags', 'video_url', 'course_hours_duration', 'max_subscribed_students'];
  113. $extra = $extra_field->addElements(
  114. $form,
  115. $courseId,
  116. [],
  117. false,
  118. false,
  119. $showOnlyTheseFields,
  120. [],
  121. false
  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('Add a picture'),
  134. ['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true]
  135. );
  136. $allowed_picture_types = api_get_supported_image_extensions(false);
  137. $form->addHtml($image);
  138. $form->addRule(
  139. 'picture',
  140. get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowed_picture_types).')',
  141. 'filetype',
  142. $allowed_picture_types
  143. );
  144. $form->addElement('checkbox', 'delete_picture', null, get_lang('Delete picture'));
  145. if (api_get_setting('pdf_export_watermark_by_course') == 'true') {
  146. $url = PDF::get_watermark($course_code);
  147. $form->addText('pdf_export_watermark_text', get_lang('PDF watermark text'), false, ['size' => '60']);
  148. $form->addElement('file', 'pdf_export_watermark_path', get_lang('Upload a watermark image'));
  149. if ($url != false) {
  150. $delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.png', get_lang('Remove picture')).'</a>';
  151. $form->addElement(
  152. 'html',
  153. '<div class="row"><div class="form"><a href="'.$url.'">'.$url.' '.$delete_url.'</a></div></div>'
  154. );
  155. }
  156. $form->addRule(
  157. 'pdf_export_watermark_path',
  158. get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowed_picture_types).')',
  159. 'filetype',
  160. $allowed_picture_types
  161. );
  162. }
  163. if (api_get_setting('allow_course_theme') == 'true') {
  164. $group = [];
  165. $group[] = $form->createElement(
  166. 'SelectTheme',
  167. 'course_theme',
  168. null,
  169. ['id' => 'course_theme_id']
  170. );
  171. $form->addGroup($group, '', [get_lang('Style sheets')]);
  172. }
  173. $form->addElement('label', get_lang('Space Available'), format_file_size(DocumentManager::get_course_quota()));
  174. $scoreModels = ExerciseLib::getScoreModels();
  175. if (!empty($scoreModels)) {
  176. $options = ['' => get_lang('none')];
  177. foreach ($scoreModels['models'] as $item) {
  178. $options[$item['id']] = get_lang($item['name']);
  179. }
  180. $form->addSelect('score_model_id', get_lang('Score model'), $options);
  181. }
  182. $form->addButtonSave(get_lang('Save settings'), 'submit_save');
  183. $form->addHtml(card_settings_close());
  184. $group = [];
  185. $group[] = $form->createElement(
  186. 'radio',
  187. 'visibility',
  188. get_lang('Course access'),
  189. get_lang('Public - access allowed for the whole world'),
  190. COURSE_VISIBILITY_OPEN_WORLD
  191. );
  192. $group[] = $form->createElement(
  193. 'radio',
  194. 'visibility',
  195. null,
  196. get_lang(' Open - access allowed for users registered on the platform'),
  197. COURSE_VISIBILITY_OPEN_PLATFORM
  198. );
  199. $group[] = $form->createElement('radio', 'visibility', null, get_lang('Private access (access authorized to group members only)'), COURSE_VISIBILITY_REGISTERED);
  200. $group[] = $form->createElement(
  201. 'radio',
  202. 'visibility',
  203. null,
  204. get_lang('Closed - the course is only accessible to the teachers'),
  205. COURSE_VISIBILITY_CLOSED
  206. );
  207. // The "hidden" visibility is only available to portal admins
  208. if (api_is_platform_admin()) {
  209. $group[] = $form->createElement(
  210. 'radio',
  211. 'visibility',
  212. null,
  213. get_lang('Hidden - Completely hidden to all users except the administrators'),
  214. COURSE_VISIBILITY_HIDDEN
  215. );
  216. }
  217. $groupElement = $form->addGroup(
  218. $group,
  219. '',
  220. [get_lang('Course access'), get_lang('Course accessConfigTip')],
  221. null,
  222. null,
  223. true
  224. );
  225. $url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1";
  226. $url = Display::url($url, $url);
  227. $label = $form->addLabel(get_lang('Direct link'), sprintf(get_lang('Course settingsRegisterDirect link'), $url), true);
  228. $group2 = [];
  229. $group2[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  230. $group2[] = $form->createElement('radio', 'subscribe', null, get_lang('This function is only available to trainers'), 0);
  231. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  232. $group3[] = $form->createElement(
  233. 'radio',
  234. 'unsubscribe',
  235. get_lang('Unsubscribe'),
  236. get_lang('Users are allowed to unsubscribe from this course'),
  237. 1
  238. );
  239. $group3[] = $form->createElement('radio', 'unsubscribe', null, get_lang('NotUsers are allowed to unsubscribe from this course'), 0);
  240. $text = $form->createElement(
  241. 'text',
  242. 'course_registration_password',
  243. get_lang('Course registration password'),
  244. false,
  245. ['size' => '60']
  246. );
  247. $checkBoxActiveLegal = $form->createElement(
  248. 'checkbox',
  249. 'activate_legal',
  250. [null, get_lang('Show a legal notice when entering the course')],
  251. get_lang('Enable legal terms')
  252. );
  253. $textAreaLegal = $form->createElement('textarea', 'legal', get_lang('Legal agreement for this course'), ['rows' => 8]);
  254. $elements = [
  255. $groupElement,
  256. $label,
  257. get_lang('Subscription') => $group2,
  258. get_lang('Unsubscribe') => $group3,
  259. $text,
  260. $checkBoxActiveLegal,
  261. $textAreaLegal,
  262. $myButton,
  263. ];
  264. $form->addPanelOption(
  265. 'course_access',
  266. get_lang('Course access'),
  267. $elements,
  268. 'course.png',
  269. false,
  270. 'accordionSettings'
  271. );
  272. // Documents
  273. $globalGroup = [];
  274. if (api_get_setting('documents_default_visibility_defined_in_course') == 'true') {
  275. $group = [
  276. $form->createElement('radio', 'documents_default_visibility', null, get_lang('Visible'), 'visible'),
  277. $form->createElement('radio', 'documents_default_visibility', null, get_lang('invisible'), 'invisible'),
  278. ];
  279. $globalGroup[get_lang('Default visibility of new documents')] = $group;
  280. }
  281. $group = [
  282. $form->createElement('radio', 'show_system_folders', null, get_lang('Yes'), 1),
  283. $form->createElement('radio', 'show_system_folders', null, get_lang('No'), 2),
  284. ];
  285. $globalGroup[get_lang('Show system folders.')] = $group;
  286. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  287. $group = [];
  288. $group[] = $form->createElement(
  289. 'radio',
  290. 'enable_document_auto_launch',
  291. get_lang('Auto-launch for documents'),
  292. get_lang('Redirect to the document list'),
  293. 1
  294. );
  295. $group[] = $form->createElement('radio', 'enable_document_auto_launch', null, get_lang('Deactivate'), 0);
  296. $globalGroup[get_lang('Auto-launch for documents')] = $group;
  297. $globalGroup[] = $myButton;
  298. $form->addPanelOption(
  299. 'documents',
  300. get_lang('Documents'),
  301. $globalGroup,
  302. 'folder.png',
  303. false,
  304. 'accordionSettings'
  305. );
  306. $globalGroup = [];
  307. $group = [];
  308. $group[] = $form->createElement(
  309. 'radio',
  310. 'email_alert_to_teacher_on_new_user_in_course',
  311. get_lang('E-mail teacher when a new user auto-subscribes'),
  312. get_lang('E-mail teacher when a new user auto-subscribesEnable'),
  313. 1
  314. );
  315. $group[] = $form->createElement(
  316. 'radio',
  317. 'email_alert_to_teacher_on_new_user_in_course',
  318. null,
  319. get_lang('E-mail teacher when a new user auto-subscribesToTeacharAndTutor'),
  320. 2
  321. );
  322. $group[] = $form->createElement(
  323. 'radio',
  324. 'email_alert_to_teacher_on_new_user_in_course',
  325. null,
  326. get_lang('E-mail teacher when a new user auto-subscribesDisable'),
  327. 0
  328. );
  329. $globalGroup[get_lang('E-mail teacher when a new user auto-subscribes')] = $group;
  330. $group = [];
  331. $group[] = $form->createElement(
  332. 'radio',
  333. 'email_alert_students_on_new_homework',
  334. get_lang('E-mail students on assignment creation'),
  335. get_lang('E-mail students on assignment creationEnable'),
  336. 1
  337. );
  338. $group[] = $form->createElement(
  339. 'radio',
  340. 'email_alert_students_on_new_homework',
  341. null,
  342. get_lang('E-mail students on assignment creationToHrmEnable'),
  343. 2
  344. );
  345. $group[] = $form->createElement(
  346. 'radio',
  347. 'email_alert_students_on_new_homework',
  348. null,
  349. get_lang('E-mail students on assignment creationDisable'),
  350. 0
  351. );
  352. $globalGroup[get_lang('E-mail students on assignment creation')] = $group;
  353. $group = [];
  354. $group[] = $form->createElement(
  355. 'radio',
  356. 'email_alert_manager_on_new_doc',
  357. get_lang('E-mail on assignments submission by students'),
  358. get_lang('E-mail on assignments submission by studentsActivate'),
  359. 1
  360. );
  361. $group[] = $form->createElement(
  362. 'radio',
  363. 'email_alert_manager_on_new_doc',
  364. null,
  365. get_lang('E-mail on assignments submission by studentsActivateOnlyForTeachers'),
  366. 3
  367. );
  368. $group[] = $form->createElement(
  369. 'radio',
  370. 'email_alert_manager_on_new_doc',
  371. null,
  372. get_lang('E-mail on assignments submission by studentsActivateOnlyForStudents'),
  373. 2
  374. );
  375. $group[] = $form->createElement(
  376. 'radio',
  377. 'email_alert_manager_on_new_doc',
  378. null,
  379. get_lang('E-mail on assignments submission by studentsDeactivate'),
  380. 0
  381. );
  382. $globalGroup[get_lang('E-mail on assignments submission by students')] = $group;
  383. $group = [];
  384. $group[] = $form->createElement(
  385. 'radio',
  386. 'email_alert_on_new_doc_dropbox',
  387. get_lang('E-mail users on dropbox file reception'),
  388. get_lang('E-mail users on dropbox file receptionActivate'),
  389. 1
  390. );
  391. $group[] = $form->createElement(
  392. 'radio',
  393. 'email_alert_on_new_doc_dropbox',
  394. null,
  395. get_lang('E-mail users on dropbox file receptionDeactivate'),
  396. 0
  397. );
  398. $globalGroup[get_lang('E-mail users on dropbox file reception')] = $group;
  399. // Exercises notifications
  400. $emailAlerts = ExerciseLib::getNotificationSettings();
  401. $group = [];
  402. foreach ($emailAlerts as $itemId => $label) {
  403. $group[] = $form->createElement(
  404. 'checkbox',
  405. 'email_alert_manager_on_new_quiz[]',
  406. null,
  407. $label,
  408. ['value' => $itemId]
  409. );
  410. }
  411. $globalGroup[get_lang('Tests')] = $group;
  412. $group = [];
  413. $group[] = $form->createElement(
  414. 'radio',
  415. 'email_to_teachers_on_new_work_feedback',
  416. get_lang('E-mail to teachers on new user\'s student publication feedback.'),
  417. get_lang('Yes'),
  418. 1
  419. );
  420. $group[] = $form->createElement(
  421. 'radio',
  422. 'email_to_teachers_on_new_work_feedback',
  423. null,
  424. get_lang('No'),
  425. 2
  426. );
  427. $globalGroup[get_lang('E-mail to teachers on new user\'s student publication feedback.')] = $group;
  428. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  429. $globalGroup[] = $myButton;
  430. $form->addPanelOption(
  431. 'email-notifications',
  432. get_lang('E-mail notifications'),
  433. $globalGroup,
  434. 'mail.png',
  435. false,
  436. 'accordionSettings'
  437. );
  438. $group = [];
  439. $group[] = $form->createElement(
  440. 'radio',
  441. 'allow_user_edit_agenda',
  442. get_lang('Allow learners to edit the agenda'),
  443. get_lang('Allow learners to edit the agendaActivate'),
  444. 1
  445. );
  446. $group[] = $form->createElement('radio', 'allow_user_edit_agenda', null, get_lang('Allow learners to edit the agendaDeactivate'), 0);
  447. $group2 = [];
  448. $group2[] = $form->createElement(
  449. 'radio',
  450. 'allow_user_edit_announcement',
  451. get_lang('Allow learners to edit announcements'),
  452. get_lang('Allow learners to edit announcementsActivate'),
  453. 1
  454. );
  455. $group2[] = $form->createElement(
  456. 'radio',
  457. 'allow_user_edit_announcement',
  458. null,
  459. get_lang('Allow learners to edit announcementsDeactivate'),
  460. 0
  461. );
  462. $group3 = [];
  463. $group3[] = $form->createElement(
  464. 'radio',
  465. 'allow_user_image_forum',
  466. get_lang('User picture in forum'),
  467. get_lang('User picture in forumActivate'),
  468. 1
  469. );
  470. $group3[] = $form->createElement('radio', 'allow_user_image_forum', null, get_lang('User picture in forumDeactivate'), 0);
  471. $group4 = [];
  472. $group4[] = $form->createElement(
  473. 'radio',
  474. 'allow_user_view_user_list',
  475. get_lang('Allow user view user list'),
  476. get_lang('Allow user view user listActivate'),
  477. 1
  478. );
  479. $group4[] = $form->createElement(
  480. 'radio',
  481. 'allow_user_view_user_list',
  482. null,
  483. get_lang('Allow user view user listDeactivate'),
  484. 0
  485. );
  486. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  487. $globalGroup = [
  488. get_lang('Allow learners to edit the agenda') => $group,
  489. get_lang('Allow learners to edit announcements') => $group2,
  490. get_lang('User picture in forum') => $group3,
  491. get_lang('Allow user view user list') => $group4,
  492. '' => $myButton,
  493. ];
  494. $form->addPanelOption(
  495. 'users',
  496. get_lang('User rights'),
  497. $globalGroup,
  498. 'user.png',
  499. false,
  500. 'accordionSettings'
  501. );
  502. // CHAT SETTINGS
  503. $group = [];
  504. $group[] = $form->createElement(
  505. 'radio',
  506. 'allow_open_chat_window',
  507. get_lang('Open chat in a new Window'),
  508. get_lang('Activate open the chat in a new window'),
  509. 1
  510. );
  511. $group[] = $form->createElement('radio', 'allow_open_chat_window', null, get_lang('Deactivate open the chat in a new window'), 0);
  512. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  513. $globalGroup = [
  514. get_lang('Open chat in a new Window') => $group,
  515. '' => $myButton,
  516. ];
  517. $form->addPanelOption(
  518. 'chat',
  519. get_lang('Chat settings'),
  520. $globalGroup,
  521. 'chat.png',
  522. false,
  523. 'accordionSettings'
  524. );
  525. $globalGroup = [];
  526. $group = [];
  527. $group[] = $form->createElement(
  528. 'radio',
  529. 'enable_lp_auto_launch',
  530. get_lang('Enable learning path auto-launch'),
  531. get_lang('Redirect to a selected learning path'),
  532. 1
  533. );
  534. $group[] = $form->createElement(
  535. 'radio',
  536. 'enable_lp_auto_launch',
  537. get_lang('Enable learning path auto-launch'),
  538. get_lang('Redirect to the learning paths list'),
  539. 2
  540. );
  541. $group[] = $form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0);
  542. $globalGroup[get_lang('Enable learning path auto-launch')] = $group;
  543. if (api_get_setting('allow_course_theme') == 'true') {
  544. // Allow theme into Learning path
  545. $group = [];
  546. $group[] = $form->createElement(
  547. 'radio',
  548. 'allow_learning_path_theme',
  549. get_lang('Enable course themes'),
  550. get_lang('Enable course themesAllow'),
  551. 1
  552. );
  553. $group[] = $form->createElement(
  554. 'radio',
  555. 'allow_learning_path_theme',
  556. null,
  557. get_lang('Enable course themesDisallow'),
  558. 0
  559. );
  560. $globalGroup[get_lang("Enable course themes")] = $group;
  561. }
  562. $allowLPReturnLink = api_get_setting('allow_lp_return_link');
  563. if ($allowLPReturnLink === 'true') {
  564. $group = [
  565. $form->createElement(
  566. 'radio',
  567. 'lp_return_link',
  568. get_lang('Learning path return link'),
  569. get_lang('Redirect to the learning paths list'),
  570. 1
  571. ),
  572. $form->createElement(
  573. 'radio',
  574. 'lp_return_link',
  575. null,
  576. get_lang('Redirect to Course home'),
  577. 0
  578. ),
  579. $form->createElement(
  580. 'radio',
  581. 'lp_return_link',
  582. null,
  583. get_lang('My courses'),
  584. 2
  585. ),
  586. ];
  587. $globalGroup[get_lang("Learning path return link")] = $group;
  588. }
  589. $exerciseInvisible = api_get_setting('exercise_invisible_in_session');
  590. $configureExerciseVisibility = api_get_setting('configure_exercise_visibility_in_course');
  591. if ($exerciseInvisible === 'true' &&
  592. $configureExerciseVisibility === 'true'
  593. ) {
  594. $group = [
  595. $form->createElement(
  596. 'radio',
  597. 'exercise_invisible_in_session',
  598. get_lang('TestinvisibleInSession'),
  599. get_lang('Yes'),
  600. 1
  601. ),
  602. $form->createElement(
  603. 'radio',
  604. 'exercise_invisible_in_session',
  605. null,
  606. get_lang('No'),
  607. 0
  608. ),
  609. ];
  610. $globalGroup[get_lang("TestinvisibleInSession")] = $group;
  611. }
  612. if ($isEditable) {
  613. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  614. $globalGroup[] = $myButton;
  615. } else {
  616. // Is it allowed to edit the course settings?
  617. if (!$isEditable) {
  618. $disabled_output = "disabled";
  619. }
  620. $form->freeze();
  621. }
  622. $form->addPanelOption(
  623. 'config_lp',
  624. get_lang('Learning path settings'),
  625. $globalGroup,
  626. 'scorms.png',
  627. false,
  628. 'accordionSettings'
  629. );
  630. if (api_get_configuration_value('allow_exercise_auto_launch')) {
  631. $globalGroup = [];
  632. // Auto launch exercise
  633. $group = [];
  634. $group[] = $form->createElement(
  635. 'radio',
  636. 'enable_exercise_auto_launch',
  637. get_lang('Auto-launch for exercises'),
  638. get_lang('Redirect to the selected exercise'),
  639. 1
  640. );
  641. $group[] = $form->createElement(
  642. 'radio',
  643. 'enable_exercise_auto_launch',
  644. get_lang('Auto-launch for exercises'),
  645. get_lang('Redirect to the exercises list'),
  646. 2
  647. );
  648. $group[] = $form->createElement('radio', 'enable_exercise_auto_launch', null, get_lang('Deactivate'), 0);
  649. $globalGroup[get_lang("Auto-launch for exercises")] = $group;
  650. if ($isEditable) {
  651. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  652. $globalGroup[] = $myButton;
  653. } else {
  654. // Is it allowed to edit the course settings?
  655. if (!$isEditable) {
  656. $disabled_output = "disabled";
  657. }
  658. $form->freeze();
  659. }
  660. $form->addPanelOption(
  661. 'config_exercise',
  662. get_lang('Test'),
  663. $globalGroup,
  664. 'quiz.png',
  665. false,
  666. 'accordionSettings'
  667. );
  668. }
  669. // *************** START THEMATIC *************/
  670. $group = [];
  671. $group[] = $form->createElement(
  672. 'radio',
  673. 'display_info_advance_inside_homecourse',
  674. get_lang('Information on thematic advance on course homepage'),
  675. get_lang('Display information about the last completed topic'),
  676. 1
  677. );
  678. $group[] = $form->createElement(
  679. 'radio',
  680. 'display_info_advance_inside_homecourse',
  681. null,
  682. get_lang('Display information about the next uncompleted topic'),
  683. 2
  684. );
  685. $group[] = $form->createElement(
  686. 'radio',
  687. 'display_info_advance_inside_homecourse',
  688. null,
  689. get_lang('Display information about the next uncompleted topicAndLastDoneAdvance'),
  690. 3
  691. );
  692. $group[] = $form->createElement(
  693. 'radio',
  694. 'display_info_advance_inside_homecourse',
  695. null,
  696. get_lang('Do not display progress'),
  697. 0
  698. );
  699. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  700. $globalGroup = [
  701. get_lang('Information on thematic advance on course homepage') => $group,
  702. '' => $myButton,
  703. ];
  704. $form->addPanelOption(
  705. 'thematic',
  706. get_lang('Thematic advance configuration'),
  707. $globalGroup,
  708. 'course_progress.png',
  709. false,
  710. 'accordionSettings'
  711. );
  712. if (api_get_setting('allow_public_certificates') === 'true') {
  713. $group = [];
  714. $group[] = $form->createElement(
  715. 'radio',
  716. 'allow_public_certificates',
  717. get_lang('Learner certificates are public'),
  718. get_lang('Yes'),
  719. 1
  720. );
  721. $group[] = $form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0);
  722. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  723. $globalGroup = [
  724. get_lang('Learner certificates are public') => $group,
  725. '' => $myButton,
  726. ];
  727. $form->addPanelOption(
  728. 'certificate',
  729. get_lang('Certificates'),
  730. $globalGroup,
  731. null,
  732. false,
  733. 'accordionSettings'
  734. );
  735. }
  736. // Forum settings
  737. $group = [
  738. $form->createElement('radio', 'enable_forum_auto_launch', null, get_lang('Redirect to forums list'), 1),
  739. $form->createElement('radio', 'enable_forum_auto_launch', null, get_lang('Disabled'), 2),
  740. ];
  741. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  742. // Forum settings
  743. $groupNotification = [
  744. $form->createElement('radio', 'hide_forum_notifications', null, get_lang('Yes'), 1),
  745. $form->createElement('radio', 'hide_forum_notifications', null, get_lang('No'), 2),
  746. ];
  747. $addUsers = [
  748. $form->createElement('radio', 'subscribe_users_to_forum_notifications', null, get_lang('Yes'), 1),
  749. $form->createElement('radio', 'subscribe_users_to_forum_notifications', null, get_lang('No'), 2),
  750. ];
  751. $globalGroup = [
  752. get_lang('Enable forum auto-launch') => $group,
  753. get_lang('Hide forum notifications') => $groupNotification,
  754. get_lang('Subscribe automatically all users to all forum notifications') => $addUsers,
  755. '' => $myButton,
  756. ];
  757. $form->addPanelOption(
  758. 'forum',
  759. get_lang('Forum'),
  760. $globalGroup,
  761. 'forum.png',
  762. false,
  763. 'accordionSettings'
  764. );
  765. // Student publication
  766. $group = [
  767. $form->createElement('radio', 'show_score', null, get_lang('New documents are visible for all users'), 0),
  768. $form->createElement('radio', 'show_score', null, get_lang('New documents are only visible for the teacher(s)'), 1),
  769. ];
  770. $group2 = [
  771. $form->createElement('radio', 'student_delete_own_publication', null, get_lang('Yes'), 1),
  772. $form->createElement('radio', 'student_delete_own_publication', null, get_lang('No'), 0),
  773. ];
  774. $myButton = $form->addButtonSave(get_lang('Save settings'), 'submit_save', true);
  775. $globalGroup = [
  776. get_lang('Default setting for the visibility of newly posted files') => $group,
  777. get_lang('Allow learners to delete their own publications') => $group2,
  778. '' => $myButton,
  779. ];
  780. $form->addPanelOption(
  781. 'student-publication',
  782. get_lang('Assignments'),
  783. $globalGroup,
  784. 'work.png',
  785. false,
  786. 'accordionSettings'
  787. );
  788. $button = Display::toolbarButton(
  789. get_lang('Configure external tools'),
  790. api_get_path(WEB_PUBLIC_PATH)."courses/$course_code/lti/",
  791. 'cog',
  792. 'primary'
  793. );
  794. $html = [
  795. $form->createElement('html', '<p>'.get_lang('LTI intro tool').'</p>'.$button),
  796. ];
  797. $form->addPanelOption(
  798. 'lti_tool',
  799. $translator->trans('External tools'),
  800. $html,
  801. 'plugin.png',
  802. false,
  803. 'accordionSettings'
  804. );
  805. // Plugin course settings
  806. $appPlugin = new AppPlugin();
  807. $appPlugin->add_course_settings_form($form);
  808. $form->addHtml('</div>');
  809. // Get all the course information
  810. $all_course_information = CourseManager::get_course_information($_course['sysCode']);
  811. // Set the default values of the form
  812. $values = [];
  813. $values['title'] = $_course['name'];
  814. $values['category_code'] = $_course['categoryCode'];
  815. $values['course_language'] = $_course['language'];
  816. $values['department_name'] = $_course['extLink']['name'];
  817. $values['department_url'] = $_course['extLink']['url'];
  818. $values['visibility'] = $_course['visibility'];
  819. $values['subscribe'] = $_course['subscribe'];
  820. $values['unsubscribe'] = $_course['unsubscribe'];
  821. $values['course_registration_password'] = $all_course_information['registration_code'];
  822. $values['legal'] = $all_course_information['legal'];
  823. $values['activate_legal'] = $all_course_information['activate_legal'];
  824. $values['show_score'] = $all_course_information['show_score'];
  825. $courseSettings = CourseManager::getCourseSettingVariables($appPlugin);
  826. foreach ($courseSettings as $setting) {
  827. $result = api_get_course_setting($setting);
  828. if ($result != '-1') {
  829. $values[$setting] = $result;
  830. }
  831. }
  832. // make sure new settings have a clear default value
  833. if (!isset($values['student_delete_own_publication'])) {
  834. $values['student_delete_own_publication'] = 0;
  835. }
  836. $form->setDefaults($values);
  837. // Validate form
  838. if ($form->validate() && $isEditable) {
  839. $updateValues = $form->getSubmitValues();
  840. // update course picture
  841. $picture = $_FILES['picture'];
  842. if (!empty($picture['name'])) {
  843. $uploadFile = $request->files->get('picture');
  844. // Remove if exists @todo just replace don't delete everything.
  845. if (!empty($courseEntity->getResourceNodeIllustration())) {
  846. $em->remove($courseEntity->getResourceNodeIllustration());
  847. $em->flush();
  848. }
  849. $illustration = new \Chamilo\CoreBundle\Entity\Illustration();
  850. $em->persist($illustration);
  851. $repo->addResourceNode($illustration, api_get_user_entity(api_get_user_id()), $courseEntity);
  852. $file = $repo->addFileToResource($illustration, $uploadFile);
  853. if ($file) {
  854. $file->setCrop($updateValues['picture_crop_result']);
  855. $em->persist($file);
  856. $em->persist($illustration);
  857. $em->flush();
  858. }
  859. }
  860. $visibility = $updateValues['visibility'];
  861. $deletePicture = isset($updateValues['delete_picture']) ? $updateValues['delete_picture'] : '';
  862. if ($deletePicture) {
  863. $image = $courseEntity->getResourceNodeIllustration();
  864. if ($image) {
  865. $em->remove($image);
  866. $em->flush();
  867. }
  868. }
  869. global $_configuration;
  870. $urlId = api_get_current_access_url_id();
  871. if (isset($_configuration[$urlId]) &&
  872. isset($_configuration[$urlId]['hosting_limit_active_courses']) &&
  873. $_configuration[$urlId]['hosting_limit_active_courses'] > 0
  874. ) {
  875. $courseInfo = api_get_course_info_by_id($courseId);
  876. // Check if
  877. if ($courseInfo['visibility'] == COURSE_VISIBILITY_HIDDEN &&
  878. $visibility != $courseInfo['visibility']
  879. ) {
  880. $num = CourseManager::countActiveCourses($urlId);
  881. if ($num >= $_configuration[$urlId]['hosting_limit_active_courses']) {
  882. api_warn_hosting_contact('hosting_limit_active_courses');
  883. Display::addFlash(
  884. Display::return_message(get_lang('Sorry, this installation has an active courses limit, which has now been reached. You can still create new courses, but only if you hide/disable at least one existing active course. To do this, edit a course from the administration courses list, and change the visibility to \'hidden\', then try creating this course again. To increase the maximum number of active courses allowed on this Chamilo installation, please contact your hosting provider or, if available, upgrade to a superior hosting plan.'))
  885. );
  886. $url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.api_get_cidreq();
  887. header("Location: $url");
  888. exit;
  889. }
  890. }
  891. }
  892. $pdf_export_watermark_path = isset($_FILES['pdf_export_watermark_path'])
  893. ? $_FILES['pdf_export_watermark_path']
  894. : null;
  895. if (!empty($pdf_export_watermark_path['name'])) {
  896. $pdf_export_watermark_path_result = PDF::upload_watermark(
  897. $pdf_export_watermark_path['name'],
  898. $pdf_export_watermark_path['tmp_name'],
  899. $course_code
  900. );
  901. unset($updateValues['pdf_export_watermark_path']);
  902. }
  903. $activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : 0;
  904. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  905. $params = [
  906. 'title' => $updateValues['title'],
  907. 'course_language' => $updateValues['course_language'],
  908. 'category_code' => $updateValues['category_code'],
  909. 'department_name' => $updateValues['department_name'],
  910. 'department_url' => $updateValues['department_url'],
  911. 'visibility' => $updateValues['visibility'],
  912. 'subscribe' => $updateValues['subscribe'],
  913. 'unsubscribe' => $updateValues['unsubscribe'],
  914. 'legal' => $updateValues['legal'],
  915. 'activate_legal' => $activeLegal,
  916. 'registration_code' => $updateValues['course_registration_password'],
  917. 'show_score' => $updateValues['show_score'],
  918. ];
  919. Database::update($table_course, $params, ['id = ?' => $courseId]);
  920. // Insert/Updates course_settings table
  921. foreach ($courseSettings as $setting) {
  922. $value = isset($updateValues[$setting]) ? $updateValues[$setting] : null;
  923. CourseManager::saveCourseConfigurationSetting(
  924. $appPlugin,
  925. $setting,
  926. $value,
  927. api_get_course_int_id()
  928. );
  929. }
  930. // update the extra fields
  931. $courseFieldValue = new ExtraFieldValue('course');
  932. $courseFieldValue->saveFieldValues($updateValues);
  933. $appPlugin->saveCourseSettingsHook($updateValues);
  934. $courseParams = api_get_cidreq();
  935. $cidReset = true;
  936. $cidReq = $course_code;
  937. Display::addFlash(Display::return_message(get_lang('Update successful')));
  938. $url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.$courseParams;
  939. header("Location: $url");
  940. exit;
  941. }
  942. if ($show_delete_watermark_text_message) {
  943. Display::addFlash(
  944. Display::return_message(get_lang('File deleted'), 'normal')
  945. );
  946. }
  947. //Template Course Info
  948. $tpl = new Template($nameTools);
  949. Display::display_header($nameTools, 'Settings');
  950. //$form->display();
  951. $tpl->assign('course_settings', $form->returnForm());
  952. $courseInfoLayout = $tpl->get_template("course_info/index.html.twig");
  953. $content = $tpl->fetch($courseInfoLayout);
  954. echo $content;
  955. Display::display_footer();