lp_edit.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. // Time Control
  141. if (Tracking::minimunTimeAvailable(api_get_session_id(), api_get_course_int_id())) {
  142. $accumulateTime = $_SESSION['oLP']->getAccumulateWorkTime();
  143. $form->addText('accumulate_work_time', [get_lang('LpMinTime'), get_lang('LpMinTimeDescription')]);
  144. $defaults['accumulate_work_time'] = $accumulateTime;
  145. }
  146. // Start date
  147. $form->addElement(
  148. 'checkbox',
  149. 'activate_start_date_check',
  150. null,
  151. get_lang('EnableStartTime'),
  152. ['onclick' => 'activate_start_date()']
  153. );
  154. $display_date = 'none';
  155. if (!empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00') {
  156. $display_date = 'block';
  157. $defaults['activate_start_date_check'] = 1;
  158. }
  159. $form->addElement('html', '<div id="start_date_div" style="display:'.$display_date.';">');
  160. $form->addDateTimePicker('publicated_on', get_lang('PublicationDate'));
  161. $form->addElement('html', '</div>');
  162. //End date
  163. $form->addElement(
  164. 'checkbox',
  165. 'activate_end_date_check',
  166. null,
  167. get_lang('EnableEndTime'),
  168. ['onclick' => 'activate_end_date()']
  169. );
  170. $display_date = 'none';
  171. if (!empty($expired_on)) {
  172. $display_date = 'block';
  173. $defaults['activate_end_date_check'] = 1;
  174. }
  175. $form->addElement('html', '<div id="end_date_div" style="display:'.$display_date.';">');
  176. $form->addDateTimePicker('expired_on', get_lang('ExpirationDate'));
  177. $form->addElement('html', '</div>');
  178. if (api_is_platform_admin()) {
  179. $form->addElement('checkbox', 'use_max_score', null, get_lang('UseMaxScore100'));
  180. $defaults['use_max_score'] = $learnPath->use_max_score;
  181. }
  182. $subscriptionSettings = learnpath::getSubscriptionSettings();
  183. if ($subscriptionSettings['allow_add_users_to_lp']) {
  184. $form->addElement(
  185. 'checkbox',
  186. 'subscribe_users',
  187. null,
  188. get_lang('SubscribeUsersToLp')
  189. );
  190. }
  191. // accumulate_scorm_time
  192. $form->addElement(
  193. 'checkbox',
  194. 'accumulate_scorm_time',
  195. [null, get_lang('AccumulateScormTimeInfo')],
  196. get_lang('AccumulateScormTime')
  197. );
  198. $options = learnpath::getIconSelect();
  199. if (!empty($options)) {
  200. $form->addSelect(
  201. 'extra_lp_icon',
  202. get_lang('Icon'),
  203. $options
  204. );
  205. $defaults['extra_lp_icon'] = learnpath::getSelectedIcon($lpId);
  206. }
  207. $enableLpExtraFields = false;
  208. if ($enableLpExtraFields) {
  209. $extraField = new ExtraField('lp');
  210. $extra = $extraField->addElements($form, $lpId);
  211. }
  212. $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, $lpId);
  213. // Submit button
  214. $form->addButtonSave(get_lang('SaveLPSettings'));
  215. // Hidden fields
  216. $form->addElement('hidden', 'action', 'update_lp');
  217. $form->addElement('hidden', 'lp_id', $lpId);
  218. if ($enableLpExtraFields) {
  219. $htmlHeadXtra[] = '<script>
  220. $(function() {
  221. '.$extra['jquery_ready_content'].'
  222. });
  223. </script>';
  224. }
  225. $htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'</script>';
  226. $defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00'
  227. ? api_get_local_time($publicated_on)
  228. : null;
  229. $defaults['expired_on'] = (!empty($expired_on))
  230. ? api_get_local_time($expired_on)
  231. : date('Y-m-d 12:00:00', time() + 84600);
  232. $defaults['subscribe_users'] = $learnPath->getSubscribeUsers();
  233. $defaults['skills'] = array_keys($skillList);
  234. $form->setDefaults($defaults);
  235. Display::display_header(get_lang('CourseSettings'), 'Path');
  236. echo $learnPath->build_action_menu(false, false, true, false);
  237. echo '<div class="row">';
  238. echo '<div class="'.($hideTableOfContents ? 'col-md-12' : 'col-md-8').'" id="pnl-frm">';
  239. $form->display();
  240. echo '</div>';
  241. echo '<div class="'.($hideTableOfContents ? 'hide' : 'col-md-4').' text-right" id="pnl-toc">';
  242. echo Display::return_icon('course_setting_layout.png');
  243. echo '</div>';
  244. echo '</div>';
  245. echo "
  246. <script>
  247. $(function() {
  248. $('[name=\'hide_toc_frame\']').on('change', function() {
  249. $('#pnl-frm').toggleClass('col-md-8').toggleClass('col-sm-12');
  250. $('#pnl-toc').toggleClass('col-md-4').toggleClass('hide');
  251. });
  252. });
  253. </script>
  254. ";
  255. Display::display_footer();