Display selected set of duplicates and allow to delete them.
authorJan Schneider <jan@horde.org>
Fri, 2 Jul 2010 22:18:29 +0000 (00:18 +0200)
committerJan Schneider <jan@horde.org>
Mon, 5 Jul 2010 10:34:46 +0000 (12:34 +0200)
turba/lib/Form/Contact.php
turba/lib/View/DeleteContact.php
turba/lib/View/Duplicates.php
turba/search.php
turba/templates/search/duplicate/contact_footer.html.php [new file with mode: 0644]
turba/templates/search/duplicate/contact_header.html.php [new file with mode: 0644]
turba/templates/search/duplicate/footer.html.php [new file with mode: 0644]
turba/templates/search/duplicate/header.html.php [new file with mode: 0644]
turba/templates/search/duplicate/list.html.php [new file with mode: 0644]
turba/templates/search/duplicate_list.html.php [deleted file]
turba/themes/screen.css

index a66c1a9..5021e10 100644 (file)
@@ -4,7 +4,7 @@
  */
 class Turba_Form_Contact extends Horde_Form
 {
-    public function __construct(&$vars, &$contact)
+    public function __construct(&$vars, &$contact, $tabs = true)
     {
         global $conf, $notification;
 
@@ -17,7 +17,7 @@ class Turba_Form_Contact extends Horde_Form
         }
         $vars->set('object', $object);
 
-        $this->_addFields($contact);
+        $this->_addFields($contact, $tabs);
 
         /* List files. */
         $v_params = $GLOBALS['injector']->getInstance('Horde_Vfs')->getConfig('documents');
@@ -35,7 +35,7 @@ class Turba_Form_Contact extends Horde_Form
     /**
      * Set up the Horde_Form fields for $contact's attributes.
      */
-    function _addFields($contact)
+    function _addFields($contact, $useTabs = true)
     {
         global $attributes;
 
@@ -64,7 +64,11 @@ class Turba_Form_Contact extends Horde_Form
         }
         foreach ($tabs as $tab => $tab_fields) {
             if (!empty($tab)) {
-                $this->setSection($tab, $tab);
+                if ($useTabs) {
+                    $this->setSection($tab, $tab);
+                } else {
+                    $this->addVariable($tab, '', 'header', false);
+                }
             }
             foreach ($tab_fields as $field) {
                 if (!in_array($field, $fields) ||
index 7b5490a..5268f8e 100644 (file)
@@ -48,6 +48,7 @@ class Turba_View_DeleteContact {
 ?>
 <form action="delete.php" method="post">
 <?php echo Horde_Util::formInput() ?>
+<input type="hidden" name="url" value="<?php echo htmlspecialchars(Horde_Util::getFormData('url')) ?>" />
 <input type="hidden" name="source" value="<?php echo htmlspecialchars($this->contact->driver->name) ?>" />
 <input type="hidden" name="key" value="<?php echo htmlspecialchars($this->contact->getValue('__key')) ?>" />
 <div class="headerbox" style="padding: 8px">
index 2a01e6b..f9d3d3f 100644 (file)
@@ -21,6 +21,20 @@ class Turba_View_Duplicates
     protected $_duplicates;
 
     /**
+     * A field name.
+     *
+     * @var string
+     */
+    protected $_type;
+
+    /**
+     * A duplicate value.
+     *
+     * @var string
+     */
+    protected $_duplicate;
+
+    /**
      * A Turba_Driver instance.
      *
      * @var Turba_Driver
@@ -30,27 +44,69 @@ class Turba_View_Duplicates
     /**
      * Constructor.
      *
+     * If the $type and $duplicate parameters are specified, they are used to
+     * lookup a single Turba_List from $duplicates with a list of duplicate
+     * contacts. The resolution interface for those duplicates is rendered
+     * above the overview tables then.
+     *
      * @param array $duplicates     Hash of Turba_List objects.
      * @param Turba_Driver $driver  A Turba_Driver instance.
+     * @param string $type          A field name.
+     * @param string $duplicate     A duplicate value.
      */
-    public function __construct(array $duplicates, Turba_Driver $driver)
+    public function __construct(array $duplicates, Turba_Driver $driver,
+                                $type = null, $duplicate = null)
     {
         $this->_duplicates = $duplicates;
         $this->_driver     = $driver;
+        $this->_type       = $type;
+        $this->_duplicate  = $duplicate;
     }
 
+    /**
+     * Renders this view.
+     */
     public function display()
     {
         require TURBA_BASE . '/config/attributes.php';
-        $view = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search'));
+
+        $view = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search/duplicate'));
         new Horde_View_Helper_Text($view);
+
+        $hasDuplicate = $this->_type && $this->_duplicate;
+        if ($hasDuplicate) {
+            $vars = new Horde_Variables();
+            $view->type = $attributes[$this->_type]['label'];
+            $view->value = $this->_duplicate;
+            echo $view->render('header');
+
+            $view->contactUrl = Horde::applicationUrl('contact.php');
+            $duplicate = $this->_duplicates[$this->_type][$this->_duplicate];
+            while ($contact = $duplicate->next()) {
+                $view->source = $contact->getSource();
+                $view->id = $contact->getValue('__key');
+                $history = $contact->getHistory();
+                if (isset($history['modified'])) {
+                    $view->changed = $history['modified'];
+                } elseif (isset($history['created'])) {
+                    $view->changed = $history['created'];
+                }
+                echo $view->render('contact_header');
+                $contactView = new Turba_Form_Contact($vars, $contact, false);
+                $contactView->renderInactive(new Horde_Form_Renderer(), $vars);
+                echo $view->render('contact_footer');
+            }
+
+            echo $view->render('footer');
+        }
+
         $view->duplicates = $this->_duplicates;
+        $view->hasDuplicate = (bool)$hasDuplicate;
         $view->attributes = $attributes;
         $view->link = Horde::applicationUrl('search.php')
             ->add(array('source' => $this->_driver->name,
-                        'search_mode' => 'duplicate',
-                        'search' => 1));
+                        'search_mode' => 'duplicate'));
 
-        echo $view->render('duplicate_list');
+        echo $view->render('list');
     }
 }
index ff54d65..fd92403 100644 (file)
@@ -131,7 +131,9 @@ if (is_a($driver, 'PEAR_Error')) {
     if ((is_array($criteria) && count($criteria)) ||
         !empty($val) ||
         ($_SESSION['turba']['search_mode'] == 'duplicate' &&
-         (Horde_Util::getFormData('search') || count($addressBooks) == 1))) {
+         (Horde_Util::getFormData('search') ||
+          Horde_Util::getFormData('dupe') ||
+          count($addressBooks) == 1))) {
         if (Horde_Util::getFormData('save_vbook')) {
             /* We create the vbook and redirect before we try to search
              * since we are not displaying the search results on this page
@@ -165,9 +167,15 @@ if (is_a($driver, 'PEAR_Error')) {
 
         /* Perform a search. */
         if ($_SESSION['turba']['search_mode'] == 'duplicate') {
-            $duplicates = $driver->searchDuplicates();
-            $view = new Turba_View_Duplicates($duplicates, $driver);
-            Horde::addScriptFile('tables.js', 'horde');
+            try {
+                $duplicates = $driver->searchDuplicates();
+                $dupe = Horde_Util::getFormData('dupe');
+                $type = Horde_Util::getFormData('type');
+                $view = new Turba_View_Duplicates($duplicates, $driver, $type, $dupe);
+                Horde::addScriptFile('tables.js', 'horde');
+            } catch (Exception $e) {
+                $notification->push($e);
+            }
         } elseif (($_SESSION['turba']['search_mode'] == 'basic' &&
              is_object($results = $driver->search(array($criteria => $val)))) ||
             ($_SESSION['turba']['search_mode'] == 'advanced' &&
diff --git a/turba/templates/search/duplicate/contact_footer.html.php b/turba/templates/search/duplicate/contact_footer.html.php
new file mode 100644 (file)
index 0000000..04f5b84
--- /dev/null
@@ -0,0 +1 @@
+</div>
diff --git a/turba/templates/search/duplicate/contact_header.html.php b/turba/templates/search/duplicate/contact_header.html.php
new file mode 100644 (file)
index 0000000..f50993b
--- /dev/null
@@ -0,0 +1,13 @@
+<div class="turba-duplicate-contact solidbox">
+  <form action="<?= $this->contactUrl ?>">
+    <p>
+      <? if ($this->changed): ?>
+      <?= _("Last change: ") . $this->changed ?>
+      <? endif; ?>
+      <input type="hidden" name="view" value="DeleteContact" />
+      <input type="hidden" name="source" value="<?= $this->source ?>" />
+      <input type="hidden" name="key" value="<?= $this->id ?>" />
+      <input type="hidden" name="url" value="<?= Horde::selfUrl(true, true, true) ?>" />
+      <input type="submit" value="<?= _("Delete") ?>" class="button" />
+    </p>
+  </form>
diff --git a/turba/templates/search/duplicate/footer.html.php b/turba/templates/search/duplicate/footer.html.php
new file mode 100644 (file)
index 0000000..04f5b84
--- /dev/null
@@ -0,0 +1 @@
+</div>
diff --git a/turba/templates/search/duplicate/header.html.php b/turba/templates/search/duplicate/header.html.php
new file mode 100644 (file)
index 0000000..1933bd9
--- /dev/null
@@ -0,0 +1,3 @@
+<br />
+<h3><?= $this->h(sprintf(_("Duplicates of %s \"%s\""), $this->type, $this->value)) ?></h3>
+<div class="turba-duplicate">
diff --git a/turba/templates/search/duplicate/list.html.php b/turba/templates/search/duplicate/list.html.php
new file mode 100644 (file)
index 0000000..a81c7d5
--- /dev/null
@@ -0,0 +1,23 @@
+<? if ($this->hasDuplicate): ?>
+<br class="clear" />
+<? endif; ?>
+<br />
+<? foreach ($this->duplicates as $field => $duplicates): ?>
+<h3><?= $this->h(sprintf(_("Duplicates of %s"), $this->attributes[$field]['label'])) ?></h3>
+<table class="horde-table horde-block-links sortable">
+  <thead>
+    <tr>
+      <th><?= $this->h($this->attributes[$field]['label']) ?></th>
+      <th><?= _("Count") ?></th>
+    </tr>
+  </thead>
+  <tbody>
+    <? foreach ($duplicates as $value => $list): ?>
+    <tr>
+      <td><a href="<?= $this->link->add(array('type' => $field, 'dupe' => $value)) ?>"><?= $this->h($value) ?></a></td>
+      <td><a href="<?= $this->link->add(array('type' => $field, 'dupe' => $value)) ?>"><?= $list->count() ?></a></td>
+    </tr>
+    <? endforeach; ?>
+  </tbody>
+</table>
+<? endforeach; ?>
diff --git a/turba/templates/search/duplicate_list.html.php b/turba/templates/search/duplicate_list.html.php
deleted file mode 100644 (file)
index 878af1f..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<br />
-<? foreach ($this->duplicates as $field => $duplicates): ?>
-<p><? printf(_("Duplicates of %s"), $this->h($this->attributes[$field]['label'])) ?></p>
-<table class="horde-table horde-block-links sortable">
-  <thead>
-    <tr>
-      <th><?= $this->h($this->attributes[$field]['label']) ?></th>
-      <th><?= _("Count") ?></th>
-    </tr>
-  </thead>
-  <tbody>
-    <? foreach ($duplicates as $value => $list): ?>
-    <tr>
-      <td><a href="<?= $this->link->add('dupe', $value) ?>"><?= $this->h($value) ?></a></td>
-      <td><a href="<?= $this->link->add('dupe', $value) ?>"><?= $list->count() ?></a></td>
-    </tr>
-    <? endforeach; ?>
-  </tbody>
-</table>
-<? endforeach; ?>
index 1c72208..8b14af7 100644 (file)
@@ -69,6 +69,20 @@ table#addressbook-list th.sortdown {
     width: 1%;
 }
 
+/* Duplicates */
+.turba-duplicate {
+    overflow-x: auto;
+    white-space: nowrap;
+}
+.turba-duplicate-contact {
+    float: left;
+    margin-top: 8px;
+    margin-right: 8px;
+}
+.turba-duplicate-contact p {
+    padding: 8px;
+}
+
 /* Preferences pages */
 #turba-prefs-cols-list {
     float: left;