ho 100 utenti da importare su joomla tramite database importo il csv ma come faccio criptare la password con il tool che mi è stato fornito lo faccio 1 volta per ogni singolo utente qualcuno sa darmi una mano???
<?php
/* Import Joomla User from CSV file
* Author:
* Date :
*/
require_once( JPATH_ROOT . "/libraries/joomla/user/helper.php" ); // Needed to create password
function importJoomlaUsers( $source ) {
/* Include the Joomla user helper */
jimport('joomla.user.helper');
$db =& JFactory::getDBO();
/* Check the user file exists */
if (file_exists( $source )) {
/* Open the file */
$handle = fopen($userFile,"r");
$content = fread ($handle,filesize ( $source ));
fclose($handle);
/* Get the file, line by line */
$lines = explode("\n", $content);
/* Remove the first line (headers only) */
unset($lines[0]);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
foreach ($lines as $key => $line){
/* Split the line by comma */
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$line = preg_split('/,/', $line);
/* Build a new user object */
$user =& JTable::getInstance('juser','Table');
$user->id = 0;
/* Set the values */
$user->name = $line[2];
$user->username = $line[12];
$user->email = $line[11];
$user->groups = array(2);
/* Build the password */
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword( preg_replace("/\s/", "", strtolower($line[13])) , $salt);
$newpassword = $crypted . ':' . $salt;
$user->password = $newpassword;
$user->usertype = "deprecated";
$user->registerDate = date('Y-m-d H:i:s');
if(!$user->store()) JError::raiseError(500,$user->getError() );
else $added++;
/* Remove any old group allocations */
$query = "DELETE FROM jos_user_usergroup_map
WHERE user_id = {$user->id}
AND group_id = 2";
$db->setQuery( $query );
if( !$result = $db->query() ) die("Error: $result");
/* Create the new group allocations */
$query = "INSERT INTO jos_user_usergroup_map (user_id,group_id) values ({$user->id},2)";
$db->setQuery( $query );
if(! $result = $db->query() ) die("Error: $result");
}
}else{
die('Could not find users import file: ' . $source);
}
die("Successfully added $added users.");
}
?>
<?php
importJoomlaUsers( '/path/filename.csv');
?>
può essere una soluzione