index.php 10.0 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. $cleanThematicTitle = isset($thematic_data['title']) ? strip_tags($thematic_data['title']) : null;
  69. // get default thematic plan title
  70. $default_thematic_plan_title = $thematic->get_default_thematic_plan_title();
  71. // Only when I see the 3 columns. Avoids double or triple click binding for onclick event
  72. $htmlHeadXtra[] = '<script>
  73. $(document).ready(function() {
  74. $(".thematic_advance_actions, .thematic_tools ").hide();
  75. $(".thematic_content").mouseover(function() {
  76. var id = parseInt(this.id.split("_")[3]);
  77. $("#thematic_id_content_"+id ).show();
  78. });
  79. $(".thematic_content").mouseleave(function() {
  80. var id = parseInt(this.id.split("_")[3]);
  81. $("#thematic_id_content_"+id ).hide();
  82. });
  83. $(".thematic_advance_content").mouseover(function() {
  84. var id = parseInt(this.id.split("_")[4]);
  85. $("#thematic_advance_tools_"+id ).show();
  86. });
  87. $(".thematic_advance_content").mouseleave(function() {
  88. var id = parseInt(this.id.split("_")[4]);
  89. $("#thematic_advance_tools_"+id ).hide();
  90. });
  91. });
  92. </script>';
  93. $htmlHeadXtra[] = '<script>
  94. function datetime_by_attendance(attendance_id, thematic_advance_id) {
  95. $.ajax({
  96. contentType: "application/x-www-form-urlencoded",
  97. beforeSend: function(objeto) {},
  98. type: "GET",
  99. url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=get_datetime_by_attendance",
  100. data: "attendance_id="+attendance_id+"&thematic_advance_id="+thematic_advance_id,
  101. success: function(data) {
  102. $("#div_datetime_attendance").html(data);
  103. if (thematic_advance_id == 0) {
  104. $("#start_date_select_calendar").val($("#start_date_select_calendar option:first").val());
  105. }
  106. }
  107. });
  108. }
  109. function update_done_thematic_advance(selected_value) {
  110. $.ajax({
  111. contentType: "application/x-www-form-urlencoded",
  112. beforeSend: function(objeto) {},
  113. type: "GET",
  114. url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=update_done_thematic_advance",
  115. data: "thematic_advance_id="+selected_value,
  116. success: function(data) {
  117. $("#div_result").html(data);
  118. }
  119. });
  120. // clean all radios
  121. for (var i=0; i< $(".done_thematic").length;i++) {
  122. var id_radio_thematic = $(".done_thematic").get(i).id;
  123. $("#td_"+id_radio_thematic).css({"background-color":"#FFF"});
  124. }
  125. // set background to previous radios
  126. for (var i=0; i < $(".done_thematic").length;i++) {
  127. var id_radio_thematic = $(".done_thematic").get(i).id;
  128. $("#td_"+id_radio_thematic).css({"background-color":"#E5EDF9"});
  129. if ($(".done_thematic").get(i).value == selected_value) {
  130. break;
  131. }
  132. }
  133. }
  134. function check_per_attendance(obj) {
  135. if (obj.checked) {
  136. $("#div_datetime_by_attendance").show();
  137. $("#div_custom_datetime").hide();
  138. } else {
  139. $("#div_datetime_by_attendance").hide();
  140. $("#div_custom_datetime").show();
  141. }
  142. }
  143. function check_per_custom_date(obj) {
  144. if (obj.checked) {
  145. $("#div_custom_datetime").show();
  146. $("#div_datetime_by_attendance").hide();
  147. } else {
  148. $("#div_custom_datetime").hide();
  149. $("#div_datetime_by_attendance").show();
  150. }
  151. }
  152. </script>';
  153. $thematicControl = Session::read('thematic_control');
  154. if ($action == 'thematic_list') {
  155. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('ThematicControl'));
  156. }
  157. if ($action == 'thematic_add') {
  158. $interbreadcrumb[] = array(
  159. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  160. 'name' => get_lang('ThematicControl')
  161. );
  162. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewThematicSection'));
  163. }
  164. if ($action == 'thematic_edit') {
  165. $interbreadcrumb[] = array(
  166. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  167. 'name' => get_lang('ThematicControl')
  168. );
  169. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditThematicSection'));
  170. }
  171. if ($action == 'thematic_details') {
  172. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('ThematicControl'));
  173. }
  174. if ($action == 'thematic_plan_list' || $action == 'thematic_plan_delete') {
  175. $interbreadcrumb[] = array(
  176. 'url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl,
  177. 'name' => get_lang('ThematicControl')
  178. );
  179. if (!empty($thematic_data)) {
  180. $interbreadcrumb[] = array(
  181. 'url' => '#',
  182. 'name' => get_lang('ThematicPlan').' ('.$cleanThematicTitle.') '
  183. );
  184. }
  185. }
  186. if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
  187. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl, 'name' => get_lang('ThematicControl'));
  188. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$thematic_id, 'name' => get_lang('ThematicPlan').' ('.$cleanThematicTitle.')');
  189. if ($description_type >= ADD_THEMATIC_PLAN) {
  190. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewBloc'));
  191. } else {
  192. $interbreadcrumb[] = array('url' => '#', 'name' => $default_thematic_plan_title[$description_type]);
  193. }
  194. }
  195. if ($action == 'thematic_advance_list' || $action == 'thematic_advance_delete') {
  196. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl, 'name' => get_lang('ThematicControl'));
  197. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('ThematicAdvance').' ('.$cleanThematicTitle.')');
  198. }
  199. if ($action == 'thematic_advance_add' || $action == 'thematic_advance_edit') {
  200. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action='.$thematicControl, 'name' => get_lang('ThematicControl'));
  201. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$thematic_id, 'name' => get_lang('ThematicAdvance').' ('.$cleanThematicTitle.')');
  202. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewThematicAdvance'));
  203. }
  204. if ($action == 'thematic_plan_list') {
  205. $htmlHeadXtra[] = "
  206. <script>
  207. $(function () {
  208. $('.btn-delete').on('click', function (e) {
  209. e.preventDefault();
  210. var id = $(this).data('id') || 0;
  211. if (!id) {
  212. return;
  213. }
  214. //$('[name=\"title[' + id + ']\"]').val('');
  215. CKEDITOR.instances['description[' + id + ']'].setData('');
  216. });
  217. });
  218. </script>
  219. ";
  220. }
  221. // Dispatch actions to controller
  222. switch ($action) {
  223. case 'thematic_add':
  224. //no break
  225. case 'thematic_edit':
  226. //no break
  227. case 'thematic_delete':
  228. //no break
  229. case 'thematic_delete_select':
  230. //no break
  231. case 'thematic_copy':
  232. //no break
  233. case 'thematic_import_select':
  234. //no break
  235. case 'thematic_import':
  236. //no break
  237. case 'moveup':
  238. //no break
  239. case 'movedown':
  240. if (!api_is_allowed_to_edit(null, true)) {
  241. api_not_allowed();
  242. }
  243. //no break
  244. case 'thematic_list':
  245. //no break
  246. case 'thematic_export':
  247. //no break
  248. case 'thematic_export_pdf':
  249. //no break
  250. case 'thematic_details':
  251. //no break
  252. case 'export_single_thematic':
  253. $thematic_controller->thematic($action);
  254. break;
  255. case 'thematic_plan_add':
  256. //no break
  257. case 'thematic_plan_edit':
  258. //no break
  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. //no break
  269. case 'thematic_advance_edit':
  270. //no break
  271. case 'thematic_advance_delete':
  272. if (!api_is_allowed_to_edit(null, true)) {
  273. api_not_allowed();
  274. }
  275. //no break
  276. case 'thematic_advance_list':
  277. $thematic_controller->thematic_advance($action);
  278. break;
  279. }