thematic_plan.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * View (MVC patter) for thematic plan.
  6. *
  7. * @author Christian Fasanando <christian1827@gmail.com>
  8. *
  9. * @package chamilo.course_progress
  10. */
  11. // actions menu
  12. $new_thematic_plan_data = [];
  13. if (!empty($thematic_plan_data)) {
  14. foreach ($thematic_plan_data as $thematic_item) {
  15. $thematic_simple_list[] = $thematic_item['description_type'];
  16. $new_thematic_plan_data[$thematic_item['description_type']] = $thematic_item;
  17. }
  18. }
  19. $new_id = ADD_THEMATIC_PLAN;
  20. if (!empty($thematic_simple_list)) {
  21. foreach ($thematic_simple_list as $item) {
  22. if ($item >= ADD_THEMATIC_PLAN) {
  23. $new_id = $item + 1;
  24. $default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
  25. }
  26. }
  27. }
  28. echo Display::tag('h2', $thematic_data['title']);
  29. echo $thematic_data['content'];
  30. if (isset($message) && $message == 'ok') {
  31. echo Display::return_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'), 'normal');
  32. }
  33. if ($action === 'thematic_plan_list') {
  34. $token = Security::get_token();
  35. Session::write('thematic_plan_token', $token);
  36. $form = new FormValidator(
  37. 'thematic_plan_add',
  38. 'POST',
  39. 'index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq()
  40. );
  41. $form->addElement('hidden', 'action', 'thematic_plan_add');
  42. $form->addElement('hidden', 'thematic_plan_token', $token);
  43. $form->addElement('hidden', 'thematic_id', $thematic_id);
  44. foreach ($default_thematic_plan_title as $id => $title) {
  45. $btnDelete = Display::toolbarButton(
  46. get_lang('Delete'),
  47. '#',
  48. 'times',
  49. 'danger',
  50. ['role' => 'button', 'data-id' => $id, 'class' => 'btn-delete']
  51. );
  52. $form->addElement('hidden', 'description_type['.$id.']', $id);
  53. $form->addText("title[$id]", [get_lang('Title'), null, $btnDelete], false);
  54. $form->addHtmlEditor(
  55. 'description['.$id.']',
  56. get_lang('Description'),
  57. false,
  58. false,
  59. [
  60. 'ToolbarStartExpanded' => 'false',
  61. 'ToolbarSet' => 'Basic',
  62. 'Height' => '150',
  63. ]
  64. );
  65. if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) {
  66. $thematic_plan = $new_thematic_plan_data[$id];
  67. // set default values
  68. $default['title['.$id.']'] = $thematic_plan['title'];
  69. $default['description['.$id.']'] = $thematic_plan['description'];
  70. $thematic_plan = null;
  71. } else {
  72. $thematic_plan = null;
  73. $default['title['.$id.']'] = $title;
  74. $default['description['.$id.']'] = '';
  75. }
  76. $form->setDefaults($default);
  77. }
  78. $form->addGroup([
  79. $form->addButton(
  80. 'add_item',
  81. get_lang('SaveAndAddNewItem'),
  82. 'plus',
  83. 'info',
  84. 'default',
  85. null,
  86. [],
  87. true
  88. ),
  89. $form->addButtonSave(get_lang('Save'), 'submit', true),
  90. ]);
  91. $form->display();
  92. } elseif ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
  93. if ($description_type >= ADD_THEMATIC_PLAN) {
  94. $header_form = get_lang('NewBloc');
  95. } else {
  96. $header_form = $default_thematic_plan_title[$description_type];
  97. }
  98. if (!$error) {
  99. $token = md5(uniqid(rand(), true));
  100. Session::write('thematic_plan_token', $token);
  101. }
  102. // display form
  103. $form = new FormValidator(
  104. 'thematic_plan_add',
  105. 'POST',
  106. 'index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq(),
  107. '',
  108. 'style="width: 100%;"'
  109. );
  110. $form->addElement('hidden', 'action', $action);
  111. $form->addElement('hidden', 'thematic_plan_token', $token);
  112. if (!empty($thematic_id)) {
  113. $form->addElement('hidden', 'thematic_id', $thematic_id);
  114. }
  115. if (!empty($description_type)) {
  116. $form->addElement('hidden', 'description_type', $description_type);
  117. }
  118. $form->addText('title', get_lang('Title'), true, ['size' => '50']);
  119. $form->addHtmlEditor(
  120. 'description',
  121. get_lang('Description'),
  122. false,
  123. false,
  124. [
  125. 'ToolbarStartExpanded' => 'false',
  126. 'ToolbarSet' => 'Basic',
  127. 'Width' => '80%',
  128. 'Height' => '150',
  129. ]
  130. );
  131. $form->addButtonSave(get_lang('Save'));
  132. if ($description_type < ADD_THEMATIC_PLAN) {
  133. $default['title'] = $default_thematic_plan_title[$description_type];
  134. }
  135. if (!empty($thematic_plan_data)) {
  136. // set default values
  137. $default['title'] = $thematic_plan_data[0]['title'];
  138. $default['description'] = $thematic_plan_data[0]['description'];
  139. }
  140. $form->setDefaults($default);
  141. if (isset($default_thematic_plan_question[$description_type])) {
  142. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  143. $message .= $default_thematic_plan_question[$description_type];
  144. Display::addFlash(Display::return_message($message, 'normal', false));
  145. }
  146. // error messages
  147. if ($error) {
  148. Display::addFlash(
  149. Display::return_message(
  150. get_lang('FormHasErrorsPleaseComplete'),
  151. 'error',
  152. false
  153. )
  154. );
  155. }
  156. $form->display();
  157. }