/* Exit with an error message if there are no sources to add to. */
if (!$addSources) {
$notification->push(_("There are no writeable address books. None of the available address books are configured to allow you to add new entries to them. If you believe this is an error, please contact your system administrator."), 'horde.error');
$url = $url ? Horde::url($url, true) : Horde::url('index.php', true);
$url->redirect();
}
/* A source has been selected, connect and set up the fields. */
if ($source) {
try {
$driver = $injector->getInstance('Turba_Factory_Driver')->create($source);
} catch (Turba_Exception $e) {
$notification->push($e, 'horde.error');
$driver = null;
}
if (!is_null($driver)) {
if (Turba::hasMaxContacts($driver)) {
$url = $url ? Horde::url($url, true) : Horde::url('index.php', true);
$url->redirect();
}
$contact = new Turba_Object($driver);
}
}
/* Set up the form. */
$form = new Turba_Form_AddContact($vars, $contact);
/* Validate the form. */
if ($form->validate()) {
$form->execute();
}
Horde::startBuffer();
$notification->notify(array('listeners' => 'status'));
$form->renderActive($form->getRenderer(), $vars, Horde::url('add.php'), 'post');