[dev] [turba-patch] replace addressbook with imported one
Francois Marier
francois at nit.ca
Thu Jul 29 10:42:50 PDT 2004
This patch adds an option (false by default) to the import page of
Turba that purges the addressbook before adding the contacts. It also
prints a clear warning that all previous entries will be lost beside
the option.
I don't know if you'll be interested in this feature, but some people
find it useful. For example, they keep their addressbook in Evolution
and once in a while import it into Horde their web version of it.
Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/turba/data.php turba/data.php
--- ../build/turba/data.php Thu Jul 29 13:33:29 2004
+++ turba/data.php Thu Jul 29 13:31:53 2004
@@ -117,6 +117,7 @@ case 'export':
case IMPORT_FILE:
$_SESSION['import_data']['target'] = Util::getFormData('dest');
+ $_SESSION['import_data']['purge'] = Util::getFormData('purge');
break;
case IMPORT_MAPPED:
@@ -154,6 +155,16 @@ if (is_array($next_step)) {
if (is_a($storage, 'PEAR_Error')) {
$notification->push(_("Failed to connect to the specified directory."), 'horde.error');
} else {
+ //Purge old address book
+ $purge = $_SESSION['import_data']['purge'];
+ if ($purge) {
+ if ($storage->purgeAddresses()) {
+ $notification->push(_("Address book successfully purged."), 'horde.success');
+ } else {
+ $notification->push(_("The address book could not be purged."), 'horde.error');
+ }
+ }
+
$error = false;
foreach ($next_step as $row) {
$row['__owner'] = Auth::getAuth();
diff -rpuN -X ../ignorelist ../build/turba/lib/Driver/sql.php turba/lib/Driver/sql.php
--- ../build/turba/lib/Driver/sql.php Wed Apr 7 10:43:52 2004
+++ turba/lib/Driver/sql.php Thu Jul 29 13:31:51 2004
@@ -302,4 +302,19 @@ class Turba_Driver_sql extends Turba_Dri
return String::convertCharset($value, NLS::getCharset(), $this->_params['charset']);
}
+ /**
+ * Deletes all contacts from the addressbook.
+ *
+ * @return True if the operation worked
+ *
+ */
+ function purgeAddresses()
+ {
+ $user = Auth::getAuth();
+ $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE owner_id=' .
+ $this->_db->quote($user);
+ $result = $this->_db->query($query);
+ return $result;
+ }
+
}
diff -rpuN -X ../ignorelist ../build/turba/lib/Driver.php turba/lib/Driver.php
--- ../build/turba/lib/Driver.php Tue Feb 24 14:31:00 2004
+++ turba/lib/Driver.php Thu Jul 29 13:31:51 2004
@@ -185,4 +185,15 @@ class Turba_Driver {
return $instances[$signature];
}
+ /**
+ * Deletes all contacts from the addressbook.
+ *
+ * @return True if the operation worked
+ *
+ */
+ function purgeAddresses()
+ {
+ return false;
+ }
+
}
diff -rpuN -X ../ignorelist ../build/turba/lib/Source.php turba/lib/Source.php
--- ../build/turba/lib/Source.php Mon May 24 20:11:06 2004
+++ turba/lib/Source.php Thu Jul 29 13:31:51 2004
@@ -524,4 +524,12 @@ class Turba_Source {
return $instances[$signature];
}
+ /**
+ * Deletes every entry from the contact source.
+ */
+ function purgeAddresses()
+ {
+ return $this->driver->purgeAddresses();
+ }
+
}
diff -rpuN -X ../ignorelist ../build/turba/templates/data/import.inc turba/templates/data/import.inc
--- ../build/turba/templates/data/import.inc Thu Jul 29 13:33:29 2004
+++ turba/templates/data/import.inc Thu Jul 29 13:33:12 2004
@@ -22,6 +22,11 @@
<option value="pine"><?php echo _("Pine Address Book") ?></option>
</select><br />
+ <input type="checkbox" align=middle name="purge" value="1" />
+ <?= _("Replace existing addressbook with the imported one? <b>(Warning: ".
+ "This deletes all entries in your current addressbook)</b>") ?>
+ <br />
+
<?php if (count($dest_options) > 1): ?>
<br />
<?php echo _("Select the destination to import to:") ?><br />
More information about the dev
mailing list