lp_edit.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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('Document');
  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('Assessments'),
  23. ];
  24. }
  25. $interbreadcrumb[] = [
  26. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  27. 'name' => get_lang('Learning paths'),
  28. ];
  29. $interbreadcrumb[] = [
  30. 'url' => api_get_self()."?action=build&lp_id=".$lpId.'&'.api_get_cidreq(),
  31. 'name' => $learnPath->getNameNoTags(),
  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('Edit'));
  57. // Title
  58. if (api_get_configuration_value('save_titles_as_html')) {
  59. $form->addHtmlEditor(
  60. 'lp_name',
  61. get_lang('Learning path name'),
  62. true,
  63. false,
  64. ['ToolbarSet' => 'TitleAsHtml']
  65. );
  66. } else {
  67. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('Title')), ['size' => 43]);
  68. }
  69. $form->applyFilter('lp_name', 'html_filter');
  70. $form->addRule('lp_name', get_lang('Required field'), 'required');
  71. $form->addElement('hidden', 'lp_encoding');
  72. $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
  73. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  74. // Hide toc frame
  75. $form->addElement(
  76. 'checkbox',
  77. 'hide_toc_frame',
  78. null,
  79. get_lang('Hide table of contents frame')
  80. );
  81. if (api_get_setting('allow_course_theme') === 'true') {
  82. $mycourselptheme = api_get_course_setting('allow_learning_path_theme');
  83. if (!empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
  84. //LP theme picker
  85. $theme_select = $form->addElement('SelectGraphical theme', 'lp_theme', get_lang('Graphical theme'));
  86. $form->applyFilter('lp_theme', 'trim');
  87. $s_theme = $learnPath->get_theme();
  88. $theme_select->setSelected($s_theme); //default
  89. }
  90. }
  91. // Author
  92. $form->addElement(
  93. 'html_editor',
  94. 'lp_author',
  95. get_lang('Author'),
  96. ['size' => 80],
  97. ['ToolbarSet' => 'LearningPathAuthor', 'Width' => '100%', 'Height' => '200px']
  98. );
  99. $form->applyFilter('lp_author', 'html_filter');
  100. // LP image
  101. if (strlen($learnPath->get_preview_image()) > 0) {
  102. $show_preview_image = '<img src='.api_get_path(WEB_COURSE_PATH).api_get_course_path()
  103. .'/upload/learning_path/images/'.$learnPath->get_preview_image().'>';
  104. $form->addElement('label', get_lang('Image preview'), $show_preview_image);
  105. $form->addElement('checkbox', 'remove_picture', null, get_lang('Remove picture'));
  106. }
  107. $label = $learnPath->get_preview_image() != '' ? get_lang('Update Image') : get_lang('Add image');
  108. $form->addElement('file', 'lp_preview_image', [$label, get_lang('Trainer picture will resize if needed')]);
  109. $form->addRule('lp_preview_image', get_lang('Only PNG, JPG or GIF images allowed'), 'filetype', ['jpg', 'jpeg', 'png', 'gif']);
  110. // Search terms (only if search is activated).
  111. if (api_get_setting('search_enabled') === 'true') {
  112. $specific_fields = get_specific_field_list();
  113. foreach ($specific_fields as $specific_field) {
  114. $form->addElement('text', $specific_field['code'], $specific_field['name']);
  115. $filter = [
  116. 'c_id' => "'".api_get_course_int_id()."'",
  117. 'field_id' => $specific_field['id'],
  118. 'ref_id' => $learnPath->lp_id,
  119. 'tool_id' => '\''.TOOL_LEARNPATH.'\'',
  120. ];
  121. $values = get_specific_field_values_list($filter, ['value']);
  122. if (!empty($values)) {
  123. $arr_str_values = [];
  124. foreach ($values as $value) {
  125. $arr_str_values[] = $value['value'];
  126. }
  127. $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
  128. }
  129. }
  130. }
  131. $hideTableOfContents = $learnPath->getHideTableOfContents();
  132. $defaults['lp_encoding'] = Security::remove_XSS($learnPath->encoding);
  133. $defaults['lp_name'] = Security::remove_XSS($learnPath->get_name());
  134. $defaults['lp_author'] = Security::remove_XSS($learnPath->get_author());
  135. $defaults['hide_toc_frame'] = $hideTableOfContents;
  136. $defaults['category_id'] = $learnPath->getCategoryId();
  137. $defaults['accumulate_scorm_time'] = $learnPath->getAccumulateScormTime();
  138. $expired_on = $learnPath->expired_on;
  139. $publicated_on = $learnPath->publicated_on;
  140. // Prerequisites
  141. $form->addElement('html', '<div class="form-group">');
  142. $items = $learnPath->display_lp_prerequisites_list();
  143. $form->addElement('html', '<label class="col-md-2">'.get_lang('Prerequisites').'</label>');
  144. $form->addElement('html', '<div class="col-md-8">');
  145. $form->addElement('html', $items);
  146. $form->addElement('html', '<div class="help-block">'.get_lang('Selecting another learning path as a prerequisite will hide the current prerequisite until the one in prerequisite is fully completed (100%)').'</div>');
  147. $form->addElement('html', '</div>');
  148. $form->addElement('html', '<div class="col-md-2"></div>');
  149. $form->addElement('html', '</div>');
  150. // Time Control
  151. if (Tracking::minimumTimeAvailable(api_get_session_id(), api_get_course_int_id())) {
  152. $accumulateTime = $_SESSION['oLP']->getAccumulateWorkTime();
  153. $form->addText('accumulate_work_time', [get_lang('Minimum time (minutes)'), get_lang('Minimum time (minutes)Description')]);
  154. $defaults['accumulate_work_time'] = $accumulateTime;
  155. }
  156. // Start date
  157. $form->addElement(
  158. 'checkbox',
  159. 'activate_start_date_check',
  160. null,
  161. get_lang('Enable start time'),
  162. ['onclick' => 'activate_start_date()']
  163. );
  164. $display_date = 'none';
  165. if (!empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00') {
  166. $display_date = 'block';
  167. $defaults['activate_start_date_check'] = 1;
  168. }
  169. $form->addElement('html', '<div id="start_date_div" style="display:'.$display_date.';">');
  170. $form->addDateTimePicker('publicated_on', get_lang('Publication date'));
  171. $form->addElement('html', '</div>');
  172. //End date
  173. $form->addElement(
  174. 'checkbox',
  175. 'activate_end_date_check',
  176. null,
  177. get_lang('Enable end time'),
  178. ['onclick' => 'activate_end_date()']
  179. );
  180. $display_date = 'none';
  181. if (!empty($expired_on)) {
  182. $display_date = 'block';
  183. $defaults['activate_end_date_check'] = 1;
  184. }
  185. $form->addElement('html', '<div id="end_date_div" style="display:'.$display_date.';">');
  186. $form->addDateTimePicker('expired_on', get_lang('Expiration date'));
  187. $form->addElement('html', '</div>');
  188. if (api_is_platform_admin()) {
  189. $form->addElement('checkbox', 'use_max_score', null, get_lang('Use default maximum score of 100'));
  190. $defaults['use_max_score'] = $learnPath->use_max_score;
  191. }
  192. $subscriptionSettings = learnpath::getSubscriptionSettings();
  193. if ($subscriptionSettings['allow_add_users_to_lp']) {
  194. $form->addElement(
  195. 'checkbox',
  196. 'subscribe_users',
  197. null,
  198. get_lang('Subscribe users to learning path')
  199. );
  200. }
  201. // accumulate_scorm_time
  202. $form->addElement(
  203. 'checkbox',
  204. 'accumulate_scorm_time',
  205. [null, get_lang('When enabled, the session time for SCORM Learning Paths will be cumulative, otherwise, it will only be counted from the last update time.')],
  206. get_lang('Accumulate SCORM session time')
  207. );
  208. $options = learnpath::getIconSelect();
  209. if (!empty($options)) {
  210. $form->addSelect(
  211. 'extra_lp_icon',
  212. get_lang('Icon'),
  213. $options
  214. );
  215. $defaults['extra_lp_icon'] = learnpath::getSelectedIcon($lpId);
  216. }
  217. $extraField = new ExtraField('lp');
  218. $extra = $extraField->addElements($form, $lpId, ['lp_icon']);
  219. $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, $lpId);
  220. // Submit button
  221. $form->addButtonSave(get_lang('Save course settings'));
  222. // Hidden fields
  223. $form->addElement('hidden', 'action', 'update_lp');
  224. $form->addElement('hidden', 'lp_id', $lpId);
  225. $htmlHeadXtra[] = '<script>
  226. $(function() {
  227. '.$extra['jquery_ready_content'].'
  228. });
  229. </script>';
  230. $htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'</script>';
  231. $defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00'
  232. ? api_get_local_time($publicated_on)
  233. : null;
  234. $defaults['expired_on'] = (!empty($expired_on))
  235. ? api_get_local_time($expired_on)
  236. : date('Y-m-d 12:00:00', time() + 84600);
  237. $defaults['subscribe_users'] = $learnPath->getSubscribeUsers();
  238. $defaults['skills'] = array_keys($skillList);
  239. $form->setDefaults($defaults);
  240. Display::display_header(get_lang('Course settings'), 'Path');
  241. echo $learnPath->build_action_menu(false, false, true, false);
  242. echo '<div class="row">';
  243. echo '<div class="'.($hideTableOfContents ? 'col-md-12' : 'col-md-8').'" id="pnl-frm">';
  244. $form->display();
  245. echo '</div>';
  246. echo '<div class="'.($hideTableOfContents ? 'hide' : 'col-md-4').' text-right" id="pnl-toc">';
  247. echo Display::return_icon('course_setting_layout.png');
  248. echo '</div>';
  249. echo '</div>';
  250. echo "
  251. <script>
  252. $(function() {
  253. $('[name=\'hide_toc_frame\']').on('change', function() {
  254. $('#pnl-frm').toggleClass('col-md-8').toggleClass('col-sm-12');
  255. $('#pnl-toc').toggleClass('col-md-4').toggleClass('hide');
  256. });
  257. });
  258. </script>
  259. ";
  260. Display::display_footer();