thematic.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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('Thematic control'));
  18. $isTeacher = api_is_allowed_to_edit(null, true);
  19. $tpl->assign('token', $url_token);
  20. $tpl->assign('is_allowed_to_edit', $isTeacher);
  21. $toolbar = null;
  22. if ($isTeacher) {
  23. switch ($action) {
  24. case 'thematic_add':
  25. case 'thematic_import_select':
  26. $actionLeft = '<a href="index.php?'.api_get_cidreq().'">';
  27. $actionLeft .= Display::return_icon(
  28. 'back.png',
  29. get_lang('Back to').' '.get_lang('Thematic view with details'),
  30. '',
  31. ICON_SIZE_MEDIUM
  32. );
  33. $actionLeft .= '</a>';
  34. break;
  35. case 'thematic_list':
  36. $actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  37. Display::return_icon('new_course_progress.png', get_lang('New thematic section'), '', ICON_SIZE_MEDIUM).'</a>';
  38. break;
  39. case 'thematic_details':
  40. $actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  41. Display::return_icon('new_course_progress.png', get_lang('New thematic section'), '', ICON_SIZE_MEDIUM).'</a>';
  42. $actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'.
  43. Display::return_icon('import_csv.png', get_lang('Import course progress'), '', ICON_SIZE_MEDIUM).'</a>';
  44. $actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'.
  45. Display::return_icon('export_csv.png', get_lang('Export course progress'), '', ICON_SIZE_MEDIUM).'</a>';
  46. $actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'.
  47. Display::return_icon('pdf.png', get_lang('Export to PDF'), '', ICON_SIZE_MEDIUM).'</a>';
  48. $actionLeft .= Display::url(
  49. Display::return_icon('export_to_documents.png', get_lang('Export latest version of this page to Documents'), [], ICON_SIZE_MEDIUM),
  50. api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'export_documents']).$url_token
  51. );
  52. break;
  53. default:
  54. $actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
  55. Display::return_icon(
  56. 'new_course_progress.png',
  57. get_lang('New thematic section'),
  58. '',
  59. ICON_SIZE_MEDIUM
  60. ).'</a>';
  61. }
  62. $toolbar = Display::toolbarAction('thematic-bar', [$actionLeft]);
  63. }
  64. if ($action == 'thematic_list') {
  65. $table = new SortableTable(
  66. 'thematic_list',
  67. ['Thematic', 'get_number_of_thematics'],
  68. ['Thematic', 'get_thematic_data']
  69. );
  70. $parameters['action'] = $action;
  71. $table->set_additional_parameters($parameters);
  72. $table->set_header(0, '', false, ['style' => 'width:20px;']);
  73. $table->set_header(1, get_lang('Title'), false);
  74. if (api_is_allowed_to_edit(null, true)) {
  75. $table->set_header(
  76. 2,
  77. get_lang('Detail'),
  78. false,
  79. ['style' => 'text-align:center;width:40%;']
  80. );
  81. $table->set_form_actions(['thematic_delete_select' => get_lang('Delete all thematics')]);
  82. }
  83. $table->display();
  84. } elseif ($action == 'thematic_details') {
  85. if (isset($_GET['thematic_plan_save_message']) &&
  86. $_GET['thematic_plan_save_message'] == 'ok'
  87. ) {
  88. Display::addFlash(
  89. Display::return_message(
  90. get_lang('Thematic section has been created successfully'),
  91. 'confirmation',
  92. false
  93. )
  94. );
  95. }
  96. if (isset($last_id) && $last_id) {
  97. $link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.
  98. Display::return_icon('lesson_plan.png', get_lang('Thematic plan'), ['style' => 'vertical-align:middle;float:none;'], ICON_SIZE_SMALL).'</a>';
  99. $link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'.
  100. Display::return_icon('lesson_plan_calendar.png', get_lang('Thematic advance'), ['style' => 'vertical-align:middle;float:none;'], ICON_SIZE_SMALL).'</a>';
  101. Display::addFlash(Display::return_message(
  102. get_lang('Thematic section has been created successfully').'<br />'.sprintf(get_lang('NowYouShouldAddThematic planXAndThematic advanceX'), $link_to_thematic_plan, $link_to_thematic_advance),
  103. 'confirmation',
  104. false
  105. ));
  106. }
  107. if (empty($thematic_id)) {
  108. // display information
  109. $text = '<strong>'.get_lang('Information').': </strong>';
  110. $text .= get_lang('Thematic view with detailsDescription');
  111. $message = Display::return_message($text, 'info', false);
  112. }
  113. $list = [];
  114. // Display thematic data
  115. if (!empty($thematic_data)) {
  116. // display progress
  117. foreach ($thematic_data as $thematic) {
  118. $list['id'] = $thematic['id'];
  119. $list['id_course'] = $thematic['c_id'];
  120. $list['id_session'] = $thematic['session_id'];
  121. $list['title'] = Security::remove_XSS($thematic['title'], STUDENT);
  122. $list['content'] = Security::remove_XSS($thematic['content'], STUDENT);
  123. $list['display_orden'] = $thematic['display_order'];
  124. $list['active'] = $thematic['active'];
  125. $my_thematic_id = $thematic['id'];
  126. $session_star = '';
  127. if (api_is_allowed_to_edit(null, true)) {
  128. if (api_get_session_id() == $thematic['session_id']) {
  129. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  130. }
  131. }
  132. $tpl->assign('session_star', $session_star);
  133. //@todo add a validation in order to load or not course thematics in the session thematic
  134. $toolbarThematic = '';
  135. if (api_is_allowed_to_edit(null, true)) {
  136. // Thematic title
  137. $toolbarThematic = Display::url(
  138. Display::return_icon(
  139. 'cd.png',
  140. get_lang('Copy'),
  141. null,
  142. ICON_SIZE_TINY
  143. ),
  144. 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$params.$url_token,
  145. ['class' => 'btn btn-default']
  146. );
  147. if (api_get_session_id() == 0) {
  148. if ($thematic['display_order'] > 1) {
  149. $toolbarThematic .= ' <a class="btn btn-default" href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$params.$url_token.'">'.
  150. Display::return_icon('up.png', get_lang('Up'), '', ICON_SIZE_TINY).'</a>';
  151. } else {
  152. $toolbarThematic .= '<div class="btn btn-default">'.
  153. Display::return_icon('up_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
  154. }
  155. if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) {
  156. $toolbarThematic .= ' <a class="btn btn-default" href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$params.$url_token.'">'.
  157. Display::return_icon('down.png', get_lang('down'), '', ICON_SIZE_TINY).'</a>';
  158. } else {
  159. $toolbarThematic .= '<div class="btn btn-default">'.
  160. Display::return_icon('down_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
  161. }
  162. }
  163. if (api_get_session_id() == $thematic['session_id']) {
  164. $toolbarThematic .= Display::url(
  165. Display::return_icon('pdf.png', get_lang('Export to PDF'), null, ICON_SIZE_TINY),
  166. api_get_self().'?'.api_get_cidreq()."$url_token&".http_build_query([
  167. 'action' => 'export_single_thematic',
  168. 'thematic_id' => $my_thematic_id,
  169. ]),
  170. ['class' => 'btn btn-default']
  171. );
  172. $toolbarThematic .= Display::url(
  173. Display::return_icon(
  174. 'export_to_documents.png',
  175. get_lang('Export latest version of this page to Documents'),
  176. [],
  177. ICON_SIZE_TINY
  178. ),
  179. api_get_self().'?'.api_get_cidreq().$url_token.'&'.http_build_query(
  180. ['action' => 'export_single_documents', 'thematic_id' => $my_thematic_id]
  181. ),
  182. ['class' => 'btn btn-default']
  183. );
  184. $toolbarThematic .= '<a class="btn btn-default" href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='
  185. .$my_thematic_id.$params.$url_token.'">'
  186. .Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_TINY).'</a>';
  187. $toolbarThematic .= '<a class="btn btn-default" onclick="javascript:if(!confirm(\''
  188. .get_lang('Are you sure you want to delete')
  189. .'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='
  190. .$my_thematic_id.$params.$url_token.'">'
  191. .Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_TINY).'</a>';
  192. }
  193. }
  194. if (empty($thematic_plan_div[$thematic['id']])) {
  195. $list['thematic_plan'] = null;
  196. } else {
  197. $list['thematic_plan'] = $thematic_plan_div[$thematic['id']];
  198. }
  199. $list['thematic_advance'] = isset($thematic_advance_data[$thematic['id']])
  200. ? $thematic_advance_data[$thematic['id']]
  201. : null;
  202. $list['last_done'] = $last_done_thematic_advance;
  203. $list['toolbar'] = $toolbarThematic;
  204. $listThematic[] = $list;
  205. $tpl->assign('data', $listThematic);
  206. } //End for
  207. }
  208. $thematicLayout = $tpl->get_template('course_progress/progress.html.twig');
  209. $content = $tpl->fetch($thematicLayout);
  210. $tpl->assign('content', $content);
  211. } elseif ($action == 'thematic_add' || $action == 'thematic_edit') {
  212. // Display form
  213. $form = new FormValidator('thematic_add', 'POST', 'index.php?action=thematic_add&'.api_get_cidreq());
  214. if ($action == 'thematic_edit') {
  215. $form->addElement('header', '', get_lang('Edit thematic section'));
  216. }
  217. $form->addElement('hidden', 'sec_token', $token);
  218. $form->addElement('hidden', 'action', $action);
  219. if (!empty($thematic_id)) {
  220. $form->addElement('hidden', 'thematic_id', $thematic_id);
  221. }
  222. if (api_get_configuration_value('save_titles_as_html')) {
  223. $form->addHtmlEditor(
  224. 'title',
  225. get_lang('Title'),
  226. true,
  227. false,
  228. ['ToolbarSet' => 'TitleAsHtml']
  229. );
  230. } else {
  231. $form->addText('title', get_lang('Title'), true, ['size' => '50']);
  232. }
  233. $form->addHtmlEditor(
  234. 'content',
  235. get_lang('Content'),
  236. false,
  237. false,
  238. ['ToolbarSet' => 'Basic', 'Height' => '150']
  239. );
  240. $form->addButtonSave(get_lang('Save'));
  241. $show_form = true;
  242. if (!empty($thematic_data)) {
  243. if (api_get_session_id()) {
  244. if ($thematic_data['session_id'] != api_get_session_id()) {
  245. $show_form = false;
  246. echo Display::return_message(get_lang('Sorry, you are not allowed to access this page, or maybe your connection has expired. Please click your browser\'s "Back" button or follow the link below to return to the previous page.'), 'error', false);
  247. }
  248. }
  249. // set default values
  250. $default['title'] = $thematic_data['title'];
  251. $default['content'] = $thematic_data['content'];
  252. $form->setDefaults($default);
  253. }
  254. // error messages
  255. if (isset($error)) {
  256. echo Display::return_message(get_lang('The form contains incorrect or incomplete data. Please check your input.'), 'error', false);
  257. }
  258. if ($show_form) {
  259. $html = $form->returnForm();
  260. }
  261. } elseif ($action == 'thematic_import_select') {
  262. // Create form to upload csv file.
  263. $form = new FormValidator(
  264. 'thematic_import',
  265. 'POST',
  266. 'index.php?action=thematic_import&'.api_get_cidreq().$url_token
  267. );
  268. $form->addElement('header', get_lang('Import course progress'));
  269. $form->addElement('file', 'file');
  270. $form->addElement('checkbox', 'replace', null, get_lang('Delete all course progress'));
  271. $form->addButtonImport(get_lang('Import'), 'SubmitImport');
  272. $html = $form->returnForm();
  273. }
  274. $tpl->assign('actions', $toolbar);
  275. if (!empty($html)) {
  276. $tpl->assign('content', $html);
  277. $thematicLayout = $tpl->get_template('course_progress/layout.tpl');
  278. }
  279. if (!empty($message) && !empty($total_average_of_advances)) {
  280. $tpl->assign('message', $message);
  281. $tpl->assign('score_progress', $total_average_of_advances);
  282. }
  283. $tpl->display_one_col_template();