Completed
Push — 1.10.x ( 786ca3...8728a6 )
by
unknown
195:12 queued 150:59
created
main/webservices/registration.soap.php 1 patch
Braces   +172 added lines, -63 removed lines patch added patch discarded remove patch
@@ -63,19 +63,22 @@  discard block
 block discarded – undo
63 63
         list($ip1) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
64 64
         $ip = trim($ip1);
65 65
     }
66
-    if ($debug)
67
-        error_log("ip: $ip");
66
+    if ($debug) {
67
+            error_log("ip: $ip");
68
+    }
68 69
     // Check if a file that limits access from webservices exists and contains
69 70
     // the restraining check
70 71
     if (is_file('webservice-auth-ip.conf.php')) {
71 72
         include 'webservice-auth-ip.conf.php';
72
-        if ($debug)
73
-            error_log("webservice-auth-ip.conf.php file included");
73
+        if ($debug) {
74
+                    error_log("webservice-auth-ip.conf.php file included");
75
+        }
74 76
         if (!empty($ws_auth_ip)) {
75 77
             $check_ip = true;
76 78
             $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip);
77
-            if ($debug)
78
-                error_log("ip_matches: $ip_matches");
79
+            if ($debug) {
80
+                            error_log("ip_matches: $ip_matches");
81
+            }
79 82
         }
80 83
     }
81 84
 
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 
93 96
     $result = api_is_valid_secret_key($secret_key, $security_key);
94 97
 
95
-    if ($debug)
96
-        error_log('WSHelperVerifyKey result: '.intval($result));
98
+    if ($debug) {
99
+            error_log('WSHelperVerifyKey result: '.intval($result));
100
+    }
97 101
     return $result;
98 102
 }
99 103
 
@@ -553,7 +557,9 @@  discard block
 block discarded – undo
553 557
 
554 558
     // First check wether the login already exists
555 559
     if (!UserManager::is_username_available($loginName)) {
556
-        if ($debug) error_log("Username $loginName is not available");
560
+        if ($debug) {
561
+            error_log("Username $loginName is not available");
562
+        }
557 563
         return 0;
558 564
     }
559 565
 
@@ -1012,7 +1018,9 @@  discard block
 block discarded – undo
1012 1018
     if (empty($userId) && empty($sessionId) && empty($courseId)) {
1013 1019
         // try original values
1014 1020
 
1015
-        if ($debug) error_log('try original values');
1021
+        if ($debug) {
1022
+            error_log('try original values');
1023
+        }
1016 1024
 
1017 1025
         $userIdName = isset($params['original_user_id_name']) ? $params['original_user_id_name'] : 0;
1018 1026
         $userIdValue = isset($params['original_user_id_value']) ? $params['original_user_id_value'] : 0;
@@ -1044,9 +1052,15 @@  discard block
 block discarded – undo
1044 1052
         );
1045 1053
     }
1046 1054
 
1047
-    if ($debug) error_log('$userId found: '. $userId);
1048
-    if ($debug) error_log('$courseId found: '. $courseId);
1049
-    if ($debug) error_log('$sessionId found: '. $sessionId);
1055
+    if ($debug) {
1056
+        error_log('$userId found: '. $userId);
1057
+    }
1058
+    if ($debug) {
1059
+        error_log('$courseId found: '. $courseId);
1060
+    }
1061
+    if ($debug) {
1062
+        error_log('$sessionId found: '. $sessionId);
1063
+    }
1050 1064
 
1051 1065
     return [
1052 1066
         'user_id' => $userId,
@@ -1076,13 +1090,17 @@  discard block
 block discarded – undo
1076 1090
 {
1077 1091
     global $debug;
1078 1092
 
1079
-    if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
1093
+    if ($debug) {
1094
+        error_log('WSSubscribeTeacherToSessionCourse');
1095
+    }
1080 1096
 
1081 1097
     if (!WSHelperVerifyKey($params)) {
1082 1098
         return returnError(WS_ERROR_SECRET_KEY);
1083 1099
     }
1084 1100
 
1085
-    if ($debug) error_log('Params '. print_r($params, 1));
1101
+    if ($debug) {
1102
+        error_log('Params '. print_r($params, 1));
1103
+    }
1086 1104
 
1087 1105
     $params = parseCourseSessionUserParams($params);
1088 1106
 
@@ -1095,13 +1113,17 @@  discard block
 block discarded – undo
1095 1113
     $result = 0;
1096 1114
 
1097 1115
     if (!empty($coaches)) {
1098
-        if ($debug) error_log('Coaches:  '. print_r($coaches, 1));
1116
+        if ($debug) {
1117
+            error_log('Coaches:  '. print_r($coaches, 1));
1118
+        }
1099 1119
         if (in_array($userId, $coaches)) {
1100 1120
             $result = 1;
1101 1121
         }
1102 1122
     }
1103 1123
 
1104
-    if ($debug) error_log('Result:  '. $result);
1124
+    if ($debug) {
1125
+        error_log('Result:  '. $result);
1126
+    }
1105 1127
 
1106 1128
     return $result;
1107 1129
 }
@@ -1127,13 +1149,17 @@  discard block
 block discarded – undo
1127 1149
 {
1128 1150
     global $debug;
1129 1151
 
1130
-    if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
1152
+    if ($debug) {
1153
+        error_log('WSSubscribeTeacherToSessionCourse');
1154
+    }
1131 1155
 
1132 1156
     if (!WSHelperVerifyKey($params)) {
1133 1157
         return returnError(WS_ERROR_SECRET_KEY);
1134 1158
     }
1135 1159
 
1136
-    if ($debug) error_log('Params '. print_r($params, 1));
1160
+    if ($debug) {
1161
+        error_log('Params '. print_r($params, 1));
1162
+    }
1137 1163
 
1138 1164
     $params = parseCourseSessionUserParams($params);
1139 1165
 
@@ -1147,7 +1173,9 @@  discard block
 block discarded – undo
1147 1173
     $result = 0;
1148 1174
 
1149 1175
     if (!empty($coaches)) {
1150
-        if ($debug) error_log('Coaches:  ' . print_r($coaches, 1));
1176
+        if ($debug) {
1177
+            error_log('Coaches:  ' . print_r($coaches, 1));
1178
+        }
1151 1179
         if (!in_array($userId, $coaches)) {
1152 1180
             $result = 1;
1153 1181
         }
@@ -1155,7 +1183,9 @@  discard block
 block discarded – undo
1155 1183
         $result = 1;
1156 1184
     }
1157 1185
 
1158
-    if ($debug) error_log('Final Result: '. $result);
1186
+    if ($debug) {
1187
+        error_log('Final Result: '. $result);
1188
+    }
1159 1189
 
1160 1190
     return $result;
1161 1191
 }
@@ -1207,8 +1237,12 @@  discard block
 block discarded – undo
1207 1237
 {
1208 1238
     global $_user, $_configuration, $debug;
1209 1239
     $debug = 1;
1210
-    if ($debug) error_log('WSCreateUserPasswordCrypted');
1211
-    if ($debug) error_log(print_r($params,1));
1240
+    if ($debug) {
1241
+        error_log('WSCreateUserPasswordCrypted');
1242
+    }
1243
+    if ($debug) {
1244
+        error_log(print_r($params,1));
1245
+    }
1212 1246
 
1213 1247
     if (!WSHelperVerifyKey($params)) {
1214 1248
         return returnError(WS_ERROR_SECRET_KEY);
@@ -1244,22 +1278,30 @@  discard block
 block discarded – undo
1244 1278
         if ($_configuration['password_encryption'] === $encrypt_method ) {
1245 1279
             if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
1246 1280
                 $msg = "Encryption $encrypt_method is invalid";
1247
-                if ($debug) error_log($msg);
1281
+                if ($debug) {
1282
+                    error_log($msg);
1283
+                }
1248 1284
                 return $msg;
1249 1285
 
1250 1286
             } else if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
1251 1287
                 $msg = "Encryption $encrypt_method is invalid";
1252
-                if ($debug) error_log($msg);
1288
+                if ($debug) {
1289
+                    error_log($msg);
1290
+                }
1253 1291
                 return $msg;
1254 1292
             }
1255 1293
         } else {
1256 1294
             $msg = "This encryption $encrypt_method is not configured";
1257
-            if ($debug) error_log($msg);
1295
+            if ($debug) {
1296
+                error_log($msg);
1297
+            }
1258 1298
             return $msg;
1259 1299
         }
1260 1300
     } else {
1261 1301
         $msg = 'The chamilo setting $_configuration["password_encryption"] is not configured';
1262
-        if ($debug) error_log($msg);
1302
+        if ($debug) {
1303
+            error_log($msg);
1304
+        }
1263 1305
         return $msg;
1264 1306
     }
1265 1307
 
@@ -1279,10 +1321,14 @@  discard block
 block discarded – undo
1279 1321
         $original_user_id_name
1280 1322
     );
1281 1323
 
1282
-    if ($debug) error_log('Ready to create user');
1324
+    if ($debug) {
1325
+        error_log('Ready to create user');
1326
+    }
1283 1327
 
1284 1328
     if ($user_id > 0) {
1285
-        if ($debug) error_log('User found with id: '.$user_id);
1329
+        if ($debug) {
1330
+            error_log('User found with id: '.$user_id);
1331
+        }
1286 1332
 
1287 1333
         // Check whether user is not active
1288 1334
         //@todo why this condition exists??
@@ -1293,7 +1339,9 @@  discard block
 block discarded – undo
1293 1339
         $count_check_user = Database::num_rows($resu);
1294 1340
         if ($count_check_user > 0) {
1295 1341
 
1296
-            if ($debug) error_log('User id: '.$user_id.' exists and is NOT active. Updating user and setting setting active = 1');
1342
+            if ($debug) {
1343
+                error_log('User id: '.$user_id.' exists and is NOT active. Updating user and setting setting active = 1');
1344
+            }
1297 1345
 
1298 1346
             $sql = "UPDATE $table_user SET
1299 1347
                     lastname='".Database::escape_string($lastName)."',
@@ -1313,7 +1361,9 @@  discard block
 block discarded – undo
1313 1361
                     active='1',
1314 1362
                     hr_dept_id=".intval($hr_dept_id);
1315 1363
             $sql .=    " WHERE user_id='".$r_check_user[0]."'";
1316
-            if ($debug) error_log($sql);
1364
+            if ($debug) {
1365
+                error_log($sql);
1366
+            }
1317 1367
             Database::query($sql);
1318 1368
 
1319 1369
             if (is_array($extra_list) && count($extra_list) > 0) {
@@ -1330,11 +1380,15 @@  discard block
 block discarded – undo
1330 1380
             }
1331 1381
             return $r_check_user[0];
1332 1382
         } else {
1333
-            if ($debug) error_log('User exists but is active. Cant be updated');
1383
+            if ($debug) {
1384
+                error_log('User exists but is active. Cant be updated');
1385
+            }
1334 1386
             return 0;
1335 1387
         }
1336 1388
     } else {
1337
-        if ($debug) error_log("User not found with original_id = $original_user_id_value and original_name = $original_user_id_name");
1389
+        if ($debug) {
1390
+            error_log("User not found with original_id = $original_user_id_value and original_name = $original_user_id_name");
1391
+        }
1338 1392
     }
1339 1393
 
1340 1394
     // Default language.
@@ -1350,12 +1404,16 @@  discard block
 block discarded – undo
1350 1404
 
1351 1405
     // First check wether the login already exists
1352 1406
     if (!UserManager::is_username_available($loginName)) {
1353
-        if ($debug) error_log("Username $loginName is not available");
1407
+        if ($debug) {
1408
+            error_log("Username $loginName is not available");
1409
+        }
1354 1410
         return 0;
1355 1411
     }
1356 1412
 
1357 1413
     $queryExpirationDate = '';
1358
-    if (!empty($params['expiration_date'])) $queryExpirationDate = "expiration_date     = '".Database::escape_string($expiration_date)."', ";
1414
+    if (!empty($params['expiration_date'])) {
1415
+        $queryExpirationDate = "expiration_date     = '".Database::escape_string($expiration_date)."', ";
1416
+    }
1359 1417
 
1360 1418
     $sql = "INSERT INTO $table_user SET
1361 1419
             lastname            = '".Database::escape_string(trim($lastName))."',
@@ -1375,7 +1433,9 @@  discard block
 block discarded – undo
1375 1433
             ".$queryExpirationDate."
1376 1434
             hr_dept_id          = '".Database::escape_string($hr_dept_id)."',
1377 1435
             active              = '".Database::escape_string($active)."'";
1378
-    if ($debug) error_log($sql);
1436
+    if ($debug) {
1437
+        error_log($sql);
1438
+    }
1379 1439
 
1380 1440
     Database::query($sql);
1381 1441
     $return = Database::insert_id();
@@ -1387,7 +1447,9 @@  discard block
 block discarded – undo
1387 1447
 
1388 1448
         $url_id = api_get_current_access_url_id();
1389 1449
         UrlManager::add_user_to_url($return, $url_id);
1390
-        if ($debug) error_log("Adding user_id = $return to URL id $url_id ");
1450
+        if ($debug) {
1451
+            error_log("Adding user_id = $return to URL id $url_id ");
1452
+        }
1391 1453
 
1392 1454
         // Create extra field for the original_user_id_name
1393 1455
         UserManager::create_extra_field(
@@ -1424,7 +1486,9 @@  discard block
 block discarded – undo
1424 1486
             }
1425 1487
         }
1426 1488
     } else {
1427
-        if ($debug) error_log('Error while inserting a user');
1489
+        if ($debug) {
1490
+            error_log('Error while inserting a user');
1491
+        }
1428 1492
         return 0;
1429 1493
     }
1430 1494
 
@@ -4487,7 +4551,9 @@  discard block
 block discarded – undo
4487 4551
     if (!WSHelperVerifyKey($params)) {
4488 4552
         return returnError(WS_ERROR_SECRET_KEY);
4489 4553
     }
4490
-    if ($debug) error_log('WSSubscribeUserToCourse params: '.print_r($params,1));
4554
+    if ($debug) {
4555
+        error_log('WSSubscribeUserToCourse params: '.print_r($params,1));
4556
+    }
4491 4557
 
4492 4558
     $results = array();
4493 4559
     $userscourses = $params['userscourses'];
@@ -4506,7 +4572,9 @@  discard block
 block discarded – undo
4506 4572
             $original_user_id['original_user_id_value'],
4507 4573
             $original_user_id['original_user_id_name']
4508 4574
         );
4509
-        if ($debug) error_log('WSSubscribeUserToCourse user_id: '.$user_id);
4575
+        if ($debug) {
4576
+            error_log('WSSubscribeUserToCourse user_id: '.$user_id);
4577
+        }
4510 4578
 
4511 4579
         if ($user_id == 0) {
4512 4580
             // If user was not found, there was a problem
@@ -4524,13 +4592,19 @@  discard block
 block discarded – undo
4524 4592
                 // Course was not found
4525 4593
                 $resultValue = 0;
4526 4594
             } else {
4527
-                if ($debug) error_log('WSSubscribeUserToCourse courseCode: '.$courseCode);
4595
+                if ($debug) {
4596
+                    error_log('WSSubscribeUserToCourse courseCode: '.$courseCode);
4597
+                }
4528 4598
                 $result = CourseManager::add_user_to_course($user_id, $courseCode, $status, false);
4529 4599
                 if ($result) {
4530 4600
                     $resultValue = 1;
4531
-                    if ($debug) error_log('WSSubscribeUserToCourse subscribed');
4601
+                    if ($debug) {
4602
+                        error_log('WSSubscribeUserToCourse subscribed');
4603
+                    }
4532 4604
                 } else {
4533
-                    if ($debug) error_log('WSSubscribeUserToCourse NOT subscribed: ');
4605
+                    if ($debug) {
4606
+                        error_log('WSSubscribeUserToCourse NOT subscribed: ');
4607
+                    }
4534 4608
                 }
4535 4609
             }
4536 4610
         }
@@ -4588,8 +4662,12 @@  discard block
 block discarded – undo
4588 4662
 function WSSubscribeUserToCourseSimple($params) {
4589 4663
     global $debug;
4590 4664
 
4591
-    if ($debug) error_log('WSSubscribeUserToCourseSimple');
4592
-    if ($debug) error_log('Params '. print_r($params, 1));
4665
+    if ($debug) {
4666
+        error_log('WSSubscribeUserToCourseSimple');
4667
+    }
4668
+    if ($debug) {
4669
+        error_log('Params '. print_r($params, 1));
4670
+    }
4593 4671
     if (!WSHelperVerifyKey($params)) {
4594 4672
         return returnError(WS_ERROR_SECRET_KEY);
4595 4673
     }
@@ -4604,7 +4682,9 @@  discard block
 block discarded – undo
4604 4682
     if (empty($user_data)) {
4605 4683
         // If user was not found, there was a problem
4606 4684
         $result = "User $user_id does not exist";
4607
-        if ($debug) error_log($result);
4685
+        if ($debug) {
4686
+            error_log($result);
4687
+        }
4608 4688
         return $result;
4609 4689
     }
4610 4690
     if (!empty($course_code)) {
@@ -4612,14 +4692,22 @@  discard block
 block discarded – undo
4612 4692
         if (empty($course_data)) {
4613 4693
             // Course was not found
4614 4694
             $result = "Course $course_code does not exist in the platform ";
4615
-            if ($debug) error_log($result);
4695
+            if ($debug) {
4696
+                error_log($result);
4697
+            }
4616 4698
         } else {
4617
-            if ($debug) error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']);
4699
+            if ($debug) {
4700
+                error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']);
4701
+            }
4618 4702
             if (!CourseManager::add_user_to_course($user_id, $course_data['code'], $status)) {
4619 4703
                 $result = 'User was not registered possible reasons: User already registered to the course, Course visibility doesnt allow user subscriptions ';
4620
-                if ($debug) error_log($result);
4704
+                if ($debug) {
4705
+                    error_log($result);
4706
+                }
4621 4707
             } else {
4622
-                if ($debug) error_log('User registered to the course: '.$course_data['code']);
4708
+                if ($debug) {
4709
+                    error_log('User registered to the course: '.$course_data['code']);
4710
+                }
4623 4711
                 $result = 1;
4624 4712
             }
4625 4713
         }
@@ -4671,8 +4759,12 @@  discard block
 block discarded – undo
4671 4759
 // define the method WSGetUser
4672 4760
 function WSGetUser($params) {
4673 4761
     global $debug;
4674
-    if ($debug) error_log('WSGetUser');
4675
-    if ($debug) error_log('$params: '.print_r($params, 1));
4762
+    if ($debug) {
4763
+        error_log('WSGetUser');
4764
+    }
4765
+    if ($debug) {
4766
+        error_log('$params: '.print_r($params, 1));
4767
+    }
4676 4768
 
4677 4769
     if (!WSHelperVerifyKey($params)) {
4678 4770
         return returnError(WS_ERROR_SECRET_KEY);
@@ -4725,8 +4817,12 @@  discard block
 block discarded – undo
4725 4817
 // define the method WSGetUserFromUsername
4726 4818
 function WSGetUserFromUsername($params) {
4727 4819
     global $debug;
4728
-    if ($debug) error_log('WSGetUserFromUsername');
4729
-    if ($debug) error_log('$params: '.print_r($params, 1));
4820
+    if ($debug) {
4821
+        error_log('WSGetUserFromUsername');
4822
+    }
4823
+    if ($debug) {
4824
+        error_log('$params: '.print_r($params, 1));
4825
+    }
4730 4826
 
4731 4827
     if (!WSHelperVerifyKey($params)) {
4732 4828
         return returnError(WS_ERROR_SECRET_KEY);
@@ -5176,7 +5272,9 @@  discard block
 block discarded – undo
5176 5272
                 $orig_session_id_value[] = $original_session_id_value;
5177 5273
                 $results[] = 1;
5178 5274
 
5179
-                if ($debug) error_log("subscribe user:$user_id to session $sessionId");
5275
+                if ($debug) {
5276
+                    error_log("subscribe user:$user_id to session $sessionId");
5277
+                }
5180 5278
             }
5181 5279
         }
5182 5280
     } // end principal foreach
@@ -5260,7 +5358,9 @@  discard block
 block discarded – undo
5260 5358
                 SESSION_VISIBLE_READ_ONLY,
5261 5359
                 false
5262 5360
             );
5263
-            if ($debug) error_log('User registered to the course: '.$session_id);
5361
+            if ($debug) {
5362
+                error_log('User registered to the course: '.$session_id);
5363
+            }
5264 5364
             $result = 1;
5265 5365
         }
5266 5366
     }
@@ -5406,7 +5506,9 @@  discard block
 block discarded – undo
5406 5506
                 $orig_session_id_value[] = $original_session_id_value;
5407 5507
                 $results[] = 1;
5408 5508
 
5409
-                if ($debug) error_log("Unsubscribe user:$user_id to session:$id_session");
5509
+                if ($debug) {
5510
+                    error_log("Unsubscribe user:$user_id to session:$id_session");
5511
+                }
5410 5512
             }
5411 5513
         }
5412 5514
     } // end principal foreach
@@ -5553,7 +5655,9 @@  discard block
 block discarded – undo
5553 5655
         return returnError(WS_ERROR_SECRET_KEY);
5554 5656
     }
5555 5657
 
5556
-    if ($debug) error_log('WSSuscribeCoursesToSession: '.print_r($params, 1));
5658
+    if ($debug) {
5659
+        error_log('WSSuscribeCoursesToSession: '.print_r($params, 1));
5660
+    }
5557 5661
 
5558 5662
     $coursessessions_params = $params['coursessessions'];
5559 5663
     $results = array();
@@ -5591,7 +5695,9 @@  discard block
 block discarded – undo
5591 5695
                     array($courseInfo['real_id']),
5592 5696
                     false
5593 5697
                 );
5594
-                if ($debug) error_log("add_courses_to_session: course:$courseCode to session:$sessionId");
5698
+                if ($debug) {
5699
+                    error_log("add_courses_to_session: course:$courseCode to session:$sessionId");
5700
+                }
5595 5701
 
5596 5702
                 $results[] = 1;
5597 5703
                 $orig_course_id_value[] = $original_session_id_value;
@@ -5969,8 +6075,7 @@  discard block
 block discarded – undo
5969 6075
             UserManager::create_extra_field($params['original_user_id_name'], 1, $params['original_user_id_name'], '');
5970 6076
             // Save the external system's id into user_field_value table.
5971 6077
             UserManager::update_extra_field_value($user_id, $params['original_user_id_name'], $params['original_user_id_value']);
5972
-        }
5973
-        else {
6078
+        } else {
5974 6079
             return 0;
5975 6080
         }
5976 6081
     }
@@ -6126,8 +6231,12 @@  discard block
 block discarded – undo
6126 6231
 {
6127 6232
     global $debug;
6128 6233
 
6129
-    if ($debug) error_log('WSUserSubscribedInCourse');
6130
-    if ($debug) error_log('Params '. print_r($params, 1));
6234
+    if ($debug) {
6235
+        error_log('WSUserSubscribedInCourse');
6236
+    }
6237
+    if ($debug) {
6238
+        error_log('Params '. print_r($params, 1));
6239
+    }
6131 6240
     if (!WSHelperVerifyKey($params)) {
6132 6241
 
6133 6242
         return returnError(WS_ERROR_SECRET_KEY);
Please login to merge, or discard this patch.