edit.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 = 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. unset ($course_description);
  20. // If no corresponding description is found, edit a new one
  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. );
  68. $form->addElement('header','',$header);
  69. $form->addElement('hidden', 'id', $original_id);
  70. $form->addElement('hidden', 'description_type',$description_type);
  71. $form->addElement('hidden', 'sec_token',$token);
  72. $form->addText('title', get_lang('Title'), true, array('size'=>'50'));
  73. $form->applyFilter('title','html_filter');
  74. $form->addHtmlEditor(
  75. 'contentDescription',
  76. get_lang('Content'),
  77. true,
  78. false,
  79. array(
  80. 'ToolbarSet' => 'TrainingDescription',
  81. 'Width' => '100%',
  82. 'Height' => '200',
  83. )
  84. );
  85. $form->addButtonCreate(get_lang('Save'));
  86. // Set some default values
  87. if (!empty($description_title)) {
  88. $default['title'] = Security::remove_XSS($description_title);
  89. }
  90. if (!empty($description_content)) {
  91. $default['contentDescription'] = Security::remove_XSS($description_content,COURSEMANAGERLOWSECURITY);
  92. }
  93. $default['description_type'] = $description_type;
  94. $form->setDefaults($default);
  95. if (isset ($question[$description_type])) {
  96. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  97. $message .= $question[$description_type];
  98. Display::display_normal_message($message, false);
  99. }
  100. $form->display();