File: vacation.php

package info (click to toggle)
ingo1 1.2.4%2Bdebian0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,196 kB
  • ctags: 1,955
  • sloc: php: 8,375; xml: 2,846; sql: 168; makefile: 74; sh: 26
file content (162 lines) | stat: -rw-r--r-- 6,689 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
<?php
/**
 * $Horde: ingo/vacation.php,v 1.28.8.12 2009/01/06 15:24:34 jan Exp $
 *
 * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file LICENSE for license information (ASL).  If you
 * did not receive this file, see http://www.horde.org/licenses/asl.php.
 *
 * @author Mike Cochrane <mike@graftonhall.co.nz>
 */

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

/* Redirect if vacation is not available. */
if (!in_array(INGO_STORAGE_ACTION_VACATION, $_SESSION['ingo']['script_categories'])) {
    $notification->push(_("Vacation is not supported in the current filtering driver."), 'horde.error');
    header('Location: ' . Horde::applicationUrl('filters.php', true));
    exit;
}

/* Get vacation object and rules. */
$vacation = &$ingo_storage->retrieve(INGO_STORAGE_ACTION_VACATION);
$filters = &$ingo_storage->retrieve(INGO_STORAGE_ACTION_FILTERS);
$vac_id = $filters->findRuleId(INGO_STORAGE_ACTION_VACATION);
$vac_rule = $filters->getRule($vac_id);

/* Load libraries. */
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
require_once 'Horde/Variables.php';
$vars = Variables::getDefaultVariables();
if ($vars->get('submitbutton') == _("Return to Rules List")) {
    header('Location: ' . Horde::applicationUrl('filters.php', true));
    exit;
}

/* Build form. */
$form = &new Horde_Form($vars);
$form->setSection('basic', _("Basic Settings"));

$v = &$form->addVariable(_("Start of vacation:"), 'start', 'monthdayyear', '');
$v->setHelp('vacation-period');
$form->addVariable(_("End of vacation:"), 'end', 'monthdayyear', '');
$v = &$form->addVariable(_("Subject of vacation message:"), 'subject', 'text', false);
$v->setHelp('vacation-subject');
$v = &$form->addVariable(_("Reason:"), 'reason', 'longtext', false, false, null, array(10, 40));
$v->setHelp('vacation-reason');
$form->setSection('advanced', _("Advanced Settings"));
if (empty($conf['hooks']['vacation_addresses']) ||
    empty($conf['hooks']['vacation_only'])) {
    $v = &$form->addVariable(_("My email addresses:"), 'addresses', 'longtext', true, false, null, array(5, 40));
    $v->setHelp('vacation-myemail');
}
$v = &$form->addVariable(_("Addresses to not send responses to:"), 'excludes', 'longtext', false, false, null, array(10, 40));
$v->setHelp('vacation-noresponse');
$v = &$form->addVariable(_("Do not send responses to bulk or list messages?"), 'ignorelist', 'boolean', false);
$v->setHelp('vacation-bulk');
$v = &$form->addVariable(_("Number of days between vacation replies:"), 'days', 'int', false);
$v->setHelp('vacation-days');
$form->setButtons(_("Save"));

/* Perform requested actions. */
if ($form->validate($vars)) {
    $form->getInfo($vars, $info);
    $vacation->setVacationAddresses(isset($info['addresses']) ? $info['addresses'] : '');
    $vacation->setVacationDays($info['days']);
    $vacation->setVacationExcludes($info['excludes']);
    $vacation->setVacationIgnorelist(($info['ignorelist'] == 'on'));
    $vacation->setVacationReason($info['reason']);
    $vacation->setVacationSubject($info['subject']);
    $vacation->setVacationStart($info['start']);
    $vacation->setVacationEnd($info['end']);

    $success = true;
    if (is_a($result = $ingo_storage->store($vacation), 'PEAR_Error')) {
        $notification->push($result);
        $success = false;
    } else {
        $notification->push(_("Changes saved."), 'horde.success');
        if ($vars->get('submitbutton') == _("Save and Enable")) {
            $filters->ruleEnable($vac_id);
            if (is_a($result = $ingo_storage->store($filters), 'PEAR_Error')) {
                $notification->push($result);
                $success = false;
            } else {
                $notification->push(_("Rule Enabled"), 'horde.success');
                $vac_rule['disable'] = false;
            }
        } elseif ($vars->get('submitbutton') == _("Save and Disable")) {
            $filters->ruleDisable($vac_id);
            if (is_a($result = $ingo_storage->store($filters), 'PEAR_Error')) {
                $notification->push($result);
                $success = false;
            } else {
                $notification->push(_("Rule Disabled"), 'horde.success');
                $vac_rule['disable'] = true;
            }
        }
    }

    if ($success && $prefs->getValue('auto_update')) {
        Ingo::updateScript();
    }

    /* Update the timestamp for the rules. */
    $_SESSION['ingo']['change'] = time();
}

/* Add buttons depending on the above actions. */
if (empty($vac_rule['disable'])) {
    $form->appendButtons(_("Save and Disable"));
} else {
    $form->appendButtons(_("Save and Enable"));
}
$form->appendButtons(_("Return to Rules List"));

/* Make sure we have at least one address. */
if (!$vacation->getVacationAddresses()) {
    require_once 'Horde/Identity.php';
    $identity = &Identity::singleton('none');
    $addresses = implode("\n", $identity->getAll('from_addr'));
    /* Remove empty lines. */
    $addresses = preg_replace('/\n+/', "\n", $addresses);
    if (empty($addresses)) {
        $addresses = Auth::getAuth();
    }
    $vacation->setVacationAddresses($addresses);
}

/* Set default values. */
if (!$form->isSubmitted()) {
    $vars->set('addresses', implode("\n", $vacation->getVacationAddresses()));
    $vars->set('excludes', implode("\n", $vacation->getVacationExcludes()));
    $vars->set('ignorelist', $vacation->getVacationIgnorelist());
    $vars->set('days', $vacation->getVacationDays());
    $vars->set('subject', $vacation->getVacationSubject());
    $vars->set('reason', $vacation->getVacationReason());
    $vars->set('start', $vacation->getVacationStart());
    $vars->set('end', $vacation->getVacationEnd());
    $vars->set('start_year', $vacation->getVacationStartYear());
    $vars->set('start_month', $vacation->getVacationStartMonth() - 1);
    $vars->set('start_day', $vacation->getVacationStartDay() - 1);
    $vars->set('end_year', $vacation->getVacationEndYear());
    $vars->set('end_month', $vacation->getVacationEndMonth() - 1);
    $vars->set('end_day', $vacation->getVacationEndDay() - 1);
}

/* Set form title. */
$form_title = _("Vacation");
if (!empty($vac_rule['disable'])) {
    $form_title .= ' [<span class="form-error">' . _("Disabled") . '</span>]';
}
$form_title .= ' ' . Help::link('ingo', 'vacation');
$form->setTitle($form_title);

$title = _("Vacation Edit");
require INGO_TEMPLATES . '/common-header.inc';
require INGO_TEMPLATES . '/menu.inc';
$form->renderActive(new Horde_Form_Renderer(array('encode_title' => false)), $vars, 'vacation.php', 'post');
require $registry->get('templates', 'horde') . '/common-footer.inc';