thematic.php 13 KB

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