thematic.ajax.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls for thematic.
  5. */
  6. require_once __DIR__.'/../global.inc.php';
  7. api_protect_course_script(true);
  8. $action = $_GET['a'];
  9. $thematic = new Thematic();
  10. switch ($action) {
  11. case 'save_thematic_plan':
  12. /*$title_list = $_REQUEST['title'];
  13. $description_list = $_REQUEST['desc'];
  14. //$description_list = $_REQUEST['description'];
  15. $description_type = $_REQUEST['description_type'];
  16. if (api_is_allowed_to_edit(null, true)) {
  17. for($i=1;$i<count($title_list)+1; $i++) {
  18. $thematic->set_thematic_plan_attributes($_REQUEST['thematic_id'], $title_list[$i], $description_list[$i], $description_type[$i]);
  19. $affected_rows = $thematic->thematic_plan_save();
  20. }
  21. }
  22. $thematic_plan_data = $thematic->get_thematic_plan_data();
  23. $return = $thematic->get_thematic_plan_div($thematic_plan_data);
  24. echo $return[$_REQUEST['thematic_id']];*/
  25. break;
  26. case 'save_thematic_advance':
  27. if (!api_is_allowed_to_edit(null, true)) {
  28. echo '';
  29. exit;
  30. }
  31. /*
  32. if (($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) || (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) ) {
  33. if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) {
  34. $start_date_error = true;
  35. $data['start_date_error'] = $start_date_error;
  36. }
  37. if (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) {
  38. $duration_error = true;
  39. $data['duration_error'] = $duration_error;
  40. }
  41. $data['action'] = $_REQUEST['action'];
  42. $data['thematic_id'] = $_REQUEST['thematic_id'];
  43. $data['attendance_select'] = $attendance_select;
  44. if (isset($_REQUEST['thematic_advance_id'])) {
  45. $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id'];
  46. $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']);
  47. $data['thematic_advance_data'] = $thematic_advance_data;
  48. }
  49. } else {
  50. if ($_REQUEST['thematic_advance_token'] == $_SESSION['thematic_advance_token'] && api_is_allowed_to_edit(null, true)) {
  51. $thematic_advance_id = $_REQUEST['thematic_advance_id'];
  52. $thematic_id = $_REQUEST['thematic_id'];
  53. $content = $_REQUEST['real_content'];
  54. $duration = $_REQUEST['duration_in_hours'];
  55. if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 2) {
  56. $start_date = $thematic->build_datetime_from_array($_REQUEST['custom_start_date']);
  57. $attendance_id = 0;
  58. } else {
  59. $start_date = $_REQUEST['start_date_by_attendance'];
  60. $attendance_id = $_REQUEST['attendance_select'];
  61. }
  62. $thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration);
  63. $affected_rows = $thematic->thematic_advance_save();
  64. if ($affected_rows) {
  65. // get last done thematic advance before move thematic list
  66. $last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
  67. // update done advances with de current thematic list
  68. if (!empty($last_done_thematic_advance)) {
  69. $update_done_advances = $thematic->update_done_thematic_advances($last_done_thematic_advance);
  70. }
  71. }
  72. }
  73. }
  74. $thematic_advance_data = $thematic->get_thematic_advance_list(null, null, true);
  75. $return = $thematic->get_thematic_advance_div($thematic_advance_data);
  76. echo $return[$_REQUEST['thematic_id']][$_REQUEST['thematic_advance_id']];*/
  77. break;
  78. case 'get_datetime_by_attendance':
  79. $attendance_id = intval($_REQUEST['attendance_id']);
  80. $thematic_advance_id = intval($_REQUEST['thematic_advance_id']);
  81. $label = '';
  82. $input_select = '';
  83. if (!empty($attendance_id)) {
  84. $attendance = new Attendance();
  85. $thematic = new Thematic();
  86. $thematic_list = $thematic->get_thematic_list();
  87. $my_list = $thematic_list_temp = [];
  88. foreach ($thematic_list as $item) {
  89. $my_list = $thematic->get_thematic_advance_by_thematic_id($item['id']);
  90. $thematic_list_temp = array_merge($my_list, $thematic_list_temp);
  91. }
  92. $new_thematic_list = [];
  93. foreach ($thematic_list_temp as $item) {
  94. if (!empty($item['attendance_id'])) {
  95. $new_thematic_list[$item['id']] = [
  96. 'attendance_id' => $item['attendance_id'],
  97. 'start_date' => $item['start_date'],
  98. ];
  99. }
  100. }
  101. $attendance_calendar = $attendance->get_attendance_calendar($attendance_id);
  102. $label = get_lang('Start Date');
  103. if (!empty($attendance_calendar)) {
  104. $input_select .= '<select id="start_date_select_calendar" name="start_date_by_attendance" size="7" class="form-control">';
  105. foreach ($attendance_calendar as $calendar) {
  106. $selected = null;
  107. $insert = true;
  108. //checking if was already taken
  109. foreach ($new_thematic_list as $key => $thematic_item) {
  110. if ($calendar['db_date_time'] == $thematic_item['start_date']) {
  111. $insert = false;
  112. if ($thematic_advance_id == $key) {
  113. $insert = true;
  114. $selected = 'selected';
  115. }
  116. break;
  117. }
  118. }
  119. if ($insert == true) {
  120. $input_select .= '<option '.$selected.' value="'.$calendar['date_time'].'">'.$calendar['date_time'].'</option>';
  121. }
  122. }
  123. $input_select .= '</select>';
  124. } else {
  125. $input_select .= '<em>'.get_lang('There is no date/time registered yet').'</em>';
  126. }
  127. }
  128. ?>
  129. <div class="form-group">
  130. <label class="col-sm-2 control-label"><?php echo $label; ?></label>
  131. <div class="col-sm-8"><?php echo $input_select; ?></div>
  132. </div>
  133. <?php
  134. break;
  135. case 'update_done_thematic_advance':
  136. $thematic_advance_id = intval($_GET['thematic_advance_id']);
  137. $total_average = 0;
  138. if (!empty($thematic_advance_id)) {
  139. $thematic = new Thematic();
  140. $affected_rows = $thematic->update_done_thematic_advances($thematic_advance_id);
  141. $total_average = $thematic->get_total_average_of_thematic_advances(
  142. api_get_course_id(),
  143. api_get_session_id()
  144. );
  145. }
  146. echo $total_average;
  147. break;
  148. default:
  149. echo '';
  150. }
  151. exit;