lp_edit.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Script allowing simple edition of learnpath information (title, description, etc).
  6. *
  7. * @package chamilo.learnpath
  8. *
  9. * @author Yannick Warnier <ywarnier@beeznest.org>
  10. */
  11. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  12. api_protect_course_script();
  13. /** @var learnpath $learnPath */
  14. $learnPath = Session::read('oLP');
  15. $nameTools = get_lang('Doc');
  16. $this_section = SECTION_COURSES;
  17. Event::event_access_tool(TOOL_LEARNPATH);
  18. $lpId = $learnPath->get_id();
  19. if (api_is_in_gradebook()) {
  20. $interbreadcrumb[] = [
  21. 'url' => Category::getUrl(),
  22. 'name' => get_lang('ToolGradebook'),
  23. ];
  24. }
  25. $interbreadcrumb[] = [
  26. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  27. 'name' => get_lang('LearningPaths'),
  28. ];
  29. $interbreadcrumb[] = [
  30. 'url' => api_get_self()."?action=build&lp_id=".$lpId.'&'.api_get_cidreq(),
  31. 'name' => $learnPath->get_name(),
  32. ];
  33. $htmlHeadXtra[] = '<script>
  34. function activate_start_date() {
  35. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  36. document.getElementById(\'start_date_div\').style.display = \'block\';
  37. } else {
  38. document.getElementById(\'start_date_div\').style.display = \'none\';
  39. }
  40. }
  41. function activate_end_date() {
  42. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  43. document.getElementById(\'end_date_div\').style.display = \'block\';
  44. } else {
  45. document.getElementById(\'end_date_div\').style.display = \'none\';
  46. }
  47. }
  48. </script>';
  49. $defaults = [];
  50. $form = new FormValidator(
  51. 'form1',
  52. 'post',
  53. 'lp_controller.php?'.api_get_cidreq()
  54. );
  55. // Form title
  56. $form->addElement('header', get_lang('EditLPSettings'));
  57. // Title
  58. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LearnpathTitle')), ['size' => 43]);
  59. $form->applyFilter('lp_name', 'html_filter');
  60. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  61. $form->addElement('hidden', 'lp_encoding');
  62. $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
  63. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  64. // Hide toc frame
  65. $form->addElement(
  66. 'checkbox',
  67. 'hide_toc_frame',
  68. null,
  69. get_lang('HideTocFrame')
  70. );
  71. if (api_get_setting('allow_course_theme') === 'true') {
  72. $mycourselptheme = api_get_course_setting('allow_learning_path_theme');
  73. if (!empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  74. //LP theme picker
  75. $theme_select = $form->addElement('SelectTheme', 'lp_theme', get_lang('Theme'));
  76. $form->applyFilter('lp_theme', 'trim');
  77. $s_theme = $learnPath->get_theme();
  78. $theme_select->setSelected($s_theme); //default
  79. }
  80. }
  81. // Author
  82. $form->addElement(
  83. 'html_editor',
  84. 'lp_author',
  85. get_lang('Author'),
  86. ['size' => 80],
  87. ['ToolbarSet' => 'LearningPathAuthor', 'Width' => '100%', 'Height' => '200px']
  88. );
  89. $form->applyFilter('lp_author', 'html_filter');
  90. // LP image
  91. if (strlen($learnPath->get_preview_image()) > 0) {
  92. $show_preview_image = '<img src='.api_get_path(WEB_COURSE_PATH).api_get_course_path()
  93. .'/upload/learning_path/images/'.$learnPath->get_preview_image().'>';
  94. $form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
  95. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  96. }
  97. $label = ($learnPath->get_preview_image() != '' ? get_lang('UpdateImage') : get_lang('AddImage'));
  98. $form->addElement('file', 'lp_preview_image', [$label, get_lang('ImageWillResizeMsg')]);
  99. $form->addRule('lp_preview_image', get_lang('OnlyImagesAllowed'), 'filetype', ['jpg', 'jpeg', 'png', 'gif']);
  100. // Search terms (only if search is activated).
  101. if (api_get_setting('search_enabled') === 'true') {
  102. $specific_fields = get_specific_field_list();
  103. foreach ($specific_fields as $specific_field) {
  104. $form->addElement('text', $specific_field['code'], $specific_field['name']);
  105. $filter = [
  106. 'c_id' => "'".api_get_course_int_id()."'",
  107. 'field_id' => $specific_field['id'],
  108. 'ref_id' => $learnPath->lp_id,
  109. 'tool_id' => '\''.TOOL_LEARNPATH.'\'',
  110. ];
  111. $values = get_specific_field_values_list($filter, ['value']);
  112. if (!empty($values)) {
  113. $arr_str_values = [];
  114. foreach ($values as $value) {
  115. $arr_str_values[] = $value['value'];
  116. }
  117. $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
  118. }
  119. }
  120. }
  121. $hideTableOfContents = $learnPath->getHideTableOfContents();
  122. $defaults['lp_encoding'] = Security::remove_XSS($learnPath->encoding);
  123. $defaults['lp_name'] = Security::remove_XSS($learnPath->get_name());
  124. $defaults['lp_author'] = Security::remove_XSS($learnPath->get_author());
  125. $defaults['hide_toc_frame'] = $hideTableOfContents;
  126. $defaults['category_id'] = $learnPath->getCategoryId();
  127. $defaults['accumulate_scorm_time'] = $learnPath->getAccumulateScormTime();
  128. $expired_on = $learnPath->expired_on;
  129. $publicated_on = $learnPath->publicated_on;
  130. // Prerequisites
  131. $form->addElement('html', '<div class="form-group">');
  132. $items = $learnPath->display_lp_prerequisites_list();
  133. $form->addElement('html', '<label class="col-md-2">'.get_lang('LearnpathPrerequisites').'</label>');
  134. $form->addElement('html', '<div class="col-md-8">');
  135. $form->addElement('html', $items);
  136. $form->addElement('html', '<div class="help-block">'.get_lang('LpPrerequisiteDescription').'</div>');
  137. $form->addElement('html', '</div>');
  138. $form->addElement('html', '<div class="col-md-2"></div>');
  139. $form->addElement('html', '</div>');
  140. //Start date
  141. $form->addElement(
  142. 'checkbox',
  143. 'activate_start_date_check',
  144. null,
  145. get_lang('EnableStartTime'),
  146. ['onclick' => 'activate_start_date()']
  147. );
  148. $display_date = 'none';
  149. if (!empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00') {
  150. $display_date = 'block';
  151. $defaults['activate_start_date_check'] = 1;
  152. }
  153. $form->addElement('html', '<div id="start_date_div" style="display:'.$display_date.';">');
  154. $form->addDateTimePicker('publicated_on', get_lang('PublicationDate'));
  155. $form->addElement('html', '</div>');
  156. //End date
  157. $form->addElement(
  158. 'checkbox',
  159. 'activate_end_date_check',
  160. null,
  161. get_lang('EnableEndTime'),
  162. ['onclick' => 'activate_end_date()']
  163. );
  164. $display_date = 'none';
  165. if (!empty($expired_on)) {
  166. $display_date = 'block';
  167. $defaults['activate_end_date_check'] = 1;
  168. }
  169. $form->addElement('html', '<div id="end_date_div" style="display:'.$display_date.';">');
  170. $form->addDateTimePicker('expired_on', get_lang('ExpirationDate'));
  171. $form->addElement('html', '</div>');
  172. if (api_is_platform_admin()) {
  173. $form->addElement('checkbox', 'use_max_score', null, get_lang('UseMaxScore100'));
  174. $defaults['use_max_score'] = $learnPath->use_max_score;
  175. }
  176. $subscriptionSettings = learnpath::getSubscriptionSettings();
  177. if ($subscriptionSettings['allow_add_users_to_lp']) {
  178. $form->addElement(
  179. 'checkbox',
  180. 'subscribe_users',
  181. null,
  182. get_lang('SubscribeUsersToLp')
  183. );
  184. }
  185. // accumulate_scorm_time
  186. $form->addElement(
  187. 'checkbox',
  188. 'accumulate_scorm_time',
  189. [null, get_lang('AccumulateScormTimeInfo')],
  190. get_lang('AccumulateScormTime')
  191. );
  192. $enableLpExtraFields = false;
  193. if ($enableLpExtraFields) {
  194. $extraField = new ExtraField('lp');
  195. $extra = $extraField->addElements($form, $lpId);
  196. }
  197. $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, $lpId);
  198. // Submit button
  199. $form->addButtonSave(get_lang('SaveLPSettings'));
  200. // Hidden fields
  201. $form->addElement('hidden', 'action', 'update_lp');
  202. $form->addElement('hidden', 'lp_id', $lpId);
  203. if ($enableLpExtraFields) {
  204. $htmlHeadXtra[] = '<script>
  205. $(function() {
  206. '.$extra['jquery_ready_content'].'
  207. });
  208. </script>';
  209. }
  210. $htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'</script>';
  211. $defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00'
  212. ? api_get_local_time($publicated_on)
  213. : null;
  214. $defaults['expired_on'] = (!empty($expired_on))
  215. ? api_get_local_time($expired_on)
  216. : date('Y-m-d 12:00:00', time() + 84600);
  217. $defaults['subscribe_users'] = $learnPath->getSubscribeUsers();
  218. $defaults['skills'] = array_keys($skillList);
  219. $form->setDefaults($defaults);
  220. Display::display_header(get_lang('CourseSettings'), 'Path');
  221. echo $learnPath->build_action_menu(false, false, true, false);
  222. echo '<div class="row">';
  223. echo '<div class="'.($hideTableOfContents ? 'col-md-12' : 'col-md-8').'" id="pnl-frm">';
  224. $form->display();
  225. echo '</div>';
  226. echo '<div class="'.($hideTableOfContents ? 'hide' : 'col-md-4').' text-right" id="pnl-toc">';
  227. echo Display::return_icon('course_setting_layout.png');
  228. echo '</div>';
  229. echo '</div>';
  230. echo "
  231. <script>
  232. $(document).on('ready', function () {
  233. $('[name=\'hide_toc_frame\']').on('change', function() {
  234. $('#pnl-frm').toggleClass('col-md-8').toggleClass('col-sm-12');
  235. $('#pnl-toc').toggleClass('col-md-4').toggleClass('hide');
  236. });
  237. });
  238. </script>
  239. ";
  240. Display::display_footer();