Completed
Push — 1.11.x ( ca7787...41c0f2 )
by José
31:51
created
main/inc/lib/api.lib.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -41,19 +41,19 @@  discard block
 block discarded – undo
41 41
 define('PLATFORM_ADMIN', 11);
42 42
 define('SESSION_COURSE_COACH', 12);
43 43
 define('SESSION_GENERAL_COACH', 13);
44
-define('COURSE_STUDENT', 14);   //student subscribed in a course
45
-define('SESSION_STUDENT', 15);  //student subscribed in a session course
44
+define('COURSE_STUDENT', 14); //student subscribed in a course
45
+define('SESSION_STUDENT', 15); //student subscribed in a session course
46 46
 define('COURSE_TUTOR', 16); // student is tutor of a course (NOT in session)
47 47
 define('STUDENT_BOSS', 17); // student is boss
48 48
 define('INVITEE', 20);
49 49
 
50 50
 // Table of status
51
-$_status_list[COURSEMANAGER] = 'teacher';        // 1
52
-$_status_list[SESSIONADMIN] = 'session_admin';  // 3
53
-$_status_list[DRH] = 'drh';            // 4
54
-$_status_list[STUDENT] = 'user';           // 5
55
-$_status_list[ANONYMOUS] = 'anonymous';      // 6
56
-$_status_list[INVITEE] = 'invited';        // 20
51
+$_status_list[COURSEMANAGER] = 'teacher'; // 1
52
+$_status_list[SESSIONADMIN] = 'session_admin'; // 3
53
+$_status_list[DRH] = 'drh'; // 4
54
+$_status_list[STUDENT] = 'user'; // 5
55
+$_status_list[ANONYMOUS] = 'anonymous'; // 6
56
+$_status_list[INVITEE] = 'invited'; // 20
57 57
 
58 58
 // COURSE VISIBILITY CONSTANTS
59 59
 /** only visible for course admin */
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
 define('IS_WINDOWS_OS', api_is_windows_os());
268 268
 
269 269
 // Checks for installed optional php-extensions.
270
-define('INTL_INSTALLED', function_exists('intl_get_error_code'));   // intl extension (from PECL), it is installed by default as of PHP 5.3.0
271
-define('ICONV_INSTALLED', function_exists('iconv'));                // iconv extension, for PHP5 on Windows it is installed by default.
272
-define('MBSTRING_INSTALLED', function_exists('mb_strlen'));         // mbstring extension.
270
+define('INTL_INSTALLED', function_exists('intl_get_error_code')); // intl extension (from PECL), it is installed by default as of PHP 5.3.0
271
+define('ICONV_INSTALLED', function_exists('iconv')); // iconv extension, for PHP5 on Windows it is installed by default.
272
+define('MBSTRING_INSTALLED', function_exists('mb_strlen')); // mbstring extension.
273 273
 
274 274
 // Patterns for processing paths.                                   // Examples:
275
-define('REPEATED_SLASHES_PURIFIER', '/\/{2,}/');                    // $path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path);
276
-define('VALID_WEB_PATH', '/https?:\/\/[^\/]*(\/.*)?/i');            // $is_valid_path = preg_match(VALID_WEB_PATH, $path);
277
-define('VALID_WEB_SERVER_BASE', '/https?:\/\/[^\/]*/i');            // $new_path = preg_replace(VALID_WEB_SERVER_BASE, $new_base, $path);
275
+define('REPEATED_SLASHES_PURIFIER', '/\/{2,}/'); // $path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path);
276
+define('VALID_WEB_PATH', '/https?:\/\/[^\/]*(\/.*)?/i'); // $is_valid_path = preg_match(VALID_WEB_PATH, $path);
277
+define('VALID_WEB_SERVER_BASE', '/https?:\/\/[^\/]*/i'); // $new_path = preg_replace(VALID_WEB_SERVER_BASE, $new_base, $path);
278 278
 
279 279
 // Constants for api_get_path() and api_get_path_type(), etc. - registered path types.
280 280
 // basic (leaf elements)
@@ -363,19 +363,19 @@  discard block
 block discarded – undo
363 363
 define('LINK_HOTPOTATOES', 9);
364 364
 
365 365
 // Score display types constants
366
-define('SCORE_DIV', 1);    // X / Y
367
-define('SCORE_PERCENT', 2);    // XX %
368
-define('SCORE_DIV_PERCENT', 3);    // X / Y (XX %)
369
-define('SCORE_AVERAGE', 4);    // XX %
370
-define('SCORE_DECIMAL', 5);    // 0.50  (X/Y)
371
-define('SCORE_BAR', 6);    // Uses the Display::bar_progress function
372
-define('SCORE_SIMPLE', 7);    // X
373
-define('SCORE_IGNORE_SPLIT', 8);    //  ??
374
-define('SCORE_DIV_PERCENT_WITH_CUSTOM', 9);    // X / Y (XX %) - Good!
375
-define('SCORE_CUSTOM', 10);    // Good!
376
-define('SCORE_DIV_SIMPLE_WITH_CUSTOM', 11);    // X - Good!
377
-define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS', 12);    // X - Good!
378
-define('SCORE_ONLY_SCORE', 13);    // X - Good!
366
+define('SCORE_DIV', 1); // X / Y
367
+define('SCORE_PERCENT', 2); // XX %
368
+define('SCORE_DIV_PERCENT', 3); // X / Y (XX %)
369
+define('SCORE_AVERAGE', 4); // XX %
370
+define('SCORE_DECIMAL', 5); // 0.50  (X/Y)
371
+define('SCORE_BAR', 6); // Uses the Display::bar_progress function
372
+define('SCORE_SIMPLE', 7); // X
373
+define('SCORE_IGNORE_SPLIT', 8); //  ??
374
+define('SCORE_DIV_PERCENT_WITH_CUSTOM', 9); // X / Y (XX %) - Good!
375
+define('SCORE_CUSTOM', 10); // Good!
376
+define('SCORE_DIV_SIMPLE_WITH_CUSTOM', 11); // X - Good!
377
+define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS', 12); // X - Good!
378
+define('SCORE_ONLY_SCORE', 13); // X - Good!
379 379
 
380 380
 define('SCORE_BOTH', 1);
381 381
 define('SCORE_ONLY_DEFAULT', 2);
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 define('TIMELINE_STATUS_INACTIVE', '2');
559 559
 
560 560
 // Event email template class
561
-define('EVENT_EMAIL_TEMPLATE_ACTIVE',  1);
561
+define('EVENT_EMAIL_TEMPLATE_ACTIVE', 1);
562 562
 define('EVENT_EMAIL_TEMPLATE_INACTIVE', 0);
563 563
 
564 564
 // Course home
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
     $emptyConfigurationParam = false;
672 672
     if (empty($configuration)) {
673
-        $configuration = (array)$_configuration;
673
+        $configuration = (array) $_configuration;
674 674
         $emptyConfigurationParam = true;
675 675
     }
676 676
 
@@ -702,10 +702,10 @@  discard block
 block discarded – undo
702 702
                         && (($server_protocol == 'http'
703 703
                                 && $_SERVER['SERVER_PORT'] != 80) || ($server_protocol == 'https' && $_SERVER['SERVER_PORT'] != 443))
704 704
                     ) {
705
-                        $server_name .= ":" . $_SERVER['SERVER_PORT'];
705
+                        $server_name .= ":".$_SERVER['SERVER_PORT'];
706 706
                     }
707
-                    $root_web = $server_protocol . '://' . $server_name . $root_rel;
708
-                    $root_sys = str_replace('\\', '/', realpath(__DIR__ . '/../../../')) . '/';
707
+                    $root_web = $server_protocol.'://'.$server_name.$root_rel;
708
+                    $root_sys = str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/';
709 709
                 }
710 710
                 // Here we give up, so we don't touch anything.
711 711
             }
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
                 $sys_course_code =
897 897
                     isset($_SESSION['_course']['sysCode'])  // User is inside a course?
898 898
                         ? $_SESSION['_course']['sysCode']   // Yes, then use course's directory name.
899
-                        : '{SYS_COURSE_CODE}';              // No, then use a fake code, it may be processed later.
899
+                        : '{SYS_COURSE_CODE}'; // No, then use a fake code, it may be processed later.
900 900
                 $path = $matches[1].'courses/'.$sys_course_code.'/document/'.str_replace('//', '/', $matches[3].'/'.$matches[2]);
901 901
             }
902 902
         }
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
                 if (in_array($ext, $exts)) {
930 930
                     //Use host as defined in $_configuration['cdn'], without
931 931
                     // trailing slash
932
-                    return str_replace($web_root,$host.'/',$web_path);
932
+                    return str_replace($web_root, $host.'/', $web_path);
933 933
                 }
934 934
             }
935 935
         }
@@ -1373,10 +1373,10 @@  discard block
 block discarded – undo
1373 1373
 
1374 1374
     if (isset($user['email'])) {
1375 1375
         $result['mail'] = isset($user['email']) ? $user['email'] : null;
1376
-        $result['email'] = isset($user['email'])? $user['email'] : null;
1376
+        $result['email'] = isset($user['email']) ? $user['email'] : null;
1377 1377
     } else {
1378 1378
         $result['mail'] = isset($user['mail']) ? $user['mail'] : null;
1379
-        $result['email'] = isset($user['mail'])? $user['mail'] : null;
1379
+        $result['email'] = isset($user['mail']) ? $user['mail'] : null;
1380 1380
     }
1381 1381
     $user_id = intval($user['user_id']);
1382 1382
     // Maintain the user_id index for backwards compatibility
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 
1466 1466
         if (isset($userFromSession)) {
1467 1467
             if ($cacheAvailable === true) {
1468
-                $apcVar = api_get_configuration_value('apc_prefix') . 'userinfo_' . $userFromSession['user_id'];
1468
+                $apcVar = api_get_configuration_value('apc_prefix').'userinfo_'.$userFromSession['user_id'];
1469 1469
                 if (apcu_exists($apcVar)) {
1470 1470
                     $user = apcu_fetch($apcVar);
1471 1471
                 } else {
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
 
1488 1488
     // Re-use user information if not stale and already stored in APCu
1489 1489
     if ($cacheAvailable === true) {
1490
-        $apcVar = api_get_configuration_value('apc_prefix') . 'userinfo_' . $user_id;
1490
+        $apcVar = api_get_configuration_value('apc_prefix').'userinfo_'.$user_id;
1491 1491
         if (apcu_exists($apcVar)) {
1492 1492
             $user = apcu_fetch($apcVar);
1493 1493
 
@@ -1495,7 +1495,7 @@  discard block
 block discarded – undo
1495 1495
         }
1496 1496
     }
1497 1497
 
1498
-    $sql = "SELECT * FROM " . Database:: get_main_table(TABLE_MAIN_USER) . "
1498
+    $sql = "SELECT * FROM ".Database:: get_main_table(TABLE_MAIN_USER)."
1499 1499
             WHERE id = $user_id";
1500 1500
     $result = Database::query($sql);
1501 1501
     if (Database::num_rows($result) > 0) {
@@ -1960,7 +1960,7 @@  discard block
 block discarded – undo
1960 1960
         foreach ($param_list1 as $key => $enreg) {
1961 1961
             list ($param_list1_keys[$key], $param_list1_vals[$key]) = explode('=', $enreg);
1962 1962
         }
1963
-        $param_list1 = array ('keys' => $param_list1_keys, 'vals' => $param_list1_vals);
1963
+        $param_list1 = array('keys' => $param_list1_keys, 'vals' => $param_list1_vals);
1964 1964
         foreach ($param_list2 as $enreg) {
1965 1965
             $enreg = explode('=', $enreg);
1966 1966
             $key = array_search($enreg[0], $param_list1['keys']);
@@ -1993,12 +1993,12 @@  discard block
 block discarded – undo
1993 1993
         $length = 2;
1994 1994
     }
1995 1995
     $password = '';
1996
-    for ($i = 0; $i < $length; $i ++) {
1996
+    for ($i = 0; $i < $length; $i++) {
1997 1997
         $password .= $characters[rand() % strlen($characters)];
1998 1998
     }
1999 1999
 
2000 2000
     // At least 2 digits
2001
-    for ($i = 0; $i < 2; $i ++) {
2001
+    for ($i = 0; $i < 2; $i++) {
2002 2002
         $password .= $numbers[rand() % strlen($numbers)];
2003 2003
     }
2004 2004
 
@@ -2026,10 +2026,10 @@  discard block
 block discarded – undo
2026 2026
     $digits = 0;
2027 2027
     $consequent_characters = 0;
2028 2028
     $previous_character_code = 0;
2029
-    for ($i = 0; $i < $password_length; $i ++) {
2029
+    for ($i = 0; $i < $password_length; $i++) {
2030 2030
         $current_character_code = api_ord(api_substr($password, $i, 1));
2031 2031
         if ($i && abs($current_character_code - $previous_character_code) <= 1) {
2032
-            $consequent_characters ++;
2032
+            $consequent_characters++;
2033 2033
             if ($consequent_characters == 3) {
2034 2034
                 return false;
2035 2035
             }
@@ -2037,9 +2037,9 @@  discard block
 block discarded – undo
2037 2037
             $consequent_characters = 1;
2038 2038
         }
2039 2039
         if ($current_character_code >= 97 && $current_character_code <= 122) {
2040
-            $letters ++;
2040
+            $letters++;
2041 2041
         } elseif ($current_character_code >= 48 && $current_character_code <= 57) {
2042
-            $digits ++;
2042
+            $digits++;
2043 2043
         } else {
2044 2044
             return false;
2045 2045
         }
@@ -2144,7 +2144,7 @@  discard block
 block discarded – undo
2144 2144
         if (empty($session_id)) { return null; }
2145 2145
     }
2146 2146
     $t = Database::get_main_table(TABLE_MAIN_SESSION);
2147
-    $s = "SELECT name FROM $t WHERE id = ".(int)$session_id;
2147
+    $s = "SELECT name FROM $t WHERE id = ".(int) $session_id;
2148 2148
     $r = Database::query($s);
2149 2149
     $c = Database::num_rows($r);
2150 2150
     if ($c > 0) {
@@ -2314,9 +2314,9 @@  discard block
 block discarded – undo
2314 2314
  */
2315 2315
 function api_get_session_image($session_id, $status_id)
2316 2316
 {
2317
-    $session_id = (int)$session_id;
2317
+    $session_id = (int) $session_id;
2318 2318
     $session_img = '';
2319
-    if ((int)$status_id != 5) { //check whether is not a student
2319
+    if ((int) $status_id != 5) { //check whether is not a student
2320 2320
         if ($session_id > 0) {
2321 2321
             $session_img = "&nbsp;&nbsp;".Display::return_icon(
2322 2322
                 'star.png',
@@ -2593,7 +2593,7 @@  discard block
 block discarded – undo
2593 2593
 function api_is_course_session_coach($user_id, $courseId, $session_id)
2594 2594
 {
2595 2595
     $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
2596
-    $session_rel_course_rel_user_table  = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
2596
+    $session_rel_course_rel_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
2597 2597
 
2598 2598
     $user_id = intval($user_id);
2599 2599
     $session_id = intval($session_id);
@@ -2667,7 +2667,7 @@  discard block
 block discarded – undo
2667 2667
                 ORDER BY access_start_date, access_end_date, name";
2668 2668
         $result = Database::query($sql);
2669 2669
         if (!empty($sessionIsCoach)) {
2670
-            $sessionIsCoach = array_merge($sessionIsCoach , Database::store_result($result));
2670
+            $sessionIsCoach = array_merge($sessionIsCoach, Database::store_result($result));
2671 2671
         } else {
2672 2672
             $sessionIsCoach = Database::store_result($result);
2673 2673
         }
@@ -2841,7 +2841,7 @@  discard block
 block discarded – undo
2841 2841
             return '';
2842 2842
         }
2843 2843
         $sourceurl = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
2844
-        $sourceurl = str_replace('lp/lp_header.php', 'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.intval($_GET['lp_id']).'&isStudentView='.($_SESSION['studentview']=='studentview' ? 'false' : 'true'), $sourceurl);
2844
+        $sourceurl = str_replace('lp/lp_header.php', 'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.intval($_GET['lp_id']).'&isStudentView='.($_SESSION['studentview'] == 'studentview' ? 'false' : 'true'), $sourceurl);
2845 2845
         //showinframes doesn't handle student view anyway...
2846 2846
         //return '';
2847 2847
         $is_framed = true;
@@ -3323,7 +3323,7 @@  discard block
 block discarded – undo
3323 3323
         }
3324 3324
         $content .= '<div class="well">';
3325 3325
         $content .= $form->returnForm();
3326
-        $content .='</div>';
3326
+        $content .= '</div>';
3327 3327
         if (api_is_cas_activated()) {
3328 3328
             $content .= "</div>";
3329 3329
         }
@@ -3375,7 +3375,7 @@  discard block
 block discarded – undo
3375 3375
         }
3376 3376
         $msg .= '<div class="well">';
3377 3377
         $msg .= $form->returnForm();
3378
-        $msg .='</div>';
3378
+        $msg .= '</div>';
3379 3379
         if ($casEnabled) {
3380 3380
             $msg .= "</div>";
3381 3381
         }
@@ -3405,7 +3405,7 @@  discard block
 block discarded – undo
3405 3405
     list ($last_post_date, $last_post_time) = explode(' ', $last_post_datetime);
3406 3406
     list ($year, $month, $day) = explode('-', $last_post_date);
3407 3407
     list ($hour, $min, $sec) = explode(':', $last_post_time);
3408
-    return mktime((int)$hour, (int)$min, (int)$sec, (int)$month, (int)$day, (int)$year);
3408
+    return mktime((int) $hour, (int) $min, (int) $sec, (int) $month, (int) $day, (int) $year);
3409 3409
 }
3410 3410
 
3411 3411
 /**
@@ -3877,7 +3877,7 @@  discard block
 block discarded – undo
3877 3877
                 c_id = $course_id AND
3878 3878
                 tool = '$tool'
3879 3879
                 $session_condition ";
3880
-    $rs  = Database::query($sql);
3880
+    $rs = Database::query($sql);
3881 3881
     $list = array();
3882 3882
     if (Database::num_rows($rs) > 0) {
3883 3883
         while ($row = Database::fetch_array($rs, 'ASSOC')) {
@@ -3958,7 +3958,7 @@  discard block
 block discarded – undo
3958 3958
                 tool = '$tool' AND
3959 3959
                 ref = $ref
3960 3960
                 $sessionCondition";
3961
-    $rs  = Database::query($sql);
3961
+    $rs = Database::query($sql);
3962 3962
     $item_property_id = '';
3963 3963
     if (Database::num_rows($rs) > 0) {
3964 3964
         $row = Database::fetch_array($rs);
@@ -4019,7 +4019,7 @@  discard block
 block discarded – undo
4019 4019
     if ($result == false) {
4020 4020
         $result = array();
4021 4021
     } else {
4022
-        $result = Database::store_result($result,'ASSOC');
4022
+        $result = Database::store_result($result, 'ASSOC');
4023 4023
     }
4024 4024
 
4025 4025
     return $result;
@@ -4071,7 +4071,7 @@  discard block
 block discarded – undo
4071 4071
     $rs  = Database::query($sql);
4072 4072
     $row = array();
4073 4073
     if (Database::num_rows($rs) > 0) {
4074
-        $row = Database::fetch_array($rs,'ASSOC');
4074
+        $row = Database::fetch_array($rs, 'ASSOC');
4075 4075
     }
4076 4076
 
4077 4077
     return $row;
@@ -4106,7 +4106,7 @@  discard block
 block discarded – undo
4106 4106
     $languages  = $language_list['name'];
4107 4107
     $folder     = $language_list['folder'];
4108 4108
 
4109
-    $ret .= '<select name="' . $name . '" id="language_chosen" class="selectpicker show-tick form-control">';
4109
+    $ret .= '<select name="'.$name.'" id="language_chosen" class="selectpicker show-tick form-control">';
4110 4110
     foreach ($languages as $key => $value) {
4111 4111
         if ($folder[$key] == $default) {
4112 4112
             $selected = ' selected="selected"';
@@ -4156,8 +4156,8 @@  discard block
 block discarded – undo
4156 4156
     }
4157 4157
     </script>';
4158 4158
     $html .= '<form id="lang_form" name="lang_form" method="post" action="'.api_get_self().'">';
4159
-    $html .= '<label style="display: none;" for="language_list">' . get_lang('Language') . '</label>';
4160
-    $html .=  '<select id="language_list" class="selectpicker show-tick form-control" name="language_list" >';
4159
+    $html .= '<label style="display: none;" for="language_list">'.get_lang('Language').'</label>';
4160
+    $html .= '<select id="language_list" class="selectpicker show-tick form-control" name="language_list" >';
4161 4161
 
4162 4162
     foreach ($original_languages as $key => $value) {
4163 4163
         if ($folder[$key] == $user_selected_language) {
@@ -4165,13 +4165,13 @@  discard block
 block discarded – undo
4165 4165
         } else {
4166 4166
             $option_end = '>';
4167 4167
         }
4168
-        $html .=  '<option value="'.api_get_self().'?language='.$folder[$key].'"'.$option_end;
4168
+        $html .= '<option value="'.api_get_self().'?language='.$folder[$key].'"'.$option_end;
4169 4169
         //echo substr($value, 0, 16); // Cut string to keep 800x600 aspect.
4170
-        $html .=  $value.'</option>';
4170
+        $html .= $value.'</option>';
4171 4171
     }
4172
-    $html .=  '</select>';
4173
-    $html .=  '<noscript><input type="submit" name="user_select_language" value="'.get_lang('Ok').'" /></noscript>';
4174
-    $html .=  '</form>';
4172
+    $html .= '</select>';
4173
+    $html .= '<noscript><input type="submit" name="user_select_language" value="'.get_lang('Ok').'" /></noscript>';
4174
+    $html .= '</form>';
4175 4175
     return $html;
4176 4176
 }
4177 4177
 
@@ -4389,7 +4389,7 @@  discard block
 block discarded – undo
4389 4389
  * Note: Directory names (names of themes) in the file system should contain ASCII-characters only.
4390 4390
  */
4391 4391
 function api_get_themes() {
4392
-    $cssdir = api_get_path(SYS_CSS_PATH) . 'themes/';
4392
+    $cssdir = api_get_path(SYS_CSS_PATH).'themes/';
4393 4393
     $list_dir = array();
4394 4394
     $list_name = array();
4395 4395
 
@@ -4550,7 +4550,7 @@  discard block
 block discarded – undo
4550 4550
     if (is_file($dirname) || is_link($dirname)) {
4551 4551
         $res = unlink($dirname);
4552 4552
         if ($res === false) {
4553
-            error_log(__FILE__.' line '.__LINE__.': '.((bool)ini_get('track_errors') ? $php_errormsg : 'Error not recorded because track_errors is off in your php.ini'), 0);
4553
+            error_log(__FILE__.' line '.__LINE__.': '.((bool) ini_get('track_errors') ? $php_errormsg : 'Error not recorded because track_errors is off in your php.ini'), 0);
4554 4554
         }
4555 4555
         return $res;
4556 4556
     }
@@ -4587,7 +4587,7 @@  discard block
 block discarded – undo
4587 4587
     if ($delete_only_content_in_folder == false) {
4588 4588
         $res = rmdir($dirname);
4589 4589
         if ($res === false) {
4590
-            error_log(__FILE__.' line '.__LINE__.': '.((bool)ini_get('track_errors') ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
4590
+            error_log(__FILE__.' line '.__LINE__.': '.((bool) ini_get('track_errors') ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
4591 4591
         }
4592 4592
     }
4593 4593
     return $res;
@@ -4672,7 +4672,7 @@  discard block
 block discarded – undo
4672 4672
 
4673 4673
     $course_id = $course_info['real_id'];
4674 4674
 
4675
-    $folders = explode(DIRECTORY_SEPARATOR,str_replace($base_path_document.DIRECTORY_SEPARATOR,'',$pathname));
4675
+    $folders = explode(DIRECTORY_SEPARATOR, str_replace($base_path_document.DIRECTORY_SEPARATOR, '', $pathname));
4676 4676
 
4677 4677
     $new_pathname = $base_path_document;
4678 4678
     $path = '';
@@ -4690,7 +4690,7 @@  discard block
 block discarded – undo
4690 4690
                         path = '$path' AND
4691 4691
                         filetype = 'folder' AND
4692 4692
                         session_id = '$session_id'";
4693
-            $rs1  = Database::query($sql);
4693
+            $rs1 = Database::query($sql);
4694 4694
             $num_rows = Database::num_rows($rs1);
4695 4695
 
4696 4696
             if ($num_rows == 0) {
@@ -4850,7 +4850,7 @@  discard block
 block discarded – undo
4850 4850
             foreach (array('key', 'value1', 'value2', 'value3') as $var) {
4851 4851
                 $$var = isset($match[++$i]) ? $match[$i] : '';
4852 4852
             }
4853
-            $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
4853
+            $value = stripslashes(substr($value1, 1, -1)).stripslashes(substr($value2, 1, -1)).$value3;
4854 4854
 
4855 4855
             // Parse array syntax.
4856 4856
             $keys = preg_split('/\]?\[/', rtrim($key, ']'));
@@ -5016,7 +5016,7 @@  discard block
 block discarded – undo
5016 5016
     $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
5017 5017
     $var = Database::escape_string($var);
5018 5018
     $value = Database::escape_string($value);
5019
-    $access_url = (int)$access_url;
5019
+    $access_url = (int) $access_url;
5020 5020
     if (empty($access_url)) { $access_url = 1; }
5021 5021
     $select = "SELECT id FROM $t_settings WHERE variable = '$var' ";
5022 5022
     if (!empty($subvar)) {
@@ -5057,11 +5057,11 @@  discard block
 block discarded – undo
5057 5057
                 $row = Database::fetch_array($res);
5058 5058
                 $insert = "INSERT INTO $t_settings (variable, subkey, type,category, selected_value, title, comment, scope, subkeytext, access_url)
5059 5059
                         VALUES
5060
-                        ('".$row['variable']."',".(!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
5061
-                        "'".$row['type']."','".$row['category']."'," .
5062
-                        "'$value','".$row['title']."'," .
5063
-                        "".(!empty($row['comment']) ? "'".$row['comment']."'" : "NULL").",".(!empty($row['scope']) ? "'".$row['scope']."'" : "NULL")."," .
5064
-                        "".(!empty($row['subkeytext'])?"'".$row['subkeytext']."'":"NULL").",$access_url)";
5060
+                        ('".$row['variable']."',".(!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL").",".
5061
+                        "'".$row['type']."','".$row['category']."',".
5062
+                        "'$value','".$row['title']."',".
5063
+                        "".(!empty($row['comment']) ? "'".$row['comment']."'" : "NULL").",".(!empty($row['scope']) ? "'".$row['scope']."'" : "NULL").",".
5064
+                        "".(!empty($row['subkeytext']) ? "'".$row['subkeytext']."'" : "NULL").",$access_url)";
5065 5065
                 Database::query($insert);
5066 5066
             } else {
5067 5067
                 // Such a setting does not exist.
@@ -5083,11 +5083,11 @@  discard block
 block discarded – undo
5083 5083
                 if ($row['access_url_changeable'] == 1) {
5084 5084
                     $insert = "INSERT INTO $t_settings (variable,subkey, type,category, selected_value,title, comment,scope, subkeytext,access_url, access_url_changeable) VALUES
5085 5085
                             ('".$row['variable']."',".
5086
-                            (!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
5087
-                            "'".$row['type']."','".$row['category']."'," .
5088
-                            "'$value','".$row['title']."'," .
5086
+                            (!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL").",".
5087
+                            "'".$row['type']."','".$row['category']."',".
5088
+                            "'$value','".$row['title']."',".
5089 5089
                             "".(!empty($row['comment']) ? "'".$row['comment']."'" : "NULL").",".
5090
-                            (!empty($row['scope']) ? "'".$row['scope']."'" : "NULL")."," .
5090
+                            (!empty($row['scope']) ? "'".$row['scope']."'" : "NULL").",".
5091 5091
                             "".(!empty($row['subkeytext']) ? "'".$row['subkeytext']."'" : "NULL").",$access_url,".$row['access_url_changeable'].")";
5092 5092
                     Database::query($insert);
5093 5093
                 }
@@ -5120,10 +5120,10 @@  discard block
 block discarded – undo
5120 5120
         $value = Database::escape_string($value);
5121 5121
         $sql = "UPDATE $t_s SET selected_value = '$value'
5122 5122
                 WHERE category = '$category' AND access_url = $access_url";
5123
-        if (is_array($fieldtype) && count($fieldtype)>0) {
5123
+        if (is_array($fieldtype) && count($fieldtype) > 0) {
5124 5124
             $sql .= " AND ( ";
5125 5125
             $i = 0;
5126
-            foreach ($fieldtype as $type){
5126
+            foreach ($fieldtype as $type) {
5127 5127
                 if ($i > 0) {
5128 5128
                     $sql .= ' OR ';
5129 5129
                 }
@@ -5138,10 +5138,10 @@  discard block
 block discarded – undo
5138 5138
     } else {
5139 5139
         $sql = "UPDATE $t_s SET selected_value = NULL
5140 5140
                 WHERE category = '$category' AND access_url = $access_url";
5141
-        if (is_array($fieldtype) && count($fieldtype)>0) {
5141
+        if (is_array($fieldtype) && count($fieldtype) > 0) {
5142 5142
             $sql .= " AND ( ";
5143 5143
             $i = 0;
5144
-            foreach ($fieldtype as $type){
5144
+            foreach ($fieldtype as $type) {
5145 5145
                 if ($i > 0) {
5146 5146
                     $sql .= ' OR ';
5147 5147
                 }
@@ -5254,7 +5254,7 @@  discard block
 block discarded – undo
5254 5254
         $sql .= " ORDER BY 1,2 ASC";
5255 5255
     }
5256 5256
     $result = Database::query($sql);
5257
-    $result = Database::store_result($result,'ASSOC');
5257
+    $result = Database::store_result($result, 'ASSOC');
5258 5258
 
5259 5259
     return $result;
5260 5260
 }
@@ -5321,12 +5321,12 @@  discard block
 block discarded – undo
5321 5321
 
5322 5322
     // Item not found for this access_url, we have to check if the whole thing is missing
5323 5323
     // (in which case we ignore the insert) or if there *is* a record but just for access_url = 1
5324
-    $insert = "INSERT INTO $t_settings " .
5325
-                "(variable,selected_value," .
5326
-                "type,category," .
5327
-                "subkey,title," .
5328
-                "comment,scope," .
5329
-                "subkeytext,access_url,access_url_changeable)" .
5324
+    $insert = "INSERT INTO $t_settings ".
5325
+                "(variable,selected_value,".
5326
+                "type,category,".
5327
+                "subkey,title,".
5328
+                "comment,scope,".
5329
+                "subkeytext,access_url,access_url_changeable)".
5330 5330
                 " VALUES ('$var','$val',";
5331 5331
     if (isset($type)) {
5332 5332
         $type = Database::escape_string($type);
@@ -5492,7 +5492,7 @@  discard block
 block discarded – undo
5492 5492
             $result = Database::query($sql);
5493 5493
 
5494 5494
             //if ($row = Database::fetch_array($result)) {
5495
-            if (Database::num_rows($result) > 0 ) {
5495
+            if (Database::num_rows($result) > 0) {
5496 5496
                 $is_courseMember = true;
5497 5497
                 $is_courseTutor = true;
5498 5498
                 $is_courseCoach = true;
@@ -5782,7 +5782,7 @@  discard block
 block discarded – undo
5782 5782
     } else {
5783 5783
         return false;
5784 5784
     }
5785
-    return strtolower(substr((string)$os, 0, 3 )) == 'win';
5785
+    return strtolower(substr((string) $os, 0, 3)) == 'win';
5786 5786
 }
5787 5787
 
5788 5788
 /**
@@ -6373,7 +6373,7 @@  discard block
 block discarded – undo
6373 6373
 function api_get_jquery_ui_js($include_jqgrid = false) {
6374 6374
     $libraries = array();
6375 6375
     if ($include_jqgrid) {
6376
-       $libraries[]='jqgrid';
6376
+       $libraries[] = 'jqgrid';
6377 6377
     }
6378 6378
     return api_get_jquery_libraries_js($libraries);
6379 6379
 }
@@ -6396,12 +6396,12 @@  discard block
 block discarded – undo
6396 6396
 
6397 6397
     //jqgrid js and css
6398 6398
     if (in_array('jqgrid', $libraries)) {
6399
-        $languaje   = 'en';
6399
+        $languaje = 'en';
6400 6400
         $platform_isocode = strtolower(api_get_language_isocode());
6401 6401
 
6402 6402
         //languages supported by jqgrid see files in main/inc/lib/javascript/jqgrid/js/i18n
6403 6403
         $jqgrid_langs = array(
6404
-            'bg', 'bg1251', 'cat','cn','cs','da','de','el','en','es','fa','fi','fr','gl','he','hu','is','it','ja','nl','no','pl','pt-br','pt','ro','ru','sk','sr','sv','tr','ua'
6404
+            'bg', 'bg1251', 'cat', 'cn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'gl', 'he', 'hu', 'is', 'it', 'ja', 'nl', 'no', 'pl', 'pt-br', 'pt', 'ro', 'ru', 'sk', 'sr', 'sv', 'tr', 'ua'
6405 6405
         );
6406 6406
 
6407 6407
         if (in_array($platform_isocode, $jqgrid_langs)) {
@@ -6432,7 +6432,7 @@  discard block
 block discarded – undo
6432 6432
 
6433 6433
     // jquery datepicker
6434 6434
     if (in_array('datepicker', $libraries)) {
6435
-        $languaje   = 'en-GB';
6435
+        $languaje = 'en-GB';
6436 6436
         $platform_isocode = strtolower(api_get_language_isocode());
6437 6437
 
6438 6438
         // languages supported by jqgrid see files in main/inc/lib/javascript/jqgrid/js/i18n
@@ -6598,7 +6598,7 @@  discard block
 block discarded – undo
6598 6598
  * @return void
6599 6599
  */
6600 6600
 function api_check_php_version($my_inc_path = null) {
6601
-    if (!function_exists('version_compare') || version_compare( phpversion(), REQUIRED_PHP_VERSION, '<')) {
6601
+    if (!function_exists('version_compare') || version_compare(phpversion(), REQUIRED_PHP_VERSION, '<')) {
6602 6602
         $global_error_code = 1;
6603 6603
         // Incorrect PHP version
6604 6604
         $global_page = $my_inc_path.'global_error_message.inc.php';
@@ -6614,7 +6614,7 @@  discard block
 block discarded – undo
6614 6614
  */
6615 6615
 function api_check_archive_dir() {
6616 6616
     if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) && !is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
6617
-        $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'),'warning');
6617
+        $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'warning');
6618 6618
         api_not_allowed(true, $message);
6619 6619
     }
6620 6620
 }
@@ -6677,7 +6677,7 @@  discard block
 block discarded – undo
6677 6677
  * @author Jorge Frisancho Jibaja <[email protected]>, USIL - Some changes to allow the use of real IP using reverse proxy
6678 6678
  * @version CEV CHANGE 24APR2012
6679 6679
  */
6680
-function api_get_real_ip(){
6680
+function api_get_real_ip() {
6681 6681
     // Guess the IP if behind a reverse proxy
6682 6682
     global $debug;
6683 6683
     $ip = trim($_SERVER['REMOTE_ADDR']);
@@ -6703,23 +6703,23 @@  discard block
 block discarded – undo
6703 6703
  * @author Yannick Warnier for improvements and managment of multiple ranges
6704 6704
  * @todo check for IPv6 support
6705 6705
  */
6706
-function api_check_ip_in_range($ip,$range)
6706
+function api_check_ip_in_range($ip, $range)
6707 6707
 {
6708 6708
     if (empty($ip) or empty($range)) {
6709 6709
         return false;
6710 6710
     }
6711
-    $ip_ip = ip2long ($ip);
6711
+    $ip_ip = ip2long($ip);
6712 6712
     // divide range param into array of elements
6713
-    if (strpos($range,',')!==false) {
6714
-        $ranges = explode(',',$range);
6713
+    if (strpos($range, ',') !== false) {
6714
+        $ranges = explode(',', $range);
6715 6715
     } else {
6716 6716
         $ranges = array($range);
6717 6717
     }
6718 6718
     foreach ($ranges as $range) {
6719 6719
         $range = trim($range);
6720 6720
         if (empty($range)) { continue; }
6721
-        if (strpos($range,'/')===false) {
6722
-            if (strcmp($ip,$range)===0) {
6721
+        if (strpos($range, '/') === false) {
6722
+            if (strcmp($ip, $range) === 0) {
6723 6723
                 return true; // there is a direct IP match, return OK
6724 6724
             }
6725 6725
             continue; //otherwise, get to the next range
@@ -6727,7 +6727,7 @@  discard block
 block discarded – undo
6727 6727
         // the range contains a "/", so analyse completely
6728 6728
         list ($net, $mask) = explode("/", $range);
6729 6729
 
6730
-        $ip_net = ip2long ($net);
6730
+        $ip_net = ip2long($net);
6731 6731
         // mask binary magic
6732 6732
         $ip_mask = ~((1 << (32 - $mask)) - 1);
6733 6733
 
@@ -7065,14 +7065,14 @@  discard block
 block discarded – undo
7065 7065
  * @assert (0) === true
7066 7066
  * @assert ('1G') === true
7067 7067
  */
7068
-function api_set_memory_limit($mem){
7068
+function api_set_memory_limit($mem) {
7069 7069
     //if ini_set() not available, this function is useless
7070 7070
     if (!function_exists('ini_set') || is_null($mem) || $mem == -1) {
7071 7071
         return false;
7072 7072
     }
7073 7073
 
7074 7074
     $memory_limit = ini_get('memory_limit');
7075
-    if (api_get_bytes_memory_limit($mem) > api_get_bytes_memory_limit($memory_limit)){
7075
+    if (api_get_bytes_memory_limit($mem) > api_get_bytes_memory_limit($memory_limit)) {
7076 7076
         ini_set('memory_limit', $mem);
7077 7077
         return true;
7078 7078
     }
@@ -7089,21 +7089,21 @@  discard block
 block discarded – undo
7089 7089
  * @assert ('1m')  === 1048576
7090 7090
  * @assert ('100k') === 102400
7091 7091
  */
7092
-function api_get_bytes_memory_limit($mem){
7093
-    $size = strtolower(substr($mem,-1));
7092
+function api_get_bytes_memory_limit($mem) {
7093
+    $size = strtolower(substr($mem, -1));
7094 7094
 
7095 7095
     switch ($size) {
7096 7096
         case 't':
7097
-            $mem = intval(substr($mem,-1))*1024*1024*1024*1024;
7097
+            $mem = intval(substr($mem, -1)) * 1024 * 1024 * 1024 * 1024;
7098 7098
             break;
7099 7099
         case 'g':
7100
-            $mem = intval(substr($mem,0,-1))*1024*1024*1024;
7100
+            $mem = intval(substr($mem, 0, -1)) * 1024 * 1024 * 1024;
7101 7101
             break;
7102 7102
         case 'm':
7103
-            $mem = intval(substr($mem,0,-1))*1024*1024;
7103
+            $mem = intval(substr($mem, 0, -1)) * 1024 * 1024;
7104 7104
             break;
7105 7105
         case 'k':
7106
-            $mem = intval(substr($mem,0,-1))*1024;
7106
+            $mem = intval(substr($mem, 0, -1)) * 1024;
7107 7107
             break;
7108 7108
         default:
7109 7109
             // we assume it's integer only
@@ -7166,7 +7166,7 @@  discard block
 block discarded – undo
7166 7166
     ];
7167 7167
 
7168 7168
     $js = api_get_asset('pwstrength-bootstrap/dist/pwstrength-bootstrap.min.js');
7169
-    $js .=  "<script>    
7169
+    $js .= "<script>    
7170 7170
     var errorMessages = {
7171 7171
         password_to_short : \"" . get_lang('PasswordIsTooShort')."\",
7172 7172
         same_as_username : \"".get_lang('YourPasswordCannotBeTheSameAsYourUsername')."\"
@@ -7213,7 +7213,7 @@  discard block
 block discarded – undo
7213 7213
         return false;
7214 7214
     }
7215 7215
     $minutesToBlock = api_get_setting('captcha_time_to_block');
7216
-    $time = time() + $minutesToBlock*60;
7216
+    $time = time() + $minutesToBlock * 60;
7217 7217
     UserManager::update_extra_field_value(
7218 7218
         $userInfo['user_id'],
7219 7219
         'captcha_blocked_until_date',
@@ -7287,7 +7287,7 @@  discard block
 block discarded – undo
7287 7287
         $out_res = str_replace('"', "''", $out_res);
7288 7288
     }
7289 7289
     // avoid text stuck together when tags are removed, adding a space after >
7290
-    $out_res = str_replace (">", "> ", $out_res);
7290
+    $out_res = str_replace(">", "> ", $out_res);
7291 7291
     $out_res = strip_tags($out_res);
7292 7292
 
7293 7293
     return $out_res;
@@ -7496,7 +7496,7 @@  discard block
 block discarded – undo
7496 7496
         $body = get_lang('PortalName').': '.api_get_path(WEB_PATH)." \n ";
7497 7497
         $body .= get_lang('PortalLimitType').': '.$limitName." \n ";
7498 7498
         if (isset($hostingParams[$limitName])) {
7499
-            $body .= get_lang('Value') . ': ' . $hostingParams[$limitName];
7499
+            $body .= get_lang('Value').': '.$hostingParams[$limitName];
7500 7500
         }
7501 7501
         api_mail_html(null, $email, $subject, $body);
7502 7502
     }
@@ -7628,7 +7628,7 @@  discard block
 block discarded – undo
7628 7628
  */
7629 7629
 function api_set_site_use_cookie_warning_cookie()
7630 7630
 {
7631
-    setcookie('ChamiloUsesCookies', 'ok', time()+31556926);
7631
+    setcookie('ChamiloUsesCookies', 'ok', time() + 31556926);
7632 7632
 }
7633 7633
 
7634 7634
 /**
@@ -7682,10 +7682,10 @@  discard block
 block discarded – undo
7682 7682
         return false;
7683 7683
     }
7684 7684
 
7685
-    $fullPath = $parentDirectory . api_replace_dangerous_char($name);
7685
+    $fullPath = $parentDirectory.api_replace_dangerous_char($name);
7686 7686
 
7687 7687
     if (mkdir($fullPath, api_get_permissions_for_new_directories(), true)) {
7688
-        $fp = fopen($fullPath . '/index.html', 'w');
7688
+        $fp = fopen($fullPath.'/index.html', 'w');
7689 7689
 
7690 7690
         if ($fp) {
7691 7691
             if (fwrite($fp, '<html><head></head><body></body></html>')) {
@@ -7750,7 +7750,7 @@  discard block
 block discarded – undo
7750 7750
             $mail->SMTPSecure = $platform_email['SMTP_SECURE'];
7751 7751
         }
7752 7752
     }
7753
-    $mail->SMTPDebug = isset($platform_email['SMTP_DEBUG'])?$platform_email['SMTP_DEBUG']:0;
7753
+    $mail->SMTPDebug = isset($platform_email['SMTP_DEBUG']) ? $platform_email['SMTP_DEBUG'] : 0;
7754 7754
 
7755 7755
     // 5 = low, 1 = high
7756 7756
     $mail->Priority = 3;
@@ -7896,11 +7896,11 @@  discard block
 block discarded – undo
7896 7896
         error_log('ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />');
7897 7897
         if ($mail->SMTPDebug) {
7898 7898
             error_log(
7899
-                "Connection details :: " .
7900
-                "Protocol: " . $mail->Mailer . ' :: ' .
7901
-                "Host/Port: " . $mail->Host . ':' . $mail->Port . ' :: ' .
7902
-                "Authent/Open: " . ($mail->SMTPAuth?'Authent':'Open') . ' :: ' .
7903
-                ($mail->SMTPAuth?"  User/Pass: " . $mail->Username . ':' . $mail->Password:'')
7899
+                "Connection details :: ".
7900
+                "Protocol: ".$mail->Mailer.' :: '.
7901
+                "Host/Port: ".$mail->Host.':'.$mail->Port.' :: '.
7902
+                "Authent/Open: ".($mail->SMTPAuth ? 'Authent' : 'Open').' :: '.
7903
+                ($mail->SMTPAuth ? "  User/Pass: ".$mail->Username.':'.$mail->Password : '')
7904 7904
             );
7905 7905
         }
7906 7906
         return 0;
@@ -7976,13 +7976,13 @@  discard block
 block discarded – undo
7976 7976
  * @return array
7977 7977
  *
7978 7978
  */
7979
-function api_unique_multidim_array($array, $key){
7979
+function api_unique_multidim_array($array, $key) {
7980 7980
     $temp_array = [];
7981 7981
     $i = 0;
7982 7982
     $key_array = [];
7983 7983
 
7984
-    foreach($array as $val){
7985
-        if(!in_array($val[$key],$key_array)){
7984
+    foreach ($array as $val) {
7985
+        if (!in_array($val[$key], $key_array)) {
7986 7986
             $key_array[$i] = $val[$key];
7987 7987
             $temp_array[$i] = $val;
7988 7988
         }
@@ -8026,7 +8026,7 @@  discard block
 block discarded – undo
8026 8026
         // No "dangerous" files
8027 8027
         $name = disable_dangerous_file($name);
8028 8028
 
8029
-        $pathId = '/'.substr((string)$itemId, 0, 1).'/'.$itemId.'/';
8029
+        $pathId = '/'.substr((string) $itemId, 0, 1).'/'.$itemId.'/';
8030 8030
         $path = api_get_path(SYS_UPLOAD_PATH).$type.$pathId;
8031 8031
 
8032 8032
         if (!is_dir($path)) {
@@ -8105,7 +8105,7 @@  discard block
 block discarded – undo
8105 8105
  */
8106 8106
 function location($url, $exit = true)
8107 8107
 {
8108
-    header('Location: ' . $url);
8108
+    header('Location: '.$url);
8109 8109
 
8110 8110
     if ($exit) {
8111 8111
         exit;
Please login to merge, or discard this patch.