index.php 9.9 KB

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