thematic.ajax.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
  9. api_protect_course_script(true);
  10. $action = $_GET['a'];
  11. $thematic = new Thematic();
  12. switch ($action) {
  13. case 'save_thematic_plan':
  14. /*$title_list = $_REQUEST['title'];
  15. $description_list = $_REQUEST['desc'];
  16. //$description_list = $_REQUEST['description'];
  17. $description_type = $_REQUEST['description_type'];
  18. if (api_is_allowed_to_edit(null, true)) {
  19. for($i=1;$i<count($title_list)+1; $i++) {
  20. $thematic->set_thematic_plan_attributes($_REQUEST['thematic_id'], $title_list[$i], $description_list[$i], $description_type[$i]);
  21. $affected_rows = $thematic->thematic_plan_save();
  22. }
  23. }
  24. $thematic_plan_data = $thematic->get_thematic_plan_data();
  25. $return = $thematic->get_thematic_plan_div($thematic_plan_data);
  26. echo $return[$_REQUEST['thematic_id']];*/
  27. break;
  28. case 'save_thematic_advance':
  29. if (!api_is_allowed_to_edit(null, true)) {
  30. echo '';
  31. exit;
  32. }
  33. /*
  34. if (($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) || (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) ) {
  35. if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) {
  36. $start_date_error = true;
  37. $data['start_date_error'] = $start_date_error;
  38. }
  39. if (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) {
  40. $duration_error = true;
  41. $data['duration_error'] = $duration_error;
  42. }
  43. $data['action'] = $_REQUEST['action'];
  44. $data['thematic_id'] = $_REQUEST['thematic_id'];
  45. $data['attendance_select'] = $attendance_select;
  46. if (isset($_REQUEST['thematic_advance_id'])) {
  47. $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id'];
  48. $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']);
  49. $data['thematic_advance_data'] = $thematic_advance_data;
  50. }
  51. } else {
  52. if ($_REQUEST['thematic_advance_token'] == $_SESSION['thematic_advance_token'] && api_is_allowed_to_edit(null, true)) {
  53. $thematic_advance_id = $_REQUEST['thematic_advance_id'];
  54. $thematic_id = $_REQUEST['thematic_id'];
  55. $content = $_REQUEST['real_content'];
  56. $duration = $_REQUEST['duration_in_hours'];
  57. if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 2) {
  58. $start_date = $thematic->build_datetime_from_array($_REQUEST['custom_start_date']);
  59. $attendance_id = 0;
  60. } else {
  61. $start_date = $_REQUEST['start_date_by_attendance'];
  62. $attendance_id = $_REQUEST['attendance_select'];
  63. }
  64. $thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration);
  65. $affected_rows = $thematic->thematic_advance_save();
  66. if ($affected_rows) {
  67. // get last done thematic advance before move thematic list
  68. $last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
  69. // update done advances with de current thematic list
  70. if (!empty($last_done_thematic_advance)) {
  71. $update_done_advances = $thematic->update_done_thematic_advances($last_done_thematic_advance);
  72. }
  73. }
  74. }
  75. }
  76. $thematic_advance_data = $thematic->get_thematic_advance_list(null, null, true);
  77. $return = $thematic->get_thematic_advance_div($thematic_advance_data);
  78. echo $return[$_REQUEST['thematic_id']][$_REQUEST['thematic_advance_id']];*/
  79. break;
  80. case 'get_datetime_by_attendance':
  81. $attendance_id = intval($_REQUEST['attendance_id']);
  82. $thematic_advance_id = intval($_REQUEST['thematic_advance_id']);
  83. $label = '';
  84. $input_select = '';
  85. if (!empty($attendance_id)) {
  86. $attendance = new Attendance();
  87. $thematic = new Thematic();
  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. $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. //if ($affected_rows) {
  142. $total_average = $thematic->get_total_average_of_thematic_advances(api_get_course_id(), api_get_session_id());
  143. //}
  144. }
  145. echo $total_average;
  146. break;
  147. default:
  148. echo '';
  149. }
  150. exit;