<?php
/**
 * $Horde: imp/filterprefs.php,v 2.4 2003/06/17 07:53:44 slusarz Exp $
 *
 * Copyright 2003 Michael Slusarz <slusarz@bigworm.colorado.edu>
 *
 * See the enclosed file COPYING for license information (GPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 */

define('IMP_BASE', dirname(__FILE__));
$authentication = OP_HALFOPEN;
require_once IMP_BASE . '/lib/base.php';
require_once IMP_BASE . '/lib/Filter.php';

/* Initialize the PrefsUI code. */
require_once HORDE_BASE . '/lib/PrefsUI.php';
require IMP_BASE . '/config/prefs.php';

/* Are preferences locked? */
$login_locked = $prefs->isLocked('filter_on_login');
$display_locked = $prefs->isLocked('filter_on_display');
$menuitem_locked = $prefs->isLocked('filter_menuitem');

/* Run through the action handlers */
$actionID = Horde::getFormData('actionID');
switch ($actionID) {
case 'filter_prefs_update':
    if (!$login_locked) {
        $prefs->setValue('filter_on_login', Horde::getFormData('filter_login'));
    }
    if (!$display_locked) {
        $prefs->setValue('filter_on_display', Horde::getFormData('filter_display'));
    }
    if (!$menuitem_locked) {
        $prefs->setValue('filter_menuitem', Horde::getFormData('filter_menuitem'));
    }
    $notification->push(_("Preferences successfully updated."), 'horde.success');   
    break;
}

/* Get filter links. */
if ($registry->hasMethod('mail/showBlacklist')) {
    $blacklist_link = $registry->link('mail/showBlacklist');
}
if ($registry->hasMethod('mail/showWhitelist')) {
    $whitelist_link = $registry->link('mail/showWhitelist');
}
if ($registry->hasMethod('mail/showFilters')) {
    $filters_link = $registry->link('mail/showFilters');
}

$title = _("Mail Filters");
$js_onLoad = null;

require IMP_TEMPLATES . '/common-header.inc';
IMP::menu();
IMP::status();

/* If filters are */
if (empty($blacklist_link) && empty($whitelist_link) && empty($filters_link)) {
    require IMP_TEMPLATES . '/filters/notactive.inc';
} else {
    $selfURL = Horde::applicationUrl('filterprefs.php');
    require IMP_TEMPLATES . '/filters/prefs.inc';
}

require IMP_TEMPLATES . '/common-footer.inc';
