*/
class Turba_Form_Contact extends Horde_Form
{
- public function __construct(&$vars, &$contact)
+ public function __construct(&$vars, &$contact, $tabs = true)
{
global $conf, $notification;
}
$vars->set('object', $object);
- $this->_addFields($contact);
+ $this->_addFields($contact, $tabs);
/* List files. */
$v_params = $GLOBALS['injector']->getInstance('Horde_Vfs')->getConfig('documents');
/**
* Set up the Horde_Form fields for $contact's attributes.
*/
- function _addFields($contact)
+ function _addFields($contact, $useTabs = true)
{
global $attributes;
}
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) ||
?>
<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">
protected $_duplicates;
/**
+ * A field name.
+ *
+ * @var string
+ */
+ protected $_type;
+
+ /**
+ * A duplicate value.
+ *
+ * @var string
+ */
+ protected $_duplicate;
+
+ /**
* A Turba_Driver instance.
*
* @var Turba_Driver
/**
* 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');
}
}
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
/* 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' &&
--- /dev/null
+<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>
--- /dev/null
+<br />
+<h3><?= $this->h(sprintf(_("Duplicates of %s \"%s\""), $this->type, $this->value)) ?></h3>
+<div class="turba-duplicate">
--- /dev/null
+<? 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; ?>
+++ /dev/null
-<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; ?>
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;