edit.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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::display_error_message(get_lang('FormHasErrorsPleaseComplete'),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. $form->addText('title', get_lang('Title'), true, array('size'=>'50'));
  72. $form->applyFilter('title', 'html_filter');
  73. $form->addHtmlEditor(
  74. 'contentDescription',
  75. get_lang('Content'),
  76. true,
  77. false,
  78. array(
  79. 'ToolbarSet' => 'TrainingDescription',
  80. 'Width' => '100%',
  81. 'Height' => '200',
  82. )
  83. );
  84. $form->addButtonCreate(get_lang('Save'));
  85. // Set some default values
  86. if (!empty($description_title)) {
  87. $default['title'] = Security::remove_XSS($description_title);
  88. }
  89. if (!empty($description_content)) {
  90. $default['contentDescription'] = Security::remove_XSS($description_content,COURSEMANAGERLOWSECURITY);
  91. }
  92. $default['description_type'] = $description_type;
  93. $form->setDefaults($default);
  94. if (isset ($question[$description_type])) {
  95. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  96. $message .= $question[$description_type];
  97. Display::display_normal_message($message, false);
  98. }
  99. $form->display();