upgrade
This commit is contained in:
36
main/cron/user_import/client.php
Normal file
36
main/cron/user_import/client.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/* See license terms in /license.txt */
|
||||
|
||||
/**
|
||||
* This is a script used to automatically import a list of users from
|
||||
* a CSV file into Dokeos.
|
||||
* It is triggered by a cron task configured on the server.
|
||||
*
|
||||
* @uses /main/webservices/user_import/
|
||||
*
|
||||
* @author Eric Marguin <eric.marguin@dokeos.com>
|
||||
*
|
||||
* @package chamilo.cron
|
||||
*/
|
||||
/**
|
||||
* Global cycle: init, execute, output.
|
||||
*/
|
||||
require_once __DIR__.'/../../inc/global.inc.php';
|
||||
// check if this client has been called by php_cli (command line or cron)
|
||||
if (php_sapi_name() != 'cli') {
|
||||
echo 'You can\'t call this service through a browser';
|
||||
exit();
|
||||
}
|
||||
|
||||
// create client
|
||||
$client = new nusoap_client(api_get_path(WEB_CODE_PATH).'cron/user_import/service.php');
|
||||
|
||||
// call import_user method
|
||||
$response = $client->call(
|
||||
'import_users',
|
||||
[
|
||||
'filepath' => api_get_path(SYS_UPLOAD_PATH)."users_import.csv",
|
||||
'security_key' => api_get_configuration_value('security_key'),
|
||||
]
|
||||
);
|
||||
echo $response;
|
||||
35
main/cron/user_import/get_data_from_mail.php
Normal file
35
main/cron/user_import/get_data_from_mail.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* This script gets users details of a given list of users
|
||||
* (given by e-mail) and prints the details in /tmp/list.txt
|
||||
* To enable script, prefix the first die(); with //.
|
||||
*
|
||||
* @package chamilo.cron.user_import
|
||||
*/
|
||||
/**
|
||||
* Initialization.
|
||||
*/
|
||||
/* Example of input file:
|
||||
sam@example.com
|
||||
Matthew@example.com
|
||||
HERMAN@example.com
|
||||
*/
|
||||
exit();
|
||||
//change filename depending on file containing mails list
|
||||
$list = file('input.txt');
|
||||
require_once '../../inc/global.inc.php';
|
||||
$users = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$string = '';
|
||||
foreach ($list as $mail) {
|
||||
$mail = trim($mail);
|
||||
$sql = "SELECT user_id, official_code, firstname, lastname, email FROM $users WHERE email = '$mail'\n";
|
||||
$res = Database::query($sql);
|
||||
if (Database::num_rows($res) == 0) {
|
||||
$string .= 'No encontrado;'.$row['email'];
|
||||
} else {
|
||||
$row = Database::fetch_assoc($res);
|
||||
$string .= $row['user_id'].';'.$row['email'].';'.$row['firstname'].';'.$row['lastname'].';'.$row['official_code']."\r\n";
|
||||
}
|
||||
}
|
||||
echo $string;
|
||||
file_put_contents('/tmp/list.txt', $string);
|
||||
88
main/cron/user_import/resend_email_with_new_password.php
Normal file
88
main/cron/user_import/resend_email_with_new_password.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This script updates the passwords of a given list of users
|
||||
* (given by e-mail) and resends them their account creation
|
||||
* confirmation e-mail.
|
||||
* Note that the password generation has been simplified, which
|
||||
* means the password below is not really "safe"
|
||||
* To enable script, prefix the first die(); with //.
|
||||
*
|
||||
* @package chamilo.cron.user_import
|
||||
*/
|
||||
/**
|
||||
* Initialization.
|
||||
*/
|
||||
/* Example of input file:
|
||||
sam@example.com
|
||||
Matthew@example.com
|
||||
HERMAN@example.com
|
||||
*/
|
||||
exit();
|
||||
//change filename depending on file containing mails list, with one e-mail per line.
|
||||
$list = file('input.txt');
|
||||
require_once '../../inc/global.inc.php';
|
||||
$users = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$userManager = UserManager::getManager();
|
||||
$repository = UserManager::getRepository();
|
||||
|
||||
/**
|
||||
* E-mails list loop.
|
||||
*/
|
||||
foreach ($list as $mail) {
|
||||
$mail = trim($mail);
|
||||
$sql = "SELECT user_id, official_code, firstname, lastname, email, username, language
|
||||
FROM $users WHERE email = '$mail'\n";
|
||||
$res = Database::query($sql);
|
||||
if ($res === false) {
|
||||
echo 'Error in database with email '.$mail."\n";
|
||||
}
|
||||
if (Database::num_rows($res) == 0) {
|
||||
echo '[Error] Email not found in database: '.$row['email']."\n";
|
||||
} else {
|
||||
$row = Database::fetch_assoc($res);
|
||||
$pass = api_substr($row['username'], 0, 4).rand(0, 9).rand(0, 9);
|
||||
|
||||
if ($user) {
|
||||
/** @var User $user */
|
||||
$user = $repository->find($row['user_id']);
|
||||
$user->setPlainPassword($pass);
|
||||
$userManager->updateUser($user, true);
|
||||
} else {
|
||||
echo "[Error] Error updating password. Skipping $mail\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = [
|
||||
'FirstName' => $row['firstname'],
|
||||
'LastName' => $row['lastname'],
|
||||
'UserName' => $row['username'],
|
||||
'Password' => $pass,
|
||||
'Email' => $mail,
|
||||
];
|
||||
$l = api_get_interface_language();
|
||||
if (!empty($row['language'])) {
|
||||
$l = $row['language'];
|
||||
}
|
||||
//This comes from main/admin/user_import.php::save_data() slightly modified
|
||||
$recipient_name = api_get_person_name(
|
||||
$user['FirstName'],
|
||||
$user['LastName'],
|
||||
null,
|
||||
PERSON_NAME_EMAIL_ADDRESS
|
||||
);
|
||||
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg', null, $l).' '.api_get_setting('siteName');
|
||||
$emailbody = get_lang('Dear', null, $l).' '.api_get_person_name($user['FirstName'], $user['LastName']).",\n\n".get_lang('YouAreReg', null, $l)." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings', null, $l)."\n\n".get_lang('Username', null, $l)." : ".$user['UserName']."\n".get_lang('Pass', null, $l)." : ".$user['Password']."\n\n".get_lang('Address', null, $l)." ".api_get_setting('siteName')." ".get_lang('Is', null, $l)." : ".api_get_path(WEB_PATH)." \n\n".get_lang('Problem', null, $l)."\n\n".get_lang('Formula', null, $l).",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".get_lang('Manager', null, $l)." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email', null, $l)." : ".api_get_setting('emailAdministrator')."";
|
||||
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
|
||||
$email_admin = api_get_setting('emailAdministrator');
|
||||
@api_mail_html(
|
||||
$recipient_name,
|
||||
$user['Email'],
|
||||
$emailsubject,
|
||||
$emailbody,
|
||||
$sender_name,
|
||||
$email_admin
|
||||
);
|
||||
echo "[OK] Sent to $mail with new password $pass (encrypted:$crypass)... w/ subject: $emailsubject\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user