<?php
// $Id: pnadmin.php,v 1.3.2.1 2006/01/12 13:05:07 markwest Exp $
// ----------------------------------------------------------------------
// PostNuke Content Management System
// Copyright (C) 2002 by the PostNuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
/**
 * Legal Module
 *
 * Purpose of file:  administration display functions --
 *                   This file contains all administrative GUI functions
 *                   for the module
 *
 * @package      PostNuke_System_Modules
 * @subpackage   Legal
 * @version      $Id: pnadmin.php,v 1.3.2.1 2006/01/12 13:05:07 markwest Exp $
 * @author       Mark West
 * @author       The PostNuke Development Team
 * @link         http://www.postnuke.com  The PostNuke Home Page
 * @copyright    Copyright (C) 2002 by the PostNuke Development Team
 * @license      http://www.gnu.org/copyleft/gpl.html GNU General Public License
 */


/**
 * the main administration function
 *
 * This function is the default function, and is called whenever the
 * module is called without defining arguments.
 * As such it can be used for a number of things, but most commonly
 * it either just shows the module menu and returns or calls whatever
 * the module designer feels should be the default function (often this
 * is the view() function)
 *
 * @author       The PostNuke Development Team
 * @return       output       The main module admin page.
 */
function legal_admin_main()
{
    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  For the
    // main function we want to check that the user has at least edit privilege
    // for some item within this component, or else they won't be able to do
    // anything and so we refuse access altogether.  The lowest level of access
    // for administration depends on the particular module, but it is generally
    // either 'edit' or 'delete'
    if (!pnSecAuthAction(0, 'legal::', '::', ACCESS_EDIT)) {
        return pnVarPrepHTMLDisplay(_MODULENOAUTH);
    }

    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $pnRender =& new pnRender('legal');

    // Return the output that has been generated by this function
    return $pnRender->fetch('legal_admin_main.htm');
}

/**
 * Modify configuration
 *
 * This is a standard function to modify the configuration parameters of the
 * module
 *
 * @author       Mark West
 * @return       output       The configuration page
 */
function legal_admin_modifyconfig()
{
    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'legal::', '::', ACCESS_ADMIN)) {
        return pnVarPrepHTMLDisplay(_MODULENOAUTH);
    }

    // Create output object
    $pnRender =& new pnRender('legal');

    // As admin output changes often, we do not want caching.
    $pnRender->caching = false;

    // Assign all the module vars
    $pnRender->assign(pnModGetVar('legal'));

    // Return the output that has been generated by this function
    return $pnRender->fetch('legal_admin_modifyconfig.htm');
}


/**
 * Update the configuration
 *
 * This is a standard function to update the configuration parameters of the
 * module given the information passed back by the modification form
 * Modify configuration
 *
 * @author       Mark West
 * @param        termsofuse          enable terms of use
 * @param        privacypolicy       enable privacy policy
 * @param        accessibilitypolicy enable accessibility policy
 */
function legal_admin_updateconfig()
{
    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'legal::', '::', ACCESS_ADMIN)) {
        return pnVarPrepHTMLDisplay(_MODULENOAUTH);
    }

    // Get parameters from whatever input we need.  All arguments to this
    // function should be obtained from pnVarCleanFromInput(), getting them
    // from other places such as the environment is not allowed, as that makes
    // assumptions that will not hold in future versions of PostNuke
    list($termsofuse,
         $privacypolicy,
         $accessibilitystatement) = pnVarCleanFromInput('termsofuse',
                                                        'privacypolicy',
                                                        'accessibilitystatement');

    // Confirm authorisation code.  This checks that the form had a valid
    // authorisation code attached to it.  If it did not then the function will
    // proceed no further as it is possible that this is an attempt at sending
    // in false data to the system
    if (!pnSecConfirmAuthKey()) {
        pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_BADAUTHKEY));
        pnRedirect(pnModURL('legal', 'admin', 'main'));
        return true;
    }

    // Update module variables.  Note that depending on the HTML structure used
    // to obtain the information from the user it is possible that the values
    // might be empty, so it is important to check them all and assign them
    // default values if required.

    // ** Please note pnVarCleanFromInput will always return a set variable, even
    // it's empty so isset() checking is not appropriate.
    if (empty($termsofuse)) {
        $termsofuse = false;
    }
    pnModSetVar('legal', 'termsofuse', $termsofuse);
    if (empty($privacypolicy)) {
        $privacypolicy = false;
    }
    pnModSetVar('legal', 'privacypolicy', $privacypolicy);
    if (empty($accessibilitystatement)) {
        $accessibilitystatement = false;
    }
    pnModSetVar('legal', 'accessibilitystatement', $accessibilitystatement);


    // report configuration updated
    pnSessionSetVar('statusmsg', pnVarPrepHTMLDisplay(_CONFIGUPDATED));

    // The configuration has been changed, so we clear all caches for
    // this module.
    $pnRender =& new pnRender('legal');
    // Please note that by using clear_cache without any parameter,
    // we clear all cached pages for this module.
    $pnRender->clear_cache();

	// the module configuration has been updated successfuly
	pnSessionSetVar('statusmsg', _CONFIGUPDATED);

    // This function generated no output, and so now it is complete we redirect
    // the user to an appropriate page for them to carry on their work
    pnRedirect(pnModURL('legal', 'admin', 'main'));

    // Return
    return true;
}

?>