<?php
// $Id: pnadmin.php 17530 2006-01-12 13:42:45Z markwest $
// ----------------------------------------------------------------------
// PostNuke Content Management System
// Copyright (C) 2001 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
// ----------------------------------------------------------------------
// Original Author of file: Jim McDonald
// Purpose of file:  Ratings administration display functions
// ----------------------------------------------------------------------

/**
 * @package PostNuke_Utility_Modules
 * @subpackage Ratings
 * @license http://www.gnu.org/copyleft/gpl.html
*/
/**
 * Main ratings administration function
 * @author Jim McDonald
 * @link http://www.mcdee.net
 * @return HTML String
 */
function ratings_admin_main()
{
    // Security check
    if (!pnSecAuthAction(0, 'Ratings::', '::', ACCESS_ADMIN)) {
        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('Ratings');

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

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

/**
 * Modify Ratings configuration
 * @author Jim McDonald
 * @return HTML String
 */
function ratings_admin_modifyconfig()
{
    // Security check
    if (!pnSecAuthAction(0, 'Ratings::', '::', ACCESS_ADMIN)) {
        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('Ratings');

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

    $pnRender->assign('defaultstylevalues', array('percentage' => _RATINGSPERCENTAGE,
                                            'outoffive' => _RATINGSOUTOFFIVE,
                                            'outoffivestars' => _RATINGSOUTOFFIVESTARS,
                                            'outoften' => _RATINGSOUTOFTEN,
                                            'outoftenstars' => _RATINGSOUTOFTENSTARS));
    $pnRender->assign('defaultstyle', pnModGetVar('Ratings', 'defaultstyle')); //style

    // Ratings security
    $pnRender->assign('securitylevelvalues', array('low' => _RATINGSSECLOW,
                                             'medium' => _RATINGSSECMEDIUM,
                                             'high' => _RATINGSSECHIGH));
    $pnRender->assign('securitylevel', pnModGetVar('Ratings', 'seclevel'));

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

}

/**
 * Update configuration
 * @author Jim McDonald
 * @param 'style' ratings style
 * @param 'seclevel' security level for ratings
 * @return true if update config success, false otherwise
 */
function ratings_admin_updateconfig()
{
    // Security check
    if (!pnSecAuthAction(0, 'Ratings::', '::', ACCESS_ADMIN)) {
        return pnVarPrepHTMLDisplay(_MODULENOAUTH);
    }

    // Get parameters
    list($style,
         $seclevel) = pnVarCleanFromInput('style',
                                          'seclevel');

    // Confirm authorisation code
    if (!pnSecConfirmAuthKey()) {
        pnSessionSetVar('errormsg', _BADAUTHKEY);
        pnRedirect(pnModURL('Ratings', 'admin', 'main'));
        return true;
    }

    // Update default style
    if (!isset($style)) {
        $style = 'outoffivestars';
    }
    pnModSetVar('Ratings', 'defaultstyle', $style);

    // Update security level
    if (!isset($seclevel)) {
        $seclevel = 'medium';
    }
    pnModSetVar('Ratings', 'seclevel', $seclevel);

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

    pnRedirect(pnModURL('Ratings', 'admin', 'main'));

    return true;
}

?>