thematic.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for thematic control.
  5. *
  6. * @author Christian Fasanando <christian1827@gmail.com>
  7. * @author Julio Montoya <gugli100@gmail.com> Bug fixing
  8. *
  9. * @package chamilo.course_progress
  10. */
  11. // protect a course script
  12. api_protect_course_script(true);
  13. $token = Security::get_token();
  14. $url_token = "&sec_token=".$token;
  15. $user_info = api_get_user_info();
  16. $params = '&'.api_get_cidreq();
  17. $tpl = new Template(get_lang('ThematicControl'));
  18. $toolbar = null;
  19. if (api_is_allowed_to_edit(null, true)) {
  20. switch ($action) {
  21. case 'thematic_add':
  22. case 'thematic_import_select':
  23. $actionLeft = '<a href="index.php?'.api_get_cidreq().'">';
  24. $actionLeft .= Display::return_icon(
  25. 'back.png',
  26. get_lang('BackTo').' '.get_lang('ThematicDetails'),
  27. '',
  28. ICON_SIZE_MEDIUM
  29. );
  30. $actionLeft .= '</a>';
  31. break;
  32. case 'thematic_list':
  33. $actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  34. Display::return_icon('new_course_progress.png', get_lang('NewThematicSection'), '', ICON_SIZE_MEDIUM).'</a>';
  35. break;
  36. case 'thematic_details':
  37. $actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  38. Display::return_icon('new_course_progress.png', get_lang('NewThematicSection'), '', ICON_SIZE_MEDIUM).'</a>';
  39. $actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'.
  40. Display::return_icon('import_csv.png', get_lang('ImportThematic'), '', ICON_SIZE_MEDIUM).'</a>';
  41. $actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'.
  42. Display::return_icon('export_csv.png', get_lang('ExportThematic'), '', ICON_SIZE_MEDIUM).'</a>';
  43. $actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'.
  44. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  45. $actionLeft .= Display::url(
  46. Display::return_icon('export_to_documents.png', get_lang('ExportToDocArea'), [], ICON_SIZE_MEDIUM),
  47. api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'export_documents']).$url_token
  48. );
  49. break;
  50. default:
  51. $actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  52. Display::return_icon(
  53. 'new_course_progress.png',
  54. get_lang('NewThematicSection'),
  55. '',
  56. ICON_SIZE_MEDIUM
  57. ).'</a>';
  58. }
  59. $toolbar = Display::toolbarAction('thematic-bar', [$actionLeft]);
  60. }
  61. if ($action == 'thematic_list') {
  62. $table = new SortableTable(
  63. 'thematic_list',
  64. ['Thematic', 'get_number_of_thematics'],
  65. ['Thematic', 'get_thematic_data']
  66. );
  67. $parameters['action'] = $action;
  68. $table->set_additional_parameters($parameters);
  69. $table->set_header(0, '', false, ['style' => 'width:20px;']);
  70. $table->set_header(1, get_lang('Title'), false);
  71. if (api_is_allowed_to_edit(null, true)) {
  72. $table->set_header(
  73. 2,
  74. get_lang('Actions'),
  75. false,
  76. ['style' => 'text-align:center;width:40%;']
  77. );
  78. $table->set_form_actions(['thematic_delete_select' => get_lang('DeleteAllThematics')]);
  79. }
  80. $table->display();
  81. } elseif ($action == 'thematic_details') {
  82. if (isset($_GET['thematic_plan_save_message']) &&
  83. $_GET['thematic_plan_save_message'] == 'ok'
  84. ) {
  85. Display::addFlash(
  86. Display::return_message(
  87. get_lang('ThematicSectionHasBeenCreatedSuccessfull'),
  88. 'confirmation',
  89. false
  90. )
  91. );
  92. }
  93. if (isset($last_id) && $last_id) {
  94. $link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.
  95. Display::return_icon('lesson_plan.png', get_lang('ThematicPlan'), ['style' => 'vertical-align:middle;float:none;'], ICON_SIZE_SMALL).'</a>';
  96. $link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'.
  97. Display::return_icon('lesson_plan_calendar.png', get_lang('ThematicAdvance'), ['style' => 'vertical-align:middle;float:none;'], ICON_SIZE_SMALL).'</a>';
  98. Display::addFlash(Display::return_message(
  99. get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'), $link_to_thematic_plan, $link_to_thematic_advance),
  100. 'confirmation',
  101. false
  102. ));
  103. }
  104. if (empty($thematic_id)) {
  105. // display information
  106. $text = '<strong>'.get_lang('Information').': </strong>';
  107. $text .= get_lang('ThematicDetailsDescription');
  108. $message = Display::return_message($text, 'info', false);
  109. }
  110. $list = [];
  111. // Display thematic data
  112. if (!empty($thematic_data)) {
  113. // display progress
  114. foreach ($thematic_data as $thematic) {
  115. $list['id'] = $thematic['id'];
  116. $list['id_course'] = $thematic['c_id'];
  117. $list['id_session'] = $thematic['session_id'];
  118. $list['title'] = Security::remove_XSS($thematic['title'], STUDENT);
  119. $list['content'] = Security::remove_XSS($thematic['content'], STUDENT);
  120. $list['display_orden'] = $thematic['display_order'];
  121. $list['active'] = $thematic['active'];
  122. $my_thematic_id = $thematic['id'];
  123. $session_star = '';
  124. if (api_is_allowed_to_edit(null, true)) {
  125. if (api_get_session_id() == $thematic['session_id']) {
  126. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  127. }
  128. }
  129. $tpl->assign('session_star', $session_star);
  130. //@todo add a validation in order to load or not course thematics in the session thematic
  131. $toolbarThematic = '';
  132. if (api_is_allowed_to_edit(null, true)) {
  133. // Thematic title
  134. $toolbarThematic = Display::url(
  135. Display::return_icon(
  136. 'cd.png',
  137. get_lang('Copy'),
  138. null,
  139. ICON_SIZE_TINY
  140. ),
  141. 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$params.$url_token,
  142. ['class' => 'btn btn-default']
  143. );
  144. if (api_get_session_id() == 0) {
  145. if ($thematic['display_order'] > 1) {
  146. $toolbarThematic .= ' <a class="btn btn-default" href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$params.$url_token.'">'.
  147. Display::return_icon('up.png', get_lang('Up'), '', ICON_SIZE_TINY).'</a>';
  148. } else {
  149. $toolbarThematic .= '<div class="btn btn-default">'.
  150. Display::return_icon('up_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
  151. }
  152. if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) {
  153. $toolbarThematic .= ' <a class="btn btn-default" href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$params.$url_token.'">'.
  154. Display::return_icon('down.png', get_lang('Down'), '', ICON_SIZE_TINY).'</a>';
  155. } else {
  156. $toolbarThematic .= '<div class="btn btn-default">'.
  157. Display::return_icon('down_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
  158. }
  159. }
  160. if (api_get_session_id() == $thematic['session_id']) {
  161. $toolbarThematic .= Display::url(
  162. Display::return_icon('pdf.png', get_lang('ExportToPDF'), null, ICON_SIZE_TINY),
  163. api_get_self().'?'.api_get_cidreq()."$url_token&".http_build_query([
  164. 'action' => 'export_single_thematic',
  165. 'thematic_id' => $my_thematic_id,
  166. ]),
  167. ['class' => 'btn btn-default']
  168. );
  169. $toolbarThematic .= Display::url(
  170. Display::return_icon(
  171. 'export_to_documents.png',
  172. get_lang('ExportToDocArea'),
  173. [],
  174. ICON_SIZE_TINY
  175. ),
  176. api_get_self().'?'.api_get_cidreq().$url_token.'&'.http_build_query(
  177. ['action' => 'export_single_documents', 'thematic_id' => $my_thematic_id]
  178. ),
  179. ['class' => 'btn btn-default']
  180. );
  181. $toolbarThematic .= '<a class="btn btn-default" href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='
  182. .$my_thematic_id.$params.$url_token.'">'
  183. .Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_TINY).'</a>';
  184. $toolbarThematic .= '<a class="btn btn-default" onclick="javascript:if(!confirm(\''
  185. .get_lang('AreYouSureToDelete')
  186. .'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='
  187. .$my_thematic_id.$params.$url_token.'">'
  188. .Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_TINY).'</a>';
  189. }
  190. }
  191. if (empty($thematic_plan_div[$thematic['id']])) {
  192. $list['thematic_plan'] = null;
  193. } else {
  194. $list['thematic_plan'] = $thematic_plan_div[$thematic['id']];
  195. }
  196. $list['thematic_advance'] = isset($thematic_advance_data[$thematic['id']])
  197. ? $thematic_advance_data[$thematic['id']]
  198. : null;
  199. $list['last_done'] = $last_done_thematic_advance;
  200. $list['toolbar'] = $toolbarThematic;
  201. $listThematic[] = $list;
  202. $tpl->assign('data', $listThematic);
  203. } //End for
  204. }
  205. $thematicLayout = $tpl->get_template('course_progress/progress.tpl');
  206. } elseif ($action == 'thematic_add' || $action == 'thematic_edit') {
  207. // Display form
  208. $form = new FormValidator('thematic_add', 'POST', 'index.php?action=thematic_add&'.api_get_cidreq());
  209. if ($action == 'thematic_edit') {
  210. $form->addElement('header', '', get_lang('EditThematicSection'));
  211. }
  212. $form->addElement('hidden', 'sec_token', $token);
  213. $form->addElement('hidden', 'action', $action);
  214. if (!empty($thematic_id)) {
  215. $form->addElement('hidden', 'thematic_id', $thematic_id);
  216. }
  217. if (api_get_configuration_value('save_titles_as_html')) {
  218. $form->addHtmlEditor(
  219. 'title',
  220. get_lang('Title'),
  221. true,
  222. false,
  223. ['ToolbarSet' => 'Minimal']
  224. );
  225. } else {
  226. $form->addText('title', get_lang('Title'), true, ['size' => '50']);
  227. }
  228. $form->addHtmlEditor(
  229. 'content',
  230. get_lang('Content'),
  231. false,
  232. false,
  233. ['ToolbarSet' => 'Basic', 'Height' => '150']
  234. );
  235. $form->addButtonSave(get_lang('Save'));
  236. $show_form = true;
  237. if (!empty($thematic_data)) {
  238. if (api_get_session_id()) {
  239. if ($thematic_data['session_id'] != api_get_session_id()) {
  240. $show_form = false;
  241. echo Display::return_message(get_lang('NotAllowedClickBack'), 'error', false);
  242. }
  243. }
  244. // set default values
  245. $default['title'] = $thematic_data['title'];
  246. $default['content'] = $thematic_data['content'];
  247. $form->setDefaults($default);
  248. }
  249. // error messages
  250. if (isset($error)) {
  251. echo Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error', false);
  252. }
  253. if ($show_form) {
  254. $html = $form->returnForm();
  255. }
  256. } elseif ($action == 'thematic_import_select') {
  257. // Create form to upload csv file.
  258. $form = new FormValidator(
  259. 'thematic_import',
  260. 'POST',
  261. 'index.php?action=thematic_import&'.api_get_cidreq().$url_token
  262. );
  263. $form->addElement('header', get_lang('ImportThematic'));
  264. $form->addElement('file', 'file');
  265. $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllThematic'));
  266. $form->addButtonImport(get_lang('Import'), 'SubmitImport');
  267. $html = $form->returnForm();
  268. }
  269. $tpl->assign('actions', $toolbar);
  270. if (!empty($html)) {
  271. $tpl->assign('content', $html);
  272. $thematicLayout = $tpl->get_template('course_progress/layout.tpl');
  273. }
  274. if (!empty($message) && !empty($total_average_of_advances)) {
  275. $tpl->assign('message', $message);
  276. $tpl->assign('score_progress', $total_average_of_advances);
  277. }
  278. $tpl->display($thematicLayout);