forked from horde/turba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.php
67 lines (58 loc) · 1.96 KB
/
add.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* The Turba script to add a new entry into an address book.
*
* Copyright 2000-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you did
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Chuck Hagenbuch <[email protected]>
*/
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('turba');
/* Setup some variables. */
$contact = null;
$vars = Horde_Variables::getDefaultVariables();
if (count($addSources) == 1) {
$vars->set('source', key($addSources));
}
$source = $vars->get('source');
$url = ($url = Horde::verifySignedUrl($vars->get('url')))
? Horde::url($url, true)
: Horde::url('index.php', true);
/* 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->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->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');
$formHtml = Horde::endBuffer();
$page_output->header(array(
'title' => _("New Contact")
));
echo $formHtml;
$page_output->footer();