File: spam.php

package info (click to toggle)
horde-sam 0.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,292 kB
  • ctags: 363
  • sloc: php: 1,449; xml: 646; makefile: 64; sql: 60; sh: 30
file content (103 lines) | stat: -rw-r--r-- 3,966 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
<?php
/**
 * $Horde: sam/spam.php,v 1.15 2006/01/13 19:52:05 jan Exp $
 * Copyright 2002-2006 Chris Bowlby <excalibur@hub.org>
 *
 * See the enclosed file COPYING for license information (GPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 */

/* Determine base directory. */
@define('SAM_BASE', dirname(__FILE__));
require_once SAM_BASE . '/lib/base.php';
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
require_once SAM_BASE . '/lib/OptionsForm.php';
require_once 'Horde/Variables.php';

if (!$conf['enable']['rules']) {
    $notification->push(_("The Spam Rules page is not enabled."), 'horde.error');
    header('Location: ' . Horde::applicationUrl('index.php'));
    exit;
}

/* Request retrieval of related user data. */
$result = $sam_driver->retrieve();
if (is_a($result, 'PEAR_Error')) {
    $notification->push(sprintf(_("Cannot get options: %s"), $result->getMessage()), 'horde.error');
}

/* Initialize the form. */
$vars = &Variables::getDefaultVariables();
$form = &Horde_Form::singleton('OptionsForm', $vars);
$renderer = &new Horde_Form_Renderer();
$renderer->setAttrColumnWidth('25%');
$defaults = false;

/* Page variables. */
$title = _("Spam Options");

if ($form->isSubmitted() &&
    $vars->exists('global_defaults') && $vars->get('global_defaults')) {
    if (!Auth::isAdmin()) {
        $notification->push(_("Only an administrator may change the global defaults."), 'horde.error');
        $vars->remove('global_defaults');
        $form->setSubmitted(false);
    } elseif (!$sam_driver->hasCapability('global_defaults')) {
        $notification->push(_("The configured backend does not support global defaults."), 'horde.error');
        $vars->remove('global_defaults');
        $form->setSubmitted(false);
    } else {
        $defaults = true;
    }
}

if ($form->validate($vars)) {
    $stackedOptions = array();

    foreach (SAM::getAttributes() as $key => $attribute) {
        if ($sam_driver->hasCapability($key) && $vars->exists($key)) {
            $data = $vars->get($key);

            if (isset($attribute['basepref'])) {
               /* SA docs claim that a null value for a rewrite string merely
                * removes any previous changes to the specified header.  This
                * should be harmless, and saves needing to add a DELETE
                * preference call in the backend when the user doesn't use
                * header rewrites. */

                /* Build string with all basepref entries, separated by
                 * newlines */
                if (!isset($stackedOptions[$attribute['basepref']])) {
                    $stackedOptions[$attribute['basepref']] = $attribute['subtype'] . " " . $data;
                } else {
                    $stackedOptions[$attribute['basepref']] .= "\n" . $attribute['subtype'] . " " . $data;
                }
            } elseif ($attribute['type'] == 'boolean') {
                $sam_driver->setOption($key, $sam_driver->booleanToOption($data), $defaults);
            } else {
                $sam_driver->setOption($key, $data, $defaults);
            }
        }
    }

    /* All form fields have been processed, so push the resulting strings to
     * the backend. */
    foreach ($stackedOptions as $key => $data) {
        $sam_driver->setStackedOption($key, $data);
    }

    $result = $sam_driver->store($defaults);
    if (is_a($result, 'PEAR_Error')) {
        $notification->push(sprintf(_("Cannot set options: %s"), $result->getMessage()), 'horde.error');
    } elseif ($defaults) {
        $notification->push(_("Updated global default rules"), 'horde.success');
    } else {
        $notification->push(_("Updated user spam rules"), 'horde.success');
    }
}

require SAM_TEMPLATES . '/common-header.inc';
require SAM_TEMPLATES . '/menu.inc';
$form->renderActive($renderer, $vars, 'spam.php', 'post');
require $registry->get('templates', 'horde') . '/common-footer.inc';