thematic.php 12 KB

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