lp_edit.php 8.9 KB

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