thematic.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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('new_course_progress.png', get_lang('NewThematicSection'), '', ICON_SIZE_MEDIUM).'</a>';
  45. }
  46. $toolbar = Display::toolbarAction('thematic-bar', array($actionLeft));
  47. }
  48. if ($action == 'thematic_list') {
  49. $table = new SortableTable(
  50. 'thematic_list',
  51. array('Thematic', 'get_number_of_thematics'),
  52. array('Thematic', 'get_thematic_data')
  53. );
  54. $parameters['action'] = $action;
  55. $table->set_additional_parameters($parameters);
  56. $table->set_header(0, '', false, array('style' => 'width:20px;'));
  57. $table->set_header(1, get_lang('Title'), false);
  58. if (api_is_allowed_to_edit(null, true)) {
  59. $table->set_header(
  60. 2,
  61. get_lang('Actions'),
  62. false,
  63. array('style' => 'text-align:center;width:40%;')
  64. );
  65. $table->set_form_actions(array('thematic_delete_select' => get_lang('DeleteAllThematics')));
  66. }
  67. $table->display();
  68. } elseif ($action == 'thematic_details') {
  69. if (isset($_GET['thematic_plan_save_message']) && $_GET['thematic_plan_save_message'] == 'ok') {
  70. Display::addFlash(Display::return_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'), 'confirmation', false));
  71. }
  72. if (isset($last_id) && $last_id) {
  73. $link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.
  74. Display::return_icon('lesson_plan.png', get_lang('ThematicPlan'), array('style' => 'vertical-align:middle;float:none;'), ICON_SIZE_SMALL).'</a>';
  75. $link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'.
  76. Display::return_icon('lesson_plan_calendar.png', get_lang('ThematicAdvance'), array('style' => 'vertical-align:middle;float:none;'), ICON_SIZE_SMALL).'</a>';
  77. Display::addFlash(Display::return_message(
  78. get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'), $link_to_thematic_plan, $link_to_thematic_advance),
  79. 'confirmation',
  80. false
  81. ));
  82. }
  83. if (empty($thematic_id)) {
  84. // display information
  85. $text = '<strong>'.get_lang('Information').': </strong>';
  86. $text .= get_lang('ThematicDetailsDescription');
  87. $message = Display::return_message($text, 'info', false);
  88. }
  89. $list = [];
  90. // Display thematic data
  91. if (!empty($thematic_data)) {
  92. // display progress
  93. foreach ($thematic_data as $thematic) {
  94. $list['id'] = $thematic['id'];
  95. $list['id_course'] = $thematic['c_id'];
  96. $list['id_session'] = $thematic['session_id'];
  97. $list['title'] = Security::remove_XSS($thematic['title'], STUDENT);
  98. $list['content'] = Security::remove_XSS($thematic['content'], STUDENT);
  99. $list['display_orden'] = $thematic['display_order'];
  100. $list['active'] = $thematic['active'];
  101. $my_thematic_id = $thematic['id'];
  102. $session_star = '';
  103. if (api_is_allowed_to_edit(null, true)) {
  104. if (api_get_session_id() == $thematic['session_id']) {
  105. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  106. }
  107. }
  108. $tpl->assign('session_star', $session_star);
  109. //@todo add a validation in order to load or not course thematics in the session thematic
  110. $toolbarThematic = '';
  111. if (api_is_allowed_to_edit(null, true)) {
  112. // Thematic title
  113. $toolbarThematic = Display::url(
  114. Display::return_icon('cd.png', get_lang('Copy'), null, ICON_SIZE_TINY),
  115. 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$params.$url_token,
  116. array('class'=> 'btn btn-default')
  117. );
  118. if (api_get_session_id() == 0) {
  119. if ($thematic['display_order'] > 1) {
  120. $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>';
  121. } else {
  122. $toolbarThematic .= '<div class="btn btn-default">'.Display::return_icon('up_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
  123. }
  124. if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) {
  125. $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>';
  126. } else {
  127. $toolbarThematic .= '<div class="btn btn-default">'.Display::return_icon('down_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
  128. }
  129. }
  130. if (api_get_session_id() == $thematic['session_id']) {
  131. $toolbarThematic .= Display::url(
  132. Display::return_icon('pdf.png', get_lang('ExportToPDF'), null, ICON_SIZE_TINY),
  133. api_get_self().'?'.api_get_cidreq()."$url_token&".http_build_query([
  134. 'action' => 'export_single_thematic',
  135. 'thematic_id' => $my_thematic_id
  136. ]),
  137. array('class' => 'btn btn-default')
  138. );
  139. $toolbarThematic .= Display::url(
  140. Display::return_icon('export_to_documents.png', get_lang('ExportToDocArea'), [], ICON_SIZE_TINY),
  141. api_get_self().'?'.api_get_cidreq().$url_token.'&'
  142. .http_build_query(['action' => 'export_single_documents', 'thematic_id' => $my_thematic_id]),
  143. ['class' => 'btn btn-default']
  144. );
  145. $toolbarThematic .= '<a class="btn btn-default" href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='
  146. .$my_thematic_id.$params.$url_token.'">'
  147. .Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_TINY).'</a>';
  148. $toolbarThematic .= '<a class="btn btn-default" onclick="javascript:if(!confirm(\''
  149. .get_lang('AreYouSureToDelete')
  150. .'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='
  151. .$my_thematic_id.$params.$url_token.'">'
  152. .Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_TINY).'</a>';
  153. }
  154. }
  155. if (empty($thematic_plan_div[$thematic['id']])) {
  156. $list['thematic_plan'] = null;
  157. } else {
  158. $list['thematic_plan'] = $thematic_plan_div[$thematic['id']];
  159. }
  160. $list['thematic_advance'] = isset($thematic_advance_data[$thematic['id']])
  161. ? $thematic_advance_data[$thematic['id']]
  162. : null;
  163. $list['last_done'] = $last_done_thematic_advance;
  164. $list['toolbar'] = $toolbarThematic;
  165. $listThematic[] = $list;
  166. $tpl->assign('data', $listThematic);
  167. } //End for
  168. }
  169. $thematicLayout = $tpl->get_template('course_progress/progress.tpl');
  170. } elseif ($action == 'thematic_add' || $action == 'thematic_edit') {
  171. // Display form
  172. $form = new FormValidator('thematic_add', 'POST', 'index.php?action=thematic_add&'.api_get_cidreq());
  173. if ($action == 'thematic_edit') {
  174. $form->addElement('header', '', get_lang('EditThematicSection'));
  175. }
  176. $form->addElement('hidden', 'sec_token', $token);
  177. $form->addElement('hidden', 'action', $action);
  178. if (!empty($thematic_id)) {
  179. $form->addElement('hidden', 'thematic_id', $thematic_id);
  180. }
  181. if (api_get_configuration_value('save_titles_as_html')) {
  182. $form->addHtmlEditor(
  183. 'title',
  184. get_lang('Title'),
  185. true,
  186. false,
  187. ['ToolbarSet' => 'Minimal']
  188. );
  189. } else {
  190. $form->addText('title', get_lang('Title'), true, array('size' => '50'));
  191. }
  192. $form->addHtmlEditor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Height' => '150'));
  193. $form->addButtonSave(get_lang('Save'));
  194. $show_form = true;
  195. if (!empty($thematic_data)) {
  196. if (api_get_session_id()) {
  197. if ($thematic_data['session_id'] != api_get_session_id()) {
  198. $show_form = false;
  199. echo Display::return_message(get_lang('NotAllowedClickBack'), 'error', false);
  200. }
  201. }
  202. // set default values
  203. $default['title'] = $thematic_data['title'];
  204. $default['content'] = $thematic_data['content'];
  205. $form->setDefaults($default);
  206. }
  207. // error messages
  208. if (isset($error)) {
  209. echo Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error', false);
  210. }
  211. if ($show_form) {
  212. $html = $form->returnForm();
  213. }
  214. } elseif ($action == 'thematic_import_select') {
  215. // Create form to upload csv file.
  216. $form = new FormValidator('thematic_import', 'POST', 'index.php?action=thematic_import&'.api_get_cidreq().$url_token);
  217. $form->addElement('header', get_lang('ImportThematic'));
  218. $form->addElement('file', 'file');
  219. $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllThematic'));
  220. $form->addButtonImport(get_lang('Import'), 'SubmitImport');
  221. $html = $form->returnForm();
  222. }
  223. $tpl->assign('actions', $toolbar);
  224. if (!empty($html)) {
  225. $tpl->assign('content', $html);
  226. $thematicLayout = $tpl->get_template('course_progress/layout.tpl');
  227. }
  228. if (!empty($message) && !empty($total_average_of_advances)) {
  229. $tpl->assign('message', $message);
  230. $tpl->assign('score_progress', $total_average_of_advances);
  231. }
  232. $tpl->display($thematicLayout);