can someone help me with this php-script, this script is for Joomla 1.5 and I am using 2.5. This is not compatible and I am confused of the tables used because 1.5 and 2.5 has different table names. some tables in 1.5 are not also in 2.5
btw, this script is a bulk user import using csv file to sql/database.
<?php
// Hande form upload
if(isset($_POST['import'])) {
$mysql_host = trim($_POST['mysql_host']);
$mysql_user = trim($_POST['mysql_username']);
$mysql_password = trim($_POST['mysql_password']);
$mysql_schema = trim($_POST['mysql_schema']);
$table_prefix = trim($_POST['table_prefix']);
if(!mysql_connect($mysql_host, $mysql_user, $mysql_password) || !mysql_select_db($mysql_schema)) {
echo 'Supplied MySQL details were incorrect - aborting';
return;
}
// Get the joomla groups
$sql = sprintf('
SELECT `id`, `value`
FROM `%score_acl_aro_groups`
',
$table_prefix
);
$rs = mysql_query($sql);
$groups = array();
while($group = mysql_fetch_object($rs)) {
$groups[$group->value] = $group->id;
}
$fp = fopen($_FILES['csv']['tmp_name'], 'r');
while($user = fgetcsv($fp)) {
printf('Importing "%s" ... ', $user[0]);
// Lookup and verify user group
if(!isset($groups[$user[4]])) {
printf('error: Invalid group (%s) for %s. Defaulting to <code>Registered</code><br />%s', $user[4], $user[0], PHP_EOL);
$user[4] = 'Registered';
}
// Insert record into wsers
$sql = sprintf('
INSERT INTO `%susers`
SET
`name` = "%s",
`username` = "%s",
`email` = "%s",
`password` = "%s",
`usertype` = "%s",
`block` = "%s",
`sendEmail` = "%s",
`gid` = "%s",
`registerDate` = NOW(),
`lastvisitDate` = "0000-00-00 00:00:00",
`activation` = "",
`params` = ""
',
$table_prefix,
sql_prep($user[0]),
sql_prep($user[1]),
sql_prep($user[2]),
isset($_POST['md5_passwords']) ? md5($user[3]) : sql_prep($user[3]),
sql_prep($user[4]),
sql_prep($user[5]),
sql_prep($user[6]),
$groups[$user[4]]
);
mysql_query($sql);
// Get back ther user's ID
list($user_id) = mysql_fetch_row(mysql_query('SELECT LAST_INSERT_ID()'));
// Insert record into core_acl_aro
$sql = sprintf('
INSERT INTO `%score_acl_aro`
SET
`section_value` = "users",
`value` = %d,
`name` = "%s"
',
$table_prefix,
$user_id,
sql_prep($user[0])
);
mysql_query($sql);
// Insert record into core_acl_groups_aro_map
$sql = sprintf('
INSERT INTO `%score_acl_groups_aro_map`
SET
`group_id` = %d,
`aro_id` = LAST_INSERT_ID()
',
$table_prefix,
$groups[$user[4]]
);
mysql_query($sql);
echo 'done.';
flush();
}
echo '<br /><br /><strong>Done</strong>';
} else {
// show upload form
?>
<html><head><title>Bulk import users into Joomla 1.5</title></head><body>
<h1>Import Users to Joomla</h1>
<p>
Use this script to do a bulk import of users into Joomla 1.5.<br />
Upload a CSV file with the following format:<br />
<code>
name, username, email, password, usertype, block, send_email
</code><br />
Wrap details with commas in them in quotes.
</p>
<hr />
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="import" value="1" />
<table cellpadding="4px">
<tr>
<td>CSV File: </td>
<td><input type="file" name="csv" /></td>
</tr>
<tr>
<td>MD5 Hash Passwords: </td>
<td><input type="checkbox" name="md5_passwords" /><br /><small>*Check this option if the passwords in your CSV are in plain text</small></td>
</tr>
<tr>
<td>Joomla Table Prefix: </td>
<td><input type="text" name="table_prefix" value="jos_" /></td>
</tr>
<tr>
<td>Joomla Database Name: </td>
<td><input type="text" name="mysql_schema" value="joomla" /></td>
</tr>
<tr>
<td>MySQL Host: </td>
<td><input type="text" name="mysql_host" value="localhost" /></td>
</tr>
<tr>
<td>MySQL Username: </td>
<td><input type="text" name="mysql_username" value="" /></td>
</tr>
<tr>
<td>MySQL Password: </td>
<td><input type="text" name="mysql_password" value="" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value=" Import Users! " /></td>
</tr>
</table>
</form>
</body></html>
<?php
}
function sql_prep($var) {
return mysql_real_escape_string($var);
}