thematic_plan.php 5.2 KB

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