edit.php 3.7 KB

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