thematic_plan.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. $tpl = new Template(get_lang('Thematic control'));
  12. $toolbar = null;
  13. $formLayout = null;
  14. // actions menu
  15. $new_thematic_plan_data = [];
  16. if (!empty($thematic_plan_data)) {
  17. foreach ($thematic_plan_data as $thematic_item) {
  18. $thematic_simple_list[] = $thematic_item['description_type'];
  19. $new_thematic_plan_data[$thematic_item['description_type']] = $thematic_item;
  20. }
  21. }
  22. $new_id = ADD_THEMATIC_PLAN;
  23. if (!empty($thematic_simple_list)) {
  24. foreach ($thematic_simple_list as $item) {
  25. if ($item >= ADD_THEMATIC_PLAN) {
  26. $new_id = $item + 1;
  27. $default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
  28. }
  29. }
  30. }
  31. if (isset($message) && $message == 'ok') {
  32. echo Display::return_message(get_lang('Thematic section has been created successfully'), 'normal');
  33. }
  34. if ($action === 'thematic_plan_list') {
  35. $token = Security::get_token();
  36. Session::write('thematic_plan_token', $token);
  37. $form = new FormValidator(
  38. 'thematic_plan_add',
  39. 'POST',
  40. 'index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq()
  41. );
  42. $form->addElement('hidden', 'action', 'thematic_plan_add');
  43. $form->addElement('hidden', 'thematic_plan_token', $token);
  44. $form->addElement('hidden', 'thematic_id', $thematic_id);
  45. foreach ($default_thematic_plan_title as $id => $title) {
  46. $btnDelete = Display::toolbarButton(
  47. get_lang('Delete'),
  48. '#',
  49. 'times',
  50. 'danger',
  51. ['role' => 'button', 'data-id' => $id, 'class' => 'btn-delete']
  52. );
  53. $form->addElement('hidden', 'description_type['.$id.']', $id);
  54. $form->addText("title[$id]", [get_lang('Title'), null, $btnDelete], false);
  55. $form->addHtmlEditor(
  56. 'description['.$id.']',
  57. get_lang('Description'),
  58. false,
  59. false,
  60. [
  61. 'ToolbarStartExpanded' => 'false',
  62. 'ToolbarSet' => 'Basic',
  63. 'Height' => '150',
  64. ]
  65. );
  66. if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) {
  67. $thematic_plan = $new_thematic_plan_data[$id];
  68. // set default values
  69. $default['title['.$id.']'] = $thematic_plan['title'];
  70. $default['description['.$id.']'] = $thematic_plan['description'];
  71. $thematic_plan = null;
  72. } else {
  73. $thematic_plan = null;
  74. $default['title['.$id.']'] = $title;
  75. $default['description['.$id.']'] = '';
  76. }
  77. $form->setDefaults($default);
  78. }
  79. $form->addGroup([
  80. $form->addButton(
  81. 'add_item',
  82. get_lang('Save and add new item'),
  83. 'plus',
  84. 'info',
  85. 'default',
  86. null,
  87. [],
  88. true
  89. ),
  90. $form->addButtonSave(get_lang('Save'), 'submit', true),
  91. ]);
  92. $formLayout = $form->returnForm();
  93. } elseif ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
  94. if ($description_type >= ADD_THEMATIC_PLAN) {
  95. $header_form = get_lang('Other');
  96. } else {
  97. $header_form = $default_thematic_plan_title[$description_type];
  98. }
  99. if (!$error) {
  100. $token = md5(uniqid(rand(), true));
  101. Session::write('thematic_plan_token', $token);
  102. }
  103. // display form
  104. $form = new FormValidator(
  105. 'thematic_plan_add',
  106. 'POST',
  107. 'index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq(),
  108. '',
  109. 'style="width: 100%;"'
  110. );
  111. $form->addElement('hidden', 'action', $action);
  112. $form->addElement('hidden', 'thematic_plan_token', $token);
  113. if (!empty($thematic_id)) {
  114. $form->addElement('hidden', 'thematic_id', $thematic_id);
  115. }
  116. if (!empty($description_type)) {
  117. $form->addElement('hidden', 'description_type', $description_type);
  118. }
  119. $form->addText('title', get_lang('Title'), true, ['size' => '50']);
  120. $form->addHtmlEditor(
  121. 'description',
  122. get_lang('Description'),
  123. false,
  124. false,
  125. [
  126. 'ToolbarStartExpanded' => 'false',
  127. 'ToolbarSet' => 'Basic',
  128. 'Width' => '80%',
  129. 'Height' => '150',
  130. ]
  131. );
  132. $form->addButtonSave(get_lang('Save'));
  133. if ($description_type < ADD_THEMATIC_PLAN) {
  134. $default['title'] = $default_thematic_plan_title[$description_type];
  135. }
  136. if (!empty($thematic_plan_data)) {
  137. // set default values
  138. $default['title'] = $thematic_plan_data[0]['title'];
  139. $default['description'] = $thematic_plan_data[0]['description'];
  140. }
  141. $form->setDefaults($default);
  142. if (isset($default_thematic_plan_question[$description_type])) {
  143. $message = '<strong>'.get_lang('Help').'</strong><br />';
  144. $message .= $default_thematic_plan_question[$description_type];
  145. Display::addFlash(Display::return_message($message, 'normal', false));
  146. }
  147. // error messages
  148. if ($error) {
  149. Display::addFlash(
  150. Display::return_message(
  151. get_lang('The form contains incorrect or incomplete data. Please check your input.'),
  152. 'error',
  153. false
  154. )
  155. );
  156. }
  157. $formLayout = $form->returnForm();
  158. }
  159. $tpl->assign('title_thematic', $thematic_data['title']);
  160. $tpl->assign('content_thematic', $thematic_data['content']);
  161. $tpl->assign('form_thematic', $formLayout);
  162. $thematicLayout = $tpl->get_template('course_progress/thematic_plan.tpl');
  163. $content = $tpl->fetch($thematicLayout);
  164. $tpl->assign('content', $content);
  165. $tpl->display_one_col_template();