ugly script, but it does the job well. I named the file import.php, placed it in my install root, and added a link to it in my addressbook file (skins/default/templates/addressbook.html)
import.php<?php
/* ************************************ */
/* Roundcube DB connection data */
/* ************************************ */
$host = "****"; //edit this
$user = "****"; //edit this
$password = "****"; //edit this
$db = "****"; //edit this
/* ************************************ */
/* END Roundcube DB connection data */
/* ************************************ */
$domain = "@domain.com"; //change this, and make sure to leave the "@"
$link = mysql_connect($host, $user, $password);
mysql_select_db($db, $link);
session_start();
$session = $_COOKIE['roundcube_sessid'];
$sql = "SELECT `vars` FROM `session` WHERE `sess_id`='$session' LIMIT 1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$data = $row['vars'];
$data_array = explode(";", $data);
foreach ($data_array as $value){
if (strstr($value, "username")){
$temp_array = explode("\"", $value);
$username2 = $temp_array[1];
}
if (strstr($value, "user_id")){
$temp_array = explode("\"", $value);
$userid = $temp_array[1];
}
}
mysql_close($link);
/* ************************************ */
/* Horde DB connection data */
/* ************************************ */
$username = "****"; //edit this
$password = "****"; //edit this
$host = "****"; //edit this
$db = "****"; //edit this
/* ************************************ */
/* END Horde DB connection data */
/* ************************************ */
$link2 = mysql_connect($host, $username, $password) or die("connection error");
mysql_select_db($db, $link2);
$user = $username2;
if (strstr($user, $domain)){
$user = str_replace($domain, "", $user);
}
$sql = "select object_name, object_alias, object_email from turba_objects where owner_id = '$user';";
$result = mysql_query($sql);
$sql2 = "INSERT INTO `contacts`(`contact_id`, `user_id`, `email`, `firstname`, `surname`) VALUES";
$count = 0;
while ($row = mysql_fetch_assoc($result)){
$name = $row['object_name'];
if (strstr($name, " ")){
$temp_array = explode(" ", $name);
if (count($temp_array) == 2){
$name = $temp_array[0];
$last_name = $temp_array[1];
}
else{
$name = $temp_array[0];
$last_name = array_pop($temp_array);
}
}
else{
$last_name = "";
}
$alias = $row['object_alias'];
$email = $row['object_email'];
if ($count == 0){
$sql2 .= "('', '$userid', '$email', '$name', '$last_name')";
$count++;
}
else{
$sql2 .= ", ('', '$userid', '$email', '$name', '$last_name')";
}
}
$sql2 .= ";";
mysql_close($link2);
/* ************************************ */
/* Roundcube DB connection data */
/* ************************************ */
$host = "****"; //edit this
$user = "****"; //edit this
$password = "****"; //edit this
$db = "*****"; //edit this
/* ************************************ */
/* END Roundcube DB connection data */
/* ************************************ */
$link = mysql_connect($host, $user, $password);
mysql_select_db("roundcube", $link);
$sql3 = "SELECT * FROM `users` WHERE `imported`!=1 AND `user_id`='$userid' LIMIT 1;";
$result3 = mysql_query($sql3);
if (mysql_num_rows($result3) != 1){
header("location:./?_task=addressbook");
exit();
}
mysql_query($sql2);
$sql = "UPDATE `users` SET `imported`='1' WHERE `user_id`='$userid' LIMIT 1;";
mysql_query($sql);
header("location:./?_task=addressbook");
exit();
?>oh, and run this SQL string on your users table:
ALTER TABLE `users` ADD `imported` TINYINT( 1 ) NOT NULL ;