@ -1,15 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/*
*
* 1. This script creates users everytime the page is executed using the Chamilo Webservices
/*
*
* 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.
* 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
@ -60,23 +60,27 @@ $params = array( 'firstname' => 'Jon',
'expiration_date' => '0000-00-00',
'original_user_id_name' => $user_field, // the extra user field that will be automatically created in the user profile see: main/admin/user_fields.php
'original_user_id_value' => $random_user_id, // third party user id
'secret_key' => $secret_key
'secret_key' => $secret_key,
'extra' => array(
array('field_name' => 'ruc', 'field_value' => '123'),
array('field_name' => 'DNI', 'field_value' => '4200000')
),
);
$user_id = $client->call('WSCreateUserPasswordCrypted', array('createUserPasswordCrypted' => $params));
if (!empty($user_id) & & is_numeric($user_id)) {
// 2. Get user info of the user
echo '< h2 > Trying to create an user via webservices< / h2 > ';
$original_params = $params;
$params = array('original_user_id_value' => $random_user_id, // third party user id
'original_user_id_name' => $user_field, // the system field in the user profile (See Profiling)
'secret_key' => $secret_key);
$result = $client->call('WSGetUser', array('GetUser' => $params));
if ($result) {
echo "Random user was created user_id: $user_id < br / > < br / > ";
echo 'User info: < br / > ';
@ -85,14 +89,49 @@ if (!empty($user_id) && is_numeric($user_id)) {
} else {
echo $result;
}
//3.Adding user to the course TEST. The course TEST must be created manually in Chamilo
//3. Updating user info
$params = array(
'firstname' => 'Jon edited',
'lastname' => 'Brion edited',
'status' => '5', // STUDENT
'email' => 'jon@example.com',
'username' => $generate_user_name,
'password' => $generate_password, // encrypted using sha1
'encrypt_method' => 'sha1',
'phone' => '00000000',
'expiration_date' => '0000-00-00',
'original_user_id_name' => $user_field, // the extra user field that will be automatically created in the user profile see: main/admin/user_fields.php
'original_user_id_value' => $random_user_id, // third party user id
'secret_key' => $secret_key,
'extra' => array(
array('field_name' => 'ruc', 'field_value' => '666 edited'),
array('field_name' => 'DNI', 'field_value' => '888 edited')
),
);
$result = $client->call('WSEditUserPasswordCrypted', array('editUserPasswordCrypted' => $params));
if ($result) {
echo "Random user was update user_id: $user_id < br / > < br / > ";
echo 'User info: < br / > ';
print_r($params);
echo '< br / > < br / > ';
} else {
$err = $client->getError();
var_dump($result);
var_dump($err);
}
exit;
//4 .Adding user to the course TEST. The course TEST must be created manually in Chamilo
echo '< h2 > Trying to add user to a course called TEST via webservices< / h2 > ';
$course_info = api_get_course_info('TEST');
if (!empty($course_info)) {
if (!empty($course_info)) {
$params = array('course' => 'TEST', //Chamilo string course code
'user_id' => $user_id,
'secret_key' => $secret_key);
@ -100,55 +139,55 @@ if (!empty($user_id) && is_numeric($user_id)) {
} else {
echo 'Course TEST does not exists please create one course with code "TEST"';
}
if ($result == 1) {
echo "User $user_id was added to course TEST";
} else {
echo $result;
}
}
//4. Adding course Test to the Session Session1
$course_id_list = array (
array('course_code' => 'TEST1'),
array('course_code' => 'TEST1'),
array('course_code' => 'TEST2')
);
$params = array('coursessessions' => array(
array('original_course_id_values' => $course_id_list,
'original_course_id_name' => 'course_id_name',
'original_session_id_value' => '1',
'original_session_id_name' => 'session_id_value')
),
'original_session_id_name' => 'session_id_value')
),
'secret_key' => $secret_key);
//$result = $client->call('WSSuscribeCoursesToSession', array('subscribeCoursesToSession' => $params));
// ------------------------
//Calling the WSSubscribeUserToCourse
/*
$course_array = array( 'original_course_id_name' => 'TEST',
'original_course_id_value' => 'TEST'
);
$user_array = array('original_user_id_value' => $user_id,
$user_array = array('original_user_id_value' => $user_id,
'original_user_id_name' => 'name');
$user_courses = array();
$user_courses[] = array ( 'course_id' => $course_array,
'user_id' => $user_array,
'status' => '1'
);
$params = array (
'userscourses' => $user_courses,
'secret_key' => $secret_key);
$result = $client->call('WSSubscribeUserToCourse', array('subscribeUserToCourse' => $params));
var_dump($result);*/
} else {
echo 'User was not created, activate the debug=true in the registration.soap.php file and see the error logs';
}