~ubuntu-branches/debian/sid/php-horde-turba/sid

« back to all changes in this revision

Viewing changes to turba-4.1.0/add.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2013-08-11 13:16:25 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130811131625-z91stjvq51jr9onv
Tags: 4.1.1-1
New upstream version 4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * The Turba script to add a new entry into an address book.
4
 
 *
5
 
 * Copyright 2000-2013 Horde LLC (http://www.horde.org/)
6
 
 *
7
 
 * See the enclosed file LICENSE for license information (ASL).  If you did
8
 
 * did not receive this file, see http://www.horde.org/licenses/apache.
9
 
 *
10
 
 * @author Chuck Hagenbuch <chuck@horde.org>
11
 
 */
12
 
 
13
 
require_once __DIR__ . '/lib/Application.php';
14
 
Horde_Registry::appInit('turba');
15
 
 
16
 
/* Setup some variables. */
17
 
$contact = null;
18
 
$vars = Horde_Variables::getDefaultVariables();
19
 
if (count($addSources) == 1) {
20
 
    $vars->set('source', key($addSources));
21
 
}
22
 
$source = $vars->get('source');
23
 
$url = $vars->get('url');
24
 
 
25
 
/* Exit with an error message if there are no sources to add to. */
26
 
if (!$addSources) {
27
 
    $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');
28
 
    $url = $url
29
 
        ? Horde::url($url, true)
30
 
        : Horde::url('index.php', true);
31
 
    $url->redirect();
32
 
}
33
 
 
34
 
/* A source has been selected, connect and set up the fields. */
35
 
if ($source) {
36
 
    try {
37
 
        $driver = $injector->getInstance('Turba_Factory_Driver')->create($source);
38
 
    } catch (Turba_Exception $e) {
39
 
        $notification->push($e, 'horde.error');
40
 
        $driver = null;
41
 
    }
42
 
 
43
 
    if (!is_null($driver)) {
44
 
        /* Check permissions. */
45
 
        $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
46
 
        if ($max_contacts !== true &&
47
 
            $max_contacts <= count($driver)) {
48
 
            Horde::permissionDeniedError(
49
 
                'turba',
50
 
                'max_contacts',
51
 
                sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title'])
52
 
            );
53
 
            $url = $url
54
 
                ? Horde::url($url, true)
55
 
                : Horde::url('index.php', true);
56
 
            $url->redirect();
57
 
        }
58
 
 
59
 
        $contact = new Turba_Object($driver);
60
 
    }
61
 
}
62
 
 
63
 
/* Set up the form. */
64
 
$form = new Turba_Form_AddContact($vars, $contact);
65
 
 
66
 
/* Validate the form. */
67
 
if ($form->validate()) {
68
 
    $form->execute();
69
 
}
70
 
Horde::startBuffer();
71
 
$notification->notify(array('listeners' => 'status'));
72
 
$form->renderActive(new Horde_Form_Renderer(), $vars, Horde::url('add.php'), 'post');
73
 
$formHtml = Horde::endBuffer();
74
 
 
75
 
$page_output->header(array(
76
 
    'title' => _("New Contact")
77
 
));
78
 
echo $formHtml;
79
 
$page_output->footer();