lp_edit.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_access_tool(TOOL_LEARNPATH);
  14. api_protect_course_script();
  15. if (isset($_SESSION['gradebook'])) {
  16. $gradebook = $_SESSION['gradebook'];
  17. }
  18. if (!empty($gradebook) && $gradebook == 'view') {
  19. $interbreadcrumb[] = array (
  20. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  21. 'name' => get_lang('ToolGradebook')
  22. );
  23. }
  24. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  25. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=".$_SESSION['oLP']->get_id(), 'name' => $_SESSION['oLP']->get_name());
  26. $htmlHeadXtra[] = '<script>
  27. function activate_start_date() {
  28. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  29. document.getElementById(\'start_date_div\').style.display = \'block\';
  30. } else {
  31. document.getElementById(\'start_date_div\').style.display = \'none\';
  32. }
  33. }
  34. function activate_end_date() {
  35. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  36. document.getElementById(\'end_date_div\').style.display = \'block\';
  37. } else {
  38. document.getElementById(\'end_date_div\').style.display = \'none\';
  39. }
  40. }
  41. </script>';
  42. Display::display_header(get_lang('CourseSettings'), 'Path');
  43. echo $_SESSION['oLP']->build_action_menu();
  44. $gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
  45. $defaults=array();
  46. $form = new FormValidator('form1', 'post', 'lp_controller.php');
  47. // Form title
  48. $form->addElement('header', get_lang('EditLPSettings'));
  49. // Title
  50. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LearnpathTitle')), array('class' => 'span5'));
  51. $form->applyFilter('lp_name', 'html_filter');
  52. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  53. $form->addElement('hidden', 'lp_encoding');
  54. $referer = isset($_REQUEST['referer']) ? Security::remove_XSS($_REQUEST['referer']) : null;
  55. $form->addElement('hidden', 'referer', $referer);
  56. $items = learnpath::get_category_from_course_into_select(api_get_course_int_id(), true);
  57. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  58. //Hide toc frame
  59. $hide_toc_frame = $form->addElement('checkbox', 'hide_toc_frame', null, get_lang('HideTocFrame'),array('onclick' => '$("#lp_layout_column").toggle()' ));
  60. if (api_get_setting('allow_course_theme') == 'true') {
  61. $mycourselptheme = api_get_course_setting('allow_learning_path_theme');
  62. if (!empty($mycourselptheme) && $mycourselptheme!=-1 && $mycourselptheme== 1) {
  63. //LP theme picker
  64. $theme_select = $form->addElement('select_theme', 'lp_theme', get_lang('Theme'));
  65. $form->applyFilter('lp_theme', 'trim');
  66. $s_theme = $_SESSION['oLP']->get_theme();
  67. $theme_select ->setSelected($s_theme); //default
  68. }
  69. }
  70. // Author
  71. $form->addElement('html_editor', 'lp_author', get_lang('Author'), array('size' => 80), array('ToolbarSet' => 'LearningPathAuthor', 'Width' => '100%', 'Height' => '150px') );
  72. $form->applyFilter('lp_author', 'html_filter');
  73. // LP image
  74. $form->add_progress_bar();
  75. if (strlen($_SESSION['oLP']->get_preview_image()) > 0) {
  76. $show_preview_image='<img src='.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image().'>';
  77. $form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
  78. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  79. }
  80. $label = ($_SESSION['oLP']->get_preview_image() != '' ? get_lang('UpdateImage') : get_lang('AddImage'));
  81. $form->addElement('file', 'lp_preview_image', array($label, get_lang('ImageWillResizeMsg')));
  82. $form->addRule('lp_preview_image', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif'));
  83. // Search terms (only if search is activated).
  84. if (api_get_setting('search_enabled') === 'true') {
  85. $specific_fields = get_specific_field_list();
  86. foreach ($specific_fields as $specific_field) {
  87. $form -> addElement ('text', $specific_field['code'], $specific_field['name']);
  88. $filter = array('c_id'=> "'". api_get_course_int_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => $_SESSION['oLP']->lp_id, 'tool_id' => '\''. TOOL_LEARNPATH .'\'');
  89. $values = get_specific_field_values_list($filter, array('value'));
  90. if (!empty($values)) {
  91. $arr_str_values = array();
  92. foreach ($values as $value) {
  93. $arr_str_values[] = $value['value'];
  94. }
  95. $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
  96. }
  97. }
  98. }
  99. $defaults['lp_encoding'] = Security::remove_XSS($_SESSION['oLP']->encoding);
  100. $defaults['lp_name'] = Security::remove_XSS($_SESSION['oLP']->get_name());
  101. $defaults['lp_author'] = Security::remove_XSS($_SESSION['oLP']->get_author());
  102. $defaults['hide_toc_frame'] = Security::remove_XSS($_SESSION['oLP']->get_hide_toc_frame());
  103. $defaults['category_id'] = intval($_SESSION['oLP']->get_category_id());
  104. $expired_on = $_SESSION['oLP'] ->expired_on;
  105. $publicated_on = $_SESSION['oLP'] ->publicated_on;
  106. // Prerequisites
  107. $form->addElement('html', '<div class="control-group"><label class="control-label">'.get_lang('LearnpathPrerequisites').'</label>
  108. <div class="controls">'.$_SESSION['oLP']->display_lp_prerequisites_list().' <span class="help-block">'.get_lang('LpPrerequisiteDescription').'</span></div></div>');
  109. $options = array(
  110. '0' => get_lang('Unlimited'),
  111. );
  112. for ($i = 1; $i <= 10; $i++) {
  113. $options[$i] = $i;
  114. }
  115. $form->addElement('select', 'max_attempts', get_lang('MaxAttempts'), $options);
  116. //Start date
  117. $form->addElement('checkbox', 'activate_start_date_check', null,get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
  118. $display_date = 'none';
  119. if ($publicated_on!='0000-00-00 00:00:00' && !empty($publicated_on)) {
  120. $display_date = 'block';
  121. $defaults['activate_start_date_check'] = 1;
  122. }
  123. $form->addElement('html','<div id="start_date_div" style="display:'.$display_date.';">');
  124. $form->addElement('datepicker', 'publicated_on', get_lang('PublicationDate'), array('form_name'=>'form1'), 5);
  125. $form->addElement('html','</div>');
  126. //End date
  127. $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
  128. $display_date = 'none';
  129. if ($expired_on!='0000-00-00 00:00:00' && !empty($expired_on)) {
  130. $display_date = 'block';
  131. $defaults['activate_end_date_check'] = 1;
  132. }
  133. $form->addElement('html','<div id="end_date_div" style="display:'.$display_date.';">');
  134. $form->addElement('datepicker', 'expired_on', get_lang('ExpirationDate'), array('form_name'=>'exercise_admin'), 5);
  135. $form->addElement('html','</div>');
  136. if (api_is_platform_admin()) {
  137. $form->addElement('checkbox', 'use_max_score', null, get_lang('UseMaxScore100'));
  138. $defaults['use_max_score'] = $_SESSION['oLP']->use_max_score;
  139. }
  140. $form->addElement('checkbox', 'subscribe_users', null, get_lang('SubscribeUsersToLP'));
  141. //Submit button
  142. $form->addElement('style_submit_button', 'Submit', get_lang('SaveLPSettings'),'class="save"');
  143. // Hidden fields
  144. $form->addElement('hidden', 'action', 'update_lp');
  145. $form->addElement('hidden', 'lp_id', $_SESSION['oLP']->get_id());
  146. $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');
  147. $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);
  148. $defaults['max_attempts'] = $_SESSION['oLP']->get_max_attempts();
  149. $defaults['subscribe_users'] = $_SESSION['oLP']->get_subscribe_users();
  150. $form->setDefaults($defaults);
  151. echo '<div class="row">';
  152. if ($_SESSION['oLP']->get_hide_toc_frame() == 1) {
  153. echo '<div class="span12">';
  154. $form -> display();
  155. echo '</div>';
  156. } else{
  157. echo '<div class="span6">';
  158. $form -> display();
  159. echo '</div>';
  160. echo '<div class="span6" align="center">';
  161. echo '<img src="../img/course_setting_layout.png" />';
  162. echo '</div>';
  163. }
  164. echo '</div>';
  165. Display::display_footer();