diff --git a/main/webservices/client_soap.php b/main/webservices/client_soap.php index dd02fb44cc..5661889f0d 100755 --- a/main/webservices/client_soap.php +++ b/main/webservices/client_soap.php @@ -3,20 +3,21 @@ /* * - * 1. This script creates users everytime the page is executed using the Chamilo Webservices - * 2. The username is generated everytime with a random value from 0 to 1000 - * 3. The default user extra field (profile) is "uid" is created when calling the WSCreateUserPasswordCrypted for the first time, you can change this value. - * In this field your third party user_id will be registered. See the main/admin/user_fields.php to view the current user fields. - * 4. You need to create manually a course called Test(with code TEST) After the user was created the new user will be added to this course via webservices. - + * 1. This script creates users every time the page is executed using the Chamilo Webservices + * 2. The username is generated every time with a random value from 0 to 1000 + * 3. The default user extra field (profile) is "uid" is created + * + * when calling the WSCreateUserPasswordCrypted for the first time, you can change this value. + * In this field your third party user_id will be registered. + * See the main/admin/user_fields.php to view the current user fields. + * 4. You need to create manually a course called Test(with code TEST) + * After the user was created the new user will be added to this course via webservices. * */ - -exit; //Uncomment this in order to execute the page - +exit; require_once __DIR__.'/../inc/global.inc.php'; // Create the client instance -$url = api_get_path(WEB_CODE_PATH)."webservices/registration.soap.php?wsdl"; +$url = api_get_path(WEB_CODE_PATH).'webservices/registration.soap.php?wsdl'; //$url = api_get_path(WEB_CODE_PATH)."webservices/access_url.php?wsdl"; global $_configuration; @@ -55,35 +56,35 @@ $generate_password = sha1($generate_user_name); $user_field = 'uid'; $sessionField = 'external_session_id'; -$params = array( - 'firstname' => 'Jon', - 'lastname' => 'Brion', - 'status' => '5', // 5 STUDENT - 1 TEACHER - 'email' => 'jon@example.com', - 'loginname' => $generate_user_name, - 'password' => $generate_password, // encrypted using sha1 - 'encrypt_method' => 'sha1', - 'language' => 'english', - 'official_code' => 'official', - 'phone' => '00000000', - 'expiration_date' => '0000-00-00', +$params = [ + 'firstname' => 'Jon', + 'lastname' => 'Brion', + 'status' => '5', // 5 STUDENT - 1 TEACHER + 'email' => 'jon@example.com', + 'loginname' => $generate_user_name, + 'password' => $generate_password, // encrypted using sha1 + 'encrypt_method' => 'bcrypt', + 'language' => 'english', + 'official_code' => 'official', + 'phone' => '00000000', + 'expiration_date' => '0000-00-00', /* the extra user field that will be automatically created in the user profile see: main/admin/user_fields.php */ - 'original_user_id_name' => $user_field, + 'original_user_id_name' => $user_field, // third party user id - 'original_user_id_value' => $random_user_id, - 'secret_key' => $secret_key, + 'original_user_id_value' => $random_user_id, + 'secret_key' => $secret_key, // Extra fields - 'extra' => array( - array('field_name' => 'ruc', 'field_value' => '123'), - array('field_name' => 'DNI', 'field_value' => '4200000') - ), -); + 'extra' => [ + ['field_name' => 'ruc', 'field_value' => '123'], + ['field_name' => 'DNI', 'field_value' => '4200000'], + ], +]; //1. Create user webservice $user_id = $client->call( 'WSCreateUserPasswordCrypted', - array('createUserPasswordCrypted' => $params) + ['createUserPasswordCrypted' => $params] ); // Check for an error @@ -94,7 +95,6 @@ if ($err) { echo '
'.$err.''; } - $sessionValueRandom = uniqid(); $params = [ @@ -119,9 +119,9 @@ $params = [ 'secret_key' => $secret_key, ]; -$user_id = $client->call( +$sessionId = $client->call( 'WSCreateSession', - array('createSession' => $params) + ['createSession' => $params] ); @@ -143,28 +143,25 @@ $data = [ $result = $client->call( 'WSSuscribeUsersToSession', - array('subscribeUsersToSession' => $data) + ['subscribeUsersToSession' => $data] ); $err = $client->getError(); var_dump($result); var_dump($err); - - - +var_dump($user_id); if (!empty($user_id) && is_numeric($user_id)) { - // 2. Get user info of the new user echo '
'.$err.''; } - //1. Create user webservice $result = $client->call( 'WSGetPortals', - array('getPortals' => ['secret_key' => $secret_key]) + ['getPortals' => ['secret_key' => $secret_key]] ); $result = $client->call( 'WSAddUserToPortal', - array('addUserToPortal' => ['user_id' => 1, 'portal_id'=> 1, 'secret_key' => $secret_key]) + ['addUserToPortal' => ['user_id' => 1, 'portal_id' => 1, 'secret_key' => $secret_key]] ); $result = $client->call( 'WSGetPortalListFromUser', - array('getPortalListFromUser' => ['user_id' => 1, 'secret_key' => $secret_key]) + ['getPortalListFromUser' => ['user_id' => 1, 'secret_key' => $secret_key]] ); $result = $client->call( 'WSGetPortalListFromCourse', - array('getPortalListFromCourse' => ['course_id' => 20, 'secret_key' => $secret_key]) + ['getPortalListFromCourse' => ['course_id' => 20, 'secret_key' => $secret_key]] ); $result = $client->call( 'WSAddCourseToPortal', - array('addCourseToPortal' => ['course_id' => 20, 'portal_id' => 1, 'secret_key' => $secret_key]) + ['addCourseToPortal' => ['course_id' => 20, 'portal_id' => 1, 'secret_key' => $secret_key]] ); - $result = $client->call( 'WSRemoveUserFromPortal', - array('removeUserFromPortal' => ['course_id' => 20, 'portal_id'=> 1, 'secret_key' => $secret_key]) + ['removeUserFromPortal' => ['course_id' => 20, 'portal_id' => 1, 'secret_key' => $secret_key]] ); - - var_dump($user_id); exit; - - - - - - if ($client->fault) { echo '
';
print_r($result);
diff --git a/main/webservices/registration.soap.php b/main/webservices/registration.soap.php
index 4cb4642e43..068a058e89 100755
--- a/main/webservices/registration.soap.php
+++ b/main/webservices/registration.soap.php
@@ -1215,21 +1215,21 @@ $server->wsdl->addComplexType(
'all',
'',
array(
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'), //encripted password using the encrypt_method
- 'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
- 'language' => array('name' => 'language', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'official_code' => array('name' => 'official_code', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
+ 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
+ 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
+ 'status' => array('name' => 'status', 'type' => 'xsd:string'),
+ 'email' => array('name' => 'email', 'type' => 'xsd:string'),
+ 'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
+ 'password' => array('name' => 'password', 'type' => 'xsd:string'), //encripted password using the encrypt_method
+ 'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
+ 'language' => array('name' => 'language', 'type' => 'xsd:string'),
+ 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
+ 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
+ 'official_code' => array('name' => 'official_code', 'type' => 'xsd:string'),
+ 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
+ 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
+ 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
+ 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
)
);
@@ -1250,9 +1250,10 @@ function WSCreateUserPasswordCrypted($params)
{
global $_configuration, $debug;
$debug = 1;
- if ($debug) error_log('WSCreateUserPasswordCrypted');
- if ($debug) error_log(print_r($params, 1));
-
+ if ($debug) {
+ error_log('WSCreateUserPasswordCrypted');
+ error_log(print_r($params, 1));
+ }
if (!WSHelperVerifyKey($params)) {
return returnError(WS_ERROR_SECRET_KEY);
}
@@ -1371,7 +1372,11 @@ function WSCreateUserPasswordCrypted($params)
return 0;
}
} else {
- if ($debug) error_log("User not found with original_id = $original_user_id_value and original_name = $original_user_id_name");
+ if ($debug) {
+ error_log(
+ "User not found with original_id = $original_user_id_value and original_name = $original_user_id_name"
+ );
+ }
}
// Default language.
@@ -1383,12 +1388,16 @@ function WSCreateUserPasswordCrypted($params)
// First check wether the login already exists
if (!UserManager::is_username_available($loginName)) {
- if ($debug) error_log("Username $loginName is not available");
+ if ($debug) {
+ error_log("Username $loginName is not available");
+ }
return 0;
}
$queryExpirationDate = '';
- if (!empty($params['expiration_date'])) $queryExpirationDate = "expiration_date = '".Database::escape_string($expiration_date)."', ";
+ if (!empty($params['expiration_date'])) {
+ $queryExpirationDate = "expiration_date = '".Database::escape_string($expiration_date)."', ";
+ }
$sql = "INSERT INTO $table_user SET
lastname = '".Database::escape_string(trim($lastName))."',
@@ -1413,12 +1422,17 @@ function WSCreateUserPasswordCrypted($params)
Database::query($sql);
$return = Database::insert_id();
if ($return) {
+ if ($debug) {
+ error_log("New user created. user_id = $return");
+ }
$sql = "UPDATE $table_user SET user_id = id WHERE id = $return";
Database::query($sql);
$url_id = api_get_current_access_url_id();
UrlManager::add_user_to_url($return, $url_id);
- if ($debug) error_log("Adding user_id = $return to URL id $url_id ");
+ if ($debug) {
+ error_log("Adding user_id = $return to URL id $url_id ");
+ }
// Create extra field for the original_user_id_name
UserManager::create_extra_field(
@@ -1437,8 +1451,8 @@ function WSCreateUserPasswordCrypted($params)
// Create extra fields
if (is_array($extra_list) && count($extra_list) > 0) {
foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
+ $extra_field_name = $extra['field_name'];
+ $extra_field_value = $extra['field_value'];
// save new fieldlabel into user_field table
UserManager::create_extra_field(
$extra_field_name,
@@ -1455,11 +1469,15 @@ function WSCreateUserPasswordCrypted($params)
}
}
} else {
- if ($debug) error_log('Error while inserting a user');
+ if ($debug) {
+ error_log('Error while inserting a user');
+ }
return 0;
}
-
+ if ($debug) {
+ error_log("Return value: $return");
+ }
return $return;
}
@@ -2666,6 +2684,12 @@ $server->wsdl->addComplexType(
function WSHelperActionOnUsers($params, $type)
{
+ $debug = 1;
+ if ($debug) {
+ error_log("WSHelperActionOnUsers");
+ error_log(print_r($params, 1));
+ }
+
if (!WSHelperVerifyKey($params)) {
return returnError(WS_ERROR_SECRET_KEY);
}
@@ -2681,18 +2705,24 @@ function WSHelperActionOnUsers($params, $type)
$original_user_id['original_user_id_name']
);
if ($user_id > 0) {
- if ($type == "delete") {
+ if ($debug) {
+ error_log("User found: $user_id");
+ }
+ if ($type == 'delete') {
$result = UserManager::delete_user($user_id);
- } else if ($type == "disable") {
+ } elseif ($type == "disable") {
$result = UserManager::disable($user_id);
- } else if ($type == "enable") {
+ } elseif ($type == "enable") {
$result = UserManager::enable($user_id);
}
+ } else {
+ if ($debug) {
+ error_log("User id not found: $user_id");
+ }
}
$results[] = $result ? 1 : 0;
}
-
$count_results = count($results);
$output = array();
for ($i = 0; $i < $count_results; $i++) {
@@ -2718,7 +2748,7 @@ $server->register(
function WSDeleteUsers($params)
{
- return WSHelperActionOnUsers($params, "delete");
+ return WSHelperActionOnUsers($params, 'delete');
}
/** WSDisableUsers **/
@@ -4534,7 +4564,9 @@ function WSSubscribeUserToCourse($params)
if (!WSHelperVerifyKey($params)) {
return returnError(WS_ERROR_SECRET_KEY);
}
- if ($debug) error_log('WSSubscribeUserToCourse params: '.print_r($params, 1));
+ if ($debug) {
+ error_log('WSSubscribeUserToCourse params: '.print_r($params, 1));
+ }
$results = array();
$userscourses = $params['userscourses'];
@@ -4553,7 +4585,9 @@ function WSSubscribeUserToCourse($params)
$original_user_id['original_user_id_value'],
$original_user_id['original_user_id_name']
);
- if ($debug) error_log('WSSubscribeUserToCourse user_id: '.$user_id);
+ if ($debug) {
+ error_log('WSSubscribeUserToCourse user_id: '.$user_id);
+ }
if ($user_id == 0) {
// If user was not found, there was a problem
@@ -4565,7 +4599,7 @@ function WSSubscribeUserToCourse($params)
$original_course_id['original_course_id_name']
);
- $courseCode = $courseInfo['code'];
+ $courseCode = isset($courseInfo['code']) ? $courseInfo['code'] : '';
if (empty($courseCode)) {
// Course was not found