lp_edit.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. global $charset;
  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. api_protect_course_script();
  15. if (api_is_in_gradebook()) {
  16. $interbreadcrumb[]= array(
  17. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  18. 'name' => get_lang('ToolGradebook')
  19. );
  20. }
  21. $learnpath = learnpath::getCurrentLpFromSession();
  22. $interbreadcrumb[] = array(
  23. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  24. 'name' => get_lang('LearningPaths'),
  25. );
  26. $interbreadcrumb[] = array(
  27. 'url' => api_get_self()."?action=build&lp_id=".$learnpath->get_id(
  28. ).'&'.api_get_cidreq(),
  29. 'name' => $learnpath->get_name(),
  30. );
  31. $htmlHeadXtra[] = '<script>
  32. function activate_start_date() {
  33. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  34. document.getElementById(\'start_date_div\').style.display = \'block\';
  35. } else {
  36. document.getElementById(\'start_date_div\').style.display = \'none\';
  37. }
  38. }
  39. function activate_end_date() {
  40. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  41. document.getElementById(\'end_date_div\').style.display = \'block\';
  42. } else {
  43. document.getElementById(\'end_date_div\').style.display = \'none\';
  44. }
  45. }
  46. </script>';
  47. $defaults=array();
  48. $form = new FormValidator('form1', 'post', 'lp_controller.php');
  49. // Form title
  50. $form->addElement('header', get_lang('EditLPSettings'));
  51. // Title
  52. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LearnpathTitle')), array('size' => 43));
  53. $form->applyFilter('lp_name', 'html_filter');
  54. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  55. $form->addElement('hidden', 'lp_encoding');
  56. $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
  57. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  58. // Origin
  59. /*
  60. $origin_select = $form->addElement('select', 'lp_maker', get_lang('Origin'));
  61. $lp_orig = $learnpath->get_maker();
  62. include 'content_makers.inc.php';
  63. foreach ($content_origins as $origin) {
  64. if ($lp_orig == $origin) {
  65. $s_selected_origin = $origin;
  66. }
  67. $origin_select->addOption($origin, $origin);
  68. }
  69. // Content proximity
  70. $content_proximity_select = $form->addElement('select', 'lp_proximity', get_lang('ContentProximity'));
  71. $lp_prox = $learnpath->get_proximity();
  72. if ($lp_prox != 'local') {
  73. $s_selected_proximity = 'remote';
  74. } else {
  75. $s_selected_proximity = 'local';
  76. }
  77. $content_proximity_select->addOption(get_lang('Local'), 'local');
  78. $content_proximity_select->addOption(get_lang('Remote'), 'remote');
  79. */
  80. //Hide toc frame
  81. $hide_toc_frame = $form->addElement(
  82. 'checkbox',
  83. 'hide_toc_frame',
  84. null,
  85. get_lang('HideTocFrame'),
  86. array('onclick' => '$("#lp_layout_column").toggle()')
  87. );
  88. if (api_get_setting('course.allow_course_theme') == 'true') {
  89. $mycourselptheme = api_get_course_setting('allow_learning_path_theme');
  90. if (!empty($mycourselptheme) && $mycourselptheme!=-1 && $mycourselptheme== 1) {
  91. //LP theme picker
  92. $theme_select = $form->addElement('SelectTheme', 'lp_theme', get_lang('Theme'));
  93. $form->applyFilter('lp_theme', 'trim');
  94. $s_theme = $learnpath->get_theme();
  95. $theme_select ->setSelected($s_theme); //default
  96. }
  97. }
  98. // Author
  99. $form->addHtmlEditor(
  100. 'lp_author',
  101. get_lang('Author'),
  102. array('size' => 80),
  103. array(
  104. 'ToolbarSet' => 'LearningPathAuthor',
  105. 'Width' => '100%',
  106. 'Height' => '150px',
  107. )
  108. );
  109. $form->applyFilter('lp_author', 'html_filter');
  110. // LP image
  111. $form->add_progress_bar();
  112. if (strlen($learnpath->get_preview_image()) > 0) {
  113. $show_preview_image = '<img src='.api_get_path(
  114. WEB_COURSE_PATH
  115. ).api_get_course_path(
  116. ).'/upload/learning_path/images/'.$learnpath->get_preview_image().'>';
  117. $form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
  118. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  119. }
  120. $label = ($learnpath->get_preview_image() != '' ? get_lang(
  121. 'UpdateImage'
  122. ) : get_lang('AddImage'));
  123. $form->addElement('file', 'lp_preview_image', array($label, get_lang('ImageWillResizeMsg')));
  124. $form->addRule('lp_preview_image', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif'));
  125. // Search terms (only if search is activated).
  126. if (api_get_setting('search.search_enabled') === 'true') {
  127. $specific_fields = get_specific_field_list();
  128. foreach ($specific_fields as $specific_field) {
  129. $form->addElement(
  130. 'text',
  131. $specific_field['code'],
  132. $specific_field['name']
  133. );
  134. $filter = array(
  135. 'c_id' => "'".api_get_course_int_id()."'",
  136. 'field_id' => $specific_field['id'],
  137. 'ref_id' => $learnpath->lp_id,
  138. 'tool_id' => '\''.TOOL_LEARNPATH.'\'',
  139. );
  140. $values = get_specific_field_values_list($filter, array('value'));
  141. if (!empty($values)) {
  142. $arr_str_values = array();
  143. foreach ($values as $value) {
  144. $arr_str_values[] = $value['value'];
  145. }
  146. $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
  147. }
  148. }
  149. }
  150. $defaults['lp_encoding'] = Security::remove_XSS($learnpath->encoding);
  151. $defaults['lp_name'] = Security::remove_XSS($learnpath->get_name());
  152. $defaults['lp_author'] = Security::remove_XSS($learnpath->get_author());
  153. $defaults['hide_toc_frame'] = Security::remove_XSS(
  154. $learnpath->get_hide_toc_frame()
  155. );
  156. $defaults['category_id'] = intval($learnpath->getCategoryId());
  157. $expired_on = $learnpath->expired_on;
  158. $publicated_on = $learnpath->publicated_on;
  159. // Prerequisites
  160. $form->addElement('html','<div class="form-group">');
  161. $items = $learnpath->display_lp_prerequisites_list();
  162. $form->addElement('html','<label class="col-md-2">'.get_lang('LearnpathPrerequisites').'</label>');
  163. $form->addElement('html','<div class="col-md-10">');
  164. $form->addElement('html',$items);
  165. $form->addElement('html', '<div class="help-block">'.get_lang('LpPrerequisiteDescription').'</div></div></div>');
  166. //Start date
  167. $form->addElement('checkbox', 'activate_start_date_check', null,get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
  168. $display_date = 'none';
  169. if ($publicated_on!='0000-00-00 00:00:00' && !empty($publicated_on)) {
  170. $display_date = 'block';
  171. $defaults['activate_start_date_check'] = 1;
  172. }
  173. $form->addElement('html','<div id="start_date_div" style="display:'.$display_date.';">');
  174. $form->addElement('DatePicker', 'publicated_on', get_lang('PublicationDate'));
  175. $form->addElement('html','</div>');
  176. //End date
  177. $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
  178. $display_date = 'none';
  179. if ($expired_on!='0000-00-00 00:00:00' && !empty($expired_on)) {
  180. $display_date = 'block';
  181. $defaults['activate_end_date_check'] = 1;
  182. }
  183. $form->addElement('html','<div id="end_date_div" style="display:'.$display_date.';">');
  184. $form->addElement('DatePicker', 'expired_on', get_lang('ExpirationDate'));
  185. $form->addElement('html','</div>');
  186. if (api_is_platform_admin()) {
  187. $form->addElement('checkbox', 'use_max_score', null, get_lang('UseMaxScore100'));
  188. $defaults['use_max_score'] = $learnpath->use_max_score;
  189. }
  190. $form->addElement('checkbox', 'subscribe_users', null, get_lang('SubscribeUsersToLp'));
  191. $enableLpExtraFields = false;
  192. if ($enableLpExtraFields) {
  193. $extraField = new ExtraField('lp');
  194. $extra = $extraField->addElements($form, $learnpath->get_id());
  195. }
  196. // Submit button
  197. $form->addButtonSave(get_lang('SaveLPSettings'));
  198. // Hidden fields
  199. $form->addElement('hidden', 'action', 'update_lp');
  200. $form->addElement('hidden', 'lp_id', $learnpath->get_id());
  201. if ($enableLpExtraFields) {
  202. $htmlHeadXtra[] = '<script>
  203. $(function() {
  204. ' . $extra['jquery_ready_content'] . '
  205. });
  206. </script>';
  207. }
  208. $defaults['publicated_on'] = ($publicated_on!='0000-00-00 00:00:00' && !empty($publicated_on))? api_get_local_time($publicated_on) : date('Y-m-d 12:00:00');
  209. $defaults['expired_on'] = ($expired_on !='0000-00-00 00:00:00' && !empty($expired_on) )? api_get_local_time($expired_on): date('Y-m-d 12:00:00',time()+84600);
  210. //$defaults['max_attempts'] = $learnpath->get_max_attempts();
  211. $defaults['subscribe_users'] = $learnpath->getSubscribeUsers();
  212. $form->setDefaults($defaults);
  213. Display::display_header(get_lang('CourseSettings'), 'Path');
  214. echo $learnpath->build_action_menu();
  215. echo '<div class="row">';
  216. if ($learnpath->get_hide_toc_frame() == 1) {
  217. echo '<div class="col-md-12">';
  218. $form -> display();
  219. echo '</div>';
  220. } else{
  221. echo '<div class="col-md-8">';
  222. $form -> display();
  223. echo '</div>';
  224. echo '<div class="col-md-4" align="center">';
  225. echo Display::return_icon(
  226. 'course_setting_layout.png'
  227. );
  228. echo '</div>';
  229. }
  230. echo '</div>';
  231. $learnpath->updateCurrentLpFromSession();