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