thematic.ajax.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * Responses to AJAX calls for thematic
  5. */
  6. require_once '../global.inc.php';
  7. require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
  8. api_protect_course_script(true);
  9. $action = $_GET['a'];
  10. $thematic = new Thematic();
  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. $label = '';
  83. $input_select = '';
  84. if (!empty($attendance_id)) {
  85. $attendance = new Attendance();
  86. $thematic = new Thematic();
  87. $thematic_list = $thematic->get_thematic_list();
  88. $my_list = $thematic_list_temp = array();
  89. foreach ($thematic_list as $item) {
  90. $my_list = $thematic->get_thematic_advance_by_thematic_id($item['id']);
  91. $thematic_list_temp = array_merge($my_list, $thematic_list_temp);
  92. }
  93. $new_thematic_list = array();
  94. foreach($thematic_list_temp as $item) {
  95. if (!empty($item['attendance_id']) ) {
  96. $new_thematic_list[$item['id']] = array('attendance_id' =>$item['attendance_id'], 'start_date'=>$item['start_date']);
  97. }
  98. }
  99. $attendance_calendar = $attendance->get_attendance_calendar($attendance_id);
  100. $label = get_lang('StartDate');
  101. if (!empty($attendance_calendar)) {
  102. $input_select .= '<select id="start_date_select_calendar" name="start_date_by_attendance" UNIQUE size="5">';
  103. foreach ($attendance_calendar as $calendar) {
  104. $selected = null;
  105. $insert = true;
  106. //checking if was already taken
  107. foreach ($new_thematic_list as $key => $thematic_item) {
  108. //if ($calendar['db_date_time'] == $thematic_item['start_date'] && $calendar['attendance_id'] == $thematic_item['attendance_id'] ) {
  109. if ($calendar['db_date_time'] == $thematic_item['start_date'] ) {
  110. $insert = false;
  111. if ($thematic_advance_id == $key) {
  112. $insert = true;
  113. $selected = 'selected';
  114. }
  115. break;
  116. }
  117. }
  118. if ($insert == true) {
  119. $input_select .= '<option '.$selected.' value="'.$calendar['date_time'].'">'.$calendar['date_time'].'</option>';
  120. }
  121. }
  122. $input_select .= '</select>';
  123. } else {
  124. $input_select .= '<em>'.get_lang('ThereAreNoRegisteredDatetimeYet').'</em>';
  125. }
  126. }
  127. ?>
  128. <div class="control-group">
  129. <label class="control-label"><?php echo $label ?></label>
  130. <div class="controls"><?php echo $input_select ?></div>
  131. </div>
  132. <?php
  133. break;
  134. case 'update_done_thematic_advance':
  135. $thematic_advance_id = intval($_GET['thematic_advance_id']);
  136. $total_average = 0;
  137. if (!empty($thematic_advance_id)) {
  138. $thematic = new Thematic();
  139. $affected_rows = $thematic->update_done_thematic_advances($thematic_advance_id);
  140. //if ($affected_rows) {
  141. $total_average = $thematic->get_total_average_of_thematic_advances(api_get_course_id(), api_get_session_id());
  142. //}
  143. }
  144. echo $total_average;
  145. break;
  146. default:
  147. echo '';
  148. }
  149. exit;