Location: PHPKode > projects > Standings module for sports > pnadmin.php
<?php
// File: $Id: Exp $ $Name:  $
// ----------------------------------------------------------------------------
// Envolution Content Management System
// Copyright (C) 2002 by the Envolution Development Team.
// http://www.envolution.com/
// ----------------------------------------------------------------------------
// Based on:
// Postnuke Content Management System - www.postnuke.com
// PHP-NUKE Web Portal System - http://phpnuke.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:  standings administration display functions
// ----------------------------------------------------------------------------

//////
/// the main administration function
//////
function standings_admin_main()
{
    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output = new pnHTML();

    // 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, 'Standings::Tournament', "::", ACCESS_EDIT)) ||
        (!pnSecAuthAction(0, 'Standings::Team', "::", ACCESS_EDIT))){
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Add a new Tournament
//////
function standings_admin_new()
{
    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output = new pnHTML();

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Standings::', "::", ACCESS_ADMIN)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'create'));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    // Title - putting a title ad the head of each page reminds the user what
    // they are doing
    $output->TableStart(_ADDSTANDINGS);

    // Tournament Name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSNAME));
    $row[] = $output->FormText('title', '', 50, 50);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Description
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSDESCRIPTION));
    $row[] = $output->FormTextArea('description', '', 5, 40);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Points per Victory
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPPVICTORY));
    $row[] = $output->FormText('ppv', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Points per Draw
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPPDRAW));
    $row[] = $output->FormText('ppd', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Points per Lost
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPPLOST));
    $row[] = $output->FormText('ppl', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSADD);
    $output->FormEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Create a new Tournament
///
/// Parameters: 
///                   'title' = name of Tournament
///             'description' = Tournament description
//////
function standings_admin_create($args)
{
    // 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($title,
         $description,
         $ppv,
         $ppd,
         $ppl) = pnVarCleanFromInput('title',
                                     'description',
                                     'ppv',
                                     'ppd',
                                     'ppl');

    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'view'));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the creation of the new item is
    // done within the API, so we need to load that in before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array
    $cid = pnModAPIFunc('Standings',
                        'admin',
                        'create',
                        array('title'       => $title,
                              'description' => $description,
                              'ppv'         => $ppv,
                              'ppd'         => $ppd,
                              'ppl'         => $ppl));

    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if ($cid != false) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSCREATED);
    }

    // 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('Standings', 'admin', 'view'));

    // Return
    return true;
}

//////
/// Create a new Team for the given Tournament
///
/// Parameters:
///                 'cid' = Tournament ID
///                'team' = Team name
///             'contact' = name of the team representative
///               'email' = representative's email 
///            'homepage' = team's Homepage
//////
function standings_admin_createteam($args)
{
    // 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($cid,
         $team,
         $city,
         $shorts,
         $tshirt,
         $contact,
         $phone,
         $paddress,
         $email,
         $homepage) = pnVarCleanFromInput('cid',
                                          'team',
                                          'city',
                                          'shorts',
                                          'tshirt',
                                          'contact',
                                          'phone',
                                          'paddress',
                                          'email',
                                          'homepage');

    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewteams', array('cid' => $cid)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the creation of the new item is
    // done within the API, so we need to load that in before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array
    $tid = pnModAPIFunc('Standings',
                        'admin',
                        'createteam',
                        array('cid'     => $cid,
                              'team'    => $team,
                              'city'    => $city,
                              'shorts'  => $shorts,
                              'tshirt'  => $tshirt,
                              'contact' => $contact,
                              'phone'   => $phone,
                              'paddress'=> $paddress,
                              'email'   => $email,
                              'homepage'=> $homepage));

    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if ($cid != false) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSTEAMCREATED);
    }

    // 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('Standings', 'admin', 'viewteams', array('cid' => $cid)));

    // Return
    return true;
}

//////
/// Create a new Player for the given Team
///
/// Parameters:
///                 'tid' = Team ID
///              'number' = Player number
///               'pname' = Player name
///               'fname' = Player Family Name
///                'role' = Role/Position 
///               'birth' = Birth Date
///              'height' = Height
///              'weight' = Weight
///              'notes'  = notes
///                'from' = Origin
//////
function standings_admin_createplayer($args)
{
    // 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($tid,
         $cid,
         $number,
         $pname,
         $fname,
         $role,
         $birth,
         $height,
         $weight,
         $notes,
         $from) = pnVarCleanFromInput('tid',
                                      'cid',
                                      'number',
                                      'pname',
                                      'fname',
                                      'role',
                                      'birth',
                                      'height',
                                      'weight',
                                      'notes',
                                      'from');

    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewplayers', array('tid' => $tid)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the creation of the new item is
    // done within the API, so we need to load that in before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array
    $pid = pnModAPIFunc('Standings',
                        'admin',
                        'createplayer',
                        array('tid'    => $tid,
                              'cid'    => $cid,
                              'number' => $number,
                              'pname'  => $pname,
                              'fname'  => $fname,
                              'role'   => $role,
                              'birth'  => $birth,
                              'height' => $height,
                              'weight' => $weight,
                              'notes'  => $notes,
                              'from'   => $from));

    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if ($pid != false) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSPLAYERCREATED);
    }

    // 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('Standings', 'admin', 'viewplayers', array('tid' => $tid)));

    // Return
    return true;
}

//////
/// Create a new Scout for the given Player
///
/// Parameters:
///                 'pid' = Player ID
///                'tcid' = Tournament calendar ID
///                 'tid' = Team ID
///                'date' = date
///                 'rid' = round ID
///                 + stats fields
//////
function standings_admin_createscout($args)
{
    // 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($pid,
         $tcid,
         $tid,
         $date,
         $rid,
         $start, $mins, $fgm, $fga, $tpm, $tpa, $ftm, $fta,
         $or, $dr, $ass, $ste, $blk, $blkr, $to, $pf, $pfr) = pnVarCleanFromInput('pid',
                                        'tcid',
                                        'tid',
                                        'date',
                                        'rid',
                                        'start', 'mins', 'fgm', 'fga', 'tpm', 'tpa',
                                        'ftm', 'fta', 'or', 'dr', 'ass', 'ste', 'blk', 'blkr', 'to', 'pf', 'pfr');

    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewscouts', array('tcid' => $tcid,
                                                                      'rid'  => $rid,
                                                                      'tid'  => $tid,
                                                                      'date' => $date)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the creation of the new item is
    // done within the API, so we need to load that in before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array
    $sid = pnModAPIFunc('Standings',
                        'admin',
                        'createscout',
                        array('pid'  => $pid,
                              'tcid' => $tcid,
                              'tid'  => $tid,
                              'date' => $date,
                              'rid'  => $rid,
                              'start'=> $start,
                              'mins' => $mins,
                              'fgm'  => $fgm,
                              'fga'  => $fga,
                              'tpm'  => $tpm,
                              'tpa'  => $tpa,
                              'ftm'  => $ftm,
                              'fta'  => $fta,
                              'or'   => $or,
                              'dr'   => $dr,
                              'ass'  => $ass,
                              'ste'  => $ste,
                              'blk'  => $blk,
                             'blkr'  => $blkr,
                              'to'   => $to,
                              'pf'   => $pf,
                             'pfr'   => $pfr));

    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if ($sid != false) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSSCOUTCREATED);
    }

    // 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('Standings', 'admin', 'viewscouts', array('tcid' => $tcid,
                                                                   'rid' => $rid,
                                                                  'tid'  => $tid,
                                                                  'date' => $date)));

    // Return
    return true;
}


//////
/// Create a new Calendar round for a given Tournament
///
/// Parameters:
///                  'cid' = Tournament ID
///             'numteams' = number of Teams on this Tournament
///                 'game' = round number
//////
function standings_admin_createcal($args)
{
    // 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
    $cid = pnVarCleanFromInput('cid');
    $numteams = pnVarCleanFromInput('numteams');
    $game = pnVarCleanFromInput('gamenum');

    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewcal', array('cid' => $cid)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the creation of the new item is
    // done within the API, so we need to load that in before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // Get the variable parameters
    // Cycle through the games
    for ($i=0; $i<=(Floor($numteams/2)-1); $i++)
	{
            $date = pnVarCleanFromInput('date'.$i);
            $time = pnVarCleanFromInput('time'.$i);
            $tma = pnVarCleanFromInput('tma'.$i);
            $tmb = pnVarCleanFromInput('tmb'.$i);
            // The API function is called.  Note that the name of the API function and
            // the name of this function are identical, this helps a lot when
            // programming more complex modules.  The arguments to the function are
            // passed in as their own arguments array
            $tcid = pnModAPIFunc('Standings',
                                 'admin',
                                 'createcal',
                                  array('cid'   => $cid,
                                        'rid'   => $game,
                                        'date'  => $date,
                                        'time'  => $time,
                                        'teama' => $tma,
                                        'teamb' => $tmb));

        }




    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if ($tcid != false) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSCHEDCREATED);
    }

    // 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('Standings', 'admin', 'viewcal', array('cid' => $cid)));

    // Return
    return true;
}


//////
/// Modify a Tournament
///
/// Parameters:
///             'cid' = Tournament ID
//////
function standings_admin_modify($args)
{
    // 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($cid,
         $objectid)= pnVarCleanFromInput('cid',
                                         'objectid');

                           
    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $cid = $objectid;
    }                       

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

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'get',
                         array('cid' => $cid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Tournament', "$item[title]::$cid", ACCESS_ADMIN)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'update'));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Add a hidden variable for the item id.  This needs to be passed on to
    // the update function so that it knows which item for which item to carry
    // out the update
    $output->FormHidden('cid', pnVarPrepForDisplay($cid));

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart(_EDITSTANDINGS);

    // Title of Tournament
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSNAME));
    $row[] = $output->FormText('title', pnVarPrepForDisplay($item['title']), 50, 50);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Description
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSDESCRIPTION));
    $row[] = $output->FormTextArea('description', pnVarPrepForDisplay($item['description']), 5, 40);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Points per Victory
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPPVICTORY));
    $row[] = $output->FormText('ppv', pnVarPrepForDisplay($item['ppv']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Points per Draw
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPPDRAW));
    $row[] = $output->FormText('ppd', pnVarPrepForDisplay($item['ppd']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Points per Lost
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPPLOST));
    $row[] = $output->FormText('ppl', pnVarPrepForDisplay($item['ppl']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);


    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSUPDATE);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}


//////
/// Updates a Tournament
///
/// Parameters:
///               'cid' = Tournament ID
///             'title' = Tournament name
///       'description' = Tournament description
//////
function standings_admin_update($args)
{
    // 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($cid,
         $objectid,
         $title,
         $description,
         $ppv,
         $ppd,
         $ppl) = pnVarCleanFromInput('cid',
                                     'objectid',
                                     'title',
                                     'description',
                                     'ppv',
                                     'ppd',
                                     'ppl');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);
                            
    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $cid = $objectid;
    }                       

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'view'));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the update of the new item is done
    // within the API, so we need to load that in before we can do anything.
    // If the API fails to load an appropriate error message is posted and the
    // function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if(pnModAPIFunc('Standings',
                    'admin',
                    'update',
                    array('cid'         => $cid,
                          'title'       => $title,
                          'description' => $description,
                          'ppv'         => $ppv,
                          'ppd'         => $ppd,
                          'ppl'         => $ppl))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSUPDATED);
    }

    // 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('Standings', 'admin', 'view'));

    // Return
    return true;
}

//////
/// Updates Ranking for a given Tournament
///
/// Parameters:
///         'cid' = Tournament ID
//////
function standings_admin_updaterank($args)
{
    // 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($cid,
         $objectid) = pnVarCleanFromInput('cid',
                                          'objectid');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $cid = $objectid;
    }                       

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'view'));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the update of the new item is done
    // within the API, so we need to load that in before we can do anything.
    // If the API fails to load an appropriate error message is posted and the
    // function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if(pnModAPIFunc('Standings',
                    'admin',
                    'updaterank',
                    array('cid' => $cid))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSRANKUPDATED);
    }

    // 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('Standings', 'admin', 'viewteams',
                                    array('cid' => $cid)));

    // Return
    return true;
}

//////
/// Add new Team to a given Tournament
///
/// Parameters:
///         'cid' = Tournament ID
//////
function standings_admin_newteam($args)
{
    // 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($cid) = pnVarCleanFromInput('cid');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

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

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADD)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Title - putting a title ad the head of each page reminds the user what
    // they are doing
    $output->Title(_ADDSTANDINGSTEAM);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'createteam', array('cid' => $cid)));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart();

    // Team Name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMNAME));
    $row[] = $output->FormText('team', '', 30, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // City
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMCITY));
    $row[] = $output->FormText('city', '', 30, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Contact
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMCONTACT));
    $row[] = $output->FormText('contact', '', 30, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Phone
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMPHONE));
    $row[] = $output->FormText('phone', '', 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Playground Address
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMPADDRESS));
    $row[] = $output->FormText('paddress', '', 20, 50);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Email
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMEMAIL));
    $row[] = $output->FormText('email', '', 30, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Homepage
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMWWW));
    $row[] = $output->FormText('homepage', '', 30, 200);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // @var colors $ | holds the color info to build a select list

    $colo = array(_STANDINGSTEAMCOLOR0,
                  _STANDINGSTEAMCOLOR1,
                  _STANDINGSTEAMCOLOR2,
                  _STANDINGSTEAMCOLOR3,
                  _STANDINGSTEAMCOLOR4,
                  _STANDINGSTEAMCOLOR5,
                  _STANDINGSTEAMCOLOR6,
                  _STANDINGSTEAMCOLOR7,
                  _STANDINGSTEAMCOLOR8,
                  _STANDINGSTEAMCOLOR9,
                  _STANDINGSTEAMCOLOR10);

    for ($i=0; $i<=10; $i++)
	{
            $colors[] = array('id' => $i, 'selected' => 0, 'name' => $colo[$i]);
        }

    // t-shirt color
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMTSHIRT));
    $row[] = $output->FormSelectMultiple('tshirt', $colors);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // shorts color
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMSHORTS));
    $row[] = $output->FormSelectMultiple('shorts', $colors);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);
    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSADDTEAM);
    $output->FormEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Add new Schedule to a given Tournament
///
/// Parameters:
///         'cid' = Tournament ID
//////
function standings_admin_newcal($args)
{
    // 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($cid) = pnVarCleanFromInput('cid');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

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

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load the APIs
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // get number of Teams for the given Tournament
    $teamnum = pnModAPIFunc('Standings',
                          'user',
                          'teamcount',
                          array('cid' => $cid));


    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 
                                'admin', 
                                'createcal', 
                                 array('cid' => $cid)));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());
    $output->FormHidden('numteams', $teamnum);

    // get all Teams for the given Tournament
    $teams = pnModAPIFunc('Standings',
                          'user',
                          'getteams',
                          array('cid' => $cid));

    if ($teams == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        $output->TableEnd();
        return $output->GetOutput();
    }

    // get the current games count
    $gamescount = pnModAPIFunc('Standings',
                               'user',
                               'getroundcount',
                               array('cid' => $cid));

    $output->TableStart(_ADDSTANDINGSSCHED,array(_STANDINGSSCHEDNUM),0,'80%');
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->FormText('gamenum', pnVarPrepForDisplay(Floor($gamescount)+1), 3, 3);

    // Send to output
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddRow($row, 'center');
    $output->SetInputMode(_PNH_PARSEINPUT);

    $output->TableEnd();

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart('',
                             array(_STANDINGSSCHEDDATE,
                                   _STANDINGSSCHEDTIME,
                                   _STANDINGSSCHEDTEAMA,
                                   " ",
                                   _STANDINGSSCHEDTEAMB),0,'80%');


    // @var teaminfo $ | holds the team info to build a select list
    $teaminfo = array();
    foreach ($teams as $team)
    {
         $teaminfo[] = array('id'    => $team['tid'],
                             'name'  => $team['team']);
    }
 
    // select list
    for ($i=0; $i<=(Floor($teamnum/2)-1); $i++)
	{
        $row = array();
        $output->SetOutputMode(_PNH_RETURNOUTPUT);
 
        // Assign the result
        $row[] = $output->FormText('date'.$i, '', 8, 8);
        $row[] = $output->FormText('time'.$i, '', 5, 5);
        $row[] = $output->FormSelectMultiple('tma'.$i, $teaminfo);
        $row[] = $output->Text('Vs');
        $row[] = $output->FormSelectMultiple('tmb'.$i, $teaminfo);

        // Send to output
        $output->SetOutputMode(_PNH_KEEPOUTPUT);
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->TableAddRow($row, 'center');
        $output->SetInputMode(_PNH_PARSEINPUT);
        $output->Linebreak(2);
        }

    // End form
    $output->TableEnd();
    $output->FormSubmit(_STANDINGSADDSCHED);
    $output->FormEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Add new Player to a given Team
///
/// Parameters:
///         'tid' = Team ID
//////
function standings_admin_newplayer($args)
{
    // 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($tid, $objectid) = pnVarCleanFromInput('tid', 'objectid');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    if (!empty($objectid)) {
        $tid = $objectid;
    }                       

    // Load the APIs
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // find team's Tournament $team[cid]
    $team = pnModAPIFunc('Standings',
                         'user',
                         'getteam',
                         array('tid' => $tid));

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

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_ADD)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'createplayer', array('tid' => $tid,
                                                                            'cid' => $team[cid])));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart(_ADDSTANDINGSPLAYER);
    $output->Linebreak(2);

    // Player Name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERNAME));
    $row[] = $output->FormText('pname', '', 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Family Name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERFNAME));
    $row[] = $output->FormText('fname', '', 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Number
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERNUMB));
    $row[] = $output->FormText('number', '', 2, 2);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Role
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERROLE));
    $row[] = $output->FormText('role', '', 2, 2);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Birth Date
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERBIRTH));
    $row[] = $output->FormText('birth', '', 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Height
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERHEIGHT));
    $row[] = $output->FormText('height', '', 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Weight
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERWEIGHT));
    $row[] = $output->FormText('weight', '', 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Notes
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERNOTES));
    $row[] = $output->FormTextArea('notes', '', 10, 30);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // From
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERFROM));
    $row[] = $output->FormText('from', '', 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);
    $output->Linebreak(2);

    $output->TableEnd();


    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSADDPLAYER);
    $output->FormEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Add new Scout to a given game
///
/// Parameters:
///         'tcid' = Tournament Calendar ID
///          'rid' = Round ID
///          'tid' = Team ID
///         'date' = date
//////
function standings_admin_newscout($args)
{
    // 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($tcid,$rid,$tid,$date) = pnVarCleanFromInput('tcid','rid','tid','date');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

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

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_ADD)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load the APIs
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }


    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 
                                'admin', 
                                'createscout', 
                                 array('pid' => $player,
                                       'tcid'=> $tcid)));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());
    $output->FormHidden('rid', $rid);
    $output->FormHidden('tid', $tid);
    $output->FormHidden('date', $date);

    // get all Teams for the given Tournament
    $players = pnModAPIFunc('Standings',
                            'user',
                            'getplayers',
                            array('tid' => $tid));

    if ($players == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }


    // @var teaminfo $ | holds the team info to build a select list
    $team = array();
    foreach ($players as $player)
    {
         $team[] = array('id'    => $player['pid'],
                         'name'  => $player['fname']);
    }

    $output->TableStart(_ADDSTANDINGSSCOUT);
 
    // select list of players
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSPLAYER));
    $row[] = $output->FormSelectMultiple('pid', $team);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // start
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSSTARTER));
    $row[] = $output->FormCheckbox('start');
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // minutes played
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMINS));
    $row[] = $output->FormText('mins', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Made/Attempts
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMADE));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSATTEMPTS));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // field goal
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSFG));
    $row[] = $output->FormText('fgm', '', 3, 3);
    $row[] = $output->FormText('fga', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // 3 points
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTS3P));
    $row[] = $output->FormText('tpm', '', 3, 3);
    $row[] = $output->FormText('tpa', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Free throws
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSFT));
    $row[] = $output->FormText('ftm', '', 3, 3);
    $row[] = $output->FormText('fta', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Rebounds off/def
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSOFF));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSDEF));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Rebounds
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSREBS));
    $row[] = $output->FormText('or', '', 3, 3);
    $row[] = $output->FormText('dr', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Assists
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSASSISTS));
    $row[] = $output->FormText('ass', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Steals
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSSTEALS));
    $row[] = $output->FormText('ste', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Blocks Made/Received
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMADE));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSRECEIVED));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Blocks
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSBLOCKS));
    $row[] = $output->FormText('blk', '', 3, 3);
    $row[] = $output->FormText('blkr', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Turnovers
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSTURNOVERS));
    $row[] = $output->FormText('to', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Personal Fouls Made/Received
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMADE));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSRECEIVED));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Personal Fouls
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSPERSFOULS));
    $row[] = $output->FormText('pf', '', 3, 3);
    $row[] = $output->FormText('pfr', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    $output->TableEnd();

    // End form
    $output->FormSubmit(_STANDINGSADDSCOUT);
    $output->FormEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Updates a Team
///
/// Parameters:
///        'tid' = Team ID
///        'cid' = Tournament ID
///       'team' = team name
///       'city' = city
///    'contact' = team's representative name
///      'phone' = phone contact
///   'paddress' = playground address
///      'email' = representative's email
///   'homepage' = team's Homepage
//////
function standings_admin_updateteam($args)
{
    // 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($tid,
         $cid,
         $objectid,
         $team,
         $city,
         $shorts,
         $tshirt,
         $contact,
         $phone,
         $paddress,
         $email,
         $homepage) = pnVarCleanFromInput('tid',
                                          'cid',
                                          'objectid',
                                          'team',
                                          'city',
                                          'shorts',
                                          'tshirt',
                                          'contact',
                                          'phone',
                                          'paddress',
                                          'email',
                                          'homepage');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);
                       
    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $tid = $objectid;
    }                       

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewteams', array('cid' => $cid)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the update of the new item is done
    // within the API, so we need to load that in before we can do anything.
    // If the API fails to load an appropriate error message is posted and the
    // function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if(pnModAPIFunc('Standings',
                    'admin',
                    'updateteam',
                    array('tid'     => $tid,
                          'cid'     => $cid,
                          'team'    => $team,
                          'city'    => $city,
                          'shorts'  => $shorts,
                          'tshirt'  => $tshirt,
                          'contact' => $contact,
                          'phone'   => $phone,
                          'paddress'=> $paddress,
                          'email'   => $email,
                          'homepage'=> $homepage))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSTEAMUPDATED);
    }

    // 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('Standings', 'admin', 'viewteams',array('cid' => $cid)));

    // Return
    return true;
}

//////
/// Updates a Schedule on a given Tournament
///
/// Parameters:
///        'tcid' = schedule ID
///         'rid' = round ID
///         'cid' = Tournament ID
///        'date' = schedule date
///        'time' = schedule time
///       'teama' = Team A ID
///       'teamb' = Team B ID
///      'scorea' = Team A's score
///      'scoreb' = Team B's score
//////
function standings_admin_updatecal($args)
{
    // 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($tcid,
         $rid,
         $cid,
         $objectid,
         $date,
         $time,
         $teama,
         $teamb,
         $scorea,
         $scoreb,
         $q1a,
         $q1b,
         $q2a,
         $q2b,
         $q3a,
         $q3b,
         $q4a,
         $q4b,
         $ot1a,
         $ot1b,
         $ot2a,
         $ot2b,
         $ot3a,
         $ot3b,
         $offic1,
         $offic2,
         $offic3) = pnVarCleanFromInput('tcid',
                                        'rid',
                                        'cid',
                                        'objectid',
                                        'date',
                                        'time',
                                        'teama',
                                        'teamb',
                                        'scorea',
                                        'scoreb',
                                        'q1a',
                                        'q1b',
                                        'q2a',
                                        'q2b',
                                        'q3a',
                                        'q3b',
                                        'q4a',
                                        'q4b',
                                        'ot1a',
                                        'ot1b',
                                        'ot2a',
                                        'ot2b',
                                        'ot3a',
                                        'ot3b',
                                        'offic1',
                                        'offic2',
                                        'offic3');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);
                       
    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $tcid = $objectid;
    }                       

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewcal', array('cid' => $cid)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the update of the new item is done
    // within the API, so we need to load that in before we can do anything.
    // If the API fails to load an appropriate error message is posted and the
    // function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if(pnModAPIFunc('Standings',
                    'admin',
                    'updatecal',
                    array('tcid'   => $tcid,
                          'rid'    => $rid,
                          'date'   => $date,
                          'time'   => $time,
                          'teama'  => $teama,
                          'teamb'  => $teamb,
                          'scorea' => $scorea,
                          'scoreb' => $scoreb,
                          'q1a'    => $q1a,
                          'q1b'    => $q1b,
                          'q2a'    => $q2a,
                          'q2b'    => $q2b,
                          'q3a'    => $q3a,
                          'q3b'    => $q3b,
                          'q4a'    => $q4a,
                          'q4b'    => $q4b,
                          'ot1a'   => $ot1a,
                          'ot1b'   => $ot1b,
                          'ot2a'   => $ot2a,
                          'ot2b'   => $ot2b,
                          'ot3a'   => $ot3a,
                          'ot3b'   => $ot3b,
                          'offic1' => $offic1,
                          'offic2' => $offic2,
                          'offic3' => $offic3))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSSCHEDUPDATED);
    }

    // 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('Standings', 'admin', 'viewcal',array('cid' => $cid)));

    // Return
    return true;
}

//////
/// Updates Player info for a given Player ID
///
/// Parameters:
///         'pid' = Player ID
///         'tid' = Team ID
///        'name' = Name
///       'fname' = Family Name
///      'number' = Number
///        'role' = Role
///      'height' = Height
///      'weight' = Weight
///      'notes'  = notes
///        'from' = Origin
//////
function standings_admin_updateplayer($args)
{
    // 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($pid,
         $tid,
         $cid,
         $objectid,
         $name,
         $fname,
         $number,
         $birth,
         $role,
         $height,
         $weight,
         $notes,
         $from) = pnVarCleanFromInput('pid',
                                      'tid',
                                      'cid',
                                      'objectid',
                                      'name',
                                      'fname',
                                      'number',
                                      'birth',
                                      'role',
                                      'height',
                                      'weight',
                                      'notes',
                                      'from');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);
                       
    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $pid = $objectid;
    }                       

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewplayers', array('tid' => $tid)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the update of the new item is done
    // within the API, so we need to load that in before we can do anything.
    // If the API fails to load an appropriate error message is posted and the
    // function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if(pnModAPIFunc('Standings',
                    'admin',
                    'updateplayer',
                    array('pid'   => $pid,
                          'tid'   => $tid,
                          'cid'   => $cid,
                          'name'  => $name,
                          'fname' => $fname,
                          'number'=> $number,
                          'birth' => $birth,
                          'role'  => $role,
                          'height'=> $height,
                          'weight'=> $weight,
                          'notes' => $notes,
                          'from'  => $from))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSPLAYERUPDATED);
    }

    // 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('Standings', 'admin', 'viewplayers',array('tid' => $tid)));

    // Return
    return true;
}

//////
/// Updates Scout for a given scout ID
///
/// Parameters:
///          'sid' = Scout ID
///        'start' = Startup
///         'mins' = Minutes
///          'fgm' = field goal made
///          'fga' = field goal attempts
///          'tpm' = 3 points made
///          'tpa' = 3 points attempts
///          'ftm' = free throws made
///         'fta'  = free throws attempts
///           'or' = Off rebounds
///           'dr' = Def rebounds
///          'ass' = assists
///          'ste' = steals
///          'blk' = blocks
///         'blkr' = blocks received
///           'to' = turnovers
///           'pf' = personal fouls
///          'pfr' = personal fouls received
//////
function standings_admin_updatescout($args)
{
    // 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($sid,
         $tcid,
         $tid,
         $rid,
         $date,
         $start,
         $objectid,
         $mins,
         $fgm,
         $fga,
         $tpm,
         $tpa,
         $ftm,
         $fta,
         $or,
         $dr,
         $ass,
         $ste,
         $blk,
         $blkr,
         $to,
         $pf,
         $pfr) = pnVarCleanFromInput('sid',
                                     'tcid',
                                     'tid',
                                     'rid',
                                     'date',
                                     'start',
                                     'objectid',
                                     'mins',
                                     'fgm',
                                     'fga',
                                     'tpm',
                                     'tpa',
                                     'ftm',
                                     'fta',
                                     'or',
                                     'dr',
                                     'ass',
                                     'ste',
                                     'blk',
                                     'blkr',
                                     'to',
                                     'pf',
                                     'pfr');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $sid = $objectid;
    }                       

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewscouts',
                                         array('tcid'=> $tcid,
                                               'rid' => $rid,
                                               'tid' => $tid,
                                               'date'=> $date)));
        return true;
    }

    // Notable by its absence there is no security check here.  This is because
    // the security check is carried out within the API function and as such we
    // do not duplicate the work here

    // Load API.  All of the actual work for the update of the new item is done
    // within the API, so we need to load that in before we can do anything.
    // If the API fails to load an appropriate error message is posted and the
    // function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        pnSessionSetVar('errormsg', _LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if(pnModAPIFunc('Standings',
                    'admin',
                    'updatescout',
                                array(  'sid'   => $sid,
                                        'start' => $start,
                                        'mins'  => $mins,
                                        'fgm'   => $fgm,
                                        'fga'   => $fga,
                                        'tpm'   => $tpm,
                                        'tpa'   => $tpa,
                                        'ftm'   => $ftm,
                                        'fta'   => $fta,
                                        'or'    => $or,
                                        'dr'    => $dr,
                                        'ass'   => $ass,
                                        'ste'   => $ste,
                                        'blk'   => $blk,
                                       'blkr'   => $blkr,
                                        'to'    => $to,
                                        'pf'    => $pf,
                                       'pfr'    => $pfr))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSSCOUTUPDATED);
    }

    // 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('Standings', 'admin', 'viewscouts',
                                        array('tcid'=> $tcid,
                                              'rid' => $rid,
                                              'tid' => $tid,
                                              'date'=> $date)));

    // Return
    return true;
}

//////
/// Delete a Tournament
///
/// Parameters:
///               'cid' = Tournament ID
///      'confirmation' = confirmation that this item can be deleted
//////
function standings_admin_delete($args)
{
    // 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($cid,
         $objectid,
         $confirmation) = pnVarCleanFromInput('cid',
                                              'objectid',
                                              'confirmation');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $cid = $objectid;
     }                     

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'get',
                         array('cid' => $cid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Tournament', "$item[title]::$cid", ACCESS_DELETE)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Check for confirmation. 
    if (empty($confirmation)) {
        // No confirmation yet - display a suitable form to obtain confirmation
        // of this action from the user

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

        // Add menu to output - it helps if all of the module pages have a
        // standard menu at their head to aid in navigation
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->Text(standings_adminmenu());
        $output->SetInputMode(_PNH_PARSEINPUT);

        // Title - putting a title ad the head of each page reminds the user
        // what they are doing
        $output->LineBreak(2);
        $output->TableStart(_DELETESTANDINGS);

        // Add confirmation to output.  Note that this uses a pnHTML helper
        // function to produce the requested confirmation in a standard
        // fashion.  This not only cuts down on code within the module but
        // allows it to be altered in future without the module developer
        // having to worry about it
        $output->ConfirmAction(_CONFIRMSTANDINGSDELETE . " (" ._WARNINGSTANDINGSTEAMS.")" ,
                               pnModURL('Standings',
                                        'admin',
                                        'delete'),
                               _CANCELSTANDINGSDELETE,
                               pnModURL('Standings',
                                        'admin',
                                        'view'),
                               array('cid' => $cid));

        $output->TableEnd();
        // Return the output that has been generated by this function
        return $output->GetOutput();
    }

    // If we get here it means that the user has confirmed the action

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'view'));
        return true;
    }

    // Load API.  All of the actual work for the deletion of the item is done
    // within the API, so we need to load that in before before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if (pnModAPIFunc('Standings',
                     'admin',
                     'delete',
                     array('cid' => $cid))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSDELETED);
    }

    // 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('Standings', 'admin', 'view'));
    
    // Return
    return true;
}

//////
/// Delete a Team
///
/// Parameters:
///             'tid' = Team ID
///             'cid' = Tournament ID
///    'confirmation' = confirmation that this item can be deleted
//////

function standings_admin_deleteteam($args)
{
    // 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($tid,
         $cid,
         $objectid,
         $confirmation) = pnVarCleanFromInput('tid',
                                              'cid',
                                              'objectid',
                                              'confirmation');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $tid = $objectid;
     }                     

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getteam',
                         array('tid' => $tid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_DELETE)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Check for confirmation. 
    if (empty($confirmation)) {
        // No confirmation yet - display a suitable form to obtain confirmation
        // of this action from the user

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

        // Add menu to output - it helps if all of the module pages have a
        // standard menu at their head to aid in navigation
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->Text(standings_adminmenu());
        $output->SetInputMode(_PNH_PARSEINPUT);

        // Title - putting a title ad the head of each page reminds the user
        // what they are doing
        $output->Title(_DELETESTANDINGSTEAM);

        // Add confirmation to output.  Note that this uses a pnHTML helper
        // function to produce the requested confirmation in a standard
        // fashion.  This not only cuts down on code within the module but
        // allows it to be altered in future without the module developer
        // having to worry about it
        $output->ConfirmAction(_CONFIRMSTANDINGSDELETETEAM,
                               pnModURL('Standings',
                                        'admin',
                                        'deleteteam',
                                        array('tid' => $tid,
                                              'cid' => $cid)),
                               _CANCELSTANDINGSDELETETEAM,
                               pnModURL('Standings',
                                        'admin',
                                        'viewteams',
                                        array('cid' => $cid)));

        // Return the output that has been generated by this function
        return $output->GetOutput();
    }

    // If we get here it means that the user has confirmed the action

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewteams',array('cid' => $cid)));
        return true;
    }

    // Load API.  All of the actual work for the deletion of the item is done
    // within the API, so we need to load that in before before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if (pnModAPIFunc('Standings',
                     'admin',
                     'deleteteam',
                     array('tid' => $tid))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSDELETEDTEAM);
    }

    // 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('Standings', 'admin', 'viewteams', array('cid' => $cid)));
    
    // Return
    return true;
}

//////
/// Delete a Player
///
/// Parameters:
///             'pid' = Player ID
///    'confirmation' = confirmation that this item can be deleted
//////

function standings_admin_deleteplayer($args)
{
    // 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($pid,
         $objectid,
         $confirmation) = pnVarCleanFromInput('pid',
                                              'objectid',
                                              'confirmation');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $pid = $objectid;
     }                     

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getplayer',
                         array('pid' => $pid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Team', "::$item[tid]", ACCESS_DELETE)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Check for confirmation. 
    if (empty($confirmation)) {
        // No confirmation yet - display a suitable form to obtain confirmation
        // of this action from the user

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

        // Add menu to output - it helps if all of the module pages have a
        // standard menu at their head to aid in navigation
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->Text(standings_adminmenu());
        $output->SetInputMode(_PNH_PARSEINPUT);

        // Title - putting a title ad the head of each page reminds the user
        // what they are doing
        $output->Title(_DELETESTANDINGSPLAYER);

        // Add confirmation to output.  Note that this uses a pnHTML helper
        // function to produce the requested confirmation in a standard
        // fashion.  This not only cuts down on code within the module but
        // allows it to be altered in future without the module developer
        // having to worry about it
        $output->ConfirmAction(_CONFIRMSTANDINGSDELETEPLAYER,
                               pnModURL('Standings',
                                        'admin',
                                        'deleteplayer',
                                        array('pid' => $pid)),
                               _CANCELSTANDINGSDELETEPLAYER,
                               pnModURL('Standings',
                                        'admin',
                                        'viewplayers',
                                        array('tid' => $item[tid])));

        // Return the output that has been generated by this function
        return $output->GetOutput();
    }

    // If we get here it means that the user has confirmed the action

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewplayers',array('tid' => $item[tid])));
        return true;
    }

    // Load API.  All of the actual work for the deletion of the item is done
    // within the API, so we need to load that in before before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if (pnModAPIFunc('Standings',
                     'admin',
                     'deleteplayer',
                     array('pid' => $pid))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSDELETEDPLAYER);
    }

    // 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('Standings', 'admin', 'viewplayers', array('tid' => $item[tid])));
    
    // Return
    return true;
}

//////
/// Delete a Scout
///
/// Parameters:
///             'sid' = Scout ID
///    'confirmation' = confirmation that this item can be deleted
//////

function standings_admin_deletescout($args)
{
    // 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($sid,$tcid,$rid,$tid,$date,
         $objectid,
         $confirmation) = pnVarCleanFromInput('sid','tcid','rid','tid','date',
                                              'objectid',
                                              'confirmation');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $sid = $objectid;
     }                     

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getscout',
                         array('sid' => $sid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_DELETE)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Check for confirmation. 
    if (empty($confirmation)) {
        // No confirmation yet - display a suitable form to obtain confirmation
        // of this action from the user

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

        // Add menu to output - it helps if all of the module pages have a
        // standard menu at their head to aid in navigation
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->Text(standings_adminmenu());
        $output->SetInputMode(_PNH_PARSEINPUT);

        // Title - putting a title ad the head of each page reminds the user
        // what they are doing
        $output->Title(_DELETESTANDINGSSCOUT);

        // Add confirmation to output.  Note that this uses a pnHTML helper
        // function to produce the requested confirmation in a standard
        // fashion.  This not only cuts down on code within the module but
        // allows it to be altered in future without the module developer
        // having to worry about it
        $output->ConfirmAction(_CONFIRMSTANDINGSDELETESCOUT,
                               pnModURL('Standings',
                                        'admin',
                                        'deletescout',
                                        array('sid' => $sid,
                                              'tcid'=> $tcid,
                                              'rid' => $rid,
                                              'tid' => $tid,
                                              'date'=> $date)),
                               _CANCELSTANDINGSDELETESCOUT,
                               pnModURL('Standings',
                                        'admin',
                                        'viewscouts',
                                        array('tcid'=> $tcid,
                                              'rid' => $rid,
                                              'tid' => $tid,
                                              'date'=> $date)));

        // Return the output that has been generated by this function
        return $output->GetOutput();
    }

    // If we get here it means that the user has confirmed the action

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewscouts', array('tcid'=> $tcid,
                                                                      'rid' => $rid,
                                                                      'tid' => $tid,
                                                                      'date'=> $date)));
        return true;
    }

    // Load API.  All of the actual work for the deletion of the item is done
    // within the API, so we need to load that in before before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if (pnModAPIFunc('Standings',
                     'admin',
                     'deletescout',
                     array('sid' => $sid))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSDELETEDSCOUT);
    }

    // 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('Standings', 'admin', 'viewscouts', array('tcid'=> $tcid,
                                                                  'rid' => $rid,
                                                                  'tid' => $tid,
                                                                  'date'=> $date)));
    
    // Return
    return true;
}

//////
/// Delete selected Schedule
///
/// Parameters:
///      'cid' = Tournament ID
//////
function standings_admin_deleteselcal($args)
{
    // 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($cid) = pnVarCleanFromInput('cid');

    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

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

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing

    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'deletecal',
                                 array('cid' => $cid)));


    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Start the table that holds the information to be modified.  Note how
    // each item in the form is kept logically separate in the code; this helps
    // to see which part of the code is responsible for the display of each
    // item, and helps with future modifications
    $output->TableStart(_DELETESTANDINGSSCHED,'',0,'40%');

    // Round ID
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDNUM));
    $row[] = $output->FormText('rid', '', 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);
    $output->Linebreak(2);

    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSDELCAL);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}


//////
/// Delete a Tournament schedule
///
/// Parameters:
///             'cid' = Tournament ID
///             'rid' = round ID
///    'confirmation' = confirmation that this item can be deleted
//////

function standings_admin_deletecal($args)
{
    // 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($cid,
         $rid,
         $objectid,
         $confirmation) = pnVarCleanFromInput('cid',
                                              'rid',
                                              'objectid',
                                              'confirmation');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $cid = $objectid;
     }                     

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Check for confirmation. 
    if (empty($confirmation)) {
        // No confirmation yet - display a suitable form to obtain confirmation
        // of this action from the user

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

        // Add menu to output - it helps if all of the module pages have a
        // standard menu at their head to aid in navigation
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->Text(standings_adminmenu());
        $output->SetInputMode(_PNH_PARSEINPUT);

        // Title - putting a title ad the head of each page reminds the user
        // what they are doing
        $output->Title(_DELETESTANDINGSSCHED);

        // Add confirmation to output.  Note that this uses a pnHTML helper
        // function to produce the requested confirmation in a standard
        // fashion.  This not only cuts down on code within the module but
        // allows it to be altered in future without the module developer
        // having to worry about it
        $output->ConfirmAction(_CONFIRMSTANDINGSDELETECAL,
                               pnModURL('Standings',
                                        'admin',
                                        'deletecal',
                                        array('cid' => $cid,
                                              'rid' => $rid)),
                               _CANCELSTANDINGSDELETECAL,
                               pnModURL('Standings',
                                        'admin',
                                        'viewcal',
                                        array('cid' => $cid)));

        // Return the output that has been generated by this function
        return $output->GetOutput();
    }

    // If we get here it means that the user has confirmed the action

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'viewcal',array('cid' => $cid)));
        return true;
    }

    // Load API.  All of the actual work for the deletion of the item is done
    // within the API, so we need to load that in before before we can do
    // anything.  If the API fails to load an appropriate error message is
    // posted and the function returns
    if (!pnModAPILoad('Standings', 'admin')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  Note that the name of the API function and
    // the name of this function are identical, this helps a lot when
    // programming more complex modules.  The arguments to the function are
    // passed in as their own arguments array.
    //
    // The return value of the function is checked here, and if the function
    // suceeded then an appropriate message is posted.  Note that if the
    // function did not succeed then the API function should have already
    // posted a failure message so no action is required
    if (pnModAPIFunc('Standings',
                     'admin',
                     'deletecal',
                     array('cid' => $cid,
                           'rid' => $rid))) {
        // Success
        pnSessionSetVar('statusmsg', _STANDINGSDELETEDCAL);
    }

    // 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('Standings', 'admin', 'viewcal', array('cid' => $cid)));
    
    // Return
    return true;
}

//////
// view Tournaments
//////

function standings_admin_view()
{
    // 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
    $startnum = pnVarCleanFromInput('startnum');

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

    if (!pnSecAuthAction(0, 'Standings::Tournament', "::", ACCESS_READ)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items.
    $items = pnModAPIFunc('Standings',
                          'user',
                          'getall',
                          array('startnum' => $startnum,
                                'numitems' => pnModGetVar('Standings',
                                                          'itemsperpage')));

    // Start output table
    // Title - putting a title ad the head of each page reminds the user what
    // they are doing
    $output->LineBreak(2);
    $output->TableStart(_VIEWSTANDINGS,
                        array(_STANDINGSNAME,
                              _STANDINGSDESCRIPTION,
                              _STANDINGSOPTIONS),
                        1);

    foreach ($items as $item) {

        $row = array();

        if (pnSecAuthAction(0, 'Standings::Tournament', "$item[title]::$item[cid]", ACCESS_READ)) {
    
            // title and description.  Note that unlike the user function we do not
            // censor the text that is being displayed.  This is so the
            // administrator can see the text as exists in the database rather
            // than the munged output version
            $row[] = $item['title'];
            $row[] = $item['description'];

            // Options for the item.  Note that each item has the appropriate
            // levels of authentication checked to ensure that it is suitable
            // for display

            $options = array();
            $output->SetOutputMode(_PNH_RETURNOUTPUT);
            if (pnSecAuthAction(0, 'Standings::Tournament', "$item[title]::$item[cid]", ACCESS_ADMIN)) {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'modify',
                                                   array('cid' => $item['cid'])),
                                          _EDIT);
            }
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'viewteams',
                                                   array('cid' => $item['cid'])),
                                          _STANDINGSVIEWTEAMS);

                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'viewcal',
                                                   array('cid' => $item['cid'])),
                                          _STANDINGSVIEWSCHED);

                if (pnSecAuthAction(0, 'Standings::Tournament', "$item[title]::$item[cid]", ACCESS_DELETE)) {
                    $options[] = $output->URL(pnModURL('Standings',
                                                       'admin',
                                                       'delete',
                                                       array('cid' => $item['cid'])),
                                              _DELETE);
                }

            $options = join(' | ', $options);
            $output->SetInputMode(_PNH_VERBATIMINPUT);
            $row[] = $output->Text($options);
            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }
    $output->TableEnd();

    // Call the pnHTML helper function to produce a pager in case of there
    // being many items to display.
    //
    // Note that this function includes another user API function.  The
    // function returns a simple count of the total number of items in the item
    // table so that the pager function can do its job properly
    $output->Pager($startnum,
                    pnModAPIFunc('Standings', 'user', 'countitems'),
                    pnModURL('Standings',
                             'admin',
                             'view',
                            array('startnum' => '%%')),
                    pnModGetVar('Standings', 'itemsperpage'));


    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// view Teams
///
/// Parameters:
///     'cid' = Tournament ID
//////
function standings_admin_viewteams($args)
{
    // 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($cid,
         $objectid) = pnVarCleanFromInput('cid',
                                          'objectid');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $cid = $objectid;
     }                     

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

    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_READ)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }


    // Start output table
    $output->Linebreak(2);
    $output->TableStart(_VIEWSTANDINGSTEAM,
                        array(_STANDINGSTEAMNAME,
                              _STANDINGSTEAMCITY,
                              _STANDINGSTEAMCONTACT,
                              _STANDINGSTEAMPHONE,
                              _STANDINGSTEAMPADDRESS,
                              _STANDINGSTEAMEMAIL,
                              _STANDINGSTEAMWWW,
                              _STANDINGSTEAMOPTIONS),
                        1);

    // The user API function is called.  This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items.
    $items = pnModAPIFunc('Standings',
                          'user',
                          'getteams',
                          array('cid' => $cid));

    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADD)) {
            $output->URL(pnModURL('Standings',
                                  'admin',
                                  'newteam',
                                  array('cid' => $cid)),
                         _NEWSTANDINGSTEAM);
            $output->Linebreak(2);
    }

    if ($items == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        $output->TableEnd();
        return $output->GetOutput();
    }

    foreach ($items as $item) {

        $row = array();

        if (pnSecAuthAction(0, 'Standings::Team', "$item[team]::$item[tid]", ACCESS_READ)) {
    
            // Team fields.  Note that unlike the user function we do not
            // censor the text that is being displayed.  This is so the
            // administrator can see the text as exists in the database rather
            // than the munged output version

            $row[] = pnVarPrepForDisplay($item['team']);
            $row[] = pnVarPrepForDisplay($item['city']);
            $row[] = pnVarPrepForDisplay($item['contact']);
            $row[] = pnVarPrepForDisplay($item['phone']);
            $row[] = pnVarPrepForDisplay($item['paddress']);
            $row[] = $item['email'];
            $row[] = pnVarPrepForDisplay($item['homepage']);

            // Options for the item.  Note that each item has the appropriate
            // levels of authentication checked to ensure that it is suitable
            // for display

            $options = array();
            $output->SetOutputMode(_PNH_RETURNOUTPUT);
            if (pnSecAuthAction(0, 'Standings::Team', "$item[team]::$item[tid]", ACCESS_EDIT)) {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'modifyteam',
                                                   array('tid' => $item['tid'],
                                                         'cid' => $cid)),
                                          _EDIT);
            }

            if (pnSecAuthAction(0, 'Standings::Team', "$item[team]::$item[tid]", ACCESS_EDIT)) {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'viewplayers',
                                                   array('tid' => $item['tid'])),
                                          _STANDINGSVIEWPLAYERS);
            }
                if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
                    $options[] = $output->URL(pnModURL('Standings',
                                                       'admin',
                                                       'deleteteam',
                                                       array('tid' => $item['tid'],
                                                             'cid' => $cid)),
                                              _DELETE);
                }

            $options = join(' | ', $options);
            $output->SetInputMode(_PNH_VERBATIMINPUT);
            $row[] = $output->Text($options);
            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }
    $output->TableEnd();

    // Start Ranking table
    $output->Linebreak(2);
    $output->TableStart(_VIEWSTANDINGSRANKING,
                        array(_STANDINGSTEAMNAME,pts,tg,tw,tl,td,tpd,tpr,
                              hg,hw,hl,hd,hpd,hpr,ag,aw,al,ad,apd,apr),0);

     foreach ($items as $item) {

        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $row = array();

        if (pnSecAuthAction(0, 'Standings::Team', "$item[team]::$item[tid]", ACCESS_READ)) {
    
            // Team fields.  Note that unlike the user function we do not
            // censor the text that is being displayed.  This is so the
            // administrator can see the text as exists in the database rather
            // than the munged output version

            $row[] = $item['team'];
            $row[] = "<b>" . $item['pts'] ."</b>";
            $row[] = $item['totg'];
            $row[] = $item['totw'];
            $row[] = $item['totl'];
            $row[] = $item['totd'];
            $row[] = $item['totpd'];
            $row[] = $item['totpr'];
            $row[] = $item['hg'];
            $row[] = $item['hw'];
            $row[] = $item['hl'];
            $row[] = $item['hd'];
            $row[] = $item['hpd'];
            $row[] = $item['hpr'];
            $row[] = $item['ag'];
            $row[] = $item['aw'];
            $row[] = $item['al'];
            $row[] = $item['ad'];
            $row[] = $item['apd'];
            $row[] = $item['apr'];

            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }


    $output->TableEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// view Players
///
/// Parameters:
///     'tid' = Team ID
//////
function standings_admin_viewplayers($args)
{
    // 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($tid,
         $objectid) = pnVarCleanFromInput('tid',
                                          'objectid');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $tid = $objectid;
     }                     

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

    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }


    // Start output table
    $output->Linebreak(2);
    $output->TableStart(_VIEWSTANDINGPLAYERS,
                        array(_STANDINGSPLAYERID,
                              _STANDINGSPLAYERNUMB,
                              _STANDINGSPLAYERNAME,
                              _STANDINGSPLAYERFNAME,
                              _STANDINGSPLAYERROLE,
                              _STANDINGSPLAYERBIRTH,
                              _STANDINGSPLAYERHEIGHT,
                              _STANDINGSPLAYERWEIGHT,
                              _STANDINGSPLAYERNOTES,
                              _STANDINGSPLAYERFROM
                                                  ),
                        1);

    // The user API function is called.  This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items.

    $items = pnModAPIFunc('Standings',
                          'user',
                          'getplayers',
                          array('tid' => $tid));

    if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_ADD)) {
            $output->URL(pnModURL('Standings',
                                  'admin',
                                  'newplayer',
                                  array('tid' => $tid)),
                         _NEWSTANDINGSPLAYER);
            $output->Linebreak(2);
    }

    if ($items == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        $output->TableEnd();
        return $output->GetOutput();
    }

    foreach ($items as $item) {

        $row = array();

        if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
    
            // Team fields.  Note that unlike the user function we do not
            // censor the text that is being displayed.  This is so the
            // administrator can see the text as exists in the database rather
            // than the munged output version

            $row[] = $item['pid'];
            $row[] = $item['number'];
            $row[] = $item['name'];
            $row[] = $item['fname'];
            $row[] = $item['role'];
            $row[] = $item['birth'];
            $row[] = $item['height'];
            $row[] = $item['weight'];
            $row[] = $item['notes'];
            $row[] = $item['from'];

            // Options for the item.  Note that each item has the appropriate
            // levels of authentication checked to ensure that it is suitable
            // for display

            $options = array();
            $output->SetOutputMode(_PNH_RETURNOUTPUT);
            if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_EDIT)) {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'modifyplayer',
                                                   array('pid' => $item['pid'])),
                                          _EDIT);

                if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_DELETE)) {
                    $options[] = $output->URL(pnModURL('Standings',
                                                       'admin',
                                                       'deleteplayer',
                                                       array('pid' => $item['pid'])),
                                              _DELETE);
                }
            }

            $options = join(' | ', $options);
            $output->SetInputMode(_PNH_VERBATIMINPUT);
            $row[] = $output->Text($options);
            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }
    $output->TableEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}


//////
/// view Tournament Calendar schedule
///
/// Parameters:
///     'cid' = Tournament ID
//////

function standings_admin_viewcal($args)
{
    // 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($cid,
         $objectid) = pnVarCleanFromInput('cid',
                                          'objectid');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $cid = $objectid;
     }                     

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

    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_READ)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }


    // Start output table
    $output->Linebreak(2);
    $output->TableStart(_VIEWSTANDINGSSCHED,
                        array(_STANDINGSSCHEDNUM,
                              _STANDINGSSCHEDDATE,
                              _STANDINGSSCHEDTIME,
                              _STANDINGSSCHEDTEAMA,
                              _STANDINGSSCHEDTEAMB,
                              ' ',
                              ' ',
                              _STANDINGSSCHEDOPTIONS),
                        1);

    // Show New calendar schedule option
    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
            $output->URL(pnModURL('Standings',
                                        'admin',
                                        'newcal',
                                        array('cid' => $cid)),
                         _NEWSTANDINGSSCHED);
            $output->Linebreak(1);
    }

    // Show Delete calendar schedule option
    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
            $options[] = $output->URL(pnModURL('Standings',
                                               'admin',
                                               'deleteselcal',
                                               array('cid' => $cid)),
                                      _DELETESTANDINGSSCHED);
            $output->Linebreak(2);
                }

    // The user API function is called.  This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items.
    $items = pnModAPIFunc('Standings',
                          'user',
                          'getcals',
                          array('cid' => $cid));


    if ($items == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        $output->TableEnd();
        return $output->GetOutput();
    }

    foreach ($items as $item) {

        $row = array();

        if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_READ)) {
            // convert ID to Team name
            $tma = pnModAPIFunc('Standings',
                                'user',
                                'getteam',
                                array('tid' => $item['teama']));
            $tmb = pnModAPIFunc('Standings',
                                'user',
                                'getteam',
                                array('tid' => $item['teamb']));
    
            // Team fields.  Note that unlike the user function we do not
            // censor the text that is being displayed.  This is so the
            // administrator can see the text as exists in the database rather
            // than the munged output version

            // Hide not updated scores (default=-1)
            if ($item['scorea'] < 0) {
                $item['scorea'] = '';
            }
            if ($item['scoreb'] < 0) {
                $item['scoreb'] = '';
            }
            $row[] = $item['rid'];
            $row[] = $item['date'];
            $row[] = $item['time'];
            $output->SetOutputMode(_PNH_RETURNOUTPUT);

            if (pnSecAuthAction(0, 'Standings::Team', "$tma[team]::$tma[tid]", ACCESS_EDIT)) {
                $row[] = $output->URL(pnModURL('Standings',
                                               'admin',
                                               'viewscouts',
                                               array('tcid'=> $item['tcid'],
                                                     'rid' => $item['rid'],
                                                     'tid' => $tma[tid],
                                                     'date'=> $item['date'])),
                                      $tma[team]);
            } else {
                $row[] = $output->Text($tma[team]);
            }


            if (pnSecAuthAction(0, 'Standings::Team', "$tmb[team]::$tmb[tid]", ACCESS_EDIT)) {
                $row[] = $output->URL(pnModURL('Standings',
                                               'admin',
                                               'viewscouts',
                                               array('tcid'=> $item['tcid'],
                                                     'rid' => $item['rid'],
                                                     'tid' => $tmb[tid],
                                                     'date'=> $item['date'])),
                                      $tmb[team]);
            } else {
                $row[] = $output->Text($tmb[team]);
            }


            $row[] = "<b>".$item['scorea']."</b>";
            $row[] = "<b>".$item['scoreb']."</b>";

            // Options for the item.  Note that each item has the appropriate
            // levels of authentication checked to ensure that it is suitable
            // for display

            $options = array();
            $output->SetOutputMode(_PNH_RETURNOUTPUT);
            if ((pnSecAuthAction(0, 'Standings::Team', "$tma[team]::$tma[tid]", ACCESS_EDIT)) ||
                (pnSecAuthAction(0, 'Standings::Team', "$tmb[team]::$tmb[tid]", ACCESS_EDIT)))
            {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'modifycal',
                                                   array('tcid' => $item['tcid'],
                                                         'cid'  => $cid)),
                                          _EDIT);

            }

            $options = join(' | ', $options);
            $output->SetInputMode(_PNH_VERBATIMINPUT);
            $row[] = $output->Text($options);
            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }
    $output->TableEnd();

    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {

        // START FORM FOR RANKINGS UPDATE
        //
        // Start form - note the use of pnModURL() to create the recipient URL of
        // this form.  All URLs should be generated through pnModURL() to ensure
        // compatibility with future versions of PostNuke
        $output->FormStart(pnModURL('Standings', 'admin', 'updaterank',
                                    array('cid' => $cid)
                                   ));

        // Add an authorisation ID - this adds a hidden field in the form that
        // contains an authorisation ID.  The authorisation ID is very important in
        // preventing certain attacks on the website
        $output->FormHidden('authid', pnSecGenAuthKey());

        // Add a hidden variable for the item id.  This needs to be passed on to
        // the update function so that it knows which item for which item to carry
        // out the update
        $output->FormHidden('cid', pnVarPrepForDisplay($cid));

        // End form
        $output->FormSubmit(_STANDINGSUPDATERANK);
        $output->FormEnd();

    }

    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// view Scouts
///
/// Parameters:
///     'tcid' = Schedule ID
///      'rid' = Round ID
///     'date' = Schedule date
///      'tid' = Team ID
//////

function standings_admin_viewscouts($args)
{
    // 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($tcid,
         $date,
         $rid,
         $tid,
         $objectid) = pnVarCleanFromInput('tcid',
                                          'date',
                                          'rid',
                                          'tid', 
                                          'objectid');


    // User functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

     // At this stage we check to see if we have been passed $objectid, the
     // generic item identifier.  This could have been passed in by a hook or
     // through some other function calling this as part of a larger module, but
     // if it exists it overrides $cid
     //
     // Note that this module couuld just use $objectid everywhere to avoid all
     // of this munging of variables, but then the resultant code is less
     // descriptive, especially where multiple objects are being used.  The
     // decision of which of these ways to go is up to the module developer
     if (!empty($objectid)) {
         $tcid = $objectid;
     }                     

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

    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    $tm = pnModAPIFunc('Standings',
                       'user',
                       'getteam',
                       array('tid' => $tid));

    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $title = _VIEWSTANDINGSSCOUTS . "<br>" . _STANDINGSTEAMNAME . ": $tm[team]<br>" .
             _STANDINGSSCHEDNUM . ": $rid<br>" . _STANDINGSSCHEDDATE . ": $date";

    // Start output table
    $output->Linebreak(2);
    $output->TableStart($title,
                        array(_STANDINGSSCOUTSPLAYER,
                              _STANDINGSSCOUTSSTART,
                              _STANDINGSSCOUTSMINS,
                              _STANDINGSSCOUTSFGM,
                              _STANDINGSSCOUTSFGA,
                              _STANDINGSSCOUTS3PM,
                              _STANDINGSSCOUTS3PA,
                              _STANDINGSSCOUTSFTM,
                              _STANDINGSSCOUTSFTA,
                              _STANDINGSSCOUTSOR,
                              _STANDINGSSCOUTSDR,
                              _STANDINGSSCOUTSASS,
                              _STANDINGSSCOUTSSTE,
                              _STANDINGSSCOUTSBLK,
                              _STANDINGSSCOUTSBLKR,
                              _STANDINGSSCOUTSTO,
                              _STANDINGSSCOUTSPF,
                              _STANDINGSSCOUTSPFR,
                              _STANDINGSSCOUTSPTS,
                              _STANDINGSSCOUTSOPTIONS),
                        1);

    // Show New Scout option
    if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_ADD)) {
            $output->URL(pnModURL('Standings',
                                        'admin',
                                        'newscout',
                                        array('tcid'=> $tcid,
                                              'rid' => $rid,
                                              'tid' => $tid,
                                              'date'=> $date)),
                         _NEWSTANDINGSSCOUT);
            $output->Linebreak(1);
    }

    // The user API function is called.  This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items: gets the scouts for the specified team and for the specified
    // tournament calendar ID.

    $items = pnModAPIFunc('Standings',
                          'user',
                          'getscouts',
                          array('tid'  => $tid,
                                'tcid' => $tcid));


    if ($items == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        $output->TableEnd();
        return $output->GetOutput();
    }


    foreach ($items as $item) {

        $player = pnModAPIFunc('Standings',
                               'user',
                               'getplayer',
                               array('pid'  => $item[pid]));

        $row = array();

        if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {

        $output->SetOutputMode(_PNH_RETURNOUTPUT);
        $row[] = $output->BoldText(substr($player[name],0,1) . ". " . $player[fname]);
        $row[] = $item['start'];
        $row[] = $item['mins'];
        $row[] = $item['fgm'];
        $row[] = $item['fga'];
        $row[] = $item['tpm'];
        $row[] = $item['tpa'];
        $row[] = $item['ftm'];
        $row[] = $item['fta'];
        $row[] = $item['or'];
        $row[] = $item['dr'];
        $row[] = $item['ass'];
        $row[] = $item['ste'];
        $row[] = $item['blk'];
        $row[] = $item['blkr'];
        $row[] = $item['to'];
        $row[] = $item['pf'];
        $row[] = $item['pfr'];
        $row[] = $output->BoldText($item['pts']);


        // Options for the item.  Note that each item has the appropriate
        // levels of authentication checked to ensure that it is suitable
        // for display
        $options = array();
        $output->SetOutputMode(_PNH_RETURNOUTPUT);

            // Show Edit Scout option
            if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_EDIT)) {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'modifyscout',
                                                   array('sid' => $item['sid'],
                                                         'tcid'=> $tcid,
                                                         'rid' => $rid,
                                                         'tid' => $tid,
                                                         'date'=> $date)),
                                          _EDIT);
            }

            // Show Delete Scout option
            if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_DELETE)) {
                $options[] = $output->URL(pnModURL('Standings',
                                                   'admin',
                                                   'deletescout',
                                                   array('sid'=> $item['sid'],
                                                         'tcid'=> $tcid,
                                                         'rid' => $rid,
                                                         'tid' => $tid,
                                                         'date'=> $date)),
                                          _DELETE);

            }

            $options = join(' | ', $options);
            $output->SetInputMode(_PNH_VERBATIMINPUT);
            $row[] = $output->Text($options);
            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }
    $output->TableEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}


//////
/// Modify a Team
///
/// Parameters:
///     'tid' = Team ID
///     'cid' = Tournament ID
//////
function standings_admin_modifyteam($args)
{
    // 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($tid,
         $cid,
         $objectid)= pnVarCleanFromInput('tid',
                                         'cid',
                                         'objectid');

                           
    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $tid = $objectid;
    }                       

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

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getteam',
                         array('tid' => $tid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Team', "$item[team]::$tid", ACCESS_EDIT)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Title - putting a title ad the head of each page reminds the user what
    // they are doing
    $output->Title(_EDITSTANDINGSTEAM);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'updateteam'));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Add a hidden variable for the item id.  This needs to be passed on to
    // the update function so that it knows which item for which item to carry
    // out the update
    $output->FormHidden('tid', pnVarPrepForDisplay($tid));

    // Add a hidden variable for the item id.  This needs to be passed on to
    // the update function so that it knows which item for which item to carry
    // out the update
    $output->FormHidden('cid', pnVarPrepForDisplay($cid));

    // only admin can change teams name
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
	    $output->FormHidden('team', pnVarPrepForDisplay($item['team']));
    }

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart();

    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMNAME));

    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
    // Team Name
	    $row[] = $output->FormText('team', pnVarPrepForDisplay($item['team']), 30, 100);
    } else {
	    $row[] = $output->Text(pnVarPrepForDisplay($item['team']));
    }

    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // City
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMCITY));
    $row[] = $output->FormText('city', pnVarPrepForDisplay($item['city']), 30, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Contact
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMCONTACT));
    $row[] = $output->FormText('contact', pnVarPrepForDisplay($item['contact']), 20, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Phone
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMPHONE));
    $row[] = $output->FormText('phone', pnVarPrepForDisplay($item['phone']), 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Playground Address
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMPADDRESS));
    $row[] = $output->FormText('paddress', pnVarPrepForDisplay($item['paddress']), 20, 50);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Email
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMEMAIL));
    $row[] = $output->FormText('email', $item['email'], 20, 100);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Homepage
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMWWW));
    $row[] = $output->FormText('homepage', pnVarPrepForDisplay($item['homepage']), 20, 200);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // @var colors $ | holds the color info to build a select list
    $colo = array(_STANDINGSTEAMCOLOR0,
                  _STANDINGSTEAMCOLOR1,
                  _STANDINGSTEAMCOLOR2,
                  _STANDINGSTEAMCOLOR3,
                  _STANDINGSTEAMCOLOR4,
                  _STANDINGSTEAMCOLOR5,
                  _STANDINGSTEAMCOLOR6,
                  _STANDINGSTEAMCOLOR7,
                  _STANDINGSTEAMCOLOR8,
                  _STANDINGSTEAMCOLOR9,
                  _STANDINGSTEAMCOLOR10);

    for ($i=0; $i<=10; $i++)
	{
            $tcolors[] = array('id' => $i, 'selected' => ($i == $item['tshirt']), 'name' => $colo[$i]);
        }

    // t-shirt color
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMTSHIRT));
    $row[] = $output->FormSelectMultiple('tshirt', $tcolors);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    for ($i=0; $i<=10; $i++)
	{
            $scolors[] = array('id' => $i, 'selected' => ($i == $item['shorts']), 'name' => $colo[$i]);
        }

    // shorts color
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSTEAMSHORTS));
    $row[] = $output->FormSelectMultiple('shorts', $scolors);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);



    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSUPDATETEAM);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Modify a tournament schedule and enter results
///
/// Parameters:
///    'tcid' = Schedule ID
///     'cid' = Tournament ID
//////
function standings_admin_modifycal($args)
{
    // 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($tcid,
         $cid,
         $objectid)= pnVarCleanFromInput('tcid',
                                         'cid',
                                         'objectid');

                           
    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $tcid = $objectid;
    }                       

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

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // get all Teams for the given Tournament
    $teams = pnModAPIFunc('Standings',
                          'user',
                          'getteams',
                          array('cid' => $cid));

    if ($teams == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getcal',
                         array('tcid' => $tcid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if ((!pnSecAuthAction(0, 'Standings::Team', "::$item[teama]", ACCESS_EDIT))  
        && (!pnSecAuthAction(0, 'Standings::Team', "::$item[teamb]", ACCESS_EDIT))) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'updatecal'));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Add a hidden variable for the item id.  This needs to be passed on to
    // the update function so that it knows which item for which item to carry
    // out the update
    $output->FormHidden('tcid', pnVarPrepForDisplay($tcid));
    $output->FormHidden('cid', pnVarPrepForDisplay($cid));

    // if not an admin, make these fields hidden (cannot be changed)
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
           $output->FormHidden('rid', pnVarPrepForDisplay($item['rid']));
           $output->FormHidden('teama', pnVarPrepForDisplay($item[teama]));
           $output->FormHidden('teamb', pnVarPrepForDisplay($item[teamb]));
    }

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart(_EDITSTANDINGSCHED);

    // Schedule round
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDNUM));
    // only admin can change round #
    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
           $row[] = $output->FormText('rid', pnVarPrepForDisplay($item['rid']), 3, 3);
    } else {
           $row[] = $output->Text(pnVarPrepForDisplay($item['rid']));
    }

    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // date
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDDATE));
    $row[] = $output->FormText('date', pnVarPrepForDisplay($item['date']), 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // time
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDTIME));
    $row[] = $output->FormText('time', pnVarPrepForDisplay($item['time']), 5, 5);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);


    // @var teaminfo $ | holds the team info to build a select list
    $teaminfo = array();
    foreach ($teams as $team)
    {
         if ($team['tid'] == $item['teama']) {
             $teaminfo[] = array('id'    => $team['tid'],
                                 'name'  => $team['team'],
                                 'selected'  => 1);
         } else {
             $teaminfo[] = array('id'    => $team['tid'],
                                 'name'  => $team['team']);
         }
    }

    // teama
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDTEAMA));
    // only admin can change TeamA
    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
           $row[] = $output->FormSelectMultiple('teama', $teaminfo);
    } else {
           $tm = pnModAPIFunc('Standings',
                              'user',
                              'getteam',
                              array('tid' => $item[teama]));
           $row[] = $output->Text(pnVarPrepForDisplay($tm[team]));
    }

    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    $teaminfo = array();
    foreach ($teams as $team)
    {
         if ($team['tid'] == $item['teamb']) {
             $teaminfo[] = array('id'    => $team['tid'],
                                 'name'  => $team['team'],
                                 'selected'  => 1);
         } else {
             $teaminfo[] = array('id'    => $team['tid'],
                                 'name'  => $team['team']);
         }
    }
    // teamb
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDTEAMB));
    // only admin can change TeamA
    if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_ADMIN)) {
           $row[] = $output->FormSelectMultiple('teamb', $teaminfo);
    } else {
           $tm = pnModAPIFunc('Standings',
                              'user',
                              'getteam',
                              array('tid' => $item[teamb]));
           $row[] = $output->Text(pnVarPrepForDisplay($tm[team]));
    }
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Score/Quarters/Overtime labels
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->BoldText(pnVarPrepForDisplay(_STANDINGSSCHEDFINAL));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDQUARTER."1"));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDQUARTER."2"));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDQUARTER."3"));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDQUARTER."4"));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDOVERTIME."1"));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDOVERTIME."2"));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDOVERTIME."3"));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // scorea / Q1-Q2-Q3-Q4-OT1-OT2-OT3
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDSCOREA));
    $row[] = $output->FormText('scorea', pnVarPrepForDisplay($item['scorea']), 3, 3);
    $row[] = $output->FormText('q1a', pnVarPrepForDisplay($item['q1a']), 3, 3);
    $row[] = $output->FormText('q2a', pnVarPrepForDisplay($item['q2a']), 3, 3);
    $row[] = $output->FormText('q3a', pnVarPrepForDisplay($item['q3a']), 3, 3);
    $row[] = $output->FormText('q4a', pnVarPrepForDisplay($item['q4a']), 3, 3);
    $row[] = $output->FormText('ot1a', pnVarPrepForDisplay($item['ot1a']), 3, 3);
    $row[] = $output->FormText('ot2a', pnVarPrepForDisplay($item['ot2a']), 3, 3);
    $row[] = $output->FormText('ot3a', pnVarPrepForDisplay($item['ot3a']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // scoreb / Q1-Q2-Q3-Q4-OT1-OT2-OT3
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDSCOREB));
    $row[] = $output->FormText('scoreb', pnVarPrepForDisplay($item['scoreb']), 3, 3);
    $row[] = $output->FormText('q1b', pnVarPrepForDisplay($item['q1b']), 3, 3);
    $row[] = $output->FormText('q2b', pnVarPrepForDisplay($item['q2b']), 3, 3);
    $row[] = $output->FormText('q3b', pnVarPrepForDisplay($item['q3b']), 3, 3);
    $row[] = $output->FormText('q4b', pnVarPrepForDisplay($item['q4b']), 3, 3);
    $row[] = $output->FormText('ot1b', pnVarPrepForDisplay($item['ot1b']), 3, 3);
    $row[] = $output->FormText('ot2b', pnVarPrepForDisplay($item['ot2b']), 3, 3);
    $row[] = $output->FormText('ot3b', pnVarPrepForDisplay($item['ot3b']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Official 1
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDOFFICIAL." 1"));
    $row[] = $output->FormText('offic1', pnVarPrepForDisplay($item['offic1']),20,20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Official 2
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDOFFICIAL." 2"));
    $row[] = $output->FormText('offic2', pnVarPrepForDisplay($item['offic2']),20,20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Official 3
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDOFFICIAL." 3"));
    $row[] = $output->FormText('offic3', pnVarPrepForDisplay($item['offic3']),20,20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSUPDATESCHED);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Modify a Player info for a given Player ID
///
/// Parameters:
///     'pid' = Player ID
//////
function standings_admin_modifyplayer($args)
{
    // 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($pid,
         $objectid)= pnVarCleanFromInput('pid',
                                         'objectid');

                           
    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $pid = $objectid;
    }                       

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

    // Load the APIs
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getplayer',
                         array('pid' => $pid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    // find team's Tournament $team[cid]
    $team = pnModAPIFunc('Standings',
                         'user',
                         'getteam',
                         array('tid' => $item[tid]));


    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Team', "$team[team]::$item[tid]", ACCESS_EDIT)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'updateplayer'));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Add a hidden variable for the item id.  This needs to be passed on to
    // the update function so that it knows which item for which item to carry
    // out the update
    $output->FormHidden('pid', pnVarPrepForDisplay($pid));

    // Add a hidden variable for the tournament id
    $output->FormHidden('cid', pnVarPrepForDisplay($team[cid]));

    // only ADMIN can change team membership!!!
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::$team[cid]", ACCESS_ADMIN)) {
    	$output->FormHidden('tid', pnVarPrepForDisplay($item['tid']));
    }

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart(_EDITSTANDINGSPLAYER);

    // New Team ID - used to change Team - ONLY ADMIN CAN CHANGE TEAM MEMBERSHIP!!!
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERTEAM));

    if (pnSecAuthAction(0, 'Standings::Tournament', "::$team[cid]", ACCESS_ADMIN)) {
	$row[] = $output->FormText('tid', pnVarPrepForDisplay($item['tid']), 3, 3);
    } else {
	$row[] = $output->Text(pnVarPrepForDisplay($item['tid']));
    }
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERNAME));
    $row[] = $output->FormText('name', pnVarPrepForDisplay($item['name']), 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Family Name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERFNAME));
    $row[] = $output->FormText('fname', pnVarPrepForDisplay($item['fname']), 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Number
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERNUMB));
    $row[] = $output->FormText('number', pnVarPrepForDisplay($item['number']), 2, 2);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Role
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERROLE));
    $row[] = $output->FormText('role', pnVarPrepForDisplay($item['role']), 2, 2);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Birth
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERBIRTH));
    $row[] = $output->FormText('birth', pnVarPrepForDisplay($item['birth']), 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Height - avoid pnVarPrepForDisplay function to allow " symbol (inches)
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERHEIGHT));
    $row[] = $output->FormText('height', $item['height'], 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Weight - avoid pnVarPrepForDisplay function to allow special symbols (pounds)
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERWEIGHT));
    $row[] = $output->FormText('weight', $item['weight'], 8, 8);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Notes
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERNOTES));
    $row[] = $output->FormTextArea('notes', pnVarPrepForDisplay($item['notes']), 10, 30);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // From
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERFROM));
    $row[] = $output->FormText('from', pnVarPrepForDisplay($item['from']), 20, 20);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);


    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSUPDATEPLAYER);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Modify a Scout for a given Scout ID
///
/// Parameters:
///     'sid' = Scout ID
///    'tcid' = Tournament calendar ID
///     'tid' = Team ID
///     'rid' = Round ID
///    'date' = Date
//////
function standings_admin_modifyscout($args)
{
    // 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($sid,
         $tcid,
         $tid,
         $rid,
         $date,
         $objectid)= pnVarCleanFromInput('sid',
                                         'tcid',
                                         'tid',
                                         'rid',
                                         'date',
                                         'objectid');
                          
    // Admin functions of this type can be called by other modules.  If this
    // happens then the calling module will be able to pass in arguments to
    // this function through the $args parameter.  Hence we extract these
    // arguments *after* we have obtained any form-based input through
    // pnVarCleanFromInput().
    extract($args);

    // At this stage we check to see if we have been passed $objectid, the
    // generic item identifier.  This could have been passed in by a hook or
    // through some other function calling this as part of a larger module, but
    // if it exists it overrides $cid
    //
    // Note that this module couuld just use $objectid everywhere to avoid all
    // of this munging of variables, but then the resultant code is less
    // descriptive, especially where multiple objects are being used.  The
    // decision of which of these ways to go is up to the module developer
    if (!empty($objectid)) {
        $sid = $objectid;
    }                       

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

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing.  However,
    // in this case we had to wait until we could obtain the item name to
    // complete the instance information so this is the first chance we get to
    // do the check
    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_EDIT)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Standings', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The user API function is called.  This takes the item ID which we
    // obtained from the input and gets us the information on the appropriate
    // item.  If the item does not exist we post an appropriate message and
    // return
    $item = pnModAPIFunc('Standings',
                         'user',
                         'getscout',
                         array('sid' => $sid));

    if ($item == false) {
        $output->Text(_STANDINGSNOSUCHITEM);
        return $output->GetOutput();
    }

    $player = pnModAPIFunc('Standings',
                           'user',
                           'getplayer',
                           array('pid' => $item[pid]));


    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'updatescout'));

    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Add a hidden variable for the item id.  This needs to be passed on to
    // the update function so that it knows which item for which item to carry
    // out the update
    $output->FormHidden('sid', pnVarPrepForDisplay($sid));
    $output->FormHidden('tid', pnVarPrepForDisplay($tid));
    $output->FormHidden('tcid', pnVarPrepForDisplay($tcid));
    $output->FormHidden('rid', pnVarPrepForDisplay($rid));
    $output->FormHidden('date', pnVarPrepForDisplay($date));

    // Start the table that holds the information to be input.  Note how each
    // item in the form is kept logically separate in the code; this helps to
    // see which part of the code is responsible for the display of each item,
    // and helps with future modifications
    $output->TableStart(_EDITSTANDINGSSCOUT);

    // Player name
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSPLAYER));
    $row[] = $output->BoldText(pnVarPrepForDisplay($player['fname']));
    $row[] = $output->Text("(" . pnVarPrepForDisplay(_STANDINGSSCOUTSPOINTS) . " " . pnVarPrepForDisplay($item['pts']) . ")");
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSSTARTER));
    $row[] = $output->FormCheckbox('start',pnVarPrepForDisplay($item['start']));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Minutes
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMINS));
    $row[] = $output->FormText('mins', pnVarPrepForDisplay($item['mins']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Made/Attempts
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMADE));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSATTEMPTS));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // field goal
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSFG));
    $row[] = $output->FormText('fgm', pnVarPrepForDisplay($item['fgm']), 3, 3);
    $row[] = $output->FormText('fga', pnVarPrepForDisplay($item['fga']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // 3 points
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTS3P));
    $row[] = $output->FormText('tpm', pnVarPrepForDisplay($item['tpm']), 3, 3);
    $row[] = $output->FormText('tpa', pnVarPrepForDisplay($item['tpa']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Free throws
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSFT));
    $row[] = $output->FormText('ftm', pnVarPrepForDisplay($item['ftm']), 3, 3);
    $row[] = $output->FormText('fta', pnVarPrepForDisplay($item['fta']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Rebounds off/def
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSOFF));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSDEF));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Rebounds
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSREBS));
    $row[] = $output->FormText('or', pnVarPrepForDisplay($item['or']), 3, 3);
    $row[] = $output->FormText('dr', pnVarPrepForDisplay($item['dr']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Assists
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSASSISTS));
    $row[] = $output->FormText('ass', pnVarPrepForDisplay($item['ass']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Steals
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSSTEALS));
    $row[] = $output->FormText('ste', pnVarPrepForDisplay($item['ste']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Blocks Made/Received
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMADE));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSRECEIVED));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Blocks
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSBLOCKS));
    $row[] = $output->FormText('blk', pnVarPrepForDisplay($item['blk']), 3, 3);
    $row[] = $output->FormText('blkr', pnVarPrepForDisplay($item['blkr']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Turnovers
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSTURNOVERS));
    $row[] = $output->FormText('to', pnVarPrepForDisplay($item['to']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Personal Fouls Made/Received
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(''));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSMADE));
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSRECEIVED));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Personal Fouls
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCOUTSPERSFOULS));
    $row[] = $output->FormText('pf', pnVarPrepForDisplay($item['pf']), 3, 3);
    $row[] = $output->FormText('pfr', pnVarPrepForDisplay($item['pfr']), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);



    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSUPDATESCOUT);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Modify configuration
//////
function standings_admin_modifyconfig()
{
    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output = new pnHTML();

    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing

    if (!pnSecAuthAction(0, 'Standings::', "::", ACCESS_ADMIN)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Start form - note the use of pnModURL() to create the recipient URL of
    // this form.  All URLs should be generated through pnModURL() to ensure
    // compatibility with future versions of PostNuke
    $output->FormStart(pnModURL('Standings', 'admin', 'updateconfig'));


    // Add an authorisation ID - this adds a hidden field in the form that
    // contains an authorisation ID.  The authorisation ID is very important in
    // preventing certain attacks on the website
    $output->FormHidden('authid', pnSecGenAuthKey());

    // Start the table that holds the information to be modified.  Note how
    // each item in the form is kept logically separate in the code; this helps
    // to see which part of the code is responsible for the display of each
    // item, and helps with future modifications
    $output->TableStart(_STANDINGSMODIFYCONFIG);

    // Background color of Schedule table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDBCKCOLOR));
    $row[] = $output->FormText('schedulebkgnd', pnModGetVar('Standings', 'schedulebkgnd'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Header color of Schedule table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDHDRCOLOR));
    $row[] = $output->FormText('scheduleheader', pnModGetVar('Standings', 'scheduleheader'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Separator color of Schedule table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSCHEDSEPCOLOR));
    $row[] = $output->FormText('schedulesep', pnModGetVar('Standings', 'schedulesep'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Separator color of Standings table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTANDSEPCOLOR));
    $row[] = $output->FormText('standseprcol', pnModGetVar('Standings', 'standseprcol'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Header color of Standings table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTANDHDRCOLOR));
    $row[] = $output->FormText('standheadercol', pnModGetVar('Standings', 'standheadercol'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Background1 color of Standings table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTANDBCK1COLOR));
    $row[] = $output->FormText('standbkgnd1col', pnModGetVar('Standings', 'standbkgnd1col'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Background2 color of Standings table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTANDBCK2COLOR));
    $row[] = $output->FormText('standbkgnd2col', pnModGetVar('Standings', 'standbkgnd2col'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Totals color of Standings table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTANDTOTCOLOR));
    $row[] = $output->FormText('standtotalscol', pnModGetVar('Standings', 'standtotalscol'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Columns color of Standings table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTANDCOLCOLOR));
    $row[] = $output->FormText('standcolscol', pnModGetVar('Standings', 'standcolscol'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Line1 color for game result table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSGAMELINE1COLOR));
    $row[] = $output->FormText('gameline1', pnModGetVar('Standings', 'gameline1'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Line2 color for game result table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSGAMELINE2COLOR));
    $row[] = $output->FormText('gameline2', pnModGetVar('Standings', 'gameline2'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Main Header for game result table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSGAMEMAINCOLOR));
    $row[] = $output->FormText('gamemainheader', pnModGetVar('Standings', 'gamemainheader'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Header for game result table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSHEADERCOLOR));
    $row[] = $output->FormText('gameheader', pnModGetVar('Standings', 'gameheader'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Header text color for game result table
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSSTATSCOLOR));
    $row[] = $output->FormText('gamestatcol', pnModGetVar('Standings', 'gamestatcol'), 7, 7);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    //////
    /// New in 1.2
    //////

    // Player evaluation based on time played
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSEVALBYTIME));
    $row[] = $output->FormCheckbox('valbytime', pnModGetVar('Standings', 'valbytime'));
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Total game time
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSGAMEMIN));
    $row[] = $output->FormText('gamemin', pnModGetVar('Standings', 'gamemin'), 3, 3);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Number of column in Player's list view
    $row = array();
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $row[] = $output->Text(pnVarPrepForDisplay(_STANDINGSPLAYERSCOL));
    $row[] = $output->FormText('playercolmn', pnModGetVar('Standings', 'playercolmn'), 1, 1);
    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddrow($row, 'left');
    $output->SetInputMode(_PNH_PARSEINPUT);




    $output->TableEnd();

    // End form
    $output->Linebreak(2);
    $output->FormSubmit(_STANDINGSUPDATECONFIG);
    $output->FormEnd();
    
    // Return the output that has been generated by this function
    return $output->GetOutput();
}

//////
/// Update configuration
//////
function standings_admin_updateconfig()
{
    // 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

    $schedulebkgnd = pnVarCleanFromInput('schedulebkgnd');
    $scheduleheader = pnVarCleanFromInput('scheduleheader');
    $schedulesep = pnVarCleanFromInput('schedulesep');

    $standseprcol = pnVarCleanFromInput('standseprcol');
    $standheadercol = pnVarCleanFromInput('standheadercol');
    $standbkgnd1col = pnVarCleanFromInput('standbkgnd1col');
    $standbkgnd2col = pnVarCleanFromInput('standbkgnd2col');
    $standtotalscol = pnVarCleanFromInput('standtotalscol');
    $standcolscol = pnVarCleanFromInput('standcolscol');

    // colors used by game results
    $gameline1      = pnVarCleanFromInput('gameline1');      // #ffffff
    $gameline2      = pnVarCleanFromInput('gameline2');      // #cccccc
    $gamemainheader = pnVarCleanFromInput('gamemainheader'); // #0099cc
    $gameheader     = pnVarCleanFromInput('gameheader');     // #003399
    $gamestatcol    = pnVarCleanFromInput('gamestatcol');    // #ffffff

    // weighted evaluation based on time played
    $valbytime      = pnVarCleanFromInput('valbytime');
    pnModSetVar('Standings', 'valbytime', $valbytime);
    $gamemin        = pnVarCleanFromInput('gamemin');
    $playercolmn    = pnVarCleanFromInput('playercolmn');

    // 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', _BADAUTHKEY);
        pnRedirect(pnModURL('Standings', 'admin', 'view'));
        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 unset, so it is important to check them all and assign them
    // default values if required

    if (!isset($schedulebkgnd) || ($schedulebkgnd == null)) {
        $schedulebkgnd = '#FFFFFF';
    }
    pnModSetVar('Standings', 'schedulebkgnd', $schedulebkgnd);

    if (!isset($scheduleheader) || ($scheduleheader == null)) {
        $scheduleheader = '#FF8A2F';
    }
    pnModSetVar('Standings', 'scheduleheader', $scheduleheader);

    if (!isset($schedulesep) || ($schedulesep == null)) {
        $schedulesep = '#CCCCCC';
    }
    pnModSetVar('Standings', 'schedulesep', $schedulesep);

    if (!isset($standseprcol) || ($standseprcol == null)) {
        $standseprcol = '#CCCCCC';
    }
    pnModSetVar('Standings', 'standseprcol', $standseprcol);

    if (!isset($standheadercol) || ($standheadercol == null)) {
        $standheadercol = '#C0C0C0';
    }
    pnModSetVar('Standings', 'standheadercol', $standheadercol);

    if (!isset($standbkgnd1col) || ($standbkgnd1col == null)) {
        $standbkgnd1col = '#CCCCCC';
    }
    pnModSetVar('Standings', 'standbkgnd1col', $standbkgnd1col);

    if (!isset($standbkgnd2col) || ($standbkgnd2col == null)) {
        $standbkgnd2col = '#FFFFFF';
    }
    pnModSetVar('Standings', 'standbkgnd2col', $standbkgnd2col);

    if (!isset($standtotalscol) || ($standtotalscol == null)) {
        $standtotalscol = '#FFFFFF';
    }
    pnModSetVar('Standings', 'standtotalscol', $standtotalscol);

    if (!isset($standcolscol) || ($standcolscol == null)) {
        $standcolscol = '#CCCCCC';
    }
    pnModSetVar('Standings', 'standcolscol', $standcolscol);

    // define colors for game result tables
    if (!isset($gameline1) || ($gameline1 == null)) {
        $gameline1 = '#FFFFFF';
    }
    pnModSetVar('Standings', 'gameline1', $gameline1);

    if (!isset($gameline2) || ($gameline2 == null)) {
        $gameline2 = '#CCCCCC';
    }
    pnModSetVar('Standings', 'gameline2', $gameline2);

    if (!isset($gamemainheader) || ($gamemainheader == null)) {
        $gamemainheader = '#0099CC';
    }
    pnModSetVar('Standings', 'gamemainheader', $gamemainheader);

    if (!isset($gameheader) || ($gameheader == null)) {
        $gameheader = '#003399';
    }
    pnModSetVar('Standings', 'gameheader', $gameheader);

    if (!isset($gamestatcol) || ($gamestatcol == null)) {
        $gamestatcol = '#FFFFFF';
    }
    pnModSetVar('Standings', 'gamestatcol', $gamestatcol);

    if (!isset($gamemin) || ($gamemin == null)) {
        $gamemin = 40;
    }
    pnModSetVar('Standings', 'gamemin', $gamemin);

    if (!isset($playercolmn) || ($playercolmn == null)) {
        $playercolmn = 3;
    }
    pnModSetVar('Standings', 'playercolmn', $playercolmn);

    // 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('Standings', 'admin', 'view'));

    // Return
    return true;
}

//////
/// Main administration menu
//////
function standings_adminmenu()
{
    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output = new pnHTML();

    // Display status message if any.  Note that in future this functionality
    // will probably be in the theme rather than in this menu, but this is the
    // best place to keep it for now
    $output->Text(pnGetStatusMsg());
    $output->Linebreak(2);

    // Start options menu
    $output->TableStart(_STANDINGS);
    $output->SetOutputMode(_PNH_RETURNOUTPUT);

    // Menu options.  These options are all added in a single row, to add
    // multiple rows of options the code below would just be repeated
    $columns = array();
    $columns[] = $output->URL(pnModURL('Standings',
                                        'admin',
                                        'new'),
                              _NEWSTANDINGS); 
    $columns[] = $output->URL(pnModURL('Standings',
                                        'admin',
                                        'view'),
                              _VIEWSTANDINGS); 
    $columns[] = $output->URL(pnModURL('Standings',
                                        'admin',
                                        'modifyconfig'),
                              _EDITSTANDINGSCONFIG); 

    $output->SetOutputMode(_PNH_KEEPOUTPUT);
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableAddRow($columns);
    $output->SetInputMode(_PNH_PARSEINPUT);

    $output->TableEnd();

    // Return the output that has been generated by this function
    return $output->GetOutput();
}


?>
Return current item: Standings module for sports