<?php
    /*
     * $Id: xadminsystem.php 1466 2010-02-21 20:19:08Z dmorton $
     *
     * MAIA MAILGUARD LICENSE v.1.0
     *
     * Copyright 2004 by Robert LeBlanc <rjl@renaissoft.com>
     *                   David Morton   <mortonda@dgrmm.net>
     * All rights reserved.
     *
     * PREAMBLE
     *
     * This License is designed for users of Maia Mailguard
     * ("the Software") who wish to support the Maia Mailguard project by
     * leaving "Maia Mailguard" branding information in the HTML output
     * of the pages generated by the Software, and providing links back
     * to the Maia Mailguard home page.  Users who wish to remove this
     * branding information should contact the copyright owner to obtain
     * a Rebranding License.
     *
     * DEFINITION OF TERMS
     *
     * The "Software" refers to Maia Mailguard, including all of the
     * associated PHP, Perl, and SQL scripts, documentation files, graphic
     * icons and logo images.
     *
     * GRANT OF LICENSE
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * 1. Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * 3. The end-user documentation included with the redistribution, if
     *    any, must include the following acknowledgment:
     *
     *    "This product includes software developed by Robert LeBlanc
     *    <rjl@renaissoft.com>."
     *
     *    Alternately, this acknowledgment may appear in the software itself,
     *    if and wherever such third-party acknowledgments normally appear.
     *
     * 4. At least one of the following branding conventions must be used:
     *
     *    a. The Maia Mailguard logo appears in the page-top banner of
     *       all HTML output pages in an unmodified form, and links
     *       directly to the Maia Mailguard home page; or
     *
     *    b. The "Powered by Maia Mailguard" graphic appears in the HTML
     *       output of all gateway pages that lead to this software,
     *       linking directly to the Maia Mailguard home page; or
     *
     *    c. A separate Rebranding License is obtained from the copyright
     *       owner, exempting the Licensee from 4(a) and 4(b), subject to
     *       the additional conditions laid out in that license document.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */

    require_once ("core.php");
    require_once ("maia_db.php");
    require_once ("authcheck.php");

    // Only the superadministrator should be here.
    if (!is_superadmin($uid)) {
       header("Location: index.php" . $sid);
       exit();
    }

    foreach($_POST as $varname => $value)
    {
        $formVars[$varname] = trim($value);
    }

    $update = "UPDATE maia_config SET enable_user_autocreation = ?, " .
                                     "enable_false_negative_management = ?, " .
                                     "enable_stats_tracking = ?, " .
                                     "enable_virus_scanning = ?, " .
                                     "enable_spam_filtering = ?, " .
                                     "enable_banned_files_checking = ?, " .
                                     "enable_bad_header_checking = ?, " .
                                     "enable_charts = ?, " .
                                     "enable_spamtraps = ?, " .
//                                     "enable_stats_reporting = ?, " .
                                     "enable_address_linking = ?, " .
                                     "enable_privacy_invasion = ?, " .
                                     "enable_username_changes = ?, " .
                                     "system_default_user_is_local = ?, " .
                                     "user_virus_scanning = ?, " .
                                     "user_spam_filtering = ?, " .
                                     "user_banned_files_checking = ?, " .
                                     "user_bad_header_checking = ?, " .
                                     "size_limit = ?, " .
                                     "oversize_policy = ?, " .
                                     "admin_email = ?, " .
                                     "expiry_period = ?, " .
                                     "ham_cache_expiry_period = ?, " .
                                     "reminder_threshold_count = ?, " .
                                     "reminder_threshold_size = ?, " .
                                     "reminder_template_file = ?, " .
                                     "reminder_login_url = ?, " .
                                     "smtp_server = ?, " .
                                     "smtp_port = ?, " .
                                     "key_file = ?, " .
                                     "currency_label = ?, " .
                                     "bandwidth_cost = ?, " .
                                     "chart_ham_colour = ?, " .
                                     "chart_spam_colour = ?, " .
                                     "chart_virus_colour = ?, " .
                                     "chart_fp_colour = ?, " .
                                     "chart_fn_colour = ?, " .
                                     "chart_suspected_ham_colour = ?, " .
                                     "chart_suspected_spam_colour = ?, " .
                                     "chart_wl_colour = ?, " .
                                     "chart_bl_colour = ?, " .
                                     "chart_background_colour = ?, " .
                                     "chart_font_colour = ?, " .
//                                   "chart_autogeneration_interval = ?, " .
                                     "banner_title = ?, " .
                                     "use_icons = ?, " .
                                     "use_logo = ?, " .
                                     "logo_url = ?, " .
                                     "logo_file = ?, " .
                                     "logo_alt_text = ?, " .
                                     "virus_info_url = ?, " .
                                     "virus_lookup = ? " .
                                     // "primary_report_server = ?, " .
                                     // "primary_report_port = ?, " .
                                     // "secondary_report_server = ?, " .
                                     // "secondary_report_port = ?, " .
                                     // "reporter_sitename = ?, " .
                                     // "reporter_username = ?, " .
                                     // "reporter_password = ? " .
              "WHERE id = 0";
    $dbh->query($update, array($formVars["enable_user_autocreation"],
                               $formVars["enable_false_negative_management"],
                               $formVars["enable_stats_tracking"],
                               $formVars["enable_virus_scanning"],
                               $formVars["enable_spam_filtering"],
                               $formVars["enable_banned_files_checking"],
                               $formVars["enable_bad_header_checking"],
                               $formVars["enable_charts"],
                               $formVars["enable_spamtraps"],
//                               $formVars["enable_stats_reporting"],
                               $formVars["enable_address_linking"],
                               $formVars["enable_privacy_invasion"],
                               $formVars["enable_username_changes"],
                               $formVars["system_default_user_is_local"],
                               $formVars["user_virus_scanning"],
                               $formVars["user_spam_filtering"],
                               $formVars["user_banned_files_checking"],
                               $formVars["user_bad_header_checking"],
                               $formVars["size_limit"],
                               $formVars["oversize_policy"],
                               $formVars["admin_email"],
                               $formVars["expiry_period"],
                               $formVars["ham_cache_expiry_period"],
                               $formVars["reminder_threshold_count"],
                               $formVars["reminder_threshold_size"],
                               $formVars["reminder_template_file"],
                               $formVars["reminder_login_url"],
                               strtolower($formVars["smtp_server"]),
                               $formVars["smtp_port"],
                               $formVars["key_file"],
                               $formVars["currency_label"],
                               $formVars["bandwidth_cost"],
                               $formVars["chart_ham_colour"],
                               $formVars["chart_spam_colour"],
                               $formVars["chart_virus_colour"],
                               $formVars["chart_fp_colour"],
                               $formVars["chart_fn_colour"],
                               $formVars["chart_suspected_ham_colour"],
                               $formVars["chart_suspected_spam_colour"],
                               $formVars["chart_wl_colour"],
                               $formVars["chart_bl_colour"],
                               $formVars["chart_background_colour"],
                               $formVars["chart_font_colour"],
//                               $formVars["chart_autogeneration_interval"],
                               $formVars["banner_title"],
                               $formVars["use_icons"],
                               $formVars["use_logo"],
                               $formVars["logo_url"],
                               $formVars["logo_file"],
                               $formVars["logo_alt_text"],
                               $formVars["virus_info_url"],
                               $formVars["virus_lookup"]
                               // strtolower($formVars["primary_report_server"]),
                               // $formVars["primary_report_port"],
                               // strtolower($formVars["secondary_report_server"]),
                               // $formVars["secondary_report_port"],
                               // $formVars["reporter_sitename"],
                               // strtolower($formVars["reporter_username"]),
                               // $formVars["reporter_password"]
                               ));

    if ($auth_method == "internal") {
        $update = "UPDATE maia_config SET internal_auth = ?, " .
                                         "newuser_template_file = ? " .
                  "WHERE id = 0";
        $dbh->query($update, array($formVars["internal_auth"],
                                   $formVars["newuser_template_file"]));
    }

    // Return to the system administration page
    header("Location: adminsystem.php" . $sid);
    exit();

?>
