lp_edit.php 8.6 KB

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