[go: up one dir, main page]

File: main.php

package info (click to toggle)
sork-vacation-h3 3.0.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,648 kB
  • ctags: 319
  • sloc: php: 1,216; xml: 498; makefile: 58; perl: 17
file content (181 lines) | stat: -rw-r--r-- 6,717 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
 * $Horde: vacation/main.php,v 1.55.2.5 2007/01/02 13:55:21 jan Exp $
 *
 * Copyright 2001-2007 Eric Rostetter <eric.rostetter@physics.utexas.edu>
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 */

@define('VACATION_BASE', dirname(__FILE__));
require_once VACATION_BASE . '/lib/base.php';

// Create a driver.
require_once VACATION_BASE . '/lib/Driver.php';
$driver = &Vacation_Driver::factory();

require_once VACATION_BASE . '/lib/AliasDriver.php';

// Get the current login username and realm.
@list($user, $realm) = explode('@', Auth::getAuth(), 2);
if (empty($realm) || empty($driver->_params[$realm])) {
    $realm = 'default';
}

// Check if hordeauth is set to 'full'
$hordeauth = $driver->getParam('hordeauth', $realm);
if ($hordeauth === 'full') {
    $user = Auth::getAuth();
}

$submit = Util::getFormData('submit', false);

if ($submit) {
    $vacationmode = Util::getFormData('mode', 'error');
    if ($vacationmode === 'error') {
        $notification->push(_("You must specify the mode (set or remove)"),
                            'horde.warning');
    }

    // Check for refused usernames, using current horde username.
    if (in_array($user, $conf['user']['refused'])) {
        $notification->push(sprintf(_("You can't change the vacation notice for %s."), $user), 'horde.error');
        $vacationmode = 'error';
    } else {
        // Check for password
        if (empty($hordeauth)) {
            $password = Util::getFormData('password', false);
            if (empty($password)) {
                $notification->push(_("You must give your password"), 'horde.warning');
                $vacationmode = 'error';
            }
        } else {
            $password = Auth::getCredential('password');
        }
    }

    // Call the requested function.
    switch ($vacationmode) {
    case 'set':
        if ($conf['aliases']['show']) {
            $alias = Util::getFormData('alias', '');
        } else {
            $aliases = &Vacation_AliasDriver::singleton();
            $alias_list = $aliases->getAliasesForUser($user);
            if (count($alias_list) > 0) {
                $alias = join(', ', $alias_list);
            } else {
                $alias = '';
            }
        }
        $vacationmsg = Util::getFormData('mess', false);

        $vacationtxt = '';
        // Include the mail subject if the driver supports it.
        if ($conf['vacation']['subject']) {
            $vacationtxt .= 'Subject: ' . Util::getFormData('subject') . "\n";
        }
        // Include the mail sender if the driver supports it.
        if ($conf['vacation']['from']) {
            $vacationtxt .= 'From: ' . Util::getFormData('from') . "\n";
        }
        $vacationtxt .= $vacationmsg;

        if (!$vacationmsg) {
            $notification->push(_("You must give a vacation message."),
                                'horde.warning');
        } elseif (!empty($conf['vacation']['validation_pattern']) &&
                  !@preg_match($conf['vacation']['validation_pattern'], $vacationtxt)) {
            // Validation is required, and wasn't matched.
            $notification->push(_("Your vacation message is not in the proper format."),
                                'horde.warning');
        } else {
            // Try and make sure to send Unix linefeeds.
            $vacationtxt = str_replace("\r\n", "\n", $vacationtxt);
            $vacationtxt = str_replace("\r", "\n", $vacationtxt);

            // Wrap at 75 characters.
            $vacationtxt = wordwrap($vacationtxt);

            if ($driver->setVacation($user, $realm, $password,
                                     $vacationtxt, $alias)) {
                $notification->push(_("Vacation notice successfully enabled."), 'horde.success');
            } else {
                $notification->push(sprintf(_("Failure in modifying vacation notice: %s"),
                                            $driver->err_str), 'horde.error');
            }
        }
        break;

    case 'unset':
        if ($driver->unsetVacation($user, $realm, $password)) {
            $notification->push(_("Vacation notice successfully removed."), 'horde.success');
        } else {
            $notification->push(sprintf(_("Failure in removing vacation notice: %s"),
                                        $driver->err_str), 'horde.error');
        }
        break;
    }
}

// If we can tell if vacation notices are enabled, then say so. But if this
// fails, it could be because it is disabled, or just because we can't tell,
// so just be quiet about it.
$pass = Auth::getCredential('password');
$status = $driver->isEnabled($user, $realm, $pass);
$
if ($status == 'Y') {
    $curmessage = $driver->currentMessage($user, $realm, $pass);
    $notification->push(_("Your vacation notice is currently enabled."), 'horde.message');
    $
} elseif ($status == 'N') {
    $curmessage = $driver->currentMessage($user, $realm, $pass);
    if (empty($curmessage)) {
        $curmessage = $conf['vacation']['default'];
    }
    $notification->push(_("Your vacation notice is currently disabled."), 'horde.message');
} else {
    // If the driver can't tell the difference between "disabled" and
    // "unknown", be inscrutable.
    $curmessage = $conf['vacation']['default'];
}

// Split the vacation text in a subject and a message if the driver supports
// it.
if ($conf['vacation']['subject']) {
    if (preg_match('/^Subject: ([^\n]+)\n(.+)$/s', $curmessage, $matches)) {
        $cursubject = $matches[1];
        $curmessage = $matches[2];
    } else {
        $cursubject = '';
    }
}

// Split the vacation text in a sender and a message if the driver supports
// it.
if ($conf['vacation']['from']) {
    if (preg_match('/^From: ([^\n]+)\n(.+)$/s', $curmessage, $matches)) {
        $curfrom = $matches[1];
        $curmessage = $matches[2];
    } else {
        require_once 'Horde/Identity.php';
        $identity = &Identity::singleton();
        // Default "From:" from identities, with name (name <address>)
        $curfrom = $identity->getDefaultFromAddress(true);
    }
}

$alias = Util::getFormData('alias');
if (is_null($alias)) {
    $aliases = &Vacation_AliasDriver::singleton();
    $alias_list = $aliases->getAliasesForUser($user);
    if (is_array($alias_list) && count($alias_list) > 0) {
        $alias = join(', ', $alias_list);
    }
}

$title = _("Change Vacation Notices");
require VACATION_TEMPLATES . '/common-header.inc';
require VACATION_TEMPLATES . '/main/main.inc';
require $registry->get('templates', 'horde') . '/common-footer.inc';