thematic.ajax.php 6.5 KB

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