@@ -11,50 +11,50 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class Attendance |
13 | 13 | { |
14 | - private $session_id; |
|
15 | - private $course_id; |
|
16 | - private $date_time; |
|
17 | - private $name; |
|
18 | - private $description; |
|
19 | - private $attendance_qualify_title; |
|
20 | - private $attendance_weight; |
|
21 | - private $course_int_id; |
|
22 | - public $category_id; |
|
23 | - |
|
24 | - // constants |
|
25 | - const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet'; |
|
26 | - const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet'; |
|
27 | - const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Constructor |
|
31 | - */ |
|
32 | - public function __construct() |
|
33 | - { |
|
34 | - //$this->course_int_id = api_get_course_int_id(); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Get the total number of attendance inside current course and current session |
|
39 | - * @see SortableTable#get_total_number_of_items() |
|
40 | - */ |
|
41 | - public static function get_number_of_attendances($active = -1) |
|
42 | - { |
|
43 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
44 | - $session_id = api_get_session_id(); |
|
45 | - $condition_session = api_get_session_condition($session_id); |
|
46 | - $course_id = api_get_course_int_id(); |
|
47 | - $sql = "SELECT COUNT(att.id) AS total_number_of_items |
|
14 | + private $session_id; |
|
15 | + private $course_id; |
|
16 | + private $date_time; |
|
17 | + private $name; |
|
18 | + private $description; |
|
19 | + private $attendance_qualify_title; |
|
20 | + private $attendance_weight; |
|
21 | + private $course_int_id; |
|
22 | + public $category_id; |
|
23 | + |
|
24 | + // constants |
|
25 | + const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet'; |
|
26 | + const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet'; |
|
27 | + const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Constructor |
|
31 | + */ |
|
32 | + public function __construct() |
|
33 | + { |
|
34 | + //$this->course_int_id = api_get_course_int_id(); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Get the total number of attendance inside current course and current session |
|
39 | + * @see SortableTable#get_total_number_of_items() |
|
40 | + */ |
|
41 | + public static function get_number_of_attendances($active = -1) |
|
42 | + { |
|
43 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
44 | + $session_id = api_get_session_id(); |
|
45 | + $condition_session = api_get_session_condition($session_id); |
|
46 | + $course_id = api_get_course_int_id(); |
|
47 | + $sql = "SELECT COUNT(att.id) AS total_number_of_items |
|
48 | 48 | FROM $tbl_attendance att |
49 | 49 | WHERE c_id = $course_id $condition_session "; |
50 | - if ($active == 1 || $active == 0) { |
|
51 | - $sql .= "AND att.active = $active"; |
|
52 | - } |
|
53 | - $res = Database::query($sql); |
|
54 | - $obj = Database::fetch_object($res); |
|
50 | + if ($active == 1 || $active == 0) { |
|
51 | + $sql .= "AND att.active = $active"; |
|
52 | + } |
|
53 | + $res = Database::query($sql); |
|
54 | + $obj = Database::fetch_object($res); |
|
55 | 55 | |
56 | - return $obj->total_number_of_items; |
|
57 | - } |
|
56 | + return $obj->total_number_of_items; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Get attendance list only the id, name and attendance_qualify_max fields |
@@ -90,36 +90,36 @@ discard block |
||
90 | 90 | return $data; |
91 | 91 | } |
92 | 92 | |
93 | - /** |
|
94 | - * Get the attendaces to display on the current page (fill the sortable-table) |
|
95 | - * @param int offset of first user to recover |
|
96 | - * @param int Number of users to get |
|
97 | - * @param int Column to sort on |
|
98 | - * @param string Order (ASC,DESC) |
|
99 | - * @see SortableTable#get_table_data($from) |
|
100 | - */ |
|
101 | - public static function get_attendance_data($from, $number_of_items, $column, $direction) |
|
102 | - { |
|
103 | - $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
|
104 | - $course_id = api_get_course_int_id(); |
|
105 | - $session_id = api_get_session_id(); |
|
106 | - $condition_session = api_get_session_condition($session_id); |
|
107 | - $column = intval($column); |
|
108 | - $from = intval($from); |
|
109 | - $number_of_items = intval($number_of_items); |
|
110 | - |
|
111 | - if (!in_array($direction, array('ASC','DESC'))) { |
|
112 | - $direction = 'ASC'; |
|
113 | - } |
|
114 | - |
|
115 | - $active_plus = ''; |
|
116 | - if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') || |
|
117 | - !api_is_allowed_to_edit(null, true) |
|
118 | - ) { |
|
119 | - $active_plus = ' AND att.active = 1'; |
|
120 | - } |
|
121 | - |
|
122 | - $sql = "SELECT |
|
93 | + /** |
|
94 | + * Get the attendaces to display on the current page (fill the sortable-table) |
|
95 | + * @param int offset of first user to recover |
|
96 | + * @param int Number of users to get |
|
97 | + * @param int Column to sort on |
|
98 | + * @param string Order (ASC,DESC) |
|
99 | + * @see SortableTable#get_table_data($from) |
|
100 | + */ |
|
101 | + public static function get_attendance_data($from, $number_of_items, $column, $direction) |
|
102 | + { |
|
103 | + $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
|
104 | + $course_id = api_get_course_int_id(); |
|
105 | + $session_id = api_get_session_id(); |
|
106 | + $condition_session = api_get_session_condition($session_id); |
|
107 | + $column = intval($column); |
|
108 | + $from = intval($from); |
|
109 | + $number_of_items = intval($number_of_items); |
|
110 | + |
|
111 | + if (!in_array($direction, array('ASC','DESC'))) { |
|
112 | + $direction = 'ASC'; |
|
113 | + } |
|
114 | + |
|
115 | + $active_plus = ''; |
|
116 | + if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') || |
|
117 | + !api_is_allowed_to_edit(null, true) |
|
118 | + ) { |
|
119 | + $active_plus = ' AND att.active = 1'; |
|
120 | + } |
|
121 | + |
|
122 | + $sql = "SELECT |
|
123 | 123 | att.id AS col0, |
124 | 124 | att.name AS col1, |
125 | 125 | att.description AS col2, |
@@ -134,318 +134,318 @@ discard block |
||
134 | 134 | ORDER BY col$column $direction |
135 | 135 | LIMIT $from,$number_of_items "; |
136 | 136 | |
137 | - $res = Database::query($sql); |
|
138 | - $attendances = array (); |
|
139 | - $user_info = api_get_user_info(); |
|
140 | - $allowDelete = api_get_setting('allow_delete_attendance'); |
|
141 | - |
|
142 | - while ($attendance = Database::fetch_row($res)) { |
|
143 | - |
|
144 | - $student_param = ''; |
|
145 | - if (api_is_drh() && $_GET['student_id']) { |
|
146 | - $student_param = '&student_id='.intval($_GET['student_id']); |
|
147 | - } |
|
148 | - |
|
149 | - $session_star = ''; |
|
150 | - |
|
151 | - if (api_get_session_id() == $attendance[6]) { |
|
152 | - $session_star = api_get_session_image(api_get_session_id(), $user_info['status']); |
|
153 | - } |
|
154 | - if ($attendance[5] == 1) { |
|
155 | - |
|
156 | - $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( |
|
157 | - api_get_user_id(), |
|
158 | - api_get_course_info() |
|
159 | - ); |
|
160 | - |
|
161 | - if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) { |
|
162 | - // Link to edit |
|
163 | - $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star; |
|
164 | - } else { |
|
165 | - // Link to view |
|
166 | - $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star; |
|
167 | - } |
|
168 | - |
|
169 | - } else { |
|
170 | - $attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star; |
|
171 | - } |
|
172 | - |
|
173 | - if ($attendance[5] == 1) { |
|
174 | - $attendance[3] = '<center>'.$attendance[3].'</center>'; |
|
175 | - } else { |
|
176 | - $attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>'; |
|
177 | - } |
|
178 | - |
|
179 | - $attendance[3] = '<center>'.$attendance[3].'</center>'; |
|
180 | - if (api_is_allowed_to_edit(null, true)) { |
|
181 | - $actions = ''; |
|
182 | - $actions .= '<center>'; |
|
183 | - |
|
184 | - if (api_is_platform_admin()) { |
|
185 | - $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'. |
|
186 | - Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a> '; |
|
187 | - // Visible |
|
188 | - if ($attendance[5] == 1) { |
|
189 | - $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'. |
|
190 | - Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>'; |
|
191 | - } else { |
|
192 | - $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'. |
|
193 | - Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>'; |
|
194 | - $attendance[2] = '<span class="muted">'.$attendance[2].'</span>'; |
|
195 | - } |
|
196 | - if ($allowDelete === 'true') { |
|
197 | - $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0]. '">' . |
|
198 | - Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; |
|
199 | - } |
|
200 | - } else { |
|
201 | - $is_locked_attendance = self::is_locked_attendance($attendance[0]); |
|
202 | - if ($is_locked_attendance) { |
|
203 | - $actions .= Display::return_icon('edit_na.png', get_lang('Edit')).' '; |
|
204 | - $actions .= Display::return_icon('visible.png', get_lang('Hide')); |
|
205 | - } else { |
|
206 | - $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'. |
|
207 | - Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a> '; |
|
208 | - |
|
209 | - if ($attendance[5] == 1) { |
|
210 | - $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'. |
|
211 | - Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>'; |
|
212 | - } else { |
|
213 | - $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'. |
|
214 | - Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>'; |
|
215 | - $attendance[2] = '<span class="muted">'.$attendance[2].'</span>'; |
|
216 | - } |
|
217 | - if ($allowDelete === 'true') { |
|
218 | - $actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' . |
|
219 | - Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - // display lock/unlock icon |
|
225 | - $is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]); |
|
226 | - |
|
227 | - if ($is_done_all_calendar) { |
|
228 | - $locked = $attendance[4]; |
|
229 | - if ($locked == 0) { |
|
230 | - if (api_is_platform_admin()) { |
|
231 | - $message_alert = get_lang('AreYouSureToLockTheAttendance'); |
|
232 | - } else { |
|
233 | - $message_alert = get_lang('UnlockMessageInformation'); |
|
234 | - } |
|
235 | - $actions .= ' <a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'. |
|
137 | + $res = Database::query($sql); |
|
138 | + $attendances = array (); |
|
139 | + $user_info = api_get_user_info(); |
|
140 | + $allowDelete = api_get_setting('allow_delete_attendance'); |
|
141 | + |
|
142 | + while ($attendance = Database::fetch_row($res)) { |
|
143 | + |
|
144 | + $student_param = ''; |
|
145 | + if (api_is_drh() && $_GET['student_id']) { |
|
146 | + $student_param = '&student_id='.intval($_GET['student_id']); |
|
147 | + } |
|
148 | + |
|
149 | + $session_star = ''; |
|
150 | + |
|
151 | + if (api_get_session_id() == $attendance[6]) { |
|
152 | + $session_star = api_get_session_image(api_get_session_id(), $user_info['status']); |
|
153 | + } |
|
154 | + if ($attendance[5] == 1) { |
|
155 | + |
|
156 | + $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( |
|
157 | + api_get_user_id(), |
|
158 | + api_get_course_info() |
|
159 | + ); |
|
160 | + |
|
161 | + if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) { |
|
162 | + // Link to edit |
|
163 | + $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star; |
|
164 | + } else { |
|
165 | + // Link to view |
|
166 | + $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star; |
|
167 | + } |
|
168 | + |
|
169 | + } else { |
|
170 | + $attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star; |
|
171 | + } |
|
172 | + |
|
173 | + if ($attendance[5] == 1) { |
|
174 | + $attendance[3] = '<center>'.$attendance[3].'</center>'; |
|
175 | + } else { |
|
176 | + $attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>'; |
|
177 | + } |
|
178 | + |
|
179 | + $attendance[3] = '<center>'.$attendance[3].'</center>'; |
|
180 | + if (api_is_allowed_to_edit(null, true)) { |
|
181 | + $actions = ''; |
|
182 | + $actions .= '<center>'; |
|
183 | + |
|
184 | + if (api_is_platform_admin()) { |
|
185 | + $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'. |
|
186 | + Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a> '; |
|
187 | + // Visible |
|
188 | + if ($attendance[5] == 1) { |
|
189 | + $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'. |
|
190 | + Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>'; |
|
191 | + } else { |
|
192 | + $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'. |
|
193 | + Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>'; |
|
194 | + $attendance[2] = '<span class="muted">'.$attendance[2].'</span>'; |
|
195 | + } |
|
196 | + if ($allowDelete === 'true') { |
|
197 | + $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0]. '">' . |
|
198 | + Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; |
|
199 | + } |
|
200 | + } else { |
|
201 | + $is_locked_attendance = self::is_locked_attendance($attendance[0]); |
|
202 | + if ($is_locked_attendance) { |
|
203 | + $actions .= Display::return_icon('edit_na.png', get_lang('Edit')).' '; |
|
204 | + $actions .= Display::return_icon('visible.png', get_lang('Hide')); |
|
205 | + } else { |
|
206 | + $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'. |
|
207 | + Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a> '; |
|
208 | + |
|
209 | + if ($attendance[5] == 1) { |
|
210 | + $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'. |
|
211 | + Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>'; |
|
212 | + } else { |
|
213 | + $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'. |
|
214 | + Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>'; |
|
215 | + $attendance[2] = '<span class="muted">'.$attendance[2].'</span>'; |
|
216 | + } |
|
217 | + if ($allowDelete === 'true') { |
|
218 | + $actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' . |
|
219 | + Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + // display lock/unlock icon |
|
225 | + $is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]); |
|
226 | + |
|
227 | + if ($is_done_all_calendar) { |
|
228 | + $locked = $attendance[4]; |
|
229 | + if ($locked == 0) { |
|
230 | + if (api_is_platform_admin()) { |
|
231 | + $message_alert = get_lang('AreYouSureToLockTheAttendance'); |
|
232 | + } else { |
|
233 | + $message_alert = get_lang('UnlockMessageInformation'); |
|
234 | + } |
|
235 | + $actions .= ' <a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'. |
|
236 | 236 | Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>'; |
237 | - } else { |
|
238 | - if (api_is_platform_admin()) { |
|
239 | - $actions .= ' <a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'. |
|
240 | - Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>'; |
|
241 | - } else { |
|
242 | - $actions .= ' '.Display::return_icon('locked_na.png', get_lang('LockedAttendance')); |
|
243 | - } |
|
244 | - } |
|
245 | - } |
|
246 | - $actions .= '</center>'; |
|
247 | - |
|
248 | - $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions); |
|
249 | - } else { |
|
250 | - $attendance[0] = ' '; |
|
251 | - $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]); |
|
252 | - } |
|
253 | - } |
|
254 | - return $attendances; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Get the attendances by id to display on the current page |
|
259 | - * @param int $attendance_id |
|
260 | - * @return array attendance data |
|
261 | - */ |
|
262 | - public function get_attendance_by_id($attendance_id) |
|
263 | - { |
|
264 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
265 | - $attendance_id = intval($attendance_id); |
|
266 | - $course_id = api_get_course_int_id(); |
|
267 | - $attendance_data = array(); |
|
268 | - $sql = "SELECT * FROM $tbl_attendance |
|
237 | + } else { |
|
238 | + if (api_is_platform_admin()) { |
|
239 | + $actions .= ' <a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'. |
|
240 | + Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>'; |
|
241 | + } else { |
|
242 | + $actions .= ' '.Display::return_icon('locked_na.png', get_lang('LockedAttendance')); |
|
243 | + } |
|
244 | + } |
|
245 | + } |
|
246 | + $actions .= '</center>'; |
|
247 | + |
|
248 | + $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions); |
|
249 | + } else { |
|
250 | + $attendance[0] = ' '; |
|
251 | + $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]); |
|
252 | + } |
|
253 | + } |
|
254 | + return $attendances; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Get the attendances by id to display on the current page |
|
259 | + * @param int $attendance_id |
|
260 | + * @return array attendance data |
|
261 | + */ |
|
262 | + public function get_attendance_by_id($attendance_id) |
|
263 | + { |
|
264 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
265 | + $attendance_id = intval($attendance_id); |
|
266 | + $course_id = api_get_course_int_id(); |
|
267 | + $attendance_data = array(); |
|
268 | + $sql = "SELECT * FROM $tbl_attendance |
|
269 | 269 | WHERE c_id = $course_id AND id = '$attendance_id'"; |
270 | - $res = Database::query($sql); |
|
271 | - if (Database::num_rows($res) > 0) { |
|
272 | - while ($row = Database::fetch_array($res)) { |
|
273 | - $attendance_data = $row; |
|
274 | - } |
|
275 | - } |
|
276 | - return $attendance_data; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Add attendances sheet inside table. This is the *list of* dates, not |
|
281 | - * a specific date in itself. |
|
282 | - * @param bool true for adding link in gradebook or false otherwise (optional) |
|
283 | - * @return int last attendance id |
|
284 | - */ |
|
285 | - public function attendance_add($link_to_gradebook = false) |
|
286 | - { |
|
287 | - $_course = api_get_course_info(); |
|
288 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
289 | - $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
290 | - $session_id = api_get_session_id(); |
|
291 | - $user_id = api_get_user_id(); |
|
292 | - $course_code = $_course['code']; |
|
293 | - $course_id = $_course['real_id']; |
|
294 | - $title_gradebook= $this->attendance_qualify_title; |
|
295 | - $value_calification = 0; |
|
296 | - $weight_calification = floatval($this->attendance_weight); |
|
297 | - |
|
298 | - $params = [ |
|
299 | - 'c_id' => $course_id, |
|
300 | - 'name' => $this->name, |
|
301 | - 'description' => $this->description, |
|
302 | - 'attendance_qualify_title' => $title_gradebook, |
|
303 | - 'attendance_weight' => $weight_calification, |
|
304 | - 'session_id' => $session_id, |
|
305 | - 'active' => 1, |
|
306 | - 'attendance_qualify_max' => 0, |
|
307 | - 'locked' => 0 |
|
308 | - ]; |
|
309 | - $last_id = Database::insert($tbl_attendance, $params); |
|
310 | - |
|
311 | - if (!empty($last_id)) { |
|
312 | - |
|
313 | - $sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id"; |
|
314 | - Database::query($sql); |
|
315 | - |
|
316 | - api_item_property_update( |
|
317 | - $_course, |
|
318 | - TOOL_ATTENDANCE, |
|
319 | - $last_id, |
|
320 | - "AttendanceAdded", |
|
321 | - $user_id |
|
322 | - ); |
|
323 | - |
|
324 | - } |
|
325 | - // add link to gradebook |
|
326 | - if ($link_to_gradebook && !empty($this->category_id)) { |
|
327 | - $description = ''; |
|
270 | + $res = Database::query($sql); |
|
271 | + if (Database::num_rows($res) > 0) { |
|
272 | + while ($row = Database::fetch_array($res)) { |
|
273 | + $attendance_data = $row; |
|
274 | + } |
|
275 | + } |
|
276 | + return $attendance_data; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Add attendances sheet inside table. This is the *list of* dates, not |
|
281 | + * a specific date in itself. |
|
282 | + * @param bool true for adding link in gradebook or false otherwise (optional) |
|
283 | + * @return int last attendance id |
|
284 | + */ |
|
285 | + public function attendance_add($link_to_gradebook = false) |
|
286 | + { |
|
287 | + $_course = api_get_course_info(); |
|
288 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
289 | + $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
290 | + $session_id = api_get_session_id(); |
|
291 | + $user_id = api_get_user_id(); |
|
292 | + $course_code = $_course['code']; |
|
293 | + $course_id = $_course['real_id']; |
|
294 | + $title_gradebook= $this->attendance_qualify_title; |
|
295 | + $value_calification = 0; |
|
296 | + $weight_calification = floatval($this->attendance_weight); |
|
297 | + |
|
298 | + $params = [ |
|
299 | + 'c_id' => $course_id, |
|
300 | + 'name' => $this->name, |
|
301 | + 'description' => $this->description, |
|
302 | + 'attendance_qualify_title' => $title_gradebook, |
|
303 | + 'attendance_weight' => $weight_calification, |
|
304 | + 'session_id' => $session_id, |
|
305 | + 'active' => 1, |
|
306 | + 'attendance_qualify_max' => 0, |
|
307 | + 'locked' => 0 |
|
308 | + ]; |
|
309 | + $last_id = Database::insert($tbl_attendance, $params); |
|
310 | + |
|
311 | + if (!empty($last_id)) { |
|
312 | + |
|
313 | + $sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id"; |
|
314 | + Database::query($sql); |
|
315 | + |
|
316 | + api_item_property_update( |
|
317 | + $_course, |
|
318 | + TOOL_ATTENDANCE, |
|
319 | + $last_id, |
|
320 | + "AttendanceAdded", |
|
321 | + $user_id |
|
322 | + ); |
|
323 | + |
|
324 | + } |
|
325 | + // add link to gradebook |
|
326 | + if ($link_to_gradebook && !empty($this->category_id)) { |
|
327 | + $description = ''; |
|
328 | 328 | $link_info = GradebookUtils::is_resource_in_course_gradebook( |
329 | 329 | $course_code, |
330 | 330 | 7, |
331 | 331 | $last_id, |
332 | 332 | $session_id |
333 | 333 | ); |
334 | - $link_id = $link_info['id']; |
|
335 | - if (!$link_info) { |
|
336 | - GradebookUtils::add_resource_to_course_gradebook( |
|
337 | - $this->category_id, |
|
338 | - $course_code, |
|
339 | - 7, |
|
340 | - $last_id, |
|
341 | - $title_gradebook, |
|
342 | - $weight_calification, |
|
343 | - $value_calification, |
|
344 | - $description, |
|
345 | - 1, |
|
346 | - $session_id |
|
347 | - ); |
|
348 | - } else { |
|
349 | - Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.''); |
|
350 | - } |
|
351 | - } |
|
352 | - return $last_id; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * edit attendances inside table |
|
357 | - * @param int attendance id |
|
358 | - * @param bool true for adding link in gradebook or false otherwise (optional) |
|
359 | - * @return int last id |
|
360 | - */ |
|
361 | - public function attendance_edit($attendance_id, $link_to_gradebook = false) |
|
362 | - { |
|
363 | - $_course = api_get_course_info(); |
|
364 | - $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE); |
|
365 | - $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
366 | - |
|
367 | - $session_id = api_get_session_id(); |
|
368 | - $user_id = api_get_user_id(); |
|
369 | - $attendance_id = intval($attendance_id); |
|
370 | - $course_code = $_course['code']; |
|
371 | - $course_id = $_course['real_id']; |
|
372 | - $title_gradebook = $this->attendance_qualify_title; |
|
373 | - $value_calification = 0; |
|
374 | - $weight_calification = floatval($this->attendance_weight); |
|
375 | - |
|
376 | - if (!empty($attendance_id)) { |
|
377 | - |
|
378 | - $params = [ |
|
379 | - 'name' => $this->name, |
|
380 | - 'description' => $this->description, |
|
381 | - 'attendance_qualify_title' => $title_gradebook, |
|
382 | - 'attendance_weight' => $weight_calification |
|
383 | - ]; |
|
384 | - Database::update( |
|
385 | - $tbl_attendance, |
|
386 | - $params, |
|
387 | - ['c_id = ? AND id = ?' => [$course_id, $attendance_id]] |
|
388 | - ); |
|
389 | - |
|
390 | - api_item_property_update( |
|
391 | - $_course, |
|
392 | - TOOL_ATTENDANCE, |
|
393 | - $attendance_id, |
|
394 | - "AttendanceUpdated", |
|
395 | - $user_id |
|
396 | - ); |
|
397 | - |
|
398 | - // add link to gradebook |
|
399 | - if ($link_to_gradebook && !empty($this->category_id)) { |
|
400 | - $description = ''; |
|
401 | - $link_info = GradebookUtils::is_resource_in_course_gradebook( |
|
402 | - $course_code, |
|
403 | - 7, |
|
404 | - $attendance_id, |
|
405 | - $session_id |
|
406 | - ); |
|
407 | - if (!$link_info) { |
|
408 | - GradebookUtils::add_resource_to_course_gradebook( |
|
409 | - $this->category_id, |
|
410 | - $course_code, |
|
411 | - 7, |
|
412 | - $attendance_id, |
|
413 | - $title_gradebook, |
|
414 | - $weight_calification, |
|
415 | - $value_calification, |
|
416 | - $description, |
|
417 | - 1, |
|
418 | - $session_id |
|
419 | - ); |
|
420 | - } else { |
|
421 | - Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_info['id'].''); |
|
422 | - } |
|
423 | - } |
|
424 | - return $attendance_id; |
|
425 | - } |
|
426 | - return null; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Restore attendance |
|
431 | - * @param int|array one or many attendances id |
|
432 | - * @return int affected rows |
|
433 | - */ |
|
434 | - public function attendance_restore($attendance_id) |
|
435 | - { |
|
436 | - $_course = api_get_course_info(); |
|
437 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
438 | - $user_id = api_get_user_id(); |
|
439 | - $course_id = $_course['real_id']; |
|
440 | - if (is_array($attendance_id)) { |
|
441 | - foreach ($attendance_id as $id) { |
|
442 | - $id = intval($id); |
|
443 | - $sql = "UPDATE $tbl_attendance SET active = 1 |
|
334 | + $link_id = $link_info['id']; |
|
335 | + if (!$link_info) { |
|
336 | + GradebookUtils::add_resource_to_course_gradebook( |
|
337 | + $this->category_id, |
|
338 | + $course_code, |
|
339 | + 7, |
|
340 | + $last_id, |
|
341 | + $title_gradebook, |
|
342 | + $weight_calification, |
|
343 | + $value_calification, |
|
344 | + $description, |
|
345 | + 1, |
|
346 | + $session_id |
|
347 | + ); |
|
348 | + } else { |
|
349 | + Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.''); |
|
350 | + } |
|
351 | + } |
|
352 | + return $last_id; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * edit attendances inside table |
|
357 | + * @param int attendance id |
|
358 | + * @param bool true for adding link in gradebook or false otherwise (optional) |
|
359 | + * @return int last id |
|
360 | + */ |
|
361 | + public function attendance_edit($attendance_id, $link_to_gradebook = false) |
|
362 | + { |
|
363 | + $_course = api_get_course_info(); |
|
364 | + $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE); |
|
365 | + $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
366 | + |
|
367 | + $session_id = api_get_session_id(); |
|
368 | + $user_id = api_get_user_id(); |
|
369 | + $attendance_id = intval($attendance_id); |
|
370 | + $course_code = $_course['code']; |
|
371 | + $course_id = $_course['real_id']; |
|
372 | + $title_gradebook = $this->attendance_qualify_title; |
|
373 | + $value_calification = 0; |
|
374 | + $weight_calification = floatval($this->attendance_weight); |
|
375 | + |
|
376 | + if (!empty($attendance_id)) { |
|
377 | + |
|
378 | + $params = [ |
|
379 | + 'name' => $this->name, |
|
380 | + 'description' => $this->description, |
|
381 | + 'attendance_qualify_title' => $title_gradebook, |
|
382 | + 'attendance_weight' => $weight_calification |
|
383 | + ]; |
|
384 | + Database::update( |
|
385 | + $tbl_attendance, |
|
386 | + $params, |
|
387 | + ['c_id = ? AND id = ?' => [$course_id, $attendance_id]] |
|
388 | + ); |
|
389 | + |
|
390 | + api_item_property_update( |
|
391 | + $_course, |
|
392 | + TOOL_ATTENDANCE, |
|
393 | + $attendance_id, |
|
394 | + "AttendanceUpdated", |
|
395 | + $user_id |
|
396 | + ); |
|
397 | + |
|
398 | + // add link to gradebook |
|
399 | + if ($link_to_gradebook && !empty($this->category_id)) { |
|
400 | + $description = ''; |
|
401 | + $link_info = GradebookUtils::is_resource_in_course_gradebook( |
|
402 | + $course_code, |
|
403 | + 7, |
|
404 | + $attendance_id, |
|
405 | + $session_id |
|
406 | + ); |
|
407 | + if (!$link_info) { |
|
408 | + GradebookUtils::add_resource_to_course_gradebook( |
|
409 | + $this->category_id, |
|
410 | + $course_code, |
|
411 | + 7, |
|
412 | + $attendance_id, |
|
413 | + $title_gradebook, |
|
414 | + $weight_calification, |
|
415 | + $value_calification, |
|
416 | + $description, |
|
417 | + 1, |
|
418 | + $session_id |
|
419 | + ); |
|
420 | + } else { |
|
421 | + Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_info['id'].''); |
|
422 | + } |
|
423 | + } |
|
424 | + return $attendance_id; |
|
425 | + } |
|
426 | + return null; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Restore attendance |
|
431 | + * @param int|array one or many attendances id |
|
432 | + * @return int affected rows |
|
433 | + */ |
|
434 | + public function attendance_restore($attendance_id) |
|
435 | + { |
|
436 | + $_course = api_get_course_info(); |
|
437 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
438 | + $user_id = api_get_user_id(); |
|
439 | + $course_id = $_course['real_id']; |
|
440 | + if (is_array($attendance_id)) { |
|
441 | + foreach ($attendance_id as $id) { |
|
442 | + $id = intval($id); |
|
443 | + $sql = "UPDATE $tbl_attendance SET active = 1 |
|
444 | 444 | WHERE c_id = $course_id AND id = '$id'"; |
445 | - $result = Database::query($sql); |
|
446 | - $affected_rows = Database::affected_rows($result); |
|
447 | - if (!empty($affected_rows)) { |
|
448 | - // update row item property table |
|
445 | + $result = Database::query($sql); |
|
446 | + $affected_rows = Database::affected_rows($result); |
|
447 | + if (!empty($affected_rows)) { |
|
448 | + // update row item property table |
|
449 | 449 | api_item_property_update( |
450 | 450 | $_course, |
451 | 451 | TOOL_ATTENDANCE, |
@@ -453,16 +453,16 @@ discard block |
||
453 | 453 | "restore", |
454 | 454 | $user_id |
455 | 455 | ); |
456 | - } |
|
457 | - } |
|
458 | - } else { |
|
459 | - $attendance_id = intval($attendance_id); |
|
460 | - $sql = "UPDATE $tbl_attendance SET active = 1 |
|
456 | + } |
|
457 | + } |
|
458 | + } else { |
|
459 | + $attendance_id = intval($attendance_id); |
|
460 | + $sql = "UPDATE $tbl_attendance SET active = 1 |
|
461 | 461 | WHERE c_id = $course_id AND id = '$attendance_id'"; |
462 | - $result = Database::query($sql); |
|
463 | - $affected_rows = Database::affected_rows($result); |
|
464 | - if (!empty($affected_rows)) { |
|
465 | - // update row item property table |
|
462 | + $result = Database::query($sql); |
|
463 | + $affected_rows = Database::affected_rows($result); |
|
464 | + if (!empty($affected_rows)) { |
|
465 | + // update row item property table |
|
466 | 466 | api_item_property_update( |
467 | 467 | $_course, |
468 | 468 | TOOL_ATTENDANCE, |
@@ -470,33 +470,33 @@ discard block |
||
470 | 470 | "restore", |
471 | 471 | $user_id |
472 | 472 | ); |
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - return $affected_rows; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Delete attendances |
|
481 | - * @param int|array $attendance_id one or many attendances id |
|
482 | - * @return int affected rows |
|
483 | - */ |
|
484 | - public function attendance_delete($attendance_id) |
|
485 | - { |
|
486 | - $_course = api_get_course_info(); |
|
487 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + return $affected_rows; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Delete attendances |
|
481 | + * @param int|array $attendance_id one or many attendances id |
|
482 | + * @return int affected rows |
|
483 | + */ |
|
484 | + public function attendance_delete($attendance_id) |
|
485 | + { |
|
486 | + $_course = api_get_course_info(); |
|
487 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
488 | 488 | $user_id = api_get_user_id(); |
489 | 489 | $course_id = $_course['real_id']; |
490 | 490 | |
491 | - if (is_array($attendance_id)) { |
|
492 | - foreach ($attendance_id as $id) { |
|
493 | - $id = intval($id); |
|
494 | - $sql = "UPDATE $tbl_attendance SET active = 2 |
|
491 | + if (is_array($attendance_id)) { |
|
492 | + foreach ($attendance_id as $id) { |
|
493 | + $id = intval($id); |
|
494 | + $sql = "UPDATE $tbl_attendance SET active = 2 |
|
495 | 495 | WHERE c_id = $course_id AND id = '$id'"; |
496 | - $result = Database::query($sql); |
|
497 | - $affected_rows = Database::affected_rows($result); |
|
498 | - if (!empty($affected_rows)) { |
|
499 | - // update row item property table |
|
496 | + $result = Database::query($sql); |
|
497 | + $affected_rows = Database::affected_rows($result); |
|
498 | + if (!empty($affected_rows)) { |
|
499 | + // update row item property table |
|
500 | 500 | api_item_property_update( |
501 | 501 | $_course, |
502 | 502 | TOOL_ATTENDANCE, |
@@ -504,142 +504,142 @@ discard block |
||
504 | 504 | "delete", |
505 | 505 | $user_id |
506 | 506 | ); |
507 | - } |
|
508 | - } |
|
509 | - } else { |
|
510 | - $attendance_id= intval($attendance_id); |
|
511 | - $sql = "UPDATE $tbl_attendance SET active = 2 |
|
507 | + } |
|
508 | + } |
|
509 | + } else { |
|
510 | + $attendance_id= intval($attendance_id); |
|
511 | + $sql = "UPDATE $tbl_attendance SET active = 2 |
|
512 | 512 | WHERE c_id = $course_id AND id = '$attendance_id'"; |
513 | 513 | |
514 | - $result = Database::query($sql); |
|
515 | - $affected_rows = Database::affected_rows($result); |
|
516 | - if (!empty($affected_rows)) { |
|
517 | - // update row item property table |
|
518 | - api_item_property_update( |
|
519 | - $_course, |
|
520 | - TOOL_ATTENDANCE, |
|
521 | - $attendance_id, |
|
522 | - "delete", |
|
523 | - $user_id |
|
524 | - ); |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - return $affected_rows; |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Changes visibility |
|
533 | - * @param int|array $attendanceId one or many attendances id |
|
534 | - * @param int status |
|
514 | + $result = Database::query($sql); |
|
515 | + $affected_rows = Database::affected_rows($result); |
|
516 | + if (!empty($affected_rows)) { |
|
517 | + // update row item property table |
|
518 | + api_item_property_update( |
|
519 | + $_course, |
|
520 | + TOOL_ATTENDANCE, |
|
521 | + $attendance_id, |
|
522 | + "delete", |
|
523 | + $user_id |
|
524 | + ); |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + return $affected_rows; |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Changes visibility |
|
533 | + * @param int|array $attendanceId one or many attendances id |
|
534 | + * @param int status |
|
535 | 535 | * |
536 | - * @return int affected rows |
|
537 | - */ |
|
538 | - public function changeVisibility($attendanceId, $status = 1) |
|
539 | - { |
|
540 | - $_course = api_get_course_info(); |
|
541 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
542 | - $user_id = api_get_user_id(); |
|
543 | - $course_id = $_course['real_id']; |
|
544 | - $status = intval($status); |
|
545 | - |
|
546 | - $action = 'visible'; |
|
547 | - if ($status == 0) { |
|
548 | - $action = 'invisible'; |
|
549 | - } |
|
550 | - |
|
551 | - if (is_array($attendanceId)) { |
|
552 | - foreach ($attendanceId as $id) { |
|
553 | - $id = intval($id); |
|
554 | - $sql = "UPDATE $tbl_attendance SET active = $status |
|
536 | + * @return int affected rows |
|
537 | + */ |
|
538 | + public function changeVisibility($attendanceId, $status = 1) |
|
539 | + { |
|
540 | + $_course = api_get_course_info(); |
|
541 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
542 | + $user_id = api_get_user_id(); |
|
543 | + $course_id = $_course['real_id']; |
|
544 | + $status = intval($status); |
|
545 | + |
|
546 | + $action = 'visible'; |
|
547 | + if ($status == 0) { |
|
548 | + $action = 'invisible'; |
|
549 | + } |
|
550 | + |
|
551 | + if (is_array($attendanceId)) { |
|
552 | + foreach ($attendanceId as $id) { |
|
553 | + $id = intval($id); |
|
554 | + $sql = "UPDATE $tbl_attendance SET active = $status |
|
555 | 555 | WHERE c_id = $course_id AND id = '$id'"; |
556 | - $result = Database::query($sql); |
|
557 | - $affected_rows = Database::affected_rows($result); |
|
558 | - if (!empty($affected_rows)) { |
|
559 | - // update row item property table |
|
560 | - api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id); |
|
561 | - } |
|
562 | - } |
|
563 | - } else { |
|
564 | - $attendanceId = intval($attendanceId); |
|
565 | - $sql = "UPDATE $tbl_attendance SET active = $status |
|
556 | + $result = Database::query($sql); |
|
557 | + $affected_rows = Database::affected_rows($result); |
|
558 | + if (!empty($affected_rows)) { |
|
559 | + // update row item property table |
|
560 | + api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id); |
|
561 | + } |
|
562 | + } |
|
563 | + } else { |
|
564 | + $attendanceId = intval($attendanceId); |
|
565 | + $sql = "UPDATE $tbl_attendance SET active = $status |
|
566 | 566 | WHERE c_id = $course_id AND id = '$attendanceId'"; |
567 | - $result = Database::query($sql); |
|
568 | - $affected_rows = Database::affected_rows($result); |
|
569 | - if (!empty($affected_rows)) { |
|
570 | - // update row item property table |
|
571 | - api_item_property_update( |
|
572 | - $_course, |
|
573 | - TOOL_ATTENDANCE, |
|
574 | - $attendanceId, |
|
575 | - $action, |
|
576 | - $user_id |
|
577 | - ); |
|
578 | - } |
|
579 | - } |
|
580 | - |
|
581 | - return $affected_rows; |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Lock or unlock an attendance |
|
586 | - * @param int attendance id |
|
587 | - * @param bool True to lock or false otherwise |
|
588 | - */ |
|
589 | - public function lock_attendance($attendance_id, $lock = true) |
|
590 | - { |
|
591 | - $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
|
592 | - $course_id = api_get_course_int_id(); |
|
593 | - $attendance_id = intval($attendance_id); |
|
594 | - $locked = ($lock)?1:0; |
|
595 | - $upd = "UPDATE $tbl_attendance SET locked = $locked |
|
567 | + $result = Database::query($sql); |
|
568 | + $affected_rows = Database::affected_rows($result); |
|
569 | + if (!empty($affected_rows)) { |
|
570 | + // update row item property table |
|
571 | + api_item_property_update( |
|
572 | + $_course, |
|
573 | + TOOL_ATTENDANCE, |
|
574 | + $attendanceId, |
|
575 | + $action, |
|
576 | + $user_id |
|
577 | + ); |
|
578 | + } |
|
579 | + } |
|
580 | + |
|
581 | + return $affected_rows; |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Lock or unlock an attendance |
|
586 | + * @param int attendance id |
|
587 | + * @param bool True to lock or false otherwise |
|
588 | + */ |
|
589 | + public function lock_attendance($attendance_id, $lock = true) |
|
590 | + { |
|
591 | + $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
|
592 | + $course_id = api_get_course_int_id(); |
|
593 | + $attendance_id = intval($attendance_id); |
|
594 | + $locked = ($lock)?1:0; |
|
595 | + $upd = "UPDATE $tbl_attendance SET locked = $locked |
|
596 | 596 | WHERE c_id = $course_id AND id = $attendance_id"; |
597 | - $result = Database::query($upd); |
|
598 | - $affected_rows = Database::affected_rows($result); |
|
599 | - if ($affected_rows && $lock) { |
|
600 | - // Save attendance sheet log |
|
601 | - $lastedit_date = api_get_utc_datetime(); |
|
602 | - $lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE; |
|
603 | - $lastedit_user_id = api_get_user_id(); |
|
604 | - $this->save_attendance_sheet_log( |
|
605 | - $attendance_id, |
|
606 | - $lastedit_date, |
|
607 | - $lastedit_type, |
|
608 | - $lastedit_user_id |
|
609 | - ); |
|
610 | - } |
|
611 | - return $affected_rows; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Get registered users inside current course |
|
616 | - * @param int $attendance_id attendance id for showing attendance result field (optional) |
|
617 | - * @param int $groupId |
|
618 | - * @return array users data |
|
619 | - */ |
|
620 | - public function get_users_rel_course($attendance_id = 0, $groupId = null) |
|
621 | - { |
|
622 | - $current_session_id = api_get_session_id(); |
|
623 | - $current_course_id = api_get_course_id(); |
|
624 | - $currentCourseIntId = api_get_course_int_id(); |
|
625 | - |
|
626 | - $studentInGroup = array(); |
|
627 | - |
|
628 | - if (!empty($current_session_id)) { |
|
629 | - $a_course_users = CourseManager:: get_user_list_from_course_code( |
|
630 | - $current_course_id, |
|
631 | - $current_session_id, |
|
632 | - '', |
|
633 | - 'lastname' |
|
634 | - ); |
|
635 | - } else { |
|
636 | - $a_course_users = CourseManager:: get_user_list_from_course_code( |
|
637 | - $current_course_id, |
|
638 | - 0, |
|
639 | - '', |
|
640 | - 'lastname' |
|
641 | - ); |
|
642 | - } |
|
597 | + $result = Database::query($upd); |
|
598 | + $affected_rows = Database::affected_rows($result); |
|
599 | + if ($affected_rows && $lock) { |
|
600 | + // Save attendance sheet log |
|
601 | + $lastedit_date = api_get_utc_datetime(); |
|
602 | + $lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE; |
|
603 | + $lastedit_user_id = api_get_user_id(); |
|
604 | + $this->save_attendance_sheet_log( |
|
605 | + $attendance_id, |
|
606 | + $lastedit_date, |
|
607 | + $lastedit_type, |
|
608 | + $lastedit_user_id |
|
609 | + ); |
|
610 | + } |
|
611 | + return $affected_rows; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Get registered users inside current course |
|
616 | + * @param int $attendance_id attendance id for showing attendance result field (optional) |
|
617 | + * @param int $groupId |
|
618 | + * @return array users data |
|
619 | + */ |
|
620 | + public function get_users_rel_course($attendance_id = 0, $groupId = null) |
|
621 | + { |
|
622 | + $current_session_id = api_get_session_id(); |
|
623 | + $current_course_id = api_get_course_id(); |
|
624 | + $currentCourseIntId = api_get_course_int_id(); |
|
625 | + |
|
626 | + $studentInGroup = array(); |
|
627 | + |
|
628 | + if (!empty($current_session_id)) { |
|
629 | + $a_course_users = CourseManager:: get_user_list_from_course_code( |
|
630 | + $current_course_id, |
|
631 | + $current_session_id, |
|
632 | + '', |
|
633 | + 'lastname' |
|
634 | + ); |
|
635 | + } else { |
|
636 | + $a_course_users = CourseManager:: get_user_list_from_course_code( |
|
637 | + $current_course_id, |
|
638 | + 0, |
|
639 | + '', |
|
640 | + 'lastname' |
|
641 | + ); |
|
642 | + } |
|
643 | 643 | |
644 | 644 | if (!empty($groupId)) { |
645 | 645 | $students = GroupManager::getStudents($groupId); |
@@ -650,192 +650,192 @@ discard block |
||
650 | 650 | } |
651 | 651 | } |
652 | 652 | |
653 | - // get registered users inside current course |
|
654 | - $a_users = array(); |
|
655 | - foreach ($a_course_users as $key => $user_data) { |
|
656 | - $value = array(); |
|
657 | - $uid = $user_data['user_id']; |
|
658 | - $userInfo = api_get_user_info($uid); |
|
659 | - |
|
660 | - $status = $user_data['status']; |
|
661 | - |
|
662 | - if (!empty($groupId)) { |
|
663 | - if (!isset($studentInGroup[$uid])) { |
|
664 | - continue; |
|
665 | - } |
|
666 | - } |
|
667 | - |
|
668 | - $user_status_in_session = null; |
|
669 | - $user_status_in_course = null; |
|
670 | - |
|
671 | - if (api_get_session_id()) { |
|
672 | - $user_status_in_session = SessionManager::get_user_status_in_course_session( |
|
673 | - $uid, |
|
674 | - $currentCourseIntId, |
|
675 | - $current_session_id |
|
676 | - ); |
|
677 | - } else { |
|
678 | - $user_status_in_course = CourseManager::get_user_in_course_status( |
|
679 | - $uid, |
|
680 | - $current_course_id |
|
681 | - ); |
|
682 | - } |
|
683 | - |
|
684 | - // Not taking into account DRH or COURSEMANAGER |
|
685 | - if ($uid <= 1 || |
|
686 | - $status == DRH || |
|
687 | - $user_status_in_course == COURSEMANAGER || |
|
688 | - $user_status_in_session == 2 |
|
689 | - ) { |
|
690 | - continue; |
|
691 | - } |
|
692 | - |
|
693 | - if (!empty($attendance_id)) { |
|
694 | - $user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId); |
|
695 | - $value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)'; |
|
696 | - $value['result_color_bar'] = $user_faults['color_bar']; |
|
697 | - } |
|
653 | + // get registered users inside current course |
|
654 | + $a_users = array(); |
|
655 | + foreach ($a_course_users as $key => $user_data) { |
|
656 | + $value = array(); |
|
657 | + $uid = $user_data['user_id']; |
|
658 | + $userInfo = api_get_user_info($uid); |
|
659 | + |
|
660 | + $status = $user_data['status']; |
|
661 | + |
|
662 | + if (!empty($groupId)) { |
|
663 | + if (!isset($studentInGroup[$uid])) { |
|
664 | + continue; |
|
665 | + } |
|
666 | + } |
|
667 | + |
|
668 | + $user_status_in_session = null; |
|
669 | + $user_status_in_course = null; |
|
670 | + |
|
671 | + if (api_get_session_id()) { |
|
672 | + $user_status_in_session = SessionManager::get_user_status_in_course_session( |
|
673 | + $uid, |
|
674 | + $currentCourseIntId, |
|
675 | + $current_session_id |
|
676 | + ); |
|
677 | + } else { |
|
678 | + $user_status_in_course = CourseManager::get_user_in_course_status( |
|
679 | + $uid, |
|
680 | + $current_course_id |
|
681 | + ); |
|
682 | + } |
|
683 | + |
|
684 | + // Not taking into account DRH or COURSEMANAGER |
|
685 | + if ($uid <= 1 || |
|
686 | + $status == DRH || |
|
687 | + $user_status_in_course == COURSEMANAGER || |
|
688 | + $user_status_in_session == 2 |
|
689 | + ) { |
|
690 | + continue; |
|
691 | + } |
|
692 | + |
|
693 | + if (!empty($attendance_id)) { |
|
694 | + $user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId); |
|
695 | + $value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)'; |
|
696 | + $value['result_color_bar'] = $user_faults['color_bar']; |
|
697 | + } |
|
698 | 698 | |
699 | 699 | $photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false); |
700 | 700 | |
701 | - $value['photo'] = $photo; |
|
702 | - $value['firstname'] = $user_data['firstname']; |
|
703 | - $value['lastname'] = $user_data['lastname']; |
|
704 | - $value['username'] = $user_data['username']; |
|
705 | - $value['user_id'] = $uid; |
|
706 | - |
|
707 | - //Sending only 5 items in the array instead of 60 |
|
708 | - $a_users[$key] = $value; |
|
709 | - } |
|
710 | - |
|
711 | - return $a_users; |
|
712 | - } |
|
713 | - |
|
714 | - /** |
|
715 | - * add attendances sheet inside table |
|
716 | - * @param int $calendar_id attendance calendar id |
|
717 | - * @param array $users_present present users during current class |
|
718 | - * @param int $attendance_id |
|
719 | - * @return int affected rows |
|
720 | - */ |
|
721 | - public function attendance_sheet_add($calendar_id, $users_present, $attendance_id) |
|
722 | - { |
|
723 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
724 | - $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
725 | - |
|
726 | - $calendar_id = intval($calendar_id); |
|
727 | - $attendance_id = intval($attendance_id); |
|
728 | - $users = $this->get_users_rel_course(); |
|
729 | - $course_id = api_get_course_int_id(); |
|
730 | - |
|
731 | - $user_ids = array_keys($users); |
|
732 | - $users_absent = array_diff($user_ids,$users_present); |
|
733 | - $affected_rows = 0; |
|
734 | - |
|
735 | - // get last edit type |
|
736 | - $calendar_data = $this->get_attendance_calendar_by_id($calendar_id); |
|
737 | - $lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE; |
|
738 | - if ($calendar_data['done_attendance']) { |
|
739 | - $lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE; |
|
740 | - } |
|
741 | - |
|
742 | - // save users present in class |
|
743 | - foreach ($users_present as $user_present) { |
|
744 | - $uid = intval($user_present); |
|
745 | - // check if user already was registered with the $calendar_id |
|
746 | - $sql = "SELECT user_id FROM $tbl_attendance_sheet |
|
701 | + $value['photo'] = $photo; |
|
702 | + $value['firstname'] = $user_data['firstname']; |
|
703 | + $value['lastname'] = $user_data['lastname']; |
|
704 | + $value['username'] = $user_data['username']; |
|
705 | + $value['user_id'] = $uid; |
|
706 | + |
|
707 | + //Sending only 5 items in the array instead of 60 |
|
708 | + $a_users[$key] = $value; |
|
709 | + } |
|
710 | + |
|
711 | + return $a_users; |
|
712 | + } |
|
713 | + |
|
714 | + /** |
|
715 | + * add attendances sheet inside table |
|
716 | + * @param int $calendar_id attendance calendar id |
|
717 | + * @param array $users_present present users during current class |
|
718 | + * @param int $attendance_id |
|
719 | + * @return int affected rows |
|
720 | + */ |
|
721 | + public function attendance_sheet_add($calendar_id, $users_present, $attendance_id) |
|
722 | + { |
|
723 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
724 | + $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
725 | + |
|
726 | + $calendar_id = intval($calendar_id); |
|
727 | + $attendance_id = intval($attendance_id); |
|
728 | + $users = $this->get_users_rel_course(); |
|
729 | + $course_id = api_get_course_int_id(); |
|
730 | + |
|
731 | + $user_ids = array_keys($users); |
|
732 | + $users_absent = array_diff($user_ids,$users_present); |
|
733 | + $affected_rows = 0; |
|
734 | + |
|
735 | + // get last edit type |
|
736 | + $calendar_data = $this->get_attendance_calendar_by_id($calendar_id); |
|
737 | + $lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE; |
|
738 | + if ($calendar_data['done_attendance']) { |
|
739 | + $lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE; |
|
740 | + } |
|
741 | + |
|
742 | + // save users present in class |
|
743 | + foreach ($users_present as $user_present) { |
|
744 | + $uid = intval($user_present); |
|
745 | + // check if user already was registered with the $calendar_id |
|
746 | + $sql = "SELECT user_id FROM $tbl_attendance_sheet |
|
747 | 747 | WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'"; |
748 | - $rs = Database::query($sql); |
|
749 | - if (Database::num_rows($rs) == 0) { |
|
750 | - $sql = "INSERT INTO $tbl_attendance_sheet SET |
|
748 | + $rs = Database::query($sql); |
|
749 | + if (Database::num_rows($rs) == 0) { |
|
750 | + $sql = "INSERT INTO $tbl_attendance_sheet SET |
|
751 | 751 | c_id = $course_id, |
752 | 752 | user_id = '$uid', |
753 | 753 | attendance_calendar_id = '$calendar_id', |
754 | 754 | presence = 1"; |
755 | - $result = Database::query($sql); |
|
755 | + $result = Database::query($sql); |
|
756 | 756 | |
757 | - $affected_rows += Database::affected_rows($result); |
|
758 | - } else { |
|
759 | - $sql = "UPDATE $tbl_attendance_sheet SET presence = 1 |
|
757 | + $affected_rows += Database::affected_rows($result); |
|
758 | + } else { |
|
759 | + $sql = "UPDATE $tbl_attendance_sheet SET presence = 1 |
|
760 | 760 | WHERE |
761 | 761 | c_id = $course_id AND |
762 | 762 | user_id ='$uid' AND |
763 | 763 | attendance_calendar_id = '$calendar_id' |
764 | 764 | "; |
765 | - $result = Database::query($sql); |
|
766 | - $affected_rows += Database::affected_rows($result); |
|
767 | - } |
|
768 | - } |
|
769 | - |
|
770 | - // save users absent in class |
|
771 | - foreach ($users_absent as $user_absent) { |
|
772 | - $uid = intval($user_absent); |
|
773 | - // check if user already was registered with the $calendar_id |
|
774 | - $sql = "SELECT user_id FROM $tbl_attendance_sheet |
|
765 | + $result = Database::query($sql); |
|
766 | + $affected_rows += Database::affected_rows($result); |
|
767 | + } |
|
768 | + } |
|
769 | + |
|
770 | + // save users absent in class |
|
771 | + foreach ($users_absent as $user_absent) { |
|
772 | + $uid = intval($user_absent); |
|
773 | + // check if user already was registered with the $calendar_id |
|
774 | + $sql = "SELECT user_id FROM $tbl_attendance_sheet |
|
775 | 775 | WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'"; |
776 | - $rs = Database::query($sql); |
|
777 | - if (Database::num_rows($rs) == 0) { |
|
778 | - $sql = "INSERT INTO $tbl_attendance_sheet SET |
|
776 | + $rs = Database::query($sql); |
|
777 | + if (Database::num_rows($rs) == 0) { |
|
778 | + $sql = "INSERT INTO $tbl_attendance_sheet SET |
|
779 | 779 | c_id = $course_id, |
780 | 780 | user_id ='$uid', |
781 | 781 | attendance_calendar_id = '$calendar_id', |
782 | 782 | presence = 0"; |
783 | - $result = Database::query($sql); |
|
783 | + $result = Database::query($sql); |
|
784 | 784 | |
785 | - Database::insert_id(); |
|
785 | + Database::insert_id(); |
|
786 | 786 | |
787 | - $affected_rows += Database::affected_rows($result); |
|
788 | - } else { |
|
789 | - $sql = "UPDATE $tbl_attendance_sheet SET presence = 0 |
|
787 | + $affected_rows += Database::affected_rows($result); |
|
788 | + } else { |
|
789 | + $sql = "UPDATE $tbl_attendance_sheet SET presence = 0 |
|
790 | 790 | WHERE |
791 | 791 | c_id = $course_id AND |
792 | 792 | user_id ='$uid' AND |
793 | 793 | attendance_calendar_id = '$calendar_id'"; |
794 | - $result = Database::query($sql); |
|
795 | - $affected_rows += Database::affected_rows($result); |
|
796 | - } |
|
797 | - } |
|
794 | + $result = Database::query($sql); |
|
795 | + $affected_rows += Database::affected_rows($result); |
|
796 | + } |
|
797 | + } |
|
798 | 798 | |
799 | - // update done_attendance inside attendance calendar table |
|
800 | - $sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1 |
|
799 | + // update done_attendance inside attendance calendar table |
|
800 | + $sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1 |
|
801 | 801 | WHERE c_id = $course_id AND id = '$calendar_id'"; |
802 | - Database::query($sql); |
|
803 | - |
|
804 | - // save users' results |
|
805 | - $this->update_users_results($user_ids, $attendance_id); |
|
806 | - |
|
807 | - if ($affected_rows) { |
|
808 | - //save attendance sheet log |
|
809 | - $lastedit_date = api_get_utc_datetime(); |
|
810 | - $lastedit_user_id = api_get_user_id(); |
|
811 | - $calendar_date_value = $calendar_data['date_time']; |
|
812 | - $this->save_attendance_sheet_log( |
|
813 | - $attendance_id, |
|
814 | - $lastedit_date, |
|
815 | - $lastedit_type, |
|
816 | - $lastedit_user_id, |
|
817 | - $calendar_date_value |
|
818 | - ); |
|
819 | - } |
|
820 | - |
|
821 | - return $affected_rows; |
|
822 | - } |
|
823 | - |
|
824 | - /** |
|
825 | - * update users' attendance results |
|
826 | - * @param array $user_ids registered users inside current course |
|
827 | - * @param int $attendance_id |
|
828 | - * @return void |
|
829 | - */ |
|
830 | - public function update_users_results($user_ids, $attendance_id) |
|
831 | - { |
|
832 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
833 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
834 | - $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
|
835 | - $course_id = api_get_course_int_id(); |
|
836 | - |
|
837 | - $attendance_id = intval($attendance_id); |
|
838 | - // fill results about presence of students |
|
802 | + Database::query($sql); |
|
803 | + |
|
804 | + // save users' results |
|
805 | + $this->update_users_results($user_ids, $attendance_id); |
|
806 | + |
|
807 | + if ($affected_rows) { |
|
808 | + //save attendance sheet log |
|
809 | + $lastedit_date = api_get_utc_datetime(); |
|
810 | + $lastedit_user_id = api_get_user_id(); |
|
811 | + $calendar_date_value = $calendar_data['date_time']; |
|
812 | + $this->save_attendance_sheet_log( |
|
813 | + $attendance_id, |
|
814 | + $lastedit_date, |
|
815 | + $lastedit_type, |
|
816 | + $lastedit_user_id, |
|
817 | + $calendar_date_value |
|
818 | + ); |
|
819 | + } |
|
820 | + |
|
821 | + return $affected_rows; |
|
822 | + } |
|
823 | + |
|
824 | + /** |
|
825 | + * update users' attendance results |
|
826 | + * @param array $user_ids registered users inside current course |
|
827 | + * @param int $attendance_id |
|
828 | + * @return void |
|
829 | + */ |
|
830 | + public function update_users_results($user_ids, $attendance_id) |
|
831 | + { |
|
832 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
833 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
834 | + $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
|
835 | + $course_id = api_get_course_int_id(); |
|
836 | + |
|
837 | + $attendance_id = intval($attendance_id); |
|
838 | + // fill results about presence of students |
|
839 | 839 | $attendance_calendar = $this->get_attendance_calendar( |
840 | 840 | $attendance_id, |
841 | 841 | 'all', |
@@ -843,82 +843,82 @@ discard block |
||
843 | 843 | null, |
844 | 844 | true |
845 | 845 | ); |
846 | - $calendar_ids = array(); |
|
847 | - // get all dates from calendar by current attendance |
|
848 | - foreach ($attendance_calendar as $cal) { |
|
849 | - $calendar_ids[] = $cal['id']; |
|
850 | - } |
|
851 | - |
|
852 | - // get count of presences by users inside current attendance and save like results |
|
853 | - if (count($user_ids) > 0) { |
|
854 | - foreach ($user_ids as $uid) { |
|
855 | - $count_presences = 0; |
|
856 | - if (count($calendar_ids) > 0) { |
|
857 | - $sql = "SELECT count(presence) as count_presences |
|
846 | + $calendar_ids = array(); |
|
847 | + // get all dates from calendar by current attendance |
|
848 | + foreach ($attendance_calendar as $cal) { |
|
849 | + $calendar_ids[] = $cal['id']; |
|
850 | + } |
|
851 | + |
|
852 | + // get count of presences by users inside current attendance and save like results |
|
853 | + if (count($user_ids) > 0) { |
|
854 | + foreach ($user_ids as $uid) { |
|
855 | + $count_presences = 0; |
|
856 | + if (count($calendar_ids) > 0) { |
|
857 | + $sql = "SELECT count(presence) as count_presences |
|
858 | 858 | FROM $tbl_attendance_sheet |
859 | 859 | WHERE |
860 | 860 | c_id = $course_id AND |
861 | 861 | user_id = '$uid' AND |
862 | 862 | attendance_calendar_id IN (".implode(',', $calendar_ids).") AND |
863 | 863 | presence = 1"; |
864 | - $rs_count = Database::query($sql); |
|
865 | - $row_count = Database::fetch_array($rs_count); |
|
866 | - $count_presences = $row_count['count_presences']; |
|
867 | - } |
|
864 | + $rs_count = Database::query($sql); |
|
865 | + $row_count = Database::fetch_array($rs_count); |
|
866 | + $count_presences = $row_count['count_presences']; |
|
867 | + } |
|
868 | 868 | |
869 | - // save results |
|
870 | - $sql = "SELECT id FROM $tbl_attendance_result |
|
869 | + // save results |
|
870 | + $sql = "SELECT id FROM $tbl_attendance_result |
|
871 | 871 | WHERE |
872 | 872 | c_id = $course_id AND |
873 | 873 | user_id = '$uid' AND |
874 | 874 | attendance_id = '$attendance_id' "; |
875 | - $rs_check_result = Database::query($sql); |
|
875 | + $rs_check_result = Database::query($sql); |
|
876 | 876 | |
877 | - if (Database::num_rows($rs_check_result) > 0) { |
|
878 | - // update result |
|
879 | - $sql = "UPDATE $tbl_attendance_result SET |
|
877 | + if (Database::num_rows($rs_check_result) > 0) { |
|
878 | + // update result |
|
879 | + $sql = "UPDATE $tbl_attendance_result SET |
|
880 | 880 | score = '$count_presences' |
881 | 881 | WHERE |
882 | 882 | c_id = $course_id AND |
883 | 883 | user_id='$uid' AND |
884 | 884 | attendance_id='$attendance_id'"; |
885 | - Database::query($sql); |
|
886 | - } else { |
|
887 | - // insert new result |
|
888 | - $sql = "INSERT INTO $tbl_attendance_result SET |
|
885 | + Database::query($sql); |
|
886 | + } else { |
|
887 | + // insert new result |
|
888 | + $sql = "INSERT INTO $tbl_attendance_result SET |
|
889 | 889 | c_id = $course_id , |
890 | 890 | user_id = '$uid', |
891 | 891 | attendance_id = '$attendance_id', |
892 | 892 | score = '$count_presences'"; |
893 | - Database::query($sql); |
|
893 | + Database::query($sql); |
|
894 | 894 | |
895 | - $insertId = Database::insert_id(); |
|
895 | + $insertId = Database::insert_id(); |
|
896 | 896 | if ($insertId) { |
897 | 897 | $sql = "UPDATE $tbl_attendance_result SET id = iid WHERE iid = $insertId"; |
898 | 898 | Database::query($sql); |
899 | 899 | } |
900 | - } |
|
901 | - } |
|
902 | - } |
|
900 | + } |
|
901 | + } |
|
902 | + } |
|
903 | 903 | |
904 | - // update attendance qualify max |
|
905 | - $count_done_calendar = self::get_done_attendance_calendar($attendance_id); |
|
904 | + // update attendance qualify max |
|
905 | + $count_done_calendar = self::get_done_attendance_calendar($attendance_id); |
|
906 | 906 | |
907 | - $sql = "UPDATE $tbl_attendance SET |
|
907 | + $sql = "UPDATE $tbl_attendance SET |
|
908 | 908 | attendance_qualify_max = '$count_done_calendar' |
909 | 909 | WHERE c_id = $course_id AND id = '$attendance_id'"; |
910 | - Database::query($sql); |
|
911 | - } |
|
912 | - |
|
913 | - /** |
|
914 | - * update attendance_sheet_log table, is used as history of an attendance sheet |
|
915 | - * @param int Attendance id |
|
916 | - * @param string Last edit datetime |
|
917 | - * @param string Event type ('locked_attendance', 'done_attendance_sheet' ...) |
|
918 | - * @param int Last edit user id |
|
919 | - * @param string Calendar datetime value (optional, when event type is 'done_attendance_sheet') |
|
920 | - * @return int Affected rows |
|
921 | - */ |
|
910 | + Database::query($sql); |
|
911 | + } |
|
912 | + |
|
913 | + /** |
|
914 | + * update attendance_sheet_log table, is used as history of an attendance sheet |
|
915 | + * @param int Attendance id |
|
916 | + * @param string Last edit datetime |
|
917 | + * @param string Event type ('locked_attendance', 'done_attendance_sheet' ...) |
|
918 | + * @param int Last edit user id |
|
919 | + * @param string Calendar datetime value (optional, when event type is 'done_attendance_sheet') |
|
920 | + * @return int Affected rows |
|
921 | + */ |
|
922 | 922 | public function save_attendance_sheet_log( |
923 | 923 | $attendance_id, |
924 | 924 | $lastedit_date, |
@@ -926,22 +926,22 @@ discard block |
||
926 | 926 | $lastedit_user_id, |
927 | 927 | $calendar_date_value = null |
928 | 928 | ) { |
929 | - $course_id = api_get_course_int_id(); |
|
929 | + $course_id = api_get_course_int_id(); |
|
930 | 930 | |
931 | - // define table |
|
932 | - $tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG); |
|
931 | + // define table |
|
932 | + $tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG); |
|
933 | 933 | |
934 | - // protect data |
|
935 | - $attendance_id = intval($attendance_id); |
|
936 | - $lastedit_user_id = intval($lastedit_user_id); |
|
934 | + // protect data |
|
935 | + $attendance_id = intval($attendance_id); |
|
936 | + $lastedit_user_id = intval($lastedit_user_id); |
|
937 | 937 | |
938 | - if (isset($calendar_date_value)) { |
|
939 | - $calendar_date_value = $calendar_date_value; |
|
940 | - } else { |
|
941 | - $calendar_date_value = ''; |
|
942 | - } |
|
938 | + if (isset($calendar_date_value)) { |
|
939 | + $calendar_date_value = $calendar_date_value; |
|
940 | + } else { |
|
941 | + $calendar_date_value = ''; |
|
942 | + } |
|
943 | 943 | |
944 | - // save data |
|
944 | + // save data |
|
945 | 945 | $params = [ |
946 | 946 | 'c_id' => $course_id, |
947 | 947 | 'attendance_id' => $attendance_id, |
@@ -950,228 +950,228 @@ discard block |
||
950 | 950 | 'lastedit_user_id' => $lastedit_user_id, |
951 | 951 | 'calendar_date_value' => $calendar_date_value, |
952 | 952 | ]; |
953 | - $insertId = Database::insert($tbl_attendance_sheet_log, $params); |
|
953 | + $insertId = Database::insert($tbl_attendance_sheet_log, $params); |
|
954 | 954 | if ($insertId) { |
955 | 955 | $sql = "UPDATE $tbl_attendance_sheet_log SET id = iid WHERE iid = $insertId"; |
956 | 956 | Database::query($sql); |
957 | 957 | } |
958 | 958 | |
959 | - return $insertId; |
|
960 | - } |
|
961 | - |
|
962 | - /** |
|
963 | - * Get number of done attendances inside current sheet |
|
964 | - * @param int attendance id |
|
965 | - * @return int number of done attendances |
|
966 | - */ |
|
967 | - public static function get_done_attendance_calendar($attendance_id) |
|
968 | - { |
|
969 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
970 | - $attendance_id = intval($attendance_id); |
|
971 | - $course_id = api_get_course_int_id(); |
|
972 | - $sql = "SELECT count(done_attendance) as count |
|
959 | + return $insertId; |
|
960 | + } |
|
961 | + |
|
962 | + /** |
|
963 | + * Get number of done attendances inside current sheet |
|
964 | + * @param int attendance id |
|
965 | + * @return int number of done attendances |
|
966 | + */ |
|
967 | + public static function get_done_attendance_calendar($attendance_id) |
|
968 | + { |
|
969 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
970 | + $attendance_id = intval($attendance_id); |
|
971 | + $course_id = api_get_course_int_id(); |
|
972 | + $sql = "SELECT count(done_attendance) as count |
|
973 | 973 | FROM $tbl_attendance_calendar |
974 | 974 | WHERE |
975 | 975 | c_id = $course_id AND |
976 | 976 | attendance_id = '$attendance_id' AND |
977 | 977 | done_attendance = 1 |
978 | 978 | "; |
979 | - $rs = Database::query($sql); |
|
980 | - $row = Database::fetch_array($rs); |
|
981 | - $count = $row['count']; |
|
982 | - return $count; |
|
983 | - } |
|
984 | - |
|
985 | - /** |
|
986 | - * Get results of faults (absents) by user |
|
987 | - * @param int $user_id |
|
988 | - * @param int $attendance_id |
|
989 | - * @param int $groupId |
|
990 | - * @return array results containing number of faults, total done attendance, |
|
991 | - * percent of faults and color depend on result (red, orange) |
|
992 | - */ |
|
993 | - public function get_faults_of_user($user_id, $attendance_id, $groupId = null) |
|
994 | - { |
|
995 | - // initializing database table and variables |
|
996 | - $user_id = intval($user_id); |
|
997 | - $attendance_id = intval($attendance_id); |
|
998 | - $results = array(); |
|
999 | - $calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id); |
|
1000 | - // $total_done_attendance = $attendance_data['attendance_qualify_max']; |
|
979 | + $rs = Database::query($sql); |
|
980 | + $row = Database::fetch_array($rs); |
|
981 | + $count = $row['count']; |
|
982 | + return $count; |
|
983 | + } |
|
984 | + |
|
985 | + /** |
|
986 | + * Get results of faults (absents) by user |
|
987 | + * @param int $user_id |
|
988 | + * @param int $attendance_id |
|
989 | + * @param int $groupId |
|
990 | + * @return array results containing number of faults, total done attendance, |
|
991 | + * percent of faults and color depend on result (red, orange) |
|
992 | + */ |
|
993 | + public function get_faults_of_user($user_id, $attendance_id, $groupId = null) |
|
994 | + { |
|
995 | + // initializing database table and variables |
|
996 | + $user_id = intval($user_id); |
|
997 | + $attendance_id = intval($attendance_id); |
|
998 | + $results = array(); |
|
999 | + $calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id); |
|
1000 | + // $total_done_attendance = $attendance_data['attendance_qualify_max']; |
|
1001 | 1001 | $total_done_attendance = self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id); |
1002 | - $attendance_user_score = $this->get_user_score($user_id, $attendance_id, $groupId); |
|
1002 | + $attendance_user_score = $this->get_user_score($user_id, $attendance_id, $groupId); |
|
1003 | 1003 | |
1004 | - //This is the main change of the BT#1381 |
|
1005 | - //$total_done_attendance = $calendar_count; |
|
1004 | + //This is the main change of the BT#1381 |
|
1005 | + //$total_done_attendance = $calendar_count; |
|
1006 | 1006 | |
1007 | - // calculate results |
|
1008 | - $faults = $total_done_attendance - $attendance_user_score; |
|
1007 | + // calculate results |
|
1008 | + $faults = $total_done_attendance - $attendance_user_score; |
|
1009 | 1009 | |
1010 | 1010 | if (empty($calendar_count)) { |
1011 | 1011 | $faults = 0; |
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | $faults = $faults > 0 ? $faults : 0; |
1015 | - $faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0; |
|
1015 | + $faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0; |
|
1016 | 1016 | $results['faults'] = $faults; |
1017 | 1017 | $results['total'] = $calendar_count; |
1018 | 1018 | $results['faults_porcent'] = $faults_porcent; |
1019 | - $color_bar = ''; |
|
1019 | + $color_bar = ''; |
|
1020 | 1020 | |
1021 | 1021 | if ($faults_porcent > 25) { |
1022 | 1022 | $color_bar = '#f28989'; |
1023 | - } else if ($faults_porcent > 10) { |
|
1024 | - $color_bar = '#F90'; |
|
1025 | - } |
|
1026 | - $results['color_bar'] = $color_bar; |
|
1027 | - |
|
1028 | - return $results; |
|
1029 | - } |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * Get results of faults average for all courses by user |
|
1033 | - * @param int $user_id |
|
1034 | - * @return array results containing number of faults, total done attendance, |
|
1035 | - * percentage of faults and color depend on result (red, orange) |
|
1036 | - */ |
|
1037 | - public function get_faults_average_inside_courses($user_id) |
|
1038 | - { |
|
1039 | - // get all courses of current user |
|
1040 | - $courses = CourseManager::get_courses_list_by_user_id($user_id, true); |
|
1041 | - |
|
1042 | - $user_id = intval($user_id); |
|
1043 | - $results = array(); |
|
1044 | - $total_faults = $total_weight = $porcent = 0; |
|
1045 | - foreach ($courses as $course) { |
|
1046 | - //$course_code = $course['code']; |
|
1047 | - //$course_info = api_get_course_info($course_code); |
|
1048 | - $course_id = $course['real_id']; |
|
1049 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1050 | - |
|
1051 | - $attendances_by_course = $this->get_attendances_list($course_id); |
|
1052 | - |
|
1053 | - foreach ($attendances_by_course as $attendance) { |
|
1054 | - // get total faults and total weight |
|
1055 | - $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1056 | - $sql = "SELECT score |
|
1023 | + } else if ($faults_porcent > 10) { |
|
1024 | + $color_bar = '#F90'; |
|
1025 | + } |
|
1026 | + $results['color_bar'] = $color_bar; |
|
1027 | + |
|
1028 | + return $results; |
|
1029 | + } |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * Get results of faults average for all courses by user |
|
1033 | + * @param int $user_id |
|
1034 | + * @return array results containing number of faults, total done attendance, |
|
1035 | + * percentage of faults and color depend on result (red, orange) |
|
1036 | + */ |
|
1037 | + public function get_faults_average_inside_courses($user_id) |
|
1038 | + { |
|
1039 | + // get all courses of current user |
|
1040 | + $courses = CourseManager::get_courses_list_by_user_id($user_id, true); |
|
1041 | + |
|
1042 | + $user_id = intval($user_id); |
|
1043 | + $results = array(); |
|
1044 | + $total_faults = $total_weight = $porcent = 0; |
|
1045 | + foreach ($courses as $course) { |
|
1046 | + //$course_code = $course['code']; |
|
1047 | + //$course_info = api_get_course_info($course_code); |
|
1048 | + $course_id = $course['real_id']; |
|
1049 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1050 | + |
|
1051 | + $attendances_by_course = $this->get_attendances_list($course_id); |
|
1052 | + |
|
1053 | + foreach ($attendances_by_course as $attendance) { |
|
1054 | + // get total faults and total weight |
|
1055 | + $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1056 | + $sql = "SELECT score |
|
1057 | 1057 | FROM $tbl_attendance_result |
1058 | 1058 | WHERE |
1059 | 1059 | c_id = $course_id AND |
1060 | 1060 | user_id = $user_id AND |
1061 | 1061 | attendance_id = ".$attendance['id']; |
1062 | - $rs = Database::query($sql); |
|
1063 | - $score = 0; |
|
1064 | - if (Database::num_rows($rs) > 0) { |
|
1065 | - $row = Database::fetch_array($rs); |
|
1066 | - $score = $row['score']; |
|
1067 | - } |
|
1068 | - $faults = $total_done_attendance-$score; |
|
1069 | - $faults = $faults > 0 ? $faults:0; |
|
1070 | - $total_faults += $faults; |
|
1071 | - $total_weight += $total_done_attendance; |
|
1072 | - } |
|
1073 | - } |
|
1074 | - |
|
1075 | - $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0; |
|
1076 | - $results['faults'] = $total_faults; |
|
1077 | - $results['total'] = $total_weight; |
|
1078 | - $results['porcent'] = $porcent; |
|
1079 | - |
|
1080 | - return $results; |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Get results of faults average by course |
|
1085 | - * @param int $user_id |
|
1086 | - * @param string $course_code |
|
1087 | - * @param int Session id (optional) |
|
1088 | - * @return array results containing number of faults, |
|
1089 | - * total done attendance, porcent of faults and color depend on result (red, orange) |
|
1090 | - */ |
|
1091 | - public function get_faults_average_by_course($user_id, $course_code, $session_id = null) |
|
1092 | - { |
|
1093 | - // Database tables and variables |
|
1094 | - $course_info = api_get_course_info($course_code); |
|
1095 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1096 | - $user_id = intval($user_id); |
|
1097 | - $results = array(); |
|
1098 | - $total_faults = $total_weight = $porcent = 0; |
|
1099 | - $attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id); |
|
1100 | - |
|
1101 | - foreach ($attendances_by_course as $attendance) { |
|
1102 | - // Get total faults and total weight |
|
1103 | - $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1104 | - $sql = "SELECT score FROM $tbl_attendance_result |
|
1105 | - WHERE |
|
1062 | + $rs = Database::query($sql); |
|
1063 | + $score = 0; |
|
1064 | + if (Database::num_rows($rs) > 0) { |
|
1065 | + $row = Database::fetch_array($rs); |
|
1066 | + $score = $row['score']; |
|
1067 | + } |
|
1068 | + $faults = $total_done_attendance-$score; |
|
1069 | + $faults = $faults > 0 ? $faults:0; |
|
1070 | + $total_faults += $faults; |
|
1071 | + $total_weight += $total_done_attendance; |
|
1072 | + } |
|
1073 | + } |
|
1074 | + |
|
1075 | + $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0; |
|
1076 | + $results['faults'] = $total_faults; |
|
1077 | + $results['total'] = $total_weight; |
|
1078 | + $results['porcent'] = $porcent; |
|
1079 | + |
|
1080 | + return $results; |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Get results of faults average by course |
|
1085 | + * @param int $user_id |
|
1086 | + * @param string $course_code |
|
1087 | + * @param int Session id (optional) |
|
1088 | + * @return array results containing number of faults, |
|
1089 | + * total done attendance, porcent of faults and color depend on result (red, orange) |
|
1090 | + */ |
|
1091 | + public function get_faults_average_by_course($user_id, $course_code, $session_id = null) |
|
1092 | + { |
|
1093 | + // Database tables and variables |
|
1094 | + $course_info = api_get_course_info($course_code); |
|
1095 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1096 | + $user_id = intval($user_id); |
|
1097 | + $results = array(); |
|
1098 | + $total_faults = $total_weight = $porcent = 0; |
|
1099 | + $attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id); |
|
1100 | + |
|
1101 | + foreach ($attendances_by_course as $attendance) { |
|
1102 | + // Get total faults and total weight |
|
1103 | + $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1104 | + $sql = "SELECT score FROM $tbl_attendance_result |
|
1105 | + WHERE |
|
1106 | 1106 | c_id = {$course_info['real_id']} AND |
1107 | 1107 | user_id = $user_id AND |
1108 | 1108 | attendance_id=".$attendance['id']; |
1109 | - $rs = Database::query($sql); |
|
1110 | - $score = 0; |
|
1111 | - if (Database::num_rows($rs) > 0) { |
|
1112 | - $row = Database::fetch_array($rs); |
|
1113 | - $score = $row['score']; |
|
1114 | - } |
|
1115 | - $faults = $total_done_attendance-$score; |
|
1116 | - $faults = $faults > 0 ? $faults:0; |
|
1117 | - $total_faults += $faults; |
|
1118 | - $total_weight += $total_done_attendance; |
|
1119 | - } |
|
1120 | - |
|
1121 | - $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0; |
|
1122 | - $results['faults'] = $total_faults; |
|
1123 | - $results['total'] = $total_weight; |
|
1124 | - $results['porcent'] = $porcent; |
|
1125 | - |
|
1126 | - return $results; |
|
1127 | - } |
|
1128 | - |
|
1129 | - /** |
|
1130 | - * Get registered users' attendance sheet inside current course |
|
1131 | - * @param int $attendance_id |
|
1132 | - * @param int $user_id for showing data for only one user (optional) |
|
1133 | - * @return array users attendance sheet data |
|
1134 | - */ |
|
1135 | - public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null) |
|
1136 | - { |
|
1137 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1138 | - $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1139 | - |
|
1140 | - $attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId); |
|
1141 | - $calendar_ids = array(); |
|
1142 | - // get all dates from calendar by current attendance |
|
1143 | - foreach ($attendance_calendar as $cal) { |
|
1144 | - $calendar_ids[] = $cal['id']; |
|
1145 | - } |
|
1146 | - |
|
1147 | - $course_id = api_get_course_int_id(); |
|
1148 | - |
|
1149 | - $data = array(); |
|
1150 | - if (empty($user_id)) { |
|
1151 | - // get all registered users inside current course |
|
1152 | - $users = $this->get_users_rel_course(); |
|
1153 | - $user_ids = array_keys($users); |
|
1154 | - if (count($calendar_ids) > 0 && count($user_ids) > 0) { |
|
1155 | - foreach ($user_ids as $uid) { |
|
1156 | - $sql = "SELECT * FROM $tbl_attendance_sheet |
|
1109 | + $rs = Database::query($sql); |
|
1110 | + $score = 0; |
|
1111 | + if (Database::num_rows($rs) > 0) { |
|
1112 | + $row = Database::fetch_array($rs); |
|
1113 | + $score = $row['score']; |
|
1114 | + } |
|
1115 | + $faults = $total_done_attendance-$score; |
|
1116 | + $faults = $faults > 0 ? $faults:0; |
|
1117 | + $total_faults += $faults; |
|
1118 | + $total_weight += $total_done_attendance; |
|
1119 | + } |
|
1120 | + |
|
1121 | + $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0; |
|
1122 | + $results['faults'] = $total_faults; |
|
1123 | + $results['total'] = $total_weight; |
|
1124 | + $results['porcent'] = $porcent; |
|
1125 | + |
|
1126 | + return $results; |
|
1127 | + } |
|
1128 | + |
|
1129 | + /** |
|
1130 | + * Get registered users' attendance sheet inside current course |
|
1131 | + * @param int $attendance_id |
|
1132 | + * @param int $user_id for showing data for only one user (optional) |
|
1133 | + * @return array users attendance sheet data |
|
1134 | + */ |
|
1135 | + public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null) |
|
1136 | + { |
|
1137 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1138 | + $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1139 | + |
|
1140 | + $attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId); |
|
1141 | + $calendar_ids = array(); |
|
1142 | + // get all dates from calendar by current attendance |
|
1143 | + foreach ($attendance_calendar as $cal) { |
|
1144 | + $calendar_ids[] = $cal['id']; |
|
1145 | + } |
|
1146 | + |
|
1147 | + $course_id = api_get_course_int_id(); |
|
1148 | + |
|
1149 | + $data = array(); |
|
1150 | + if (empty($user_id)) { |
|
1151 | + // get all registered users inside current course |
|
1152 | + $users = $this->get_users_rel_course(); |
|
1153 | + $user_ids = array_keys($users); |
|
1154 | + if (count($calendar_ids) > 0 && count($user_ids) > 0) { |
|
1155 | + foreach ($user_ids as $uid) { |
|
1156 | + $sql = "SELECT * FROM $tbl_attendance_sheet |
|
1157 | 1157 | WHERE |
1158 | 1158 | c_id = $course_id AND |
1159 | 1159 | user_id = '$uid' AND |
1160 | 1160 | attendance_calendar_id IN(".implode(',',$calendar_ids).") |
1161 | 1161 | "; |
1162 | - $res = Database::query($sql); |
|
1163 | - if (Database::num_rows($res) > 0) { |
|
1164 | - while ($row = Database::fetch_array($res)) { |
|
1165 | - $data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence']; |
|
1166 | - } |
|
1167 | - } |
|
1168 | - } |
|
1169 | - } |
|
1170 | - } else { |
|
1171 | - // Get attendance for current user |
|
1172 | - $user_id = intval($user_id); |
|
1173 | - if (count($calendar_ids) > 0) { |
|
1174 | - $sql = "SELECT cal.date_time, att.presence |
|
1162 | + $res = Database::query($sql); |
|
1163 | + if (Database::num_rows($res) > 0) { |
|
1164 | + while ($row = Database::fetch_array($res)) { |
|
1165 | + $data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence']; |
|
1166 | + } |
|
1167 | + } |
|
1168 | + } |
|
1169 | + } |
|
1170 | + } else { |
|
1171 | + // Get attendance for current user |
|
1172 | + $user_id = intval($user_id); |
|
1173 | + if (count($calendar_ids) > 0) { |
|
1174 | + $sql = "SELECT cal.date_time, att.presence |
|
1175 | 1175 | FROM $tbl_attendance_sheet att |
1176 | 1176 | INNER JOIN $tbl_attendance_calendar cal |
1177 | 1177 | ON cal.id = att.attendance_calendar_id |
@@ -1181,87 +1181,87 @@ discard block |
||
1181 | 1181 | att.user_id = '$user_id' AND |
1182 | 1182 | att.attendance_calendar_id IN (".implode(',',$calendar_ids).") |
1183 | 1183 | ORDER BY date_time"; |
1184 | - $res = Database::query($sql); |
|
1185 | - if (Database::num_rows($res) > 0) { |
|
1186 | - while ($row = Database::fetch_array($res)) { |
|
1187 | - $row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get()); |
|
1188 | - $data[$user_id][] = $row; |
|
1189 | - } |
|
1190 | - } |
|
1191 | - } |
|
1192 | - } |
|
1193 | - return $data; |
|
1194 | - } |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Get next attendance calendar without presences (done attendances) |
|
1198 | - * @param int attendance id |
|
1199 | - * @return int attendance calendar id |
|
1200 | - */ |
|
1201 | - public function get_next_attendance_calendar_id($attendance_id) |
|
1202 | - { |
|
1203 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1204 | - $attendance_id = intval($attendance_id); |
|
1205 | - $course_id = api_get_course_int_id(); |
|
1206 | - |
|
1207 | - $sql = "SELECT id FROM $tbl_attendance_calendar |
|
1184 | + $res = Database::query($sql); |
|
1185 | + if (Database::num_rows($res) > 0) { |
|
1186 | + while ($row = Database::fetch_array($res)) { |
|
1187 | + $row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get()); |
|
1188 | + $data[$user_id][] = $row; |
|
1189 | + } |
|
1190 | + } |
|
1191 | + } |
|
1192 | + } |
|
1193 | + return $data; |
|
1194 | + } |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Get next attendance calendar without presences (done attendances) |
|
1198 | + * @param int attendance id |
|
1199 | + * @return int attendance calendar id |
|
1200 | + */ |
|
1201 | + public function get_next_attendance_calendar_id($attendance_id) |
|
1202 | + { |
|
1203 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1204 | + $attendance_id = intval($attendance_id); |
|
1205 | + $course_id = api_get_course_int_id(); |
|
1206 | + |
|
1207 | + $sql = "SELECT id FROM $tbl_attendance_calendar |
|
1208 | 1208 | WHERE |
1209 | 1209 | c_id = $course_id AND |
1210 | 1210 | attendance_id = '$attendance_id' AND |
1211 | 1211 | done_attendance = 0 |
1212 | 1212 | ORDER BY date_time |
1213 | 1213 | LIMIT 1"; |
1214 | - $rs = Database::query($sql); |
|
1215 | - $next_calendar_id = 0; |
|
1216 | - if (Database::num_rows($rs) > 0) { |
|
1217 | - $row = Database::fetch_array($rs); |
|
1218 | - $next_calendar_id = $row['id']; |
|
1219 | - } |
|
1220 | - return $next_calendar_id; |
|
1221 | - } |
|
1222 | - |
|
1223 | - /** |
|
1224 | - * Get next attendance calendar datetime without presences (done attendances) |
|
1225 | - * @param int attendance id |
|
1226 | - * @return int UNIX time format datetime |
|
1227 | - */ |
|
1228 | - public function get_next_attendance_calendar_datetime($attendance_id) |
|
1229 | - { |
|
1230 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1231 | - $course_id = api_get_course_int_id(); |
|
1232 | - $attendance_id = intval($attendance_id); |
|
1233 | - $sql = "SELECT id, date_time FROM $tbl_attendance_calendar |
|
1214 | + $rs = Database::query($sql); |
|
1215 | + $next_calendar_id = 0; |
|
1216 | + if (Database::num_rows($rs) > 0) { |
|
1217 | + $row = Database::fetch_array($rs); |
|
1218 | + $next_calendar_id = $row['id']; |
|
1219 | + } |
|
1220 | + return $next_calendar_id; |
|
1221 | + } |
|
1222 | + |
|
1223 | + /** |
|
1224 | + * Get next attendance calendar datetime without presences (done attendances) |
|
1225 | + * @param int attendance id |
|
1226 | + * @return int UNIX time format datetime |
|
1227 | + */ |
|
1228 | + public function get_next_attendance_calendar_datetime($attendance_id) |
|
1229 | + { |
|
1230 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1231 | + $course_id = api_get_course_int_id(); |
|
1232 | + $attendance_id = intval($attendance_id); |
|
1233 | + $sql = "SELECT id, date_time FROM $tbl_attendance_calendar |
|
1234 | 1234 | WHERE |
1235 | 1235 | c_id = $course_id AND |
1236 | 1236 | attendance_id = '$attendance_id' AND |
1237 | 1237 | done_attendance = 0 |
1238 | 1238 | ORDER BY date_time |
1239 | 1239 | LIMIT 1"; |
1240 | - $rs = Database::query($sql); |
|
1241 | - $next_calendar_datetime = 0; |
|
1242 | - if (Database::num_rows($rs) > 0) { |
|
1243 | - $row = Database::fetch_array($rs); |
|
1244 | - $next_calendar_datetime = api_get_local_time($row['date_time']); |
|
1245 | - } |
|
1246 | - |
|
1247 | - return $next_calendar_datetime; |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * Get user' score from current attendance |
|
1252 | - * @param int $user_id |
|
1253 | - * @param int $attendance_id |
|
1254 | - * @return int score |
|
1255 | - */ |
|
1256 | - public function get_user_score($user_id, $attendance_id, $groupId = null) |
|
1257 | - { |
|
1258 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1240 | + $rs = Database::query($sql); |
|
1241 | + $next_calendar_datetime = 0; |
|
1242 | + if (Database::num_rows($rs) > 0) { |
|
1243 | + $row = Database::fetch_array($rs); |
|
1244 | + $next_calendar_datetime = api_get_local_time($row['date_time']); |
|
1245 | + } |
|
1246 | + |
|
1247 | + return $next_calendar_datetime; |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * Get user' score from current attendance |
|
1252 | + * @param int $user_id |
|
1253 | + * @param int $attendance_id |
|
1254 | + * @return int score |
|
1255 | + */ |
|
1256 | + public function get_user_score($user_id, $attendance_id, $groupId = null) |
|
1257 | + { |
|
1258 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1259 | 1259 | $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
1260 | 1260 | $tbl_attendance_cal_rel_group = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
1261 | 1261 | $tbl_attendance_cal = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
1262 | - $user_id = intval($user_id); |
|
1263 | - $attendance_id = intval($attendance_id); |
|
1264 | - $course_id = api_get_course_int_id(); |
|
1262 | + $user_id = intval($user_id); |
|
1263 | + $attendance_id = intval($attendance_id); |
|
1264 | + $course_id = api_get_course_int_id(); |
|
1265 | 1265 | if (empty($groupId)) { |
1266 | 1266 | $sql = "SELECT score FROM $tbl_attendance_result |
1267 | 1267 | WHERE |
@@ -1285,68 +1285,68 @@ discard block |
||
1285 | 1285 | ) |
1286 | 1286 | "; |
1287 | 1287 | } |
1288 | - $rs = Database::query($sql); |
|
1289 | - $score = 0; |
|
1290 | - if (Database::num_rows($rs) > 0) { |
|
1291 | - $row = Database::fetch_array($rs); |
|
1292 | - $score = $row['score']; |
|
1293 | - } |
|
1294 | - |
|
1295 | - return $score; |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Get attendance calendar data by id |
|
1300 | - * @param int attendance calendar id |
|
1301 | - * @return array attendance calendar data |
|
1302 | - */ |
|
1303 | - public function get_attendance_calendar_by_id($calendar_id) |
|
1304 | - { |
|
1305 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1306 | - $calendar_id = intval($calendar_id); |
|
1307 | - $course_id = api_get_course_int_id(); |
|
1308 | - $sql = "SELECT * FROM $tbl_attendance_calendar |
|
1288 | + $rs = Database::query($sql); |
|
1289 | + $score = 0; |
|
1290 | + if (Database::num_rows($rs) > 0) { |
|
1291 | + $row = Database::fetch_array($rs); |
|
1292 | + $score = $row['score']; |
|
1293 | + } |
|
1294 | + |
|
1295 | + return $score; |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Get attendance calendar data by id |
|
1300 | + * @param int attendance calendar id |
|
1301 | + * @return array attendance calendar data |
|
1302 | + */ |
|
1303 | + public function get_attendance_calendar_by_id($calendar_id) |
|
1304 | + { |
|
1305 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1306 | + $calendar_id = intval($calendar_id); |
|
1307 | + $course_id = api_get_course_int_id(); |
|
1308 | + $sql = "SELECT * FROM $tbl_attendance_calendar |
|
1309 | 1309 | WHERE c_id = $course_id AND id = '$calendar_id' "; |
1310 | - $rs = Database::query($sql); |
|
1311 | - $data = array(); |
|
1312 | - if (Database::num_rows($rs) > 0) { |
|
1313 | - while ($row = Database::fetch_array($rs)) { |
|
1314 | - $row['date_time'] = api_get_local_time($row['date_time']); |
|
1315 | - $data = $row; |
|
1316 | - } |
|
1317 | - } |
|
1318 | - |
|
1319 | - return $data; |
|
1320 | - } |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * Get all attendance calendar data inside current attendance |
|
1324 | - * @param int $attendance_id |
|
1325 | - * @param string $type |
|
1326 | - * @param int $calendar_id |
|
1327 | - * @param int $groupId |
|
1328 | - * @param bool $showAll = false show group calendar items or not |
|
1329 | - * |
|
1330 | - * @return array attendance calendar data |
|
1331 | - */ |
|
1332 | - public function get_attendance_calendar( |
|
1333 | - $attendance_id, |
|
1334 | - $type = 'all', |
|
1335 | - $calendar_id = null, |
|
1336 | - $groupId = null, |
|
1337 | - $showAll = false |
|
1338 | - ) { |
|
1339 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1310 | + $rs = Database::query($sql); |
|
1311 | + $data = array(); |
|
1312 | + if (Database::num_rows($rs) > 0) { |
|
1313 | + while ($row = Database::fetch_array($rs)) { |
|
1314 | + $row['date_time'] = api_get_local_time($row['date_time']); |
|
1315 | + $data = $row; |
|
1316 | + } |
|
1317 | + } |
|
1318 | + |
|
1319 | + return $data; |
|
1320 | + } |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * Get all attendance calendar data inside current attendance |
|
1324 | + * @param int $attendance_id |
|
1325 | + * @param string $type |
|
1326 | + * @param int $calendar_id |
|
1327 | + * @param int $groupId |
|
1328 | + * @param bool $showAll = false show group calendar items or not |
|
1329 | + * |
|
1330 | + * @return array attendance calendar data |
|
1331 | + */ |
|
1332 | + public function get_attendance_calendar( |
|
1333 | + $attendance_id, |
|
1334 | + $type = 'all', |
|
1335 | + $calendar_id = null, |
|
1336 | + $groupId = null, |
|
1337 | + $showAll = false |
|
1338 | + ) { |
|
1339 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1340 | 1340 | $tbl_acrg = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
1341 | - $attendance_id = intval($attendance_id); |
|
1342 | - $course_id = api_get_course_int_id(); |
|
1343 | - $groupCondition = null; |
|
1341 | + $attendance_id = intval($attendance_id); |
|
1342 | + $course_id = api_get_course_int_id(); |
|
1343 | + $groupCondition = null; |
|
1344 | 1344 | |
1345 | - if ($showAll) { |
|
1346 | - $sql = "SELECT * FROM $tbl_attendance_calendar c |
|
1345 | + if ($showAll) { |
|
1346 | + $sql = "SELECT * FROM $tbl_attendance_calendar c |
|
1347 | 1347 | WHERE c_id = $course_id AND attendance_id = '$attendance_id'"; |
1348 | - } else { |
|
1349 | - $sql = "SELECT * FROM $tbl_attendance_calendar c |
|
1348 | + } else { |
|
1349 | + $sql = "SELECT * FROM $tbl_attendance_calendar c |
|
1350 | 1350 | WHERE |
1351 | 1351 | c_id = $course_id AND |
1352 | 1352 | attendance_id = '$attendance_id' AND |
@@ -1355,11 +1355,11 @@ discard block |
||
1355 | 1355 | WHERE c_id = $course_id AND group_id != 0 AND group_id IS NOT NULL |
1356 | 1356 | ) |
1357 | 1357 | "; |
1358 | - } |
|
1358 | + } |
|
1359 | 1359 | |
1360 | - if (!empty($groupId)) { |
|
1361 | - $groupId = intval($groupId); |
|
1362 | - $sql = "SELECT c.* FROM $tbl_attendance_calendar c |
|
1360 | + if (!empty($groupId)) { |
|
1361 | + $groupId = intval($groupId); |
|
1362 | + $sql = "SELECT c.* FROM $tbl_attendance_calendar c |
|
1363 | 1363 | INNER JOIN $tbl_acrg g |
1364 | 1364 | ON c.c_id = g.c_id AND c.id = g.calendar_id |
1365 | 1365 | WHERE |
@@ -1367,62 +1367,62 @@ discard block |
||
1367 | 1367 | g.group_id = '$groupId' AND |
1368 | 1368 | c.attendance_id = '$attendance_id' |
1369 | 1369 | "; |
1370 | - } |
|
1371 | - |
|
1372 | - if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) { |
|
1373 | - $type = 'all'; |
|
1374 | - } |
|
1375 | - |
|
1376 | - switch ($type) { |
|
1377 | - case 'calendar_id': |
|
1378 | - $calendar_id = intval($calendar_id); |
|
1379 | - if (!empty($calendar_id)) { |
|
1380 | - $sql.= " AND c.id = $calendar_id"; |
|
1381 | - } |
|
1382 | - break; |
|
1383 | - case 'today': |
|
1384 | - //$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )'; |
|
1385 | - break; |
|
1386 | - case 'all_done': |
|
1387 | - $sql .= " AND done_attendance = 1 "; |
|
1388 | - break; |
|
1389 | - case 'all_not_done': |
|
1390 | - $sql .= " AND done_attendance = 0 "; |
|
1391 | - break; |
|
1392 | - case 'all': |
|
1393 | - default: |
|
1394 | - break; |
|
1395 | - } |
|
1396 | - $sql .= " ORDER BY date_time "; |
|
1370 | + } |
|
1397 | 1371 | |
1398 | - $rs = Database::query($sql); |
|
1399 | - $data = array(); |
|
1400 | - if (Database::num_rows($rs) > 0) { |
|
1401 | - while ($row = Database::fetch_array($rs,'ASSOC')) { |
|
1402 | - $row['db_date_time'] = $row['date_time']; |
|
1403 | - $row['date_time'] = api_get_local_time($row['date_time']); |
|
1404 | - $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT); |
|
1405 | - $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT); |
|
1406 | - $row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id); |
|
1407 | - if ($type == 'today') { |
|
1408 | - if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) { |
|
1409 | - $data[] = $row; |
|
1410 | - } |
|
1411 | - } else { |
|
1412 | - $data[] = $row; |
|
1413 | - } |
|
1414 | - } |
|
1415 | - } |
|
1416 | - |
|
1417 | - return $data; |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Get number of attendance calendar inside current attendance |
|
1422 | - * @param int $attendance_id |
|
1423 | - * @param int $groupId |
|
1424 | - * @return int number of dates in attendance calendar |
|
1425 | - */ |
|
1372 | + if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) { |
|
1373 | + $type = 'all'; |
|
1374 | + } |
|
1375 | + |
|
1376 | + switch ($type) { |
|
1377 | + case 'calendar_id': |
|
1378 | + $calendar_id = intval($calendar_id); |
|
1379 | + if (!empty($calendar_id)) { |
|
1380 | + $sql.= " AND c.id = $calendar_id"; |
|
1381 | + } |
|
1382 | + break; |
|
1383 | + case 'today': |
|
1384 | + //$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )'; |
|
1385 | + break; |
|
1386 | + case 'all_done': |
|
1387 | + $sql .= " AND done_attendance = 1 "; |
|
1388 | + break; |
|
1389 | + case 'all_not_done': |
|
1390 | + $sql .= " AND done_attendance = 0 "; |
|
1391 | + break; |
|
1392 | + case 'all': |
|
1393 | + default: |
|
1394 | + break; |
|
1395 | + } |
|
1396 | + $sql .= " ORDER BY date_time "; |
|
1397 | + |
|
1398 | + $rs = Database::query($sql); |
|
1399 | + $data = array(); |
|
1400 | + if (Database::num_rows($rs) > 0) { |
|
1401 | + while ($row = Database::fetch_array($rs,'ASSOC')) { |
|
1402 | + $row['db_date_time'] = $row['date_time']; |
|
1403 | + $row['date_time'] = api_get_local_time($row['date_time']); |
|
1404 | + $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT); |
|
1405 | + $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT); |
|
1406 | + $row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id); |
|
1407 | + if ($type == 'today') { |
|
1408 | + if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) { |
|
1409 | + $data[] = $row; |
|
1410 | + } |
|
1411 | + } else { |
|
1412 | + $data[] = $row; |
|
1413 | + } |
|
1414 | + } |
|
1415 | + } |
|
1416 | + |
|
1417 | + return $data; |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * Get number of attendance calendar inside current attendance |
|
1422 | + * @param int $attendance_id |
|
1423 | + * @param int $groupId |
|
1424 | + * @return int number of dates in attendance calendar |
|
1425 | + */ |
|
1426 | 1426 | public static function get_number_of_attendance_calendar($attendance_id, $groupId = 0, $done_attendance = NULL, $userId = 0) |
1427 | 1427 | { |
1428 | 1428 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
@@ -1508,111 +1508,111 @@ discard block |
||
1508 | 1508 | |
1509 | 1509 | |
1510 | 1510 | /** |
1511 | - * Get count dates inside attendance calendar by attendance id |
|
1512 | - * @param int $attendance_id |
|
1513 | - * @return int count of dates |
|
1514 | - */ |
|
1515 | - public static function get_count_dates_inside_attendance_calendar($attendance_id) |
|
1516 | - { |
|
1517 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1518 | - $attendance_id = intval($attendance_id); |
|
1519 | - $course_id = api_get_course_int_id(); |
|
1520 | - $sql = "SELECT count(id) FROM $tbl_attendance_calendar |
|
1511 | + * Get count dates inside attendance calendar by attendance id |
|
1512 | + * @param int $attendance_id |
|
1513 | + * @return int count of dates |
|
1514 | + */ |
|
1515 | + public static function get_count_dates_inside_attendance_calendar($attendance_id) |
|
1516 | + { |
|
1517 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1518 | + $attendance_id = intval($attendance_id); |
|
1519 | + $course_id = api_get_course_int_id(); |
|
1520 | + $sql = "SELECT count(id) FROM $tbl_attendance_calendar |
|
1521 | 1521 | WHERE |
1522 | 1522 | c_id = $course_id AND |
1523 | 1523 | attendance_id = '$attendance_id'"; |
1524 | - $rs = Database::query($sql); |
|
1525 | - $count = 0; |
|
1526 | - if (Database::num_rows($rs) > 0) { |
|
1527 | - $row = Database::fetch_row($rs); |
|
1528 | - $count = $row[0]; |
|
1529 | - } |
|
1530 | - return $count; |
|
1531 | - } |
|
1532 | - |
|
1533 | - /** |
|
1534 | - * check if all calendar of an attendance is done |
|
1535 | - * @param int $attendance_id |
|
1536 | - * @return bool True if all calendar is done, otherwise false |
|
1537 | - */ |
|
1538 | - public static function is_all_attendance_calendar_done($attendance_id) |
|
1539 | - { |
|
1540 | - $attendance_id = intval($attendance_id); |
|
1541 | - $done_calendar = self::get_done_attendance_calendar($attendance_id); |
|
1542 | - $count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id); |
|
1543 | - $number_of_dates = self::get_number_of_attendance_calendar($attendance_id); |
|
1544 | - |
|
1545 | - $result = false; |
|
1546 | - if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) { |
|
1547 | - $result = true; |
|
1548 | - } |
|
1549 | - return $result; |
|
1550 | - } |
|
1551 | - |
|
1552 | - /** |
|
1553 | - * check if an attendance is locked |
|
1554 | - * @param int $attendance_id |
|
1555 | - * @param bool |
|
1556 | - */ |
|
1557 | - public static function is_locked_attendance($attendance_id) |
|
1558 | - { |
|
1559 | - //use gradebook lock |
|
1560 | - $result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE); |
|
1561 | - return $result; |
|
1562 | - } |
|
1563 | - |
|
1564 | - /** |
|
1565 | - * Add new datetime inside attendance calendar table |
|
1566 | - * @param int $attendance_id |
|
1567 | - * @param array $groupList |
|
1568 | - * @return int affected rows |
|
1569 | - */ |
|
1570 | - public function attendance_calendar_add($attendance_id, $groupList = array()) |
|
1571 | - { |
|
1572 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1573 | - $affected_rows = 0; |
|
1574 | - $attendance_id = intval($attendance_id); |
|
1575 | - $course_id = api_get_course_int_id(); |
|
1576 | - // check if datetime already exists inside the table |
|
1577 | - /*$sql = "SELECT id FROM $tbl_attendance_calendar |
|
1524 | + $rs = Database::query($sql); |
|
1525 | + $count = 0; |
|
1526 | + if (Database::num_rows($rs) > 0) { |
|
1527 | + $row = Database::fetch_row($rs); |
|
1528 | + $count = $row[0]; |
|
1529 | + } |
|
1530 | + return $count; |
|
1531 | + } |
|
1532 | + |
|
1533 | + /** |
|
1534 | + * check if all calendar of an attendance is done |
|
1535 | + * @param int $attendance_id |
|
1536 | + * @return bool True if all calendar is done, otherwise false |
|
1537 | + */ |
|
1538 | + public static function is_all_attendance_calendar_done($attendance_id) |
|
1539 | + { |
|
1540 | + $attendance_id = intval($attendance_id); |
|
1541 | + $done_calendar = self::get_done_attendance_calendar($attendance_id); |
|
1542 | + $count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id); |
|
1543 | + $number_of_dates = self::get_number_of_attendance_calendar($attendance_id); |
|
1544 | + |
|
1545 | + $result = false; |
|
1546 | + if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) { |
|
1547 | + $result = true; |
|
1548 | + } |
|
1549 | + return $result; |
|
1550 | + } |
|
1551 | + |
|
1552 | + /** |
|
1553 | + * check if an attendance is locked |
|
1554 | + * @param int $attendance_id |
|
1555 | + * @param bool |
|
1556 | + */ |
|
1557 | + public static function is_locked_attendance($attendance_id) |
|
1558 | + { |
|
1559 | + //use gradebook lock |
|
1560 | + $result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE); |
|
1561 | + return $result; |
|
1562 | + } |
|
1563 | + |
|
1564 | + /** |
|
1565 | + * Add new datetime inside attendance calendar table |
|
1566 | + * @param int $attendance_id |
|
1567 | + * @param array $groupList |
|
1568 | + * @return int affected rows |
|
1569 | + */ |
|
1570 | + public function attendance_calendar_add($attendance_id, $groupList = array()) |
|
1571 | + { |
|
1572 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1573 | + $affected_rows = 0; |
|
1574 | + $attendance_id = intval($attendance_id); |
|
1575 | + $course_id = api_get_course_int_id(); |
|
1576 | + // check if datetime already exists inside the table |
|
1577 | + /*$sql = "SELECT id FROM $tbl_attendance_calendar |
|
1578 | 1578 | WHERE |
1579 | 1579 | c_id = $course_id AND |
1580 | 1580 | date_time='".Database::escape_string($this->date_time)."' AND |
1581 | 1581 | attendance_id = '$attendance_id'"; |
1582 | 1582 | $rs = Database::query($sql); |
1583 | 1583 | if (Database::num_rows($rs) == 0) {*/ |
1584 | - $params = array( |
|
1585 | - 'c_id' => $course_id, |
|
1586 | - 'date_time' => $this->date_time, |
|
1587 | - 'attendance_id' => $attendance_id |
|
1588 | - ); |
|
1589 | - $id = Database::insert($tbl_attendance_calendar, $params); |
|
1590 | - |
|
1591 | - if ($id) { |
|
1592 | - $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id"; |
|
1593 | - Database::query($sql); |
|
1594 | - $affected_rows++; |
|
1595 | - } |
|
1596 | - $this->addAttendanceCalendarToGroup($id, $course_id, $groupList); |
|
1597 | - //} |
|
1598 | - |
|
1599 | - // update locked attendance |
|
1600 | - $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1601 | - if (!$is_all_calendar_done) { |
|
1602 | - self::lock_attendance($attendance_id, false); |
|
1603 | - } else { |
|
1604 | - self::lock_attendance($attendance_id); |
|
1605 | - } |
|
1606 | - return $affected_rows; |
|
1607 | - } |
|
1608 | - |
|
1609 | - /** |
|
1610 | - * @param int $calendarId |
|
1611 | - * @param int $courseId |
|
1612 | - * @param array $groupList |
|
1613 | - */ |
|
1614 | - public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList) |
|
1615 | - { |
|
1584 | + $params = array( |
|
1585 | + 'c_id' => $course_id, |
|
1586 | + 'date_time' => $this->date_time, |
|
1587 | + 'attendance_id' => $attendance_id |
|
1588 | + ); |
|
1589 | + $id = Database::insert($tbl_attendance_calendar, $params); |
|
1590 | + |
|
1591 | + if ($id) { |
|
1592 | + $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id"; |
|
1593 | + Database::query($sql); |
|
1594 | + $affected_rows++; |
|
1595 | + } |
|
1596 | + $this->addAttendanceCalendarToGroup($id, $course_id, $groupList); |
|
1597 | + //} |
|
1598 | + |
|
1599 | + // update locked attendance |
|
1600 | + $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1601 | + if (!$is_all_calendar_done) { |
|
1602 | + self::lock_attendance($attendance_id, false); |
|
1603 | + } else { |
|
1604 | + self::lock_attendance($attendance_id); |
|
1605 | + } |
|
1606 | + return $affected_rows; |
|
1607 | + } |
|
1608 | + |
|
1609 | + /** |
|
1610 | + * @param int $calendarId |
|
1611 | + * @param int $courseId |
|
1612 | + * @param array $groupList |
|
1613 | + */ |
|
1614 | + public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList) |
|
1615 | + { |
|
1616 | 1616 | if (empty($groupList)) { |
1617 | 1617 | return false; |
1618 | 1618 | } |
@@ -1640,506 +1640,506 @@ discard block |
||
1640 | 1640 | Database::insert($table, $params); |
1641 | 1641 | } |
1642 | 1642 | } |
1643 | - } |
|
1644 | - |
|
1645 | - /** |
|
1646 | - * @param int $calendarId |
|
1647 | - * @param int $courseId |
|
1648 | - * @param int $groupId |
|
1649 | - * @return array |
|
1650 | - */ |
|
1651 | - public function getGroupListByAttendanceCalendar($calendarId, $courseId) |
|
1652 | - { |
|
1653 | - $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1654 | - return Database::select( |
|
1655 | - '*', |
|
1656 | - $table, |
|
1657 | - array('where'=> |
|
1658 | - array( |
|
1659 | - 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1660 | - ) |
|
1661 | - ) |
|
1662 | - ); |
|
1663 | - } |
|
1664 | - |
|
1665 | - /** |
|
1666 | - * @param int $calendarId |
|
1667 | - * @param int $courseId |
|
1668 | - * @param int $groupId |
|
1669 | - * @return array |
|
1670 | - */ |
|
1671 | - public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId) |
|
1672 | - { |
|
1673 | - $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1674 | - return Database::select( |
|
1675 | - '*', |
|
1676 | - $table, |
|
1677 | - array('where'=> |
|
1678 | - array( |
|
1679 | - 'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId) |
|
1680 | - ) |
|
1681 | - ) |
|
1682 | - ); |
|
1683 | - } |
|
1684 | - |
|
1685 | - /** |
|
1686 | - * @param int $calendarId |
|
1687 | - * @param int $courseId |
|
1688 | - * @param int $groupId |
|
1643 | + } |
|
1644 | + |
|
1645 | + /** |
|
1646 | + * @param int $calendarId |
|
1647 | + * @param int $courseId |
|
1648 | + * @param int $groupId |
|
1649 | + * @return array |
|
1650 | + */ |
|
1651 | + public function getGroupListByAttendanceCalendar($calendarId, $courseId) |
|
1652 | + { |
|
1653 | + $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1654 | + return Database::select( |
|
1655 | + '*', |
|
1656 | + $table, |
|
1657 | + array('where'=> |
|
1658 | + array( |
|
1659 | + 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1660 | + ) |
|
1661 | + ) |
|
1662 | + ); |
|
1663 | + } |
|
1664 | + |
|
1665 | + /** |
|
1666 | + * @param int $calendarId |
|
1667 | + * @param int $courseId |
|
1668 | + * @param int $groupId |
|
1669 | + * @return array |
|
1670 | + */ |
|
1671 | + public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId) |
|
1672 | + { |
|
1673 | + $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1674 | + return Database::select( |
|
1675 | + '*', |
|
1676 | + $table, |
|
1677 | + array('where'=> |
|
1678 | + array( |
|
1679 | + 'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId) |
|
1680 | + ) |
|
1681 | + ) |
|
1682 | + ); |
|
1683 | + } |
|
1684 | + |
|
1685 | + /** |
|
1686 | + * @param int $calendarId |
|
1687 | + * @param int $courseId |
|
1688 | + * @param int $groupId |
|
1689 | 1689 | * |
1690 | - * @return array |
|
1691 | - */ |
|
1692 | - public function deleteAttendanceCalendarGroup($calendarId, $courseId) |
|
1693 | - { |
|
1694 | - $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1695 | - Database::delete( |
|
1696 | - $table, |
|
1697 | - array( |
|
1698 | - 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1699 | - ) |
|
1700 | - ); |
|
1701 | - } |
|
1702 | - |
|
1703 | - /** |
|
1704 | - * save repeated date inside attendance calendar table |
|
1705 | - * @param int $attendance_id |
|
1706 | - * @param int $start_date start date in tms |
|
1707 | - * @param int $end_date end date in tms |
|
1708 | - * @param string $repeat_type daily, weekly, monthlyByDate |
|
1709 | - * @param array $groupList |
|
1710 | - */ |
|
1711 | - public function attendance_repeat_calendar_add( |
|
1712 | - $attendance_id, |
|
1713 | - $start_date, |
|
1714 | - $end_date, |
|
1715 | - $repeat_type, |
|
1716 | - $groupList = array() |
|
1717 | - ) { |
|
1718 | - $attendance_id = intval($attendance_id); |
|
1719 | - // save start date |
|
1720 | - $datetimezone = api_get_utc_datetime($start_date); |
|
1721 | - $this->set_date_time($datetimezone); |
|
1722 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1723 | - |
|
1724 | - // 86400 = 24 hours in seconds |
|
1725 | - // 604800 = 1 week in seconds |
|
1726 | - // Saves repeated dates |
|
1727 | - switch ($repeat_type) { |
|
1728 | - case 'daily': |
|
1729 | - $j = 1; |
|
1730 | - for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) { |
|
1731 | - $datetimezone = api_get_utc_datetime($i); |
|
1732 | - $this->set_date_time($datetimezone); |
|
1733 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1734 | - $j++; |
|
1735 | - } |
|
1736 | - break; |
|
1737 | - case 'weekly': |
|
1738 | - $j = 1; |
|
1739 | - for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { |
|
1740 | - $datetimezone = api_get_utc_datetime($i); |
|
1741 | - $this->set_date_time($datetimezone); |
|
1742 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1743 | - $j++; |
|
1744 | - } |
|
1745 | - break; |
|
1746 | - case 'monthlyByDate': |
|
1747 | - $j = 1; |
|
1748 | - //@todo fix bug with february |
|
1749 | - for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) { |
|
1750 | - $datetimezone = api_get_utc_datetime($i); |
|
1751 | - $this->set_date_time($datetimezone); |
|
1752 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1753 | - $j++; |
|
1754 | - } |
|
1755 | - break; |
|
1756 | - } |
|
1757 | - } |
|
1758 | - |
|
1759 | - /** |
|
1760 | - * Adds x months to a UNIX timestamp |
|
1761 | - * @param int The timestamp |
|
1762 | - * @param int The number of years to add |
|
1763 | - * @return int The new timestamp |
|
1764 | - */ |
|
1765 | - private function add_month($timestamp, $num=1) |
|
1766 | - { |
|
1767 | - $values = api_get_utc_datetime($timestamp); |
|
1768 | - $values = str_replace(array(':','-',' '), '/', $values); |
|
1769 | - list($y, $m, $d, $h, $n, $s) = split('/',$values); |
|
1770 | - if($m+$num>12) { |
|
1771 | - $y += floor($num/12); |
|
1772 | - $m += $num%12; |
|
1773 | - } else { |
|
1774 | - $m += $num; |
|
1775 | - } |
|
1776 | - //date_default_timezone_set('UTC'); |
|
1777 | - // return mktime($h, $n, $s, $m, $d, $y); |
|
1778 | - $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC'); |
|
1779 | - if (!empty($result)) { |
|
1780 | - return $result; |
|
1781 | - } |
|
1782 | - return false; |
|
1783 | - } |
|
1784 | - |
|
1785 | - /** |
|
1786 | - * edit a datetime inside attendance calendar table |
|
1787 | - * @param int attendance calendar id |
|
1788 | - * @param int attendance id |
|
1789 | - * @return int affected rows |
|
1790 | - */ |
|
1791 | - public function attendance_calendar_edit($calendar_id, $attendance_id) |
|
1792 | - { |
|
1793 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1794 | - $affected_rows = 0; |
|
1795 | - $attendance_id = intval($attendance_id); |
|
1796 | - $course_id = api_get_course_int_id(); |
|
1797 | - // check if datetime already exists inside the table |
|
1798 | - $sql = "SELECT id FROM $tbl_attendance_calendar |
|
1690 | + * @return array |
|
1691 | + */ |
|
1692 | + public function deleteAttendanceCalendarGroup($calendarId, $courseId) |
|
1693 | + { |
|
1694 | + $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1695 | + Database::delete( |
|
1696 | + $table, |
|
1697 | + array( |
|
1698 | + 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1699 | + ) |
|
1700 | + ); |
|
1701 | + } |
|
1702 | + |
|
1703 | + /** |
|
1704 | + * save repeated date inside attendance calendar table |
|
1705 | + * @param int $attendance_id |
|
1706 | + * @param int $start_date start date in tms |
|
1707 | + * @param int $end_date end date in tms |
|
1708 | + * @param string $repeat_type daily, weekly, monthlyByDate |
|
1709 | + * @param array $groupList |
|
1710 | + */ |
|
1711 | + public function attendance_repeat_calendar_add( |
|
1712 | + $attendance_id, |
|
1713 | + $start_date, |
|
1714 | + $end_date, |
|
1715 | + $repeat_type, |
|
1716 | + $groupList = array() |
|
1717 | + ) { |
|
1718 | + $attendance_id = intval($attendance_id); |
|
1719 | + // save start date |
|
1720 | + $datetimezone = api_get_utc_datetime($start_date); |
|
1721 | + $this->set_date_time($datetimezone); |
|
1722 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1723 | + |
|
1724 | + // 86400 = 24 hours in seconds |
|
1725 | + // 604800 = 1 week in seconds |
|
1726 | + // Saves repeated dates |
|
1727 | + switch ($repeat_type) { |
|
1728 | + case 'daily': |
|
1729 | + $j = 1; |
|
1730 | + for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) { |
|
1731 | + $datetimezone = api_get_utc_datetime($i); |
|
1732 | + $this->set_date_time($datetimezone); |
|
1733 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1734 | + $j++; |
|
1735 | + } |
|
1736 | + break; |
|
1737 | + case 'weekly': |
|
1738 | + $j = 1; |
|
1739 | + for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { |
|
1740 | + $datetimezone = api_get_utc_datetime($i); |
|
1741 | + $this->set_date_time($datetimezone); |
|
1742 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1743 | + $j++; |
|
1744 | + } |
|
1745 | + break; |
|
1746 | + case 'monthlyByDate': |
|
1747 | + $j = 1; |
|
1748 | + //@todo fix bug with february |
|
1749 | + for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) { |
|
1750 | + $datetimezone = api_get_utc_datetime($i); |
|
1751 | + $this->set_date_time($datetimezone); |
|
1752 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1753 | + $j++; |
|
1754 | + } |
|
1755 | + break; |
|
1756 | + } |
|
1757 | + } |
|
1758 | + |
|
1759 | + /** |
|
1760 | + * Adds x months to a UNIX timestamp |
|
1761 | + * @param int The timestamp |
|
1762 | + * @param int The number of years to add |
|
1763 | + * @return int The new timestamp |
|
1764 | + */ |
|
1765 | + private function add_month($timestamp, $num=1) |
|
1766 | + { |
|
1767 | + $values = api_get_utc_datetime($timestamp); |
|
1768 | + $values = str_replace(array(':','-',' '), '/', $values); |
|
1769 | + list($y, $m, $d, $h, $n, $s) = split('/',$values); |
|
1770 | + if($m+$num>12) { |
|
1771 | + $y += floor($num/12); |
|
1772 | + $m += $num%12; |
|
1773 | + } else { |
|
1774 | + $m += $num; |
|
1775 | + } |
|
1776 | + //date_default_timezone_set('UTC'); |
|
1777 | + // return mktime($h, $n, $s, $m, $d, $y); |
|
1778 | + $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC'); |
|
1779 | + if (!empty($result)) { |
|
1780 | + return $result; |
|
1781 | + } |
|
1782 | + return false; |
|
1783 | + } |
|
1784 | + |
|
1785 | + /** |
|
1786 | + * edit a datetime inside attendance calendar table |
|
1787 | + * @param int attendance calendar id |
|
1788 | + * @param int attendance id |
|
1789 | + * @return int affected rows |
|
1790 | + */ |
|
1791 | + public function attendance_calendar_edit($calendar_id, $attendance_id) |
|
1792 | + { |
|
1793 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1794 | + $affected_rows = 0; |
|
1795 | + $attendance_id = intval($attendance_id); |
|
1796 | + $course_id = api_get_course_int_id(); |
|
1797 | + // check if datetime already exists inside the table |
|
1798 | + $sql = "SELECT id FROM $tbl_attendance_calendar |
|
1799 | 1799 | WHERE |
1800 | 1800 | c_id = $course_id AND |
1801 | 1801 | date_time = '".Database::escape_string($this->date_time)."' AND |
1802 | 1802 | attendance_id = '$attendance_id'"; |
1803 | - $rs = Database::query($sql); |
|
1803 | + $rs = Database::query($sql); |
|
1804 | 1804 | |
1805 | - if (Database::num_rows($rs) == 0) { |
|
1806 | - $sql = "UPDATE $tbl_attendance_calendar |
|
1805 | + if (Database::num_rows($rs) == 0) { |
|
1806 | + $sql = "UPDATE $tbl_attendance_calendar |
|
1807 | 1807 | SET date_time='".Database::escape_string($this->date_time)."' |
1808 | 1808 | WHERE c_id = $course_id AND id = '".intval($calendar_id)."'"; |
1809 | - Database::query($sql); |
|
1810 | - } |
|
1811 | - |
|
1812 | - // update locked attendance |
|
1813 | - $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1814 | - if (!$is_all_calendar_done) { |
|
1815 | - self::lock_attendance($attendance_id, false); |
|
1816 | - } else { |
|
1817 | - self::lock_attendance($attendance_id); |
|
1818 | - } |
|
1819 | - |
|
1820 | - return $affected_rows; |
|
1821 | - } |
|
1822 | - |
|
1823 | - /** |
|
1824 | - * delete a datetime from attendance calendar table |
|
1825 | - * @param int attendance calendar id |
|
1826 | - * @param int attendance id |
|
1827 | - * @param bool true for removing all calendar inside current attendance, false for removing by calendar id |
|
1828 | - * @return int affected rows |
|
1829 | - */ |
|
1830 | - public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false) |
|
1831 | - { |
|
1832 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1833 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1834 | - |
|
1835 | - $attendance_id = intval($attendance_id); |
|
1836 | - // get all registered users inside current course |
|
1837 | - $users = $this->get_users_rel_course(); |
|
1838 | - $user_ids = array_keys($users); |
|
1839 | - $course_id = api_get_course_int_id(); |
|
1840 | - $affected_rows = 0; |
|
1841 | - if ($all_delete) { |
|
1842 | - $attendance_calendar = $this->get_attendance_calendar($attendance_id); |
|
1843 | - // get all dates from calendar by current attendance |
|
1844 | - if (!empty($attendance_calendar)) { |
|
1845 | - foreach ($attendance_calendar as $cal) { |
|
1846 | - // delete all data from attendance sheet |
|
1847 | - $sql = "DELETE FROM $tbl_attendance_sheet |
|
1809 | + Database::query($sql); |
|
1810 | + } |
|
1811 | + |
|
1812 | + // update locked attendance |
|
1813 | + $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1814 | + if (!$is_all_calendar_done) { |
|
1815 | + self::lock_attendance($attendance_id, false); |
|
1816 | + } else { |
|
1817 | + self::lock_attendance($attendance_id); |
|
1818 | + } |
|
1819 | + |
|
1820 | + return $affected_rows; |
|
1821 | + } |
|
1822 | + |
|
1823 | + /** |
|
1824 | + * delete a datetime from attendance calendar table |
|
1825 | + * @param int attendance calendar id |
|
1826 | + * @param int attendance id |
|
1827 | + * @param bool true for removing all calendar inside current attendance, false for removing by calendar id |
|
1828 | + * @return int affected rows |
|
1829 | + */ |
|
1830 | + public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false) |
|
1831 | + { |
|
1832 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1833 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1834 | + |
|
1835 | + $attendance_id = intval($attendance_id); |
|
1836 | + // get all registered users inside current course |
|
1837 | + $users = $this->get_users_rel_course(); |
|
1838 | + $user_ids = array_keys($users); |
|
1839 | + $course_id = api_get_course_int_id(); |
|
1840 | + $affected_rows = 0; |
|
1841 | + if ($all_delete) { |
|
1842 | + $attendance_calendar = $this->get_attendance_calendar($attendance_id); |
|
1843 | + // get all dates from calendar by current attendance |
|
1844 | + if (!empty($attendance_calendar)) { |
|
1845 | + foreach ($attendance_calendar as $cal) { |
|
1846 | + // delete all data from attendance sheet |
|
1847 | + $sql = "DELETE FROM $tbl_attendance_sheet |
|
1848 | 1848 | WHERE c_id = $course_id AND attendance_calendar_id = '".intval($cal['id'])."'"; |
1849 | - Database::query($sql); |
|
1850 | - // delete data from attendance calendar |
|
1851 | - $sql = "DELETE FROM $tbl_attendance_calendar |
|
1849 | + Database::query($sql); |
|
1850 | + // delete data from attendance calendar |
|
1851 | + $sql = "DELETE FROM $tbl_attendance_calendar |
|
1852 | 1852 | WHERE c_id = $course_id AND id = '".intval($cal['id'])."'"; |
1853 | - Database::query($sql); |
|
1854 | - |
|
1855 | - $this->deleteAttendanceCalendarGroup($cal['id'], $course_id); |
|
1856 | - $affected_rows++; |
|
1857 | - } |
|
1858 | - } |
|
1859 | - } else { |
|
1860 | - // delete just one row from attendance sheet by the calendar id |
|
1861 | - $sql = "DELETE FROM $tbl_attendance_sheet |
|
1853 | + Database::query($sql); |
|
1854 | + |
|
1855 | + $this->deleteAttendanceCalendarGroup($cal['id'], $course_id); |
|
1856 | + $affected_rows++; |
|
1857 | + } |
|
1858 | + } |
|
1859 | + } else { |
|
1860 | + // delete just one row from attendance sheet by the calendar id |
|
1861 | + $sql = "DELETE FROM $tbl_attendance_sheet |
|
1862 | 1862 | WHERE c_id = $course_id AND attendance_calendar_id = '".intval($calendar_id)."'"; |
1863 | - Database::query($sql); |
|
1864 | - // delete data from attendance calendar |
|
1865 | - $sql = "DELETE FROM $tbl_attendance_calendar |
|
1863 | + Database::query($sql); |
|
1864 | + // delete data from attendance calendar |
|
1865 | + $sql = "DELETE FROM $tbl_attendance_calendar |
|
1866 | 1866 | WHERE c_id = $course_id AND id = '".intval($calendar_id)."'"; |
1867 | - Database::query($sql); |
|
1868 | - |
|
1869 | - $this->deleteAttendanceCalendarGroup($calendar_id, $course_id); |
|
1870 | - $affected_rows++; |
|
1871 | - } |
|
1872 | - |
|
1873 | - // update users' results |
|
1874 | - $this->update_users_results($user_ids, $attendance_id); |
|
1875 | - |
|
1876 | - return $affected_rows; |
|
1877 | - } |
|
1878 | - |
|
1879 | - /** Setters for fields of attendances tables **/ |
|
1880 | - public function set_session_id($session_id) |
|
1881 | - { |
|
1882 | - $this->session_id = $session_id; |
|
1883 | - } |
|
1884 | - |
|
1885 | - public function set_course_id($course_id) |
|
1886 | - { |
|
1887 | - $this->course_id = $course_id; |
|
1888 | - } |
|
1889 | - |
|
1890 | - public function set_date_time($datetime) |
|
1891 | - { |
|
1892 | - $this->date_time = $datetime; |
|
1893 | - } |
|
1894 | - |
|
1895 | - public function set_name($name) |
|
1896 | - { |
|
1897 | - $this->name = $name; |
|
1898 | - } |
|
1899 | - |
|
1900 | - public function set_description($description) |
|
1901 | - { |
|
1902 | - $this->description = $description; |
|
1903 | - } |
|
1904 | - |
|
1905 | - public function set_attendance_qualify_title($attendance_qualify_title) |
|
1906 | - { |
|
1907 | - $this->attendance_qualify_title = $attendance_qualify_title; |
|
1908 | - } |
|
1909 | - |
|
1910 | - public function set_attendance_weight($attendance_weight) |
|
1911 | - { |
|
1912 | - $this->attendance_weight = $attendance_weight; |
|
1913 | - } |
|
1914 | - |
|
1915 | - /** Getters for fields of attendances tables **/ |
|
1916 | - public function get_session_id() |
|
1917 | - { |
|
1918 | - return $this->session_id; |
|
1919 | - } |
|
1920 | - |
|
1921 | - public function get_course_id() |
|
1922 | - { |
|
1923 | - return $this->course_id; |
|
1924 | - } |
|
1925 | - |
|
1926 | - public function get_date_time() |
|
1927 | - { |
|
1928 | - return $this->date_time; |
|
1929 | - } |
|
1930 | - |
|
1931 | - public function get_name() |
|
1932 | - { |
|
1933 | - return $this->name; |
|
1934 | - } |
|
1935 | - |
|
1936 | - public function get_description() |
|
1937 | - { |
|
1938 | - return $this->description; |
|
1939 | - } |
|
1940 | - |
|
1941 | - public function get_attendance_qualify_title() |
|
1942 | - { |
|
1943 | - return $this->attendance_qualify_title; |
|
1944 | - } |
|
1945 | - |
|
1946 | - public function get_attendance_weight() |
|
1947 | - { |
|
1948 | - return $this->attendance_weight; |
|
1949 | - } |
|
1950 | - |
|
1951 | - /** |
|
1952 | - * @param string $startDate in UTC time |
|
1953 | - * @param string $endDate in UTC time |
|
1954 | - * |
|
1955 | - * @return array |
|
1956 | - */ |
|
1957 | - public function getAttendanceLogin($startDate, $endDate) |
|
1958 | - { |
|
1959 | - if (empty($startDate) || $startDate == '0000-00-00' || |
|
1960 | - empty($endDate) || $endDate == '0000-00-00' |
|
1961 | - ) { |
|
1962 | - return false; |
|
1963 | - } |
|
1964 | - |
|
1965 | - $sessionId = api_get_session_id(); |
|
1966 | - $courseCode = api_get_course_id(); |
|
1967 | - if (!empty($sessionId)) { |
|
1968 | - $users = CourseManager:: get_user_list_from_course_code( |
|
1969 | - $courseCode, |
|
1970 | - $sessionId, |
|
1971 | - '', |
|
1972 | - 'lastname', |
|
1973 | - 0 |
|
1974 | - ); |
|
1975 | - } else { |
|
1976 | - $users = CourseManager:: get_user_list_from_course_code( |
|
1977 | - $courseCode, |
|
1978 | - 0, |
|
1979 | - '', |
|
1980 | - 'lastname', |
|
1981 | - STUDENT |
|
1982 | - ); |
|
1983 | - } |
|
1984 | - |
|
1985 | - $dateTimeStartOriginal = new DateTime($startDate); |
|
1986 | - $dateTimeStart = new DateTime($startDate); |
|
1987 | - $dateTimeEnd= new DateTime($endDate); |
|
1988 | - $interval = $dateTimeStart->diff($dateTimeEnd); |
|
1989 | - $days = intval($interval->format('%a')); |
|
1990 | - |
|
1991 | - $dateList = array($dateTimeStart->format('Y-m-d')); |
|
1992 | - $headers = array( |
|
1993 | - get_lang('User'), |
|
1994 | - $dateTimeStart->format('Y-m-d') |
|
1995 | - ); |
|
1996 | - |
|
1997 | - for ($i = 0; $i < $days; $i++) { |
|
1998 | - $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D')); |
|
1999 | - $date = $dateTimeStart->format('Y-m-d'); |
|
2000 | - $dateList[] = $date; |
|
2001 | - $headers[] = $date; |
|
2002 | - } |
|
2003 | - |
|
2004 | - $accessData = CourseManager::getCourseAccessPerCourseAndSession( |
|
2005 | - $courseCode, |
|
2006 | - $sessionId, |
|
2007 | - $dateTimeStartOriginal->format('Y-m-d H:i:s'), |
|
2008 | - $dateTimeEnd->format('Y-m-d H:i:s') |
|
2009 | - ); |
|
2010 | - |
|
2011 | - $results = array(); |
|
2012 | - if (!empty($accessData)) { |
|
2013 | - foreach ($accessData as $data) { |
|
2014 | - $onlyDate = substr($data['login_course_date'], 0, 10); |
|
2015 | - $results[$data['user_id']][$onlyDate] = true; |
|
2016 | - } |
|
2017 | - } |
|
2018 | - |
|
2019 | - return array( |
|
2020 | - 'users' => $users, |
|
2021 | - 'dateList' => $dateList, |
|
2022 | - 'headers' => $headers, |
|
2023 | - 'results' => $results |
|
2024 | - ); |
|
2025 | - } |
|
2026 | - |
|
2027 | - /** |
|
2028 | - * @param string $startDate in UTC time |
|
2029 | - * @param string $endDate in UTC time |
|
2030 | - * |
|
2031 | - * @return string |
|
2032 | - */ |
|
2033 | - public function getAttendanceLoginTable($startDate, $endDate) |
|
2034 | - { |
|
2035 | - $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2036 | - |
|
2037 | - if (!$data) { |
|
2038 | - return null; |
|
2039 | - } |
|
2040 | - |
|
2041 | - $headers = $data['headers']; |
|
2042 | - $dateList = $data['dateList']; |
|
2043 | - $users = $data['users']; |
|
2044 | - $results = $data['results']; |
|
2045 | - |
|
2046 | - $table = new HTML_Table(array('class' => 'data_table')); |
|
2047 | - $row = 0; |
|
2048 | - $column = 0; |
|
2049 | - foreach ($headers as $header) { |
|
2050 | - $table->setHeaderContents($row, $column, $header); |
|
2051 | - $column++; |
|
2052 | - } |
|
2053 | - $row = 1; |
|
2054 | - foreach ($users as $user) { |
|
2055 | - $table->setCellContents( |
|
2056 | - $row, |
|
2057 | - 0, |
|
2058 | - $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2059 | - ); |
|
2060 | - $row ++; |
|
2061 | - } |
|
2062 | - |
|
2063 | - $column = 1; |
|
2064 | - $row = 1; |
|
2065 | - foreach ($users as $user) { |
|
2066 | - foreach ($dateList as $date) { |
|
2067 | - $status = null; |
|
2068 | - if (isset($results[$user['user_id']]) && |
|
2069 | - isset($results[$user['user_id']][$date]) |
|
2070 | - ) { |
|
2071 | - $status = 'X'; |
|
2072 | - } |
|
2073 | - $table->setCellContents($row, $column, $status); |
|
2074 | - $column++; |
|
2075 | - } |
|
2076 | - $row++; |
|
2077 | - $column = 1; |
|
2078 | - } |
|
2079 | - |
|
2080 | - return $table->toHtml(); |
|
2081 | - } |
|
2082 | - |
|
2083 | - /** |
|
2084 | - * @param string $startDate in UTC time |
|
2085 | - * @param string $endDate in UTC time |
|
2086 | - * |
|
2087 | - * @return string |
|
2088 | - */ |
|
2089 | - public function exportAttendanceLogin($startDate, $endDate) |
|
2090 | - { |
|
2091 | - $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2092 | - |
|
2093 | - if (!$data) { |
|
2094 | - return null; |
|
2095 | - } |
|
2096 | - $users = $data['users']; |
|
2097 | - $results = $data['results']; |
|
2098 | - |
|
2099 | - $table = new HTML_Table(array('class' => 'data_table')); |
|
2100 | - |
|
2101 | - $table->setHeaderContents(0, 0, get_lang('User')); |
|
2102 | - $table->setHeaderContents(0, 1, get_lang('Date')); |
|
2103 | - |
|
2104 | - $row = 1; |
|
2105 | - foreach ($users as $user) { |
|
2106 | - $table->setCellContents( |
|
2107 | - $row, |
|
2108 | - 0, |
|
2109 | - $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2110 | - ); |
|
2111 | - $row++; |
|
2112 | - } |
|
2113 | - $table->setColAttributes(0, array('style' => 'width:28%')); |
|
2114 | - |
|
2115 | - $row = 1; |
|
2116 | - foreach ($users as $user) { |
|
2117 | - if (isset($results[$user['user_id']]) && |
|
2118 | - !empty($results[$user['user_id']]) |
|
2119 | - ) { |
|
2120 | - $dates = implode(', ', array_keys($results[$user['user_id']])); |
|
2121 | - $table->setCellContents($row, 1, $dates); |
|
2122 | - } |
|
2123 | - $row++; |
|
2124 | - } |
|
2125 | - |
|
2126 | - //$tableToString = null; |
|
2127 | - |
|
2128 | - //$sessionInfo = api_get_session_info(api_get_session_id()); |
|
2129 | - //if (!empty($sessionInfo)) { |
|
2130 | - /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '. |
|
1867 | + Database::query($sql); |
|
1868 | + |
|
1869 | + $this->deleteAttendanceCalendarGroup($calendar_id, $course_id); |
|
1870 | + $affected_rows++; |
|
1871 | + } |
|
1872 | + |
|
1873 | + // update users' results |
|
1874 | + $this->update_users_results($user_ids, $attendance_id); |
|
1875 | + |
|
1876 | + return $affected_rows; |
|
1877 | + } |
|
1878 | + |
|
1879 | + /** Setters for fields of attendances tables **/ |
|
1880 | + public function set_session_id($session_id) |
|
1881 | + { |
|
1882 | + $this->session_id = $session_id; |
|
1883 | + } |
|
1884 | + |
|
1885 | + public function set_course_id($course_id) |
|
1886 | + { |
|
1887 | + $this->course_id = $course_id; |
|
1888 | + } |
|
1889 | + |
|
1890 | + public function set_date_time($datetime) |
|
1891 | + { |
|
1892 | + $this->date_time = $datetime; |
|
1893 | + } |
|
1894 | + |
|
1895 | + public function set_name($name) |
|
1896 | + { |
|
1897 | + $this->name = $name; |
|
1898 | + } |
|
1899 | + |
|
1900 | + public function set_description($description) |
|
1901 | + { |
|
1902 | + $this->description = $description; |
|
1903 | + } |
|
1904 | + |
|
1905 | + public function set_attendance_qualify_title($attendance_qualify_title) |
|
1906 | + { |
|
1907 | + $this->attendance_qualify_title = $attendance_qualify_title; |
|
1908 | + } |
|
1909 | + |
|
1910 | + public function set_attendance_weight($attendance_weight) |
|
1911 | + { |
|
1912 | + $this->attendance_weight = $attendance_weight; |
|
1913 | + } |
|
1914 | + |
|
1915 | + /** Getters for fields of attendances tables **/ |
|
1916 | + public function get_session_id() |
|
1917 | + { |
|
1918 | + return $this->session_id; |
|
1919 | + } |
|
1920 | + |
|
1921 | + public function get_course_id() |
|
1922 | + { |
|
1923 | + return $this->course_id; |
|
1924 | + } |
|
1925 | + |
|
1926 | + public function get_date_time() |
|
1927 | + { |
|
1928 | + return $this->date_time; |
|
1929 | + } |
|
1930 | + |
|
1931 | + public function get_name() |
|
1932 | + { |
|
1933 | + return $this->name; |
|
1934 | + } |
|
1935 | + |
|
1936 | + public function get_description() |
|
1937 | + { |
|
1938 | + return $this->description; |
|
1939 | + } |
|
1940 | + |
|
1941 | + public function get_attendance_qualify_title() |
|
1942 | + { |
|
1943 | + return $this->attendance_qualify_title; |
|
1944 | + } |
|
1945 | + |
|
1946 | + public function get_attendance_weight() |
|
1947 | + { |
|
1948 | + return $this->attendance_weight; |
|
1949 | + } |
|
1950 | + |
|
1951 | + /** |
|
1952 | + * @param string $startDate in UTC time |
|
1953 | + * @param string $endDate in UTC time |
|
1954 | + * |
|
1955 | + * @return array |
|
1956 | + */ |
|
1957 | + public function getAttendanceLogin($startDate, $endDate) |
|
1958 | + { |
|
1959 | + if (empty($startDate) || $startDate == '0000-00-00' || |
|
1960 | + empty($endDate) || $endDate == '0000-00-00' |
|
1961 | + ) { |
|
1962 | + return false; |
|
1963 | + } |
|
1964 | + |
|
1965 | + $sessionId = api_get_session_id(); |
|
1966 | + $courseCode = api_get_course_id(); |
|
1967 | + if (!empty($sessionId)) { |
|
1968 | + $users = CourseManager:: get_user_list_from_course_code( |
|
1969 | + $courseCode, |
|
1970 | + $sessionId, |
|
1971 | + '', |
|
1972 | + 'lastname', |
|
1973 | + 0 |
|
1974 | + ); |
|
1975 | + } else { |
|
1976 | + $users = CourseManager:: get_user_list_from_course_code( |
|
1977 | + $courseCode, |
|
1978 | + 0, |
|
1979 | + '', |
|
1980 | + 'lastname', |
|
1981 | + STUDENT |
|
1982 | + ); |
|
1983 | + } |
|
1984 | + |
|
1985 | + $dateTimeStartOriginal = new DateTime($startDate); |
|
1986 | + $dateTimeStart = new DateTime($startDate); |
|
1987 | + $dateTimeEnd= new DateTime($endDate); |
|
1988 | + $interval = $dateTimeStart->diff($dateTimeEnd); |
|
1989 | + $days = intval($interval->format('%a')); |
|
1990 | + |
|
1991 | + $dateList = array($dateTimeStart->format('Y-m-d')); |
|
1992 | + $headers = array( |
|
1993 | + get_lang('User'), |
|
1994 | + $dateTimeStart->format('Y-m-d') |
|
1995 | + ); |
|
1996 | + |
|
1997 | + for ($i = 0; $i < $days; $i++) { |
|
1998 | + $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D')); |
|
1999 | + $date = $dateTimeStart->format('Y-m-d'); |
|
2000 | + $dateList[] = $date; |
|
2001 | + $headers[] = $date; |
|
2002 | + } |
|
2003 | + |
|
2004 | + $accessData = CourseManager::getCourseAccessPerCourseAndSession( |
|
2005 | + $courseCode, |
|
2006 | + $sessionId, |
|
2007 | + $dateTimeStartOriginal->format('Y-m-d H:i:s'), |
|
2008 | + $dateTimeEnd->format('Y-m-d H:i:s') |
|
2009 | + ); |
|
2010 | + |
|
2011 | + $results = array(); |
|
2012 | + if (!empty($accessData)) { |
|
2013 | + foreach ($accessData as $data) { |
|
2014 | + $onlyDate = substr($data['login_course_date'], 0, 10); |
|
2015 | + $results[$data['user_id']][$onlyDate] = true; |
|
2016 | + } |
|
2017 | + } |
|
2018 | + |
|
2019 | + return array( |
|
2020 | + 'users' => $users, |
|
2021 | + 'dateList' => $dateList, |
|
2022 | + 'headers' => $headers, |
|
2023 | + 'results' => $results |
|
2024 | + ); |
|
2025 | + } |
|
2026 | + |
|
2027 | + /** |
|
2028 | + * @param string $startDate in UTC time |
|
2029 | + * @param string $endDate in UTC time |
|
2030 | + * |
|
2031 | + * @return string |
|
2032 | + */ |
|
2033 | + public function getAttendanceLoginTable($startDate, $endDate) |
|
2034 | + { |
|
2035 | + $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2036 | + |
|
2037 | + if (!$data) { |
|
2038 | + return null; |
|
2039 | + } |
|
2040 | + |
|
2041 | + $headers = $data['headers']; |
|
2042 | + $dateList = $data['dateList']; |
|
2043 | + $users = $data['users']; |
|
2044 | + $results = $data['results']; |
|
2045 | + |
|
2046 | + $table = new HTML_Table(array('class' => 'data_table')); |
|
2047 | + $row = 0; |
|
2048 | + $column = 0; |
|
2049 | + foreach ($headers as $header) { |
|
2050 | + $table->setHeaderContents($row, $column, $header); |
|
2051 | + $column++; |
|
2052 | + } |
|
2053 | + $row = 1; |
|
2054 | + foreach ($users as $user) { |
|
2055 | + $table->setCellContents( |
|
2056 | + $row, |
|
2057 | + 0, |
|
2058 | + $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2059 | + ); |
|
2060 | + $row ++; |
|
2061 | + } |
|
2062 | + |
|
2063 | + $column = 1; |
|
2064 | + $row = 1; |
|
2065 | + foreach ($users as $user) { |
|
2066 | + foreach ($dateList as $date) { |
|
2067 | + $status = null; |
|
2068 | + if (isset($results[$user['user_id']]) && |
|
2069 | + isset($results[$user['user_id']][$date]) |
|
2070 | + ) { |
|
2071 | + $status = 'X'; |
|
2072 | + } |
|
2073 | + $table->setCellContents($row, $column, $status); |
|
2074 | + $column++; |
|
2075 | + } |
|
2076 | + $row++; |
|
2077 | + $column = 1; |
|
2078 | + } |
|
2079 | + |
|
2080 | + return $table->toHtml(); |
|
2081 | + } |
|
2082 | + |
|
2083 | + /** |
|
2084 | + * @param string $startDate in UTC time |
|
2085 | + * @param string $endDate in UTC time |
|
2086 | + * |
|
2087 | + * @return string |
|
2088 | + */ |
|
2089 | + public function exportAttendanceLogin($startDate, $endDate) |
|
2090 | + { |
|
2091 | + $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2092 | + |
|
2093 | + if (!$data) { |
|
2094 | + return null; |
|
2095 | + } |
|
2096 | + $users = $data['users']; |
|
2097 | + $results = $data['results']; |
|
2098 | + |
|
2099 | + $table = new HTML_Table(array('class' => 'data_table')); |
|
2100 | + |
|
2101 | + $table->setHeaderContents(0, 0, get_lang('User')); |
|
2102 | + $table->setHeaderContents(0, 1, get_lang('Date')); |
|
2103 | + |
|
2104 | + $row = 1; |
|
2105 | + foreach ($users as $user) { |
|
2106 | + $table->setCellContents( |
|
2107 | + $row, |
|
2108 | + 0, |
|
2109 | + $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2110 | + ); |
|
2111 | + $row++; |
|
2112 | + } |
|
2113 | + $table->setColAttributes(0, array('style' => 'width:28%')); |
|
2114 | + |
|
2115 | + $row = 1; |
|
2116 | + foreach ($users as $user) { |
|
2117 | + if (isset($results[$user['user_id']]) && |
|
2118 | + !empty($results[$user['user_id']]) |
|
2119 | + ) { |
|
2120 | + $dates = implode(', ', array_keys($results[$user['user_id']])); |
|
2121 | + $table->setCellContents($row, 1, $dates); |
|
2122 | + } |
|
2123 | + $row++; |
|
2124 | + } |
|
2125 | + |
|
2126 | + //$tableToString = null; |
|
2127 | + |
|
2128 | + //$sessionInfo = api_get_session_info(api_get_session_id()); |
|
2129 | + //if (!empty($sessionInfo)) { |
|
2130 | + /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '. |
|
2131 | 2131 | sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);*/ |
2132 | - //} |
|
2133 | - |
|
2134 | - $tableToString = $table->toHtml(); |
|
2135 | - |
|
2136 | - $params = array( |
|
2137 | - 'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(), |
|
2138 | - 'pdf_title' => get_lang('Attendance'), |
|
2139 | - 'course_code' => api_get_course_id(), |
|
2140 | - 'show_real_course_teachers' => true |
|
2141 | - ); |
|
2142 | - $pdf = new PDF('A4', null, $params); |
|
2143 | - $pdf->html_to_pdf_with_template($tableToString); |
|
2144 | - } |
|
2132 | + //} |
|
2133 | + |
|
2134 | + $tableToString = $table->toHtml(); |
|
2135 | + |
|
2136 | + $params = array( |
|
2137 | + 'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(), |
|
2138 | + 'pdf_title' => get_lang('Attendance'), |
|
2139 | + 'course_code' => api_get_course_id(), |
|
2140 | + 'show_real_course_teachers' => true |
|
2141 | + ); |
|
2142 | + $pdf = new PDF('A4', null, $params); |
|
2143 | + $pdf->html_to_pdf_with_template($tableToString); |
|
2144 | + } |
|
2145 | 2145 | } |
@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Project: MagpieRSS: a simple RSS integration tool |
|
4 | - * File: rss_fetch.inc, a simple functional interface |
|
3 | + * Project: MagpieRSS: a simple RSS integration tool |
|
4 | + * File: rss_fetch.inc, a simple functional interface |
|
5 | 5 | to fetching and parsing RSS files, via the |
6 | 6 | function fetch_rss() |
7 | - * Author: Kellan Elliott-McCrea <[email protected]> |
|
8 | - * License: GPL |
|
9 | - * |
|
10 | - * The lastest version of MagpieRSS can be obtained from: |
|
11 | - * http://magpierss.sourceforge.net |
|
12 | - * |
|
13 | - * For questions, help, comments, discussion, etc., please join the |
|
14 | - * Magpie mailing list: |
|
15 | - * [email protected] |
|
16 | - * @package chamilo.include.rss |
|
17 | - */ |
|
7 | + * Author: Kellan Elliott-McCrea <[email protected]> |
|
8 | + * License: GPL |
|
9 | + * |
|
10 | + * The lastest version of MagpieRSS can be obtained from: |
|
11 | + * http://magpierss.sourceforge.net |
|
12 | + * |
|
13 | + * For questions, help, comments, discussion, etc., please join the |
|
14 | + * Magpie mailing list: |
|
15 | + * [email protected] |
|
16 | + * @package chamilo.include.rss |
|
17 | + */ |
|
18 | 18 | /** |
19 | - * Code |
|
20 | - */ |
|
19 | + * Code |
|
20 | + */ |
|
21 | 21 | // Setup MAGPIE_DIR for use on hosts that don't include |
22 | 22 | // the current path in include_path. |
23 | 23 | // with thanks to rajiv and smarty |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $resp = _fetch_remote_file( $url, $request_headers ); |
165 | 165 | |
166 | 166 | if (isset($resp) and $resp) { |
167 | - if ($resp->status == '304' ) { |
|
167 | + if ($resp->status == '304' ) { |
|
168 | 168 | // we have the most current copy |
169 | 169 | if ( MAGPIE_DEBUG > 1) { |
170 | 170 | debug("Got 304 for $url"); |
@@ -36,81 +36,81 @@ discard block |
||
36 | 36 | *************************************************/ |
37 | 37 | |
38 | 38 | class Snoopy { |
39 | - /**** Public variables ****/ |
|
39 | + /**** Public variables ****/ |
|
40 | 40 | |
41 | - /* user definable vars */ |
|
42 | - |
|
43 | - public $host = "www.php.net"; // host name we are connecting to |
|
44 | - public $port = 80; // port we are connecting to |
|
45 | - public $proxy_host = ""; // proxy host to use |
|
46 | - public $proxy_port = ""; // proxy port to use |
|
47 | - public $agent = "Snoopy v1.0"; // agent we masquerade as |
|
48 | - public $referer = ""; // referer info to pass |
|
49 | - public $cookies = array(); // array of cookies to pass |
|
50 | - // $cookies["username"]="joe"; |
|
51 | - public $rawheaders = array(); // array of raw headers to send |
|
52 | - // $rawheaders["Content-type"]="text/html"; |
|
53 | - |
|
54 | - public $maxredirs = 5; // http redirection depth maximum. 0 = disallow |
|
55 | - public $lastredirectaddr = ""; // contains address of last redirected address |
|
56 | - public $offsiteok = true; // allows redirection off-site |
|
57 | - public $maxframes = 0; // frame content depth maximum. 0 = disallow |
|
58 | - public $expandlinks = true; // expand links to fully qualified URLs. |
|
59 | - // this only applies to fetchlinks() |
|
60 | - // or submitlinks() |
|
61 | - public $passcookies = true; // pass set cookies back through redirects |
|
62 | - // NOTE: this currently does not respect |
|
63 | - // dates, domains or paths. |
|
41 | + /* user definable vars */ |
|
42 | + |
|
43 | + public $host = "www.php.net"; // host name we are connecting to |
|
44 | + public $port = 80; // port we are connecting to |
|
45 | + public $proxy_host = ""; // proxy host to use |
|
46 | + public $proxy_port = ""; // proxy port to use |
|
47 | + public $agent = "Snoopy v1.0"; // agent we masquerade as |
|
48 | + public $referer = ""; // referer info to pass |
|
49 | + public $cookies = array(); // array of cookies to pass |
|
50 | + // $cookies["username"]="joe"; |
|
51 | + public $rawheaders = array(); // array of raw headers to send |
|
52 | + // $rawheaders["Content-type"]="text/html"; |
|
53 | + |
|
54 | + public $maxredirs = 5; // http redirection depth maximum. 0 = disallow |
|
55 | + public $lastredirectaddr = ""; // contains address of last redirected address |
|
56 | + public $offsiteok = true; // allows redirection off-site |
|
57 | + public $maxframes = 0; // frame content depth maximum. 0 = disallow |
|
58 | + public $expandlinks = true; // expand links to fully qualified URLs. |
|
59 | + // this only applies to fetchlinks() |
|
60 | + // or submitlinks() |
|
61 | + public $passcookies = true; // pass set cookies back through redirects |
|
62 | + // NOTE: this currently does not respect |
|
63 | + // dates, domains or paths. |
|
64 | 64 | |
65 | - public $user = ""; // user for http authentication |
|
66 | - public $pass = ""; // password for http authentication |
|
65 | + public $user = ""; // user for http authentication |
|
66 | + public $pass = ""; // password for http authentication |
|
67 | 67 | |
68 | - // http accept types |
|
69 | - public $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
68 | + // http accept types |
|
69 | + public $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
70 | 70 | |
71 | - public $results = ""; // where the content is put |
|
71 | + public $results = ""; // where the content is put |
|
72 | 72 | |
73 | - public $error = ""; // error messages sent here |
|
74 | - public $response_code = ""; // response code returned from server |
|
75 | - public $headers = array(); // headers returned from server sent here |
|
76 | - public $maxlength = 500000; // max return data length (body) |
|
77 | - public $read_timeout = 0; // timeout on read operations, in seconds |
|
78 | - // supported only since PHP 4 Beta 4 |
|
79 | - // set to 0 to disallow timeouts |
|
80 | - public $timed_out = false; // if a read operation timed out |
|
81 | - public $status = 0; // http request status |
|
73 | + public $error = ""; // error messages sent here |
|
74 | + public $response_code = ""; // response code returned from server |
|
75 | + public $headers = array(); // headers returned from server sent here |
|
76 | + public $maxlength = 500000; // max return data length (body) |
|
77 | + public $read_timeout = 0; // timeout on read operations, in seconds |
|
78 | + // supported only since PHP 4 Beta 4 |
|
79 | + // set to 0 to disallow timeouts |
|
80 | + public $timed_out = false; // if a read operation timed out |
|
81 | + public $status = 0; // http request status |
|
82 | 82 | |
83 | - public $curl_path = "/usr/bin/curl"; |
|
84 | - // Snoopy will use cURL for fetching |
|
85 | - // SSL content if a full system path to |
|
86 | - // the cURL binary is supplied here. |
|
87 | - // set to false if you do not have |
|
88 | - // cURL installed. See http://curl.haxx.se |
|
89 | - // for details on installing cURL. |
|
90 | - // Snoopy does *not* use the cURL |
|
91 | - // library functions built into php, |
|
92 | - // as these functions are not stable |
|
93 | - // as of this Snoopy release. |
|
83 | + public $curl_path = "/usr/bin/curl"; |
|
84 | + // Snoopy will use cURL for fetching |
|
85 | + // SSL content if a full system path to |
|
86 | + // the cURL binary is supplied here. |
|
87 | + // set to false if you do not have |
|
88 | + // cURL installed. See http://curl.haxx.se |
|
89 | + // for details on installing cURL. |
|
90 | + // Snoopy does *not* use the cURL |
|
91 | + // library functions built into php, |
|
92 | + // as these functions are not stable |
|
93 | + // as of this Snoopy release. |
|
94 | 94 | |
95 | - // send Accept-encoding: gzip? |
|
96 | - public $use_gzip = true; |
|
95 | + // send Accept-encoding: gzip? |
|
96 | + public $use_gzip = true; |
|
97 | 97 | |
98 | - /**** Private variables ****/ |
|
98 | + /**** Private variables ****/ |
|
99 | 99 | |
100 | - private $_maxlinelen = 4096; // max line length (headers) |
|
100 | + private $_maxlinelen = 4096; // max line length (headers) |
|
101 | 101 | |
102 | - private $_httpmethod = "GET"; // default http request method |
|
103 | - private $_httpversion = "HTTP/1.0"; // default http request version |
|
104 | - private $_submit_method = "POST"; // default submit method |
|
105 | - private $_submit_type = "application/x-www-form-urlencoded"; // default submit type |
|
106 | - private $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type |
|
107 | - private $_redirectaddr = false; // will be set if page fetched is a redirect |
|
108 | - private $_redirectdepth = 0; // increments on an http redirect |
|
109 | - private $_frameurls = array(); // frame src urls |
|
110 | - private $_framedepth = 0; // increments on frame depth |
|
102 | + private $_httpmethod = "GET"; // default http request method |
|
103 | + private $_httpversion = "HTTP/1.0"; // default http request version |
|
104 | + private $_submit_method = "POST"; // default submit method |
|
105 | + private $_submit_type = "application/x-www-form-urlencoded"; // default submit type |
|
106 | + private $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type |
|
107 | + private $_redirectaddr = false; // will be set if page fetched is a redirect |
|
108 | + private $_redirectdepth = 0; // increments on an http redirect |
|
109 | + private $_frameurls = array(); // frame src urls |
|
110 | + private $_framedepth = 0; // increments on frame depth |
|
111 | 111 | |
112 | - private $_isproxy = false; // set if using a proxy server |
|
113 | - private $_fp_timeout = 30; // timeout for socket connection |
|
112 | + private $_isproxy = false; // set if using a proxy server |
|
113 | + private $_fp_timeout = 30; // timeout for socket connection |
|
114 | 114 | |
115 | 115 | /*======================================================================*\ |
116 | 116 | Function: fetch |
@@ -121,136 +121,136 @@ discard block |
||
121 | 121 | Output: $this->results the output text from the fetch |
122 | 122 | \*======================================================================*/ |
123 | 123 | |
124 | - public function fetch($URI) { |
|
125 | - //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
|
126 | - $URI_PARTS = parse_url($URI); |
|
127 | - if (!empty($URI_PARTS["user"])) |
|
128 | - $this->user = $URI_PARTS["user"]; |
|
129 | - if (!empty($URI_PARTS["pass"])) |
|
130 | - $this->pass = $URI_PARTS["pass"]; |
|
131 | - if (!isset($fp)) { $fp = false; } |
|
132 | - switch ($URI_PARTS["scheme"]) { |
|
133 | - case "http": |
|
134 | - $this->host = $URI_PARTS["host"]; |
|
135 | - if(!empty($URI_PARTS["port"])) |
|
136 | - $this->port = $URI_PARTS["port"]; |
|
137 | - if($this->_connect($fp)) |
|
138 | - { |
|
139 | - if($this->_isproxy) |
|
140 | - { |
|
141 | - // using proxy, send entire URI |
|
142 | - $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|
143 | - } |
|
144 | - else |
|
145 | - { |
|
146 | - $path = $URI_PARTS["path"].(isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : ""); |
|
147 | - // no proxy, send only the path |
|
148 | - $this->_httprequest($path, $fp, $URI, $this->_httpmethod); |
|
149 | - } |
|
124 | + public function fetch($URI) { |
|
125 | + //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
|
126 | + $URI_PARTS = parse_url($URI); |
|
127 | + if (!empty($URI_PARTS["user"])) |
|
128 | + $this->user = $URI_PARTS["user"]; |
|
129 | + if (!empty($URI_PARTS["pass"])) |
|
130 | + $this->pass = $URI_PARTS["pass"]; |
|
131 | + if (!isset($fp)) { $fp = false; } |
|
132 | + switch ($URI_PARTS["scheme"]) { |
|
133 | + case "http": |
|
134 | + $this->host = $URI_PARTS["host"]; |
|
135 | + if(!empty($URI_PARTS["port"])) |
|
136 | + $this->port = $URI_PARTS["port"]; |
|
137 | + if($this->_connect($fp)) |
|
138 | + { |
|
139 | + if($this->_isproxy) |
|
140 | + { |
|
141 | + // using proxy, send entire URI |
|
142 | + $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|
143 | + } |
|
144 | + else |
|
145 | + { |
|
146 | + $path = $URI_PARTS["path"].(isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : ""); |
|
147 | + // no proxy, send only the path |
|
148 | + $this->_httprequest($path, $fp, $URI, $this->_httpmethod); |
|
149 | + } |
|
150 | 150 | |
151 | - $this->_disconnect($fp); |
|
152 | - |
|
153 | - if($this->_redirectaddr) |
|
154 | - { |
|
155 | - /* url was redirected, check if we've hit the max depth */ |
|
156 | - if($this->maxredirs > $this->_redirectdepth) |
|
157 | - { |
|
158 | - // only follow redirect if it's on this site, or offsiteok is true |
|
159 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
160 | - { |
|
161 | - /* follow the redirect */ |
|
162 | - $this->_redirectdepth++; |
|
163 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
164 | - $this->fetch($this->_redirectaddr); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
170 | - { |
|
171 | - $frameurls = $this->_frameurls; |
|
172 | - $this->_frameurls = array(); |
|
151 | + $this->_disconnect($fp); |
|
152 | + |
|
153 | + if($this->_redirectaddr) |
|
154 | + { |
|
155 | + /* url was redirected, check if we've hit the max depth */ |
|
156 | + if($this->maxredirs > $this->_redirectdepth) |
|
157 | + { |
|
158 | + // only follow redirect if it's on this site, or offsiteok is true |
|
159 | + if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
160 | + { |
|
161 | + /* follow the redirect */ |
|
162 | + $this->_redirectdepth++; |
|
163 | + $this->lastredirectaddr=$this->_redirectaddr; |
|
164 | + $this->fetch($this->_redirectaddr); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
170 | + { |
|
171 | + $frameurls = $this->_frameurls; |
|
172 | + $this->_frameurls = array(); |
|
173 | 173 | |
174 | - while(list(,$frameurl) = each($frameurls)) |
|
175 | - { |
|
176 | - if($this->_framedepth < $this->maxframes) |
|
177 | - { |
|
178 | - $this->fetch($frameurl); |
|
179 | - $this->_framedepth++; |
|
180 | - } |
|
181 | - else |
|
182 | - break; |
|
183 | - } |
|
184 | - } |
|
185 | - } |
|
186 | - else |
|
187 | - { |
|
188 | - return false; |
|
189 | - } |
|
190 | - return true; |
|
191 | - break; |
|
192 | - case "https": |
|
193 | - if(!$this->curl_path || (!is_executable($this->curl_path))) { |
|
194 | - $this->error = "Bad curl ($this->curl_path), can't fetch HTTPS \n"; |
|
195 | - return false; |
|
196 | - } |
|
197 | - $this->host = $URI_PARTS["host"]; |
|
198 | - if(!empty($URI_PARTS["port"])) |
|
199 | - $this->port = $URI_PARTS["port"]; |
|
200 | - if($this->_isproxy) |
|
201 | - { |
|
202 | - // using proxy, send entire URI |
|
203 | - $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|
204 | - } |
|
205 | - else |
|
206 | - { |
|
207 | - $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|
208 | - // no proxy, send only the path |
|
209 | - $this->_httpsrequest($path, $URI, $this->_httpmethod); |
|
210 | - } |
|
211 | - |
|
212 | - if($this->_redirectaddr) |
|
213 | - { |
|
214 | - /* url was redirected, check if we've hit the max depth */ |
|
215 | - if($this->maxredirs > $this->_redirectdepth) |
|
216 | - { |
|
217 | - // only follow redirect if it's on this site, or offsiteok is true |
|
218 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
219 | - { |
|
220 | - /* follow the redirect */ |
|
221 | - $this->_redirectdepth++; |
|
222 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
223 | - $this->fetch($this->_redirectaddr); |
|
224 | - } |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
229 | - { |
|
230 | - $frameurls = $this->_frameurls; |
|
231 | - $this->_frameurls = array(); |
|
232 | - |
|
233 | - while(list(,$frameurl) = each($frameurls)) |
|
234 | - { |
|
235 | - if($this->_framedepth < $this->maxframes) |
|
236 | - { |
|
237 | - $this->fetch($frameurl); |
|
238 | - $this->_framedepth++; |
|
239 | - } |
|
240 | - else |
|
241 | - break; |
|
242 | - } |
|
243 | - } |
|
244 | - return true; |
|
245 | - break; |
|
246 | - default: |
|
247 | - // not a valid protocol |
|
248 | - $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
249 | - return false; |
|
250 | - break; |
|
251 | - } |
|
252 | - return true; |
|
253 | - } |
|
174 | + while(list(,$frameurl) = each($frameurls)) |
|
175 | + { |
|
176 | + if($this->_framedepth < $this->maxframes) |
|
177 | + { |
|
178 | + $this->fetch($frameurl); |
|
179 | + $this->_framedepth++; |
|
180 | + } |
|
181 | + else |
|
182 | + break; |
|
183 | + } |
|
184 | + } |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
188 | + return false; |
|
189 | + } |
|
190 | + return true; |
|
191 | + break; |
|
192 | + case "https": |
|
193 | + if(!$this->curl_path || (!is_executable($this->curl_path))) { |
|
194 | + $this->error = "Bad curl ($this->curl_path), can't fetch HTTPS \n"; |
|
195 | + return false; |
|
196 | + } |
|
197 | + $this->host = $URI_PARTS["host"]; |
|
198 | + if(!empty($URI_PARTS["port"])) |
|
199 | + $this->port = $URI_PARTS["port"]; |
|
200 | + if($this->_isproxy) |
|
201 | + { |
|
202 | + // using proxy, send entire URI |
|
203 | + $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|
204 | + } |
|
205 | + else |
|
206 | + { |
|
207 | + $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|
208 | + // no proxy, send only the path |
|
209 | + $this->_httpsrequest($path, $URI, $this->_httpmethod); |
|
210 | + } |
|
211 | + |
|
212 | + if($this->_redirectaddr) |
|
213 | + { |
|
214 | + /* url was redirected, check if we've hit the max depth */ |
|
215 | + if($this->maxredirs > $this->_redirectdepth) |
|
216 | + { |
|
217 | + // only follow redirect if it's on this site, or offsiteok is true |
|
218 | + if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
219 | + { |
|
220 | + /* follow the redirect */ |
|
221 | + $this->_redirectdepth++; |
|
222 | + $this->lastredirectaddr=$this->_redirectaddr; |
|
223 | + $this->fetch($this->_redirectaddr); |
|
224 | + } |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
229 | + { |
|
230 | + $frameurls = $this->_frameurls; |
|
231 | + $this->_frameurls = array(); |
|
232 | + |
|
233 | + while(list(,$frameurl) = each($frameurls)) |
|
234 | + { |
|
235 | + if($this->_framedepth < $this->maxframes) |
|
236 | + { |
|
237 | + $this->fetch($frameurl); |
|
238 | + $this->_framedepth++; |
|
239 | + } |
|
240 | + else |
|
241 | + break; |
|
242 | + } |
|
243 | + } |
|
244 | + return true; |
|
245 | + break; |
|
246 | + default: |
|
247 | + // not a valid protocol |
|
248 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
249 | + return false; |
|
250 | + break; |
|
251 | + } |
|
252 | + return true; |
|
253 | + } |
|
254 | 254 | |
255 | 255 | |
256 | 256 | |
@@ -266,32 +266,32 @@ discard block |
||
266 | 266 | Output: $match an array of the links |
267 | 267 | \*======================================================================*/ |
268 | 268 | |
269 | - private function _striplinks($document) |
|
270 | - { |
|
271 | - preg_match_all("'<\s*a\s+.*href\s*=\s* # find <a href= |
|
269 | + private function _striplinks($document) |
|
270 | + { |
|
271 | + preg_match_all("'<\s*a\s+.*href\s*=\s* # find <a href= |
|
272 | 272 | ([\"\'])? # find single or double quote |
273 | 273 | (?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching |
274 | 274 | # quote, otherwise match up to next space |
275 | 275 | 'isx",$document,$links); |
276 | 276 | |
277 | 277 | |
278 | - // catenate the non-empty matches from the conditional subpattern |
|
278 | + // catenate the non-empty matches from the conditional subpattern |
|
279 | 279 | |
280 | - while(list($key,$val) = each($links[2])) |
|
281 | - { |
|
282 | - if(!empty($val)) |
|
283 | - $match[] = $val; |
|
284 | - } |
|
280 | + while(list($key,$val) = each($links[2])) |
|
281 | + { |
|
282 | + if(!empty($val)) |
|
283 | + $match[] = $val; |
|
284 | + } |
|
285 | 285 | |
286 | - while(list($key,$val) = each($links[3])) |
|
287 | - { |
|
288 | - if(!empty($val)) |
|
289 | - $match[] = $val; |
|
290 | - } |
|
286 | + while(list($key,$val) = each($links[3])) |
|
287 | + { |
|
288 | + if(!empty($val)) |
|
289 | + $match[] = $val; |
|
290 | + } |
|
291 | 291 | |
292 | - // return the links |
|
293 | - return $match; |
|
294 | - } |
|
292 | + // return the links |
|
293 | + return $match; |
|
294 | + } |
|
295 | 295 | |
296 | 296 | /*======================================================================*\ |
297 | 297 | Function: _stripform |
@@ -300,16 +300,16 @@ discard block |
||
300 | 300 | Output: $match an array of the links |
301 | 301 | \*======================================================================*/ |
302 | 302 | |
303 | - private function _stripform($document) |
|
304 | - { |
|
305 | - preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); |
|
303 | + private function _stripform($document) |
|
304 | + { |
|
305 | + preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); |
|
306 | 306 | |
307 | - // catenate the matches |
|
308 | - $match = implode("\r\n",$elements[0]); |
|
307 | + // catenate the matches |
|
308 | + $match = implode("\r\n",$elements[0]); |
|
309 | 309 | |
310 | - // return the links |
|
311 | - return $match; |
|
312 | - } |
|
310 | + // return the links |
|
311 | + return $match; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | |
315 | 315 | |
@@ -320,43 +320,43 @@ discard block |
||
320 | 320 | Output: $text the resulting text |
321 | 321 | \*======================================================================*/ |
322 | 322 | |
323 | - private function _striptext($document) |
|
324 | - { |
|
323 | + private function _striptext($document) |
|
324 | + { |
|
325 | 325 | |
326 | - // I didn't use preg eval (//e) since that is only available in PHP 4.0. |
|
327 | - // so, list your entities one by one here. I included some of the |
|
328 | - // more common ones. |
|
326 | + // I didn't use preg eval (//e) since that is only available in PHP 4.0. |
|
327 | + // so, list your entities one by one here. I included some of the |
|
328 | + // more common ones. |
|
329 | 329 | |
330 | - $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript |
|
331 | - "'<[\/\!]*?[^<>]*?>'si", // strip out html tags |
|
332 | - "'([\r\n])[\s]+'", // strip out white space |
|
333 | - "'&(quote|#34);'i", // replace html entities |
|
334 | - "'&(amp|#38);'i", |
|
335 | - "'&(lt|#60);'i", |
|
336 | - "'&(gt|#62);'i", |
|
337 | - "'&(nbsp|#160);'i", |
|
338 | - "'&(iexcl|#161);'i", |
|
339 | - "'&(cent|#162);'i", |
|
340 | - "'&(pound|#163);'i", |
|
341 | - "'&(copy|#169);'i" |
|
342 | - ); |
|
343 | - $replace = array( "", |
|
344 | - "", |
|
345 | - "\\1", |
|
346 | - "\"", |
|
347 | - "&", |
|
348 | - "<", |
|
349 | - ">", |
|
350 | - " ", |
|
351 | - chr(161), |
|
352 | - chr(162), |
|
353 | - chr(163), |
|
354 | - chr(169)); |
|
330 | + $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript |
|
331 | + "'<[\/\!]*?[^<>]*?>'si", // strip out html tags |
|
332 | + "'([\r\n])[\s]+'", // strip out white space |
|
333 | + "'&(quote|#34);'i", // replace html entities |
|
334 | + "'&(amp|#38);'i", |
|
335 | + "'&(lt|#60);'i", |
|
336 | + "'&(gt|#62);'i", |
|
337 | + "'&(nbsp|#160);'i", |
|
338 | + "'&(iexcl|#161);'i", |
|
339 | + "'&(cent|#162);'i", |
|
340 | + "'&(pound|#163);'i", |
|
341 | + "'&(copy|#169);'i" |
|
342 | + ); |
|
343 | + $replace = array( "", |
|
344 | + "", |
|
345 | + "\\1", |
|
346 | + "\"", |
|
347 | + "&", |
|
348 | + "<", |
|
349 | + ">", |
|
350 | + " ", |
|
351 | + chr(161), |
|
352 | + chr(162), |
|
353 | + chr(163), |
|
354 | + chr(169)); |
|
355 | 355 | |
356 | - $text = preg_replace($search,$replace,$document); |
|
356 | + $text = preg_replace($search,$replace,$document); |
|
357 | 357 | |
358 | - return $text; |
|
359 | - } |
|
358 | + return $text; |
|
359 | + } |
|
360 | 360 | |
361 | 361 | /*======================================================================*\ |
362 | 362 | Function: _expandlinks |
@@ -366,29 +366,29 @@ discard block |
||
366 | 366 | Output: $expandedLinks the expanded links |
367 | 367 | \*======================================================================*/ |
368 | 368 | |
369 | - private function _expandlinks($links,$URI) |
|
370 | - { |
|
369 | + private function _expandlinks($links,$URI) |
|
370 | + { |
|
371 | 371 | |
372 | - preg_match("/^[^\?]+/",$URI,$match); |
|
372 | + preg_match("/^[^\?]+/",$URI,$match); |
|
373 | 373 | |
374 | - $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); |
|
374 | + $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); |
|
375 | 375 | |
376 | - $search = array( "|^http://".preg_quote($this->host)."|i", |
|
377 | - "|^(?!http://)(\/)?(?!mailto:)|i", |
|
378 | - "|/\./|", |
|
379 | - "|/[^\/]+/\.\./|" |
|
380 | - ); |
|
376 | + $search = array( "|^http://".preg_quote($this->host)."|i", |
|
377 | + "|^(?!http://)(\/)?(?!mailto:)|i", |
|
378 | + "|/\./|", |
|
379 | + "|/[^\/]+/\.\./|" |
|
380 | + ); |
|
381 | 381 | |
382 | - $replace = array( "", |
|
383 | - $match."/", |
|
384 | - "/", |
|
385 | - "/" |
|
386 | - ); |
|
382 | + $replace = array( "", |
|
383 | + $match."/", |
|
384 | + "/", |
|
385 | + "/" |
|
386 | + ); |
|
387 | 387 | |
388 | - $expandedLinks = preg_replace($search,$replace,$links); |
|
388 | + $expandedLinks = preg_replace($search,$replace,$links); |
|
389 | 389 | |
390 | - return $expandedLinks; |
|
391 | - } |
|
390 | + return $expandedLinks; |
|
391 | + } |
|
392 | 392 | |
393 | 393 | /*======================================================================*\ |
394 | 394 | Function: _httprequest |
@@ -400,179 +400,179 @@ discard block |
||
400 | 400 | Output: |
401 | 401 | \*======================================================================*/ |
402 | 402 | |
403 | - private function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
|
404 | - { |
|
405 | - if($this->passcookies && $this->_redirectaddr) |
|
406 | - $this->setcookies(); |
|
403 | + private function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
|
404 | + { |
|
405 | + if($this->passcookies && $this->_redirectaddr) |
|
406 | + $this->setcookies(); |
|
407 | 407 | |
408 | - $URI_PARTS = parse_url($URI); |
|
409 | - if(empty($url)) |
|
410 | - $url = "/"; |
|
411 | - $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
|
412 | - if(!empty($this->agent)) |
|
413 | - $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
414 | - if(!empty($this->host) && !isset($this->rawheaders['Host'])) |
|
415 | - $headers .= "Host: ".$this->host."\r\n"; |
|
416 | - if(!empty($this->accept)) |
|
417 | - $headers .= "Accept: ".$this->accept."\r\n"; |
|
408 | + $URI_PARTS = parse_url($URI); |
|
409 | + if(empty($url)) |
|
410 | + $url = "/"; |
|
411 | + $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
|
412 | + if(!empty($this->agent)) |
|
413 | + $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
414 | + if(!empty($this->host) && !isset($this->rawheaders['Host'])) |
|
415 | + $headers .= "Host: ".$this->host."\r\n"; |
|
416 | + if(!empty($this->accept)) |
|
417 | + $headers .= "Accept: ".$this->accept."\r\n"; |
|
418 | 418 | |
419 | - if($this->use_gzip) { |
|
420 | - // make sure PHP was built with --with-zlib |
|
421 | - // and we can handle gzipp'ed data |
|
422 | - if ( function_exists(gzinflate) ) { |
|
423 | - $headers .= "Accept-encoding: gzip\r\n"; |
|
424 | - } |
|
425 | - else { |
|
426 | - trigger_error( |
|
427 | - "use_gzip is on, but PHP was built without zlib support.". |
|
428 | - " Requesting file(s) without gzip encoding.", |
|
429 | - E_USER_NOTICE); |
|
430 | - } |
|
431 | - } |
|
419 | + if($this->use_gzip) { |
|
420 | + // make sure PHP was built with --with-zlib |
|
421 | + // and we can handle gzipp'ed data |
|
422 | + if ( function_exists(gzinflate) ) { |
|
423 | + $headers .= "Accept-encoding: gzip\r\n"; |
|
424 | + } |
|
425 | + else { |
|
426 | + trigger_error( |
|
427 | + "use_gzip is on, but PHP was built without zlib support.". |
|
428 | + " Requesting file(s) without gzip encoding.", |
|
429 | + E_USER_NOTICE); |
|
430 | + } |
|
431 | + } |
|
432 | 432 | |
433 | - if(!empty($this->referer)) |
|
434 | - $headers .= "Referer: ".$this->referer."\r\n"; |
|
435 | - if(!empty($this->cookies)) |
|
436 | - { |
|
437 | - if(!is_array($this->cookies)) |
|
438 | - $this->cookies = (array)$this->cookies; |
|
433 | + if(!empty($this->referer)) |
|
434 | + $headers .= "Referer: ".$this->referer."\r\n"; |
|
435 | + if(!empty($this->cookies)) |
|
436 | + { |
|
437 | + if(!is_array($this->cookies)) |
|
438 | + $this->cookies = (array)$this->cookies; |
|
439 | 439 | |
440 | - reset($this->cookies); |
|
441 | - if ( count($this->cookies) > 0 ) { |
|
442 | - $cookie_headers .= 'Cookie: '; |
|
443 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
444 | - $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
|
445 | - } |
|
446 | - $headers .= substr($cookie_headers,0,-2) . "\r\n"; |
|
447 | - } |
|
448 | - } |
|
449 | - if(!empty($this->rawheaders)) |
|
450 | - { |
|
451 | - if(!is_array($this->rawheaders)) |
|
452 | - $this->rawheaders = (array)$this->rawheaders; |
|
453 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
454 | - $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
455 | - } |
|
456 | - if(!empty($content_type)) { |
|
457 | - $headers .= "Content-type: $content_type"; |
|
458 | - if ($content_type == "multipart/form-data") |
|
459 | - $headers .= "; boundary=".$this->_mime_boundary; |
|
460 | - $headers .= "\r\n"; |
|
461 | - } |
|
462 | - if(!empty($body)) |
|
463 | - $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
464 | - if(!empty($this->user) || !empty($this->pass)) |
|
465 | - $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
466 | - |
|
467 | - $headers .= "\r\n"; |
|
440 | + reset($this->cookies); |
|
441 | + if ( count($this->cookies) > 0 ) { |
|
442 | + $cookie_headers .= 'Cookie: '; |
|
443 | + foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
444 | + $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
|
445 | + } |
|
446 | + $headers .= substr($cookie_headers,0,-2) . "\r\n"; |
|
447 | + } |
|
448 | + } |
|
449 | + if(!empty($this->rawheaders)) |
|
450 | + { |
|
451 | + if(!is_array($this->rawheaders)) |
|
452 | + $this->rawheaders = (array)$this->rawheaders; |
|
453 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
454 | + $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
455 | + } |
|
456 | + if(!empty($content_type)) { |
|
457 | + $headers .= "Content-type: $content_type"; |
|
458 | + if ($content_type == "multipart/form-data") |
|
459 | + $headers .= "; boundary=".$this->_mime_boundary; |
|
460 | + $headers .= "\r\n"; |
|
461 | + } |
|
462 | + if(!empty($body)) |
|
463 | + $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
464 | + if(!empty($this->user) || !empty($this->pass)) |
|
465 | + $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
466 | + |
|
467 | + $headers .= "\r\n"; |
|
468 | 468 | |
469 | - // set the read timeout if needed |
|
470 | - if ($this->read_timeout > 0) |
|
471 | - socket_set_timeout($fp, $this->read_timeout); |
|
472 | - $this->timed_out = false; |
|
469 | + // set the read timeout if needed |
|
470 | + if ($this->read_timeout > 0) |
|
471 | + socket_set_timeout($fp, $this->read_timeout); |
|
472 | + $this->timed_out = false; |
|
473 | 473 | |
474 | - fwrite($fp,$headers.$body,strlen($headers.$body)); |
|
474 | + fwrite($fp,$headers.$body,strlen($headers.$body)); |
|
475 | 475 | |
476 | - $this->_redirectaddr = false; |
|
477 | - unset($this->headers); |
|
476 | + $this->_redirectaddr = false; |
|
477 | + unset($this->headers); |
|
478 | 478 | |
479 | - // content was returned gzip encoded? |
|
480 | - $is_gzipped = false; |
|
479 | + // content was returned gzip encoded? |
|
480 | + $is_gzipped = false; |
|
481 | 481 | |
482 | - while($currentHeader = fgets($fp,$this->_maxlinelen)) |
|
483 | - { |
|
484 | - if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
|
485 | - { |
|
486 | - $this->status=-100; |
|
487 | - return false; |
|
488 | - } |
|
482 | + while($currentHeader = fgets($fp,$this->_maxlinelen)) |
|
483 | + { |
|
484 | + if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
|
485 | + { |
|
486 | + $this->status=-100; |
|
487 | + return false; |
|
488 | + } |
|
489 | 489 | |
490 | - // if($currentHeader == "\r\n") |
|
491 | - if(preg_match("/^\r?\n$/", $currentHeader) ) |
|
492 | - break; |
|
490 | + // if($currentHeader == "\r\n") |
|
491 | + if(preg_match("/^\r?\n$/", $currentHeader) ) |
|
492 | + break; |
|
493 | 493 | |
494 | - // if a header begins with Location: or URI:, set the redirect |
|
495 | - if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
|
496 | - { |
|
497 | - // get URL portion of the redirect |
|
498 | - preg_match("/^(Location:|URI:)\s+(.*)/",chop($currentHeader),$matches); |
|
499 | - // look for :// in the Location header to see if hostname is included |
|
500 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
501 | - { |
|
502 | - // no host in the path, so prepend |
|
503 | - $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|
504 | - // eliminate double slash |
|
505 | - if(!preg_match("|^/|",$matches[2])) |
|
506 | - $this->_redirectaddr .= "/".$matches[2]; |
|
507 | - else |
|
508 | - $this->_redirectaddr .= $matches[2]; |
|
509 | - } |
|
510 | - else |
|
511 | - $this->_redirectaddr = $matches[2]; |
|
512 | - } |
|
494 | + // if a header begins with Location: or URI:, set the redirect |
|
495 | + if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
|
496 | + { |
|
497 | + // get URL portion of the redirect |
|
498 | + preg_match("/^(Location:|URI:)\s+(.*)/",chop($currentHeader),$matches); |
|
499 | + // look for :// in the Location header to see if hostname is included |
|
500 | + if(!preg_match("|\:\/\/|",$matches[2])) |
|
501 | + { |
|
502 | + // no host in the path, so prepend |
|
503 | + $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|
504 | + // eliminate double slash |
|
505 | + if(!preg_match("|^/|",$matches[2])) |
|
506 | + $this->_redirectaddr .= "/".$matches[2]; |
|
507 | + else |
|
508 | + $this->_redirectaddr .= $matches[2]; |
|
509 | + } |
|
510 | + else |
|
511 | + $this->_redirectaddr = $matches[2]; |
|
512 | + } |
|
513 | 513 | |
514 | - if(preg_match("|^HTTP/|",$currentHeader)) |
|
515 | - { |
|
514 | + if(preg_match("|^HTTP/|",$currentHeader)) |
|
515 | + { |
|
516 | 516 | if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
517 | - { |
|
518 | - $this->status= $status[1]; |
|
517 | + { |
|
518 | + $this->status= $status[1]; |
|
519 | 519 | } |
520 | - $this->response_code = $currentHeader; |
|
521 | - } |
|
520 | + $this->response_code = $currentHeader; |
|
521 | + } |
|
522 | 522 | |
523 | - if (preg_match("/Content-Encoding: gzip/", $currentHeader) ) { |
|
524 | - $is_gzipped = true; |
|
525 | - } |
|
523 | + if (preg_match("/Content-Encoding: gzip/", $currentHeader) ) { |
|
524 | + $is_gzipped = true; |
|
525 | + } |
|
526 | 526 | |
527 | - $this->headers[] = $currentHeader; |
|
528 | - } |
|
529 | - |
|
530 | - # $results = fread($fp, $this->maxlength); |
|
531 | - $results = ""; |
|
532 | - while ( $data = fread($fp, $this->maxlength) ) { |
|
533 | - $results .= $data; |
|
534 | - if ( |
|
535 | - strlen($results) > $this->maxlength ) { |
|
536 | - break; |
|
537 | - } |
|
538 | - } |
|
527 | + $this->headers[] = $currentHeader; |
|
528 | + } |
|
529 | + |
|
530 | + # $results = fread($fp, $this->maxlength); |
|
531 | + $results = ""; |
|
532 | + while ( $data = fread($fp, $this->maxlength) ) { |
|
533 | + $results .= $data; |
|
534 | + if ( |
|
535 | + strlen($results) > $this->maxlength ) { |
|
536 | + break; |
|
537 | + } |
|
538 | + } |
|
539 | 539 | |
540 | - // gunzip |
|
541 | - if ( $is_gzipped ) { |
|
542 | - // per http://www.php.net/manual/en/function.gzencode.php |
|
543 | - $results = substr($results, 10); |
|
544 | - $results = gzinflate($results); |
|
545 | - } |
|
540 | + // gunzip |
|
541 | + if ( $is_gzipped ) { |
|
542 | + // per http://www.php.net/manual/en/function.gzencode.php |
|
543 | + $results = substr($results, 10); |
|
544 | + $results = gzinflate($results); |
|
545 | + } |
|
546 | 546 | |
547 | - if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
|
548 | - { |
|
549 | - $this->status=-100; |
|
550 | - return false; |
|
551 | - } |
|
547 | + if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
|
548 | + { |
|
549 | + $this->status=-100; |
|
550 | + return false; |
|
551 | + } |
|
552 | 552 | |
553 | - // check if there is a a redirect meta tag |
|
553 | + // check if there is a a redirect meta tag |
|
554 | 554 | |
555 | - if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
556 | - { |
|
557 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
558 | - } |
|
559 | - |
|
560 | - // have we hit our frame depth and is there frame src to fetch? |
|
561 | - if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
562 | - { |
|
563 | - $this->results[] = $results; |
|
564 | - for($x=0; $x<count($match[1]); $x++) |
|
565 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
566 | - } |
|
567 | - // have we already fetched framed content? |
|
568 | - elseif(is_array($this->results)) |
|
569 | - $this->results[] = $results; |
|
570 | - // no framed content |
|
571 | - else |
|
572 | - $this->results = $results; |
|
555 | + if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
556 | + { |
|
557 | + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
558 | + } |
|
559 | + |
|
560 | + // have we hit our frame depth and is there frame src to fetch? |
|
561 | + if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
562 | + { |
|
563 | + $this->results[] = $results; |
|
564 | + for($x=0; $x<count($match[1]); $x++) |
|
565 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
566 | + } |
|
567 | + // have we already fetched framed content? |
|
568 | + elseif(is_array($this->results)) |
|
569 | + $this->results[] = $results; |
|
570 | + // no framed content |
|
571 | + else |
|
572 | + $this->results = $results; |
|
573 | 573 | |
574 | - return true; |
|
575 | - } |
|
574 | + return true; |
|
575 | + } |
|
576 | 576 | |
577 | 577 | /*======================================================================*\ |
578 | 578 | Function: _httpsrequest |
@@ -583,163 +583,163 @@ discard block |
||
583 | 583 | Output: |
584 | 584 | \*======================================================================*/ |
585 | 585 | |
586 | - private function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
|
587 | - { |
|
588 | - if($this->passcookies && $this->_redirectaddr) |
|
589 | - $this->setcookies(); |
|
586 | + private function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
|
587 | + { |
|
588 | + if($this->passcookies && $this->_redirectaddr) |
|
589 | + $this->setcookies(); |
|
590 | 590 | |
591 | - $headers = array(); |
|
591 | + $headers = array(); |
|
592 | 592 | |
593 | - $URI_PARTS = parse_url($URI); |
|
594 | - if(empty($url)) |
|
595 | - $url = "/"; |
|
596 | - // GET ... header not needed for curl |
|
597 | - //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
|
598 | - if(!empty($this->agent)) |
|
599 | - $headers[] = "User-Agent: ".$this->agent; |
|
600 | - if(!empty($this->host)) |
|
601 | - $headers[] = "Host: ".$this->host; |
|
602 | - if(!empty($this->accept)) |
|
603 | - $headers[] = "Accept: ".$this->accept; |
|
604 | - if(!empty($this->referer)) |
|
605 | - $headers[] = "Referer: ".$this->referer; |
|
606 | - if(!empty($this->cookies)) |
|
607 | - { |
|
608 | - if(!is_array($this->cookies)) |
|
609 | - $this->cookies = (array)$this->cookies; |
|
593 | + $URI_PARTS = parse_url($URI); |
|
594 | + if(empty($url)) |
|
595 | + $url = "/"; |
|
596 | + // GET ... header not needed for curl |
|
597 | + //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
|
598 | + if(!empty($this->agent)) |
|
599 | + $headers[] = "User-Agent: ".$this->agent; |
|
600 | + if(!empty($this->host)) |
|
601 | + $headers[] = "Host: ".$this->host; |
|
602 | + if(!empty($this->accept)) |
|
603 | + $headers[] = "Accept: ".$this->accept; |
|
604 | + if(!empty($this->referer)) |
|
605 | + $headers[] = "Referer: ".$this->referer; |
|
606 | + if(!empty($this->cookies)) |
|
607 | + { |
|
608 | + if(!is_array($this->cookies)) |
|
609 | + $this->cookies = (array)$this->cookies; |
|
610 | 610 | |
611 | - reset($this->cookies); |
|
612 | - if ( count($this->cookies) > 0 ) { |
|
613 | - $cookie_str = 'Cookie: '; |
|
614 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
615 | - $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; |
|
616 | - } |
|
617 | - $headers[] = substr($cookie_str,0,-2); |
|
618 | - } |
|
619 | - } |
|
620 | - if(!empty($this->rawheaders)) |
|
621 | - { |
|
622 | - if(!is_array($this->rawheaders)) |
|
623 | - $this->rawheaders = (array)$this->rawheaders; |
|
624 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
625 | - $headers[] = $headerKey.": ".$headerVal; |
|
626 | - } |
|
627 | - if(!empty($content_type)) { |
|
628 | - if ($content_type == "multipart/form-data") |
|
629 | - $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
630 | - else |
|
631 | - $headers[] = "Content-type: $content_type"; |
|
632 | - } |
|
633 | - if(!empty($body)) |
|
634 | - $headers[] = "Content-length: ".strlen($body); |
|
635 | - if(!empty($this->user) || !empty($this->pass)) |
|
636 | - $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
611 | + reset($this->cookies); |
|
612 | + if ( count($this->cookies) > 0 ) { |
|
613 | + $cookie_str = 'Cookie: '; |
|
614 | + foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
615 | + $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; |
|
616 | + } |
|
617 | + $headers[] = substr($cookie_str,0,-2); |
|
618 | + } |
|
619 | + } |
|
620 | + if(!empty($this->rawheaders)) |
|
621 | + { |
|
622 | + if(!is_array($this->rawheaders)) |
|
623 | + $this->rawheaders = (array)$this->rawheaders; |
|
624 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
625 | + $headers[] = $headerKey.": ".$headerVal; |
|
626 | + } |
|
627 | + if(!empty($content_type)) { |
|
628 | + if ($content_type == "multipart/form-data") |
|
629 | + $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
630 | + else |
|
631 | + $headers[] = "Content-type: $content_type"; |
|
632 | + } |
|
633 | + if(!empty($body)) |
|
634 | + $headers[] = "Content-length: ".strlen($body); |
|
635 | + if(!empty($this->user) || !empty($this->pass)) |
|
636 | + $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
637 | 637 | |
638 | - for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|
639 | - $cmdline_params .= " -H \"".$headers[$curr_header]."\""; |
|
640 | - } |
|
638 | + for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|
639 | + $cmdline_params .= " -H \"".$headers[$curr_header]."\""; |
|
640 | + } |
|
641 | 641 | |
642 | - if(!empty($body)) |
|
643 | - $cmdline_params .= " -d \"$body\""; |
|
642 | + if(!empty($body)) |
|
643 | + $cmdline_params .= " -d \"$body\""; |
|
644 | 644 | |
645 | - if($this->read_timeout > 0) |
|
646 | - $cmdline_params .= " -m ".$this->read_timeout; |
|
645 | + if($this->read_timeout > 0) |
|
646 | + $cmdline_params .= " -m ".$this->read_timeout; |
|
647 | 647 | |
648 | - $headerfile = uniqid(time()); |
|
648 | + $headerfile = uniqid(time()); |
|
649 | 649 | |
650 | - # accept self-signed certs |
|
651 | - $cmdline_params .= " -k"; |
|
650 | + # accept self-signed certs |
|
651 | + $cmdline_params .= " -k"; |
|
652 | 652 | $results = array(); |
653 | 653 | $return = 0; |
654 | - exec($this->curl_path." -D \"/tmp/$headerfile\"".escapeshellcmd($cmdline_params)." ".escapeshellcmd($URI),$results,$return); |
|
654 | + exec($this->curl_path." -D \"/tmp/$headerfile\"".escapeshellcmd($cmdline_params)." ".escapeshellcmd($URI),$results,$return); |
|
655 | 655 | |
656 | - if($return) |
|
657 | - { |
|
658 | - $this->error = "Error: cURL could not retrieve the document, error $return."; |
|
659 | - return false; |
|
660 | - } |
|
656 | + if($return) |
|
657 | + { |
|
658 | + $this->error = "Error: cURL could not retrieve the document, error $return."; |
|
659 | + return false; |
|
660 | + } |
|
661 | 661 | |
662 | 662 | |
663 | - $results = implode("\r\n",$results); |
|
663 | + $results = implode("\r\n",$results); |
|
664 | 664 | |
665 | - $result_headers = file("/tmp/$headerfile"); |
|
665 | + $result_headers = file("/tmp/$headerfile"); |
|
666 | 666 | |
667 | - $this->_redirectaddr = false; |
|
668 | - unset($this->headers); |
|
667 | + $this->_redirectaddr = false; |
|
668 | + unset($this->headers); |
|
669 | 669 | |
670 | - for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
671 | - { |
|
670 | + for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
671 | + { |
|
672 | 672 | |
673 | - // if a header begins with Location: or URI:, set the redirect |
|
674 | - if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) |
|
675 | - { |
|
676 | - // get URL portion of the redirect |
|
677 | - preg_match("/^(Location: |URI:)(.*)/",chop($result_headers[$currentHeader]),$matches); |
|
678 | - // look for :// in the Location header to see if hostname is included |
|
679 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
680 | - { |
|
681 | - // no host in the path, so prepend |
|
682 | - $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|
683 | - // eliminate double slash |
|
684 | - if(!preg_match("|^/|",$matches[2])) |
|
685 | - $this->_redirectaddr .= "/".$matches[2]; |
|
686 | - else |
|
687 | - $this->_redirectaddr .= $matches[2]; |
|
688 | - } |
|
689 | - else |
|
690 | - $this->_redirectaddr = $matches[2]; |
|
691 | - } |
|
673 | + // if a header begins with Location: or URI:, set the redirect |
|
674 | + if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) |
|
675 | + { |
|
676 | + // get URL portion of the redirect |
|
677 | + preg_match("/^(Location: |URI:)(.*)/",chop($result_headers[$currentHeader]),$matches); |
|
678 | + // look for :// in the Location header to see if hostname is included |
|
679 | + if(!preg_match("|\:\/\/|",$matches[2])) |
|
680 | + { |
|
681 | + // no host in the path, so prepend |
|
682 | + $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|
683 | + // eliminate double slash |
|
684 | + if(!preg_match("|^/|",$matches[2])) |
|
685 | + $this->_redirectaddr .= "/".$matches[2]; |
|
686 | + else |
|
687 | + $this->_redirectaddr .= $matches[2]; |
|
688 | + } |
|
689 | + else |
|
690 | + $this->_redirectaddr = $matches[2]; |
|
691 | + } |
|
692 | 692 | |
693 | - if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
694 | - { |
|
695 | - $this->response_code = $result_headers[$currentHeader]; |
|
696 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$this->response_code, $match)) |
|
697 | - { |
|
698 | - $this->status= $match[1]; |
|
699 | - } |
|
700 | - } |
|
701 | - $this->headers[] = $result_headers[$currentHeader]; |
|
702 | - } |
|
703 | - |
|
704 | - // check if there is a a redirect meta tag |
|
693 | + if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
694 | + { |
|
695 | + $this->response_code = $result_headers[$currentHeader]; |
|
696 | + if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$this->response_code, $match)) |
|
697 | + { |
|
698 | + $this->status= $match[1]; |
|
699 | + } |
|
700 | + } |
|
701 | + $this->headers[] = $result_headers[$currentHeader]; |
|
702 | + } |
|
703 | + |
|
704 | + // check if there is a a redirect meta tag |
|
705 | 705 | |
706 | - if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
707 | - { |
|
708 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
709 | - } |
|
710 | - |
|
711 | - // have we hit our frame depth and is there frame src to fetch? |
|
712 | - if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
713 | - { |
|
714 | - $this->results[] = $results; |
|
715 | - for($x=0; $x<count($match[1]); $x++) |
|
716 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
717 | - } |
|
718 | - // have we already fetched framed content? |
|
719 | - elseif(is_array($this->results)) |
|
720 | - $this->results[] = $results; |
|
721 | - // no framed content |
|
722 | - else |
|
723 | - $this->results = $results; |
|
724 | - |
|
725 | - unlink("/tmp/$headerfile"); |
|
706 | + if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
707 | + { |
|
708 | + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
709 | + } |
|
710 | + |
|
711 | + // have we hit our frame depth and is there frame src to fetch? |
|
712 | + if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
713 | + { |
|
714 | + $this->results[] = $results; |
|
715 | + for($x=0; $x<count($match[1]); $x++) |
|
716 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
717 | + } |
|
718 | + // have we already fetched framed content? |
|
719 | + elseif(is_array($this->results)) |
|
720 | + $this->results[] = $results; |
|
721 | + // no framed content |
|
722 | + else |
|
723 | + $this->results = $results; |
|
724 | + |
|
725 | + unlink("/tmp/$headerfile"); |
|
726 | 726 | |
727 | - return true; |
|
728 | - } |
|
727 | + return true; |
|
728 | + } |
|
729 | 729 | |
730 | 730 | /*======================================================================*\ |
731 | 731 | Function: setcookies() |
732 | 732 | Purpose: set cookies for a redirection |
733 | 733 | \*======================================================================*/ |
734 | 734 | |
735 | - public function setcookies() |
|
736 | - { |
|
737 | - for($x=0; $x<count($this->headers); $x++) |
|
738 | - { |
|
739 | - if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) |
|
740 | - $this->cookies[$match[1]] = $match[2]; |
|
741 | - } |
|
742 | - } |
|
735 | + public function setcookies() |
|
736 | + { |
|
737 | + for($x=0; $x<count($this->headers); $x++) |
|
738 | + { |
|
739 | + if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) |
|
740 | + $this->cookies[$match[1]] = $match[2]; |
|
741 | + } |
|
742 | + } |
|
743 | 743 | |
744 | 744 | |
745 | 745 | /*======================================================================*\ |
@@ -748,17 +748,17 @@ discard block |
||
748 | 748 | Input: $fp file pointer |
749 | 749 | \*======================================================================*/ |
750 | 750 | |
751 | - private function _check_timeout($fp) |
|
752 | - { |
|
753 | - if ($this->read_timeout > 0) { |
|
754 | - $fp_status = socket_get_status($fp); |
|
755 | - if ($fp_status["timed_out"]) { |
|
756 | - $this->timed_out = true; |
|
757 | - return true; |
|
758 | - } |
|
759 | - } |
|
760 | - return false; |
|
761 | - } |
|
751 | + private function _check_timeout($fp) |
|
752 | + { |
|
753 | + if ($this->read_timeout > 0) { |
|
754 | + $fp_status = socket_get_status($fp); |
|
755 | + if ($fp_status["timed_out"]) { |
|
756 | + $this->timed_out = true; |
|
757 | + return true; |
|
758 | + } |
|
759 | + } |
|
760 | + return false; |
|
761 | + } |
|
762 | 762 | |
763 | 763 | /*======================================================================*\ |
764 | 764 | Function: _connect |
@@ -766,62 +766,62 @@ discard block |
||
766 | 766 | Input: $fp file pointer |
767 | 767 | \*======================================================================*/ |
768 | 768 | |
769 | - private function _connect(&$fp) |
|
770 | - { |
|
771 | - if(!empty($this->proxy_host) && !empty($this->proxy_port)) |
|
772 | - { |
|
773 | - $this->_isproxy = true; |
|
774 | - $host = $this->proxy_host; |
|
775 | - $port = $this->proxy_port; |
|
776 | - } |
|
777 | - else |
|
778 | - { |
|
779 | - $host = $this->host; |
|
780 | - $port = $this->port; |
|
781 | - } |
|
769 | + private function _connect(&$fp) |
|
770 | + { |
|
771 | + if(!empty($this->proxy_host) && !empty($this->proxy_port)) |
|
772 | + { |
|
773 | + $this->_isproxy = true; |
|
774 | + $host = $this->proxy_host; |
|
775 | + $port = $this->proxy_port; |
|
776 | + } |
|
777 | + else |
|
778 | + { |
|
779 | + $host = $this->host; |
|
780 | + $port = $this->port; |
|
781 | + } |
|
782 | 782 | |
783 | - $this->status = 0; |
|
783 | + $this->status = 0; |
|
784 | 784 | |
785 | - if($fp = fsockopen( |
|
786 | - $host, |
|
787 | - $port, |
|
788 | - $errno, |
|
789 | - $errstr, |
|
790 | - $this->_fp_timeout |
|
791 | - )) |
|
792 | - { |
|
793 | - // socket connection succeeded |
|
794 | - |
|
795 | - return true; |
|
796 | - } |
|
797 | - else |
|
798 | - { |
|
799 | - // socket connection failed |
|
800 | - $this->status = $errno; |
|
801 | - switch($errno) |
|
802 | - { |
|
803 | - case -3: |
|
804 | - $this->error="socket creation failed (-3)"; |
|
805 | - case -4: |
|
806 | - $this->error="dns lookup failure (-4)"; |
|
807 | - case -5: |
|
808 | - $this->error="connection refused or timed out (-5)"; |
|
809 | - default: |
|
810 | - $this->error="connection failed (".$errno.")"; |
|
811 | - } |
|
812 | - return false; |
|
813 | - } |
|
814 | - } |
|
785 | + if($fp = fsockopen( |
|
786 | + $host, |
|
787 | + $port, |
|
788 | + $errno, |
|
789 | + $errstr, |
|
790 | + $this->_fp_timeout |
|
791 | + )) |
|
792 | + { |
|
793 | + // socket connection succeeded |
|
794 | + |
|
795 | + return true; |
|
796 | + } |
|
797 | + else |
|
798 | + { |
|
799 | + // socket connection failed |
|
800 | + $this->status = $errno; |
|
801 | + switch($errno) |
|
802 | + { |
|
803 | + case -3: |
|
804 | + $this->error="socket creation failed (-3)"; |
|
805 | + case -4: |
|
806 | + $this->error="dns lookup failure (-4)"; |
|
807 | + case -5: |
|
808 | + $this->error="connection refused or timed out (-5)"; |
|
809 | + default: |
|
810 | + $this->error="connection failed (".$errno.")"; |
|
811 | + } |
|
812 | + return false; |
|
813 | + } |
|
814 | + } |
|
815 | 815 | /*======================================================================*\ |
816 | 816 | Function: _disconnect |
817 | 817 | Purpose: disconnect a socket connection |
818 | 818 | Input: $fp file pointer |
819 | 819 | \*======================================================================*/ |
820 | 820 | |
821 | - private function _disconnect($fp) |
|
822 | - { |
|
823 | - return(fclose($fp)); |
|
824 | - } |
|
821 | + private function _disconnect($fp) |
|
822 | + { |
|
823 | + return(fclose($fp)); |
|
824 | + } |
|
825 | 825 | |
826 | 826 | |
827 | 827 | /*======================================================================*\ |
@@ -832,65 +832,65 @@ discard block |
||
832 | 832 | Output: post body |
833 | 833 | \*======================================================================*/ |
834 | 834 | |
835 | - private function _prepare_post_body($formvars, $formfiles) |
|
836 | - { |
|
837 | - settype($formvars, "array"); |
|
838 | - settype($formfiles, "array"); |
|
835 | + private function _prepare_post_body($formvars, $formfiles) |
|
836 | + { |
|
837 | + settype($formvars, "array"); |
|
838 | + settype($formfiles, "array"); |
|
839 | 839 | |
840 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
841 | - return; |
|
840 | + if (count($formvars) == 0 && count($formfiles) == 0) |
|
841 | + return; |
|
842 | 842 | |
843 | - switch ($this->_submit_type) { |
|
844 | - case "application/x-www-form-urlencoded": |
|
845 | - reset($formvars); |
|
846 | - while(list($key,$val) = each($formvars)) { |
|
847 | - if (is_array($val) || is_object($val)) { |
|
848 | - while (list($cur_key, $cur_val) = each($val)) { |
|
849 | - $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
|
850 | - } |
|
851 | - } else |
|
852 | - $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
853 | - } |
|
854 | - break; |
|
855 | - |
|
856 | - case "multipart/form-data": |
|
857 | - $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
|
843 | + switch ($this->_submit_type) { |
|
844 | + case "application/x-www-form-urlencoded": |
|
845 | + reset($formvars); |
|
846 | + while(list($key,$val) = each($formvars)) { |
|
847 | + if (is_array($val) || is_object($val)) { |
|
848 | + while (list($cur_key, $cur_val) = each($val)) { |
|
849 | + $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
|
850 | + } |
|
851 | + } else |
|
852 | + $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
853 | + } |
|
854 | + break; |
|
855 | + |
|
856 | + case "multipart/form-data": |
|
857 | + $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
|
858 | 858 | |
859 | - reset($formvars); |
|
860 | - while(list($key,$val) = each($formvars)) { |
|
861 | - if (is_array($val) || is_object($val)) { |
|
862 | - while (list($cur_key, $cur_val) = each($val)) { |
|
863 | - $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
864 | - $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n"; |
|
865 | - $postdata .= "$cur_val\r\n"; |
|
866 | - } |
|
867 | - } else { |
|
868 | - $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
869 | - $postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n"; |
|
870 | - $postdata .= "$val\r\n"; |
|
871 | - } |
|
872 | - } |
|
859 | + reset($formvars); |
|
860 | + while(list($key,$val) = each($formvars)) { |
|
861 | + if (is_array($val) || is_object($val)) { |
|
862 | + while (list($cur_key, $cur_val) = each($val)) { |
|
863 | + $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
864 | + $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n"; |
|
865 | + $postdata .= "$cur_val\r\n"; |
|
866 | + } |
|
867 | + } else { |
|
868 | + $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
869 | + $postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n"; |
|
870 | + $postdata .= "$val\r\n"; |
|
871 | + } |
|
872 | + } |
|
873 | 873 | |
874 | - reset($formfiles); |
|
875 | - while (list($field_name, $file_names) = each($formfiles)) { |
|
876 | - settype($file_names, "array"); |
|
877 | - while (list(, $file_name) = each($file_names)) { |
|
878 | - if (!is_readable($file_name)) continue; |
|
879 | - |
|
880 | - $fp = fopen($file_name, "r"); |
|
881 | - $file_content = fread($fp, filesize($file_name)); |
|
882 | - fclose($fp); |
|
883 | - $base_name = basename($file_name); |
|
884 | - |
|
885 | - $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
886 | - $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n"; |
|
887 | - $postdata .= "$file_content\r\n"; |
|
888 | - } |
|
889 | - } |
|
890 | - $postdata .= "--".$this->_mime_boundary."--\r\n"; |
|
891 | - break; |
|
892 | - } |
|
893 | - |
|
894 | - return $postdata; |
|
895 | - } |
|
874 | + reset($formfiles); |
|
875 | + while (list($field_name, $file_names) = each($formfiles)) { |
|
876 | + settype($file_names, "array"); |
|
877 | + while (list(, $file_name) = each($file_names)) { |
|
878 | + if (!is_readable($file_name)) continue; |
|
879 | + |
|
880 | + $fp = fopen($file_name, "r"); |
|
881 | + $file_content = fread($fp, filesize($file_name)); |
|
882 | + fclose($fp); |
|
883 | + $base_name = basename($file_name); |
|
884 | + |
|
885 | + $postdata .= "--".$this->_mime_boundary."\r\n"; |
|
886 | + $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n"; |
|
887 | + $postdata .= "$file_content\r\n"; |
|
888 | + } |
|
889 | + } |
|
890 | + $postdata .= "--".$this->_mime_boundary."--\r\n"; |
|
891 | + break; |
|
892 | + } |
|
893 | + |
|
894 | + return $postdata; |
|
895 | + } |
|
896 | 896 | } |
897 | 897 | \ No newline at end of file |
@@ -1,26 +1,26 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Project: MagpieRSS: a simple RSS integration tool |
|
4 | - * File: rss_parse.inc - parse an RSS or Atom feed |
|
5 | - * return as a simple object. |
|
6 | - * |
|
7 | - * Handles RSS 0.9x, RSS 2.0, RSS 1.0, and Atom 0.3 |
|
8 | - * |
|
9 | - * The lastest version of MagpieRSS can be obtained from: |
|
10 | - * http://magpierss.sourceforge.net |
|
11 | - * |
|
12 | - * For questions, help, comments, discussion, etc., please join the |
|
13 | - * Magpie mailing list: |
|
14 | - * [email protected] |
|
15 | - * |
|
16 | - * @author Kellan Elliott-McCrea <[email protected]> |
|
17 | - * @version 0.7a |
|
18 | - * @license GPL |
|
19 | - * @package chamilo.include.rss |
|
20 | - */ |
|
3 | + * Project: MagpieRSS: a simple RSS integration tool |
|
4 | + * File: rss_parse.inc - parse an RSS or Atom feed |
|
5 | + * return as a simple object. |
|
6 | + * |
|
7 | + * Handles RSS 0.9x, RSS 2.0, RSS 1.0, and Atom 0.3 |
|
8 | + * |
|
9 | + * The lastest version of MagpieRSS can be obtained from: |
|
10 | + * http://magpierss.sourceforge.net |
|
11 | + * |
|
12 | + * For questions, help, comments, discussion, etc., please join the |
|
13 | + * Magpie mailing list: |
|
14 | + * [email protected] |
|
15 | + * |
|
16 | + * @author Kellan Elliott-McCrea <[email protected]> |
|
17 | + * @version 0.7a |
|
18 | + * @license GPL |
|
19 | + * @package chamilo.include.rss |
|
20 | + */ |
|
21 | 21 | /** |
22 | - * Code |
|
23 | - */ |
|
22 | + * Code |
|
23 | + */ |
|
24 | 24 | define('RSS', 'RSS'); |
25 | 25 | define('ATOM', 'Atom'); |
26 | 26 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | # |
101 | 101 | if (!function_exists('xml_parser_create')) { |
102 | 102 | $this->error( "Failed to load PHP's XML Extension. " . |
103 | - "http://www.php.net/manual/en/ref.xml.php", |
|
104 | - E_USER_ERROR ); |
|
103 | + "http://www.php.net/manual/en/ref.xml.php", |
|
104 | + E_USER_ERROR ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | list($parser, $source) = $this->create_parser($source, |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | |
111 | 111 | if (!is_resource($parser)) { |
112 | 112 | $this->error( "Failed to create an instance of PHP's XML parser. " . |
113 | - "http://www.php.net/manual/en/ref.xml.php", |
|
114 | - E_USER_ERROR ); |
|
113 | + "http://www.php.net/manual/en/ref.xml.php", |
|
114 | + E_USER_ERROR ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -447,9 +447,9 @@ discard block |
||
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * return XML parser, and possibly re-encoded source |
|
451 | - * |
|
452 | - */ |
|
450 | + * return XML parser, and possibly re-encoded source |
|
451 | + * |
|
452 | + */ |
|
453 | 453 | public function create_parser($source, $out_enc, $in_enc, $detect) { |
454 | 454 | if ( substr(phpversion(),0,1) == 5) { |
455 | 455 | $parser = $this->php5_create_parser($in_enc, $detect); |
@@ -466,14 +466,14 @@ discard block |
||
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Instantiate an XML parser under PHP5 |
|
470 | - * |
|
471 | - * PHP5 will do a fine job of detecting input encoding |
|
472 | - * if passed an empty string as the encoding. |
|
473 | - * |
|
474 | - * All hail libxml2! |
|
475 | - * |
|
476 | - */ |
|
469 | + * Instantiate an XML parser under PHP5 |
|
470 | + * |
|
471 | + * PHP5 will do a fine job of detecting input encoding |
|
472 | + * if passed an empty string as the encoding. |
|
473 | + * |
|
474 | + * All hail libxml2! |
|
475 | + * |
|
476 | + */ |
|
477 | 477 | public function php5_create_parser($in_enc, $detect) { |
478 | 478 | // by default php5 does a fine job of detecting input encodings |
479 | 479 | if(!$detect && $in_enc) { |
@@ -485,20 +485,20 @@ discard block |
||
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Instaniate an XML parser under PHP4 |
|
489 | - * |
|
490 | - * Unfortunately PHP4's support for character encodings |
|
491 | - * and especially XML and character encodings sucks. As |
|
492 | - * long as the documents you parse only contain characters |
|
493 | - * from the ISO-8859-1 character set (a superset of ASCII, |
|
494 | - * and a subset of UTF-8) you're fine. However once you |
|
495 | - * step out of that comfy little world things get mad, bad, |
|
496 | - * and dangerous to know. |
|
497 | - * |
|
498 | - * The following code is based on SJM's work with FoF |
|
499 | - * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
500 | - * |
|
501 | - */ |
|
488 | + * Instaniate an XML parser under PHP4 |
|
489 | + * |
|
490 | + * Unfortunately PHP4's support for character encodings |
|
491 | + * and especially XML and character encodings sucks. As |
|
492 | + * long as the documents you parse only contain characters |
|
493 | + * from the ISO-8859-1 character set (a superset of ASCII, |
|
494 | + * and a subset of UTF-8) you're fine. However once you |
|
495 | + * step out of that comfy little world things get mad, bad, |
|
496 | + * and dangerous to know. |
|
497 | + * |
|
498 | + * The following code is based on SJM's work with FoF |
|
499 | + * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
500 | + * |
|
501 | + */ |
|
502 | 502 | public function php4_create_parser($source, $in_enc, $detect) { |
503 | 503 | if ( !$detect ) { |
504 | 504 | return array(xml_parser_create($in_enc), $source); |
@@ -542,8 +542,8 @@ discard block |
||
542 | 542 | |
543 | 543 | // else |
544 | 544 | $this->error("Feed is in an unsupported character encoding. ($in_enc) " . |
545 | - "You may see strange artifacts, and mangled characters.", |
|
546 | - E_USER_NOTICE); |
|
545 | + "You may see strange artifacts, and mangled characters.", |
|
546 | + E_USER_NOTICE); |
|
547 | 547 | |
548 | 548 | return array(xml_parser_create(), $source); |
549 | 549 | } |
@@ -589,17 +589,17 @@ discard block |
||
589 | 589 | // courtesy, Ryan Currie, [email protected] |
590 | 590 | |
591 | 591 | if (!function_exists('array_change_key_case')) { |
592 | - define("CASE_UPPER",1); |
|
593 | - define("CASE_LOWER",0); |
|
592 | + define("CASE_UPPER",1); |
|
593 | + define("CASE_LOWER",0); |
|
594 | 594 | |
595 | 595 | |
596 | - function array_change_key_case($array,$case=CASE_LOWER) { |
|
597 | - if ($case=CASE_LOWER) $cmd=strtolower; |
|
598 | - elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
599 | - foreach($array as $key=>$value) { |
|
600 | - $output[$cmd($key)]=$value; |
|
601 | - } |
|
602 | - return $output; |
|
603 | - } |
|
596 | + function array_change_key_case($array,$case=CASE_LOWER) { |
|
597 | + if ($case=CASE_LOWER) $cmd=strtolower; |
|
598 | + elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
599 | + foreach($array as $key=>$value) { |
|
600 | + $output[$cmd($key)]=$value; |
|
601 | + } |
|
602 | + return $output; |
|
603 | + } |
|
604 | 604 | |
605 | 605 | } |
@@ -42,20 +42,20 @@ discard block |
||
42 | 42 | $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&courseCode='.$_course['official_code'] : '' ); |
43 | 43 | $navigation['myprofile']['title'] = get_lang('ModifyProfile'); |
44 | 44 | $navigation['myprofile']['key'] = 'profile'; |
45 | - // Link to my agenda |
|
45 | + // Link to my agenda |
|
46 | 46 | $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal'; |
47 | 47 | $navigation['myagenda']['title'] = get_lang('MyAgenda'); |
48 | 48 | $navigation['myagenda']['key'] = 'agenda'; |
49 | 49 | |
50 | - // Gradebook |
|
51 | - if (api_get_setting('gradebook_enable') == 'true') { |
|
50 | + // Gradebook |
|
51 | + if (api_get_setting('gradebook_enable') == 'true') { |
|
52 | 52 | $navigation['mygradebook']['url'] = api_get_path(WEB_CODE_PATH).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&courseCode='.$_course['official_code'] : '' ); |
53 | 53 | $navigation['mygradebook']['title'] = get_lang('MyGradebook'); |
54 | 54 | $navigation['mygradebook']['key'] = 'gradebook'; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - // Reporting |
|
58 | - if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) { |
|
57 | + // Reporting |
|
58 | + if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) { |
|
59 | 59 | // Link to my space |
60 | 60 | $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/'.(api_is_drh()?'session.php':''); |
61 | 61 | $navigation['session_my_space']['title'] = get_lang('MySpace'); |
@@ -79,21 +79,21 @@ discard block |
||
79 | 79 | $navigation['session_my_progress']['key'] = 'my-progress'; |
80 | 80 | } |
81 | 81 | |
82 | - // Social |
|
83 | - if (api_get_setting('allow_social_tool')=='true') { |
|
82 | + // Social |
|
83 | + if (api_get_setting('allow_social_tool')=='true') { |
|
84 | 84 | $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php'; |
85 | 85 | $navigation['social']['title'] = get_lang('SocialNetwork'); |
86 | 86 | $navigation['social']['key'] = 'social-network'; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - // Dashboard |
|
90 | - if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) { |
|
89 | + // Dashboard |
|
90 | + if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) { |
|
91 | 91 | $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php'; |
92 | 92 | $navigation['dashboard']['title'] = get_lang('Dashboard'); |
93 | 93 | $navigation['dashboard']['key'] = 'dashboard'; |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - // Reports |
|
96 | + // Reports |
|
97 | 97 | /* |
98 | 98 | if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) { |
99 | 99 | $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php'; |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | } |
117 | 117 | // End Custom Tabs |
118 | 118 | |
119 | - // Platform administration |
|
120 | - if (api_is_platform_admin(true)) { |
|
119 | + // Platform administration |
|
120 | + if (api_is_platform_admin(true)) { |
|
121 | 121 | $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/'; |
122 | 122 | $navigation['platform_admin']['title'] = get_lang('PlatformAdmin'); |
123 | 123 | $navigation['platform_admin']['key'] = 'admin'; |
124 | - } |
|
124 | + } |
|
125 | 125 | |
126 | - return $navigation; |
|
126 | + return $navigation; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | - // Reports |
|
354 | + // Reports |
|
355 | 355 | if (!empty($possible_tabs['reports'])) { |
356 | 356 | if (api_get_setting('show_tabs', 'reports') == 'true') { |
357 | 357 | if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin()) && Rights::hasRight('show_tabs:reports')) { |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | $menu = null; |
494 | 494 | if (!empty($lis)) { |
495 | - $menu .= $lis; |
|
495 | + $menu .= $lis; |
|
496 | 496 | } |
497 | 497 | return $menu; |
498 | 498 | } |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $navigation_item_my_courses['title'] = get_lang('MyCourses'); |
549 | 549 | $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php'; |
550 | 550 | $navigation[] = $navigation_item_my_courses; |
551 | - */ |
|
551 | + */ |
|
552 | 552 | $navigation[] = $navigation_item; |
553 | 553 | } |
554 | 554 |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | if ($height >= $max_size_for_picture) { |
48 | 48 | // scale width |
49 | 49 | $new_width = round($width * ($max_size_for_picture / $height)); |
50 | - $this->image_wrapper->resize($new_width, $max_size_for_picture, 0); |
|
50 | + $this->image_wrapper->resize($new_width, $max_size_for_picture, 0); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | public function __construct($path) |
151 | 151 | { |
152 | - parent::__construct($path); |
|
152 | + parent::__construct($path); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function set_image_wrapper() |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | - public function get_image_size() |
|
187 | + public function get_image_size() |
|
188 | 188 | { |
189 | - $imagesize = array('width'=>0,'height'=>0); |
|
190 | - if ($this->image_validated) { |
|
189 | + $imagesize = array('width'=>0,'height'=>0); |
|
190 | + if ($this->image_validated) { |
|
191 | 191 | $imagesize = $this->image->getImageGeometry(); |
192 | - } |
|
193 | - return $imagesize; |
|
194 | - } |
|
192 | + } |
|
193 | + return $imagesize; |
|
194 | + } |
|
195 | 195 | |
196 | - //@todo implement border logic case for Imagick |
|
197 | - public function resize($thumbw, $thumbh, $border, $specific_size = false) |
|
196 | + //@todo implement border logic case for Imagick |
|
197 | + public function resize($thumbw, $thumbh, $border, $specific_size = false) |
|
198 | 198 | { |
199 | - if (!$this->image_validated) return false; |
|
199 | + if (!$this->image_validated) return false; |
|
200 | 200 | |
201 | 201 | if ($specific_size) { |
202 | 202 | $width = $thumbw; |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | $width = (int)($this->width * $scale); |
207 | 207 | $height = (int)($this->height * $scale); |
208 | 208 | } |
209 | - $result = $this->image->resizeImage($width, $height, $this->filter, 1); |
|
210 | - $this->width = $thumbw; |
|
211 | - $this->height = $thumbh; |
|
212 | - } |
|
209 | + $result = $this->image->resizeImage($width, $height, $this->filter, 1); |
|
210 | + $this->width = $thumbw; |
|
211 | + $this->height = $thumbh; |
|
212 | + } |
|
213 | 213 | |
214 | 214 | /** |
215 | 215 | * @author José Loguercio <[email protected]> |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
225 | 225 | if (!$this->image_validated) return false; |
226 | 226 | $this->image->cropimage($width, $height, $x, $y); |
227 | - $this->width = $width; |
|
228 | - $this->height = $height; |
|
227 | + $this->width = $width; |
|
228 | + $this->height = $height; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
@@ -235,35 +235,35 @@ discard block |
||
235 | 235 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
236 | 236 | $type = $convert_file_to; |
237 | 237 | } |
238 | - switch ($type) { |
|
239 | - case 'jpeg': |
|
240 | - case 'jpg': |
|
241 | - if (!$file) header("Content-type: image/jpeg"); |
|
242 | - break; |
|
243 | - case 'png': |
|
244 | - if (!$file) header("Content-type: image/png"); |
|
245 | - break; |
|
246 | - case 'gif': |
|
247 | - if (!$file) header("Content-type: image/gif"); |
|
248 | - break; |
|
249 | - } |
|
250 | - $result = false; |
|
251 | - try { |
|
252 | - $result = $this->image->writeImage($file); |
|
253 | - } catch(ImagickException $e) { |
|
238 | + switch ($type) { |
|
239 | + case 'jpeg': |
|
240 | + case 'jpg': |
|
241 | + if (!$file) header("Content-type: image/jpeg"); |
|
242 | + break; |
|
243 | + case 'png': |
|
244 | + if (!$file) header("Content-type: image/png"); |
|
245 | + break; |
|
246 | + case 'gif': |
|
247 | + if (!$file) header("Content-type: image/gif"); |
|
248 | + break; |
|
249 | + } |
|
250 | + $result = false; |
|
251 | + try { |
|
252 | + $result = $this->image->writeImage($file); |
|
253 | + } catch(ImagickException $e) { |
|
254 | 254 | if ($this->debug) error_log($e->getMessage()); |
255 | 255 | } |
256 | 256 | |
257 | - if (!$file) { |
|
258 | - echo $this->image; |
|
259 | - $this->image->clear(); |
|
257 | + if (!$file) { |
|
258 | + echo $this->image; |
|
259 | + $this->image->clear(); |
|
260 | 260 | $this->image->destroy(); |
261 | - } else { |
|
262 | - $this->image->clear(); |
|
261 | + } else { |
|
262 | + $this->image->clear(); |
|
263 | 263 | $this->image->destroy(); |
264 | - return $result; |
|
265 | - } |
|
266 | - } |
|
264 | + return $result; |
|
265 | + } |
|
266 | + } |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
@@ -285,21 +285,21 @@ discard block |
||
285 | 285 | $this->fill_image_info(); |
286 | 286 | |
287 | 287 | switch ($this->type) { |
288 | - case 0: |
|
289 | - $handler = false; |
|
290 | - break; |
|
291 | - case 1 : |
|
288 | + case 0: |
|
289 | + $handler = false; |
|
290 | + break; |
|
291 | + case 1 : |
|
292 | 292 | $handler = @imagecreatefromgif($this->path); |
293 | 293 | $this->type = 'gif'; |
294 | 294 | break; |
295 | - case 2 : |
|
295 | + case 2 : |
|
296 | 296 | $handler = @imagecreatefromjpeg($this->path); |
297 | 297 | $this->type = 'jpg'; |
298 | 298 | break; |
299 | - case 3 : |
|
300 | - $handler = @imagecreatefrompng($this->path); |
|
301 | - $this->type = 'png'; |
|
302 | - break; |
|
299 | + case 3 : |
|
300 | + $handler = @imagecreatefrompng($this->path); |
|
301 | + $this->type = 'png'; |
|
302 | + break; |
|
303 | 303 | } |
304 | 304 | if ($handler) { |
305 | 305 | $this->image_validated = true; |
@@ -313,29 +313,29 @@ discard block |
||
313 | 313 | { |
314 | 314 | $return_array = array('width'=>0,'height'=>0); |
315 | 315 | if ($this->image_validated) { |
316 | - $return_array = array('width'=>$this->width,'height'=>$this->height); |
|
316 | + $return_array = array('width'=>$this->width,'height'=>$this->height); |
|
317 | 317 | } |
318 | 318 | return $return_array; |
319 | - } |
|
319 | + } |
|
320 | 320 | |
321 | 321 | public function fill_image_info() |
322 | 322 | { |
323 | - if (file_exists($this->path)) { |
|
324 | - $image_info = getimagesize($this->path); |
|
325 | - $this->width = $image_info[0]; |
|
326 | - $this->height = $image_info[1]; |
|
327 | - $this->type = $image_info[2]; |
|
328 | - } else { |
|
329 | - $this->width = 0; |
|
330 | - $this->height = 0; |
|
331 | - $this->type = 0; |
|
332 | - } |
|
323 | + if (file_exists($this->path)) { |
|
324 | + $image_info = getimagesize($this->path); |
|
325 | + $this->width = $image_info[0]; |
|
326 | + $this->height = $image_info[1]; |
|
327 | + $this->type = $image_info[2]; |
|
328 | + } else { |
|
329 | + $this->width = 0; |
|
330 | + $this->height = 0; |
|
331 | + $this->type = 0; |
|
332 | + } |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
336 | 336 | { |
337 | 337 | if (!$this->image_validated) return false; |
338 | - if ($border == 1) { |
|
338 | + if ($border == 1) { |
|
339 | 339 | if ($specific_size) { |
340 | 340 | $width = $thumbw; |
341 | 341 | $height = $thumbh; |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | $width = (int)($this->width * $scale); |
345 | 345 | $height = (int)($this->height * $scale); |
346 | 346 | } |
347 | - $deltaw = (int)(($thumbw - $width) / 2); |
|
348 | - $deltah = (int)(($thumbh - $height) / 2); |
|
349 | - $dst_img = @ImageCreateTrueColor($thumbw, $thumbh); |
|
350 | - @imagealphablending($dst_img, false); |
|
351 | - @imagesavealpha($dst_img, true); |
|
352 | - if (!empty($this->color)) { |
|
353 | - @imagefill($dst_img, 0, 0, $this->color); |
|
354 | - } |
|
355 | - $this->width = $thumbw; |
|
356 | - $this->height = $thumbh; |
|
357 | - } elseif ($border == 0) { |
|
347 | + $deltaw = (int)(($thumbw - $width) / 2); |
|
348 | + $deltah = (int)(($thumbh - $height) / 2); |
|
349 | + $dst_img = @ImageCreateTrueColor($thumbw, $thumbh); |
|
350 | + @imagealphablending($dst_img, false); |
|
351 | + @imagesavealpha($dst_img, true); |
|
352 | + if (!empty($this->color)) { |
|
353 | + @imagefill($dst_img, 0, 0, $this->color); |
|
354 | + } |
|
355 | + $this->width = $thumbw; |
|
356 | + $this->height = $thumbh; |
|
357 | + } elseif ($border == 0) { |
|
358 | 358 | if ($specific_size) { |
359 | 359 | $width = $thumbw; |
360 | 360 | $height = $thumbh; |
@@ -363,19 +363,19 @@ discard block |
||
363 | 363 | $width = (int)($this->width * $scale); |
364 | 364 | $height = (int)($this->height * $scale); |
365 | 365 | } |
366 | - $deltaw = 0; |
|
367 | - $deltah = 0; |
|
368 | - $dst_img = @ImageCreateTrueColor($width, $height); |
|
369 | - @imagealphablending($dst_img, false); |
|
370 | - @imagesavealpha($dst_img, true); |
|
371 | - $this->width = $width; |
|
372 | - $this->height = $height; |
|
373 | - } |
|
374 | - $src_img = $this->bg; |
|
375 | - @ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img)); |
|
376 | - $this->bg = $dst_img; |
|
377 | - @imagedestroy($src_img); |
|
378 | - } |
|
366 | + $deltaw = 0; |
|
367 | + $deltah = 0; |
|
368 | + $dst_img = @ImageCreateTrueColor($width, $height); |
|
369 | + @imagealphablending($dst_img, false); |
|
370 | + @imagesavealpha($dst_img, true); |
|
371 | + $this->width = $width; |
|
372 | + $this->height = $height; |
|
373 | + } |
|
374 | + $src_img = $this->bg; |
|
375 | + @ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img)); |
|
376 | + $this->bg = $dst_img; |
|
377 | + @imagedestroy($src_img); |
|
378 | + } |
|
379 | 379 | |
380 | 380 | /** |
381 | 381 | * @author José Loguercio <[email protected]> |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
390 | 390 | if (!$this->image_validated) return false; |
391 | 391 | $this->width = $width; |
392 | - $this->height = $height; |
|
392 | + $this->height = $height; |
|
393 | 393 | $src = null; |
394 | 394 | $dest = @imagecreatetruecolor($width, $height); |
395 | 395 | $type = $this->type; |
@@ -400,56 +400,56 @@ discard block |
||
400 | 400 | @imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height); |
401 | 401 | @imagejpeg($dest, $this->path); |
402 | 402 | break; |
403 | - case 'png' : |
|
403 | + case 'png' : |
|
404 | 404 | $src = @imagecreatefrompng($this->path); |
405 | 405 | @imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height); |
406 | 406 | @imagepng($dest, $this->path); |
407 | 407 | break; |
408 | - case 'gif' : |
|
409 | - $src = @imagecreatefromgif($this->path); |
|
408 | + case 'gif' : |
|
409 | + $src = @imagecreatefromgif($this->path); |
|
410 | 410 | @imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height); |
411 | 411 | @imagegif($dest, $this->path); |
412 | - break; |
|
412 | + break; |
|
413 | 413 | default: return 0; |
414 | 414 | } |
415 | 415 | @imagedestroy($dest); |
416 | 416 | @imagedestroy($src); |
417 | 417 | } |
418 | 418 | |
419 | - public function send_image($file = '', $compress = -1, $convert_file_to = null) |
|
419 | + public function send_image($file = '', $compress = -1, $convert_file_to = null) |
|
420 | 420 | { |
421 | - if (!$this->image_validated) return false; |
|
421 | + if (!$this->image_validated) return false; |
|
422 | 422 | $compress = (int)$compress; |
423 | 423 | $type = $this->type; |
424 | 424 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
425 | 425 | $type = $convert_file_to; |
426 | 426 | } |
427 | - switch ($type) { |
|
428 | - case 'jpeg': |
|
429 | - case 'jpg': |
|
430 | - if (!$file) header("Content-type: image/jpeg"); |
|
431 | - if ($compress == -1) $compress = 100; |
|
432 | - return imagejpeg($this->bg, $file, $compress); |
|
433 | - break; |
|
434 | - case 'png': |
|
435 | - if (!$file) header("Content-type: image/png"); |
|
436 | - if ($compress != -1) { |
|
437 | - @imagetruecolortopalette($this->bg, true, $compress); |
|
438 | - } |
|
439 | - return imagepng($this->bg, $file, $compress); |
|
440 | - break; |
|
441 | - case 'gif': |
|
442 | - if (!$file) header("Content-type: image/gif"); |
|
443 | - if ($compress != -1) { |
|
444 | - @imagetruecolortopalette($this->bg, true, $compress); |
|
445 | - } |
|
446 | - return imagegif($this->bg, $file, $compress); |
|
447 | - break; |
|
448 | - default: return 0; |
|
449 | - } |
|
450 | - // TODO: Occupied memory is not released, because the following fragment of code is actually dead. |
|
451 | - @imagedestroy($this->bg); |
|
452 | - } |
|
427 | + switch ($type) { |
|
428 | + case 'jpeg': |
|
429 | + case 'jpg': |
|
430 | + if (!$file) header("Content-type: image/jpeg"); |
|
431 | + if ($compress == -1) $compress = 100; |
|
432 | + return imagejpeg($this->bg, $file, $compress); |
|
433 | + break; |
|
434 | + case 'png': |
|
435 | + if (!$file) header("Content-type: image/png"); |
|
436 | + if ($compress != -1) { |
|
437 | + @imagetruecolortopalette($this->bg, true, $compress); |
|
438 | + } |
|
439 | + return imagepng($this->bg, $file, $compress); |
|
440 | + break; |
|
441 | + case 'gif': |
|
442 | + if (!$file) header("Content-type: image/gif"); |
|
443 | + if ($compress != -1) { |
|
444 | + @imagetruecolortopalette($this->bg, true, $compress); |
|
445 | + } |
|
446 | + return imagegif($this->bg, $file, $compress); |
|
447 | + break; |
|
448 | + default: return 0; |
|
449 | + } |
|
450 | + // TODO: Occupied memory is not released, because the following fragment of code is actually dead. |
|
451 | + @imagedestroy($this->bg); |
|
452 | + } |
|
453 | 453 | |
454 | 454 | /** |
455 | 455 | * Convert image to black & white |
@@ -838,18 +838,18 @@ |
||
838 | 838 | $email = false; |
839 | 839 | } |
840 | 840 | |
841 | - if ($email) { |
|
842 | - $condition = "LOWER(email) = '".Database::escape_string($username)."' "; |
|
843 | - } else { |
|
841 | + if ($email) { |
|
842 | + $condition = "LOWER(email) = '".Database::escape_string($username)."' "; |
|
843 | + } else { |
|
844 | 844 | $condition = "LOWER(username) = '".Database::escape_string($username)."'"; |
845 | 845 | } |
846 | 846 | |
847 | - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
848 | - $query = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email, |
|
847 | + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
848 | + $query = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email, |
|
849 | 849 | status AS status, official_code, phone, picture_uri, creator_id |
850 | 850 | FROM $tbl_user |
851 | 851 | WHERE ( $condition AND active = 1) "; |
852 | - $result = Database::query($query); |
|
852 | + $result = Database::query($query); |
|
853 | 853 | $num_rows = Database::num_rows($result); |
854 | 854 | if ($result && $num_rows > 0) { |
855 | 855 | return Database::fetch_assoc($result); |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Manage specific tools |
|
4 | - * @package chamilo.library |
|
5 | - */ |
|
3 | + * Manage specific tools |
|
4 | + * @package chamilo.library |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | // Database table definitions |
8 | 8 | $table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD); |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | * @param int Internal ID used in specific tool table |
238 | 238 | */ |
239 | 239 | function delete_all_values_for_item($course_id, $tool_id, $ref_id) { |
240 | - $table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES); |
|
241 | - $sql = 'DELETE FROM %s WHERE course_code = \'%s\' AND tool_id = \'%s\' AND ref_id = %s'; |
|
242 | - $sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id); |
|
243 | - Database::query($sql); |
|
240 | + $table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES); |
|
241 | + $sql = 'DELETE FROM %s WHERE course_code = \'%s\' AND tool_id = \'%s\' AND ref_id = %s'; |
|
242 | + $sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id); |
|
243 | + Database::query($sql); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | ); |
26 | 26 | public $is_course_model = true; |
27 | 27 | |
28 | - public function __construct() |
|
28 | + public function __construct() |
|
29 | 29 | { |
30 | 30 | $this->table = Database::get_course_table(TABLE_TIMELINE); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Get the count of elements |
@@ -52,16 +52,16 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Displays the title + grid |
54 | 54 | */ |
55 | - public function listing() |
|
55 | + public function listing() |
|
56 | 56 | { |
57 | - // action links |
|
58 | - $html = '<div class="actions">'; |
|
57 | + // action links |
|
58 | + $html = '<div class="actions">'; |
|
59 | 59 | //$html .= '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>'; |
60 | - $html .= '<a href="'.api_get_self().'?action=add">'.Display::return_icon('add.png', get_lang('Add'),'','32').'</a>'; |
|
61 | - $html .= '</div>'; |
|
60 | + $html .= '<a href="'.api_get_self().'?action=add">'.Display::return_icon('add.png', get_lang('Add'),'','32').'</a>'; |
|
61 | + $html .= '</div>'; |
|
62 | 62 | $html .= Display::grid_html('timelines'); |
63 | 63 | return $html; |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | 66 | public function get_status_list() |
67 | 67 | { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | $form->addElement('text', 'headline', get_lang('Name'), array('size' => '70')); |
91 | 91 | //$form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Careers','Width' => '100%', 'Height' => '250')); |
92 | - $status_list = $this->get_status_list(); |
|
92 | + $status_list = $this->get_status_list(); |
|
93 | 93 | $form->addElement('select', 'status', get_lang('Status'), $status_list); |
94 | 94 | if ($action == 'edit') { |
95 | 95 | //$form->addElement('text', 'created_at', get_lang('CreatedAt')); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | // Setting the rules |
175 | 175 | $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); |
176 | - return $form; |
|
176 | + return $form; |
|
177 | 177 | |
178 | 178 | } |
179 | 179 | |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | public function save_item($params) |
185 | 185 | { |
186 | 186 | $params['c_id'] = api_get_course_int_id(); |
187 | - $id = parent::save($params); |
|
188 | - if (!empty($id)) { |
|
189 | - //event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); |
|
190 | - } |
|
191 | - return $id; |
|
187 | + $id = parent::save($params); |
|
188 | + if (!empty($id)) { |
|
189 | + //event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); |
|
190 | + } |
|
191 | + return $id; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | $params['c_id'] = api_get_course_int_id(); |
200 | 200 | $params['parent_id'] = '0'; |
201 | 201 | $params['type'] = 'default'; |
202 | - $id = parent::save($params); |
|
203 | - if (!empty($id)) { |
|
204 | - //event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); |
|
205 | - } |
|
206 | - return $id; |
|
202 | + $id = parent::save($params); |
|
203 | + if (!empty($id)) { |
|
204 | + //event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); |
|
205 | + } |
|
206 | + return $id; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | public function delete($id) { |
210 | - parent::delete($id); |
|
211 | - //event_system(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); |
|
210 | + parent::delete($id); |
|
211 | + //event_system(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id()); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | public function get_url($id) { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $item['asset'] = array( 'media' => $item['media'], |
248 | 248 | 'credit' => $item['media_credit'], |
249 | 249 | 'caption' => $item['media_caption'], |
250 | - ); |
|
250 | + ); |
|
251 | 251 | |
252 | 252 | //Cleaning items |
253 | 253 | unset($item['id']); |