thematic_plan.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. echo Display::return_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'), 'normal');
  30. }
  31. if ($action === 'thematic_plan_list') {
  32. $token = Security::get_token();
  33. ChamiloSession::write('thematic_plan_token', $token);
  34. $form = new FormValidator(
  35. 'thematic_plan_add',
  36. 'POST',
  37. 'index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq()
  38. );
  39. $form->addElement('hidden', 'action', 'thematic_plan_add');
  40. $form->addElement('hidden', 'thematic_plan_token', $token);
  41. $form->addElement('hidden', 'thematic_id', $thematic_id);
  42. foreach ($default_thematic_plan_title as $id => $title) {
  43. $btnDelete = Display::toolbarButton(
  44. get_lang('Delete'),
  45. '#',
  46. 'times',
  47. 'danger',
  48. ['role' => 'button', 'data-id' => $id, 'class' => 'btn-delete']
  49. );
  50. $form->addElement('hidden', 'description_type['.$id.']', $id);
  51. $form->addText("title[$id]", [get_lang('Title'), null, $btnDelete], false);
  52. $form->addHtmlEditor(
  53. 'description['.$id.']',
  54. get_lang('Description'),
  55. false,
  56. false,
  57. array(
  58. 'ToolbarStartExpanded' => 'false',
  59. 'ToolbarSet' => 'TrainingDescription',
  60. 'Height' => '150'
  61. )
  62. );
  63. if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) {
  64. $thematic_plan = $new_thematic_plan_data[$id];
  65. // set default values
  66. $default['title['.$id.']'] = $thematic_plan['title'];
  67. $default['description['.$id.']'] = $thematic_plan['description'];
  68. $thematic_plan = null;
  69. } else {
  70. $thematic_plan = null;
  71. $default['title['.$id.']'] = $title;
  72. $default['description['.$id.']'] = '';
  73. }
  74. $form->setDefaults($default);
  75. }
  76. $form->addGroup([
  77. $form->addButton(
  78. 'add_item',
  79. get_lang('SaveAndAddNewItem'),
  80. 'plus',
  81. 'info',
  82. 'default',
  83. null,
  84. [],
  85. true
  86. ),
  87. $form->addButtonSave(get_lang('Save'), 'submit', true)
  88. ]);
  89. $form->display();
  90. } elseif ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
  91. if ($description_type >= ADD_THEMATIC_PLAN) {
  92. $header_form = get_lang('NewBloc');
  93. } else {
  94. $header_form = $default_thematic_plan_title[$description_type];
  95. }
  96. if (!$error) {
  97. $token = md5(uniqid(rand(), true));
  98. $_SESSION['thematic_plan_token'] = $token;
  99. }
  100. // display form
  101. $form = new FormValidator(
  102. 'thematic_plan_add',
  103. 'POST',
  104. 'index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq(),
  105. '',
  106. 'style="width: 100%;"'
  107. );
  108. $form->addElement('hidden', 'action', $action);
  109. $form->addElement('hidden', 'thematic_plan_token', $token);
  110. if (!empty($thematic_id)) {
  111. $form->addElement('hidden', 'thematic_id', $thematic_id);
  112. }
  113. if (!empty($description_type)) {
  114. $form->addElement('hidden', 'description_type', $description_type);
  115. }
  116. $form->addText('title', get_lang('Title'), true, array('size'=>'50'));
  117. $form->addHtmlEditor(
  118. 'description',
  119. get_lang('Description'),
  120. false,
  121. false,
  122. array(
  123. 'ToolbarStartExpanded' => 'false',
  124. 'ToolbarSet' => 'TrainingDescription',
  125. 'Width' => '80%',
  126. 'Height' => '150'
  127. )
  128. );
  129. $form->addButtonSave(get_lang('Save'));
  130. if ($description_type < ADD_THEMATIC_PLAN) {
  131. $default['title'] = $default_thematic_plan_title[$description_type];
  132. }
  133. if (!empty($thematic_plan_data)) {
  134. // set default values
  135. $default['title'] = $thematic_plan_data[0]['title'];
  136. $default['description'] = $thematic_plan_data[0]['description'];
  137. }
  138. $form->setDefaults($default);
  139. if (isset($default_thematic_plan_question[$description_type])) {
  140. $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
  141. $message .= $default_thematic_plan_question[$description_type];
  142. Display::addFlash(Display::return_message($message, 'normal', false));
  143. }
  144. // error messages
  145. if ($error) {
  146. Display::addFlash(Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error', false));
  147. }
  148. $form->display();
  149. }