edit.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for editing a course description
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @package chamilo.course_description
  7. */
  8. // protect a course script
  9. api_protect_course_script(true);
  10. if (empty($id)) {
  11. $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : '';
  12. if (empty($id)) {
  13. // If the ID was not provided, find the first matching description item given the item type
  14. $course_description = new CourseDescription();
  15. $description = $course_description->get_data_by_description_type($description_type);
  16. if (count($description) > 0) {
  17. $id = $description['id'];
  18. }
  19. // If no corresponding description is found, edit a new one
  20. unset($course_description);
  21. }
  22. }
  23. $original_id = $id;
  24. if (empty($error)) {
  25. $token = Security::get_token();
  26. }
  27. // display categories
  28. $categories = array();
  29. foreach ($default_description_titles as $id => $title) {
  30. $categories[$id] = $title;
  31. }
  32. $categories[ADD_BLOCK] = get_lang('NewBloc');
  33. $i = 1;
  34. echo '<div class="actions" style="margin-bottom:30px">';
  35. echo '<a href="index.php?'.api_get_cidreq().'">'.
  36. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('ToolCourseDescription'), '', ICON_SIZE_MEDIUM).
  37. '</a>';
  38. ksort($categories);
  39. foreach ($categories as $id => $title) {
  40. if ($i == ADD_BLOCK) {
  41. echo '<a href="index.php?'.api_get_cidreq().'&action=add">'.
  42. Display::return_icon($default_description_icon[$id], $title, '', ICON_SIZE_MEDIUM).'</a>';
  43. break;
  44. } else {
  45. echo '<a href="index.php?action=edit&'.api_get_cidreq().'&description_type='.$id.'">'.
  46. Display::return_icon($default_description_icon[$id], $title, '', ICON_SIZE_MEDIUM).'</a>';
  47. $i++;
  48. }
  49. }
  50. echo '</div>';
  51. // error messages
  52. if (isset($error) && intval($error) == 1) {
  53. Display::addFlash(Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error', false));
  54. }
  55. // default header title form
  56. $description_type = intval($description_type);
  57. $header = $default_description_titles[$description_type];
  58. if ($description_type >= ADD_BLOCK) {
  59. $header = $default_description_titles[ADD_BLOCK];
  60. }
  61. // display form
  62. $form = new FormValidator(
  63. 'course_description',
  64. 'POST',
  65. 'index.php?action=edit&id='.$original_id.'&description_type='.$description_type.'&'.api_get_cidreq()
  66. );
  67. $form->addElement('header', $header);
  68. $form->addElement('hidden', 'id', $original_id);
  69. $form->addElement('hidden', 'description_type', $description_type);
  70. $form->addElement('hidden', 'sec_token', $token);
  71. if (api_get_configuration_value('save_titles_as_html')) {
  72. $form->addHtmlEditor(
  73. 'title',
  74. get_lang('Title'),
  75. true,
  76. false,
  77. ['ToolbarSet' => 'Minimal']
  78. );
  79. } else {
  80. $form->addText('title', get_lang('Title'));
  81. $form->applyFilter('title', 'html_filter');
  82. }
  83. $form->addHtmlEditor(
  84. 'contentDescription',
  85. get_lang('Content'),
  86. true,
  87. false,
  88. array(
  89. 'ToolbarSet' => 'TrainingDescription',
  90. 'Width' => '100%',
  91. 'Height' => '200',
  92. )
  93. );
  94. $form->addButtonCreate(get_lang('Save'));
  95. // Set some default values
  96. if (!empty($description_title)) {
  97. $default['title'] = Security::remove_XSS($description_title);
  98. }
  99. if (!empty($description_content)) {
  100. $default['contentDescription'] = Security::remove_XSS($description_content, COURSEMANAGERLOWSECURITY);
  101. }
  102. $default['description_type'] = $description_type;
  103. $form->setDefaults($default);
  104. if (isset ($question[$description_type])) {
  105. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  106. $message .= $question[$description_type];
  107. Display::addFlash(Display::return_message($message, 'normal', false));
  108. }
  109. $form->display();