@@ -2,7 +2,7 @@ |
||
2 | 2 | // $Id: xbd.php,v 1.1.8.1 2008/06/12 20:34:32 smk Exp $ |
3 | 3 | |
4 | 4 | return array( |
5 | - 'en' => array('bols', 'bolt', 'bolp', 'bolh', 'bom', 'bob', 'bobs', 'bos', 'boss', 'bong', 'boj', 'boc', 'bok', 'bot', 'bop', 'boh', |
|
5 | + 'en' => array('bols', 'bolt', 'bolp', 'bolh', 'bom', 'bob', 'bobs', 'bos', 'boss', 'bong', 'boj', 'boc', 'bok', 'bot', 'bop', 'boh', |
|
6 | 6 | 'bwa', 'bwag', 'bwagg', 'bwags', 'bwan', 'bwanj', 'bwanh', 'bwad', 'bwal', 'bwalg', 'bwalm', 'bwalb', 'bwals', 'bwalt', 'bwalp', 'bwalh', |
7 | 7 | 'bwam', 'bwab', 'bwabs', 'bwas', 'bwass', 'bwang', 'bwaj', 'bwac', 'bwak', 'bwat', 'bwap', 'bwah', 'bwae', 'bwaeg', 'bwaegg', 'bwaegs', |
8 | 8 | 'bwaen', 'bwaenj', 'bwaenh', 'bwaed', 'bwael', 'bwaelg', 'bwaelm', 'bwaelb', 'bwaels', 'bwaelt', 'bwaelp', 'bwaelh', 'bwaem', 'bwaeb', 'bwaebs', 'bwaes', |
@@ -18,30 +18,30 @@ discard block |
||
18 | 18 | if (api_is_student() && !api_get_setting('student_page_after_login') == '') { |
19 | 19 | $redirect_url = html_entity_decode(api_get_setting('student_page_after_login')); |
20 | 20 | if ($redirect_url[0] == "/") { |
21 | - $redirect_url = substr(api_get_path(WEB_PATH), 0, -1) . $redirect_url; |
|
21 | + $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url; |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | if (api_is_teacher() && !api_get_setting('teacher_page_after_login') == '') { |
25 | 25 | $redirect_url = html_entity_decode(api_get_setting('teacher_page_after_login')); |
26 | 26 | if ($redirect_url[0] == "/") { |
27 | - $redirect_url = substr(api_get_path(WEB_PATH), 0, -1) . $redirect_url; |
|
27 | + $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url; |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | if (api_is_drh() && !api_get_setting('drh_page_after_login') == '') { |
31 | 31 | $redirect_url = html_entity_decode(api_get_setting('drh_page_after_login')); |
32 | 32 | if ($redirect_url[0] == "/") { |
33 | - $redirect_url = substr(api_get_path(WEB_PATH), 0, -1) . $redirect_url; |
|
33 | + $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url; |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | if (api_is_session_admin() && !api_get_setting('sessionadmin_page_after_login') == '') { |
37 | 37 | $redirect_url = html_entity_decode(api_get_setting('sessionadmin_page_after_login')); |
38 | 38 | if ($redirect_url[0] == "/") { |
39 | - $redirect_url = substr(api_get_path(WEB_PATH), 0, -1) . $redirect_url; |
|
39 | + $redirect_url = substr(api_get_path(WEB_PATH), 0, -1).$redirect_url; |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | 43 | if (!empty($redirect_url)) { |
44 | - header('Location: ' . $redirect_url . $param); |
|
44 | + header('Location: '.$redirect_url.$param); |
|
45 | 45 | exit(); |
46 | 46 | } |
47 | 47 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | if (CustomPages::enabled()) { |
50 | 50 | CustomPages::display(CustomPages::INDEX_LOGGED); |
51 | 51 | } |
52 | - header('location: ' . api_get_path(WEB_PATH) . api_get_setting('page_after_login') . $param); |
|
52 | + header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param); |
|
53 | 53 | exit(); |
54 | 54 | } |
55 | 55 | } |
@@ -6022,7 +6022,7 @@ |
||
6022 | 6022 | ]); |
6023 | 6023 | } |
6024 | 6024 | |
6025 | - /** |
|
6025 | + /** |
|
6026 | 6026 | * Get the count of user courses in session |
6027 | 6027 | * @param int $sessionId The session id |
6028 | 6028 | * @return array |
@@ -1588,8 +1588,10 @@ discard block |
||
1588 | 1588 | if (empty($session_visibility)) { |
1589 | 1589 | $session_visibility = $session->getVisibility(); |
1590 | 1590 | //default status loaded if empty |
1591 | - if (empty($session_visibility)) |
|
1592 | - $session_visibility = SESSION_VISIBLE_READ_ONLY; // by default readonly 1 |
|
1591 | + if (empty($session_visibility)) { |
|
1592 | + $session_visibility = SESSION_VISIBLE_READ_ONLY; |
|
1593 | + } |
|
1594 | + // by default readonly 1 |
|
1593 | 1595 | } else { |
1594 | 1596 | if (!in_array($session_visibility, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_INVISIBLE))) { |
1595 | 1597 | $session_visibility = SESSION_VISIBLE_READ_ONLY; |
@@ -2792,10 +2794,11 @@ discard block |
||
2792 | 2794 | c_id = $courseId AND |
2793 | 2795 | user_id = $user_id "; |
2794 | 2796 | $result = Database::query($sql); |
2795 | - if (Database::affected_rows($result) > 0) |
|
2796 | - return true; |
|
2797 | - else |
|
2798 | - return false; |
|
2797 | + if (Database::affected_rows($result) > 0) { |
|
2798 | + return true; |
|
2799 | + } else { |
|
2800 | + return false; |
|
2801 | + } |
|
2799 | 2802 | } else { |
2800 | 2803 | // The user is not subscribed to the session, so make sure |
2801 | 2804 | // he isn't subscribed to a course in this session either |
@@ -2806,10 +2809,11 @@ discard block |
||
2806 | 2809 | c_id = $courseId AND |
2807 | 2810 | user_id = $user_id "; |
2808 | 2811 | $result = Database::query($sql); |
2809 | - if (Database::affected_rows($result) > 0) |
|
2810 | - return true; |
|
2811 | - else |
|
2812 | - return false; |
|
2812 | + if (Database::affected_rows($result) > 0) { |
|
2813 | + return true; |
|
2814 | + } else { |
|
2815 | + return false; |
|
2816 | + } |
|
2813 | 2817 | } |
2814 | 2818 | } else { |
2815 | 2819 | // Assign user as a coach to course |
@@ -1336,9 +1336,9 @@ discard block |
||
1336 | 1336 | * @param integer $sessionCategoryId |
1337 | 1337 | * @param int $visibility |
1338 | 1338 | * @param string $description |
1339 | - * @param bool $showDescription |
|
1339 | + * @param integer $showDescription |
|
1340 | 1340 | * @param int $duration |
1341 | - * @param array $extraFields |
|
1341 | + * @param boolean|null $extraFields |
|
1342 | 1342 | * @param int $sessionAdminId |
1343 | 1343 | * @param boolean $sendSubscriptionNotification Optional. |
1344 | 1344 | * Whether send a mail notification to users being subscribed |
@@ -1558,7 +1558,7 @@ discard block |
||
1558 | 1558 | * @param array $user_list |
1559 | 1559 | * @param int $session_visibility |
1560 | 1560 | * @param bool $empty_users |
1561 | - * @return bool |
|
1561 | + * @return false|null |
|
1562 | 1562 | */ |
1563 | 1563 | public static function suscribe_users_to_session( |
1564 | 1564 | $id_session, |
@@ -1830,7 +1830,7 @@ discard block |
||
1830 | 1830 | * @param array $courseInfo |
1831 | 1831 | * @param int $status |
1832 | 1832 | * @param bool $updateTotal |
1833 | - * @return bool |
|
1833 | + * @return false|null |
|
1834 | 1834 | */ |
1835 | 1835 | public static function removeUsersFromCourseSession( |
1836 | 1836 | $userList, |
@@ -1896,7 +1896,7 @@ discard block |
||
1896 | 1896 | * @param string $course_code |
1897 | 1897 | * @param int $session_visibility |
1898 | 1898 | * @param bool $removeUsersNotInList |
1899 | - * @return bool |
|
1899 | + * @return false|null |
|
1900 | 1900 | */ |
1901 | 1901 | public static function subscribe_users_to_session_course( |
1902 | 1902 | $user_list, |
@@ -2079,7 +2079,7 @@ discard block |
||
2079 | 2079 | * @param bool $removeExistingCoursesWithUsers Whether to unsubscribe |
2080 | 2080 | * existing courses and users (true, default) or not (false) |
2081 | 2081 | * @param $copyEvaluation from base course to session course |
2082 | - * @return void Nothing, or false on error |
|
2082 | + * @return false|null Nothing, or false on error |
|
2083 | 2083 | * */ |
2084 | 2084 | public static function add_courses_to_session( |
2085 | 2085 | $sessionId, |
@@ -2275,6 +2275,8 @@ discard block |
||
2275 | 2275 | * |
2276 | 2276 | * @param int Session id |
2277 | 2277 | * @param int Course id |
2278 | + * @param integer $session_id |
|
2279 | + * @param integer $course_id |
|
2278 | 2280 | * @return bool True in case of success, false otherwise |
2279 | 2281 | */ |
2280 | 2282 | public static function unsubscribe_course_from_session($session_id, $course_id) |
@@ -2330,7 +2332,7 @@ discard block |
||
2330 | 2332 | * @param string $variable Field's internal variable name |
2331 | 2333 | * @param int $fieldType Field's type |
2332 | 2334 | * @param string $displayText Field's language var name |
2333 | - * @return int new extra field id |
|
2335 | + * @return boolean new extra field id |
|
2334 | 2336 | */ |
2335 | 2337 | public static function create_session_extra_field($variable, $fieldType, $displayText) |
2336 | 2338 | { |
@@ -2349,7 +2351,7 @@ discard block |
||
2349 | 2351 | * @param integer Course ID |
2350 | 2352 | * @param string Field variable name |
2351 | 2353 | * @param string Field value |
2352 | - * @return boolean true if field updated, false otherwise |
|
2354 | + * @return boolean|null true if field updated, false otherwise |
|
2353 | 2355 | */ |
2354 | 2356 | public static function update_session_extra_field_value($sessionId, $variable, $value = '') |
2355 | 2357 | { |
@@ -2554,7 +2556,7 @@ discard block |
||
2554 | 2556 | * @param array id_checked |
2555 | 2557 | * @param bool include delete session |
2556 | 2558 | * @param bool optional, true if the function is called by a webservice, false otherwise. |
2557 | - * @return void Nothing, or false on error |
|
2559 | + * @return boolean Nothing, or false on error |
|
2558 | 2560 | * The parameters is a array to delete sessions |
2559 | 2561 | * */ |
2560 | 2562 | public static function delete_session_category($id_checked, $delete_session = false, $from_ws = false) |
@@ -3049,6 +3051,7 @@ discard block |
||
3049 | 3051 | * @param string $orderCondition |
3050 | 3052 | * @param string $keyword |
3051 | 3053 | * @param string $description |
3054 | + * @param integer $status |
|
3052 | 3055 | * @return array sessions |
3053 | 3056 | */ |
3054 | 3057 | public static function getSessionsFollowedByUser( |
@@ -3261,8 +3264,8 @@ discard block |
||
3261 | 3264 | /** |
3262 | 3265 | * Gets the list of courses by session filtered by access_url |
3263 | 3266 | * |
3264 | - * @param $userId |
|
3265 | - * @param $sessionId |
|
3267 | + * @param integer $userId |
|
3268 | + * @param null|integer $sessionId |
|
3266 | 3269 | * @param null $from |
3267 | 3270 | * @param null $limit |
3268 | 3271 | * @param null $column |
@@ -3387,6 +3390,7 @@ discard block |
||
3387 | 3390 | /** |
3388 | 3391 | * Gets the count of courses by session filtered by access_url |
3389 | 3392 | * @param int session id |
3393 | + * @param integer $session_id |
|
3390 | 3394 | * @return array list of courses |
3391 | 3395 | */ |
3392 | 3396 | public static function getCourseCountBySessionId($session_id, $keyword = null) |
@@ -3638,6 +3642,7 @@ discard block |
||
3638 | 3642 | * Updates a session status |
3639 | 3643 | * @param int session id |
3640 | 3644 | * @param int status |
3645 | + * @param integer $status |
|
3641 | 3646 | */ |
3642 | 3647 | public static function set_session_status($session_id, $status) |
3643 | 3648 | { |
@@ -3949,7 +3954,7 @@ discard block |
||
3949 | 3954 | |
3950 | 3955 | /** |
3951 | 3956 | * @param $id |
3952 | - * @return bool |
|
3957 | + * @return null|boolean |
|
3953 | 3958 | */ |
3954 | 3959 | public static function protect_teacher_session_edit($id) |
3955 | 3960 | { |
@@ -4013,7 +4018,7 @@ discard block |
||
4013 | 4018 | * true: if the session exists it will be updated. |
4014 | 4019 | * false: if session exists a new session will be created adding a counter session1, session2, etc |
4015 | 4020 | * @param int $defaultUserId |
4016 | - * @param mixed $logger |
|
4021 | + * @param Logger $logger |
|
4017 | 4022 | * @param array $extraFields convert a file row to an extra field. Example in CSV file there's a SessionID then it will |
4018 | 4023 | * converted to extra_external_session_id if you set this: array('SessionId' => 'extra_external_session_id') |
4019 | 4024 | * @param string $extraFieldId |
@@ -5255,7 +5260,6 @@ discard block |
||
5255 | 5260 | * @param string $lastConnectionDate |
5256 | 5261 | * @param array $sessionIdList |
5257 | 5262 | * @param array $studentIdList |
5258 | - * @param int $userStatus STUDENT|COURSEMANAGER constants |
|
5259 | 5263 | * |
5260 | 5264 | * @return array|int |
5261 | 5265 | */ |
@@ -5407,7 +5411,7 @@ discard block |
||
5407 | 5411 | /** |
5408 | 5412 | * Get the list of course tools that have to be dealt with in case of |
5409 | 5413 | * registering any course to a session |
5410 | - * @return array The list of tools to be dealt with (literal names) |
|
5414 | + * @return string[] The list of tools to be dealt with (literal names) |
|
5411 | 5415 | */ |
5412 | 5416 | public static function getCourseToolToBeManaged() |
5413 | 5417 | { |
@@ -5421,7 +5425,7 @@ discard block |
||
5421 | 5425 | * Calls the methods bound to each tool when a course is registered into a session |
5422 | 5426 | * @param int $sessionId |
5423 | 5427 | * @param int $courseId |
5424 | - * @return void |
|
5428 | + * @return boolean|null |
|
5425 | 5429 | */ |
5426 | 5430 | public static function installCourse($sessionId, $courseId) |
5427 | 5431 | { |
@@ -6061,6 +6065,7 @@ discard block |
||
6061 | 6065 | * @param int $categoryId The internal ID of the session category |
6062 | 6066 | * @param string $target Value to search for in the session field values |
6063 | 6067 | * @param array $extraFields A list of fields to be scanned and returned |
6068 | + * @param DateTime $publicationDate |
|
6064 | 6069 | * @return mixed |
6065 | 6070 | */ |
6066 | 6071 | public static function getShortSessionListAndExtraByCategory($categoryId, $target, $extraFields = null, $publicationDate = null) |
@@ -7390,7 +7395,7 @@ discard block |
||
7390 | 7395 | /** |
7391 | 7396 | * Get link to the admin page for this session |
7392 | 7397 | * @param int $id Session ID |
7393 | - * @return mixed URL to the admin page to manage the session, or false on error |
|
7398 | + * @return false|string URL to the admin page to manage the session, or false on error |
|
7394 | 7399 | */ |
7395 | 7400 | public static function getAdminPath($id) |
7396 | 7401 | { |
@@ -7407,7 +7412,7 @@ discard block |
||
7407 | 7412 | * If a course is provided, build the link to the course |
7408 | 7413 | * @param int $id Session ID |
7409 | 7414 | * @param int $courseId Course ID (optional) in case the link has to send straight to the course |
7410 | - * @return mixed URL to the page to use the session, or false on error |
|
7415 | + * @return false|string URL to the page to use the session, or false on error |
|
7411 | 7416 | */ |
7412 | 7417 | public static function getPath($id, $courseId = 0) |
7413 | 7418 | { |
@@ -7505,7 +7510,7 @@ discard block |
||
7505 | 7510 | /** |
7506 | 7511 | * Return true if coach is allowed to access this session |
7507 | 7512 | * @param int $sessionId |
7508 | - * @return bool |
|
7513 | + * @return integer |
|
7509 | 7514 | */ |
7510 | 7515 | public static function isSessionDateOkForCoach($sessionId) |
7511 | 7516 | { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | return $msg; |
144 | 144 | } |
145 | 145 | } else { |
146 | - $rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='" . $name . "'"); |
|
146 | + $rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".$name."'"); |
|
147 | 147 | if (Database::num_rows($rs)) { |
148 | 148 | $msg = get_lang('SessionNameAlreadyExists'); |
149 | 149 | return $msg; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | public static function session_name_exists($name) |
257 | 257 | { |
258 | 258 | $name = Database::escape_string($name); |
259 | - $sql = "SELECT COUNT(*) as count FROM " . Database::get_main_table(TABLE_MAIN_SESSION) . " |
|
259 | + $sql = "SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." |
|
260 | 260 | WHERE name = '$name'"; |
261 | 261 | $result = Database::fetch_array(Database::query($sql)); |
262 | 262 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $where .= " AND ( |
288 | 288 | s.session_admin_id = $user_id OR |
289 | 289 | sru.user_id = '$user_id' AND |
290 | - sru.relation_type = '" . SESSION_RELATION_TYPE_RRHH . "' |
|
290 | + sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' |
|
291 | 291 | ) |
292 | 292 | "; |
293 | 293 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $where_condition = str_replace('category_name', 'sc.name', $where_condition); |
306 | 306 | $where_condition = str_replace( |
307 | 307 | array("AND session_active = '1' )", " AND ( session_active = '1' )"), |
308 | - array(') GROUP BY s.name HAVING session_active = 1 ', " GROUP BY s.name HAVING session_active = 1 " ) |
|
308 | + array(') GROUP BY s.name HAVING session_active = 1 ', " GROUP BY s.name HAVING session_active = 1 ") |
|
309 | 309 | , $where_condition |
310 | 310 | ); |
311 | 311 | $where_condition = str_replace( |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | |
351 | 351 | $access_url_id = api_get_current_access_url_id(); |
352 | 352 | if ($access_url_id != -1) { |
353 | - $where.= " AND ar.access_url_id = $access_url_id "; |
|
353 | + $where .= " AND ar.access_url_id = $access_url_id "; |
|
354 | 354 | |
355 | 355 | $sql = "SELECT count(id) as total_rows FROM ( |
356 | 356 | SELECT DISTINCT |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | if (api_is_session_admin() && |
401 | 401 | api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false' |
402 | 402 | ) { |
403 | - $where .=" AND s.session_admin_id = $user_id "; |
|
403 | + $where .= " AND s.session_admin_id = $user_id "; |
|
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | 407 | if (!api_is_platform_admin() && api_is_teacher() && |
408 | 408 | api_get_setting('allow_teachers_to_create_sessions') == 'true' |
409 | 409 | ) { |
410 | - $where .=" AND s.id_coach = $user_id "; |
|
410 | + $where .= " AND s.id_coach = $user_id "; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | $extra_field = new ExtraField('session'); |
@@ -457,10 +457,10 @@ discard block |
||
457 | 457 | $query = "$select FROM $tbl_session s $inject_joins $where $inject_where"; |
458 | 458 | |
459 | 459 | if (api_is_multiple_url_enabled()) { |
460 | - $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
460 | + $table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
461 | 461 | $access_url_id = api_get_current_access_url_id(); |
462 | 462 | if ($access_url_id != -1) { |
463 | - $where.= " AND ar.access_url_id = $access_url_id "; |
|
463 | + $where .= " AND ar.access_url_id = $access_url_id "; |
|
464 | 464 | $query = "$select |
465 | 465 | FROM $tbl_session s $inject_joins |
466 | 466 | INNER JOIN $table_access_url_rel_session ar |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | INNER JOIN $tbl_lp l ON l.id = v.lp_id |
565 | 565 | INNER JOIN $tbl_user u ON u.user_id = v.user_id |
566 | 566 | INNER JOIN $tbl_course c |
567 | - WHERE v.session_id = " . $sessionId; |
|
567 | + WHERE v.session_id = ".$sessionId; |
|
568 | 568 | $result_rows = Database::query($sql); |
569 | 569 | $row = Database::fetch_array($result_rows); |
570 | 570 | $num = $row['total_rows']; |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | |
617 | 617 | $limit = null; |
618 | 618 | if (!empty($options['limit'])) { |
619 | - $limit = " LIMIT " . $options['limit']; |
|
619 | + $limit = " LIMIT ".$options['limit']; |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | if (!empty($options['where'])) { |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | |
626 | 626 | $order = null; |
627 | 627 | if (!empty($options['order'])) { |
628 | - $order = " ORDER BY " . $options['order']; |
|
628 | + $order = " ORDER BY ".$options['order']; |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | $sql = "SELECT u.user_id, u.lastname, u.firstname, u.username, u.email, s.c_id |
@@ -684,13 +684,13 @@ discard block |
||
684 | 684 | foreach ($lessons as $lesson) { |
685 | 685 | $data[$lesson['id']] = (!empty($user_lessons[$lesson['id']]['progress'])) ? $user_lessons[$lesson['id']]['progress'] : 0; |
686 | 686 | $progress += $data[$lesson['id']]; |
687 | - $data[$lesson['id']] = $data[$lesson['id']] . '%'; |
|
687 | + $data[$lesson['id']] = $data[$lesson['id']].'%'; |
|
688 | 688 | $count++; |
689 | 689 | } |
690 | 690 | if ($count == 0) { |
691 | 691 | $data['total'] = 0; |
692 | 692 | } else { |
693 | - $data['total'] = round($progress / $count, 2) . '%'; |
|
693 | + $data['total'] = round($progress / $count, 2).'%'; |
|
694 | 694 | } |
695 | 695 | $table[] = $data; |
696 | 696 | } |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | |
732 | 732 | $limit = null; |
733 | 733 | if (!empty($options['limit'])) { |
734 | - $limit = " LIMIT " . $options['limit']; |
|
734 | + $limit = " LIMIT ".$options['limit']; |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | if (!empty($options['where'])) { |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | |
741 | 741 | $order = null; |
742 | 742 | if (!empty($options['order'])) { |
743 | - $order = " ORDER BY " . $options['order']; |
|
743 | + $order = " ORDER BY ".$options['order']; |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | $sql = "SELECT u.user_id, u.lastname, u.firstname, u.username, u.email, s.c_id |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | $limit = null; |
844 | 844 | if (!empty($options['limit'])) { |
845 | - $limit = " LIMIT " . $options['limit']; |
|
845 | + $limit = " LIMIT ".$options['limit']; |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | if (!empty($options['where'])) { |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | |
852 | 852 | $order = null; |
853 | 853 | if (!empty($options['order'])) { |
854 | - $order = " ORDER BY " . $options['order']; |
|
854 | + $order = " ORDER BY ".$options['order']; |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | //TODO, fix create report without session |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | /** |
885 | 885 | * Lessons |
886 | 886 | */ |
887 | - $sql = "SELECT * FROM $tbl_course_lp WHERE c_id = %s "; //AND session_id = %s |
|
887 | + $sql = "SELECT * FROM $tbl_course_lp WHERE c_id = %s "; //AND session_id = %s |
|
888 | 888 | $sql_query = sprintf($sql, $course['real_id']); |
889 | 889 | $result = Database::query($sql_query); |
890 | 890 | $arrLesson = array(array()); |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | if (empty($arrLesson[$row['session_id']]['lessons_total'])) { |
893 | 893 | $arrLesson[$row['session_id']]['lessons_total'] = 1; |
894 | 894 | } else { |
895 | - $arrLesson[$row['session_id']]['lessons_total'] ++; |
|
895 | + $arrLesson[$row['session_id']]['lessons_total']++; |
|
896 | 896 | } |
897 | 897 | } |
898 | 898 | |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | $course['real_id'] |
960 | 960 | ); |
961 | 961 | foreach ($user_list as $user_id) { |
962 | - isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id] ++ : $survey_user_list[$user_id] = 1; |
|
962 | + isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id]++ : $survey_user_list[$user_id] = 1; |
|
963 | 963 | } |
964 | 964 | } |
965 | 965 | |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | $assignments_done = Tracking::count_student_assignments($user['user_id'], $course['code'], $user['id_session']); |
1014 | 1014 | $assignments_left = $assignments_total - $assignments_done; |
1015 | 1015 | if (!empty($assignments_total)) { |
1016 | - $assignments_progress = round((( $assignments_done * 100 ) / $assignments_total), 2); |
|
1016 | + $assignments_progress = round((($assignments_done * 100) / $assignments_total), 2); |
|
1017 | 1017 | } else { |
1018 | 1018 | $assignments_progress = 0; |
1019 | 1019 | } |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | $wiki_read = $row['count']; |
1044 | 1044 | $wiki_unread = $wiki_total - $wiki_read; |
1045 | 1045 | if (!empty($wiki_total)) { |
1046 | - $wiki_progress = round((( $wiki_read * 100 ) / $wiki_total), 2); |
|
1046 | + $wiki_progress = round((($wiki_read * 100) / $wiki_total), 2); |
|
1047 | 1047 | } else { |
1048 | 1048 | $wiki_progress = 0; |
1049 | 1049 | } |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | $surveys_done = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0); |
1053 | 1053 | $surveys_left = $surveys_total - $surveys_done; |
1054 | 1054 | if (!empty($surveys_total)) { |
1055 | - $surveys_progress = round((( $surveys_done * 100 ) / $surveys_total), 2); |
|
1055 | + $surveys_progress = round((($surveys_done * 100) / $surveys_total), 2); |
|
1056 | 1056 | } else { |
1057 | 1057 | $surveys_progress = 0; |
1058 | 1058 | } |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | ); |
1066 | 1066 | $forums_left = $forums_total - $forums_done; |
1067 | 1067 | if (!empty($forums_total)) { |
1068 | - $forums_progress = round((( $forums_done * 100 ) / $forums_total), 2); |
|
1068 | + $forums_progress = round((($forums_done * 100) / $forums_total), 2); |
|
1069 | 1069 | } else { |
1070 | 1070 | $forums_progress = 0; |
1071 | 1071 | } |
@@ -1073,58 +1073,58 @@ discard block |
||
1073 | 1073 | //Overall Total |
1074 | 1074 | $overall_total = ($course_description_progress + $exercises_progress + $forums_progress + $assignments_progress + $wiki_progress + $surveys_progress) / 6; |
1075 | 1075 | |
1076 | - $link = '<a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/myStudents.php?student=' . $user[0] . '&details=true&course=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>'; |
|
1077 | - $linkForum = '<a href="' . api_get_path(WEB_CODE_PATH) . 'forum/index.php?cidReq=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>'; |
|
1078 | - $linkWork = '<a href="' . api_get_path(WEB_CODE_PATH) . 'work/work.php?cidReq=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>'; |
|
1079 | - $linkWiki = '<a href="' . api_get_path(WEB_CODE_PATH) . 'wiki/index.php?cidReq=' . $course['code'] . '&session_id=' . $user['id_session'] . '&action=statistics"> %s </a>'; |
|
1080 | - $linkSurvey = '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?cidReq=' . $course['code'] . '&id_session=' . $user['id_session'] . '"> %s </a>'; |
|
1076 | + $link = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$user[0].'&details=true&course='.$course['code'].'&id_session='.$user['id_session'].'"> %s </a>'; |
|
1077 | + $linkForum = '<a href="'.api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$course['code'].'&id_session='.$user['id_session'].'"> %s </a>'; |
|
1078 | + $linkWork = '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?cidReq='.$course['code'].'&id_session='.$user['id_session'].'"> %s </a>'; |
|
1079 | + $linkWiki = '<a href="'.api_get_path(WEB_CODE_PATH).'wiki/index.php?cidReq='.$course['code'].'&session_id='.$user['id_session'].'&action=statistics"> %s </a>'; |
|
1080 | + $linkSurvey = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?cidReq='.$course['code'].'&id_session='.$user['id_session'].'"> %s </a>'; |
|
1081 | 1081 | |
1082 | 1082 | $table[] = array( |
1083 | 1083 | 'lastname' => $user[1], |
1084 | 1084 | 'firstname' => $user[2], |
1085 | 1085 | 'username' => $user[3], |
1086 | 1086 | #'profile' => '', |
1087 | - 'total' => round($overall_total, 2) . '%', |
|
1088 | - 'courses' => sprintf($link, $course_description_progress . '%'), |
|
1089 | - 'lessons' => sprintf($link, $lessons_progress . '%'), |
|
1090 | - 'exercises' => sprintf($link, $exercises_progress . '%'), |
|
1091 | - 'forums' => sprintf($link, $forums_progress . '%'), |
|
1092 | - 'homeworks' => sprintf($link, $assignments_progress . '%'), |
|
1093 | - 'wikis' => sprintf($link, $wiki_progress . '%'), |
|
1094 | - 'surveys' => sprintf($link, $surveys_progress . '%'), |
|
1087 | + 'total' => round($overall_total, 2).'%', |
|
1088 | + 'courses' => sprintf($link, $course_description_progress.'%'), |
|
1089 | + 'lessons' => sprintf($link, $lessons_progress.'%'), |
|
1090 | + 'exercises' => sprintf($link, $exercises_progress.'%'), |
|
1091 | + 'forums' => sprintf($link, $forums_progress.'%'), |
|
1092 | + 'homeworks' => sprintf($link, $assignments_progress.'%'), |
|
1093 | + 'wikis' => sprintf($link, $wiki_progress.'%'), |
|
1094 | + 'surveys' => sprintf($link, $surveys_progress.'%'), |
|
1095 | 1095 | //course description |
1096 | - 'course_description_progress' => $course_description_progress . '%', |
|
1096 | + 'course_description_progress' => $course_description_progress.'%', |
|
1097 | 1097 | //lessons |
1098 | 1098 | 'lessons_total' => sprintf($link, $lessons_total), |
1099 | 1099 | 'lessons_done' => sprintf($link, $lessons_done), |
1100 | 1100 | 'lessons_left' => sprintf($link, $lessons_left), |
1101 | - 'lessons_progress' => sprintf($link, $lessons_progress . '%'), |
|
1101 | + 'lessons_progress' => sprintf($link, $lessons_progress.'%'), |
|
1102 | 1102 | //exercises |
1103 | 1103 | 'exercises_total' => sprintf($link, $exercises_total), |
1104 | 1104 | 'exercises_done' => sprintf($link, $exercises_done), |
1105 | 1105 | 'exercises_left' => sprintf($link, $exercises_left), |
1106 | - 'exercises_progress' => sprintf($link, $exercises_progress . '%'), |
|
1106 | + 'exercises_progress' => sprintf($link, $exercises_progress.'%'), |
|
1107 | 1107 | //forums |
1108 | 1108 | 'forums_total' => sprintf($linkForum, $forums_total), |
1109 | 1109 | 'forums_done' => sprintf($linkForum, $forums_done), |
1110 | 1110 | 'forums_left' => sprintf($linkForum, $forums_left), |
1111 | - 'forums_progress' => sprintf($linkForum, $forums_progress . '%'), |
|
1111 | + 'forums_progress' => sprintf($linkForum, $forums_progress.'%'), |
|
1112 | 1112 | //assignments |
1113 | 1113 | 'assignments_total' => sprintf($linkWork, $assignments_total), |
1114 | 1114 | 'assignments_done' => sprintf($linkWork, $assignments_done), |
1115 | 1115 | 'assignments_left' => sprintf($linkWork, $assignments_left), |
1116 | - 'assignments_progress' => sprintf($linkWork, $assignments_progress . '%'), |
|
1116 | + 'assignments_progress' => sprintf($linkWork, $assignments_progress.'%'), |
|
1117 | 1117 | //wiki |
1118 | 1118 | 'wiki_total' => sprintf($linkWiki, $wiki_total), |
1119 | 1119 | 'wiki_revisions' => sprintf($linkWiki, $wiki_revisions), |
1120 | 1120 | 'wiki_read' => sprintf($linkWiki, $wiki_read), |
1121 | 1121 | 'wiki_unread' => sprintf($linkWiki, $wiki_unread), |
1122 | - 'wiki_progress' => sprintf($linkWiki, $wiki_progress . '%'), |
|
1122 | + 'wiki_progress' => sprintf($linkWiki, $wiki_progress.'%'), |
|
1123 | 1123 | //survey |
1124 | 1124 | 'surveys_total' => sprintf($linkSurvey, $surveys_total), |
1125 | 1125 | 'surveys_done' => sprintf($linkSurvey, $surveys_done), |
1126 | 1126 | 'surveys_left' => sprintf($linkSurvey, $surveys_left), |
1127 | - 'surveys_progress' => sprintf($linkSurvey, $surveys_progress . '%'), |
|
1127 | + 'surveys_progress' => sprintf($linkSurvey, $surveys_progress.'%'), |
|
1128 | 1128 | ); |
1129 | 1129 | } |
1130 | 1130 | |
@@ -1204,7 +1204,7 @@ discard block |
||
1204 | 1204 | |
1205 | 1205 | $limit = null; |
1206 | 1206 | if (!empty($options['limit'])) { |
1207 | - $limit = " LIMIT " . $options['limit']; |
|
1207 | + $limit = " LIMIT ".$options['limit']; |
|
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | if (!empty($options['where'])) { |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | |
1214 | 1214 | $order = null; |
1215 | 1215 | if (!empty($options['order'])) { |
1216 | - $order = " ORDER BY " . $options['order']; |
|
1216 | + $order = " ORDER BY ".$options['order']; |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | //TODO add course name |
@@ -1226,7 +1226,7 @@ discard block |
||
1226 | 1226 | " : " |
1227 | 1227 | u.lastname, |
1228 | 1228 | u.firstname, |
1229 | - ") . " |
|
1229 | + ")." |
|
1230 | 1230 | a.logout_course_date, |
1231 | 1231 | a.counter, |
1232 | 1232 | c.title, |
@@ -1308,7 +1308,7 @@ discard block |
||
1308 | 1308 | if (Database::num_rows($result) > 0) { |
1309 | 1309 | $row = Database::fetch_array($result); |
1310 | 1310 | $count = $row['count'] + 1; |
1311 | - $session_name = $session_name . '_' . $count; |
|
1311 | + $session_name = $session_name.'_'.$count; |
|
1312 | 1312 | $result = self::session_name_exists($session_name); |
1313 | 1313 | if (!$result) { |
1314 | 1314 | return $session_name; |
@@ -1388,7 +1388,7 @@ discard block |
||
1388 | 1388 | |
1389 | 1389 | return false; |
1390 | 1390 | } else { |
1391 | - $sql = "SELECT id FROM $tbl_session WHERE name='" . Database::escape_string($name) . "'"; |
|
1391 | + $sql = "SELECT id FROM $tbl_session WHERE name='".Database::escape_string($name)."'"; |
|
1392 | 1392 | $rs = Database::query($sql); |
1393 | 1393 | $exists = false; |
1394 | 1394 | while ($row = Database::fetch_array($rs)) { |
@@ -1754,7 +1754,7 @@ discard block |
||
1754 | 1754 | // Delete users from the session |
1755 | 1755 | if ($empty_users === true) { |
1756 | 1756 | $sql = "DELETE FROM $tbl_session_rel_user |
1757 | - WHERE session_id = $id_session AND relation_type<>" . SESSION_RELATION_TYPE_RRHH . ""; |
|
1757 | + WHERE session_id = $id_session AND relation_type<>".SESSION_RELATION_TYPE_RRHH.""; |
|
1758 | 1758 | Database::query($sql); |
1759 | 1759 | } |
1760 | 1760 | |
@@ -1765,7 +1765,7 @@ discard block |
||
1765 | 1765 | $enreg_user = Database::escape_string($enreg_user); |
1766 | 1766 | $nbr_users++; |
1767 | 1767 | $sql = "INSERT IGNORE INTO $tbl_session_rel_user (relation_type, session_id, user_id, registered_at) |
1768 | - VALUES (0, $id_session, $enreg_user, '" . api_get_utc_datetime() . "')"; |
|
1768 | + VALUES (0, $id_session, $enreg_user, '".api_get_utc_datetime()."')"; |
|
1769 | 1769 | Database::query($sql); |
1770 | 1770 | } |
1771 | 1771 | |
@@ -1855,9 +1855,9 @@ discard block |
||
1855 | 1855 | is_array($courseInfo) ? $courseId = $courseInfo['real_id'] : $courseId = $courseInfo; |
1856 | 1856 | |
1857 | 1857 | $statusCondition = null; |
1858 | - if (isset($status) && !is_null($status)) { |
|
1858 | + if (isset($status) && !is_null($status)) { |
|
1859 | 1859 | $status = intval($status); |
1860 | - $statusCondition = " AND status = $status"; |
|
1860 | + $statusCondition = " AND status = $status"; |
|
1861 | 1861 | } |
1862 | 1862 | |
1863 | 1863 | foreach ($userList as $userId) { |
@@ -1989,7 +1989,7 @@ discard block |
||
1989 | 1989 | if (empty($count)) { |
1990 | 1990 | // If user is not registered to a session then add it. |
1991 | 1991 | $sql = "INSERT IGNORE INTO $tbl_session_rel_user (session_id, user_id, registered_at) |
1992 | - VALUES ($session_id, $enreg_user, '" . api_get_utc_datetime() . "')"; |
|
1992 | + VALUES ($session_id, $enreg_user, '".api_get_utc_datetime()."')"; |
|
1993 | 1993 | Database::query($sql); |
1994 | 1994 | |
1995 | 1995 | $sql = "UPDATE $tbl_session SET nbr_users = nbr_users + 1 |
@@ -2032,7 +2032,7 @@ discard block |
||
2032 | 2032 | WHERE |
2033 | 2033 | session_id = $session_id AND |
2034 | 2034 | user_id = $user_id AND |
2035 | - relation_type <> " . SESSION_RELATION_TYPE_RRHH . ""; |
|
2035 | + relation_type <> ".SESSION_RELATION_TYPE_RRHH.""; |
|
2036 | 2036 | $result = Database::query($delete_sql); |
2037 | 2037 | $return = Database::affected_rows($result); |
2038 | 2038 | |
@@ -2116,7 +2116,7 @@ discard block |
||
2116 | 2116 | FROM $tbl_session_rel_user |
2117 | 2117 | WHERE |
2118 | 2118 | session_id = $sessionId AND |
2119 | - relation_type<>" . SESSION_RELATION_TYPE_RRHH; |
|
2119 | + relation_type<>".SESSION_RELATION_TYPE_RRHH; |
|
2120 | 2120 | $result = Database::query($sql); |
2121 | 2121 | $user_list = Database::store_result($result); |
2122 | 2122 | |
@@ -2128,7 +2128,7 @@ discard block |
||
2128 | 2128 | |
2129 | 2129 | $sql = "DELETE FROM $tbl_session_rel_course |
2130 | 2130 | WHERE |
2131 | - c_id = " . $existingCourse['c_id'] . " AND |
|
2131 | + c_id = ".$existingCourse['c_id']." AND |
|
2132 | 2132 | session_id = $sessionId"; |
2133 | 2133 | Database::query($sql); |
2134 | 2134 | |
@@ -2191,7 +2191,7 @@ discard block |
||
2191 | 2191 | $links = $cat->get_links(null, false, $courseInfo['code'], 0); |
2192 | 2192 | |
2193 | 2193 | $cat->set_session_id($sessionId); |
2194 | - $oldCategoryId= $cat->get_id(); |
|
2194 | + $oldCategoryId = $cat->get_id(); |
|
2195 | 2195 | $newId = $cat->add(); |
2196 | 2196 | $newCategoryIdList[$oldCategoryId] = $newId; |
2197 | 2197 | |
@@ -2379,8 +2379,8 @@ discard block |
||
2379 | 2379 | $return_value = false; |
2380 | 2380 | $sql = "SELECT c_id FROM $tbl_session_course |
2381 | 2381 | WHERE |
2382 | - session_id = " . intval($session_id) . " AND |
|
2383 | - c_id = " . intval($courseId) . ""; |
|
2382 | + session_id = ".intval($session_id)." AND |
|
2383 | + c_id = " . intval($courseId).""; |
|
2384 | 2384 | $result = Database::query($sql); |
2385 | 2385 | $num = Database::num_rows($result); |
2386 | 2386 | if ($num > 0) { |
@@ -2403,8 +2403,8 @@ discard block |
||
2403 | 2403 | } |
2404 | 2404 | |
2405 | 2405 | $sql = 'SELECT * |
2406 | - FROM ' . $tbl_session . ' |
|
2407 | - WHERE name = "' . Database::escape_string($session_name) . '"'; |
|
2406 | + FROM ' . $tbl_session.' |
|
2407 | + WHERE name = "' . Database::escape_string($session_name).'"'; |
|
2408 | 2408 | $result = Database::query($sql); |
2409 | 2409 | $num = Database::num_rows($result); |
2410 | 2410 | if ($num > 0) { |
@@ -2444,8 +2444,8 @@ discard block |
||
2444 | 2444 | $month_end = intval($smonth_end); |
2445 | 2445 | $day_end = intval($sday_end); |
2446 | 2446 | |
2447 | - $date_start = "$year_start-" . (($month_start < 10) ? "0$month_start" : $month_start) . "-" . (($day_start < 10) ? "0$day_start" : $day_start); |
|
2448 | - $date_end = "$year_end-" . (($month_end < 10) ? "0$month_end" : $month_end) . "-" . (($day_end < 10) ? "0$day_end" : $day_end); |
|
2447 | + $date_start = "$year_start-".(($month_start < 10) ? "0$month_start" : $month_start)."-".(($day_start < 10) ? "0$day_start" : $day_start); |
|
2448 | + $date_end = "$year_end-".(($month_end < 10) ? "0$month_end" : $month_end)."-".(($day_end < 10) ? "0$day_end" : $day_end); |
|
2449 | 2449 | |
2450 | 2450 | if (empty($name)) { |
2451 | 2451 | $msg = get_lang('SessionCategoryNameIsRequired'); |
@@ -2517,8 +2517,8 @@ discard block |
||
2517 | 2517 | $month_end = intval($smonth_end); |
2518 | 2518 | $day_end = intval($sday_end); |
2519 | 2519 | $id = intval($id); |
2520 | - $date_start = "$year_start-" . (($month_start < 10) ? "0$month_start" : $month_start) . "-" . (($day_start < 10) ? "0$day_start" : $day_start); |
|
2521 | - $date_end = "$year_end-" . (($month_end < 10) ? "0$month_end" : $month_end) . "-" . (($day_end < 10) ? "0$day_end" : $day_end); |
|
2520 | + $date_start = "$year_start-".(($month_start < 10) ? "0$month_start" : $month_start)."-".(($day_start < 10) ? "0$day_start" : $day_start); |
|
2521 | + $date_end = "$year_end-".(($month_end < 10) ? "0$month_end" : $month_end)."-".(($day_end < 10) ? "0$day_end" : $day_end); |
|
2522 | 2522 | |
2523 | 2523 | if (empty($name)) { |
2524 | 2524 | $msg = get_lang('SessionCategoryNameIsRequired'); |
@@ -2538,13 +2538,13 @@ discard block |
||
2538 | 2538 | if ($date_end <> null) { |
2539 | 2539 | $sql = "UPDATE $tbl_session_category |
2540 | 2540 | SET |
2541 | - name = '" . Database::escape_string($name) . "', |
|
2541 | + name = '".Database::escape_string($name)."', |
|
2542 | 2542 | date_start = '$date_start' , |
2543 | 2543 | date_end = '$date_end' |
2544 | 2544 | WHERE id= $id"; |
2545 | 2545 | } else { |
2546 | 2546 | $sql = "UPDATE $tbl_session_category SET |
2547 | - name = '" . Database::escape_string($name) . "', |
|
2547 | + name = '".Database::escape_string($name)."', |
|
2548 | 2548 | date_start = '$date_start', |
2549 | 2549 | date_end = NULL |
2550 | 2550 | WHERE id= $id"; |
@@ -2574,10 +2574,10 @@ discard block |
||
2574 | 2574 | |
2575 | 2575 | //Setting session_category_id to 0 |
2576 | 2576 | $sql = "UPDATE $tbl_session SET session_category_id = 0 |
2577 | - WHERE session_category_id IN (" . $id_checked . ")"; |
|
2577 | + WHERE session_category_id IN (".$id_checked.")"; |
|
2578 | 2578 | Database::query($sql); |
2579 | 2579 | |
2580 | - $sql = "SELECT id FROM $tbl_session WHERE session_category_id IN (" . $id_checked . ")"; |
|
2580 | + $sql = "SELECT id FROM $tbl_session WHERE session_category_id IN (".$id_checked.")"; |
|
2581 | 2581 | $result = Database::query($sql); |
2582 | 2582 | while ($rows = Database::fetch_array($result)) { |
2583 | 2583 | $session_id = $rows['id']; |
@@ -2589,7 +2589,7 @@ discard block |
||
2589 | 2589 | } |
2590 | 2590 | } |
2591 | 2591 | } |
2592 | - $sql = "DELETE FROM $tbl_session_category WHERE id IN (" . $id_checked . ")"; |
|
2592 | + $sql = "DELETE FROM $tbl_session_category WHERE id IN (".$id_checked.")"; |
|
2593 | 2593 | Database::query($sql); |
2594 | 2594 | |
2595 | 2595 | // Add event to system log |
@@ -2662,7 +2662,7 @@ discard block |
||
2662 | 2662 | $value = Database::escape_string($options['value']); |
2663 | 2663 | $sql_query .= ' AND '; |
2664 | 2664 | if (in_array($field, $availableFields) && in_array($operator, $availableOperator)) { |
2665 | - $sql_query .= $field . " $operator '" . $value . "'"; |
|
2665 | + $sql_query .= $field." $operator '".$value."'"; |
|
2666 | 2666 | } |
2667 | 2667 | } |
2668 | 2668 | } |
@@ -2729,8 +2729,8 @@ discard block |
||
2729 | 2729 | { |
2730 | 2730 | $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); |
2731 | 2731 | $id = api_get_current_access_url_id(); |
2732 | - $sql = 'SELECT * FROM ' . $tbl_session_category . ' |
|
2733 | - WHERE access_url_id = ' . $id . ' |
|
2732 | + $sql = 'SELECT * FROM '.$tbl_session_category.' |
|
2733 | + WHERE access_url_id = ' . $id.' |
|
2734 | 2734 | ORDER BY name ASC'; |
2735 | 2735 | $result = Database::query($sql); |
2736 | 2736 | if (Database::num_rows($result) > 0) { |
@@ -2909,11 +2909,11 @@ discard block |
||
2909 | 2909 | INNER JOIN $tbl_session_rel_access_url a ON (a.session_id = s.session_id) |
2910 | 2910 | WHERE |
2911 | 2911 | s.user_id = $userId AND |
2912 | - relation_type=" . SESSION_RELATION_TYPE_RRHH . " AND |
|
2913 | - access_url_id = " . api_get_current_access_url_id() . ""; |
|
2912 | + relation_type=".SESSION_RELATION_TYPE_RRHH." AND |
|
2913 | + access_url_id = " . api_get_current_access_url_id().""; |
|
2914 | 2914 | } else { |
2915 | 2915 | $sql = "SELECT session_id FROM $tbl_session_rel_user s |
2916 | - WHERE user_id = $userId AND relation_type=" . SESSION_RELATION_TYPE_RRHH . ""; |
|
2916 | + WHERE user_id = $userId AND relation_type=".SESSION_RELATION_TYPE_RRHH.""; |
|
2917 | 2917 | } |
2918 | 2918 | $result = Database::query($sql); |
2919 | 2919 | |
@@ -2923,7 +2923,7 @@ discard block |
||
2923 | 2923 | WHERE |
2924 | 2924 | session_id = {$row['session_id']} AND |
2925 | 2925 | user_id = $userId AND |
2926 | - relation_type=" . SESSION_RELATION_TYPE_RRHH . " "; |
|
2926 | + relation_type=".SESSION_RELATION_TYPE_RRHH." "; |
|
2927 | 2927 | Database::query($sql); |
2928 | 2928 | } |
2929 | 2929 | } |
@@ -2937,8 +2937,8 @@ discard block |
||
2937 | 2937 | VALUES ( |
2938 | 2938 | $session_id, |
2939 | 2939 | $userId, |
2940 | - '" . SESSION_RELATION_TYPE_RRHH . "', |
|
2941 | - '" . api_get_utc_datetime() . "' |
|
2940 | + '".SESSION_RELATION_TYPE_RRHH."', |
|
2941 | + '" . api_get_utc_datetime()."' |
|
2942 | 2942 | )"; |
2943 | 2943 | |
2944 | 2944 | Database::query($sql); |
@@ -2980,8 +2980,8 @@ discard block |
||
2980 | 2980 | WHERE |
2981 | 2981 | sru.user_id = '$userId' AND |
2982 | 2982 | sru.session_id = '$sessionId' AND |
2983 | - sru.relation_type = '" . SESSION_RELATION_TYPE_RRHH . "' AND |
|
2984 | - access_url_id = " . api_get_current_access_url_id() . " |
|
2983 | + sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' AND |
|
2984 | + access_url_id = " . api_get_current_access_url_id()." |
|
2985 | 2985 | "; |
2986 | 2986 | } else { |
2987 | 2987 | $sql = "$select FROM $tbl_session s |
@@ -2990,7 +2990,7 @@ discard block |
||
2990 | 2990 | sru.session_id = s.id AND |
2991 | 2991 | sru.user_id = '$userId' AND |
2992 | 2992 | sru.session_id = '$sessionId' AND |
2993 | - sru.relation_type = '" . SESSION_RELATION_TYPE_RRHH . "' |
|
2993 | + sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' |
|
2994 | 2994 | "; |
2995 | 2995 | } |
2996 | 2996 | |
@@ -3088,7 +3088,7 @@ discard block |
||
3088 | 3088 | |
3089 | 3089 | $limitCondition = null; |
3090 | 3090 | if (!empty($start) && !empty($limit)) { |
3091 | - $limitCondition = " LIMIT " . intval($start) . ", " . intval($limit); |
|
3091 | + $limitCondition = " LIMIT ".intval($start).", ".intval($limit); |
|
3092 | 3092 | } |
3093 | 3093 | |
3094 | 3094 | if (empty($orderCondition)) { |
@@ -3166,26 +3166,26 @@ discard block |
||
3166 | 3166 | |
3167 | 3167 | $sessions = array(); |
3168 | 3168 | if (Database::num_rows($result) > 0) { |
3169 | - $sysUploadPath = api_get_path(SYS_UPLOAD_PATH). 'sessions/'; |
|
3170 | - $webUploadPath = api_get_path(WEB_UPLOAD_PATH). 'sessions/'; |
|
3169 | + $sysUploadPath = api_get_path(SYS_UPLOAD_PATH).'sessions/'; |
|
3170 | + $webUploadPath = api_get_path(WEB_UPLOAD_PATH).'sessions/'; |
|
3171 | 3171 | $imgPath = Display::returnIconPath('session_default_small.png'); |
3172 | 3172 | |
3173 | 3173 | $tableExtraFields = Database::get_main_table(TABLE_EXTRA_FIELD); |
3174 | - $sql = "SELECT id FROM " . $tableExtraFields . " |
|
3174 | + $sql = "SELECT id FROM ".$tableExtraFields." |
|
3175 | 3175 | WHERE extra_field_type = 3 AND variable='image'"; |
3176 | 3176 | $resultField = Database::query($sql); |
3177 | 3177 | $imageFieldId = Database::fetch_assoc($resultField); |
3178 | 3178 | |
3179 | 3179 | while ($row = Database::fetch_array($result)) { |
3180 | 3180 | |
3181 | - $row['image'] = null; |
|
3182 | - $sessionImage = $sysUploadPath . $imageFieldId['id'] . '_' . $row['id'] . '.png'; |
|
3181 | + $row['image'] = null; |
|
3182 | + $sessionImage = $sysUploadPath.$imageFieldId['id'].'_'.$row['id'].'.png'; |
|
3183 | 3183 | |
3184 | 3184 | if (is_file($sessionImage)) { |
3185 | - $sessionImage = $webUploadPath . $imageFieldId['id'] . '_' . $row['id'] . '.png'; |
|
3185 | + $sessionImage = $webUploadPath.$imageFieldId['id'].'_'.$row['id'].'.png'; |
|
3186 | 3186 | $row['image'] = $sessionImage; |
3187 | 3187 | } else { |
3188 | - $row['image'] = $imgPath; |
|
3188 | + $row['image'] = $imgPath; |
|
3189 | 3189 | } |
3190 | 3190 | |
3191 | 3191 | $sessions[$row['id']] = $row; |
@@ -3255,7 +3255,7 @@ discard block |
||
3255 | 3255 | return intval($count[0]); |
3256 | 3256 | } |
3257 | 3257 | |
3258 | - while ($row = Database::fetch_array($result,'ASSOC')) { |
|
3258 | + while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
3259 | 3259 | $courses[$row['real_id']] = $row; |
3260 | 3260 | } |
3261 | 3261 | } |
@@ -3299,7 +3299,7 @@ discard block |
||
3299 | 3299 | } |
3300 | 3300 | |
3301 | 3301 | $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); |
3302 | - $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
3302 | + $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
3303 | 3303 | |
3304 | 3304 | if ($getCount) { |
3305 | 3305 | $select = "SELECT COUNT(DISTINCT(c.code)) as count "; |
@@ -3324,7 +3324,7 @@ discard block |
||
3324 | 3324 | "; |
3325 | 3325 | if ($getCount) { |
3326 | 3326 | $result = Database::query($sql); |
3327 | - $row = Database::fetch_array($result,'ASSOC'); |
|
3327 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
3328 | 3328 | return $row['count']; |
3329 | 3329 | } |
3330 | 3330 | |
@@ -3339,7 +3339,7 @@ discard block |
||
3339 | 3339 | $courses = array(); |
3340 | 3340 | |
3341 | 3341 | if ($num_rows > 0) { |
3342 | - while ($row = Database::fetch_array($result,'ASSOC')) { |
|
3342 | + while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
3343 | 3343 | $courses[$row['id']] = $row; |
3344 | 3344 | } |
3345 | 3345 | } |
@@ -3417,7 +3417,7 @@ discard block |
||
3417 | 3417 | $result = Database::query($sql); |
3418 | 3418 | $num_rows = Database::num_rows($result); |
3419 | 3419 | if ($num_rows > 0) { |
3420 | - $row = Database::fetch_array($result,'ASSOC'); |
|
3420 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
3421 | 3421 | return $row['count']; |
3422 | 3422 | } |
3423 | 3423 | |
@@ -3529,9 +3529,9 @@ discard block |
||
3529 | 3529 | |
3530 | 3530 | if ($access_url_id != -1) { |
3531 | 3531 | $sql = 'SELECT DISTINCT session.* |
3532 | - FROM ' . $session_table . ' session INNER JOIN ' . $tbl_session_rel_access_url . ' session_rel_url |
|
3532 | + FROM ' . $session_table.' session INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url |
|
3533 | 3533 | ON (session.id = session_rel_url.session_id) |
3534 | - WHERE '.$sqlCoach.' access_url_id = ' . $access_url_id; |
|
3534 | + WHERE '.$sqlCoach.' access_url_id = '.$access_url_id; |
|
3535 | 3535 | } |
3536 | 3536 | } |
3537 | 3537 | $sql .= ' ORDER by name'; |
@@ -3565,8 +3565,8 @@ discard block |
||
3565 | 3565 | FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user |
3566 | 3566 | WHERE |
3567 | 3567 | session_rcru.user_id = user.user_id AND |
3568 | - session_rcru.session_id = '" . intval($session_id) . "' AND |
|
3569 | - session_rcru.c_id ='" . intval($courseId) . "' AND |
|
3568 | + session_rcru.session_id = '".intval($session_id)."' AND |
|
3569 | + session_rcru.c_id ='" . intval($courseId)."' AND |
|
3570 | 3570 | user.user_id = " . intval($user_id); |
3571 | 3571 | |
3572 | 3572 | $result = Database::query($sql); |
@@ -3597,8 +3597,8 @@ discard block |
||
3597 | 3597 | $sql = "SELECT session_rcru.status |
3598 | 3598 | FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user |
3599 | 3599 | WHERE session_rcru.user_id = user.user_id AND |
3600 | - session_rcru.session_id = '" . intval($session_id) . "' AND |
|
3601 | - session_rcru.c_id ='" . intval($courseId) . "' AND |
|
3600 | + session_rcru.session_id = '".intval($session_id)."' AND |
|
3601 | + session_rcru.c_id ='" . intval($courseId)."' AND |
|
3602 | 3602 | user.user_id = " . intval($user_id); |
3603 | 3603 | $result = Database::query($sql); |
3604 | 3604 | $status = false; |
@@ -3675,7 +3675,7 @@ discard block |
||
3675 | 3675 | // Get timestamp for now in UTC - see http://php.net/manual/es/function.time.php#117251 |
3676 | 3676 | $now = time() - date('Z'); |
3677 | 3677 | // Timestamp in one month |
3678 | - $inOneMonth = $now + (30*24*3600); |
|
3678 | + $inOneMonth = $now + (30 * 24 * 3600); |
|
3679 | 3679 | $inOneMonth = api_get_local_time($inOneMonth); |
3680 | 3680 | if (api_strtotime($s['access_start_date']) < $now) { |
3681 | 3681 | $s['access_start_date'] = api_get_local_time($now); |
@@ -3697,16 +3697,16 @@ discard block |
||
3697 | 3697 | } |
3698 | 3698 | // Now try to create the session |
3699 | 3699 | $sid = self::create_session( |
3700 | - $s['name'] . ' ' . get_lang('CopyLabelSuffix'), |
|
3700 | + $s['name'].' '.get_lang('CopyLabelSuffix'), |
|
3701 | 3701 | $s['access_start_date'], |
3702 | 3702 | $s['access_end_date'], |
3703 | 3703 | $s['display_start_date'], |
3704 | 3704 | $s['display_end_date'], |
3705 | 3705 | $s['coach_access_start_date'], |
3706 | 3706 | $s['coach_access_end_date'], |
3707 | - (int)$s['id_coach'], |
|
3707 | + (int) $s['id_coach'], |
|
3708 | 3708 | $s['session_category_id'], |
3709 | - (int)$s['visibility'], |
|
3709 | + (int) $s['visibility'], |
|
3710 | 3710 | true |
3711 | 3711 | ); |
3712 | 3712 | |
@@ -3820,7 +3820,7 @@ discard block |
||
3820 | 3820 | $session_table = Database::get_main_table(TABLE_MAIN_SESSION); |
3821 | 3821 | $sql = "SELECT DISTINCT id |
3822 | 3822 | FROM $session_table |
3823 | - WHERE session.id_coach = '" . $user_id . "' AND id = '$session_id'"; |
|
3823 | + WHERE session.id_coach = '".$user_id."' AND id = '$session_id'"; |
|
3824 | 3824 | $result = Database::query($sql); |
3825 | 3825 | if ($result && Database::num_rows($result)) { |
3826 | 3826 | return true; |
@@ -3839,7 +3839,7 @@ discard block |
||
3839 | 3839 | $access_url_rel_session_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
3840 | 3840 | $sql = "SELECT count(id) FROM $session_table s"; |
3841 | 3841 | if (!empty($access_url_id) && $access_url_id == intval($access_url_id)) { |
3842 | - $sql .= ", $access_url_rel_session_table u " . |
|
3842 | + $sql .= ", $access_url_rel_session_table u ". |
|
3843 | 3843 | " WHERE s.id = u.session_id AND u.access_url_id = $access_url_id"; |
3844 | 3844 | } |
3845 | 3845 | $res = Database::query($sql); |
@@ -4090,7 +4090,7 @@ discard block |
||
4090 | 4090 | |
4091 | 4091 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
4092 | 4092 | $tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); |
4093 | - $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
4093 | + $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
4094 | 4094 | $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
4095 | 4095 | |
4096 | 4096 | $sessions = array(); |
@@ -4184,10 +4184,10 @@ discard block |
||
4184 | 4184 | $suffix = null; |
4185 | 4185 | while (!$unique_name) { |
4186 | 4186 | if ($i > 1) { |
4187 | - $suffix = ' - ' . $i; |
|
4187 | + $suffix = ' - '.$i; |
|
4188 | 4188 | } |
4189 | - $sql = 'SELECT 1 FROM ' . $tbl_session . ' |
|
4190 | - WHERE name="' . $session_name . $suffix . '"'; |
|
4189 | + $sql = 'SELECT 1 FROM '.$tbl_session.' |
|
4190 | + WHERE name="' . $session_name.$suffix.'"'; |
|
4191 | 4191 | $rs = Database::query($sql); |
4192 | 4192 | |
4193 | 4193 | if (Database::result($rs, 0, 0)) { |
@@ -4205,13 +4205,13 @@ discard block |
||
4205 | 4205 | |
4206 | 4206 | // Creating the session. |
4207 | 4207 | $sql = "INSERT IGNORE INTO $tbl_session SET |
4208 | - name = '" . $session_name . "', |
|
4208 | + name = '".$session_name."', |
|
4209 | 4209 | id_coach = '$coach_id', |
4210 | 4210 | access_start_date = '$date_start', |
4211 | 4211 | access_end_date = '$date_end', |
4212 | 4212 | visibility = '$visibilityAfterExpirationPerSession', |
4213 | 4213 | $sessionCondition |
4214 | - session_admin_id = " . intval($defaultUserId) . $extraParameters . $extraSessionParameters; |
|
4214 | + session_admin_id = ".intval($defaultUserId).$extraParameters.$extraSessionParameters; |
|
4215 | 4215 | Database::query($sql); |
4216 | 4216 | |
4217 | 4217 | $session_id = Database::insert_id(); |
@@ -4251,7 +4251,7 @@ discard block |
||
4251 | 4251 | access_start_date = '$date_start', |
4252 | 4252 | access_end_date = '$date_end', |
4253 | 4253 | visibility = '$visibilityAfterExpirationPerSession', |
4254 | - session_category_id = '$session_category_id' " . $extraParameters . $extraSessionParameters; |
|
4254 | + session_category_id = '$session_category_id' ".$extraParameters.$extraSessionParameters; |
|
4255 | 4255 | |
4256 | 4256 | Database::query($sql); |
4257 | 4257 | |
@@ -4271,7 +4271,7 @@ discard block |
||
4271 | 4271 | |
4272 | 4272 | // Delete session-user relation only for students |
4273 | 4273 | $sql = "DELETE FROM $tbl_session_user |
4274 | - WHERE session_id = '$session_id' AND relation_type <> " . SESSION_RELATION_TYPE_RRHH; |
|
4274 | + WHERE session_id = '$session_id' AND relation_type <> ".SESSION_RELATION_TYPE_RRHH; |
|
4275 | 4275 | Database::query($sql); |
4276 | 4276 | |
4277 | 4277 | $sql = "DELETE FROM $tbl_session_course WHERE session_id = '$session_id'"; |
@@ -4359,7 +4359,7 @@ discard block |
||
4359 | 4359 | |
4360 | 4360 | // Delete session-user relation only for students |
4361 | 4361 | $sql = "DELETE FROM $tbl_session_user |
4362 | - WHERE session_id = '$session_id' AND relation_type <> " . SESSION_RELATION_TYPE_RRHH; |
|
4362 | + WHERE session_id = '$session_id' AND relation_type <> ".SESSION_RELATION_TYPE_RRHH; |
|
4363 | 4363 | Database::query($sql); |
4364 | 4364 | |
4365 | 4365 | $sql = "DELETE FROM $tbl_session_course WHERE session_id = '$session_id'"; |
@@ -4402,7 +4402,7 @@ discard block |
||
4402 | 4402 | $sql = "INSERT IGNORE INTO $tbl_session_user SET |
4403 | 4403 | user_id = '$user_id', |
4404 | 4404 | session_id = '$session_id', |
4405 | - registered_at = '" . api_get_utc_datetime() . "'"; |
|
4405 | + registered_at = '".api_get_utc_datetime()."'"; |
|
4406 | 4406 | Database::query($sql); |
4407 | 4407 | if ($debug) { |
4408 | 4408 | $logger->addInfo("Sessions - Adding User #$user_id ($user) to session #$session_id"); |
@@ -5040,7 +5040,7 @@ discard block |
||
5040 | 5040 | |
5041 | 5041 | if (!empty($lastConnectionDate)) { |
5042 | 5042 | $lastConnectionDate = Database::escape_string($lastConnectionDate); |
5043 | - $userConditions .= " AND u.last_login <= '$lastConnectionDate' "; |
|
5043 | + $userConditions .= " AND u.last_login <= '$lastConnectionDate' "; |
|
5044 | 5044 | } |
5045 | 5045 | |
5046 | 5046 | if (!empty($keyword)) { |
@@ -5099,7 +5099,7 @@ discard block |
||
5099 | 5099 | $result = Database::query($sql); |
5100 | 5100 | $result = Database::store_result($result); |
5101 | 5101 | |
5102 | - return $result ; |
|
5102 | + return $result; |
|
5103 | 5103 | } |
5104 | 5104 | |
5105 | 5105 | /** |
@@ -5159,7 +5159,7 @@ discard block |
||
5159 | 5159 | $userToString = null; |
5160 | 5160 | foreach ($userList as $userInfo) { |
5161 | 5161 | $newUserList[] = $userInfo['user_id']; |
5162 | - $userToString .= $userInfo['firstname'] . ' ' . $userInfo['lastname'] . '<br />'; |
|
5162 | + $userToString .= $userInfo['firstname'].' '.$userInfo['lastname'].'<br />'; |
|
5163 | 5163 | } |
5164 | 5164 | |
5165 | 5165 | if (!empty($sessionsDestination)) { |
@@ -5172,7 +5172,7 @@ discard block |
||
5172 | 5172 | $messages[] = Display::return_message(sprintf(get_lang('SessionXSkipped'), $sessionDestinationId), 'warning', false); |
5173 | 5173 | continue; |
5174 | 5174 | } |
5175 | - $messages[] = Display::return_message(get_lang('StudentList') . '<br />' . $userToString, 'info', false); |
|
5175 | + $messages[] = Display::return_message(get_lang('StudentList').'<br />'.$userToString, 'info', false); |
|
5176 | 5176 | SessionManager::suscribe_users_to_session( |
5177 | 5177 | $sessionDestinationId, |
5178 | 5178 | $newUserList, |
@@ -5223,7 +5223,7 @@ discard block |
||
5223 | 5223 | } |
5224 | 5224 | } |
5225 | 5225 | } |
5226 | - $sessionUrl = api_get_path(WEB_CODE_PATH) . 'admin/resume_session.php?id_session='; |
|
5226 | + $sessionUrl = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='; |
|
5227 | 5227 | |
5228 | 5228 | $htmlResult = null; |
5229 | 5229 | |
@@ -5238,7 +5238,7 @@ discard block |
||
5238 | 5238 | $sessionInfo = self::fetch($sessionId); |
5239 | 5239 | $htmlResult .= '<br />'; |
5240 | 5240 | $htmlResult .= Display::url( |
5241 | - get_lang('Session') . ': ' . $sessionInfo['name'] . ' <br />', $sessionUrl . $sessionId, array('target' => '_blank') |
|
5241 | + get_lang('Session').': '.$sessionInfo['name'].' <br />', $sessionUrl.$sessionId, array('target' => '_blank') |
|
5242 | 5242 | ); |
5243 | 5243 | $teacherList = array(); |
5244 | 5244 | foreach ($coachList as $coachId) { |
@@ -5351,7 +5351,7 @@ discard block |
||
5351 | 5351 | } |
5352 | 5352 | |
5353 | 5353 | $sessionIdList = array_map('intval', $sessionIdList); |
5354 | - $sessionToString = implode("', '", $sessionIdList); |
|
5354 | + $sessionToString = implode("', '", $sessionIdList); |
|
5355 | 5355 | |
5356 | 5356 | $course = Database::get_main_table(TABLE_MAIN_COURSE); |
5357 | 5357 | $sessionCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
@@ -5363,7 +5363,7 @@ discard block |
||
5363 | 5363 | INNER JOIN $courseUser cu ON (cu.c_id = c.id) |
5364 | 5364 | WHERE src.session_id IN ('$sessionToString') AND cu.status = 1"; |
5365 | 5365 | $result = Database::query($sql); |
5366 | - while($row = Database::fetch_array($result, 'ASSOC')) { |
|
5366 | + while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
5367 | 5367 | $teacherListId[$row['user_id']] = $row['user_id']; |
5368 | 5368 | } |
5369 | 5369 | } else { |
@@ -5438,7 +5438,7 @@ discard block |
||
5438 | 5438 | $toolList = self::getCourseToolToBeManaged(); |
5439 | 5439 | |
5440 | 5440 | foreach ($toolList as $tool) { |
5441 | - $method = 'add' . $tool; |
|
5441 | + $method = 'add'.$tool; |
|
5442 | 5442 | if (method_exists(get_class(), $method)) { |
5443 | 5443 | self::$method($sessionId, $courseId); |
5444 | 5444 | } |
@@ -5457,7 +5457,7 @@ discard block |
||
5457 | 5457 | $toolList = self::getCourseToolToBeManaged(); |
5458 | 5458 | |
5459 | 5459 | foreach ($toolList as $tool) { |
5460 | - $method = 'remove' . $tool; |
|
5460 | + $method = 'remove'.$tool; |
|
5461 | 5461 | if (method_exists(get_class(), $method)) { |
5462 | 5462 | self::$method($sessionId, $courseId); |
5463 | 5463 | } |
@@ -5575,18 +5575,18 @@ discard block |
||
5575 | 5575 | } |
5576 | 5576 | } |
5577 | 5577 | |
5578 | - $message .= '<strong>' . get_lang('User') . '</strong> ' . $userInfo['complete_name'] . ' <br />'; |
|
5578 | + $message .= '<strong>'.get_lang('User').'</strong> '.$userInfo['complete_name'].' <br />'; |
|
5579 | 5579 | |
5580 | 5580 | if (!in_array($userInfo['status'], array(DRH)) && !api_is_platform_admin_by_id($userInfo['user_id'])) { |
5581 | - $message .= get_lang('UserMustHaveTheDrhRole') . '<br />'; |
|
5581 | + $message .= get_lang('UserMustHaveTheDrhRole').'<br />'; |
|
5582 | 5582 | continue; |
5583 | 5583 | } |
5584 | 5584 | |
5585 | 5585 | if (!empty($sessionList)) { |
5586 | - $message .= '<strong>' . get_lang('Sessions') . ':</strong> <br />'; |
|
5587 | - $message .= implode(', ', $sessionList) . '<br /><br />'; |
|
5586 | + $message .= '<strong>'.get_lang('Sessions').':</strong> <br />'; |
|
5587 | + $message .= implode(', ', $sessionList).'<br /><br />'; |
|
5588 | 5588 | } else { |
5589 | - $message .= get_lang('NoSessionProvided') . ' <br /><br />'; |
|
5589 | + $message .= get_lang('NoSessionProvided').' <br /><br />'; |
|
5590 | 5590 | } |
5591 | 5591 | } |
5592 | 5592 | } |
@@ -5766,8 +5766,8 @@ discard block |
||
5766 | 5766 | |
5767 | 5767 | $firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC'); |
5768 | 5768 | |
5769 | - $endDateInSeconds = $firstAccess + $duration*24*60*60; |
|
5770 | - $leftDays = round(($endDateInSeconds- $currentTime) / 60 / 60 / 24); |
|
5769 | + $endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60; |
|
5770 | + $leftDays = round(($endDateInSeconds - $currentTime) / 60 / 60 / 24); |
|
5771 | 5771 | |
5772 | 5772 | return $leftDays; |
5773 | 5773 | } |
@@ -6049,7 +6049,7 @@ discard block |
||
6049 | 6049 | $sql = "SELECT COUNT(1) as count, u.id, scu.status status_in_session, u.status user_status |
6050 | 6050 | FROM $tableSessionRelCourseRelUser scu |
6051 | 6051 | INNER JOIN $tableUser u ON scu.user_id = u.id |
6052 | - WHERE scu.session_id = " . intval($sessionId) ." |
|
6052 | + WHERE scu.session_id = ".intval($sessionId)." |
|
6053 | 6053 | GROUP BY u.id"; |
6054 | 6054 | |
6055 | 6055 | $result = Database::query($sql); |
@@ -6084,7 +6084,7 @@ discard block |
||
6084 | 6084 | $sfTable = Database::get_main_table(TABLE_EXTRA_FIELD); |
6085 | 6085 | $sfvTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); |
6086 | 6086 | // Join session field and session field values tables |
6087 | - $joinTable = $sfTable . ' sf INNER JOIN ' . $sfvTable . ' sfv ON sf.id = sfv.field_id'; |
|
6087 | + $joinTable = $sfTable.' sf INNER JOIN '.$sfvTable.' sfv ON sf.id = sfv.field_id'; |
|
6088 | 6088 | $fieldsArray = array(); |
6089 | 6089 | foreach ($extraFields as $field) { |
6090 | 6090 | $fieldsArray[] = Database::escape_string($field); |
@@ -6127,14 +6127,14 @@ discard block |
||
6127 | 6127 | for ($i = 1; $i < count($fieldsArray); $i++) { |
6128 | 6128 | $whereParams .= ', ?'; |
6129 | 6129 | } |
6130 | - $whereFieldVariables = ' variable IN ( ' . $whereParams .' )'; |
|
6131 | - $whereFieldIds = 'field_id IN ( ' . $whereParams . ' )'; |
|
6130 | + $whereFieldVariables = ' variable IN ( '.$whereParams.' )'; |
|
6131 | + $whereFieldIds = 'field_id IN ( '.$whereParams.' )'; |
|
6132 | 6132 | } |
6133 | 6133 | // Get session fields |
6134 | 6134 | $extraField = new ExtraField('session'); |
6135 | 6135 | $questionMarks = substr(str_repeat('?, ', count($fieldsArray)), 0, -2); |
6136 | 6136 | $fieldsList = $extraField->get_all(array( |
6137 | - ' variable IN ( ' . $questionMarks . ' )' => $fieldsArray, |
|
6137 | + ' variable IN ( '.$questionMarks.' )' => $fieldsArray, |
|
6138 | 6138 | )); |
6139 | 6139 | // Index session fields |
6140 | 6140 | foreach ($fieldsList as $field) { |
@@ -6143,7 +6143,7 @@ discard block |
||
6143 | 6143 | // Get session field values |
6144 | 6144 | $extra = new ExtraFieldValue('session'); |
6145 | 6145 | $questionMarksFields = substr(str_repeat('?, ', count($fields)), 0, -2); |
6146 | - $sessionFieldValueList = $extra->get_all(array ('where' => array('field_id IN ( ' . $questionMarksFields . ' )' => array_keys($fields)))); |
|
6146 | + $sessionFieldValueList = $extra->get_all(array('where' => array('field_id IN ( '.$questionMarksFields.' )' => array_keys($fields)))); |
|
6147 | 6147 | // Add session fields values to session list |
6148 | 6148 | foreach ($sessionList as $id => &$session) { |
6149 | 6149 | foreach ($sessionFieldValueList as $sessionFieldValue) { |
@@ -6196,7 +6196,7 @@ discard block |
||
6196 | 6196 | // Check the result |
6197 | 6197 | if ($result < 1) { |
6198 | 6198 | // If not found any result, update error message |
6199 | - $errorResult['errorMessage'] = 'Not found any session category name ' . $categoryName; |
|
6199 | + $errorResult['errorMessage'] = 'Not found any session category name '.$categoryName; |
|
6200 | 6200 | } elseif (count($result) > 1 && !$force) { |
6201 | 6201 | // If found more than one result and force is disabled, update error message |
6202 | 6202 | $errorResult['errorMessage'] = 'Found many session categories'; |
@@ -6255,7 +6255,7 @@ discard block |
||
6255 | 6255 | // Check if session list query had result |
6256 | 6256 | if (!empty($sessionList)) { |
6257 | 6257 | // implode all session id |
6258 | - $sessionIdsString = '(' . implode(', ', array_keys($sessionList)) . ')'; |
|
6258 | + $sessionIdsString = '('.implode(', ', array_keys($sessionList)).')'; |
|
6259 | 6259 | // Get all field variables |
6260 | 6260 | $sessionFieldList = Database::select( |
6261 | 6261 | 'id, variable', |
@@ -6342,7 +6342,7 @@ discard block |
||
6342 | 6342 | return $sessionList; |
6343 | 6343 | } else { |
6344 | 6344 | // Not found result, update error message |
6345 | - $errorResult['errorMessage'] = 'Not found any session for session category id ' . $sessionCategoryId; |
|
6345 | + $errorResult['errorMessage'] = 'Not found any session for session category id '.$sessionCategoryId; |
|
6346 | 6346 | } |
6347 | 6347 | } |
6348 | 6348 | |
@@ -6446,7 +6446,7 @@ discard block |
||
6446 | 6446 | |
6447 | 6447 | $sessionExtraField = new ExtraField('session'); |
6448 | 6448 | $fieldList = $sessionExtraField->get_all(array( |
6449 | - "variable IN ( " . implode(", ", $variablePlaceHolders) . " ) " => $variables, |
|
6449 | + "variable IN ( ".implode(", ", $variablePlaceHolders)." ) " => $variables, |
|
6450 | 6450 | )); |
6451 | 6451 | |
6452 | 6452 | $fields = array(); |
@@ -6460,7 +6460,7 @@ discard block |
||
6460 | 6460 | $extra = new ExtraFieldValue('session'); |
6461 | 6461 | $sessionFieldValueList = $extra->get_all( |
6462 | 6462 | array( |
6463 | - "field_id IN ( " . implode(", ", $variablePlaceHolders) . " )" => array_keys($fields), |
|
6463 | + "field_id IN ( ".implode(", ", $variablePlaceHolders)." )" => array_keys($fields), |
|
6464 | 6464 | ) |
6465 | 6465 | ); |
6466 | 6466 | |
@@ -6531,7 +6531,7 @@ discard block |
||
6531 | 6531 | FROM $sessionTable s |
6532 | 6532 | INNER JOIN $sessionUserTable sru ON s.id = sru.id_session |
6533 | 6533 | WHERE |
6534 | - (sru.id_user IN (" . implode(', ', $userIdList) . ") |
|
6534 | + (sru.id_user IN (".implode(', ', $userIdList).") |
|
6535 | 6535 | AND sru.relation_type = 0 |
6536 | 6536 | )"; |
6537 | 6537 | |
@@ -6547,7 +6547,7 @@ discard block |
||
6547 | 6547 | WHERE |
6548 | 6548 | srau.access_url_id = $accessUrlId |
6549 | 6549 | AND ( |
6550 | - sru.id_user IN (" . implode(', ', $userIdList) . ") |
|
6550 | + sru.id_user IN (".implode(', ', $userIdList).") |
|
6551 | 6551 | AND sru.relation_type = 0 |
6552 | 6552 | )"; |
6553 | 6553 | } |
@@ -6568,7 +6568,7 @@ discard block |
||
6568 | 6568 | */ |
6569 | 6569 | public static function getSessionVisibility($sessionInfo) |
6570 | 6570 | { |
6571 | - switch($sessionInfo['visibility']) { |
|
6571 | + switch ($sessionInfo['visibility']) { |
|
6572 | 6572 | case 1: |
6573 | 6573 | return get_lang('ReadOnly'); |
6574 | 6574 | case 2: |
@@ -6599,7 +6599,7 @@ discard block |
||
6599 | 6599 | |
6600 | 6600 | $result = ''; |
6601 | 6601 | if (!empty($startDateToLocal) && !empty($endDateToLocal)) { |
6602 | - $result = sprintf(get_lang('FromDateXToDateY'), $startDateToLocal, $endDateToLocal); |
|
6602 | + $result = sprintf(get_lang('FromDateXToDateY'), $startDateToLocal, $endDateToLocal); |
|
6603 | 6603 | } else { |
6604 | 6604 | if (!empty($startDateToLocal)) { |
6605 | 6605 | $result = get_lang('From').' '.$startDateToLocal; |
@@ -6742,7 +6742,7 @@ discard block |
||
6742 | 6742 | get_lang('CoachName'), |
6743 | 6743 | null, |
6744 | 6744 | [ |
6745 | - 'url' => api_get_path(WEB_AJAX_PATH) . 'session.ajax.php?a=search_general_coach', |
|
6745 | + 'url' => api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_general_coach', |
|
6746 | 6746 | 'width' => '100%', |
6747 | 6747 | ] |
6748 | 6748 | ); |
@@ -6753,7 +6753,7 @@ discard block |
||
6753 | 6753 | $form->addHtml('<div id="ajax_list_coachs"></div>'); |
6754 | 6754 | |
6755 | 6755 | $form->addButtonAdvancedSettings('advanced_params'); |
6756 | - $form->addElement('html','<div id="advanced_params_options" style="display:none">'); |
|
6756 | + $form->addElement('html', '<div id="advanced_params_options" style="display:none">'); |
|
6757 | 6757 | |
6758 | 6758 | $form->addSelect('session_category', get_lang('SessionCategory'), $categoriesOptions, array( |
6759 | 6759 | 'id' => 'session_category' |
@@ -6891,7 +6891,7 @@ discard block |
||
6891 | 6891 | $extra_field = new ExtraField('session'); |
6892 | 6892 | $extra = $extra_field->addElements($form, $sessionId); |
6893 | 6893 | |
6894 | - $form->addElement('html','</div>'); |
|
6894 | + $form->addElement('html', '</div>'); |
|
6895 | 6895 | |
6896 | 6896 | $js = $extra['jquery_ready_content']; |
6897 | 6897 | |
@@ -6922,16 +6922,16 @@ discard block |
||
6922 | 6922 | if (api_is_session_admin() && |
6923 | 6923 | api_get_setting('allow_session_admins_to_see_all_sessions') == 'false' |
6924 | 6924 | ) { |
6925 | - $where.=" WHERE s.session_admin_id = $user_id "; |
|
6925 | + $where .= " WHERE s.session_admin_id = $user_id "; |
|
6926 | 6926 | } |
6927 | 6927 | |
6928 | 6928 | if (!empty($options['where'])) { |
6929 | 6929 | $options['where'] = str_replace('course_title', 'c.title', $options['where']); |
6930 | - $options['where'] = str_replace("( session_active = '0' )", '1=1', $options['where']); |
|
6930 | + $options['where'] = str_replace("( session_active = '0' )", '1=1', $options['where']); |
|
6931 | 6931 | |
6932 | 6932 | $options['where'] = str_replace( |
6933 | 6933 | array("AND session_active = '1' )", " AND ( session_active = '1' )"), |
6934 | - array(') GROUP BY s.name HAVING session_active = 1 ', " GROUP BY s.name HAVING session_active = 1 " ) |
|
6934 | + array(') GROUP BY s.name HAVING session_active = 1 ', " GROUP BY s.name HAVING session_active = 1 ") |
|
6935 | 6935 | , $options['where'] |
6936 | 6936 | ); |
6937 | 6937 | |
@@ -6973,10 +6973,10 @@ discard block |
||
6973 | 6973 | $where "; |
6974 | 6974 | |
6975 | 6975 | if (api_is_multiple_url_enabled()) { |
6976 | - $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
6976 | + $table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
6977 | 6977 | $access_url_id = api_get_current_access_url_id(); |
6978 | 6978 | if ($access_url_id != -1) { |
6979 | - $where.= " AND ar.access_url_id = $access_url_id "; |
|
6979 | + $where .= " AND ar.access_url_id = $access_url_id "; |
|
6980 | 6980 | |
6981 | 6981 | $query_rows = "SELECT count(*) as total_rows |
6982 | 6982 | FROM $tbl_session s |
@@ -7021,12 +7021,12 @@ discard block |
||
7021 | 7021 | //get_lang('CourseTitle'), |
7022 | 7022 | get_lang('Visibility'), |
7023 | 7023 | ); |
7024 | - $column_model = array ( |
|
7025 | - array('name'=>'name', 'index'=>'s.name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)), |
|
7026 | - array('name'=>'category_name', 'index'=>'category_name', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)), |
|
7027 | - array('name'=>'display_start_date', 'index'=>'display_start_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_today', 'sopt' => $date_operators)), |
|
7028 | - array('name'=>'display_end_date', 'index'=>'display_end_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_one_month', 'sopt' => $date_operators)), |
|
7029 | - array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'), |
|
7024 | + $column_model = array( |
|
7025 | + array('name'=>'name', 'index'=>'s.name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)), |
|
7026 | + array('name'=>'category_name', 'index'=>'category_name', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)), |
|
7027 | + array('name'=>'display_start_date', 'index'=>'display_start_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_today', 'sopt' => $date_operators)), |
|
7028 | + array('name'=>'display_end_date', 'index'=>'display_end_date', 'width'=>'50', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_one_month', 'sopt' => $date_operators)), |
|
7029 | + array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'), |
|
7030 | 7030 | ); |
7031 | 7031 | break; |
7032 | 7032 | case 'complete': |
@@ -7039,12 +7039,12 @@ discard block |
||
7039 | 7039 | get_lang('Visibility'), |
7040 | 7040 | get_lang('CourseTitle'), |
7041 | 7041 | ); |
7042 | - $column_model = array ( |
|
7043 | - array('name'=>'name', 'index'=>'s.name', 'width'=>'200', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)), |
|
7044 | - array('name'=>'display_start_date', 'index'=>'display_start_date', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_today', 'sopt' => $date_operators)), |
|
7045 | - array('name'=>'display_end_date', 'index'=>'display_end_date', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_one_month', 'sopt' => $date_operators)), |
|
7046 | - array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'70', 'align'=>'left', 'search' => 'false', 'searchoptions' => array('sopt' => $operators)), |
|
7047 | - array('name'=>'session_active', 'index'=>'session_active', 'width'=>'25', 'align'=>'left', 'search' => 'true', 'stype'=>'select', |
|
7042 | + $column_model = array( |
|
7043 | + array('name'=>'name', 'index'=>'s.name', 'width'=>'200', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('sopt' => $operators)), |
|
7044 | + array('name'=>'display_start_date', 'index'=>'display_start_date', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_today', 'sopt' => $date_operators)), |
|
7045 | + array('name'=>'display_end_date', 'index'=>'display_end_date', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array('dataInit' => 'date_pick_one_month', 'sopt' => $date_operators)), |
|
7046 | + array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'70', 'align'=>'left', 'search' => 'false', 'searchoptions' => array('sopt' => $operators)), |
|
7047 | + array('name'=>'session_active', 'index'=>'session_active', 'width'=>'25', 'align'=>'left', 'search' => 'true', 'stype'=>'select', |
|
7048 | 7048 | // for the bottom bar |
7049 | 7049 | 'searchoptions' => array( |
7050 | 7050 | 'defaultValue' => '1', |
@@ -7052,8 +7052,8 @@ discard block |
||
7052 | 7052 | // for the top bar |
7053 | 7053 | 'editoptions' => array('value' => '" ":'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive')), |
7054 | 7054 | ), |
7055 | - array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'), |
|
7056 | - array('name'=>'course_title', 'index'=>'course_title', 'width'=>'50', 'hidden' => 'true', 'search' => 'true', 'searchoptions' => array('searchhidden' =>'true','sopt' => $operators)), |
|
7055 | + array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'), |
|
7056 | + array('name'=>'course_title', 'index'=>'course_title', 'width'=>'50', 'hidden' => 'true', 'search' => 'true', 'searchoptions' => array('searchhidden' =>'true', 'sopt' => $operators)), |
|
7057 | 7057 | ); |
7058 | 7058 | break; |
7059 | 7059 | } |
@@ -7062,14 +7062,14 @@ discard block |
||
7062 | 7062 | $session_field = new ExtraField('session'); |
7063 | 7063 | $rules = $session_field->getRules($columns, $column_model); |
7064 | 7064 | |
7065 | - $column_model[] = array('name'=>'actions', 'index'=>'actions', 'width'=>'80', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false'); |
|
7065 | + $column_model[] = array('name'=>'actions', 'index'=>'actions', 'width'=>'80', 'align'=>'left', 'formatter'=>'action_formatter', 'sortable'=>'false', 'search' => 'false'); |
|
7066 | 7066 | $columns[] = get_lang('Actions'); |
7067 | 7067 | |
7068 | 7068 | foreach ($column_model as $col_model) { |
7069 | 7069 | $simple_column_name[] = $col_model['name']; |
7070 | 7070 | } |
7071 | 7071 | |
7072 | - $return_array = array( |
|
7072 | + $return_array = array( |
|
7073 | 7073 | 'columns' => $columns, |
7074 | 7074 | 'column_model' => $column_model, |
7075 | 7075 | 'rules' => $rules, |
@@ -7158,7 +7158,7 @@ discard block |
||
7158 | 7158 | if (api_is_session_admin() && |
7159 | 7159 | api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false' |
7160 | 7160 | ) { |
7161 | - $where.=" AND s.session_admin_id = $user_id "; |
|
7161 | + $where .= " AND s.session_admin_id = $user_id "; |
|
7162 | 7162 | } |
7163 | 7163 | } |
7164 | 7164 | |
@@ -7241,11 +7241,11 @@ discard block |
||
7241 | 7241 | } |
7242 | 7242 | $options['where'] = str_replace('course_title', 'c.title', $options['where']); |
7243 | 7243 | |
7244 | - $options['where'] = str_replace("( session_active = '0' )", '1=1', $options['where']); |
|
7244 | + $options['where'] = str_replace("( session_active = '0' )", '1=1', $options['where']); |
|
7245 | 7245 | |
7246 | 7246 | $options['where'] = str_replace( |
7247 | 7247 | array("AND session_active = '1' )", " AND ( session_active = '1' )"), |
7248 | - array(') GROUP BY s.name HAVING session_active = 1 ', " GROUP BY s.name HAVING session_active = 1 " ) |
|
7248 | + array(') GROUP BY s.name HAVING session_active = 1 ', " GROUP BY s.name HAVING session_active = 1 ") |
|
7249 | 7249 | , $options['where'] |
7250 | 7250 | ); |
7251 | 7251 | |
@@ -7280,10 +7280,10 @@ discard block |
||
7280 | 7280 | $where; |
7281 | 7281 | |
7282 | 7282 | if (api_is_multiple_url_enabled()) { |
7283 | - $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
7283 | + $table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
7284 | 7284 | $access_url_id = api_get_current_access_url_id(); |
7285 | 7285 | if ($access_url_id != -1) { |
7286 | - $where.= " AND ar.access_url_id = $access_url_id "; |
|
7286 | + $where .= " AND ar.access_url_id = $access_url_id "; |
|
7287 | 7287 | $query = "$select |
7288 | 7288 | FROM $tbl_session s |
7289 | 7289 | LEFT JOIN $tbl_session_field_values fv ON (fv.session_id = s.id) |
@@ -7310,7 +7310,7 @@ discard block |
||
7310 | 7310 | $formatted_sessions = array(); |
7311 | 7311 | |
7312 | 7312 | if (Database::num_rows($result)) { |
7313 | - $sessions = Database::store_result($result, 'ASSOC'); |
|
7313 | + $sessions = Database::store_result($result, 'ASSOC'); |
|
7314 | 7314 | foreach ($sessions as $session) { |
7315 | 7315 | $session_id = $session['id']; |
7316 | 7316 | $session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']); |
@@ -7325,14 +7325,14 @@ discard block |
||
7325 | 7325 | |
7326 | 7326 | switch ($session['visibility']) { |
7327 | 7327 | case SESSION_VISIBLE_READ_ONLY: //1 |
7328 | - $session['visibility'] = get_lang('ReadOnly'); |
|
7328 | + $session['visibility'] = get_lang('ReadOnly'); |
|
7329 | 7329 | break; |
7330 | 7330 | case SESSION_VISIBLE: //2 |
7331 | 7331 | case SESSION_AVAILABLE: //4 |
7332 | - $session['visibility'] = get_lang('Visible'); |
|
7332 | + $session['visibility'] = get_lang('Visible'); |
|
7333 | 7333 | break; |
7334 | 7334 | case SESSION_INVISIBLE: //3 |
7335 | - $session['visibility'] = api_ucfirst(get_lang('Invisible')); |
|
7335 | + $session['visibility'] = api_ucfirst(get_lang('Invisible')); |
|
7336 | 7336 | break; |
7337 | 7337 | } |
7338 | 7338 | |
@@ -7408,7 +7408,7 @@ discard block |
||
7408 | 7408 | if (empty($session)) { |
7409 | 7409 | return false; |
7410 | 7410 | } |
7411 | - return api_get_path(WEB_CODE_PATH) . 'session/resume_session.php?id_session=' . $id; |
|
7411 | + return api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$id; |
|
7412 | 7412 | } |
7413 | 7413 | |
7414 | 7414 | /** |
@@ -7426,7 +7426,7 @@ discard block |
||
7426 | 7426 | return false; |
7427 | 7427 | } |
7428 | 7428 | if (empty($courseId)) { |
7429 | - return api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $id; |
|
7429 | + return api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$id; |
|
7430 | 7430 | } else { |
7431 | 7431 | $courseInfo = api_get_course_info_by_id($courseId); |
7432 | 7432 | if ($courseInfo) { |
@@ -7672,7 +7672,7 @@ discard block |
||
7672 | 7672 | // sort $listCat by catSessionName |
7673 | 7673 | usort($listCat, 'self::compareBySessionName'); |
7674 | 7674 | // in each catSession sort sessionList by sessionName |
7675 | - foreach($listCat as $i => $listCatSessionInfo) { |
|
7675 | + foreach ($listCat as $i => $listCatSessionInfo) { |
|
7676 | 7676 | $listSessionList = $listCatSessionInfo['sessionList']; |
7677 | 7677 | usort($listSessionList, 'self::compareCatSessionInfo'); |
7678 | 7678 | $listCat[$i]['sessionList'] = $listSessionList; |
@@ -7687,8 +7687,8 @@ discard block |
||
7687 | 7687 | ); |
7688 | 7688 | |
7689 | 7689 | $userCatId = intval($userCatId); |
7690 | - $listResults[$userCatId]['courseInUserCategoryId'] = $userCatId; |
|
7691 | - $listResults[$userCatId]['courseInUserCategoryTitle'] = $userCatTitle; |
|
7690 | + $listResults[$userCatId]['courseInUserCategoryId'] = $userCatId; |
|
7691 | + $listResults[$userCatId]['courseInUserCategoryTitle'] = $userCatTitle; |
|
7692 | 7692 | $listResults[$userCatId]['courseInUserCatList'][] = $listOneCourse; |
7693 | 7693 | } |
7694 | 7694 | |
@@ -7714,7 +7714,7 @@ discard block |
||
7714 | 7714 | { |
7715 | 7715 | if ($listA['sessionName'] == $listB['sessionName']) { |
7716 | 7716 | return 0; |
7717 | - } else if($listA['sessionName'] > $listB['sessionName']) { |
|
7717 | + } else if ($listA['sessionName'] > $listB['sessionName']) { |
|
7718 | 7718 | return 1; |
7719 | 7719 | } else { |
7720 | 7720 | return -1; |
@@ -7734,7 +7734,7 @@ discard block |
||
7734 | 7734 | return 1; |
7735 | 7735 | } else if ($listA['catSessionName'] == $listB['catSessionName']) { |
7736 | 7736 | return 0; |
7737 | - } else if($listA['catSessionName'] > $listB['catSessionName']) { |
|
7737 | + } else if ($listA['catSessionName'] > $listB['catSessionName']) { |
|
7738 | 7738 | return 1; |
7739 | 7739 | } else { |
7740 | 7740 | return -1; |
@@ -7750,7 +7750,7 @@ discard block |
||
7750 | 7750 | { |
7751 | 7751 | if ($listA['courseInUserCategoryTitle'] == $listB['courseInUserCategoryTitle']) { |
7752 | 7752 | return 0; |
7753 | - } else if($listA['courseInUserCategoryTitle'] > $listB['courseInUserCategoryTitle']) { |
|
7753 | + } else if ($listA['courseInUserCategoryTitle'] > $listB['courseInUserCategoryTitle']) { |
|
7754 | 7754 | return 1; |
7755 | 7755 | } else { |
7756 | 7756 | return -1; |
@@ -7766,7 +7766,7 @@ discard block |
||
7766 | 7766 | { |
7767 | 7767 | if ($listA['title'] == $listB['title']) { |
7768 | 7768 | return 0; |
7769 | - } else if($listA['title'] > $listB['title']) { |
|
7769 | + } else if ($listA['title'] > $listB['title']) { |
|
7770 | 7770 | return 1; |
7771 | 7771 | } else { |
7772 | 7772 | return -1; |
@@ -7812,8 +7812,8 @@ discard block |
||
7812 | 7812 | |
7813 | 7813 | $marginShift = 20; |
7814 | 7814 | if ($catSessionName != '') { |
7815 | - $htmlCatSessions .= '<div style="margin-left:'.$marginShift.'px;">' . |
|
7816 | - CourseManager::course_item_html($listParamsCatSession, true) . '</div>'; |
|
7815 | + $htmlCatSessions .= '<div style="margin-left:'.$marginShift.'px;">'. |
|
7816 | + CourseManager::course_item_html($listParamsCatSession, true).'</div>'; |
|
7817 | 7817 | $marginShift = 40; |
7818 | 7818 | } |
7819 | 7819 |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $course_id = intval($course_id); |
74 | 74 | } |
75 | 75 | |
76 | - $session_id = isset($session_id)?intval($session_id):api_get_session_id(); |
|
76 | + $session_id = isset($session_id) ? intval($session_id) : api_get_session_id(); |
|
77 | 77 | $condition_session = api_get_session_condition($session_id); |
78 | 78 | |
79 | 79 | // Get attendance data |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | WHERE c_id = $course_id AND active = 1 $condition_session "; |
83 | 83 | $rs = Database::query($sql); |
84 | 84 | if (Database::num_rows($rs) > 0) { |
85 | - while ($row = Database::fetch_array($rs,'ASSOC')) { |
|
85 | + while ($row = Database::fetch_array($rs, 'ASSOC')) { |
|
86 | 86 | $data[$row['id']] = $row; |
87 | 87 | } |
88 | 88 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $from = intval($from); |
109 | 109 | $number_of_items = intval($number_of_items); |
110 | 110 | |
111 | - if (!in_array($direction, array('ASC','DESC'))) { |
|
111 | + if (!in_array($direction, array('ASC', 'DESC'))) { |
|
112 | 112 | $direction = 'ASC'; |
113 | 113 | } |
114 | 114 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | LIMIT $from,$number_of_items "; |
136 | 136 | |
137 | 137 | $res = Database::query($sql); |
138 | - $attendances = array (); |
|
138 | + $attendances = array(); |
|
139 | 139 | $user_info = api_get_user_info(); |
140 | 140 | $allowDelete = api_get_setting('allow_delete_attendance'); |
141 | 141 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | $attendance[2] = '<span class="muted">'.$attendance[2].'</span>'; |
195 | 195 | } |
196 | 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>'; |
|
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 | 199 | } |
200 | 200 | } else { |
201 | 201 | $is_locked_attendance = self::is_locked_attendance($attendance[0]); |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | $attendance[2] = '<span class="muted">'.$attendance[2].'</span>'; |
216 | 216 | } |
217 | 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>'; |
|
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 | 220 | } |
221 | 221 | } |
222 | 222 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]); |
226 | 226 | |
227 | 227 | if ($is_done_all_calendar) { |
228 | - $locked = $attendance[4]; |
|
228 | + $locked = $attendance[4]; |
|
229 | 229 | if ($locked == 0) { |
230 | 230 | if (api_is_platform_admin()) { |
231 | 231 | $message_alert = get_lang('AreYouSureToLockTheAttendance'); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | } |
246 | 246 | $actions .= '</center>'; |
247 | 247 | |
248 | - $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions); |
|
248 | + $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3], $actions); |
|
249 | 249 | } else { |
250 | 250 | $attendance[0] = ' '; |
251 | 251 | $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]); |
@@ -285,13 +285,13 @@ discard block |
||
285 | 285 | public function attendance_add($link_to_gradebook = false) |
286 | 286 | { |
287 | 287 | $_course = api_get_course_info(); |
288 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
288 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
289 | 289 | $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
290 | 290 | $session_id = api_get_session_id(); |
291 | 291 | $user_id = api_get_user_id(); |
292 | 292 | $course_code = $_course['code']; |
293 | 293 | $course_id = $_course['real_id']; |
294 | - $title_gradebook= $this->attendance_qualify_title; |
|
294 | + $title_gradebook = $this->attendance_qualify_title; |
|
295 | 295 | $value_calification = 0; |
296 | 296 | $weight_calification = floatval($this->attendance_weight); |
297 | 297 | |
@@ -434,12 +434,12 @@ discard block |
||
434 | 434 | public function attendance_restore($attendance_id) |
435 | 435 | { |
436 | 436 | $_course = api_get_course_info(); |
437 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
437 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
438 | 438 | $user_id = api_get_user_id(); |
439 | 439 | $course_id = $_course['real_id']; |
440 | 440 | if (is_array($attendance_id)) { |
441 | 441 | foreach ($attendance_id as $id) { |
442 | - $id = intval($id); |
|
442 | + $id = intval($id); |
|
443 | 443 | $sql = "UPDATE $tbl_attendance SET active = 1 |
444 | 444 | WHERE c_id = $course_id AND id = '$id'"; |
445 | 445 | $result = Database::query($sql); |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | ); |
456 | 456 | } |
457 | 457 | } |
458 | - } else { |
|
459 | - $attendance_id = intval($attendance_id); |
|
458 | + } else { |
|
459 | + $attendance_id = intval($attendance_id); |
|
460 | 460 | $sql = "UPDATE $tbl_attendance SET active = 1 |
461 | 461 | WHERE c_id = $course_id AND id = '$attendance_id'"; |
462 | 462 | $result = Database::query($sql); |
@@ -484,13 +484,13 @@ discard block |
||
484 | 484 | public function attendance_delete($attendance_id) |
485 | 485 | { |
486 | 486 | $_course = api_get_course_info(); |
487 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
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 | 491 | if (is_array($attendance_id)) { |
492 | 492 | foreach ($attendance_id as $id) { |
493 | - $id = intval($id); |
|
493 | + $id = intval($id); |
|
494 | 494 | $sql = "UPDATE $tbl_attendance SET active = 2 |
495 | 495 | WHERE c_id = $course_id AND id = '$id'"; |
496 | 496 | $result = Database::query($sql); |
@@ -506,8 +506,8 @@ discard block |
||
506 | 506 | ); |
507 | 507 | } |
508 | 508 | } |
509 | - } else { |
|
510 | - $attendance_id= intval($attendance_id); |
|
509 | + } else { |
|
510 | + $attendance_id = intval($attendance_id); |
|
511 | 511 | $sql = "UPDATE $tbl_attendance SET active = 2 |
512 | 512 | WHERE c_id = $course_id AND id = '$attendance_id'"; |
513 | 513 | |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | public function changeVisibility($attendanceId, $status = 1) |
539 | 539 | { |
540 | 540 | $_course = api_get_course_info(); |
541 | - $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
541 | + $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
542 | 542 | $user_id = api_get_user_id(); |
543 | 543 | $course_id = $_course['real_id']; |
544 | 544 | $status = intval($status); |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | |
551 | 551 | if (is_array($attendanceId)) { |
552 | 552 | foreach ($attendanceId as $id) { |
553 | - $id = intval($id); |
|
553 | + $id = intval($id); |
|
554 | 554 | $sql = "UPDATE $tbl_attendance SET active = $status |
555 | 555 | WHERE c_id = $course_id AND id = '$id'"; |
556 | 556 | $result = Database::query($sql); |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id); |
561 | 561 | } |
562 | 562 | } |
563 | - } else { |
|
564 | - $attendanceId = intval($attendanceId); |
|
563 | + } else { |
|
564 | + $attendanceId = intval($attendanceId); |
|
565 | 565 | $sql = "UPDATE $tbl_attendance SET active = $status |
566 | 566 | WHERE c_id = $course_id AND id = '$attendanceId'"; |
567 | 567 | $result = Database::query($sql); |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
592 | 592 | $course_id = api_get_course_int_id(); |
593 | 593 | $attendance_id = intval($attendance_id); |
594 | - $locked = ($lock)?1:0; |
|
594 | + $locked = ($lock) ? 1 : 0; |
|
595 | 595 | $upd = "UPDATE $tbl_attendance SET locked = $locked |
596 | 596 | WHERE c_id = $course_id AND id = $attendance_id"; |
597 | 597 | $result = Database::query($upd); |
@@ -720,8 +720,8 @@ discard block |
||
720 | 720 | */ |
721 | 721 | public function attendance_sheet_add($calendar_id, $users_present, $attendance_id) |
722 | 722 | { |
723 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
724 | - $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
723 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
724 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
725 | 725 | |
726 | 726 | $calendar_id = intval($calendar_id); |
727 | 727 | $attendance_id = intval($attendance_id); |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | $course_id = api_get_course_int_id(); |
730 | 730 | |
731 | 731 | $user_ids = array_keys($users); |
732 | - $users_absent = array_diff($user_ids,$users_present); |
|
732 | + $users_absent = array_diff($user_ids, $users_present); |
|
733 | 733 | $affected_rows = 0; |
734 | 734 | |
735 | 735 | // get last edit type |
@@ -993,13 +993,13 @@ discard block |
||
993 | 993 | public function get_faults_of_user($user_id, $attendance_id, $groupId = null) |
994 | 994 | { |
995 | 995 | // initializing database table and variables |
996 | - $user_id = intval($user_id); |
|
996 | + $user_id = intval($user_id); |
|
997 | 997 | $attendance_id = intval($attendance_id); |
998 | 998 | $results = array(); |
999 | 999 | $calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id); |
1000 | 1000 | // $total_done_attendance = $attendance_data['attendance_qualify_max']; |
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); |
|
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); |
|
1003 | 1003 | |
1004 | 1004 | //This is the main change of the BT#1381 |
1005 | 1005 | //$total_done_attendance = $calendar_count; |
@@ -1012,7 +1012,7 @@ discard block |
||
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; |
@@ -1046,13 +1046,13 @@ discard block |
||
1046 | 1046 | //$course_code = $course['code']; |
1047 | 1047 | //$course_info = api_get_course_info($course_code); |
1048 | 1048 | $course_id = $course['real_id']; |
1049 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1049 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1050 | 1050 | |
1051 | 1051 | $attendances_by_course = $this->get_attendances_list($course_id); |
1052 | 1052 | |
1053 | 1053 | foreach ($attendances_by_course as $attendance) { |
1054 | 1054 | // get total faults and total weight |
1055 | - $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1055 | + $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1056 | 1056 | $sql = "SELECT score |
1057 | 1057 | FROM $tbl_attendance_result |
1058 | 1058 | WHERE |
@@ -1065,16 +1065,16 @@ discard block |
||
1065 | 1065 | $row = Database::fetch_array($rs); |
1066 | 1066 | $score = $row['score']; |
1067 | 1067 | } |
1068 | - $faults = $total_done_attendance-$score; |
|
1069 | - $faults = $faults > 0 ? $faults:0; |
|
1068 | + $faults = $total_done_attendance - $score; |
|
1069 | + $faults = $faults > 0 ? $faults : 0; |
|
1070 | 1070 | $total_faults += $faults; |
1071 | 1071 | $total_weight += $total_done_attendance; |
1072 | 1072 | } |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0; |
|
1075 | + $porcent = $total_weight > 0 ? round(($total_faults * 100) / $total_weight, 0) : 0; |
|
1076 | 1076 | $results['faults'] = $total_faults; |
1077 | - $results['total'] = $total_weight; |
|
1077 | + $results['total'] = $total_weight; |
|
1078 | 1078 | $results['porcent'] = $porcent; |
1079 | 1079 | |
1080 | 1080 | return $results; |
@@ -1092,7 +1092,7 @@ discard block |
||
1092 | 1092 | { |
1093 | 1093 | // Database tables and variables |
1094 | 1094 | $course_info = api_get_course_info($course_code); |
1095 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1095 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
1096 | 1096 | $user_id = intval($user_id); |
1097 | 1097 | $results = array(); |
1098 | 1098 | $total_faults = $total_weight = $porcent = 0; |
@@ -1100,7 +1100,7 @@ discard block |
||
1100 | 1100 | |
1101 | 1101 | foreach ($attendances_by_course as $attendance) { |
1102 | 1102 | // Get total faults and total weight |
1103 | - $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1103 | + $total_done_attendance = $attendance['attendance_qualify_max']; |
|
1104 | 1104 | $sql = "SELECT score FROM $tbl_attendance_result |
1105 | 1105 | WHERE |
1106 | 1106 | c_id = {$course_info['real_id']} AND |
@@ -1112,15 +1112,15 @@ discard block |
||
1112 | 1112 | $row = Database::fetch_array($rs); |
1113 | 1113 | $score = $row['score']; |
1114 | 1114 | } |
1115 | - $faults = $total_done_attendance-$score; |
|
1116 | - $faults = $faults > 0 ? $faults:0; |
|
1115 | + $faults = $total_done_attendance - $score; |
|
1116 | + $faults = $faults > 0 ? $faults : 0; |
|
1117 | 1117 | $total_faults += $faults; |
1118 | 1118 | $total_weight += $total_done_attendance; |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0; |
|
1121 | + $porcent = $total_weight > 0 ? round(($total_faults * 100) / $total_weight, 0) : 0; |
|
1122 | 1122 | $results['faults'] = $total_faults; |
1123 | - $results['total'] = $total_weight; |
|
1123 | + $results['total'] = $total_weight; |
|
1124 | 1124 | $results['porcent'] = $porcent; |
1125 | 1125 | |
1126 | 1126 | return $results; |
@@ -1134,8 +1134,8 @@ discard block |
||
1134 | 1134 | */ |
1135 | 1135 | public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null) |
1136 | 1136 | { |
1137 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1138 | - $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1137 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1138 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1139 | 1139 | |
1140 | 1140 | $attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId); |
1141 | 1141 | $calendar_ids = array(); |
@@ -1157,7 +1157,7 @@ discard block |
||
1157 | 1157 | WHERE |
1158 | 1158 | c_id = $course_id AND |
1159 | 1159 | user_id = '$uid' AND |
1160 | - attendance_calendar_id IN(".implode(',',$calendar_ids).") |
|
1160 | + attendance_calendar_id IN(".implode(',', $calendar_ids).") |
|
1161 | 1161 | "; |
1162 | 1162 | $res = Database::query($sql); |
1163 | 1163 | if (Database::num_rows($res) > 0) { |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | att.c_id = $course_id AND |
1180 | 1180 | cal.c_id = $course_id AND |
1181 | 1181 | att.user_id = '$user_id' AND |
1182 | - att.attendance_calendar_id IN (".implode(',',$calendar_ids).") |
|
1182 | + att.attendance_calendar_id IN (".implode(',', $calendar_ids).") |
|
1183 | 1183 | ORDER BY date_time"; |
1184 | 1184 | $res = Database::query($sql); |
1185 | 1185 | if (Database::num_rows($res) > 0) { |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | */ |
1256 | 1256 | public function get_user_score($user_id, $attendance_id, $groupId = null) |
1257 | 1257 | { |
1258 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
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); |
@@ -1369,7 +1369,7 @@ discard block |
||
1369 | 1369 | "; |
1370 | 1370 | } |
1371 | 1371 | |
1372 | - if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) { |
|
1372 | + if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done', 'calendar_id'))) { |
|
1373 | 1373 | $type = 'all'; |
1374 | 1374 | } |
1375 | 1375 | |
@@ -1377,7 +1377,7 @@ discard block |
||
1377 | 1377 | case 'calendar_id': |
1378 | 1378 | $calendar_id = intval($calendar_id); |
1379 | 1379 | if (!empty($calendar_id)) { |
1380 | - $sql.= " AND c.id = $calendar_id"; |
|
1380 | + $sql .= " AND c.id = $calendar_id"; |
|
1381 | 1381 | } |
1382 | 1382 | break; |
1383 | 1383 | case 'today': |
@@ -1398,7 +1398,7 @@ discard block |
||
1398 | 1398 | $rs = Database::query($sql); |
1399 | 1399 | $data = array(); |
1400 | 1400 | if (Database::num_rows($rs) > 0) { |
1401 | - while ($row = Database::fetch_array($rs,'ASSOC')) { |
|
1401 | + while ($row = Database::fetch_array($rs, 'ASSOC')) { |
|
1402 | 1402 | $row['db_date_time'] = $row['date_time']; |
1403 | 1403 | $row['date_time'] = api_get_local_time($row['date_time']); |
1404 | 1404 | $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT); |
@@ -1762,14 +1762,14 @@ discard block |
||
1762 | 1762 | * @param int The number of years to add |
1763 | 1763 | * @return int The new timestamp |
1764 | 1764 | */ |
1765 | - private function add_month($timestamp, $num=1) |
|
1765 | + private function add_month($timestamp, $num = 1) |
|
1766 | 1766 | { |
1767 | 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; |
|
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 | 1773 | } else { |
1774 | 1774 | $m += $num; |
1775 | 1775 | } |
@@ -1827,7 +1827,7 @@ discard block |
||
1827 | 1827 | * @param bool true for removing all calendar inside current attendance, false for removing by calendar id |
1828 | 1828 | * @return int affected rows |
1829 | 1829 | */ |
1830 | - public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false) |
|
1830 | + public function attendance_calendar_delete($calendar_id, $attendance_id, $all_delete = false) |
|
1831 | 1831 | { |
1832 | 1832 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
1833 | 1833 | $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
@@ -1963,7 +1963,7 @@ discard block |
||
1963 | 1963 | } |
1964 | 1964 | |
1965 | 1965 | $sessionId = api_get_session_id(); |
1966 | - $courseCode = api_get_course_id(); |
|
1966 | + $courseCode = api_get_course_id(); |
|
1967 | 1967 | if (!empty($sessionId)) { |
1968 | 1968 | $users = CourseManager:: get_user_list_from_course_code( |
1969 | 1969 | $courseCode, |
@@ -1984,7 +1984,7 @@ discard block |
||
1984 | 1984 | |
1985 | 1985 | $dateTimeStartOriginal = new DateTime($startDate); |
1986 | 1986 | $dateTimeStart = new DateTime($startDate); |
1987 | - $dateTimeEnd= new DateTime($endDate); |
|
1987 | + $dateTimeEnd = new DateTime($endDate); |
|
1988 | 1988 | $interval = $dateTimeStart->diff($dateTimeEnd); |
1989 | 1989 | $days = intval($interval->format('%a')); |
1990 | 1990 | |
@@ -2057,7 +2057,7 @@ discard block |
||
2057 | 2057 | 0, |
2058 | 2058 | $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
2059 | 2059 | ); |
2060 | - $row ++; |
|
2060 | + $row++; |
|
2061 | 2061 | } |
2062 | 2062 | |
2063 | 2063 | $column = 1; |
@@ -2134,7 +2134,7 @@ discard block |
||
2134 | 2134 | $tableToString = $table->toHtml(); |
2135 | 2135 | |
2136 | 2136 | $params = array( |
2137 | - 'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(), |
|
2137 | + 'filename' => get_lang('Attendance').'_'.api_get_utc_datetime(), |
|
2138 | 2138 | 'pdf_title' => get_lang('Attendance'), |
2139 | 2139 | 'course_code' => api_get_course_id(), |
2140 | 2140 | 'show_real_course_teachers' => true |
@@ -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,112 +1508,112 @@ 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, |
|
1584 | + $params = array( |
|
1585 | + 'c_id' => $course_id, |
|
1586 | + 'date_time' => $this->date_time, |
|
1587 | + 'attendance_id' => $attendance_id, |
|
1588 | 1588 | 'done_attendance' => 0 |
1589 | - ); |
|
1590 | - $id = Database::insert($tbl_attendance_calendar, $params); |
|
1591 | - |
|
1592 | - if ($id) { |
|
1593 | - $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id"; |
|
1594 | - Database::query($sql); |
|
1595 | - $affected_rows++; |
|
1596 | - } |
|
1597 | - $this->addAttendanceCalendarToGroup($id, $course_id, $groupList); |
|
1598 | - //} |
|
1599 | - |
|
1600 | - // update locked attendance |
|
1601 | - $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1602 | - if (!$is_all_calendar_done) { |
|
1603 | - self::lock_attendance($attendance_id, false); |
|
1604 | - } else { |
|
1605 | - self::lock_attendance($attendance_id); |
|
1606 | - } |
|
1607 | - return $affected_rows; |
|
1608 | - } |
|
1609 | - |
|
1610 | - /** |
|
1611 | - * @param int $calendarId |
|
1612 | - * @param int $courseId |
|
1613 | - * @param array $groupList |
|
1614 | - */ |
|
1615 | - public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList) |
|
1616 | - { |
|
1589 | + ); |
|
1590 | + $id = Database::insert($tbl_attendance_calendar, $params); |
|
1591 | + |
|
1592 | + if ($id) { |
|
1593 | + $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id"; |
|
1594 | + Database::query($sql); |
|
1595 | + $affected_rows++; |
|
1596 | + } |
|
1597 | + $this->addAttendanceCalendarToGroup($id, $course_id, $groupList); |
|
1598 | + //} |
|
1599 | + |
|
1600 | + // update locked attendance |
|
1601 | + $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1602 | + if (!$is_all_calendar_done) { |
|
1603 | + self::lock_attendance($attendance_id, false); |
|
1604 | + } else { |
|
1605 | + self::lock_attendance($attendance_id); |
|
1606 | + } |
|
1607 | + return $affected_rows; |
|
1608 | + } |
|
1609 | + |
|
1610 | + /** |
|
1611 | + * @param int $calendarId |
|
1612 | + * @param int $courseId |
|
1613 | + * @param array $groupList |
|
1614 | + */ |
|
1615 | + public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList) |
|
1616 | + { |
|
1617 | 1617 | if (empty($groupList)) { |
1618 | 1618 | return false; |
1619 | 1619 | } |
@@ -1641,506 +1641,506 @@ discard block |
||
1641 | 1641 | Database::insert($table, $params); |
1642 | 1642 | } |
1643 | 1643 | } |
1644 | - } |
|
1645 | - |
|
1646 | - /** |
|
1647 | - * @param int $calendarId |
|
1648 | - * @param int $courseId |
|
1649 | - * @param int $groupId |
|
1650 | - * @return array |
|
1651 | - */ |
|
1652 | - public function getGroupListByAttendanceCalendar($calendarId, $courseId) |
|
1653 | - { |
|
1654 | - $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1655 | - return Database::select( |
|
1656 | - '*', |
|
1657 | - $table, |
|
1658 | - array('where'=> |
|
1659 | - array( |
|
1660 | - 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1661 | - ) |
|
1662 | - ) |
|
1663 | - ); |
|
1664 | - } |
|
1665 | - |
|
1666 | - /** |
|
1667 | - * @param int $calendarId |
|
1668 | - * @param int $courseId |
|
1669 | - * @param int $groupId |
|
1670 | - * @return array |
|
1671 | - */ |
|
1672 | - public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId) |
|
1673 | - { |
|
1674 | - $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1675 | - return Database::select( |
|
1676 | - '*', |
|
1677 | - $table, |
|
1678 | - array('where'=> |
|
1679 | - array( |
|
1680 | - 'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId) |
|
1681 | - ) |
|
1682 | - ) |
|
1683 | - ); |
|
1684 | - } |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * @param int $calendarId |
|
1688 | - * @param int $courseId |
|
1689 | - * @param int $groupId |
|
1644 | + } |
|
1645 | + |
|
1646 | + /** |
|
1647 | + * @param int $calendarId |
|
1648 | + * @param int $courseId |
|
1649 | + * @param int $groupId |
|
1650 | + * @return array |
|
1651 | + */ |
|
1652 | + public function getGroupListByAttendanceCalendar($calendarId, $courseId) |
|
1653 | + { |
|
1654 | + $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1655 | + return Database::select( |
|
1656 | + '*', |
|
1657 | + $table, |
|
1658 | + array('where'=> |
|
1659 | + array( |
|
1660 | + 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1661 | + ) |
|
1662 | + ) |
|
1663 | + ); |
|
1664 | + } |
|
1665 | + |
|
1666 | + /** |
|
1667 | + * @param int $calendarId |
|
1668 | + * @param int $courseId |
|
1669 | + * @param int $groupId |
|
1670 | + * @return array |
|
1671 | + */ |
|
1672 | + public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId) |
|
1673 | + { |
|
1674 | + $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1675 | + return Database::select( |
|
1676 | + '*', |
|
1677 | + $table, |
|
1678 | + array('where'=> |
|
1679 | + array( |
|
1680 | + 'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId) |
|
1681 | + ) |
|
1682 | + ) |
|
1683 | + ); |
|
1684 | + } |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * @param int $calendarId |
|
1688 | + * @param int $courseId |
|
1689 | + * @param int $groupId |
|
1690 | 1690 | * |
1691 | - * @return array |
|
1692 | - */ |
|
1693 | - public function deleteAttendanceCalendarGroup($calendarId, $courseId) |
|
1694 | - { |
|
1695 | - $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1696 | - Database::delete( |
|
1697 | - $table, |
|
1698 | - array( |
|
1699 | - 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1700 | - ) |
|
1701 | - ); |
|
1702 | - } |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * save repeated date inside attendance calendar table |
|
1706 | - * @param int $attendance_id |
|
1707 | - * @param int $start_date start date in tms |
|
1708 | - * @param int $end_date end date in tms |
|
1709 | - * @param string $repeat_type daily, weekly, monthlyByDate |
|
1710 | - * @param array $groupList |
|
1711 | - */ |
|
1712 | - public function attendance_repeat_calendar_add( |
|
1713 | - $attendance_id, |
|
1714 | - $start_date, |
|
1715 | - $end_date, |
|
1716 | - $repeat_type, |
|
1717 | - $groupList = array() |
|
1718 | - ) { |
|
1719 | - $attendance_id = intval($attendance_id); |
|
1720 | - // save start date |
|
1721 | - $datetimezone = api_get_utc_datetime($start_date); |
|
1722 | - $this->set_date_time($datetimezone); |
|
1723 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1724 | - |
|
1725 | - // 86400 = 24 hours in seconds |
|
1726 | - // 604800 = 1 week in seconds |
|
1727 | - // Saves repeated dates |
|
1728 | - switch ($repeat_type) { |
|
1729 | - case 'daily': |
|
1730 | - $j = 1; |
|
1731 | - for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) { |
|
1732 | - $datetimezone = api_get_utc_datetime($i); |
|
1733 | - $this->set_date_time($datetimezone); |
|
1734 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1735 | - $j++; |
|
1736 | - } |
|
1737 | - break; |
|
1738 | - case 'weekly': |
|
1739 | - $j = 1; |
|
1740 | - for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { |
|
1741 | - $datetimezone = api_get_utc_datetime($i); |
|
1742 | - $this->set_date_time($datetimezone); |
|
1743 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1744 | - $j++; |
|
1745 | - } |
|
1746 | - break; |
|
1747 | - case 'monthlyByDate': |
|
1748 | - $j = 1; |
|
1749 | - //@todo fix bug with february |
|
1750 | - for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) { |
|
1751 | - $datetimezone = api_get_utc_datetime($i); |
|
1752 | - $this->set_date_time($datetimezone); |
|
1753 | - $this->attendance_calendar_add($attendance_id, $groupList); |
|
1754 | - $j++; |
|
1755 | - } |
|
1756 | - break; |
|
1757 | - } |
|
1758 | - } |
|
1759 | - |
|
1760 | - /** |
|
1761 | - * Adds x months to a UNIX timestamp |
|
1762 | - * @param int The timestamp |
|
1763 | - * @param int The number of years to add |
|
1764 | - * @return int The new timestamp |
|
1765 | - */ |
|
1766 | - private function add_month($timestamp, $num=1) |
|
1767 | - { |
|
1768 | - $values = api_get_utc_datetime($timestamp); |
|
1769 | - $values = str_replace(array(':','-',' '), '/', $values); |
|
1770 | - list($y, $m, $d, $h, $n, $s) = split('/',$values); |
|
1771 | - if($m+$num>12) { |
|
1772 | - $y += floor($num/12); |
|
1773 | - $m += $num%12; |
|
1774 | - } else { |
|
1775 | - $m += $num; |
|
1776 | - } |
|
1777 | - //date_default_timezone_set('UTC'); |
|
1778 | - // return mktime($h, $n, $s, $m, $d, $y); |
|
1779 | - $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC'); |
|
1780 | - if (!empty($result)) { |
|
1781 | - return $result; |
|
1782 | - } |
|
1783 | - return false; |
|
1784 | - } |
|
1785 | - |
|
1786 | - /** |
|
1787 | - * edit a datetime inside attendance calendar table |
|
1788 | - * @param int attendance calendar id |
|
1789 | - * @param int attendance id |
|
1790 | - * @return int affected rows |
|
1791 | - */ |
|
1792 | - public function attendance_calendar_edit($calendar_id, $attendance_id) |
|
1793 | - { |
|
1794 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1795 | - $affected_rows = 0; |
|
1796 | - $attendance_id = intval($attendance_id); |
|
1797 | - $course_id = api_get_course_int_id(); |
|
1798 | - // check if datetime already exists inside the table |
|
1799 | - $sql = "SELECT id FROM $tbl_attendance_calendar |
|
1691 | + * @return array |
|
1692 | + */ |
|
1693 | + public function deleteAttendanceCalendarGroup($calendarId, $courseId) |
|
1694 | + { |
|
1695 | + $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP); |
|
1696 | + Database::delete( |
|
1697 | + $table, |
|
1698 | + array( |
|
1699 | + 'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId) |
|
1700 | + ) |
|
1701 | + ); |
|
1702 | + } |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * save repeated date inside attendance calendar table |
|
1706 | + * @param int $attendance_id |
|
1707 | + * @param int $start_date start date in tms |
|
1708 | + * @param int $end_date end date in tms |
|
1709 | + * @param string $repeat_type daily, weekly, monthlyByDate |
|
1710 | + * @param array $groupList |
|
1711 | + */ |
|
1712 | + public function attendance_repeat_calendar_add( |
|
1713 | + $attendance_id, |
|
1714 | + $start_date, |
|
1715 | + $end_date, |
|
1716 | + $repeat_type, |
|
1717 | + $groupList = array() |
|
1718 | + ) { |
|
1719 | + $attendance_id = intval($attendance_id); |
|
1720 | + // save start date |
|
1721 | + $datetimezone = api_get_utc_datetime($start_date); |
|
1722 | + $this->set_date_time($datetimezone); |
|
1723 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1724 | + |
|
1725 | + // 86400 = 24 hours in seconds |
|
1726 | + // 604800 = 1 week in seconds |
|
1727 | + // Saves repeated dates |
|
1728 | + switch ($repeat_type) { |
|
1729 | + case 'daily': |
|
1730 | + $j = 1; |
|
1731 | + for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) { |
|
1732 | + $datetimezone = api_get_utc_datetime($i); |
|
1733 | + $this->set_date_time($datetimezone); |
|
1734 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1735 | + $j++; |
|
1736 | + } |
|
1737 | + break; |
|
1738 | + case 'weekly': |
|
1739 | + $j = 1; |
|
1740 | + for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { |
|
1741 | + $datetimezone = api_get_utc_datetime($i); |
|
1742 | + $this->set_date_time($datetimezone); |
|
1743 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1744 | + $j++; |
|
1745 | + } |
|
1746 | + break; |
|
1747 | + case 'monthlyByDate': |
|
1748 | + $j = 1; |
|
1749 | + //@todo fix bug with february |
|
1750 | + for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) { |
|
1751 | + $datetimezone = api_get_utc_datetime($i); |
|
1752 | + $this->set_date_time($datetimezone); |
|
1753 | + $this->attendance_calendar_add($attendance_id, $groupList); |
|
1754 | + $j++; |
|
1755 | + } |
|
1756 | + break; |
|
1757 | + } |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** |
|
1761 | + * Adds x months to a UNIX timestamp |
|
1762 | + * @param int The timestamp |
|
1763 | + * @param int The number of years to add |
|
1764 | + * @return int The new timestamp |
|
1765 | + */ |
|
1766 | + private function add_month($timestamp, $num=1) |
|
1767 | + { |
|
1768 | + $values = api_get_utc_datetime($timestamp); |
|
1769 | + $values = str_replace(array(':','-',' '), '/', $values); |
|
1770 | + list($y, $m, $d, $h, $n, $s) = split('/',$values); |
|
1771 | + if($m+$num>12) { |
|
1772 | + $y += floor($num/12); |
|
1773 | + $m += $num%12; |
|
1774 | + } else { |
|
1775 | + $m += $num; |
|
1776 | + } |
|
1777 | + //date_default_timezone_set('UTC'); |
|
1778 | + // return mktime($h, $n, $s, $m, $d, $y); |
|
1779 | + $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC'); |
|
1780 | + if (!empty($result)) { |
|
1781 | + return $result; |
|
1782 | + } |
|
1783 | + return false; |
|
1784 | + } |
|
1785 | + |
|
1786 | + /** |
|
1787 | + * edit a datetime inside attendance calendar table |
|
1788 | + * @param int attendance calendar id |
|
1789 | + * @param int attendance id |
|
1790 | + * @return int affected rows |
|
1791 | + */ |
|
1792 | + public function attendance_calendar_edit($calendar_id, $attendance_id) |
|
1793 | + { |
|
1794 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1795 | + $affected_rows = 0; |
|
1796 | + $attendance_id = intval($attendance_id); |
|
1797 | + $course_id = api_get_course_int_id(); |
|
1798 | + // check if datetime already exists inside the table |
|
1799 | + $sql = "SELECT id FROM $tbl_attendance_calendar |
|
1800 | 1800 | WHERE |
1801 | 1801 | c_id = $course_id AND |
1802 | 1802 | date_time = '".Database::escape_string($this->date_time)."' AND |
1803 | 1803 | attendance_id = '$attendance_id'"; |
1804 | - $rs = Database::query($sql); |
|
1804 | + $rs = Database::query($sql); |
|
1805 | 1805 | |
1806 | - if (Database::num_rows($rs) == 0) { |
|
1807 | - $sql = "UPDATE $tbl_attendance_calendar |
|
1806 | + if (Database::num_rows($rs) == 0) { |
|
1807 | + $sql = "UPDATE $tbl_attendance_calendar |
|
1808 | 1808 | SET date_time='".Database::escape_string($this->date_time)."' |
1809 | 1809 | WHERE c_id = $course_id AND id = '".intval($calendar_id)."'"; |
1810 | - Database::query($sql); |
|
1811 | - } |
|
1812 | - |
|
1813 | - // update locked attendance |
|
1814 | - $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1815 | - if (!$is_all_calendar_done) { |
|
1816 | - self::lock_attendance($attendance_id, false); |
|
1817 | - } else { |
|
1818 | - self::lock_attendance($attendance_id); |
|
1819 | - } |
|
1820 | - |
|
1821 | - return $affected_rows; |
|
1822 | - } |
|
1823 | - |
|
1824 | - /** |
|
1825 | - * delete a datetime from attendance calendar table |
|
1826 | - * @param int attendance calendar id |
|
1827 | - * @param int attendance id |
|
1828 | - * @param bool true for removing all calendar inside current attendance, false for removing by calendar id |
|
1829 | - * @return int affected rows |
|
1830 | - */ |
|
1831 | - public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false) |
|
1832 | - { |
|
1833 | - $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1834 | - $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1835 | - |
|
1836 | - $attendance_id = intval($attendance_id); |
|
1837 | - // get all registered users inside current course |
|
1838 | - $users = $this->get_users_rel_course(); |
|
1839 | - $user_ids = array_keys($users); |
|
1840 | - $course_id = api_get_course_int_id(); |
|
1841 | - $affected_rows = 0; |
|
1842 | - if ($all_delete) { |
|
1843 | - $attendance_calendar = $this->get_attendance_calendar($attendance_id); |
|
1844 | - // get all dates from calendar by current attendance |
|
1845 | - if (!empty($attendance_calendar)) { |
|
1846 | - foreach ($attendance_calendar as $cal) { |
|
1847 | - // delete all data from attendance sheet |
|
1848 | - $sql = "DELETE FROM $tbl_attendance_sheet |
|
1810 | + Database::query($sql); |
|
1811 | + } |
|
1812 | + |
|
1813 | + // update locked attendance |
|
1814 | + $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id); |
|
1815 | + if (!$is_all_calendar_done) { |
|
1816 | + self::lock_attendance($attendance_id, false); |
|
1817 | + } else { |
|
1818 | + self::lock_attendance($attendance_id); |
|
1819 | + } |
|
1820 | + |
|
1821 | + return $affected_rows; |
|
1822 | + } |
|
1823 | + |
|
1824 | + /** |
|
1825 | + * delete a datetime from attendance calendar table |
|
1826 | + * @param int attendance calendar id |
|
1827 | + * @param int attendance id |
|
1828 | + * @param bool true for removing all calendar inside current attendance, false for removing by calendar id |
|
1829 | + * @return int affected rows |
|
1830 | + */ |
|
1831 | + public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false) |
|
1832 | + { |
|
1833 | + $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
1834 | + $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
|
1835 | + |
|
1836 | + $attendance_id = intval($attendance_id); |
|
1837 | + // get all registered users inside current course |
|
1838 | + $users = $this->get_users_rel_course(); |
|
1839 | + $user_ids = array_keys($users); |
|
1840 | + $course_id = api_get_course_int_id(); |
|
1841 | + $affected_rows = 0; |
|
1842 | + if ($all_delete) { |
|
1843 | + $attendance_calendar = $this->get_attendance_calendar($attendance_id); |
|
1844 | + // get all dates from calendar by current attendance |
|
1845 | + if (!empty($attendance_calendar)) { |
|
1846 | + foreach ($attendance_calendar as $cal) { |
|
1847 | + // delete all data from attendance sheet |
|
1848 | + $sql = "DELETE FROM $tbl_attendance_sheet |
|
1849 | 1849 | WHERE c_id = $course_id AND attendance_calendar_id = '".intval($cal['id'])."'"; |
1850 | - Database::query($sql); |
|
1851 | - // delete data from attendance calendar |
|
1852 | - $sql = "DELETE FROM $tbl_attendance_calendar |
|
1850 | + Database::query($sql); |
|
1851 | + // delete data from attendance calendar |
|
1852 | + $sql = "DELETE FROM $tbl_attendance_calendar |
|
1853 | 1853 | WHERE c_id = $course_id AND id = '".intval($cal['id'])."'"; |
1854 | - Database::query($sql); |
|
1855 | - |
|
1856 | - $this->deleteAttendanceCalendarGroup($cal['id'], $course_id); |
|
1857 | - $affected_rows++; |
|
1858 | - } |
|
1859 | - } |
|
1860 | - } else { |
|
1861 | - // delete just one row from attendance sheet by the calendar id |
|
1862 | - $sql = "DELETE FROM $tbl_attendance_sheet |
|
1854 | + Database::query($sql); |
|
1855 | + |
|
1856 | + $this->deleteAttendanceCalendarGroup($cal['id'], $course_id); |
|
1857 | + $affected_rows++; |
|
1858 | + } |
|
1859 | + } |
|
1860 | + } else { |
|
1861 | + // delete just one row from attendance sheet by the calendar id |
|
1862 | + $sql = "DELETE FROM $tbl_attendance_sheet |
|
1863 | 1863 | WHERE c_id = $course_id AND attendance_calendar_id = '".intval($calendar_id)."'"; |
1864 | - Database::query($sql); |
|
1865 | - // delete data from attendance calendar |
|
1866 | - $sql = "DELETE FROM $tbl_attendance_calendar |
|
1864 | + Database::query($sql); |
|
1865 | + // delete data from attendance calendar |
|
1866 | + $sql = "DELETE FROM $tbl_attendance_calendar |
|
1867 | 1867 | WHERE c_id = $course_id AND id = '".intval($calendar_id)."'"; |
1868 | - Database::query($sql); |
|
1869 | - |
|
1870 | - $this->deleteAttendanceCalendarGroup($calendar_id, $course_id); |
|
1871 | - $affected_rows++; |
|
1872 | - } |
|
1873 | - |
|
1874 | - // update users' results |
|
1875 | - $this->update_users_results($user_ids, $attendance_id); |
|
1876 | - |
|
1877 | - return $affected_rows; |
|
1878 | - } |
|
1879 | - |
|
1880 | - /** Setters for fields of attendances tables **/ |
|
1881 | - public function set_session_id($session_id) |
|
1882 | - { |
|
1883 | - $this->session_id = $session_id; |
|
1884 | - } |
|
1885 | - |
|
1886 | - public function set_course_id($course_id) |
|
1887 | - { |
|
1888 | - $this->course_id = $course_id; |
|
1889 | - } |
|
1890 | - |
|
1891 | - public function set_date_time($datetime) |
|
1892 | - { |
|
1893 | - $this->date_time = $datetime; |
|
1894 | - } |
|
1895 | - |
|
1896 | - public function set_name($name) |
|
1897 | - { |
|
1898 | - $this->name = $name; |
|
1899 | - } |
|
1900 | - |
|
1901 | - public function set_description($description) |
|
1902 | - { |
|
1903 | - $this->description = $description; |
|
1904 | - } |
|
1905 | - |
|
1906 | - public function set_attendance_qualify_title($attendance_qualify_title) |
|
1907 | - { |
|
1908 | - $this->attendance_qualify_title = $attendance_qualify_title; |
|
1909 | - } |
|
1910 | - |
|
1911 | - public function set_attendance_weight($attendance_weight) |
|
1912 | - { |
|
1913 | - $this->attendance_weight = $attendance_weight; |
|
1914 | - } |
|
1915 | - |
|
1916 | - /** Getters for fields of attendances tables **/ |
|
1917 | - public function get_session_id() |
|
1918 | - { |
|
1919 | - return $this->session_id; |
|
1920 | - } |
|
1921 | - |
|
1922 | - public function get_course_id() |
|
1923 | - { |
|
1924 | - return $this->course_id; |
|
1925 | - } |
|
1926 | - |
|
1927 | - public function get_date_time() |
|
1928 | - { |
|
1929 | - return $this->date_time; |
|
1930 | - } |
|
1931 | - |
|
1932 | - public function get_name() |
|
1933 | - { |
|
1934 | - return $this->name; |
|
1935 | - } |
|
1936 | - |
|
1937 | - public function get_description() |
|
1938 | - { |
|
1939 | - return $this->description; |
|
1940 | - } |
|
1941 | - |
|
1942 | - public function get_attendance_qualify_title() |
|
1943 | - { |
|
1944 | - return $this->attendance_qualify_title; |
|
1945 | - } |
|
1946 | - |
|
1947 | - public function get_attendance_weight() |
|
1948 | - { |
|
1949 | - return $this->attendance_weight; |
|
1950 | - } |
|
1951 | - |
|
1952 | - /** |
|
1953 | - * @param string $startDate in UTC time |
|
1954 | - * @param string $endDate in UTC time |
|
1955 | - * |
|
1956 | - * @return array |
|
1957 | - */ |
|
1958 | - public function getAttendanceLogin($startDate, $endDate) |
|
1959 | - { |
|
1960 | - if (empty($startDate) || $startDate == '0000-00-00' || |
|
1961 | - empty($endDate) || $endDate == '0000-00-00' |
|
1962 | - ) { |
|
1963 | - return false; |
|
1964 | - } |
|
1965 | - |
|
1966 | - $sessionId = api_get_session_id(); |
|
1967 | - $courseCode = api_get_course_id(); |
|
1968 | - if (!empty($sessionId)) { |
|
1969 | - $users = CourseManager:: get_user_list_from_course_code( |
|
1970 | - $courseCode, |
|
1971 | - $sessionId, |
|
1972 | - '', |
|
1973 | - 'lastname', |
|
1974 | - 0 |
|
1975 | - ); |
|
1976 | - } else { |
|
1977 | - $users = CourseManager:: get_user_list_from_course_code( |
|
1978 | - $courseCode, |
|
1979 | - 0, |
|
1980 | - '', |
|
1981 | - 'lastname', |
|
1982 | - STUDENT |
|
1983 | - ); |
|
1984 | - } |
|
1985 | - |
|
1986 | - $dateTimeStartOriginal = new DateTime($startDate); |
|
1987 | - $dateTimeStart = new DateTime($startDate); |
|
1988 | - $dateTimeEnd= new DateTime($endDate); |
|
1989 | - $interval = $dateTimeStart->diff($dateTimeEnd); |
|
1990 | - $days = intval($interval->format('%a')); |
|
1991 | - |
|
1992 | - $dateList = array($dateTimeStart->format('Y-m-d')); |
|
1993 | - $headers = array( |
|
1994 | - get_lang('User'), |
|
1995 | - $dateTimeStart->format('Y-m-d') |
|
1996 | - ); |
|
1997 | - |
|
1998 | - for ($i = 0; $i < $days; $i++) { |
|
1999 | - $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D')); |
|
2000 | - $date = $dateTimeStart->format('Y-m-d'); |
|
2001 | - $dateList[] = $date; |
|
2002 | - $headers[] = $date; |
|
2003 | - } |
|
2004 | - |
|
2005 | - $accessData = CourseManager::getCourseAccessPerCourseAndSession( |
|
2006 | - $courseCode, |
|
2007 | - $sessionId, |
|
2008 | - $dateTimeStartOriginal->format('Y-m-d H:i:s'), |
|
2009 | - $dateTimeEnd->format('Y-m-d H:i:s') |
|
2010 | - ); |
|
2011 | - |
|
2012 | - $results = array(); |
|
2013 | - if (!empty($accessData)) { |
|
2014 | - foreach ($accessData as $data) { |
|
2015 | - $onlyDate = substr($data['login_course_date'], 0, 10); |
|
2016 | - $results[$data['user_id']][$onlyDate] = true; |
|
2017 | - } |
|
2018 | - } |
|
2019 | - |
|
2020 | - return array( |
|
2021 | - 'users' => $users, |
|
2022 | - 'dateList' => $dateList, |
|
2023 | - 'headers' => $headers, |
|
2024 | - 'results' => $results |
|
2025 | - ); |
|
2026 | - } |
|
2027 | - |
|
2028 | - /** |
|
2029 | - * @param string $startDate in UTC time |
|
2030 | - * @param string $endDate in UTC time |
|
2031 | - * |
|
2032 | - * @return string |
|
2033 | - */ |
|
2034 | - public function getAttendanceLoginTable($startDate, $endDate) |
|
2035 | - { |
|
2036 | - $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2037 | - |
|
2038 | - if (!$data) { |
|
2039 | - return null; |
|
2040 | - } |
|
2041 | - |
|
2042 | - $headers = $data['headers']; |
|
2043 | - $dateList = $data['dateList']; |
|
2044 | - $users = $data['users']; |
|
2045 | - $results = $data['results']; |
|
2046 | - |
|
2047 | - $table = new HTML_Table(array('class' => 'data_table')); |
|
2048 | - $row = 0; |
|
2049 | - $column = 0; |
|
2050 | - foreach ($headers as $header) { |
|
2051 | - $table->setHeaderContents($row, $column, $header); |
|
2052 | - $column++; |
|
2053 | - } |
|
2054 | - $row = 1; |
|
2055 | - foreach ($users as $user) { |
|
2056 | - $table->setCellContents( |
|
2057 | - $row, |
|
2058 | - 0, |
|
2059 | - $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2060 | - ); |
|
2061 | - $row ++; |
|
2062 | - } |
|
2063 | - |
|
2064 | - $column = 1; |
|
2065 | - $row = 1; |
|
2066 | - foreach ($users as $user) { |
|
2067 | - foreach ($dateList as $date) { |
|
2068 | - $status = null; |
|
2069 | - if (isset($results[$user['user_id']]) && |
|
2070 | - isset($results[$user['user_id']][$date]) |
|
2071 | - ) { |
|
2072 | - $status = 'X'; |
|
2073 | - } |
|
2074 | - $table->setCellContents($row, $column, $status); |
|
2075 | - $column++; |
|
2076 | - } |
|
2077 | - $row++; |
|
2078 | - $column = 1; |
|
2079 | - } |
|
2080 | - |
|
2081 | - return $table->toHtml(); |
|
2082 | - } |
|
2083 | - |
|
2084 | - /** |
|
2085 | - * @param string $startDate in UTC time |
|
2086 | - * @param string $endDate in UTC time |
|
2087 | - * |
|
2088 | - * @return string |
|
2089 | - */ |
|
2090 | - public function exportAttendanceLogin($startDate, $endDate) |
|
2091 | - { |
|
2092 | - $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2093 | - |
|
2094 | - if (!$data) { |
|
2095 | - return null; |
|
2096 | - } |
|
2097 | - $users = $data['users']; |
|
2098 | - $results = $data['results']; |
|
2099 | - |
|
2100 | - $table = new HTML_Table(array('class' => 'data_table')); |
|
2101 | - |
|
2102 | - $table->setHeaderContents(0, 0, get_lang('User')); |
|
2103 | - $table->setHeaderContents(0, 1, get_lang('Date')); |
|
2104 | - |
|
2105 | - $row = 1; |
|
2106 | - foreach ($users as $user) { |
|
2107 | - $table->setCellContents( |
|
2108 | - $row, |
|
2109 | - 0, |
|
2110 | - $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2111 | - ); |
|
2112 | - $row++; |
|
2113 | - } |
|
2114 | - $table->setColAttributes(0, array('style' => 'width:28%')); |
|
2115 | - |
|
2116 | - $row = 1; |
|
2117 | - foreach ($users as $user) { |
|
2118 | - if (isset($results[$user['user_id']]) && |
|
2119 | - !empty($results[$user['user_id']]) |
|
2120 | - ) { |
|
2121 | - $dates = implode(', ', array_keys($results[$user['user_id']])); |
|
2122 | - $table->setCellContents($row, 1, $dates); |
|
2123 | - } |
|
2124 | - $row++; |
|
2125 | - } |
|
2126 | - |
|
2127 | - //$tableToString = null; |
|
2128 | - |
|
2129 | - //$sessionInfo = api_get_session_info(api_get_session_id()); |
|
2130 | - //if (!empty($sessionInfo)) { |
|
2131 | - /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '. |
|
1868 | + Database::query($sql); |
|
1869 | + |
|
1870 | + $this->deleteAttendanceCalendarGroup($calendar_id, $course_id); |
|
1871 | + $affected_rows++; |
|
1872 | + } |
|
1873 | + |
|
1874 | + // update users' results |
|
1875 | + $this->update_users_results($user_ids, $attendance_id); |
|
1876 | + |
|
1877 | + return $affected_rows; |
|
1878 | + } |
|
1879 | + |
|
1880 | + /** Setters for fields of attendances tables **/ |
|
1881 | + public function set_session_id($session_id) |
|
1882 | + { |
|
1883 | + $this->session_id = $session_id; |
|
1884 | + } |
|
1885 | + |
|
1886 | + public function set_course_id($course_id) |
|
1887 | + { |
|
1888 | + $this->course_id = $course_id; |
|
1889 | + } |
|
1890 | + |
|
1891 | + public function set_date_time($datetime) |
|
1892 | + { |
|
1893 | + $this->date_time = $datetime; |
|
1894 | + } |
|
1895 | + |
|
1896 | + public function set_name($name) |
|
1897 | + { |
|
1898 | + $this->name = $name; |
|
1899 | + } |
|
1900 | + |
|
1901 | + public function set_description($description) |
|
1902 | + { |
|
1903 | + $this->description = $description; |
|
1904 | + } |
|
1905 | + |
|
1906 | + public function set_attendance_qualify_title($attendance_qualify_title) |
|
1907 | + { |
|
1908 | + $this->attendance_qualify_title = $attendance_qualify_title; |
|
1909 | + } |
|
1910 | + |
|
1911 | + public function set_attendance_weight($attendance_weight) |
|
1912 | + { |
|
1913 | + $this->attendance_weight = $attendance_weight; |
|
1914 | + } |
|
1915 | + |
|
1916 | + /** Getters for fields of attendances tables **/ |
|
1917 | + public function get_session_id() |
|
1918 | + { |
|
1919 | + return $this->session_id; |
|
1920 | + } |
|
1921 | + |
|
1922 | + public function get_course_id() |
|
1923 | + { |
|
1924 | + return $this->course_id; |
|
1925 | + } |
|
1926 | + |
|
1927 | + public function get_date_time() |
|
1928 | + { |
|
1929 | + return $this->date_time; |
|
1930 | + } |
|
1931 | + |
|
1932 | + public function get_name() |
|
1933 | + { |
|
1934 | + return $this->name; |
|
1935 | + } |
|
1936 | + |
|
1937 | + public function get_description() |
|
1938 | + { |
|
1939 | + return $this->description; |
|
1940 | + } |
|
1941 | + |
|
1942 | + public function get_attendance_qualify_title() |
|
1943 | + { |
|
1944 | + return $this->attendance_qualify_title; |
|
1945 | + } |
|
1946 | + |
|
1947 | + public function get_attendance_weight() |
|
1948 | + { |
|
1949 | + return $this->attendance_weight; |
|
1950 | + } |
|
1951 | + |
|
1952 | + /** |
|
1953 | + * @param string $startDate in UTC time |
|
1954 | + * @param string $endDate in UTC time |
|
1955 | + * |
|
1956 | + * @return array |
|
1957 | + */ |
|
1958 | + public function getAttendanceLogin($startDate, $endDate) |
|
1959 | + { |
|
1960 | + if (empty($startDate) || $startDate == '0000-00-00' || |
|
1961 | + empty($endDate) || $endDate == '0000-00-00' |
|
1962 | + ) { |
|
1963 | + return false; |
|
1964 | + } |
|
1965 | + |
|
1966 | + $sessionId = api_get_session_id(); |
|
1967 | + $courseCode = api_get_course_id(); |
|
1968 | + if (!empty($sessionId)) { |
|
1969 | + $users = CourseManager:: get_user_list_from_course_code( |
|
1970 | + $courseCode, |
|
1971 | + $sessionId, |
|
1972 | + '', |
|
1973 | + 'lastname', |
|
1974 | + 0 |
|
1975 | + ); |
|
1976 | + } else { |
|
1977 | + $users = CourseManager:: get_user_list_from_course_code( |
|
1978 | + $courseCode, |
|
1979 | + 0, |
|
1980 | + '', |
|
1981 | + 'lastname', |
|
1982 | + STUDENT |
|
1983 | + ); |
|
1984 | + } |
|
1985 | + |
|
1986 | + $dateTimeStartOriginal = new DateTime($startDate); |
|
1987 | + $dateTimeStart = new DateTime($startDate); |
|
1988 | + $dateTimeEnd= new DateTime($endDate); |
|
1989 | + $interval = $dateTimeStart->diff($dateTimeEnd); |
|
1990 | + $days = intval($interval->format('%a')); |
|
1991 | + |
|
1992 | + $dateList = array($dateTimeStart->format('Y-m-d')); |
|
1993 | + $headers = array( |
|
1994 | + get_lang('User'), |
|
1995 | + $dateTimeStart->format('Y-m-d') |
|
1996 | + ); |
|
1997 | + |
|
1998 | + for ($i = 0; $i < $days; $i++) { |
|
1999 | + $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D')); |
|
2000 | + $date = $dateTimeStart->format('Y-m-d'); |
|
2001 | + $dateList[] = $date; |
|
2002 | + $headers[] = $date; |
|
2003 | + } |
|
2004 | + |
|
2005 | + $accessData = CourseManager::getCourseAccessPerCourseAndSession( |
|
2006 | + $courseCode, |
|
2007 | + $sessionId, |
|
2008 | + $dateTimeStartOriginal->format('Y-m-d H:i:s'), |
|
2009 | + $dateTimeEnd->format('Y-m-d H:i:s') |
|
2010 | + ); |
|
2011 | + |
|
2012 | + $results = array(); |
|
2013 | + if (!empty($accessData)) { |
|
2014 | + foreach ($accessData as $data) { |
|
2015 | + $onlyDate = substr($data['login_course_date'], 0, 10); |
|
2016 | + $results[$data['user_id']][$onlyDate] = true; |
|
2017 | + } |
|
2018 | + } |
|
2019 | + |
|
2020 | + return array( |
|
2021 | + 'users' => $users, |
|
2022 | + 'dateList' => $dateList, |
|
2023 | + 'headers' => $headers, |
|
2024 | + 'results' => $results |
|
2025 | + ); |
|
2026 | + } |
|
2027 | + |
|
2028 | + /** |
|
2029 | + * @param string $startDate in UTC time |
|
2030 | + * @param string $endDate in UTC time |
|
2031 | + * |
|
2032 | + * @return string |
|
2033 | + */ |
|
2034 | + public function getAttendanceLoginTable($startDate, $endDate) |
|
2035 | + { |
|
2036 | + $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2037 | + |
|
2038 | + if (!$data) { |
|
2039 | + return null; |
|
2040 | + } |
|
2041 | + |
|
2042 | + $headers = $data['headers']; |
|
2043 | + $dateList = $data['dateList']; |
|
2044 | + $users = $data['users']; |
|
2045 | + $results = $data['results']; |
|
2046 | + |
|
2047 | + $table = new HTML_Table(array('class' => 'data_table')); |
|
2048 | + $row = 0; |
|
2049 | + $column = 0; |
|
2050 | + foreach ($headers as $header) { |
|
2051 | + $table->setHeaderContents($row, $column, $header); |
|
2052 | + $column++; |
|
2053 | + } |
|
2054 | + $row = 1; |
|
2055 | + foreach ($users as $user) { |
|
2056 | + $table->setCellContents( |
|
2057 | + $row, |
|
2058 | + 0, |
|
2059 | + $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2060 | + ); |
|
2061 | + $row ++; |
|
2062 | + } |
|
2063 | + |
|
2064 | + $column = 1; |
|
2065 | + $row = 1; |
|
2066 | + foreach ($users as $user) { |
|
2067 | + foreach ($dateList as $date) { |
|
2068 | + $status = null; |
|
2069 | + if (isset($results[$user['user_id']]) && |
|
2070 | + isset($results[$user['user_id']][$date]) |
|
2071 | + ) { |
|
2072 | + $status = 'X'; |
|
2073 | + } |
|
2074 | + $table->setCellContents($row, $column, $status); |
|
2075 | + $column++; |
|
2076 | + } |
|
2077 | + $row++; |
|
2078 | + $column = 1; |
|
2079 | + } |
|
2080 | + |
|
2081 | + return $table->toHtml(); |
|
2082 | + } |
|
2083 | + |
|
2084 | + /** |
|
2085 | + * @param string $startDate in UTC time |
|
2086 | + * @param string $endDate in UTC time |
|
2087 | + * |
|
2088 | + * @return string |
|
2089 | + */ |
|
2090 | + public function exportAttendanceLogin($startDate, $endDate) |
|
2091 | + { |
|
2092 | + $data = $this->getAttendanceLogin($startDate, $endDate); |
|
2093 | + |
|
2094 | + if (!$data) { |
|
2095 | + return null; |
|
2096 | + } |
|
2097 | + $users = $data['users']; |
|
2098 | + $results = $data['results']; |
|
2099 | + |
|
2100 | + $table = new HTML_Table(array('class' => 'data_table')); |
|
2101 | + |
|
2102 | + $table->setHeaderContents(0, 0, get_lang('User')); |
|
2103 | + $table->setHeaderContents(0, 1, get_lang('Date')); |
|
2104 | + |
|
2105 | + $row = 1; |
|
2106 | + foreach ($users as $user) { |
|
2107 | + $table->setCellContents( |
|
2108 | + $row, |
|
2109 | + 0, |
|
2110 | + $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')' |
|
2111 | + ); |
|
2112 | + $row++; |
|
2113 | + } |
|
2114 | + $table->setColAttributes(0, array('style' => 'width:28%')); |
|
2115 | + |
|
2116 | + $row = 1; |
|
2117 | + foreach ($users as $user) { |
|
2118 | + if (isset($results[$user['user_id']]) && |
|
2119 | + !empty($results[$user['user_id']]) |
|
2120 | + ) { |
|
2121 | + $dates = implode(', ', array_keys($results[$user['user_id']])); |
|
2122 | + $table->setCellContents($row, 1, $dates); |
|
2123 | + } |
|
2124 | + $row++; |
|
2125 | + } |
|
2126 | + |
|
2127 | + //$tableToString = null; |
|
2128 | + |
|
2129 | + //$sessionInfo = api_get_session_info(api_get_session_id()); |
|
2130 | + //if (!empty($sessionInfo)) { |
|
2131 | + /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '. |
|
2132 | 2132 | sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);*/ |
2133 | - //} |
|
2134 | - |
|
2135 | - $tableToString = $table->toHtml(); |
|
2136 | - |
|
2137 | - $params = array( |
|
2138 | - 'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(), |
|
2139 | - 'pdf_title' => get_lang('Attendance'), |
|
2140 | - 'course_code' => api_get_course_id(), |
|
2141 | - 'show_real_course_teachers' => true |
|
2142 | - ); |
|
2143 | - $pdf = new PDF('A4', null, $params); |
|
2144 | - $pdf->html_to_pdf_with_template($tableToString); |
|
2145 | - } |
|
2133 | + //} |
|
2134 | + |
|
2135 | + $tableToString = $table->toHtml(); |
|
2136 | + |
|
2137 | + $params = array( |
|
2138 | + 'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(), |
|
2139 | + 'pdf_title' => get_lang('Attendance'), |
|
2140 | + 'course_code' => api_get_course_id(), |
|
2141 | + 'show_real_course_teachers' => true |
|
2142 | + ); |
|
2143 | + $pdf = new PDF('A4', null, $params); |
|
2144 | + $pdf->html_to_pdf_with_template($tableToString); |
|
2145 | + } |
|
2146 | 2146 | } |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | if (!defined('MAGPIE_DIR')) { |
29 | - define('MAGPIE_DIR', dirname(__FILE__) . DIR_SEP); |
|
29 | + define('MAGPIE_DIR', dirname(__FILE__).DIR_SEP); |
|
30 | 30 | } |
31 | 31 | |
32 | -require_once( MAGPIE_DIR . 'rss_parse.inc' ); |
|
33 | -require_once( MAGPIE_DIR . 'rss_cache.inc' ); |
|
32 | +require_once(MAGPIE_DIR.'rss_parse.inc'); |
|
33 | +require_once(MAGPIE_DIR.'rss_cache.inc'); |
|
34 | 34 | |
35 | 35 | // for including 3rd party libraries |
36 | -define('MAGPIE_EXTLIB', MAGPIE_DIR . 'extlib' . DIR_SEP); |
|
37 | -require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc'); |
|
36 | +define('MAGPIE_EXTLIB', MAGPIE_DIR.'extlib'.DIR_SEP); |
|
37 | +require_once(MAGPIE_EXTLIB.'Snoopy.class.inc'); |
|
38 | 38 | define('MAGPIE_CACHE_DIR', api_get_path(SYS_ARCHIVE_PATH)); |
39 | 39 | |
40 | 40 | /* |
@@ -87,21 +87,21 @@ discard block |
||
87 | 87 | |
88 | 88 | $MAGPIE_ERROR = ""; |
89 | 89 | |
90 | -function fetch_rss ($url) { |
|
90 | +function fetch_rss($url) { |
|
91 | 91 | // initialize constants |
92 | 92 | init(); |
93 | 93 | |
94 | - if ( !isset($url) ) { |
|
94 | + if (!isset($url)) { |
|
95 | 95 | error("fetch_rss called without a url"); |
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // if cache is disabled |
100 | - if ( !MAGPIE_CACHE_ON ) { |
|
100 | + if (!MAGPIE_CACHE_ON) { |
|
101 | 101 | // fetch file, and parse it |
102 | - $resp = _fetch_remote_file( $url ); |
|
103 | - if ( is_success( $resp->status ) ) { |
|
104 | - return _response_to_rss( $resp ); |
|
102 | + $resp = _fetch_remote_file($url); |
|
103 | + if (is_success($resp->status)) { |
|
104 | + return _response_to_rss($resp); |
|
105 | 105 | } |
106 | 106 | else { |
107 | 107 | error("Failed to fetch $url and cache is off"); |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | // 3. if cached obj fails freshness check, fetch remote |
117 | 117 | // 4. if remote fails, return stale object, or error |
118 | 118 | |
119 | - $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); |
|
119 | + $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE); |
|
120 | 120 | |
121 | 121 | if (MAGPIE_DEBUG and $cache->ERROR) { |
122 | 122 | debug($cache->ERROR, E_USER_WARNING); |
123 | 123 | } |
124 | 124 | |
125 | 125 | |
126 | - $cache_status = 0; // response of check_cache |
|
126 | + $cache_status = 0; // response of check_cache |
|
127 | 127 | $request_headers = array(); // HTTP headers to send with fetch |
128 | - $rss = 0; // parsed RSS object |
|
129 | - $errormsg = 0; // errors, if any |
|
128 | + $rss = 0; // parsed RSS object |
|
129 | + $errormsg = 0; // errors, if any |
|
130 | 130 | |
131 | 131 | // store parsed XML by desired output encoding |
132 | 132 | // as character munging happens at parse time |
133 | - $cache_key = $url . MAGPIE_OUTPUT_ENCODING; |
|
133 | + $cache_key = $url.MAGPIE_OUTPUT_ENCODING; |
|
134 | 134 | |
135 | 135 | if (!$cache->ERROR) { |
136 | 136 | // return cache HIT, MISS, or STALE |
137 | - $cache_status = $cache->check_cache( $cache_key); |
|
137 | + $cache_status = $cache->check_cache($cache_key); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // if object cached, and cache is fresh, return cached obj |
141 | - if ( $cache_status == 'HIT' ) { |
|
142 | - $rss = $cache->get( $cache_key ); |
|
143 | - if ( isset($rss) and $rss ) { |
|
141 | + if ($cache_status == 'HIT') { |
|
142 | + $rss = $cache->get($cache_key); |
|
143 | + if (isset($rss) and $rss) { |
|
144 | 144 | // should be cache age |
145 | 145 | $rss->from_cache = 1; |
146 | - if ( MAGPIE_DEBUG > 1) { |
|
146 | + if (MAGPIE_DEBUG > 1) { |
|
147 | 147 | debug("MagpieRSS: Cache HIT", E_USER_NOTICE); |
148 | 148 | } |
149 | 149 | return $rss; |
@@ -153,50 +153,50 @@ discard block |
||
153 | 153 | // else attempt a conditional get |
154 | 154 | |
155 | 155 | // setup headers |
156 | - if ( $cache_status == 'STALE' ) { |
|
157 | - $rss = $cache->get( $cache_key ); |
|
158 | - if ( $rss and $rss->etag and $rss->last_modified ) { |
|
156 | + if ($cache_status == 'STALE') { |
|
157 | + $rss = $cache->get($cache_key); |
|
158 | + if ($rss and $rss->etag and $rss->last_modified) { |
|
159 | 159 | $request_headers['If-None-Match'] = $rss->etag; |
160 | 160 | $request_headers['If-Last-Modified'] = $rss->last_modified; |
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - $resp = _fetch_remote_file( $url, $request_headers ); |
|
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 | - if ( MAGPIE_DEBUG > 1) { |
|
169 | + if (MAGPIE_DEBUG > 1) { |
|
170 | 170 | debug("Got 304 for $url"); |
171 | 171 | } |
172 | 172 | // reset cache on 304 (at minutillo insistent prodding) |
173 | 173 | $cache->set($cache_key, $rss); |
174 | 174 | return $rss; |
175 | 175 | } |
176 | - elseif ( is_success( $resp->status ) ) { |
|
177 | - $rss = _response_to_rss( $resp ); |
|
178 | - if ( $rss ) { |
|
176 | + elseif (is_success($resp->status)) { |
|
177 | + $rss = _response_to_rss($resp); |
|
178 | + if ($rss) { |
|
179 | 179 | if (MAGPIE_DEBUG > 1) { |
180 | 180 | debug("Fetch successful"); |
181 | 181 | } |
182 | 182 | // add object to cache |
183 | - $cache->set( $cache_key, $rss ); |
|
183 | + $cache->set($cache_key, $rss); |
|
184 | 184 | return $rss; |
185 | 185 | } |
186 | 186 | } |
187 | 187 | else { |
188 | 188 | $errormsg = "Failed to fetch $url "; |
189 | - if ( $resp->status == '-100' ) { |
|
190 | - $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; |
|
189 | + if ($resp->status == '-100') { |
|
190 | + $errormsg .= "(Request timed out after ".MAGPIE_FETCH_TIME_OUT." seconds)"; |
|
191 | 191 | } |
192 | - elseif ( $resp->error ) { |
|
192 | + elseif ($resp->error) { |
|
193 | 193 | # compensate for Snoopy's annoying habbit to tacking |
194 | 194 | # on '\n' |
195 | 195 | $http_error = substr($resp->error, 0, -2); |
196 | 196 | $errormsg .= "(HTTP Error: $http_error)"; |
197 | 197 | } |
198 | 198 | else { |
199 | - $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
|
199 | + $errormsg .= "(HTTP Response: ".$resp->response_code.')'; |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | |
209 | 209 | // attempt to return cached object |
210 | 210 | if ($rss) { |
211 | - if ( MAGPIE_DEBUG ) { |
|
211 | + if (MAGPIE_DEBUG) { |
|
212 | 212 | debug("Returning STALE object for $url"); |
213 | 213 | } |
214 | 214 | return $rss; |
@@ -228,21 +228,21 @@ discard block |
||
228 | 228 | Purpose: set MAGPIE_ERROR, and trigger error |
229 | 229 | \*=======================================================================*/ |
230 | 230 | |
231 | -function error ($errormsg, $lvl=E_USER_WARNING) { |
|
231 | +function error($errormsg, $lvl = E_USER_WARNING) { |
|
232 | 232 | global $MAGPIE_ERROR; |
233 | 233 | |
234 | 234 | // append PHP's error message if track_errors enabled |
235 | - if ( isset($php_errormsg) ) { |
|
235 | + if (isset($php_errormsg)) { |
|
236 | 236 | $errormsg .= " ($php_errormsg)"; |
237 | 237 | } |
238 | - if ( $errormsg ) { |
|
238 | + if ($errormsg) { |
|
239 | 239 | $errormsg = "MagpieRSS: $errormsg"; |
240 | 240 | $MAGPIE_ERROR = $errormsg; |
241 | - trigger_error( $errormsg, $lvl); |
|
241 | + trigger_error($errormsg, $lvl); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | -function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
245 | +function debug($debugmsg, $lvl = E_USER_NOTICE) { |
|
246 | 246 | trigger_error("MagpieRSS [debug] $debugmsg", $lvl); |
247 | 247 | } |
248 | 248 | |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | Function: magpie_error |
251 | 251 | Purpose: accessor for the magpie error variable |
252 | 252 | \*=======================================================================*/ |
253 | -function magpie_error ($errormsg="") { |
|
253 | +function magpie_error($errormsg = "") { |
|
254 | 254 | global $MAGPIE_ERROR; |
255 | 255 | |
256 | - if ( isset($errormsg) and $errormsg ) { |
|
256 | + if (isset($errormsg) and $errormsg) { |
|
257 | 257 | $MAGPIE_ERROR = $errormsg; |
258 | 258 | } |
259 | 259 | |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | headers to send along with the request (optional) |
268 | 268 | Output: an HTTP response object (see Snoopy.class.inc) |
269 | 269 | \*=======================================================================*/ |
270 | -function _fetch_remote_file ($url, $headers = "" ) { |
|
270 | +function _fetch_remote_file($url, $headers = "") { |
|
271 | 271 | // Snoopy is an HTTP client in PHP |
272 | 272 | $client = new Snoopy(); |
273 | 273 | $client->agent = MAGPIE_USER_AGENT; |
274 | 274 | $client->read_timeout = MAGPIE_FETCH_TIME_OUT; |
275 | 275 | $client->use_gzip = MAGPIE_USE_GZIP; |
276 | - if (is_array($headers) ) { |
|
276 | + if (is_array($headers)) { |
|
277 | 277 | $client->rawheaders = $headers; |
278 | 278 | } |
279 | 279 | |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | Input: an HTTP response object (see Snoopy) |
289 | 289 | Output: parsed RSS object (see rss_parse) |
290 | 290 | \*=======================================================================*/ |
291 | -function _response_to_rss ($resp) { |
|
292 | - $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); |
|
291 | +function _response_to_rss($resp) { |
|
292 | + $rss = new MagpieRSS($resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING); |
|
293 | 293 | |
294 | 294 | // if RSS parsed successfully |
295 | - if ( $rss and !$rss->ERROR) { |
|
295 | + if ($rss and !$rss->ERROR) { |
|
296 | 296 | |
297 | 297 | // find Etag, and Last-Modified |
298 | - foreach($resp->headers as $h) { |
|
298 | + foreach ($resp->headers as $h) { |
|
299 | 299 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
300 | 300 | if (strpos($h, ": ")) { |
301 | 301 | list($field, $val) = explode(": ", $h, 2); |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | $val = ""; |
306 | 306 | } |
307 | 307 | |
308 | - if ( $field == 'ETag' ) { |
|
308 | + if ($field == 'ETag') { |
|
309 | 309 | $rss->etag = $val; |
310 | 310 | } |
311 | 311 | |
312 | - if ( $field == 'Last-Modified' ) { |
|
312 | + if ($field == 'Last-Modified') { |
|
313 | 313 | $rss->last_modified = $val; |
314 | 314 | } |
315 | 315 | } |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | $errormsg = "Failed to parse RSS file."; |
321 | 321 | |
322 | 322 | if ($rss) { |
323 | - $errormsg .= " (" . $rss->ERROR . ")"; |
|
323 | + $errormsg .= " (".$rss->ERROR.")"; |
|
324 | 324 | } |
325 | - error($errormsg,E_USER_NOTICE); |
|
325 | + error($errormsg, E_USER_NOTICE); |
|
326 | 326 | |
327 | 327 | return false; |
328 | 328 | } // end if ($rss and !$rss->error) |
@@ -333,65 +333,65 @@ discard block |
||
333 | 333 | Purpose: setup constants with default values |
334 | 334 | check for user overrides |
335 | 335 | \*=======================================================================*/ |
336 | -function init () { |
|
337 | - if ( defined('MAGPIE_INITALIZED') ) { |
|
336 | +function init() { |
|
337 | + if (defined('MAGPIE_INITALIZED')) { |
|
338 | 338 | return; |
339 | 339 | } |
340 | 340 | else { |
341 | 341 | define('MAGPIE_INITALIZED', true); |
342 | 342 | } |
343 | 343 | |
344 | - if ( !defined('MAGPIE_CACHE_ON') ) { |
|
344 | + if (!defined('MAGPIE_CACHE_ON')) { |
|
345 | 345 | define('MAGPIE_CACHE_ON', true); |
346 | 346 | } |
347 | 347 | |
348 | - if ( !defined('MAGPIE_CACHE_DIR') ) { |
|
348 | + if (!defined('MAGPIE_CACHE_DIR')) { |
|
349 | 349 | define('MAGPIE_CACHE_DIR', './cache'); |
350 | 350 | } |
351 | 351 | |
352 | - if ( !defined('MAGPIE_CACHE_AGE') ) { |
|
353 | - define('MAGPIE_CACHE_AGE', 60*60); // one hour |
|
352 | + if (!defined('MAGPIE_CACHE_AGE')) { |
|
353 | + define('MAGPIE_CACHE_AGE', 60 * 60); // one hour |
|
354 | 354 | } |
355 | 355 | |
356 | - if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) { |
|
356 | + if (!defined('MAGPIE_CACHE_FRESH_ONLY')) { |
|
357 | 357 | define('MAGPIE_CACHE_FRESH_ONLY', false); |
358 | 358 | } |
359 | 359 | |
360 | - if ( !defined('MAGPIE_OUTPUT_ENCODING') ) { |
|
360 | + if (!defined('MAGPIE_OUTPUT_ENCODING')) { |
|
361 | 361 | define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); |
362 | 362 | } |
363 | 363 | |
364 | - if ( !defined('MAGPIE_INPUT_ENCODING') ) { |
|
364 | + if (!defined('MAGPIE_INPUT_ENCODING')) { |
|
365 | 365 | define('MAGPIE_INPUT_ENCODING', null); |
366 | 366 | } |
367 | 367 | |
368 | - if ( !defined('MAGPIE_DETECT_ENCODING') ) { |
|
368 | + if (!defined('MAGPIE_DETECT_ENCODING')) { |
|
369 | 369 | define('MAGPIE_DETECT_ENCODING', true); |
370 | 370 | } |
371 | 371 | |
372 | - if ( !defined('MAGPIE_DEBUG') ) { |
|
372 | + if (!defined('MAGPIE_DEBUG')) { |
|
373 | 373 | define('MAGPIE_DEBUG', 0); |
374 | 374 | } |
375 | 375 | |
376 | - if ( !defined('MAGPIE_USER_AGENT') ) { |
|
377 | - $ua = 'MagpieRSS/'. MAGPIE_VERSION . ' (+http://magpierss.sf.net'; |
|
376 | + if (!defined('MAGPIE_USER_AGENT')) { |
|
377 | + $ua = 'MagpieRSS/'.MAGPIE_VERSION.' (+http://magpierss.sf.net'; |
|
378 | 378 | |
379 | - if ( MAGPIE_CACHE_ON ) { |
|
380 | - $ua = $ua . ')'; |
|
379 | + if (MAGPIE_CACHE_ON) { |
|
380 | + $ua = $ua.')'; |
|
381 | 381 | } |
382 | 382 | else { |
383 | - $ua = $ua . '; No cache)'; |
|
383 | + $ua = $ua.'; No cache)'; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | define('MAGPIE_USER_AGENT', $ua); |
387 | 387 | } |
388 | 388 | |
389 | - if ( !defined('MAGPIE_FETCH_TIME_OUT') ) { |
|
389 | + if (!defined('MAGPIE_FETCH_TIME_OUT')) { |
|
390 | 390 | define('MAGPIE_FETCH_TIME_OUT', 5); // 5 second timeout |
391 | 391 | } |
392 | 392 | |
393 | 393 | // use gzip encoding to fetch rss files if supported? |
394 | - if ( !defined('MAGPIE_USE_GZIP') ) { |
|
394 | + if (!defined('MAGPIE_USE_GZIP')) { |
|
395 | 395 | define('MAGPIE_USE_GZIP', true); |
396 | 396 | } |
397 | 397 | } |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | Function: is_info |
415 | 415 | Purpose: return true if Informational status code |
416 | 416 | \*=======================================================================*/ |
417 | -function is_info ($sc) { |
|
417 | +function is_info($sc) { |
|
418 | 418 | return $sc >= 100 && $sc < 200; |
419 | 419 | } |
420 | 420 | |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | Function: is_success |
423 | 423 | Purpose: return true if Successful status code |
424 | 424 | \*=======================================================================*/ |
425 | -function is_success ($sc) { |
|
425 | +function is_success($sc) { |
|
426 | 426 | return $sc >= 200 && $sc < 300; |
427 | 427 | } |
428 | 428 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | Function: is_redirect |
431 | 431 | Purpose: return true if Redirection status code |
432 | 432 | \*=======================================================================*/ |
433 | -function is_redirect ($sc) { |
|
433 | +function is_redirect($sc) { |
|
434 | 434 | return $sc >= 300 && $sc < 400; |
435 | 435 | } |
436 | 436 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | Function: is_error |
439 | 439 | Purpose: return true if Error status code |
440 | 440 | \*=======================================================================*/ |
441 | -function is_error ($sc) { |
|
441 | +function is_error($sc) { |
|
442 | 442 | return $sc >= 400 && $sc < 600; |
443 | 443 | } |
444 | 444 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | Function: is_client_error |
447 | 447 | Purpose: return true if Error status code, and its a client error |
448 | 448 | \*=======================================================================*/ |
449 | -function is_client_error ($sc) { |
|
449 | +function is_client_error($sc) { |
|
450 | 450 | return $sc >= 400 && $sc < 500; |
451 | 451 | } |
452 | 452 | |
@@ -454,6 +454,6 @@ discard block |
||
454 | 454 | Function: is_client_error |
455 | 455 | Purpose: return true if Error status code, and its a server error |
456 | 456 | \*=======================================================================*/ |
457 | -function is_server_error ($sc) { |
|
457 | +function is_server_error($sc) { |
|
458 | 458 | return $sc >= 500 && $sc < 600; |
459 | 459 | } |
@@ -102,8 +102,7 @@ discard block |
||
102 | 102 | $resp = _fetch_remote_file( $url ); |
103 | 103 | if ( is_success( $resp->status ) ) { |
104 | 104 | return _response_to_rss( $resp ); |
105 | - } |
|
106 | - else { |
|
105 | + } else { |
|
107 | 106 | error("Failed to fetch $url and cache is off"); |
108 | 107 | return false; |
109 | 108 | } |
@@ -172,8 +171,7 @@ discard block |
||
172 | 171 | // reset cache on 304 (at minutillo insistent prodding) |
173 | 172 | $cache->set($cache_key, $rss); |
174 | 173 | return $rss; |
175 | - } |
|
176 | - elseif ( is_success( $resp->status ) ) { |
|
174 | + } elseif ( is_success( $resp->status ) ) { |
|
177 | 175 | $rss = _response_to_rss( $resp ); |
178 | 176 | if ( $rss ) { |
179 | 177 | if (MAGPIE_DEBUG > 1) { |
@@ -183,24 +181,20 @@ discard block |
||
183 | 181 | $cache->set( $cache_key, $rss ); |
184 | 182 | return $rss; |
185 | 183 | } |
186 | - } |
|
187 | - else { |
|
184 | + } else { |
|
188 | 185 | $errormsg = "Failed to fetch $url "; |
189 | 186 | if ( $resp->status == '-100' ) { |
190 | 187 | $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; |
191 | - } |
|
192 | - elseif ( $resp->error ) { |
|
188 | + } elseif ( $resp->error ) { |
|
193 | 189 | # compensate for Snoopy's annoying habbit to tacking |
194 | 190 | # on '\n' |
195 | 191 | $http_error = substr($resp->error, 0, -2); |
196 | 192 | $errormsg .= "(HTTP Error: $http_error)"; |
197 | - } |
|
198 | - else { |
|
193 | + } else { |
|
199 | 194 | $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
200 | 195 | } |
201 | 196 | } |
202 | - } |
|
203 | - else { |
|
197 | + } else { |
|
204 | 198 | $errormsg = "Unable to retrieve RSS file for unknown reasons."; |
205 | 199 | } |
206 | 200 | |
@@ -299,8 +293,7 @@ discard block |
||
299 | 293 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
300 | 294 | if (strpos($h, ": ")) { |
301 | 295 | list($field, $val) = explode(": ", $h, 2); |
302 | - } |
|
303 | - else { |
|
296 | + } else { |
|
304 | 297 | $field = $h; |
305 | 298 | $val = ""; |
306 | 299 | } |
@@ -336,8 +329,7 @@ discard block |
||
336 | 329 | function init () { |
337 | 330 | if ( defined('MAGPIE_INITALIZED') ) { |
338 | 331 | return; |
339 | - } |
|
340 | - else { |
|
332 | + } else { |
|
341 | 333 | define('MAGPIE_INITALIZED', true); |
342 | 334 | } |
343 | 335 | |
@@ -378,8 +370,7 @@ discard block |
||
378 | 370 | |
379 | 371 | if ( MAGPIE_CACHE_ON ) { |
380 | 372 | $ua = $ua . ')'; |
381 | - } |
|
382 | - else { |
|
373 | + } else { |
|
383 | 374 | $ua = $ua . '; No cache)'; |
384 | 375 | } |
385 | 376 |
@@ -164,7 +164,7 @@ |
||
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"); |
@@ -228,6 +228,9 @@ discard block |
||
228 | 228 | Purpose: set MAGPIE_ERROR, and trigger error |
229 | 229 | \*=======================================================================*/ |
230 | 230 | |
231 | +/** |
|
232 | + * @param integer $lvl |
|
233 | + */ |
|
231 | 234 | function error ($errormsg, $lvl=E_USER_WARNING) { |
232 | 235 | global $MAGPIE_ERROR; |
233 | 236 | |
@@ -242,6 +245,9 @@ discard block |
||
242 | 245 | } |
243 | 246 | } |
244 | 247 | |
248 | +/** |
|
249 | + * @param integer $lvl |
|
250 | + */ |
|
245 | 251 | function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
246 | 252 | trigger_error("MagpieRSS [debug] $debugmsg", $lvl); |
247 | 253 | } |
@@ -288,6 +294,9 @@ discard block |
||
288 | 294 | Input: an HTTP response object (see Snoopy) |
289 | 295 | Output: parsed RSS object (see rss_parse) |
290 | 296 | \*=======================================================================*/ |
297 | +/** |
|
298 | + * @param Snoopy $resp |
|
299 | + */ |
|
291 | 300 | function _response_to_rss ($resp) { |
292 | 301 | $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); |
293 | 302 |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | * @package chamilo.include.rss |
20 | 20 | */ |
21 | 21 | class RSSCache { |
22 | - public $BASE_CACHE = './cache'; // where the cache files are stored |
|
23 | - public $MAX_AGE = 3600; // when are files stale, default one hour |
|
24 | - public $ERROR = ""; // accumulate error messages |
|
22 | + public $BASE_CACHE = './cache'; // where the cache files are stored |
|
23 | + public $MAX_AGE = 3600; // when are files stale, default one hour |
|
24 | + public $ERROR = ""; // accumulate error messages |
|
25 | 25 | |
26 | - public function RSSCache ($base='', $age='') { |
|
27 | - if ( $base ) { |
|
26 | + public function RSSCache($base = '', $age = '') { |
|
27 | + if ($base) { |
|
28 | 28 | $this->BASE_CACHE = $base; |
29 | 29 | } |
30 | - if ( $age ) { |
|
30 | + if ($age) { |
|
31 | 31 | $this->MAX_AGE = $age; |
32 | 32 | } |
33 | 33 | |
34 | 34 | // attempt to make the cache directory |
35 | - if ( ! file_exists( $this->BASE_CACHE ) ) { |
|
36 | - $status = @mkdir( $this->BASE_CACHE, 0755 ); |
|
35 | + if (!file_exists($this->BASE_CACHE)) { |
|
36 | + $status = @mkdir($this->BASE_CACHE, 0755); |
|
37 | 37 | |
38 | 38 | // if make failed |
39 | - if ( ! $status ) { |
|
39 | + if (!$status) { |
|
40 | 40 | $this->error( |
41 | - "Cache couldn't make dir '" . $this->BASE_CACHE . "'." |
|
41 | + "Cache couldn't make dir '".$this->BASE_CACHE."'." |
|
42 | 42 | ); |
43 | 43 | } |
44 | 44 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | Input: url from wich the rss file was fetched |
51 | 51 | Output: true on sucess |
52 | 52 | \*=======================================================================*/ |
53 | - public function set ($url, $rss) { |
|
53 | + public function set($url, $rss) { |
|
54 | 54 | $this->ERROR = ""; |
55 | - $cache_file = $this->file_name( $url ); |
|
56 | - $fp = @fopen( $cache_file, 'w' ); |
|
55 | + $cache_file = $this->file_name($url); |
|
56 | + $fp = @fopen($cache_file, 'w'); |
|
57 | 57 | |
58 | - if ( ! $fp ) { |
|
58 | + if (!$fp) { |
|
59 | 59 | $this->error( |
60 | 60 | "Cache unable to open file for writing: $cache_file" |
61 | 61 | ); |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | |
66 | - $data = $this->serialize( $rss ); |
|
67 | - fwrite( $fp, $data ); |
|
68 | - fclose( $fp ); |
|
66 | + $data = $this->serialize($rss); |
|
67 | + fwrite($fp, $data); |
|
68 | + fclose($fp); |
|
69 | 69 | |
70 | 70 | return $cache_file; |
71 | 71 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | Input: url from wich the rss file was fetched |
77 | 77 | Output: cached object on HIT, false on MISS |
78 | 78 | \*=======================================================================*/ |
79 | - public function get ($url) { |
|
79 | + public function get($url) { |
|
80 | 80 | $this->ERROR = ""; |
81 | - $cache_file = $this->file_name( $url ); |
|
81 | + $cache_file = $this->file_name($url); |
|
82 | 82 | |
83 | - if ( ! file_exists( $cache_file ) ) { |
|
83 | + if (!file_exists($cache_file)) { |
|
84 | 84 | $this->debug( |
85 | 85 | "Cache doesn't contain: $url (cache file: $cache_file)" |
86 | 86 | ); |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | $fp = @fopen($cache_file, 'r'); |
91 | - if ( ! $fp ) { |
|
91 | + if (!$fp) { |
|
92 | 92 | $this->error( |
93 | 93 | "Failed to open cache file for reading: $cache_file" |
94 | 94 | ); |
95 | 95 | return 0; |
96 | 96 | } |
97 | 97 | |
98 | - if ($filesize = filesize($cache_file) ) { |
|
99 | - $data = fread( $fp, filesize($cache_file) ); |
|
100 | - $rss = $this->unserialize( $data ); |
|
98 | + if ($filesize = filesize($cache_file)) { |
|
99 | + $data = fread($fp, filesize($cache_file)); |
|
100 | + $rss = $this->unserialize($data); |
|
101 | 101 | |
102 | 102 | return $rss; |
103 | 103 | } |
@@ -112,16 +112,16 @@ discard block |
||
112 | 112 | Input: url from wich the rss file was fetched |
113 | 113 | Output: cached object on HIT, false on MISS |
114 | 114 | \*=======================================================================*/ |
115 | - public function check_cache ( $url ) { |
|
115 | + public function check_cache($url) { |
|
116 | 116 | $this->ERROR = ""; |
117 | - $filename = $this->file_name( $url ); |
|
117 | + $filename = $this->file_name($url); |
|
118 | 118 | |
119 | - if ( file_exists( $filename ) ) { |
|
119 | + if (file_exists($filename)) { |
|
120 | 120 | // find how long ago the file was added to the cache |
121 | 121 | // and whether that is longer then MAX_AGE |
122 | - $mtime = filemtime( $filename ); |
|
122 | + $mtime = filemtime($filename); |
|
123 | 123 | $age = time() - $mtime; |
124 | - if ( $this->MAX_AGE > $age ) { |
|
124 | + if ($this->MAX_AGE > $age) { |
|
125 | 125 | // object exists and is current |
126 | 126 | return 'HIT'; |
127 | 127 | } |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - public function cache_age( $url ) { |
|
140 | - $filename = $this->file_name( $url); |
|
141 | - if ( file_exists( $filename ) ) { |
|
142 | - $mtime = filemtime( $filename ); |
|
139 | + public function cache_age($url) { |
|
140 | + $filename = $this->file_name($url); |
|
141 | + if (file_exists($filename)) { |
|
142 | + $mtime = filemtime($filename); |
|
143 | 143 | $age = time() - $mtime; |
144 | 144 | return $age; |
145 | 145 | } |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | /*=======================================================================*\ |
152 | 152 | Function: serialize |
153 | 153 | \*=======================================================================*/ |
154 | - public function serialize ( $rss ) { |
|
155 | - return serialize( $rss ); |
|
154 | + public function serialize($rss) { |
|
155 | + return serialize($rss); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /*=======================================================================*\ |
159 | 159 | Function: unserialize |
160 | 160 | \*=======================================================================*/ |
161 | - public function unserialize ( $data ) { |
|
162 | - return unserialize( $data ); |
|
161 | + public function unserialize($data) { |
|
162 | + return unserialize($data); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /*=======================================================================*\ |
@@ -168,31 +168,31 @@ discard block |
||
168 | 168 | Input: url from wich the rss file was fetched |
169 | 169 | Output: a file name |
170 | 170 | \*=======================================================================*/ |
171 | - public function file_name ($url) { |
|
172 | - $filename = md5( $url ); |
|
173 | - return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); |
|
171 | + public function file_name($url) { |
|
172 | + $filename = md5($url); |
|
173 | + return join(DIRECTORY_SEPARATOR, array($this->BASE_CACHE, $filename)); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /*=======================================================================*\ |
177 | 177 | Function: error |
178 | 178 | Purpose: register error |
179 | 179 | \*=======================================================================*/ |
180 | - public function error ($errormsg, $lvl=E_USER_WARNING) { |
|
180 | + public function error($errormsg, $lvl = E_USER_WARNING) { |
|
181 | 181 | // append PHP's error message if track_errors enabled |
182 | - if ( isset($php_errormsg) ) { |
|
182 | + if (isset($php_errormsg)) { |
|
183 | 183 | $errormsg .= " ($php_errormsg)"; |
184 | 184 | } |
185 | 185 | $this->ERROR = $errormsg; |
186 | - if ( MAGPIE_DEBUG ) { |
|
187 | - trigger_error( $errormsg, $lvl); |
|
186 | + if (MAGPIE_DEBUG) { |
|
187 | + trigger_error($errormsg, $lvl); |
|
188 | 188 | } |
189 | 189 | else { |
190 | - error_log( $errormsg, 0); |
|
190 | + error_log($errormsg, 0); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - public function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
195 | - if ( MAGPIE_DEBUG ) { |
|
194 | + public function debug($debugmsg, $lvl = E_USER_NOTICE) { |
|
195 | + if (MAGPIE_DEBUG) { |
|
196 | 196 | $this->error("MagpieRSS [debug] $debugmsg", $lvl); |
197 | 197 | } |
198 | 198 | } |
@@ -124,13 +124,11 @@ discard block |
||
124 | 124 | if ( $this->MAX_AGE > $age ) { |
125 | 125 | // object exists and is current |
126 | 126 | return 'HIT'; |
127 | - } |
|
128 | - else { |
|
127 | + } else { |
|
129 | 128 | // object exists but is old |
130 | 129 | return 'STALE'; |
131 | 130 | } |
132 | - } |
|
133 | - else { |
|
131 | + } else { |
|
134 | 132 | // object does not exist |
135 | 133 | return 'MISS'; |
136 | 134 | } |
@@ -142,8 +140,7 @@ discard block |
||
142 | 140 | $mtime = filemtime( $filename ); |
143 | 141 | $age = time() - $mtime; |
144 | 142 | return $age; |
145 | - } |
|
146 | - else { |
|
143 | + } else { |
|
147 | 144 | return -1; |
148 | 145 | } |
149 | 146 | } |
@@ -185,8 +182,7 @@ discard block |
||
185 | 182 | $this->ERROR = $errormsg; |
186 | 183 | if ( MAGPIE_DEBUG ) { |
187 | 184 | trigger_error( $errormsg, $lvl); |
188 | - } |
|
189 | - else { |
|
185 | + } else { |
|
190 | 186 | error_log( $errormsg, 0); |
191 | 187 | } |
192 | 188 | } |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | if ($filesize = filesize($cache_file) ) { |
99 | - $data = fread( $fp, filesize($cache_file) ); |
|
100 | - $rss = $this->unserialize( $data ); |
|
99 | + $data = fread( $fp, filesize($cache_file) ); |
|
100 | + $rss = $this->unserialize( $data ); |
|
101 | 101 | |
102 | - return $rss; |
|
103 | - } |
|
102 | + return $rss; |
|
103 | + } |
|
104 | 104 | |
105 | - return 0; |
|
105 | + return 0; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /*=======================================================================*\ |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - public function cache_age( $url ) { |
|
140 | - $filename = $this->file_name( $url); |
|
141 | - if ( file_exists( $filename ) ) { |
|
142 | - $mtime = filemtime( $filename ); |
|
139 | + public function cache_age( $url ) { |
|
140 | + $filename = $this->file_name( $url); |
|
141 | + if ( file_exists( $filename ) ) { |
|
142 | + $mtime = filemtime( $filename ); |
|
143 | 143 | $age = time() - $mtime; |
144 | - return $age; |
|
145 | - } |
|
146 | - else { |
|
147 | - return -1; |
|
148 | - } |
|
149 | - } |
|
144 | + return $age; |
|
145 | + } |
|
146 | + else { |
|
147 | + return -1; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /*=======================================================================*\ |
152 | 152 | Function: serialize |
@@ -50,6 +50,9 @@ discard block |
||
50 | 50 | Input: url from wich the rss file was fetched |
51 | 51 | Output: true on sucess |
52 | 52 | \*=======================================================================*/ |
53 | + /** |
|
54 | + * @param string $url |
|
55 | + */ |
|
53 | 56 | public function set ($url, $rss) { |
54 | 57 | $this->ERROR = ""; |
55 | 58 | $cache_file = $this->file_name( $url ); |
@@ -76,6 +79,9 @@ discard block |
||
76 | 79 | Input: url from wich the rss file was fetched |
77 | 80 | Output: cached object on HIT, false on MISS |
78 | 81 | \*=======================================================================*/ |
82 | + /** |
|
83 | + * @param string $url |
|
84 | + */ |
|
79 | 85 | public function get ($url) { |
80 | 86 | $this->ERROR = ""; |
81 | 87 | $cache_file = $this->file_name( $url ); |
@@ -112,6 +118,9 @@ discard block |
||
112 | 118 | Input: url from wich the rss file was fetched |
113 | 119 | Output: cached object on HIT, false on MISS |
114 | 120 | \*=======================================================================*/ |
121 | + /** |
|
122 | + * @param string $url |
|
123 | + */ |
|
115 | 124 | public function check_cache ( $url ) { |
116 | 125 | $this->ERROR = ""; |
117 | 126 | $filename = $this->file_name( $url ); |
@@ -158,6 +167,9 @@ discard block |
||
158 | 167 | /*=======================================================================*\ |
159 | 168 | Function: unserialize |
160 | 169 | \*=======================================================================*/ |
170 | + /** |
|
171 | + * @param string $data |
|
172 | + */ |
|
161 | 173 | public function unserialize ( $data ) { |
162 | 174 | return unserialize( $data ); |
163 | 175 | } |
@@ -22,35 +22,35 @@ |
||
22 | 22 | * |
23 | 23 | * NOTE: http://www.w3.org/TR/NOTE-datetime |
24 | 24 | */ |
25 | -function parse_w3cdtf ( $date_str ) { |
|
25 | +function parse_w3cdtf($date_str) { |
|
26 | 26 | |
27 | 27 | # regex to match wc3dtf |
28 | 28 | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
29 | 29 | |
30 | - if ( preg_match( $pat, $date_str, $match ) ) { |
|
31 | - list( $year, $month, $day, $hours, $minutes, $seconds) = |
|
32 | - array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|
30 | + if (preg_match($pat, $date_str, $match)) { |
|
31 | + list($year, $month, $day, $hours, $minutes, $seconds) = |
|
32 | + array($match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|
33 | 33 | |
34 | 34 | # calc epoch for current date assuming GMT |
35 | - $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); |
|
35 | + $epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year); |
|
36 | 36 | |
37 | 37 | $offset = 0; |
38 | - if ( $match[10] == 'Z' ) { |
|
38 | + if ($match[10] == 'Z') { |
|
39 | 39 | # zulu time, aka GMT |
40 | 40 | } |
41 | 41 | else { |
42 | - list( $tz_mod, $tz_hour, $tz_min ) = |
|
43 | - array( $match[8], $match[9], $match[10]); |
|
42 | + list($tz_mod, $tz_hour, $tz_min) = |
|
43 | + array($match[8], $match[9], $match[10]); |
|
44 | 44 | |
45 | 45 | # zero out the variables |
46 | - if ( ! $tz_hour ) { $tz_hour = 0; } |
|
47 | - if ( ! $tz_min ) { $tz_min = 0; } |
|
46 | + if (!$tz_hour) { $tz_hour = 0; } |
|
47 | + if (!$tz_min) { $tz_min = 0; } |
|
48 | 48 | |
49 | - $offset_secs = (($tz_hour*60)+$tz_min)*60; |
|
49 | + $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
50 | 50 | |
51 | 51 | # is timezone ahead of GMT? then subtract offset |
52 | 52 | # |
53 | - if ( $tz_mod == '+' ) { |
|
53 | + if ($tz_mod == '+') { |
|
54 | 54 | $offset_secs = $offset_secs * -1; |
55 | 55 | } |
56 | 56 |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | $offset = 0; |
38 | 38 | if ( $match[10] == 'Z' ) { |
39 | 39 | # zulu time, aka GMT |
40 | - } |
|
41 | - else { |
|
40 | + } else { |
|
42 | 41 | list( $tz_mod, $tz_hour, $tz_min ) = |
43 | 42 | array( $match[8], $match[9], $match[10]); |
44 | 43 | |
@@ -58,8 +57,7 @@ discard block |
||
58 | 57 | } |
59 | 58 | $epoch = $epoch + $offset; |
60 | 59 | return $epoch; |
61 | - } |
|
62 | - else { |
|
60 | + } else { |
|
63 | 61 | return -1; |
64 | 62 | } |
65 | 63 | } |
@@ -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 |
@@ -40,47 +40,47 @@ discard block |
||
40 | 40 | |
41 | 41 | /* user definable vars */ |
42 | 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 |
|
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 | 50 | // $cookies["username"]="joe"; |
51 | - public $rawheaders = array(); // array of raw headers to send |
|
51 | + public $rawheaders = array(); // array of raw headers to send |
|
52 | 52 | // $rawheaders["Content-type"]="text/html"; |
53 | 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. |
|
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 | 59 | // this only applies to fetchlinks() |
60 | 60 | // or submitlinks() |
61 | - public $passcookies = true; // pass set cookies back through redirects |
|
61 | + public $passcookies = true; // pass set cookies back through redirects |
|
62 | 62 | // NOTE: this currently does not respect |
63 | 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 | 68 | // http accept types |
69 | - public $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
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 |
|
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 | 78 | // supported only since PHP 4 Beta 4 |
79 | 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 |
|
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"; |
|
83 | + public $curl_path = "/usr/bin/curl"; |
|
84 | 84 | // Snoopy will use cURL for fetching |
85 | 85 | // SSL content if a full system path to |
86 | 86 | // the cURL binary is supplied here. |
@@ -93,24 +93,24 @@ discard block |
||
93 | 93 | // as of this Snoopy release. |
94 | 94 | |
95 | 95 | // send Accept-encoding: gzip? |
96 | - public $use_gzip = true; |
|
96 | + public $use_gzip = true; |
|
97 | 97 | |
98 | 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 |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | switch ($URI_PARTS["scheme"]) { |
133 | 133 | case "http": |
134 | 134 | $this->host = $URI_PARTS["host"]; |
135 | - if(!empty($URI_PARTS["port"])) |
|
135 | + if (!empty($URI_PARTS["port"])) |
|
136 | 136 | $this->port = $URI_PARTS["port"]; |
137 | - if($this->_connect($fp)) |
|
137 | + if ($this->_connect($fp)) |
|
138 | 138 | { |
139 | - if($this->_isproxy) |
|
139 | + if ($this->_isproxy) |
|
140 | 140 | { |
141 | 141 | // using proxy, send entire URI |
142 | - $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|
142 | + $this->_httprequest($URI, $fp, $URI, $this->_httpmethod); |
|
143 | 143 | } |
144 | 144 | else |
145 | 145 | { |
@@ -150,30 +150,30 @@ discard block |
||
150 | 150 | |
151 | 151 | $this->_disconnect($fp); |
152 | 152 | |
153 | - if($this->_redirectaddr) |
|
153 | + if ($this->_redirectaddr) |
|
154 | 154 | { |
155 | 155 | /* url was redirected, check if we've hit the max depth */ |
156 | - if($this->maxredirs > $this->_redirectdepth) |
|
156 | + if ($this->maxredirs > $this->_redirectdepth) |
|
157 | 157 | { |
158 | 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) |
|
159 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
160 | 160 | { |
161 | 161 | /* follow the redirect */ |
162 | 162 | $this->_redirectdepth++; |
163 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
163 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
164 | 164 | $this->fetch($this->_redirectaddr); |
165 | 165 | } |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
169 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
170 | 170 | { |
171 | 171 | $frameurls = $this->_frameurls; |
172 | 172 | $this->_frameurls = array(); |
173 | 173 | |
174 | - while(list(,$frameurl) = each($frameurls)) |
|
174 | + while (list(,$frameurl) = each($frameurls)) |
|
175 | 175 | { |
176 | - if($this->_framedepth < $this->maxframes) |
|
176 | + if ($this->_framedepth < $this->maxframes) |
|
177 | 177 | { |
178 | 178 | $this->fetch($frameurl); |
179 | 179 | $this->_framedepth++; |
@@ -190,17 +190,17 @@ discard block |
||
190 | 190 | return true; |
191 | 191 | break; |
192 | 192 | case "https": |
193 | - if(!$this->curl_path || (!is_executable($this->curl_path))) { |
|
193 | + if (!$this->curl_path || (!is_executable($this->curl_path))) { |
|
194 | 194 | $this->error = "Bad curl ($this->curl_path), can't fetch HTTPS \n"; |
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | $this->host = $URI_PARTS["host"]; |
198 | - if(!empty($URI_PARTS["port"])) |
|
198 | + if (!empty($URI_PARTS["port"])) |
|
199 | 199 | $this->port = $URI_PARTS["port"]; |
200 | - if($this->_isproxy) |
|
200 | + if ($this->_isproxy) |
|
201 | 201 | { |
202 | 202 | // using proxy, send entire URI |
203 | - $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|
203 | + $this->_httpsrequest($URI, $URI, $this->_httpmethod); |
|
204 | 204 | } |
205 | 205 | else |
206 | 206 | { |
@@ -209,30 +209,30 @@ discard block |
||
209 | 209 | $this->_httpsrequest($path, $URI, $this->_httpmethod); |
210 | 210 | } |
211 | 211 | |
212 | - if($this->_redirectaddr) |
|
212 | + if ($this->_redirectaddr) |
|
213 | 213 | { |
214 | 214 | /* url was redirected, check if we've hit the max depth */ |
215 | - if($this->maxredirs > $this->_redirectdepth) |
|
215 | + if ($this->maxredirs > $this->_redirectdepth) |
|
216 | 216 | { |
217 | 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) |
|
218 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
219 | 219 | { |
220 | 220 | /* follow the redirect */ |
221 | 221 | $this->_redirectdepth++; |
222 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
222 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
223 | 223 | $this->fetch($this->_redirectaddr); |
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
228 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
229 | 229 | { |
230 | 230 | $frameurls = $this->_frameurls; |
231 | 231 | $this->_frameurls = array(); |
232 | 232 | |
233 | - while(list(,$frameurl) = each($frameurls)) |
|
233 | + while (list(,$frameurl) = each($frameurls)) |
|
234 | 234 | { |
235 | - if($this->_framedepth < $this->maxframes) |
|
235 | + if ($this->_framedepth < $this->maxframes) |
|
236 | 236 | { |
237 | 237 | $this->fetch($frameurl); |
238 | 238 | $this->_framedepth++; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | break; |
246 | 246 | default: |
247 | 247 | // not a valid protocol |
248 | - $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
248 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
249 | 249 | return false; |
250 | 250 | break; |
251 | 251 | } |
@@ -272,20 +272,20 @@ discard block |
||
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 | - 'isx",$document,$links); |
|
275 | + 'isx",$document, $links); |
|
276 | 276 | |
277 | 277 | |
278 | 278 | // catenate the non-empty matches from the conditional subpattern |
279 | 279 | |
280 | - while(list($key,$val) = each($links[2])) |
|
280 | + while (list($key, $val) = each($links[2])) |
|
281 | 281 | { |
282 | - if(!empty($val)) |
|
282 | + if (!empty($val)) |
|
283 | 283 | $match[] = $val; |
284 | 284 | } |
285 | 285 | |
286 | - while(list($key,$val) = each($links[3])) |
|
286 | + while (list($key, $val) = each($links[3])) |
|
287 | 287 | { |
288 | - if(!empty($val)) |
|
288 | + if (!empty($val)) |
|
289 | 289 | $match[] = $val; |
290 | 290 | } |
291 | 291 | |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | |
303 | 303 | private function _stripform($document) |
304 | 304 | { |
305 | - preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); |
|
305 | + preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi", $document, $elements); |
|
306 | 306 | |
307 | 307 | // catenate the matches |
308 | - $match = implode("\r\n",$elements[0]); |
|
308 | + $match = implode("\r\n", $elements[0]); |
|
309 | 309 | |
310 | 310 | // return the links |
311 | 311 | return $match; |
@@ -327,10 +327,10 @@ discard block |
||
327 | 327 | // so, list your entities one by one here. I included some of the |
328 | 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 |
|
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 | 334 | "'&(amp|#38);'i", |
335 | 335 | "'&(lt|#60);'i", |
336 | 336 | "'&(gt|#62);'i", |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | "'&(pound|#163);'i", |
341 | 341 | "'&(copy|#169);'i" |
342 | 342 | ); |
343 | - $replace = array( "", |
|
343 | + $replace = array("", |
|
344 | 344 | "", |
345 | 345 | "\\1", |
346 | 346 | "\"", |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | chr(163), |
354 | 354 | chr(169)); |
355 | 355 | |
356 | - $text = preg_replace($search,$replace,$document); |
|
356 | + $text = preg_replace($search, $replace, $document); |
|
357 | 357 | |
358 | 358 | return $text; |
359 | 359 | } |
@@ -366,26 +366,26 @@ discard block |
||
366 | 366 | Output: $expandedLinks the expanded links |
367 | 367 | \*======================================================================*/ |
368 | 368 | |
369 | - private function _expandlinks($links,$URI) |
|
369 | + private function _expandlinks($links, $URI) |
|
370 | 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", |
|
376 | + $search = array("|^http://".preg_quote($this->host)."|i", |
|
377 | 377 | "|^(?!http://)(\/)?(?!mailto:)|i", |
378 | 378 | "|/\./|", |
379 | 379 | "|/[^\/]+/\.\./|" |
380 | 380 | ); |
381 | 381 | |
382 | - $replace = array( "", |
|
382 | + $replace = array("", |
|
383 | 383 | $match."/", |
384 | 384 | "/", |
385 | 385 | "/" |
386 | 386 | ); |
387 | 387 | |
388 | - $expandedLinks = preg_replace($search,$replace,$links); |
|
388 | + $expandedLinks = preg_replace($search, $replace, $links); |
|
389 | 389 | |
390 | 390 | return $expandedLinks; |
391 | 391 | } |
@@ -400,26 +400,26 @@ discard block |
||
400 | 400 | Output: |
401 | 401 | \*======================================================================*/ |
402 | 402 | |
403 | - private function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
|
403 | + private function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "") |
|
404 | 404 | { |
405 | - if($this->passcookies && $this->_redirectaddr) |
|
405 | + if ($this->passcookies && $this->_redirectaddr) |
|
406 | 406 | $this->setcookies(); |
407 | 407 | |
408 | 408 | $URI_PARTS = parse_url($URI); |
409 | - if(empty($url)) |
|
409 | + if (empty($url)) |
|
410 | 410 | $url = "/"; |
411 | 411 | $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
412 | - if(!empty($this->agent)) |
|
412 | + if (!empty($this->agent)) |
|
413 | 413 | $headers .= "User-Agent: ".$this->agent."\r\n"; |
414 | - if(!empty($this->host) && !isset($this->rawheaders['Host'])) |
|
414 | + if (!empty($this->host) && !isset($this->rawheaders['Host'])) |
|
415 | 415 | $headers .= "Host: ".$this->host."\r\n"; |
416 | - if(!empty($this->accept)) |
|
416 | + if (!empty($this->accept)) |
|
417 | 417 | $headers .= "Accept: ".$this->accept."\r\n"; |
418 | 418 | |
419 | - if($this->use_gzip) { |
|
419 | + if ($this->use_gzip) { |
|
420 | 420 | // make sure PHP was built with --with-zlib |
421 | 421 | // and we can handle gzipp'ed data |
422 | - if ( function_exists(gzinflate) ) { |
|
422 | + if (function_exists(gzinflate)) { |
|
423 | 423 | $headers .= "Accept-encoding: gzip\r\n"; |
424 | 424 | } |
425 | 425 | else { |
@@ -430,38 +430,38 @@ discard block |
||
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - if(!empty($this->referer)) |
|
433 | + if (!empty($this->referer)) |
|
434 | 434 | $headers .= "Referer: ".$this->referer."\r\n"; |
435 | - if(!empty($this->cookies)) |
|
435 | + if (!empty($this->cookies)) |
|
436 | 436 | { |
437 | - if(!is_array($this->cookies)) |
|
438 | - $this->cookies = (array)$this->cookies; |
|
437 | + if (!is_array($this->cookies)) |
|
438 | + $this->cookies = (array) $this->cookies; |
|
439 | 439 | |
440 | 440 | reset($this->cookies); |
441 | - if ( count($this->cookies) > 0 ) { |
|
441 | + if (count($this->cookies) > 0) { |
|
442 | 442 | $cookie_headers .= 'Cookie: '; |
443 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
443 | + foreach ($this->cookies as $cookieKey => $cookieVal) { |
|
444 | 444 | $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
445 | 445 | } |
446 | - $headers .= substr($cookie_headers,0,-2) . "\r\n"; |
|
446 | + $headers .= substr($cookie_headers, 0, -2)."\r\n"; |
|
447 | 447 | } |
448 | 448 | } |
449 | - if(!empty($this->rawheaders)) |
|
449 | + if (!empty($this->rawheaders)) |
|
450 | 450 | { |
451 | - if(!is_array($this->rawheaders)) |
|
452 | - $this->rawheaders = (array)$this->rawheaders; |
|
453 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
451 | + if (!is_array($this->rawheaders)) |
|
452 | + $this->rawheaders = (array) $this->rawheaders; |
|
453 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
454 | 454 | $headers .= $headerKey.": ".$headerVal."\r\n"; |
455 | 455 | } |
456 | - if(!empty($content_type)) { |
|
456 | + if (!empty($content_type)) { |
|
457 | 457 | $headers .= "Content-type: $content_type"; |
458 | 458 | if ($content_type == "multipart/form-data") |
459 | 459 | $headers .= "; boundary=".$this->_mime_boundary; |
460 | 460 | $headers .= "\r\n"; |
461 | 461 | } |
462 | - if(!empty($body)) |
|
462 | + if (!empty($body)) |
|
463 | 463 | $headers .= "Content-length: ".strlen($body)."\r\n"; |
464 | - if(!empty($this->user) || !empty($this->pass)) |
|
464 | + if (!empty($this->user) || !empty($this->pass)) |
|
465 | 465 | $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; |
466 | 466 | |
467 | 467 | $headers .= "\r\n"; |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | socket_set_timeout($fp, $this->read_timeout); |
472 | 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 | 476 | $this->_redirectaddr = false; |
477 | 477 | unset($this->headers); |
@@ -479,30 +479,30 @@ discard block |
||
479 | 479 | // content was returned gzip encoded? |
480 | 480 | $is_gzipped = false; |
481 | 481 | |
482 | - while($currentHeader = fgets($fp,$this->_maxlinelen)) |
|
482 | + while ($currentHeader = fgets($fp, $this->_maxlinelen)) |
|
483 | 483 | { |
484 | 484 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
485 | 485 | { |
486 | - $this->status=-100; |
|
486 | + $this->status = -100; |
|
487 | 487 | return false; |
488 | 488 | } |
489 | 489 | |
490 | 490 | // if($currentHeader == "\r\n") |
491 | - if(preg_match("/^\r?\n$/", $currentHeader) ) |
|
491 | + if (preg_match("/^\r?\n$/", $currentHeader)) |
|
492 | 492 | break; |
493 | 493 | |
494 | 494 | // if a header begins with Location: or URI:, set the redirect |
495 | - if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
|
495 | + if (preg_match("/^(Location:|URI:)/i", $currentHeader)) |
|
496 | 496 | { |
497 | 497 | // get URL portion of the redirect |
498 | - preg_match("/^(Location:|URI:)\s+(.*)/",chop($currentHeader),$matches); |
|
498 | + preg_match("/^(Location:|URI:)\s+(.*)/", chop($currentHeader), $matches); |
|
499 | 499 | // look for :// in the Location header to see if hostname is included |
500 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
500 | + if (!preg_match("|\:\/\/|", $matches[2])) |
|
501 | 501 | { |
502 | 502 | // no host in the path, so prepend |
503 | 503 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
504 | 504 | // eliminate double slash |
505 | - if(!preg_match("|^/|",$matches[2])) |
|
505 | + if (!preg_match("|^/|", $matches[2])) |
|
506 | 506 | $this->_redirectaddr .= "/".$matches[2]; |
507 | 507 | else |
508 | 508 | $this->_redirectaddr .= $matches[2]; |
@@ -511,16 +511,16 @@ discard block |
||
511 | 511 | $this->_redirectaddr = $matches[2]; |
512 | 512 | } |
513 | 513 | |
514 | - if(preg_match("|^HTTP/|",$currentHeader)) |
|
514 | + if (preg_match("|^HTTP/|", $currentHeader)) |
|
515 | 515 | { |
516 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
516 | + if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $currentHeader, $status)) |
|
517 | 517 | { |
518 | - $this->status= $status[1]; |
|
518 | + $this->status = $status[1]; |
|
519 | 519 | } |
520 | 520 | $this->response_code = $currentHeader; |
521 | 521 | } |
522 | 522 | |
523 | - if (preg_match("/Content-Encoding: gzip/", $currentHeader) ) { |
|
523 | + if (preg_match("/Content-Encoding: gzip/", $currentHeader)) { |
|
524 | 524 | $is_gzipped = true; |
525 | 525 | } |
526 | 526 | |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | |
530 | 530 | # $results = fread($fp, $this->maxlength); |
531 | 531 | $results = ""; |
532 | - while ( $data = fread($fp, $this->maxlength) ) { |
|
532 | + while ($data = fread($fp, $this->maxlength)) { |
|
533 | 533 | $results .= $data; |
534 | 534 | if ( |
535 | 535 | strlen($results) > $this->maxlength ) { |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | } |
539 | 539 | |
540 | 540 | // gunzip |
541 | - if ( $is_gzipped ) { |
|
541 | + if ($is_gzipped) { |
|
542 | 542 | // per http://www.php.net/manual/en/function.gzencode.php |
543 | 543 | $results = substr($results, 10); |
544 | 544 | $results = gzinflate($results); |
@@ -546,26 +546,26 @@ discard block |
||
546 | 546 | |
547 | 547 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
548 | 548 | { |
549 | - $this->status=-100; |
|
549 | + $this->status = -100; |
|
550 | 550 | return false; |
551 | 551 | } |
552 | 552 | |
553 | 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)) |
|
555 | + if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match)) |
|
556 | 556 | { |
557 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
557 | + $this->_redirectaddr = $this->_expandlinks($match[1], $URI); |
|
558 | 558 | } |
559 | 559 | |
560 | 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)) |
|
561 | + if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) |
|
562 | 562 | { |
563 | 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); |
|
564 | + for ($x = 0; $x < count($match[1]); $x++) |
|
565 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
566 | 566 | } |
567 | 567 | // have we already fetched framed content? |
568 | - elseif(is_array($this->results)) |
|
568 | + elseif (is_array($this->results)) |
|
569 | 569 | $this->results[] = $results; |
570 | 570 | // no framed content |
571 | 571 | else |
@@ -583,66 +583,66 @@ discard block |
||
583 | 583 | Output: |
584 | 584 | \*======================================================================*/ |
585 | 585 | |
586 | - private function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
|
586 | + private function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "") |
|
587 | 587 | { |
588 | - if($this->passcookies && $this->_redirectaddr) |
|
588 | + if ($this->passcookies && $this->_redirectaddr) |
|
589 | 589 | $this->setcookies(); |
590 | 590 | |
591 | 591 | $headers = array(); |
592 | 592 | |
593 | 593 | $URI_PARTS = parse_url($URI); |
594 | - if(empty($url)) |
|
594 | + if (empty($url)) |
|
595 | 595 | $url = "/"; |
596 | 596 | // GET ... header not needed for curl |
597 | 597 | //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
598 | - if(!empty($this->agent)) |
|
598 | + if (!empty($this->agent)) |
|
599 | 599 | $headers[] = "User-Agent: ".$this->agent; |
600 | - if(!empty($this->host)) |
|
600 | + if (!empty($this->host)) |
|
601 | 601 | $headers[] = "Host: ".$this->host; |
602 | - if(!empty($this->accept)) |
|
602 | + if (!empty($this->accept)) |
|
603 | 603 | $headers[] = "Accept: ".$this->accept; |
604 | - if(!empty($this->referer)) |
|
604 | + if (!empty($this->referer)) |
|
605 | 605 | $headers[] = "Referer: ".$this->referer; |
606 | - if(!empty($this->cookies)) |
|
606 | + if (!empty($this->cookies)) |
|
607 | 607 | { |
608 | - if(!is_array($this->cookies)) |
|
609 | - $this->cookies = (array)$this->cookies; |
|
608 | + if (!is_array($this->cookies)) |
|
609 | + $this->cookies = (array) $this->cookies; |
|
610 | 610 | |
611 | 611 | reset($this->cookies); |
612 | - if ( count($this->cookies) > 0 ) { |
|
612 | + if (count($this->cookies) > 0) { |
|
613 | 613 | $cookie_str = 'Cookie: '; |
614 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
614 | + foreach ($this->cookies as $cookieKey => $cookieVal) { |
|
615 | 615 | $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; |
616 | 616 | } |
617 | - $headers[] = substr($cookie_str,0,-2); |
|
617 | + $headers[] = substr($cookie_str, 0, -2); |
|
618 | 618 | } |
619 | 619 | } |
620 | - if(!empty($this->rawheaders)) |
|
620 | + if (!empty($this->rawheaders)) |
|
621 | 621 | { |
622 | - if(!is_array($this->rawheaders)) |
|
623 | - $this->rawheaders = (array)$this->rawheaders; |
|
624 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
622 | + if (!is_array($this->rawheaders)) |
|
623 | + $this->rawheaders = (array) $this->rawheaders; |
|
624 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
625 | 625 | $headers[] = $headerKey.": ".$headerVal; |
626 | 626 | } |
627 | - if(!empty($content_type)) { |
|
627 | + if (!empty($content_type)) { |
|
628 | 628 | if ($content_type == "multipart/form-data") |
629 | 629 | $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
630 | 630 | else |
631 | 631 | $headers[] = "Content-type: $content_type"; |
632 | 632 | } |
633 | - if(!empty($body)) |
|
633 | + if (!empty($body)) |
|
634 | 634 | $headers[] = "Content-length: ".strlen($body); |
635 | - if(!empty($this->user) || !empty($this->pass)) |
|
635 | + if (!empty($this->user) || !empty($this->pass)) |
|
636 | 636 | $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
637 | 637 | |
638 | - for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|
638 | + for ($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|
639 | 639 | $cmdline_params .= " -H \"".$headers[$curr_header]."\""; |
640 | 640 | } |
641 | 641 | |
642 | - if(!empty($body)) |
|
642 | + if (!empty($body)) |
|
643 | 643 | $cmdline_params .= " -d \"$body\""; |
644 | 644 | |
645 | - if($this->read_timeout > 0) |
|
645 | + if ($this->read_timeout > 0) |
|
646 | 646 | $cmdline_params .= " -m ".$this->read_timeout; |
647 | 647 | |
648 | 648 | $headerfile = uniqid(time()); |
@@ -651,37 +651,37 @@ discard block |
||
651 | 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) |
|
656 | + if ($return) |
|
657 | 657 | { |
658 | 658 | $this->error = "Error: cURL could not retrieve the document, error $return."; |
659 | 659 | return false; |
660 | 660 | } |
661 | 661 | |
662 | 662 | |
663 | - $results = implode("\r\n",$results); |
|
663 | + $results = implode("\r\n", $results); |
|
664 | 664 | |
665 | 665 | $result_headers = file("/tmp/$headerfile"); |
666 | 666 | |
667 | 667 | $this->_redirectaddr = false; |
668 | 668 | unset($this->headers); |
669 | 669 | |
670 | - for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
670 | + for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
671 | 671 | { |
672 | 672 | |
673 | 673 | // if a header begins with Location: or URI:, set the redirect |
674 | - if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) |
|
674 | + if (preg_match("/^(Location: |URI: )/i", $result_headers[$currentHeader])) |
|
675 | 675 | { |
676 | 676 | // get URL portion of the redirect |
677 | - preg_match("/^(Location: |URI:)(.*)/",chop($result_headers[$currentHeader]),$matches); |
|
677 | + preg_match("/^(Location: |URI:)(.*)/", chop($result_headers[$currentHeader]), $matches); |
|
678 | 678 | // look for :// in the Location header to see if hostname is included |
679 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
679 | + if (!preg_match("|\:\/\/|", $matches[2])) |
|
680 | 680 | { |
681 | 681 | // no host in the path, so prepend |
682 | 682 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
683 | 683 | // eliminate double slash |
684 | - if(!preg_match("|^/|",$matches[2])) |
|
684 | + if (!preg_match("|^/|", $matches[2])) |
|
685 | 685 | $this->_redirectaddr .= "/".$matches[2]; |
686 | 686 | else |
687 | 687 | $this->_redirectaddr .= $matches[2]; |
@@ -690,12 +690,12 @@ discard block |
||
690 | 690 | $this->_redirectaddr = $matches[2]; |
691 | 691 | } |
692 | 692 | |
693 | - if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
693 | + if (preg_match("|^HTTP/|", $result_headers[$currentHeader])) |
|
694 | 694 | { |
695 | 695 | $this->response_code = $result_headers[$currentHeader]; |
696 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$this->response_code, $match)) |
|
696 | + if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $this->response_code, $match)) |
|
697 | 697 | { |
698 | - $this->status= $match[1]; |
|
698 | + $this->status = $match[1]; |
|
699 | 699 | } |
700 | 700 | } |
701 | 701 | $this->headers[] = $result_headers[$currentHeader]; |
@@ -703,20 +703,20 @@ discard block |
||
703 | 703 | |
704 | 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)) |
|
706 | + if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match)) |
|
707 | 707 | { |
708 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
708 | + $this->_redirectaddr = $this->_expandlinks($match[1], $URI); |
|
709 | 709 | } |
710 | 710 | |
711 | 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)) |
|
712 | + if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) |
|
713 | 713 | { |
714 | 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); |
|
715 | + for ($x = 0; $x < count($match[1]); $x++) |
|
716 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
717 | 717 | } |
718 | 718 | // have we already fetched framed content? |
719 | - elseif(is_array($this->results)) |
|
719 | + elseif (is_array($this->results)) |
|
720 | 720 | $this->results[] = $results; |
721 | 721 | // no framed content |
722 | 722 | else |
@@ -734,9 +734,9 @@ discard block |
||
734 | 734 | |
735 | 735 | public function setcookies() |
736 | 736 | { |
737 | - for($x=0; $x<count($this->headers); $x++) |
|
737 | + for ($x = 0; $x < count($this->headers); $x++) |
|
738 | 738 | { |
739 | - if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) |
|
739 | + if (preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x], $match)) |
|
740 | 740 | $this->cookies[$match[1]] = $match[2]; |
741 | 741 | } |
742 | 742 | } |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | |
769 | 769 | private function _connect(&$fp) |
770 | 770 | { |
771 | - if(!empty($this->proxy_host) && !empty($this->proxy_port)) |
|
771 | + if (!empty($this->proxy_host) && !empty($this->proxy_port)) |
|
772 | 772 | { |
773 | 773 | $this->_isproxy = true; |
774 | 774 | $host = $this->proxy_host; |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | |
783 | 783 | $this->status = 0; |
784 | 784 | |
785 | - if($fp = fsockopen( |
|
785 | + if ($fp = fsockopen( |
|
786 | 786 | $host, |
787 | 787 | $port, |
788 | 788 | $errno, |
@@ -798,16 +798,16 @@ discard block |
||
798 | 798 | { |
799 | 799 | // socket connection failed |
800 | 800 | $this->status = $errno; |
801 | - switch($errno) |
|
801 | + switch ($errno) |
|
802 | 802 | { |
803 | 803 | case -3: |
804 | - $this->error="socket creation failed (-3)"; |
|
804 | + $this->error = "socket creation failed (-3)"; |
|
805 | 805 | case -4: |
806 | - $this->error="dns lookup failure (-4)"; |
|
806 | + $this->error = "dns lookup failure (-4)"; |
|
807 | 807 | case -5: |
808 | - $this->error="connection refused or timed out (-5)"; |
|
808 | + $this->error = "connection refused or timed out (-5)"; |
|
809 | 809 | default: |
810 | - $this->error="connection failed (".$errno.")"; |
|
810 | + $this->error = "connection failed (".$errno.")"; |
|
811 | 811 | } |
812 | 812 | return false; |
813 | 813 | } |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | switch ($this->_submit_type) { |
844 | 844 | case "application/x-www-form-urlencoded": |
845 | 845 | reset($formvars); |
846 | - while(list($key,$val) = each($formvars)) { |
|
846 | + while (list($key, $val) = each($formvars)) { |
|
847 | 847 | if (is_array($val) || is_object($val)) { |
848 | 848 | while (list($cur_key, $cur_val) = each($val)) { |
849 | 849 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
858 | 858 | |
859 | 859 | reset($formvars); |
860 | - while(list($key,$val) = each($formvars)) { |
|
860 | + while (list($key, $val) = each($formvars)) { |
|
861 | 861 | if (is_array($val) || is_object($val)) { |
862 | 862 | while (list($cur_key, $cur_val) = each($val)) { |
863 | 863 | $postdata .= "--".$this->_mime_boundary."\r\n"; |
@@ -124,24 +124,26 @@ discard block |
||
124 | 124 | public function fetch($URI) { |
125 | 125 | //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
126 | 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"]; |
|
127 | + if (!empty($URI_PARTS["user"])) { |
|
128 | + $this->user = $URI_PARTS["user"]; |
|
129 | + } |
|
130 | + if (!empty($URI_PARTS["pass"])) { |
|
131 | + $this->pass = $URI_PARTS["pass"]; |
|
132 | + } |
|
131 | 133 | if (!isset($fp)) { $fp = false; } |
132 | 134 | switch ($URI_PARTS["scheme"]) { |
133 | 135 | case "http": |
134 | 136 | $this->host = $URI_PARTS["host"]; |
135 | - if(!empty($URI_PARTS["port"])) |
|
136 | - $this->port = $URI_PARTS["port"]; |
|
137 | + if(!empty($URI_PARTS["port"])) { |
|
138 | + $this->port = $URI_PARTS["port"]; |
|
139 | + } |
|
137 | 140 | if($this->_connect($fp)) |
138 | 141 | { |
139 | 142 | if($this->_isproxy) |
140 | 143 | { |
141 | 144 | // using proxy, send entire URI |
142 | 145 | $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
143 | - } |
|
144 | - else |
|
146 | + } else |
|
145 | 147 | { |
146 | 148 | $path = $URI_PARTS["path"].(isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : ""); |
147 | 149 | // no proxy, send only the path |
@@ -177,13 +179,12 @@ discard block |
||
177 | 179 | { |
178 | 180 | $this->fetch($frameurl); |
179 | 181 | $this->_framedepth++; |
182 | + } else { |
|
183 | + break; |
|
180 | 184 | } |
181 | - else |
|
182 | - break; |
|
183 | 185 | } |
184 | 186 | } |
185 | - } |
|
186 | - else |
|
187 | + } else |
|
187 | 188 | { |
188 | 189 | return false; |
189 | 190 | } |
@@ -195,14 +196,14 @@ discard block |
||
195 | 196 | return false; |
196 | 197 | } |
197 | 198 | $this->host = $URI_PARTS["host"]; |
198 | - if(!empty($URI_PARTS["port"])) |
|
199 | - $this->port = $URI_PARTS["port"]; |
|
199 | + if(!empty($URI_PARTS["port"])) { |
|
200 | + $this->port = $URI_PARTS["port"]; |
|
201 | + } |
|
200 | 202 | if($this->_isproxy) |
201 | 203 | { |
202 | 204 | // using proxy, send entire URI |
203 | 205 | $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
204 | - } |
|
205 | - else |
|
206 | + } else |
|
206 | 207 | { |
207 | 208 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
208 | 209 | // no proxy, send only the path |
@@ -236,9 +237,9 @@ discard block |
||
236 | 237 | { |
237 | 238 | $this->fetch($frameurl); |
238 | 239 | $this->_framedepth++; |
240 | + } else { |
|
241 | + break; |
|
239 | 242 | } |
240 | - else |
|
241 | - break; |
|
242 | 243 | } |
243 | 244 | } |
244 | 245 | return true; |
@@ -279,14 +280,16 @@ discard block |
||
279 | 280 | |
280 | 281 | while(list($key,$val) = each($links[2])) |
281 | 282 | { |
282 | - if(!empty($val)) |
|
283 | - $match[] = $val; |
|
283 | + if(!empty($val)) { |
|
284 | + $match[] = $val; |
|
285 | + } |
|
284 | 286 | } |
285 | 287 | |
286 | 288 | while(list($key,$val) = each($links[3])) |
287 | 289 | { |
288 | - if(!empty($val)) |
|
289 | - $match[] = $val; |
|
290 | + if(!empty($val)) { |
|
291 | + $match[] = $val; |
|
292 | + } |
|
290 | 293 | } |
291 | 294 | |
292 | 295 | // return the links |
@@ -402,27 +405,31 @@ discard block |
||
402 | 405 | |
403 | 406 | private function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
404 | 407 | { |
405 | - if($this->passcookies && $this->_redirectaddr) |
|
406 | - $this->setcookies(); |
|
408 | + if($this->passcookies && $this->_redirectaddr) { |
|
409 | + $this->setcookies(); |
|
410 | + } |
|
407 | 411 | |
408 | 412 | $URI_PARTS = parse_url($URI); |
409 | - if(empty($url)) |
|
410 | - $url = "/"; |
|
413 | + if(empty($url)) { |
|
414 | + $url = "/"; |
|
415 | + } |
|
411 | 416 | $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"; |
|
417 | + if(!empty($this->agent)) { |
|
418 | + $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
419 | + } |
|
420 | + if(!empty($this->host) && !isset($this->rawheaders['Host'])) { |
|
421 | + $headers .= "Host: ".$this->host."\r\n"; |
|
422 | + } |
|
423 | + if(!empty($this->accept)) { |
|
424 | + $headers .= "Accept: ".$this->accept."\r\n"; |
|
425 | + } |
|
418 | 426 | |
419 | 427 | if($this->use_gzip) { |
420 | 428 | // make sure PHP was built with --with-zlib |
421 | 429 | // and we can handle gzipp'ed data |
422 | 430 | if ( function_exists(gzinflate) ) { |
423 | 431 | $headers .= "Accept-encoding: gzip\r\n"; |
424 | - } |
|
425 | - else { |
|
432 | + } else { |
|
426 | 433 | trigger_error( |
427 | 434 | "use_gzip is on, but PHP was built without zlib support.". |
428 | 435 | " Requesting file(s) without gzip encoding.", |
@@ -430,12 +437,14 @@ discard block |
||
430 | 437 | } |
431 | 438 | } |
432 | 439 | |
433 | - if(!empty($this->referer)) |
|
434 | - $headers .= "Referer: ".$this->referer."\r\n"; |
|
440 | + if(!empty($this->referer)) { |
|
441 | + $headers .= "Referer: ".$this->referer."\r\n"; |
|
442 | + } |
|
435 | 443 | if(!empty($this->cookies)) |
436 | 444 | { |
437 | - if(!is_array($this->cookies)) |
|
438 | - $this->cookies = (array)$this->cookies; |
|
445 | + if(!is_array($this->cookies)) { |
|
446 | + $this->cookies = (array)$this->cookies; |
|
447 | + } |
|
439 | 448 | |
440 | 449 | reset($this->cookies); |
441 | 450 | if ( count($this->cookies) > 0 ) { |
@@ -448,27 +457,33 @@ discard block |
||
448 | 457 | } |
449 | 458 | if(!empty($this->rawheaders)) |
450 | 459 | { |
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"; |
|
460 | + if(!is_array($this->rawheaders)) { |
|
461 | + $this->rawheaders = (array)$this->rawheaders; |
|
462 | + } |
|
463 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
464 | + $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
465 | + } |
|
455 | 466 | } |
456 | 467 | if(!empty($content_type)) { |
457 | 468 | $headers .= "Content-type: $content_type"; |
458 | - if ($content_type == "multipart/form-data") |
|
459 | - $headers .= "; boundary=".$this->_mime_boundary; |
|
469 | + if ($content_type == "multipart/form-data") { |
|
470 | + $headers .= "; boundary=".$this->_mime_boundary; |
|
471 | + } |
|
460 | 472 | $headers .= "\r\n"; |
461 | 473 | } |
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"; |
|
474 | + if(!empty($body)) { |
|
475 | + $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
476 | + } |
|
477 | + if(!empty($this->user) || !empty($this->pass)) { |
|
478 | + $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
479 | + } |
|
466 | 480 | |
467 | 481 | $headers .= "\r\n"; |
468 | 482 | |
469 | 483 | // set the read timeout if needed |
470 | - if ($this->read_timeout > 0) |
|
471 | - socket_set_timeout($fp, $this->read_timeout); |
|
484 | + if ($this->read_timeout > 0) { |
|
485 | + socket_set_timeout($fp, $this->read_timeout); |
|
486 | + } |
|
472 | 487 | $this->timed_out = false; |
473 | 488 | |
474 | 489 | fwrite($fp,$headers.$body,strlen($headers.$body)); |
@@ -488,8 +503,9 @@ discard block |
||
488 | 503 | } |
489 | 504 | |
490 | 505 | // if($currentHeader == "\r\n") |
491 | - if(preg_match("/^\r?\n$/", $currentHeader) ) |
|
492 | - break; |
|
506 | + if(preg_match("/^\r?\n$/", $currentHeader) ) { |
|
507 | + break; |
|
508 | + } |
|
493 | 509 | |
494 | 510 | // if a header begins with Location: or URI:, set the redirect |
495 | 511 | if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
@@ -502,13 +518,14 @@ discard block |
||
502 | 518 | // no host in the path, so prepend |
503 | 519 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
504 | 520 | // eliminate double slash |
505 | - if(!preg_match("|^/|",$matches[2])) |
|
506 | - $this->_redirectaddr .= "/".$matches[2]; |
|
507 | - else |
|
508 | - $this->_redirectaddr .= $matches[2]; |
|
521 | + if(!preg_match("|^/|",$matches[2])) { |
|
522 | + $this->_redirectaddr .= "/".$matches[2]; |
|
523 | + } else { |
|
524 | + $this->_redirectaddr .= $matches[2]; |
|
525 | + } |
|
526 | + } else { |
|
527 | + $this->_redirectaddr = $matches[2]; |
|
509 | 528 | } |
510 | - else |
|
511 | - $this->_redirectaddr = $matches[2]; |
|
512 | 529 | } |
513 | 530 | |
514 | 531 | if(preg_match("|^HTTP/|",$currentHeader)) |
@@ -561,15 +578,18 @@ discard block |
||
561 | 578 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
562 | 579 | { |
563 | 580 | $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); |
|
581 | + for($x=0; $x<count($match[1]); $x++) { |
|
582 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
583 | + } |
|
566 | 584 | } |
567 | 585 | // have we already fetched framed content? |
568 | - elseif(is_array($this->results)) |
|
569 | - $this->results[] = $results; |
|
586 | + elseif(is_array($this->results)) { |
|
587 | + $this->results[] = $results; |
|
588 | + } |
|
570 | 589 | // no framed content |
571 | - else |
|
572 | - $this->results = $results; |
|
590 | + else { |
|
591 | + $this->results = $results; |
|
592 | + } |
|
573 | 593 | |
574 | 594 | return true; |
575 | 595 | } |
@@ -585,28 +605,35 @@ discard block |
||
585 | 605 | |
586 | 606 | private function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
587 | 607 | { |
588 | - if($this->passcookies && $this->_redirectaddr) |
|
589 | - $this->setcookies(); |
|
608 | + if($this->passcookies && $this->_redirectaddr) { |
|
609 | + $this->setcookies(); |
|
610 | + } |
|
590 | 611 | |
591 | 612 | $headers = array(); |
592 | 613 | |
593 | 614 | $URI_PARTS = parse_url($URI); |
594 | - if(empty($url)) |
|
595 | - $url = "/"; |
|
615 | + if(empty($url)) { |
|
616 | + $url = "/"; |
|
617 | + } |
|
596 | 618 | // GET ... header not needed for curl |
597 | 619 | //$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; |
|
620 | + if(!empty($this->agent)) { |
|
621 | + $headers[] = "User-Agent: ".$this->agent; |
|
622 | + } |
|
623 | + if(!empty($this->host)) { |
|
624 | + $headers[] = "Host: ".$this->host; |
|
625 | + } |
|
626 | + if(!empty($this->accept)) { |
|
627 | + $headers[] = "Accept: ".$this->accept; |
|
628 | + } |
|
629 | + if(!empty($this->referer)) { |
|
630 | + $headers[] = "Referer: ".$this->referer; |
|
631 | + } |
|
606 | 632 | if(!empty($this->cookies)) |
607 | 633 | { |
608 | - if(!is_array($this->cookies)) |
|
609 | - $this->cookies = (array)$this->cookies; |
|
634 | + if(!is_array($this->cookies)) { |
|
635 | + $this->cookies = (array)$this->cookies; |
|
636 | + } |
|
610 | 637 | |
611 | 638 | reset($this->cookies); |
612 | 639 | if ( count($this->cookies) > 0 ) { |
@@ -619,31 +646,38 @@ discard block |
||
619 | 646 | } |
620 | 647 | if(!empty($this->rawheaders)) |
621 | 648 | { |
622 | - if(!is_array($this->rawheaders)) |
|
623 | - $this->rawheaders = (array)$this->rawheaders; |
|
624 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
625 | - $headers[] = $headerKey.": ".$headerVal; |
|
649 | + if(!is_array($this->rawheaders)) { |
|
650 | + $this->rawheaders = (array)$this->rawheaders; |
|
651 | + } |
|
652 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
653 | + $headers[] = $headerKey.": ".$headerVal; |
|
654 | + } |
|
626 | 655 | } |
627 | 656 | 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); |
|
657 | + if ($content_type == "multipart/form-data") { |
|
658 | + $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
659 | + } else { |
|
660 | + $headers[] = "Content-type: $content_type"; |
|
661 | + } |
|
662 | + } |
|
663 | + if(!empty($body)) { |
|
664 | + $headers[] = "Content-length: ".strlen($body); |
|
665 | + } |
|
666 | + if(!empty($this->user) || !empty($this->pass)) { |
|
667 | + $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
668 | + } |
|
637 | 669 | |
638 | 670 | for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
639 | 671 | $cmdline_params .= " -H \"".$headers[$curr_header]."\""; |
640 | 672 | } |
641 | 673 | |
642 | - if(!empty($body)) |
|
643 | - $cmdline_params .= " -d \"$body\""; |
|
674 | + if(!empty($body)) { |
|
675 | + $cmdline_params .= " -d \"$body\""; |
|
676 | + } |
|
644 | 677 | |
645 | - if($this->read_timeout > 0) |
|
646 | - $cmdline_params .= " -m ".$this->read_timeout; |
|
678 | + if($this->read_timeout > 0) { |
|
679 | + $cmdline_params .= " -m ".$this->read_timeout; |
|
680 | + } |
|
647 | 681 | |
648 | 682 | $headerfile = uniqid(time()); |
649 | 683 | |
@@ -681,13 +715,14 @@ discard block |
||
681 | 715 | // no host in the path, so prepend |
682 | 716 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
683 | 717 | // eliminate double slash |
684 | - if(!preg_match("|^/|",$matches[2])) |
|
685 | - $this->_redirectaddr .= "/".$matches[2]; |
|
686 | - else |
|
687 | - $this->_redirectaddr .= $matches[2]; |
|
718 | + if(!preg_match("|^/|",$matches[2])) { |
|
719 | + $this->_redirectaddr .= "/".$matches[2]; |
|
720 | + } else { |
|
721 | + $this->_redirectaddr .= $matches[2]; |
|
722 | + } |
|
723 | + } else { |
|
724 | + $this->_redirectaddr = $matches[2]; |
|
688 | 725 | } |
689 | - else |
|
690 | - $this->_redirectaddr = $matches[2]; |
|
691 | 726 | } |
692 | 727 | |
693 | 728 | if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
@@ -712,15 +747,18 @@ discard block |
||
712 | 747 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
713 | 748 | { |
714 | 749 | $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); |
|
750 | + for($x=0; $x<count($match[1]); $x++) { |
|
751 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
752 | + } |
|
717 | 753 | } |
718 | 754 | // have we already fetched framed content? |
719 | - elseif(is_array($this->results)) |
|
720 | - $this->results[] = $results; |
|
755 | + elseif(is_array($this->results)) { |
|
756 | + $this->results[] = $results; |
|
757 | + } |
|
721 | 758 | // no framed content |
722 | - else |
|
723 | - $this->results = $results; |
|
759 | + else { |
|
760 | + $this->results = $results; |
|
761 | + } |
|
724 | 762 | |
725 | 763 | unlink("/tmp/$headerfile"); |
726 | 764 | |
@@ -736,8 +774,9 @@ discard block |
||
736 | 774 | { |
737 | 775 | for($x=0; $x<count($this->headers); $x++) |
738 | 776 | { |
739 | - if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) |
|
740 | - $this->cookies[$match[1]] = $match[2]; |
|
777 | + if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) { |
|
778 | + $this->cookies[$match[1]] = $match[2]; |
|
779 | + } |
|
741 | 780 | } |
742 | 781 | } |
743 | 782 | |
@@ -773,8 +812,7 @@ discard block |
||
773 | 812 | $this->_isproxy = true; |
774 | 813 | $host = $this->proxy_host; |
775 | 814 | $port = $this->proxy_port; |
776 | - } |
|
777 | - else |
|
815 | + } else |
|
778 | 816 | { |
779 | 817 | $host = $this->host; |
780 | 818 | $port = $this->port; |
@@ -793,8 +831,7 @@ discard block |
||
793 | 831 | // socket connection succeeded |
794 | 832 | |
795 | 833 | return true; |
796 | - } |
|
797 | - else |
|
834 | + } else |
|
798 | 835 | { |
799 | 836 | // socket connection failed |
800 | 837 | $this->status = $errno; |
@@ -837,8 +874,9 @@ discard block |
||
837 | 874 | settype($formvars, "array"); |
838 | 875 | settype($formfiles, "array"); |
839 | 876 | |
840 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
841 | - return; |
|
877 | + if (count($formvars) == 0 && count($formfiles) == 0) { |
|
878 | + return; |
|
879 | + } |
|
842 | 880 | |
843 | 881 | switch ($this->_submit_type) { |
844 | 882 | case "application/x-www-form-urlencoded": |
@@ -848,8 +886,9 @@ discard block |
||
848 | 886 | while (list($cur_key, $cur_val) = each($val)) { |
849 | 887 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
850 | 888 | } |
851 | - } else |
|
852 | - $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
889 | + } else { |
|
890 | + $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
891 | + } |
|
853 | 892 | } |
854 | 893 | break; |
855 | 894 | |
@@ -875,7 +914,9 @@ discard block |
||
875 | 914 | while (list($field_name, $file_names) = each($formfiles)) { |
876 | 915 | settype($file_names, "array"); |
877 | 916 | while (list(, $file_name) = each($file_names)) { |
878 | - if (!is_readable($file_name)) continue; |
|
917 | + if (!is_readable($file_name)) { |
|
918 | + continue; |
|
919 | + } |
|
879 | 920 | |
880 | 921 | $fp = fopen($file_name, "r"); |
881 | 922 | $file_content = fread($fp, filesize($file_name)); |
@@ -366,6 +366,9 @@ discard block |
||
366 | 366 | Output: $expandedLinks the expanded links |
367 | 367 | \*======================================================================*/ |
368 | 368 | |
369 | + /** |
|
370 | + * @param string $links |
|
371 | + */ |
|
369 | 372 | private function _expandlinks($links,$URI) |
370 | 373 | { |
371 | 374 | |
@@ -400,6 +403,9 @@ discard block |
||
400 | 403 | Output: |
401 | 404 | \*======================================================================*/ |
402 | 405 | |
406 | + /** |
|
407 | + * @param string $http_method |
|
408 | + */ |
|
403 | 409 | private function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
404 | 410 | { |
405 | 411 | if($this->passcookies && $this->_redirectaddr) |
@@ -583,6 +589,9 @@ discard block |
||
583 | 589 | Output: |
584 | 590 | \*======================================================================*/ |
585 | 591 | |
592 | + /** |
|
593 | + * @param string $http_method |
|
594 | + */ |
|
586 | 595 | private function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
587 | 596 | { |
588 | 597 | if($this->passcookies && $this->_redirectaddr) |
@@ -766,6 +775,9 @@ discard block |
||
766 | 775 | Input: $fp file pointer |
767 | 776 | \*======================================================================*/ |
768 | 777 | |
778 | + /** |
|
779 | + * @param boolean $fp |
|
780 | + */ |
|
769 | 781 | private function _connect(&$fp) |
770 | 782 | { |
771 | 783 | if(!empty($this->proxy_host) && !empty($this->proxy_port)) |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | define('RSS', 'RSS'); |
25 | 25 | define('ATOM', 'Atom'); |
26 | 26 | |
27 | -require_once (MAGPIE_DIR . 'rss_utils.inc'); |
|
27 | +require_once (MAGPIE_DIR.'rss_utils.inc'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Hybrid parser, and object, takes RSS as a string and returns a simple object. |
@@ -36,16 +36,16 @@ discard block |
||
36 | 36 | class MagpieRSS { |
37 | 37 | public $parser; |
38 | 38 | |
39 | - public $current_item = array(); // item currently being parsed |
|
40 | - public $items = array(); // collection of parsed items |
|
41 | - public $channel = array(); // hash of channel fields |
|
39 | + public $current_item = array(); // item currently being parsed |
|
40 | + public $items = array(); // collection of parsed items |
|
41 | + public $channel = array(); // hash of channel fields |
|
42 | 42 | public $textinput = array(); |
43 | 43 | public $image = array(); |
44 | 44 | public $feed_type; |
45 | 45 | public $feed_version; |
46 | - public $encoding = ''; // output encoding of parsed rss |
|
46 | + public $encoding = ''; // output encoding of parsed rss |
|
47 | 47 | |
48 | - private $_source_encoding = ''; // only set if we have to parse xml prolog |
|
48 | + private $_source_encoding = ''; // only set if we have to parse xml prolog |
|
49 | 49 | |
50 | 50 | public $ERROR = ""; |
51 | 51 | public $WARNING = ""; |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | * source encoding. (caveat emptor) |
94 | 94 | * |
95 | 95 | */ |
96 | - public function MagpieRSS ($source, $output_encoding='ISO-8859-1', |
|
97 | - $input_encoding=null, $detect_encoding=true) |
|
96 | + public function MagpieRSS($source, $output_encoding = 'ISO-8859-1', |
|
97 | + $input_encoding = null, $detect_encoding = true) |
|
98 | 98 | { |
99 | 99 | # if PHP xml isn't compiled in, die |
100 | 100 | # |
101 | 101 | if (!function_exists('xml_parser_create')) { |
102 | - $this->error( "Failed to load PHP's XML Extension. " . |
|
102 | + $this->error("Failed to load PHP's XML Extension. ". |
|
103 | 103 | "http://www.php.net/manual/en/ref.xml.php", |
104 | - E_USER_ERROR ); |
|
104 | + E_USER_ERROR); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | list($parser, $source) = $this->create_parser($source, |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | |
110 | 110 | |
111 | 111 | if (!is_resource($parser)) { |
112 | - $this->error( "Failed to create an instance of PHP's XML parser. " . |
|
112 | + $this->error("Failed to create an instance of PHP's XML parser. ". |
|
113 | 113 | "http://www.php.net/manual/en/ref.xml.php", |
114 | - E_USER_ERROR ); |
|
114 | + E_USER_ERROR); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -120,27 +120,27 @@ discard block |
||
120 | 120 | # pass in parser, and a reference to this object |
121 | 121 | # setup handlers |
122 | 122 | # |
123 | - xml_set_object( $this->parser, $this ); |
|
123 | + xml_set_object($this->parser, $this); |
|
124 | 124 | xml_set_element_handler($this->parser, |
125 | - 'feed_start_element', 'feed_end_element' ); |
|
125 | + 'feed_start_element', 'feed_end_element'); |
|
126 | 126 | |
127 | - xml_set_character_data_handler( $this->parser, 'feed_cdata' ); |
|
127 | + xml_set_character_data_handler($this->parser, 'feed_cdata'); |
|
128 | 128 | |
129 | - $status = xml_parse( $this->parser, $source ); |
|
129 | + $status = xml_parse($this->parser, $source); |
|
130 | 130 | |
131 | - if (! $status ) { |
|
132 | - $errorcode = xml_get_error_code( $this->parser ); |
|
133 | - if ( $errorcode != XML_ERROR_NONE ) { |
|
134 | - $xml_error = xml_error_string( $errorcode ); |
|
131 | + if (!$status) { |
|
132 | + $errorcode = xml_get_error_code($this->parser); |
|
133 | + if ($errorcode != XML_ERROR_NONE) { |
|
134 | + $xml_error = xml_error_string($errorcode); |
|
135 | 135 | $error_line = xml_get_current_line_number($this->parser); |
136 | 136 | $error_col = xml_get_current_column_number($this->parser); |
137 | 137 | $errormsg = "$xml_error at line $error_line, column $error_col"; |
138 | 138 | |
139 | - $this->error( $errormsg ); |
|
139 | + $this->error($errormsg); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - xml_parser_free( $this->parser ); |
|
143 | + xml_parser_free($this->parser); |
|
144 | 144 | |
145 | 145 | $this->normalize(); |
146 | 146 | } |
@@ -151,26 +151,26 @@ discard block |
||
151 | 151 | |
152 | 152 | // check for a namespace, and split if found |
153 | 153 | $ns = false; |
154 | - if ( strpos( $element, ':' ) ) { |
|
155 | - list($ns, $el) = split( ':', $element, 2); |
|
154 | + if (strpos($element, ':')) { |
|
155 | + list($ns, $el) = split(':', $element, 2); |
|
156 | 156 | } |
157 | - if ( $ns and $ns != 'rdf' ) { |
|
157 | + if ($ns and $ns != 'rdf') { |
|
158 | 158 | $this->current_namespace = $ns; |
159 | 159 | } |
160 | 160 | |
161 | 161 | # if feed type isn't set, then this is first element of feed |
162 | 162 | # identify feed from root element |
163 | 163 | # |
164 | - if (!isset($this->feed_type) ) { |
|
165 | - if ( $el == 'rdf' ) { |
|
164 | + if (!isset($this->feed_type)) { |
|
165 | + if ($el == 'rdf') { |
|
166 | 166 | $this->feed_type = RSS; |
167 | 167 | $this->feed_version = '1.0'; |
168 | 168 | } |
169 | - elseif ( $el == 'rss' ) { |
|
169 | + elseif ($el == 'rss') { |
|
170 | 170 | $this->feed_type = RSS; |
171 | 171 | $this->feed_version = $attrs['version']; |
172 | 172 | } |
173 | - elseif ( $el == 'feed' ) { |
|
173 | + elseif ($el == 'feed') { |
|
174 | 174 | $this->feed_type = ATOM; |
175 | 175 | $this->feed_version = $attrs['version']; |
176 | 176 | $this->inchannel = true; |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | return; |
179 | 179 | } |
180 | 180 | |
181 | - if ( $el == 'channel' ) |
|
181 | + if ($el == 'channel') |
|
182 | 182 | { |
183 | 183 | $this->inchannel = true; |
184 | 184 | } |
185 | - elseif ($el == 'item' or $el == 'entry' ) |
|
185 | + elseif ($el == 'item' or $el == 'entry') |
|
186 | 186 | { |
187 | 187 | $this->initem = true; |
188 | - if ( isset($attrs['rdf:about']) ) { |
|
188 | + if (isset($attrs['rdf:about'])) { |
|
189 | 189 | $this->current_item['about'] = $attrs['rdf:about']; |
190 | 190 | } |
191 | 191 | } |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | # handle atom content constructs |
212 | - elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
212 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
213 | 213 | { |
214 | 214 | // avoid clashing w/ RSS mod_content |
215 | - if ($el == 'content' ) { |
|
215 | + if ($el == 'content') { |
|
216 | 216 | $el = 'atom_content'; |
217 | 217 | } |
218 | 218 | |
@@ -222,31 +222,31 @@ discard block |
||
222 | 222 | } |
223 | 223 | |
224 | 224 | // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
225 | - elseif ($this->feed_type == ATOM and $this->incontent ) |
|
225 | + elseif ($this->feed_type == ATOM and $this->incontent) |
|
226 | 226 | { |
227 | 227 | // if tags are inlined, then flatten |
228 | 228 | $attrs_str = join(' ', |
229 | 229 | array_map('map_attrs', |
230 | 230 | array_keys($attrs), |
231 | - array_values($attrs) ) ); |
|
231 | + array_values($attrs))); |
|
232 | 232 | |
233 | - $this->append_content( "<$element $attrs_str>" ); |
|
233 | + $this->append_content("<$element $attrs_str>"); |
|
234 | 234 | |
235 | - array_unshift( $this->stack, $el ); |
|
235 | + array_unshift($this->stack, $el); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | // Atom support many links per containging element. |
239 | 239 | // Magpie treats link elements of type rel='alternate' |
240 | 240 | // as being equivalent to RSS's simple link element. |
241 | 241 | // |
242 | - elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
242 | + elseif ($this->feed_type == ATOM and $el == 'link') |
|
243 | 243 | { |
244 | - if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
244 | + if (isset($attrs['rel']) and $attrs['rel'] == 'alternate') |
|
245 | 245 | { |
246 | 246 | $link_el = 'link'; |
247 | 247 | } |
248 | 248 | else { |
249 | - $link_el = 'link_' . $attrs['rel']; |
|
249 | + $link_el = 'link_'.$attrs['rel']; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | $this->append($link_el, $attrs['href']); |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | |
260 | 260 | |
261 | 261 | |
262 | - public function feed_cdata ($p, $text) { |
|
262 | + public function feed_cdata($p, $text) { |
|
263 | 263 | if ($this->feed_type == ATOM and $this->incontent) |
264 | 264 | { |
265 | - $this->append_content( $text ); |
|
265 | + $this->append_content($text); |
|
266 | 266 | } |
267 | 267 | else { |
268 | 268 | $current_el = join('_', array_reverse($this->stack)); |
@@ -270,35 +270,35 @@ discard block |
||
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | - public function feed_end_element ($p, $el) { |
|
273 | + public function feed_end_element($p, $el) { |
|
274 | 274 | $el = strtolower($el); |
275 | 275 | |
276 | - if ( $el == 'item' or $el == 'entry' ) |
|
276 | + if ($el == 'item' or $el == 'entry') |
|
277 | 277 | { |
278 | 278 | $this->items[] = $this->current_item; |
279 | 279 | $this->current_item = array(); |
280 | 280 | $this->initem = false; |
281 | 281 | } |
282 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
282 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput') |
|
283 | 283 | { |
284 | 284 | $this->intextinput = false; |
285 | 285 | } |
286 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
286 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image') |
|
287 | 287 | { |
288 | 288 | $this->inimage = false; |
289 | 289 | } |
290 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
290 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
291 | 291 | { |
292 | 292 | $this->incontent = false; |
293 | 293 | } |
294 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
294 | + elseif ($el == 'channel' or $el == 'feed') |
|
295 | 295 | { |
296 | 296 | $this->inchannel = false; |
297 | 297 | } |
298 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
298 | + elseif ($this->feed_type == ATOM and $this->incontent) { |
|
299 | 299 | // balance tags properly |
300 | 300 | // note: i don't think this is actually neccessary |
301 | - if ( $this->stack[0] == $el ) |
|
301 | + if ($this->stack[0] == $el) |
|
302 | 302 | { |
303 | 303 | $this->append_content("</$el>"); |
304 | 304 | } |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | $this->append_content("<$el />"); |
307 | 307 | } |
308 | 308 | |
309 | - array_shift( $this->stack ); |
|
309 | + array_shift($this->stack); |
|
310 | 310 | } |
311 | 311 | else { |
312 | - array_shift( $this->stack ); |
|
312 | + array_shift($this->stack); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $this->current_namespace = false; |
316 | 316 | } |
317 | 317 | |
318 | - public function concat (&$str1, $str2="") { |
|
319 | - if (!isset($str1) ) { |
|
320 | - $str1=""; |
|
318 | + public function concat(&$str1, $str2 = "") { |
|
319 | + if (!isset($str1)) { |
|
320 | + $str1 = ""; |
|
321 | 321 | } |
322 | 322 | $str1 .= $str2; |
323 | 323 | } |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | |
326 | 326 | |
327 | 327 | public function append_content($text) { |
328 | - if ( $this->initem ) { |
|
329 | - $this->concat( $this->current_item[ $this->incontent ], $text ); |
|
328 | + if ($this->initem) { |
|
329 | + $this->concat($this->current_item[$this->incontent], $text); |
|
330 | 330 | } |
331 | - elseif ( $this->inchannel ) { |
|
332 | - $this->concat( $this->channel[ $this->incontent ], $text ); |
|
331 | + elseif ($this->inchannel) { |
|
332 | + $this->concat($this->channel[$this->incontent], $text); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
@@ -338,59 +338,59 @@ discard block |
||
338 | 338 | if (!$el) { |
339 | 339 | return; |
340 | 340 | } |
341 | - if ( $this->current_namespace ) |
|
341 | + if ($this->current_namespace) |
|
342 | 342 | { |
343 | - if ( $this->initem ) { |
|
343 | + if ($this->initem) { |
|
344 | 344 | $this->concat( |
345 | - $this->current_item[ $this->current_namespace ][ $el ], $text); |
|
345 | + $this->current_item[$this->current_namespace][$el], $text); |
|
346 | 346 | } |
347 | 347 | elseif ($this->inchannel) { |
348 | 348 | $this->concat( |
349 | - $this->channel[ $this->current_namespace][ $el ], $text ); |
|
349 | + $this->channel[$this->current_namespace][$el], $text ); |
|
350 | 350 | } |
351 | 351 | elseif ($this->intextinput) { |
352 | 352 | $this->concat( |
353 | - $this->textinput[ $this->current_namespace][ $el ], $text ); |
|
353 | + $this->textinput[$this->current_namespace][$el], $text ); |
|
354 | 354 | } |
355 | 355 | elseif ($this->inimage) { |
356 | 356 | $this->concat( |
357 | - $this->image[ $this->current_namespace ][ $el ], $text ); |
|
357 | + $this->image[$this->current_namespace][$el], $text ); |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 | else { |
361 | - if ( $this->initem ) { |
|
361 | + if ($this->initem) { |
|
362 | 362 | $this->concat( |
363 | - $this->current_item[ $el ], $text); |
|
363 | + $this->current_item[$el], $text); |
|
364 | 364 | } |
365 | 365 | elseif ($this->intextinput) { |
366 | 366 | $this->concat( |
367 | - $this->textinput[ $el ], $text ); |
|
367 | + $this->textinput[$el], $text ); |
|
368 | 368 | } |
369 | 369 | elseif ($this->inimage) { |
370 | 370 | $this->concat( |
371 | - $this->image[ $el ], $text ); |
|
371 | + $this->image[$el], $text ); |
|
372 | 372 | } |
373 | 373 | elseif ($this->inchannel) { |
374 | 374 | $this->concat( |
375 | - $this->channel[ $el ], $text ); |
|
375 | + $this->channel[$el], $text ); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | - public function normalize () { |
|
381 | + public function normalize() { |
|
382 | 382 | // if atom populate rss fields |
383 | - if ( $this->is_atom() ) { |
|
383 | + if ($this->is_atom()) { |
|
384 | 384 | $this->channel['description'] = $this->channel['tagline']; |
385 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
385 | + for ($i = 0; $i < count($this->items); $i++) { |
|
386 | 386 | $item = $this->items[$i]; |
387 | - if ( isset($item['summary']) ) |
|
387 | + if (isset($item['summary'])) |
|
388 | 388 | $item['description'] = $item['summary']; |
389 | - if ( isset($item['atom_content'])) |
|
389 | + if (isset($item['atom_content'])) |
|
390 | 390 | $item['content']['encoded'] = $item['atom_content']; |
391 | 391 | |
392 | - $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified']; |
|
393 | - if ( $atom_date ) { |
|
392 | + $atom_date = (isset($item['issued'])) ? $item['issued'] : $item['modified']; |
|
393 | + if ($atom_date) { |
|
394 | 394 | $epoch = @parse_w3cdtf($atom_date); |
395 | 395 | if ($epoch and $epoch > 0) { |
396 | 396 | $item['date_timestamp'] = $epoch; |
@@ -400,22 +400,22 @@ discard block |
||
400 | 400 | $this->items[$i] = $item; |
401 | 401 | } |
402 | 402 | } |
403 | - elseif ( $this->is_rss() ) { |
|
403 | + elseif ($this->is_rss()) { |
|
404 | 404 | $this->channel['tagline'] = $this->channel['description']; |
405 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
405 | + for ($i = 0; $i < count($this->items); $i++) { |
|
406 | 406 | $item = $this->items[$i]; |
407 | - if ( isset($item['description'])) |
|
407 | + if (isset($item['description'])) |
|
408 | 408 | $item['summary'] = $item['description']; |
409 | - if ( isset($item['content']['encoded'] ) ) |
|
409 | + if (isset($item['content']['encoded'])) |
|
410 | 410 | $item['atom_content'] = $item['content']['encoded']; |
411 | 411 | |
412 | - if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
|
412 | + if ($this->is_rss() == '1.0' and isset($item['dc']['date'])) { |
|
413 | 413 | $epoch = @parse_w3cdtf($item['dc']['date']); |
414 | 414 | if ($epoch and $epoch > 0) { |
415 | 415 | $item['date_timestamp'] = $epoch; |
416 | 416 | } |
417 | 417 | } |
418 | - elseif ( isset($item['pubdate']) ) { |
|
418 | + elseif (isset($item['pubdate'])) { |
|
419 | 419 | $epoch = @strtotime($item['pubdate']); |
420 | 420 | if ($epoch > 0) { |
421 | 421 | $item['date_timestamp'] = $epoch; |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | } |
429 | 429 | |
430 | 430 | |
431 | - public function is_rss () { |
|
432 | - if ( $this->feed_type == RSS ) { |
|
431 | + public function is_rss() { |
|
432 | + if ($this->feed_type == RSS) { |
|
433 | 433 | return $this->feed_version; |
434 | 434 | } |
435 | 435 | else { |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | public function is_atom() { |
441 | - if ( $this->feed_type == ATOM ) { |
|
441 | + if ($this->feed_type == ATOM) { |
|
442 | 442 | return $this->feed_version; |
443 | 443 | } |
444 | 444 | else { |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * |
452 | 452 | */ |
453 | 453 | public function create_parser($source, $out_enc, $in_enc, $detect) { |
454 | - if ( substr(phpversion(),0,1) == 5) { |
|
454 | + if (substr(phpversion(), 0, 1) == 5) { |
|
455 | 455 | $parser = $this->php5_create_parser($in_enc, $detect); |
456 | 456 | } |
457 | 457 | else { |
@@ -476,7 +476,7 @@ discard block |
||
476 | 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 | - if(!$detect && $in_enc) { |
|
479 | + if (!$detect && $in_enc) { |
|
480 | 480 | return xml_parser_create($in_enc); |
481 | 481 | } |
482 | 482 | else { |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | * |
501 | 501 | */ |
502 | 502 | public function php4_create_parser($source, $in_enc, $detect) { |
503 | - if ( !$detect ) { |
|
503 | + if (!$detect) { |
|
504 | 504 | return array(xml_parser_create($in_enc), $source); |
505 | 505 | } |
506 | 506 | |
@@ -524,8 +524,8 @@ discard block |
||
524 | 524 | // cast the XML to a known encoding |
525 | 525 | // @see http://php.net/iconv |
526 | 526 | |
527 | - if (function_exists('iconv')) { |
|
528 | - $encoded_source = iconv($in_enc,'UTF-8', $source); |
|
527 | + if (function_exists('iconv')) { |
|
528 | + $encoded_source = iconv($in_enc, 'UTF-8', $source); |
|
529 | 529 | if ($encoded_source) { |
530 | 530 | return array(xml_parser_create('UTF-8'), $encoded_source); |
531 | 531 | } |
@@ -533,15 +533,15 @@ discard block |
||
533 | 533 | |
534 | 534 | // iconv didn't work, try mb_convert_encoding |
535 | 535 | // @see http://php.net/mbstring |
536 | - if(function_exists('mb_convert_encoding')) { |
|
537 | - $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc ); |
|
536 | + if (function_exists('mb_convert_encoding')) { |
|
537 | + $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc); |
|
538 | 538 | if ($encoded_source) { |
539 | 539 | return array(xml_parser_create('UTF-8'), $encoded_source); |
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | 543 | // else |
544 | - $this->error("Feed is in an unsupported character encoding. ($in_enc) " . |
|
544 | + $this->error("Feed is in an unsupported character encoding. ($in_enc) ". |
|
545 | 545 | "You may see strange artifacts, and mangled characters.", |
546 | 546 | E_USER_NOTICE); |
547 | 547 | |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | |
551 | 551 | public function known_encoding($enc) { |
552 | 552 | $enc = strtoupper($enc); |
553 | - if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
|
553 | + if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
554 | 554 | return $enc; |
555 | 555 | } |
556 | 556 | else { |
@@ -558,20 +558,20 @@ discard block |
||
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - public function error ($errormsg, $lvl=E_USER_WARNING) { |
|
561 | + public function error($errormsg, $lvl = E_USER_WARNING) { |
|
562 | 562 | // append PHP's error message if track_errors enabled |
563 | - if ( isset($php_errormsg) ) { |
|
563 | + if (isset($php_errormsg)) { |
|
564 | 564 | $errormsg .= " ($php_errormsg)"; |
565 | 565 | } |
566 | - if ( MAGPIE_DEBUG ) { |
|
567 | - trigger_error( $errormsg, $lvl); |
|
566 | + if (MAGPIE_DEBUG) { |
|
567 | + trigger_error($errormsg, $lvl); |
|
568 | 568 | } |
569 | 569 | else { |
570 | - error_log( $errormsg, 0); |
|
570 | + error_log($errormsg, 0); |
|
571 | 571 | } |
572 | 572 | |
573 | - $notices = E_USER_NOTICE|E_NOTICE; |
|
574 | - if ( $lvl&$notices ) { |
|
573 | + $notices = E_USER_NOTICE | E_NOTICE; |
|
574 | + if ($lvl & $notices) { |
|
575 | 575 | $this->WARNING = $errormsg; |
576 | 576 | } else { |
577 | 577 | $this->ERROR = $errormsg; |
@@ -589,15 +589,15 @@ 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; |
|
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 | 601 | } |
602 | 602 | return $output; |
603 | 603 | } |
@@ -165,12 +165,10 @@ discard block |
||
165 | 165 | if ( $el == 'rdf' ) { |
166 | 166 | $this->feed_type = RSS; |
167 | 167 | $this->feed_version = '1.0'; |
168 | - } |
|
169 | - elseif ( $el == 'rss' ) { |
|
168 | + } elseif ( $el == 'rss' ) { |
|
170 | 169 | $this->feed_type = RSS; |
171 | 170 | $this->feed_version = $attrs['version']; |
172 | - } |
|
173 | - elseif ( $el == 'feed' ) { |
|
171 | + } elseif ( $el == 'feed' ) { |
|
174 | 172 | $this->feed_type = ATOM; |
175 | 173 | $this->feed_version = $attrs['version']; |
176 | 174 | $this->inchannel = true; |
@@ -181,8 +179,7 @@ discard block |
||
181 | 179 | if ( $el == 'channel' ) |
182 | 180 | { |
183 | 181 | $this->inchannel = true; |
184 | - } |
|
185 | - elseif ($el == 'item' or $el == 'entry' ) |
|
182 | + } elseif ($el == 'item' or $el == 'entry' ) |
|
186 | 183 | { |
187 | 184 | $this->initem = true; |
188 | 185 | if ( isset($attrs['rdf:about']) ) { |
@@ -198,9 +195,7 @@ discard block |
||
198 | 195 | $el == 'textinput' ) |
199 | 196 | { |
200 | 197 | $this->intextinput = true; |
201 | - } |
|
202 | - |
|
203 | - elseif ( |
|
198 | + } elseif ( |
|
204 | 199 | $this->feed_type == RSS and |
205 | 200 | $this->current_namespace == '' and |
206 | 201 | $el == 'image' ) |
@@ -244,8 +239,7 @@ discard block |
||
244 | 239 | if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
245 | 240 | { |
246 | 241 | $link_el = 'link'; |
247 | - } |
|
248 | - else { |
|
242 | + } else { |
|
249 | 243 | $link_el = 'link_' . $attrs['rel']; |
250 | 244 | } |
251 | 245 | |
@@ -263,8 +257,7 @@ discard block |
||
263 | 257 | if ($this->feed_type == ATOM and $this->incontent) |
264 | 258 | { |
265 | 259 | $this->append_content( $text ); |
266 | - } |
|
267 | - else { |
|
260 | + } else { |
|
268 | 261 | $current_el = join('_', array_reverse($this->stack)); |
269 | 262 | $this->append($current_el, $text); |
270 | 263 | } |
@@ -278,37 +271,30 @@ discard block |
||
278 | 271 | $this->items[] = $this->current_item; |
279 | 272 | $this->current_item = array(); |
280 | 273 | $this->initem = false; |
281 | - } |
|
282 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
274 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
283 | 275 | { |
284 | 276 | $this->intextinput = false; |
285 | - } |
|
286 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
277 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
287 | 278 | { |
288 | 279 | $this->inimage = false; |
289 | - } |
|
290 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
280 | + } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
291 | 281 | { |
292 | 282 | $this->incontent = false; |
293 | - } |
|
294 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
283 | + } elseif ($el == 'channel' or $el == 'feed' ) |
|
295 | 284 | { |
296 | 285 | $this->inchannel = false; |
297 | - } |
|
298 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
286 | + } elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
299 | 287 | // balance tags properly |
300 | 288 | // note: i don't think this is actually neccessary |
301 | 289 | if ( $this->stack[0] == $el ) |
302 | 290 | { |
303 | 291 | $this->append_content("</$el>"); |
304 | - } |
|
305 | - else { |
|
292 | + } else { |
|
306 | 293 | $this->append_content("<$el />"); |
307 | 294 | } |
308 | 295 | |
309 | 296 | array_shift( $this->stack ); |
310 | - } |
|
311 | - else { |
|
297 | + } else { |
|
312 | 298 | array_shift( $this->stack ); |
313 | 299 | } |
314 | 300 | |
@@ -327,8 +313,7 @@ discard block |
||
327 | 313 | public function append_content($text) { |
328 | 314 | if ( $this->initem ) { |
329 | 315 | $this->concat( $this->current_item[ $this->incontent ], $text ); |
330 | - } |
|
331 | - elseif ( $this->inchannel ) { |
|
316 | + } elseif ( $this->inchannel ) { |
|
332 | 317 | $this->concat( $this->channel[ $this->incontent ], $text ); |
333 | 318 | } |
334 | 319 | } |
@@ -343,34 +328,27 @@ discard block |
||
343 | 328 | if ( $this->initem ) { |
344 | 329 | $this->concat( |
345 | 330 | $this->current_item[ $this->current_namespace ][ $el ], $text); |
346 | - } |
|
347 | - elseif ($this->inchannel) { |
|
331 | + } elseif ($this->inchannel) { |
|
348 | 332 | $this->concat( |
349 | 333 | $this->channel[ $this->current_namespace][ $el ], $text ); |
350 | - } |
|
351 | - elseif ($this->intextinput) { |
|
334 | + } elseif ($this->intextinput) { |
|
352 | 335 | $this->concat( |
353 | 336 | $this->textinput[ $this->current_namespace][ $el ], $text ); |
354 | - } |
|
355 | - elseif ($this->inimage) { |
|
337 | + } elseif ($this->inimage) { |
|
356 | 338 | $this->concat( |
357 | 339 | $this->image[ $this->current_namespace ][ $el ], $text ); |
358 | 340 | } |
359 | - } |
|
360 | - else { |
|
341 | + } else { |
|
361 | 342 | if ( $this->initem ) { |
362 | 343 | $this->concat( |
363 | 344 | $this->current_item[ $el ], $text); |
364 | - } |
|
365 | - elseif ($this->intextinput) { |
|
345 | + } elseif ($this->intextinput) { |
|
366 | 346 | $this->concat( |
367 | 347 | $this->textinput[ $el ], $text ); |
368 | - } |
|
369 | - elseif ($this->inimage) { |
|
348 | + } elseif ($this->inimage) { |
|
370 | 349 | $this->concat( |
371 | 350 | $this->image[ $el ], $text ); |
372 | - } |
|
373 | - elseif ($this->inchannel) { |
|
351 | + } elseif ($this->inchannel) { |
|
374 | 352 | $this->concat( |
375 | 353 | $this->channel[ $el ], $text ); |
376 | 354 | } |
@@ -384,10 +362,12 @@ discard block |
||
384 | 362 | $this->channel['description'] = $this->channel['tagline']; |
385 | 363 | for ( $i = 0; $i < count($this->items); $i++) { |
386 | 364 | $item = $this->items[$i]; |
387 | - if ( isset($item['summary']) ) |
|
388 | - $item['description'] = $item['summary']; |
|
389 | - if ( isset($item['atom_content'])) |
|
390 | - $item['content']['encoded'] = $item['atom_content']; |
|
365 | + if ( isset($item['summary']) ) { |
|
366 | + $item['description'] = $item['summary']; |
|
367 | + } |
|
368 | + if ( isset($item['atom_content'])) { |
|
369 | + $item['content']['encoded'] = $item['atom_content']; |
|
370 | + } |
|
391 | 371 | |
392 | 372 | $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified']; |
393 | 373 | if ( $atom_date ) { |
@@ -399,23 +379,23 @@ discard block |
||
399 | 379 | |
400 | 380 | $this->items[$i] = $item; |
401 | 381 | } |
402 | - } |
|
403 | - elseif ( $this->is_rss() ) { |
|
382 | + } elseif ( $this->is_rss() ) { |
|
404 | 383 | $this->channel['tagline'] = $this->channel['description']; |
405 | 384 | for ( $i = 0; $i < count($this->items); $i++) { |
406 | 385 | $item = $this->items[$i]; |
407 | - if ( isset($item['description'])) |
|
408 | - $item['summary'] = $item['description']; |
|
409 | - if ( isset($item['content']['encoded'] ) ) |
|
410 | - $item['atom_content'] = $item['content']['encoded']; |
|
386 | + if ( isset($item['description'])) { |
|
387 | + $item['summary'] = $item['description']; |
|
388 | + } |
|
389 | + if ( isset($item['content']['encoded'] ) ) { |
|
390 | + $item['atom_content'] = $item['content']['encoded']; |
|
391 | + } |
|
411 | 392 | |
412 | 393 | if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { |
413 | 394 | $epoch = @parse_w3cdtf($item['dc']['date']); |
414 | 395 | if ($epoch and $epoch > 0) { |
415 | 396 | $item['date_timestamp'] = $epoch; |
416 | 397 | } |
417 | - } |
|
418 | - elseif ( isset($item['pubdate']) ) { |
|
398 | + } elseif ( isset($item['pubdate']) ) { |
|
419 | 399 | $epoch = @strtotime($item['pubdate']); |
420 | 400 | if ($epoch > 0) { |
421 | 401 | $item['date_timestamp'] = $epoch; |
@@ -431,8 +411,7 @@ discard block |
||
431 | 411 | public function is_rss () { |
432 | 412 | if ( $this->feed_type == RSS ) { |
433 | 413 | return $this->feed_version; |
434 | - } |
|
435 | - else { |
|
414 | + } else { |
|
436 | 415 | return false; |
437 | 416 | } |
438 | 417 | } |
@@ -440,8 +419,7 @@ discard block |
||
440 | 419 | public function is_atom() { |
441 | 420 | if ( $this->feed_type == ATOM ) { |
442 | 421 | return $this->feed_version; |
443 | - } |
|
444 | - else { |
|
422 | + } else { |
|
445 | 423 | return false; |
446 | 424 | } |
447 | 425 | } |
@@ -453,8 +431,7 @@ discard block |
||
453 | 431 | public function create_parser($source, $out_enc, $in_enc, $detect) { |
454 | 432 | if ( substr(phpversion(),0,1) == 5) { |
455 | 433 | $parser = $this->php5_create_parser($in_enc, $detect); |
456 | - } |
|
457 | - else { |
|
434 | + } else { |
|
458 | 435 | list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
459 | 436 | } |
460 | 437 | if ($out_enc) { |
@@ -478,8 +455,7 @@ discard block |
||
478 | 455 | // by default php5 does a fine job of detecting input encodings |
479 | 456 | if(!$detect && $in_enc) { |
480 | 457 | return xml_parser_create($in_enc); |
481 | - } |
|
482 | - else { |
|
458 | + } else { |
|
483 | 459 | return xml_parser_create(''); |
484 | 460 | } |
485 | 461 | } |
@@ -508,8 +484,7 @@ discard block |
||
508 | 484 | if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
509 | 485 | $in_enc = strtoupper($m[1]); |
510 | 486 | $this->source_encoding = $in_enc; |
511 | - } |
|
512 | - else { |
|
487 | + } else { |
|
513 | 488 | $in_enc = 'UTF-8'; |
514 | 489 | } |
515 | 490 | } |
@@ -552,8 +527,7 @@ discard block |
||
552 | 527 | $enc = strtoupper($enc); |
553 | 528 | if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { |
554 | 529 | return $enc; |
555 | - } |
|
556 | - else { |
|
530 | + } else { |
|
557 | 531 | return false; |
558 | 532 | } |
559 | 533 | } |
@@ -565,8 +539,7 @@ discard block |
||
565 | 539 | } |
566 | 540 | if ( MAGPIE_DEBUG ) { |
567 | 541 | trigger_error( $errormsg, $lvl); |
568 | - } |
|
569 | - else { |
|
542 | + } else { |
|
570 | 543 | error_log( $errormsg, 0); |
571 | 544 | } |
572 | 545 | |
@@ -594,8 +567,11 @@ discard block |
||
594 | 567 | |
595 | 568 | |
596 | 569 | function array_change_key_case($array,$case=CASE_LOWER) { |
597 | - if ($case=CASE_LOWER) $cmd=strtolower; |
|
598 | - elseif ($case=CASE_UPPER) $cmd=strtoupper; |
|
570 | + if ($case=CASE_LOWER) { |
|
571 | + $cmd=strtolower; |
|
572 | + } elseif ($case=CASE_UPPER) { |
|
573 | + $cmd=strtoupper; |
|
574 | + } |
|
599 | 575 | foreach($array as $key=>$value) { |
600 | 576 | $output[$cmd($key)]=$value; |
601 | 577 | } |
@@ -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 | } |
@@ -449,6 +449,10 @@ discard block |
||
449 | 449 | /** |
450 | 450 | * return XML parser, and possibly re-encoded source |
451 | 451 | * |
452 | + * @param string $source |
|
453 | + * @param string $out_enc |
|
454 | + * @param string|null $in_enc |
|
455 | + * @param boolean $detect |
|
452 | 456 | */ |
453 | 457 | public function create_parser($source, $out_enc, $in_enc, $detect) { |
454 | 458 | if ( substr(phpversion(),0,1) == 5) { |
@@ -558,6 +562,9 @@ discard block |
||
558 | 562 | } |
559 | 563 | } |
560 | 564 | |
565 | + /** |
|
566 | + * @param integer $lvl |
|
567 | + */ |
|
561 | 568 | public function error ($errormsg, $lvl=E_USER_WARNING) { |
562 | 569 | // append PHP's error message if track_errors enabled |
563 | 570 | if ( isset($php_errormsg) ) { |
@@ -593,6 +600,9 @@ discard block |
||
593 | 600 | define("CASE_LOWER",0); |
594 | 601 | |
595 | 602 | |
603 | + /** |
|
604 | + * @param integer $case |
|
605 | + */ |
|
596 | 606 | function array_change_key_case($array,$case=CASE_LOWER) { |
597 | 607 | if ($case=CASE_LOWER) $cmd=strtolower; |
598 | 608 | elseif ($case=CASE_UPPER) $cmd=strtoupper; |