index.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action.
  6. *
  7. * @author Christian Fasanando <christian1827@gmail.com>
  8. * @author Julio Montoya <gugli100@gmail.com> Bugfixes session support
  9. *
  10. * @package chamilo.course_progress
  11. */
  12. // including files
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. require_once 'thematic_controller.php';
  15. // current section
  16. $this_section = SECTION_COURSES;
  17. $current_course_tool = TOOL_COURSE_PROGRESS;
  18. // protect a course script
  19. api_protect_course_script(true);
  20. // get actions
  21. $actions = [
  22. 'thematic_details',
  23. 'thematic_list',
  24. 'thematic_add',
  25. 'thematic_edit',
  26. 'thematic_copy',
  27. 'thematic_delete',
  28. 'moveup',
  29. 'movedown',
  30. 'thematic_import_select',
  31. 'thematic_import',
  32. 'thematic_export',
  33. 'thematic_export_pdf',
  34. 'export_documents',
  35. 'thematic_plan_list',
  36. 'thematic_plan_add',
  37. 'thematic_plan_edit',
  38. 'thematic_plan_delete',
  39. 'thematic_advance_list',
  40. 'thematic_advance_add',
  41. 'thematic_advance_edit',
  42. 'thematic_advance_delete',
  43. 'export_single_thematic',
  44. 'export_single_documents',
  45. ];
  46. $action = 'thematic_details';
  47. if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], $actions)) {
  48. $action = $_REQUEST['action'];
  49. }
  50. if (isset($_POST['action']) && $_POST['action'] == 'thematic_delete_select') {
  51. $action = 'thematic_delete_select';
  52. }
  53. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  54. $action = 'thematic_details';
  55. }
  56. if ($action == 'thematic_details' || $action == 'thematic_list') {
  57. Session::write('thematic_control', $action);
  58. }
  59. // get thematic id
  60. $thematic_id = isset($_GET['thematic_id']) ? (int) $_GET['thematic_id'] : 0;
  61. // instance thematic object for using like library here
  62. $thematic = new Thematic();
  63. // thematic controller object
  64. $thematic_controller = new ThematicController();
  65. $thematic_data = [];
  66. if (!empty($thematic_id)) {
  67. // thematic data by id
  68. $thematic_data = $thematic->get_thematic_list($thematic_id);
  69. }
  70. $cleanThematicTitle = isset($thematic_data['title']) ? strip_tags($thematic_data['title']) : null;
  71. // get default thematic plan title
  72. $default_thematic_plan_title = $thematic->get_default_thematic_plan_title();
  73. // Only when I see the 3 columns. Avoids double or triple click binding for onclick event
  74. $htmlHeadXtra[] = '<script>
  75. $(function() {
  76. $(".thematic_advance_actions, .thematic_tools ").hide();
  77. $(".thematic_content").mouseover(function() {
  78. var id = parseInt(this.id.split("_")[3]);
  79. $("#thematic_id_content_"+id ).show();
  80. });
  81. $(".thematic_content").mouseleave(function() {
  82. var id = parseInt(this.id.split("_")[3]);
  83. $("#thematic_id_content_"+id ).hide();
  84. });
  85. $(".thematic_advance_content").mouseover(function() {
  86. var id = parseInt(this.id.split("_")[4]);
  87. $("#thematic_advance_tools_"+id ).show();
  88. });
  89. $(".thematic_advance_content").mouseleave(function() {
  90. var id = parseInt(this.id.split("_")[4]);
  91. $("#thematic_advance_tools_"+id ).hide();
  92. });
  93. });
  94. </script>';
  95. $htmlHeadXtra[] = '<script>
  96. function datetime_by_attendance(attendance_id, thematic_advance_id) {
  97. $.ajax({
  98. contentType: "application/x-www-form-urlencoded",
  99. beforeSend: function(myObject) {},
  100. type: "GET",
  101. url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=get_datetime_by_attendance",
  102. data: "attendance_id="+attendance_id+"&thematic_advance_id="+thematic_advance_id,
  103. success: function(data) {
  104. $("#div_datetime_attendance").html(data);
  105. if (thematic_advance_id == 0) {
  106. $("#start_date_select_calendar").val($("#start_date_select_calendar option:first").val());
  107. }
  108. }
  109. });
  110. }
  111. function update_done_thematic_advance(selected_value) {
  112. $.ajax({
  113. contentType: "application/x-www-form-urlencoded",
  114. beforeSend: function(myObject) {},
  115. type: "GET",
  116. url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=update_done_thematic_advance",
  117. data: "thematic_advance_id="+selected_value,
  118. success: function(data) {
  119. $("#div_result").html(data);
  120. }
  121. });
  122. // clean all radios
  123. for (var i=0; i< $(".done_thematic").length;i++) {
  124. var id_radio_thematic = $(".done_thematic").get(i).id;
  125. $("#td_"+id_radio_thematic).css({"background-color":"#FFF"});
  126. }
  127. // set background to previous radios
  128. for (var i=0; i < $(".done_thematic").length;i++) {
  129. var id_radio_thematic = $(".done_thematic").get(i).id;
  130. $("#td_"+id_radio_thematic).css({"background-color":"#E5EDF9"});
  131. if ($(".done_thematic").get(i).value == selected_value) {
  132. break;
  133. }
  134. }
  135. }
  136. function check_per_attendance(obj) {
  137. if (obj.checked) {
  138. $("#div_datetime_by_attendance").show();
  139. $("#div_custom_datetime").hide();
  140. } else {
  141. $("#div_datetime_by_attendance").hide();
  142. $("#div_custom_datetime").show();
  143. }
  144. }
  145. function check_per_custom_date(obj) {
  146. if (obj.checked) {
  147. $("#div_custom_datetime").show();
  148. $("#div_datetime_by_attendance").hide();
  149. } else {
  150. $("#div_custom_datetime").hide();
  151. $("#div_datetime_by_attendance").show();
  152. }
  153. }
  154. </script>';
  155. $thematicControl = Session::read('thematic_control');
  156. if ($action == 'thematic_list') {
  157. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('ThematicControl')];
  158. }
  159. if ($action == 'thematic_add') {
  160. $interbreadcrumb[] = [
  161. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  162. 'name' => get_lang('ThematicControl'),
  163. ];
  164. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewThematicSection')];
  165. }
  166. if ($action == 'thematic_edit') {
  167. $interbreadcrumb[] = [
  168. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  169. 'name' => get_lang('ThematicControl'),
  170. ];
  171. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('EditThematicSection')];
  172. }
  173. if ($action == 'thematic_details') {
  174. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('ThematicControl')];
  175. }
  176. if ($action == 'thematic_plan_list' || $action == 'thematic_plan_delete') {
  177. $interbreadcrumb[] = [
  178. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  179. 'name' => get_lang('ThematicControl'),
  180. ];
  181. if (!empty($thematic_data)) {
  182. $interbreadcrumb[] = [
  183. 'url' => '#',
  184. 'name' => get_lang('ThematicPlan').' ('.$cleanThematicTitle.') ',
  185. ];
  186. }
  187. }
  188. if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
  189. $interbreadcrumb[] = [
  190. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  191. 'name' => get_lang('ThematicControl'),
  192. ];
  193. $interbreadcrumb[] = [
  194. 'url' => 'index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic_id,
  195. 'name' => get_lang('ThematicPlan').' ('.$cleanThematicTitle.')',
  196. ];
  197. }
  198. if ($action == 'thematic_advance_list' || $action == 'thematic_advance_delete') {
  199. $interbreadcrumb[] = [
  200. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  201. 'name' => get_lang('ThematicControl'),
  202. ];
  203. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('ThematicAdvance').' ('.$cleanThematicTitle.')'];
  204. }
  205. if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
  206. $interbreadcrumb[] = [
  207. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  208. 'name' => get_lang('ThematicControl'),
  209. ];
  210. $interbreadcrumb[] = [
  211. 'url' => 'index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic_id,
  212. 'name' => get_lang('ThematicAdvance').' ('.$cleanThematicTitle.')',
  213. ];
  214. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewThematicAdvance')];
  215. }
  216. if ($action == 'thematic_plan_list') {
  217. $htmlHeadXtra[] = "
  218. <script>
  219. $(function () {
  220. $('.btn-delete').on('click', function (e) {
  221. e.preventDefault();
  222. var id = $(this).data('id') || 0;
  223. if (!id) {
  224. return;
  225. }
  226. //$('[name=\"title[' + id + ']\"]').val('');
  227. CKEDITOR.instances['description[' + id + ']'].setData('');
  228. });
  229. });
  230. </script>
  231. ";
  232. }
  233. // Dispatch actions to controller
  234. switch ($action) {
  235. case 'thematic_add':
  236. case 'thematic_edit':
  237. case 'thematic_delete':
  238. case 'thematic_delete_select':
  239. case 'thematic_copy':
  240. case 'thematic_import_select':
  241. case 'thematic_import':
  242. case 'moveup':
  243. case 'movedown':
  244. if (!api_is_allowed_to_edit(null, true)) {
  245. api_not_allowed();
  246. }
  247. //no break
  248. case 'thematic_list':
  249. case 'thematic_export':
  250. case 'thematic_export_pdf':
  251. case 'thematic_details':
  252. case 'export_single_thematic':
  253. case 'export_documents':
  254. case 'export_single_documents':
  255. $thematic_controller->thematic($action);
  256. break;
  257. case 'thematic_plan_add':
  258. case 'thematic_plan_edit':
  259. case 'thematic_plan_delete':
  260. if (!api_is_allowed_to_edit(null, true)) {
  261. api_not_allowed();
  262. }
  263. //no break
  264. case 'thematic_plan_list':
  265. $thematic_controller->thematic_plan($action);
  266. break;
  267. case 'thematic_advance_add':
  268. case 'thematic_advance_edit':
  269. case 'thematic_advance_delete':
  270. if (!api_is_allowed_to_edit(null, true)) {
  271. api_not_allowed();
  272. }
  273. //no break
  274. case 'thematic_advance_list':
  275. $thematic_controller->thematic_advance($action);
  276. break;
  277. }