Location: PHPKode > projects > Standings module for sports > pnuser.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 user display functions
// ----------------------------------------------------------------------------

//////
/// the main user function
//////
function standings_user_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 overview
    // privilege for some item within this component, or else they won't be
    // able to see anything and so we refuse access altogether.  The lowest
    // level of access for administration depends on the particular module, but
    // it is generally either 'overview' or 'read'
    if (!pnSecAuthAction(0, 'Standings::', "::", 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// View Teams
//////
function standings_user_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
    $cid = pnVarCleanFromInput('cid');

    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();

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // 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_OVERVIEW)) {
        $output->Text(_STANDINGSNOAUTH);
        return $output->GetOutput();
    }

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  The arguments to the function are passed in
    // as their own arguments array
    $items = pnModAPIFunc('Standings',
                          'user',
                          'getteams',
                          array('cid' => $cid));

    // 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 ($items == false) {
        $output->Text(_STANDINGSITEMFAILED);
    }

    // Loop through each item and display it.  Note the use of pnVarCensor() to
    // remove any words from the name that the administrator has deemed
    // unsuitable for the site
    $output->SetInputMode(_PNH_VERBATIMINPUT);

    foreach ($items as $item) {
        
        if (pnSecAuthAction(0,
                            'Standings::Team',
                            "$item[title]::$item[tid]",
                            ACCESS_READ)) {
            $output->URL(pnModURL('Standings',
                                  'user',
                                  'display',
                                  array('tid' => $item['tid'])),
                         pnVarPrepForDisplay(pnVarCensor($item['title'])));
            $output->Linebreak();
        }
    }
    $output->SetInputMode(_PNH_PARSEINPUT);

    // 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',
                                  'user',
                                  'view',
                                  array('startnum' => '%%')),
                         pnModGetVar('Standings', 'itemsperpage'));

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



//////
/// display Teams
//////
function standings_user_displayteams($args)
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    // 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 $tid
    //
    // 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;
    }

    // get the configured colors for the tables
    $back = pnModGetVar('Standings', 'schedulebkgnd');
    $hedr = pnModGetVar('Standings', 'scheduleheader');
    $sepr = pnModGetVar('Standings', 'schedulesep');

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  The arguments to the function are passed in
    // as their own arguments array
    $item = pnModAPIFunc('Standings',
                          'user',
                          'getteams',
                          array('cid' => $cid));

    // 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 ($item == false) {
        $output->Text(_STANDINGSITEMFAILED);
        return $output->GetOutput();
    }

    // Show Team table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(2);
    $output->TableStart();

    $output->Text("<tr bgcolor=".$hedr."><td align=center>");
    $output->BoldText(_STANDINGSTEAMNAME);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTEAMCITY);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTEAMCONTACT);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTEAMPHONE);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTEAMFIELD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTEAMEMAIL);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTEAMWWW);
    $output->Text("</td></tr>");


    // Display details of the item.  Note the use of pnVarCensor() to remove
    // any words from the name that the administrator has deemed unsuitable for
    // the site.  Also note that a module variable is used here to determine
    // whether not not parts of the item information should be displayed in
    // bold type or not
    foreach ($item as $team)
    {
        $output->Text("<tr bgcolor=".$back."><td align=center>");
        $output->URL(pnModURL('Standings',
                              'user',
                              'displayteam',
                              array('tid' => $team[tid])),$team[team]);
        $output->Text("</td><td align=center>");
        $output->Text($team[city]);
        $output->Text("</td><td align=center>");
        $output->Text($team[contact]);
        $output->Text("</td><td align=center>");
        if ($team[phone] != null) {
            $output->Text("<a title='".$team[phone]."'><img src='modules/".$modinfo['directory'].
                          "/pnimages/phone.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
        $output->Text("</td><td align=center>");
        if ($team[paddress] != null) {
            $output->Text("<a title='".$team[paddress]."'><img src='modules/".$modinfo['directory'].
                          "/pnimages/field.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
        $output->Text("</td><td align=center>");
        if ($team[email] != null) {
            $output->Text("<a href=mailto:".$team[email]."><img src='modules/".$modinfo['directory'].
                          "/pnimages/email.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
        $output->Text("</td><td align=center>");
        if ($team[homepage] != null) {
            $output->Text("<a href=http://".$team[homepage]."><img src='modules/".$modinfo['directory'].
                          "/pnimages/site.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
        $output->Text("</td></tr>");
        $output->Text("<tr bgcolor=".$sepr." height=1><td colspan=7></td></tr>");
    }

    $output->TableEnd();

    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// display Player's list
//////
function standings_user_displayplayers($args)
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    // 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 $tid
    //
    // 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();

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  The arguments to the function are passed in
    // as their own arguments array
    $item = pnModAPIFunc('Standings',
                          'user',
                          'getplayerst',
                          array('cid' => $cid));

    // 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 ($item == false) {
        $output->Text(_STANDINGSITEMFAILED);
        return $output->GetOutput();
    }

    $alpha = array('A','B','C','D','E','F','G','H','I','J','K','L','M',
                   'N','O','P','Q','R','S','T','U','V','W','Y','Z');

    // Show Players table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(2);

    $output->Text("<a name='top'></a>");
    $output->Text("<table align='center' border='0' width='50%' bgcolor='#ff8a2f'><tr><td>\n");
    $output->Text("<table align='center' border='0' width='100%' cellpadding=0 cellspacing=1 bgcolor='#ffffff'>\n");
    $output->Text("<tr><td align='center' bgcolor='#ff8a2f'><b><font class='pn-title'>"._STANDINGSPLAYERS."</font></b></td></tr>");
    $output->Text("<tr><td align='center'><br>");

    $num = count($alpha) - 1;
    $output->Text("[ ");
    $counter = 0;

        while(list(, $ltr) = each($alpha)) {
            $output->Text("<a class='pn-normal' href='#$ltr'>$ltr</a>");
            if ($counter == round($num/2)) {
                $output->Text(" ]\n<br>\n[ ");
            } elseif($counter != $num) {
                $output->Text("&nbsp;|&nbsp;\n");
            }
            $counter++;
        }
        $output->Text(" ]<br><br>\n");

    $output->Text("</td></tr>");
    $output->Text("</table>\n");
    $output->Text("</td></tr></table>\n");



    $numcol = pnModGetVar('Standings', 'playercolmn');;
    $curcol = 0;
    $i = 0;
    // start the list from the 1st letter
    $curltr = $alpha[$i];

    $output->TableStart();

    // Display details of the item.  Note the use of pnVarCensor() to remove
    // any words from the name that the administrator has deemed unsuitable for
    // the site.  Also note that a module variable is used here to determine
    // whether not not parts of the item information should be displayed in
    // bold type or not
    $output->Text("<tr><td align=left colspan=$numcol>&nbsp;</td></tr>");
    $output->Text("<tr><td align=left colspan=$numcol-1><font size='5' color='#ff8a2f'><b><a name='$curltr'>$curltr</a></b></font></td></tr>");

    foreach ($item as $player)
    {

        while ($curltr != strtoupper(substr($player[fname],0,1)) ) {
            $output->Text("</tr>");
            $i++;
            $curltr = $alpha[$i];
            $output->Text("<tr><td align='center' colspan=$numcol>[ <a href='#top'>"._STANDINGSPLAYERSTOP."</a> ]</td></tr>");
            $output->Text("<tr><td align=left colspan=$numcol>&nbsp;</td></tr>");
            $output->Text("<tr><td align=left colspan=$numcol><font size='5' color='#ff8a2f'><b><a name='$curltr'>$curltr</a></b></font></td></tr>");
            $curcol = 0;
        }

        if ($curcol != $numcol) {
            $output->Text("<td align=left>");
            $output->URL(pnModURL('Standings',
                                  'user',
                                  'displayplayer',
                                  array('pid' => $player[pid])),$player[fname].", ".$player[name]);
            $output->Text("</td>");
            $curcol++;
        } else {
            $output->Text("</tr><tr>");
            $curcol = 0;
        }

    }

    $output->TableEnd();

    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// display Tournament schedules
//////
function standings_user_displaysched($args)
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    // 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 $tid
    //
    // 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;
    }

    // get the configured colors for the tables
    $back = pnModGetVar('Standings', 'schedulebkgnd');
    $hedr = pnModGetVar('Standings', 'scheduleheader');
    $sepr = pnModGetVar('Standings', 'schedulesep');

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // Get all the schedules for the given cid
    // The API function is called.  The arguments to the function are passed in
    // as their own arguments array
    $item = pnModAPIFunc('Standings',
                          'user',
                          'getcals',
                          array('cid' => $cid));

    // 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 ($item == false) {
        $output->Text(_STANDINGSITEMFAILED);
        return $output->GetOutput();
    }

    // Show Team table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(2);


    $output->TableStart();
    $output->TableRowStart();
    $output->TableColStart();


    // Display details of the item.  Note the use of pnVarCensor() to remove
    // any words from the name that the administrator has deemed unsuitable for
    // the site.  Also note that a module variable is used here to determine
    // whether not not parts of the item information should be displayed in
    // bold type or not

    $currid = 0;
    $col = 0;
    foreach ($item as $sched)
    {


        // get current round ID
        if ($currid != $sched[rid]) {

           if ($currid != 0) {
               if (Floor($col/2)*2 == $col) {
                   $output->TableEnd();
                   $output->TableColEnd();
                   $output->TableRowEnd();
                   $output->TableRowStart();
                   $output->TableColStart();
               } else {
                   $output->TableEnd();
                   $output->TableColEnd();
                   $output->TableColStart();
               }
           }


               $currid = $sched[rid];
               $col++;

               $output->TableStart(_STANDINGSSCHEDGAME . " " . $currid);
               $output->Text("<tr bgcolor=".$hedr.">");
               $output->Text("<td align=center width=20% colspan=2>");
               $output->BoldText(_STANDINGSSCHEDTEAMA);
               $output->Text("</td><td align=center width=10%>");
               $output->Text("");
               $output->Text("</td><td align=center width=20%>");
               $output->BoldText(_STANDINGSSCHEDTEAMB);
               $output->Text("</td></tr>");
               
        }

        // Get the team name given its ID
        $tma = pnModAPIFunc('Standings',
                            'user',
                            'getteam',
                            array('tid' => $sched[teama]));

        $tmb = pnModAPIFunc('Standings',
                            'user',
                            'getteam',
                            array('tid' => $sched[teamb]));

        $output->Text("<tr bgcolor=".$back.">");

        // if info available, show the info picture
        $output->Text("<td align=center width=2%>");
        if (($sched[date] != null) | ($sched[time] != null)) {
               $output->Text("<a title='" . _STANDINGSSCHEDDAY . ": " . 
                             $sched[date] . "  " . _STANDINGSSCHEDTIME . ": " . $sched[time] . 
                             "'><img src='modules/" . $modinfo['directory'] . 
                             "/pnimages/info.gif' border=0></a>");
        } else {
               $output->Text("&nbsp;");
        }
        $output->Text("</td>");

        $output->Text("<td align=center>");
        $output->Text($tma[team]);
        $output->Text("</td><td align=center>");
        if ($sched[scorea] == -1) {
               $sched[scorea] = " ";
               $sched[scoreb] = " ";
        }
        $output->URL(pnModURL('Standings',
                              'user',
                              'displaygame',
                               array('tcid' => $sched[tcid])),$sched[scorea]." - ".$sched[scoreb]);
        $output->Text("</td><td align=center>");
        $output->Text($tmb[team]);
        $output->Text("</td></tr>");
        $output->Text("<tr bgcolor=".$sepr." height=1><td colspan=5></td></tr>");

    }

    $output->TableEnd();
    $output->TableEnd();

    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// display Game result details
//////
function standings_user_displaygame($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,
         $objectid) = pnVarCleanFromInput('tcid',
                                          '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 $tid
    //
    // 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;
    }

    // get the configured colors for the tables
    $colo1     = pnModGetVar('Standings', 'gameline1');      // #ffffff
    $colo2     = pnModGetVar('Standings', 'gameline2');      // #cccccc
    $mainhdr   = pnModGetVar('Standings', 'gamemainheader'); // #0099cc
    $headr     = pnModGetVar('Standings', 'gameheader');     // #003399
    $statcol   = pnModGetVar('Standings', 'gamestatcol');    // #ffffff

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // Get all the schedule info for the given tcid
    $sched = pnModAPIFunc('Standings',
                          'user',
                          'getcal',
                          array('tcid' => $tcid));

    // 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 ($sched == false) {
        $output->Text(_STANDINGSITEMFAILED);
        return $output->GetOutput();
    }

    // Get all the scouts for the given teamA ID
    // and schedule tcid
    $scouta = pnModAPIFunc('Standings',
                           'user',
                           'getscouts',
                            array('tid' => $sched[teama],
                                  'tcid' => $tcid));

    // Get all the scouts for the given teamB ID
    // and schedule tcid
    $scoutb = pnModAPIFunc('Standings',
                           'user',
                           'getscouts',
                            array('tid' => $sched[teamb],
                                  'tcid' => $tcid));

    // Get team info
    $tma = pnModAPIFunc('Standings',
                           'user',
                           'getteam',
                            array('tid' => $sched[teama]));

    // Get team info
    $tmb = pnModAPIFunc('Standings',
                           'user',
                           'getteam',
                            array('tid' => $sched[teamb]));

    // do not display un-played game results
    if ($sched[scorea]==-1) {
           $sched[scorea]=" ";
           $sched[scoreb]=" ";
    }

    // Show game stats table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(3);
    $output->TableStart($tma[team]." ".$sched[scorea]." - ".$tmb[team]." ".$sched[scoreb]);
    $output->Text("<tr><td align=left colspan=4><font color='#000000'>$tma[city]: $sched[date] ($sched[time]) - $tma[paddress]</font></td></tr>");
    $output->Text("<tr><td align=left colspan=4><font color='#000000'><b>"._STANDINGSGAMEOFFIC."</b>: $sched[offic1] - $sched[offic2] - $sched[offic3]</font></td></tr>");

    // Display Team A scouts
    // Player stats
    $output->Text("<tr bgcolor=#cccccc><td align=left colspan=4>");
    $output->Text("<table valign=center border=0 width=100% cellpadding=0 cellspacing=0 bgcolor=$mainhdr> \n");
    $output->Text("<tr align=center><td colspan=20 bgcolor=$headr><b><font color=$statcol>$tma[team]</b></td></tr>");
    $output->Text("<tr align=center><td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPLAYER."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER5."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERMIN."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFGMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFGP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERTPMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER3PP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFTMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER1PP."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERREB."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERASS."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERSTE."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERBLK."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERTO."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPF."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERVAL."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPTS."</b></td>");
    $output->Text("</tr></font>");

    $output->Text("<tr align='center'>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYEROFF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERDEF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERMADE."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERSUFF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERMADE."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERSUFF."</b></td>");
    $output->Text("</tr></font>");

    if ($scouta != false) {
        foreach ($scouta as $scout)
        {
             $i++;
             $rowcol = (Floor($i/2)*2 == $i) ? $colo1 : $colo2;

             // Calculate percentages
             if ($scout[fga]>0) {
                  $fgp=number_format($scout[fgm]/$scout[fga],3);
             } else {
                  $fgp = number_format($scout[fga],3);
             }
             if ($scout[tpa]>0) {
                  $tpp=number_format($scout[tpm]/$scout[tpa],3);
             } else {
                  $tpp = number_format($scout[tpa],3);
             }
             if ($scout[fta]>0) {
                  $ftp=number_format($scout[ftm]/$scout[fta],3);
             } else {
                  $ftp = number_format($scout[fta],3);
             }

             if ($scout[start]==1) {
                  $sta="*";
             } else {
                  $sta = "&nbsp;";
             }

             // Calculate Player's Game Evaluation
             // as follows: (positives) - (negatives)
             // where:
             //       positives = points|rebounds|blocks|faults-received|steals|assists
             //       negatives = wrong throws|blocks-received|faults|turnovers
             $evalu = $scout[pts] + $scout['or'] + $scout['dr'] + $scout[blk] + $scout[pfr] + $scout[ste] + $scout[ass]
                      - ($scout[fga]-$scout[fgm]) - ($scout[tpa]-$scout[tpm]) - ($scout[fta]-$scout[ftm]) - $scout[blkr] - $scout[pf] - $scout[to];

             // made it dependant on the time played
             $bytime = pnModGetVar('Standings', 'valbytime');
             $gamemin = pnModGetVar('Standings', 'gamemin');
             if ($bytime == 1) {
                 $evalu = round($evalu * $gamemin / $scout[mins]);
             }
                 

             // Get the player name given its ID
             $ply = pnModAPIFunc('Standings',
                                 'user',
                                 'getplayer',
                                  array('pid' => $scout[pid]));

             $output->Text("<tr align=center bgcolor=$rowcol height='18'>");
             $output->Text("<td><font color=#000000>");
             $output->URL(pnModURL('Standings',
                                    'user',
                                    'displayplayer',
                                     array('pid' => $scout[pid])),$ply[fname] . " " . substr($ply[name],0,1) .".");

             $output->Text("</td><td><font color=#000000>$sta</td><td><font color=#000000>$scout[mins]</td>");
             $output->Text("<td><font color=#000000>$scout[fgm]-$scout[fga]</td><td><font color=#000000>$fgp</td><td><font color=#000000>$scout[tpm]-$scout[tpa]</td><td><font color=#000000>$tpp</td>");
             $output->Text("<td><font color=#000000>$scout[ftm]-$scout[fta]</td><td><font color=#000000>$ftp</td><td><font color=#000000>$scout[or]</td><td><font color=#000000>$scout[dr]</td>");
             $output->Text("<td><font color=#000000>$scout[ass]</td><td><font color=#000000>$scout[ste]</td><td><font color=#000000>$scout[blk]</td><td><font color=#000000>$scout[blkr]</td><td><font color=#000000>$scout[to]</td>");
             $output->Text("<td><font color=#000000>$scout[pf]</td><td><font color=#000000>$scout[pfr]</td><td><font color=#000000>$evalu</td><td><b><font color=#000000>$scout[pts]</b></td>");
             $output->Text("</tr>");

        // calculate totals
             $totmina += $scout[mins];
             $totfgma += $scout[fgm];
             $totfgaa += $scout[fga];
             $tottpma += $scout[tpm];
             $tottpaa += $scout[tpa];
             $totftma += $scout[ftm];
             $totftaa += $scout[fta];
             $totreba += ($scout['dr']+$scout['or']);
             $totassa += $scout[ass];
             $totstea += $scout[ste];
             $totblka += $scout[blk];
             $totblkra += $scout[blkr];
             $tottoa += $scout[to];
             $totpfa += $scout[pf];
             $totpfra += $scout[pfr];
             $totvala += $evalu;
             $totptsa += $scout[pts];

        }
    }

             // Calculate percentages
             if ($totfgaa>0) {
                  $fgp=number_format($totfgma/$totfgaa*100,1);
             } else {
                  $fgp = number_format($totfgaa,1);
             }
             if ($tottpaa>0) {
                  $tpp=number_format($tottpma/$tottpaa*100,1);
             } else {
                  $tpp = number_format($tottpaa,1);
             }
             if ($totftaa>0) {
                  $ftp=number_format($totftma/$totftaa*100,1);
             } else {
                  $ftp = number_format($totftaa,1);
             }

    // display totals for team B
    $output->Text("<tr align=center height=1 colspan=20></tr>");
    $output->Text("<tr align=center bgcolor=#c0c0c0>");
    $output->Text("<td colspan=2><font color=#000000>&nbsp;"._STANDINGSPLAYERTOTAL."</td>");
    $output->Text("<td><font color=#000000>$totmina</td>");
    $output->Text("<td><font color=#000000>$totfgma-$totfgaa</td><td><font color=#000000>$fgp%</td><td><font color=#000000>$tottpma-$tottpaa</td><td><font color=#000000>$tpp%</td>");
    $output->Text("<td><font color=#000000>$totftma-$totftaa</td><td><font color=#000000>$ftp%</td><td colspan=2><font color=#000000>$totreba</td></td>");
    $output->Text("<td><font color=#000000>$totassa</td><td><font color=#000000>$totstea</td><td><font color=#000000>$totblka</td><td><font color=#000000>$totblkra</td><td><font color=#000000>$tottoa</td>");
    $output->Text("<td><font color=#000000>$totpfa</td><td><font color=#000000>$totpfra</td><td><font color=#000000>$totvala</td><td><b><font color=#000000>$totptsa</b></td>");
    $output->Text("</tr>");

    $output->Text("</table>\n");
    $output->Text("</td></tr>\n");
    $output->Text("<tr><td colspan=20>&nbsp;</td></tr>\n");


    // Display Team B scouts
    // Player stats
    $output->Text("<tr bgcolor=#cccccc><td align=left colspan=4>");
    $output->Text("<table valign=center border=0 width=100% cellpadding=0 cellspacing=0 bgcolor=$mainhdr> \n");
    $output->Text("<tr align=center><td colspan=20 bgcolor=$headr><b><font color=$statcol>$tmb[team]</b></td></tr>");
    $output->Text("<tr align=center><td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPLAYER."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER5."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERMIN."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFGMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFGP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERTPMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER3PP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFTMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER1PP."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERREB."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERASS."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERSTE."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERBLK."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERTO."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPF."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERVAL."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPTS."</b></td>");
    $output->Text("</tr></font>");

    $output->Text("<tr align='center'>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYEROFF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERDEF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERMADE."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERSUFF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERMADE."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERSUFF."</b></td>");
    $output->Text("</tr></font>");

    if ($scoutb != false) {
        foreach ($scoutb as $scout)
        {
             $i++;
             $rowcol = (Floor($i/2)*2 == $i) ? $colo1 : $colo2;

             // Calculate percentages
             if ($scout[fga]>0) {
                  $fgp=number_format($scout[fgm]/$scout[fga],3);
             } else {
                  $fgp = number_format($scout[fga],3);
             }
             if ($scout[tpa]>0) {
                  $tpp=number_format($scout[tpm]/$scout[tpa],3);
             } else {
                  $tpp = number_format($scout[tpa],3);
             }
             if ($scout[fta]>0) {
                  $ftp=number_format($scout[ftm]/$scout[fta],3);
             } else {
                  $ftp = number_format($scout[fta],3);
             }

             if ($scout[start]==1) {
                  $sta="*";
             } else {
                  $sta = "&nbsp;";
             }

             // Calculate Player's Game Evaluation
             // as follows: (positives) - (negatives)
             // where:
             //       positives = points|rebounds|blocks|faults-received|steals|assists
             //       negatives = wrong throws|blocks-received|faults|turnovers
             $evalu = $scout[pts] + $scout['or'] + $scout['dr'] + $scout[blk] + $scout[pfr] + $scout[ste] + $scout[ass]
                      - ($scout[fga]-$scout[fgm]) - ($scout[tpa]-$scout[tpm]) - ($scout[fta]-$scout[ftm]) - $scout[blkr] - $scout[pf] - $scout[to];

             // made it dependant on the time played
             if ($bytime == 1) {
                 $evalu = round($evalu * 40.0 / $scout[mins]);
             }

             // Get the player name given its ID
             $ply = pnModAPIFunc('Standings',
                                 'user',
                                 'getplayer',
                                  array('pid' => $scout[pid]));

             $output->Text("<tr align=center bgcolor=$rowcol height='18'>");
             $output->Text("<td><font color=#000000>");
             $output->URL(pnModURL('Standings',
                                    'user',
                                    'displayplayer',
                                     array('pid' => $scout[pid])),$ply[fname] . " " . substr($ply[name],0,1) .".");

             $output->Text("</td><td><font color=#000000>$sta</td><td><font color=#000000>$scout[mins]</td>");
             $output->Text("<td><font color=#000000>$scout[fgm]-$scout[fga]</td><td><font color=#000000>$fgp</td><td><font color=#000000>$scout[tpm]-$scout[tpa]</td><td><font color=#000000>$tpp</td>");
             $output->Text("<td><font color=#000000>$scout[ftm]-$scout[fta]</td><td><font color=#000000>$ftp</td><td><font color=#000000>$scout[or]</td><td><font color=#000000>$scout[dr]</td>");
             $output->Text("<td><font color=#000000>$scout[ass]</td><td><font color=#000000>$scout[ste]</td><td><font color=#000000>$scout[blk]</td><td><font color=#000000>$scout[blkr]</td><td><font color=#000000>$scout[to]</td>");
             $output->Text("<td><font color=#000000>$scout[pf]</td><td><font color=#000000>$scout[pfr]</td><td><font color=#000000>$evalu</td><td><b><font color=#000000>$scout[pts]</b></td>");
             $output->Text("</tr>");

        // calculate totals
             $totminb += $scout[mins];
             $totfgmb += $scout[fgm];
             $totfgab += $scout[fga];
             $tottpmb += $scout[tpm];
             $tottpab += $scout[tpa];
             $totftmb += $scout[ftm];
             $totftab += $scout[fta];
             $totrebb += ($scout['dr']+$scout['or']);
             $totassb += $scout[ass];
             $totsteb += $scout[ste];
             $totblkb += $scout[blk];
             $totblkrb += $scout[blkr];
             $tottob += $scout[to];
             $totpfb += $scout[pf];
             $totpfrb += $scout[pfr];
             $totvalb += $evalu;
             $totptsb += $scout[pts];

        }
    }

             // Calculate percentages
             if ($totfgab>0) {
                  $fgp=number_format($totfgmb/$totfgab*100,1);
             } else {
                  $fgp = number_format($totfgab,1);
             }
             if ($tottpab>0) {
                  $tpp=number_format($tottpmb/$tottpab*100,1);
             } else {
                  $tpp = number_format($tottpab,1);
             }
             if ($totftab>0) {
                  $ftp=number_format($totftmb/$totftab*100,1);
             } else {
                  $ftp = number_format($totftab,1);
             }

    // display totals for team B
    $output->Text("<tr align=center height=1 colspan=18></tr>");
    $output->Text("<tr align=center bgcolor=#c0c0c0>");
    $output->Text("<td colspan=2><font color=#000000>&nbsp;"._STANDINGSPLAYERTOTAL."</td>");
    $output->Text("<td><font color=#000000>$totminb</td>");
    $output->Text("<td><font color=#000000>$totfgmb-$totfgab</td><td><font color=#000000>$fgp%</td><td><font color=#000000>$tottpmb-$tottpab</td><td><font color=#000000>$tpp%</td>");
    $output->Text("<td><font color=#000000>$totftmb-$totftab</td><td><font color=#000000>$ftp%</td><td colspan=2><font color=#000000>$totrebb</td></td>");
    $output->Text("<td><font color=#000000>$totassb</td><td><font color=#000000>$totsteb</td><td><font color=#000000>$totblkb</td><td><font color=#000000>$totblkrb</td><td><font color=#000000>$tottob</td>");
    $output->Text("<td><font color=#000000>$totpfb</td><td><font color=#000000>$totpfrb</td><td><font color=#000000>$totvalb</td><td><b><font color=#000000>$totptsb</b></td>");
    $output->Text("</tr>");

    $output->Text("</table>\n");
    $output->Text("</td></tr>\n");

    $output->TableEnd();
    $output->LineBreak(2);

    //////
    /// score by Quarters
    //////
    $output->TableStart(null, null, 0, '40%');
    $output->Text("<tr align='center'><td>&nbsp;</td><td><font color='#000000'>"._STANDINGSSCHEDQUARTER."1</font></td>");
    $output->Text("<td><font color='#000000'>"._STANDINGSSCHEDQUARTER."2</font></td>");
    $output->Text("<td><font color='#000000'>"._STANDINGSSCHEDQUARTER."3</font></td>");
    $output->Text("<td><font color='#000000'>"._STANDINGSSCHEDQUARTER."4</font></td>");
    if ($sched[ot1a] != 0) {
       $output->Text("<td><font color='#000000'>"._STANDINGSSCHEDOVERTIME."1</font></td>");
    }
    if ($sched[ot2a] != 0) {
       $output->Text("<td><font color='#000000'>"._STANDINGSSCHEDOVERTIME."2</font></td>");
    }
    if ($sched[ot3a] != 0) {
       $output->Text("<td><font color='#000000'>"._STANDINGSSCHEDOVERTIME."3</font></td>");
    }
    $output->Text("<td><font color='#000000'><b>"._STANDINGSSCHEDFINAL."</b></font></td></tr>");

    // TeamA
    $output->Text("<tr align='center'><td align='left'><font size=2 color='#000000'>$tma[team]</font></td><td>$sched[q1a]</td><td>$sched[q2a]</td><td>$sched[q3a]</td><td>$sched[q4a]</td>");
    if ($sched[ot1a] != 0) {
       $output->Text("<td><font color='#000000'>$sched[ot1a]</font></td>");
    }
    if ($sched[ot2a] != 0) {
       $output->Text("<td><font color='#000000'>$sched[ot2a]</font></td>");
    }
    if ($sched[ot3a] != 0) {
       $output->Text("<td><font color='#000000'>$sched[ot3a]</font></td>");
    }
    $output->Text("<td><font color='#000000'><b>$sched[scorea]</b></font></td></tr>");

    // TeamB
    $output->Text("<tr align='center'><td align='left'><font size=2 color='#000000'>$tmb[team]</font></td><td>$sched[q1b]</td><td>$sched[q2b]</td><td>$sched[q3b]</td><td>$sched[q4b]</td>");
    if ($sched[ot1b] != 0) {
       $output->Text("<td><font color='#000000'>$sched[ot1b]</font></td>");
    }
    if ($sched[ot2b] != 0) {
       $output->Text("<td><font color='#000000'>$sched[ot2b]</font></td>");
    }
    if ($sched[ot3b] != 0) {
       $output->Text("<td><font color='#000000'>$sched[ot3b]</font></td>");
    }
    $output->Text("<td><font color='#000000'><b>$sched[scoreb]</b></font></td></tr>");

    $output->TableEnd();



    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// display Team Info
//////
function standings_user_displayteam($args)
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    // 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 $tid
    //
    // 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();

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

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

    // Get the Team info
    $team = pnModAPIFunc('Standings',
                         'user',
                         'getteam',
                         array('tid' => $tid));

    // Get the Team schedules
    $sch = pnModAPIFunc('Standings',
                        'user',
                        'getteamcal',
                        array('tid' => $tid));

    // Show Players table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(2);

    $output->TableStart($team[team],null,0,'100%');

    ////
    // Start 1st row: Description - Team picture - Team info
    ////
    $output->TableRowStart();

    // social colors
    $imgt = "modules/".$modinfo['directory']. "/pnimages/photos/colors/t" . $team[tshirt] . ".jpg";
    $imgt = "<img src='$imgt' border=0>";
    $imgp = "modules/".$modinfo['directory']. "/pnimages/photos/colors/p" . $team[shorts] . ".jpg";
    $imgp = "<img src='$imgp' border=0>";

    $output->Text("<td width='25%'>");
    $output->Text("<table border='0' width='100%'><tr><td>\n");
    $output->Text("<table align='center' border='0' width='99%' cellpadding=0 cellspacing=1 bgcolor='#ffffff'>\n");
    $output->Text("<tr><td align='center' bgcolor='ff8a2f'><font class='pn-title'>&nbsp;"._STANDINGSTEAMCOLORS."</font></td></tr>");
    $output->Text("<tr><td align='center' valign='bottom'>&nbsp;$imgt</td></tr>");
    $output->Text("<tr><td align='center' valign='top'>&nbsp;$imgp</td></tr>");
    $output->Text("</table>\n");
    $output->Text("</td></tr></table>\n");
    $output->TableColEnd();

    // Team Picture
    $imgfile = "modules/".$modinfo['directory']. "/pnimages/photos/teams/team" . $tid . ".jpg";
    $img = "<img width='220' height='160' src='$imgfile' border='0'>";

    if (!file_exists($imgfile)) {
         $img = ""._STANDINGSTEAMNOPHOTO;
    }

    $output->Text("<td colspan='2'>");
    $output->Text("<table border='0' width='100%'><tr><td>\n");
    $output->Text("<table align='center' border='0' width='99%' cellpadding=0 cellspacing=1 bgcolor='#ff8a2f'>\n");
    $output->Text("<tr><td align='center' bgcolor='c0c0c0'>&nbsp;$img</td></tr>");
    $output->Text("</table>\n");
    $output->Text("</td></tr></table>\n");
    $output->TableColEnd();

    // Team Info
    $output->Text("<td width='25%'>");
    $output->Text("<table border='0' width='100%'><tr><td>\n");
    $output->Text("<table align='center' border='0' width='99%' cellpadding=0 cellspacing=1 bgcolor='#ff8a2f'>\n");
    $output->Text("<tr><td align='center' colspan='2'><font class='pn-title'><b>"._STANDINGSTEAMINFO."</b></font></td></tr>");
    $output->Text("<tr><td align='left' bgcolor='c0c0c0'><font color='#000000'>&nbsp;"._STANDINGSTEAMCITY."</font></td><td bgcolor='ffffff'>&nbsp;$team[city]</td></tr>");
    $output->Text("<tr><td align='left' bgcolor='c0c0c0'><font color='#000000'>&nbsp;"._STANDINGSTEAMCONTACT."</font></td><td bgcolor='ffffff'>&nbsp;$team[contact]</td></tr>");
    $output->Text("<tr><td align='left' bgcolor='c0c0c0'><font color='#000000'>&nbsp;"._STANDINGSTEAMPHONE."</font></td><td bgcolor='ffffff'>&nbsp;$team[phone]</td></tr>");

    $output->Text("<tr><td align='left' bgcolor='c0c0c0'><font color='#000000'>&nbsp;"._STANDINGSTEAMFIELD."</font></td><td bgcolor='ffffff' align='center'>&nbsp;");
        if ($team[paddress] != null) {
            $output->Text("<a title='".$team[paddress]."'><img src='modules/".$modinfo['directory'].
                          "/pnimages/field.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
    $output->Text("</td></tr>");

    $output->Text("<tr><td align='left' bgcolor='c0c0c0'><font color='#000000'>&nbsp;"._STANDINGSTEAMEMAIL."</font></td><td bgcolor='ffffff' align='center'>&nbsp;");
        if ($team[email] != null) {
            $output->Text("<a href=mailto:".$team[email]."><img src='modules/".$modinfo['directory'].
                          "/pnimages/email.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
    $output->Text("</td></tr>");

    $output->Text("<tr><td align='left' bgcolor='c0c0c0'><font color='#000000'>&nbsp;"._STANDINGSTEAMWWW."</font></td><td bgcolor='ffffff' align='center'>&nbsp;");
        if ($team[homepage] != null) {
            $output->Text("<a href=http://".$team[homepage]."><img src='modules/".$modinfo['directory'].
                          "/pnimages/site.gif' border=0></a>");
        } else {
            $output->Text("&nbsp;");
        }
    $output->Text("</td></tr>");

    $output->Text("</table>\n");
    $output->Text("</td></tr></table>\n");
    $output->TableColEnd();

    $output->TableRowEnd();

    ////
    // Start 2nd row: Roster details - Games list
    ////
    $output->TableRowStart();

    // Roster
    $output->Text("<td valign='top' colspan='2'>");
    $output->Text("<table border='0' width='100%'><tr><td>\n");
    $output->Text("<table align='center' border='0' width='99%' cellpadding=0 cellspacing=1 bgcolor='#ff8a2f'>\n");
    $output->Text("<tr><td align='center'><font color='#000000'><b>"._STANDINGSPLAYERNO."</b></font></td>");
    $output->Text("<td align='center'><font color='#000000'><b>"._STANDINGSPLAYERPLAYER."</b></font></td>");
    $output->Text("<td align='center'><font color='#000000'><b>"._STANDINGSPLAYERROLE."</b></font></td>");
    $output->Text("<td align='center'><font color='#000000'><b>"._STANDINGSPLAYERFROM."</b></font></td>");
    $output->Text("<td align='center'><font color='#000000'><b>"._STANDINGSPLAYERHEIGHT."</b></font></td>");
    $output->Text("<td align='center'><font color='#000000'><b>"._STANDINGSPLAYERWEIGHT."</b></font></td>");
    $output->Text("<td align='center'><font color='#000000'><b>"._STANDINGSPLAYERBIRTH."</b></font></td></tr>");

    // if roster not available
    if ($item == false) {
         $output->Text("<tr bgcolor='#ffffff'>");
         $output->Text("<td align='center'>&nbsp;</td>");
         $output->Text("<td align='left'>&nbsp;");
         $output->Text(_STANDINGSTEAMNOROSTER);
         $output->Text("</td><td align='center'>&nbsp;</td>");
         $output->Text("<td align='center'>&nbsp;</td>");
         $output->Text("<td align='center'>&nbsp;</td>");
         $output->Text("<td align='center'>&nbsp;</td>");
         $output->Text("<td align='center'>&nbsp;</td></tr>");
    } else {

         foreach ($item as $playr)
         {
              $output->Text("<tr bgcolor='#ffffff'>");
              $output->Text("<td align='center'>".$playr[number]."</td>");
              $output->Text("<td align='left'>&nbsp;");
              $output->URL(pnModURL('Standings',
                                   'user',
                                   'displayplayer',
                                   array('pid' => $playr[pid])),$playr[fname].", ".$playr[name]);
              $output->Text("</td><td align='center'>".$playr[role]."</td>");
              $output->Text("<td align='center'>".$playr[from]."</td>");
              $output->Text("<td align='center'>".$playr[height]."</td>");
              $output->Text("<td align='center'>".$playr[weight]."</td>");
              $output->Text("<td align='center'>".$playr[birth]."</td></tr>");

         }
    }

    $output->Text("</table>\n");
    $output->Text("</td></tr></table>\n");
    $output->TableColEnd();

    // Games list
    $output->Text("<td valign='top' width='30%' rowspan='2' colspan='2'>");
    $output->Text("<table border='0' width='100%'><tr><td>\n");
    $output->Text("<table align='center' border='0' width='99%' cellpadding='0' cellspacing='1' bgcolor='#ff8a2f'>\n");
    $output->Text("<tr bgcolor='#ffffff'><td align='center' colspan='4'><font color='#000000'><b>"._STANDINGSTEAMGAMES."</b></font></td>");

    foreach ($sch as $sched)
    {
         // define victory/defeat colors
         $vict = "<font color='00ff00'><b>&nbsp;"._STANDINGSTEAMGAMEWON."</b></font>";
         $deft = "<font color='ff0000'><b>&nbsp;"._STANDINGSTEAMGAMELOST."</b></font>";

         // check if game Won/Lost and Home/Away
         if ($sched[home] == 1) {
             $won = ($sched[scorea]>$sched[scoreb]) ? $vict : $deft;
             $where = ""._STANDINGSTEAMGAMEHOME;
         } else {
             $won = ($sched[scorea]>$sched[scoreb]) ? $deft : $vict;
             $where = ""._STANDINGSTEAMGAMEAWAY;
         }

         if ($sched[scorea] == -1) {
             $res = $sched[date];
             $won = "&nbsp;";
         } else {
             $res = $sched[scorea]." - ".$sched[scoreb];
         }

         // get the name of the opponent team given its ID
         $opteam = pnModAPIFunc('Standings',
                                'user',
                                'getteam',
                                array('tid' => $sched[opp]));

         $output->Text("<tr bgcolor='#ffffff'>");
         $output->Text("<td align='center'><font color='000000'>".$sched[rid]."</font></td>");
         $output->Text("<td align='center'>".$won."</td>");
         $output->Text("<td align='center'>&nbsp;".$where." <font color='000000'>");
         $output->URL(pnModURL('Standings',
                               'user',
                               'displayteam',
                               array('tid' => $sched[opp])),$opteam[team]);
         $output->Text("</font></td>");
         $output->Text("<td align='center'>");
         if ($sched[scorea] == -1) {
             $output->Text("<a title='".$sched[time]."'>".$res."</a>");
         } else {
             $output->URL(pnModURL('Standings',
                                   'user',
                                   'displaygame',
                                   array('tcid' => $sched[tcid])),$res);
         }
         $output->Text("</td></tr>");

    }

    $output->Text("</table>\n");
    $output->Text("</td></tr></table>\n");

    $output->TableColEnd();

    $output->TableRowEnd();

    ////
    // Start 3rd row: Players pictures
    ////

    $output->TableRowStart();
    $output->TableColStart(2,'left','middle',1);
    $output->TableStart();

    // Display details of the item.  Note the use of pnVarCensor() to remove
    // any words from the name that the administrator has deemed unsuitable for
    // the site.  Also note that a module variable is used here to determine
    // whether not not parts of the item information should be displayed in
    // bold type or not

    $output->TableRowStart();
    $i = -1;

    // if roster not available
    if ($item <> false) {

         foreach ($item as $player)
         {
         // Photo - player picture if available - default otherwise
         $imgfile = "modules/".$modinfo['directory']. "/pnimages/photos/players/pict" . $player[pid] . ".jpg";
         if (!file_exists($imgfile)) {
              $imgfile = "modules/".$modinfo['directory']. "/pnimages/photos/players/pshape.jpg";
         }
         $img = "<img src='$imgfile' border=0 height='70'>";
              $i++;
              if ((floor($i/4)*4)==$i) {
                  $output->TableRowEnd();
                  $output->TableRowStart();
              }
              $output->TableColStart();
              $output->URL(pnModURL('Standings',
                                   'user',
                                   'displayplayer',
                                   array('pid' => $player[pid])),$img . "<br>" . $player[name] . " " . $player[fname]);
              $output->TableColEnd();

         }
    }

    $output->TableRowEnd();

    // close 3rd row
    $output->TableColEnd();
    $output->TableEnd();
    $output->TableRowEnd();



    $output->TableEnd();

    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// display Player Info
//////
function standings_user_displayplayer($args)
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    // 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');

    // 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);

    // get the configured colors for the tables
    $colo1     = pnModGetVar('Standings', 'gameline1');
    $colo2     = pnModGetVar('Standings', 'gameline2');
    $headr     = pnModGetVar('Standings', 'gamemainheader');
    $statcol   = pnModGetVar('Standings', 'gamestatcol');

    // 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 $tid
    //
    // 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();

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // Get all the player info for the given pid
    $item = pnModAPIFunc('Standings',
                          'user',
                          'getplayer',
                          array('pid' => $pid));

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

    // Get player's scouts
    $scouts = pnModAPIFunc('Standings',
                          'user',
                          'getplayerscouts',
                          array('pid' => $pid));

    // Show Players table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(2);

    $output->TableStart($item[name] . " " . $item[fname] . " - " . $item[number]);

    // 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 ($item == false) {
        $output->Text(_STANDINGSITEMFAILED);
        $output->TableEnd();
        return $output->GetOutput();
    }


    // Display details of the item.  Note the use of pnVarCensor() to remove
    // any words from the name that the administrator has deemed unsuitable for
    // the site.  Also note that a module variable is used here to determine
    // whether not not parts of the item information should be displayed in
    // bold type or not
    $output->Text("<table border=0 width=100%><tr><td>\n");
    $output->Text("<table align=center border=0 width=99% cellpadding=8 cellspacing=1 bgcolor=#000000> \n");

    // Team
    $output->Text("<tr bgcolor=#cccccc><td align=center colspan=4>");
    $output->URL(pnModURL('Standings',
                          'user',
                          'displayteam',
                          array('tid' => $team[tid])),
                          $team[team]);
    $output->Text("</td></tr>");

    // Photo - player picture if available - default otherwise
    $imgfile = "modules/".$modinfo['directory']. "/pnimages/photos/players/pict" . $pid . ".jpg";
    if (!file_exists($imgfile)) {
         $imgfile = "modules/".$modinfo['directory']. "/pnimages/photos/players/blank.jpg";
    }

    $imgfilea = "modules/".$modinfo['directory']. "/pnimages/photos/players/picta" . $pid . ".jpg";
    if (!file_exists($imgfilea)) {
         $imgfilea = "modules/".$modinfo['directory']. "/pnimages/photos/players/blanka.jpg";
    }

    $imga = "<img width=140 height=200 src='$imgfilea' border=0>";
    $img = "<img width=85 height=100 src='$imgfile' border=0>";
    $output->Text("<tr><td bgcolor=#ffffff width=150 align=center>$img</td>");

    // Averages per game
    // Calculate averages
    if ($scouts != false) {
       foreach ($scouts as $scout)
       {
             $s++;
   
             $totmin += $scout[mins];
             $totfgm += $scout[fgm];
             $tottpm += $scout[tpm];
             $totftm += $scout[ftm];
             $totreb += ($scout['dr']+$scout['or']);
             $totass += $scout[ass];
             $totste += $scout[ste];
             $totblk += $scout[blk];
             $totblkr += $scout[blkr];
             $totto += $scout[to];
             $totpf += $scout[pf];
             $totpfr += $scout[pfr];
             $totpts += $scout[pts];
       }
    } else {
       $totpts = 0;
       $s = 1;
    }

    $mpg=number_format(($totmin/$s),1);
    $ppg=number_format(($totpts/$s),1);
    $fgpg=number_format(($totfgm/$s),1);
    $tppg=number_format(($tottpm/$s),1);
    $ftpg=number_format(($totftm/$s),1);
    $rpg=number_format(($totreb/$s),1);
    $apg=number_format(($totass/$s),1);
    $spg=number_format(($totste/$s),1);
    $bpg=number_format(($totblk/$s),1);
    $brpg=number_format(($totblkr/$s),1);
    $tpg=number_format(($totto/$s),1);
    $fpg=number_format(($totpf/$s),1);
    $frpg=number_format(($totpfr/$s),1);

    $output->Text("<td  bgcolor=#c0c0c0 align=center valign=top rowspan=2 width=20%>");
    $output->Text("<table border=0 width=100% cellpadding=0 cellspacing=0> \n");
    $output->Text("<tr align=center bgcolor=#ff8a2f><td colspan=2><b><font color=#ffffff>"._STANDINGSPLAYERPOINTS."</b></td></tr>");
    $output->Text("<tr align=center><td colspan=2><font color=#000000>$totpts</td></tr>");
    $output->Text("<tr><td colspan=2>&nbsp;</td></tr>");
    $output->Text("<tr align=center bgcolor=#ff8a2f><td colspan=2><b><font color=#ffffff>"._STANDINGSPLAYERAVERAGES."</b></td></tr>");
    // Minutes per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERMPP."</b></td>");
    $output->Text("<td align=right><font color=#cc0000>$mpg</td></tr>");
    // Points per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERPPG."</b></td>");
    $output->Text("<td align=right><font color=#cc0000>$ppg</td></tr>");
    // 2 Points per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYER2PG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$fgpg</td></tr>");
    // 3 Points per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYER3PG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$tppg</td></tr>");
    // Free Throws per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYER1PG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$ftpg</td></tr>");
    // Rebounds per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERREBPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$rpg</td></tr>");
    // Assists per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERASSPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$apg</td></tr>");
    // Steals per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERSTEPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$spg</td></tr>");
    // Blocks per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERBLKPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$bpg</td></tr>");
    // Blocks received per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERBLKRPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$brpg</td></tr>");
    // Turnovers per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERTOPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$tpg</td></tr>");
    // Personal Fouls per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERPFPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$fpg</td></tr>");
    // Personal Fouls Received per game
    $output->Text("<tr><td><b><font color=#000000>"._STANDINGSPLAYERPFRPG."</b></td>");
    $output->Text("<td align=right><font color=#000000>$frpg</td></tr>");
    $output->Text("</table>");
    $output->Text("</td>");

    // Notes
    $output->Text("<td  bgcolor=#ffffff align=left valign=top rowspan=2 width=20%><b>"._STANDINGSPLAYERCAREER."</b>:<br>$item[notes]</td>");
    $output->Text("<td  bgcolor=#ffffff align=center valign=top rowspan=2 width=35%>$imga</td></tr>");

    // Player's Info
    $output->Text("<tr bgcolor=#ffffff><td align=center>");
    $output->Text("<table border=0 width=100%>\n");
    $output->Text("<tr><td align=right width=50%><b>"._STANDINGSPLAYERROLE."</b>:</td><td align=left width=50%>$item[role]</td></tr>");
    $output->Text("<tr><td align=right width=50%><b>"._STANDINGSPLAYERBIRTH."</b>:</td><td align=left width=50%>$item[birth]</td></tr>");
    $output->Text("<tr><td align=right width=50%><b>"._STANDINGSPLAYERHEIGHT."</b>:</td><td align=left width=50%>$item[height]</td></tr>");
    $output->Text("<tr><td align=right width=50%><b>"._STANDINGSPLAYERWEIGHT."</b>:</td><td align=left width=50%>$item[weight]</td></tr>");
    $output->Text("<tr><td align=right width=50%><b>"._STANDINGSPLAYERFROM."</b>:</td><td align=left width=50%>$item[from]</td></tr>");
    $output->Text("</table>\n");
    $output->Text("</td></tr>");

    // Player stats
    $output->Text("<tr bgcolor=$colo2><td align=left colspan=4>");
    $output->Text("<table valign=center border=0 width=100% cellpadding=0 cellspacing=0 bgcolor=$headr> \n");
    $output->Text("<tr align=center><td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERGAME."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYEROPP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER5."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERMIN."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFGMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFGP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERTPMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER3PP."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERFTMA."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYER1PP."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERREB."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERASS."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERSTE."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERBLK."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERTO."</b></td>");
    $output->Text("<td colspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPF."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERVAL."</b></td>");
    $output->Text("<td rowspan='2'><b><font color=$statcol>"._STANDINGSPLAYERPTS."</b></td>");
    $output->Text("</tr></font>");

    $output->Text("<tr align=center>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYEROFF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERDEF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERMADE."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERSUFF."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERMADE."</b></td>");
    $output->Text("<td><b><font color=$statcol>"._STANDINGSPLAYERSUFF."</b></td>");
    $output->Text("</tr></font>");

    if ($scouts != false) {
       foreach ($scouts as $scout)
       {
             $i++;
             $rowcol = (Floor($i/2)*2 == $i) ? $colo1 : $colo2;

             // Calculate Player's Game Evaluation
             // as follows: (positives) - (negatives)
             // where:
             //       positives = points|rebounds|blocks|faults-received|steals|assists
             //       negatives = wrong throws|blocks-received|faults|turnovers
             $evalu = $scout[pts] + $scout['or'] + $scout['dr'] + $scout[blk] + $scout[pfr] + $scout[ste] + $scout[ass]
                      - ($scout[fga]-$scout[fgm]) - ($scout[tpa]-$scout[tpm]) - ($scout[fta]-$scout[ftm]) - $scout[blkr] - $scout[pf] - $scout[to];

             // made it dependant on the time played
             $bytime = pnModGetVar('Standings', 'valbytime');
             $gamemin = pnModGetVar('Standings', 'gamemin');
             if ($bytime == 1) {
                 $evalu = round($evalu * $gamemin / $scout[mins]);
             }

             // Calculate percentages
             if ($scout[fga]>0) {
                  $fgp=number_format($scout[fgm]/$scout[fga],3);
             } else {
                  $fgp = number_format($scout[fga],3);
             }
             if ($scout[tpa]>0) {
                  $tpp=number_format($scout[tpm]/$scout[tpa],3);
             } else {
                  $tpp = number_format($scout[tpa],3);
             }
             if ($scout[fta]>0) {
                  $ftp=number_format($scout[ftm]/$scout[fta],3);
             } else {
                  $ftp = number_format($scout[fta],3);
             }

             if ($scout[start]==1) {
                  $sta="*";
             } else {
                  $sta = "&nbsp;";
             }

             // find opponent team for given game
             $cal = pnModAPIFunc('Standings',
                                 'user',
                                 'getcal',
                                 array('tcid' => $scout[tcid]));

             // opponent ID
             $oppid = ($cal[teama] == $item[tid]) ? $cal[teamb] : $cal[teama];
             $oppteam = pnModAPIFunc('Standings',
                                     'user',
                                     'getteam',
                                     array('tid' => $oppid));
             $opponent = $oppteam[team];

             $output->Text("<tr align=center bgcolor=$rowcol>");
             $output->Text("<td><font color=#000000>");
             $output->URL(pnModURL('Standings',
                                   'user',
                                   'displaygame',
                                    array('tcid' => $scout[tcid])),$scout[rid]);
             $output->Text("</td><td><font color=#0000FF>");
             $output->URL(pnModURL('Standings',
                                   'user',
                                   'displayteam',
                                    array('tid' => $oppid)),"<font color=#0000FF>".$opponent);

             $output->Text("</td><td><font color=#000000>$sta</td><td><font color=#000000>$scout[mins]</td>");
             $output->Text("<td><font color=#000000>$scout[fgm]-$scout[fga]</td><td><font color=#000000>$fgp</td><td><font color=#000000>$scout[tpm]-$scout[tpa]</td><td><font color=#000000>$tpp</td>");
             $output->Text("<td><font color=#000000>$scout[ftm]-$scout[fta]</td><td><font color=#000000>$ftp</td><td><font color=#000000>$scout[or]</td><td><font color=#000000>$scout[dr]</td>");
             $output->Text("<td><font color=#000000>$scout[ass]</td><td><font color=#000000>$scout[ste]</td><td><font color=#000000>$scout[blk]</td><td><font color=#000000>$scout[blkr]</td><td><font color=#000000>$scout[to]</td>");
             $output->Text("<td><font color=#000000>$scout[pf]</td><td><font color=#000000>$scout[pfr]</td><td><font color=#000000>$evalu</td><td><b><font color=#000000>$scout[pts]</b></td>");
             $output->Text("</tr>");
       }
    }
    $output->Text("</table>\n");
    $output->Text("</td></tr>");

    $output->Text("</td></tr></table>\n");

    $output->TableEnd();

    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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

//////
/// display Standings
//////
function standings_user_displaystand($args)
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    // 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 $tid
    //
    // 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;
    }

    // get the configured colors for the tables
    $back1 = pnModGetVar('Standings', 'standbkgnd1col');
    $back2 = pnModGetVar('Standings', 'standbkgnd2col');
    $hedr = pnModGetVar('Standings', 'standheadercol');
    $sepr = pnModGetVar('Standings', 'standseprcol');
    $tots = pnModGetVar('Standings', 'standtotalscol');
    $cols = pnModGetVar('Standings', 'standcolscol');

    // 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_usermenu());
    $output->SetInputMode(_PNH_PARSEINPUT);

    // Load API.  All of the actual work for obtaining information on the items
    // 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', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }

    // The API function is called.  The arguments to the function are passed in
    // as their own arguments array
    $item = pnModAPIFunc('Standings',
                          'user',
                          'getteams',
                          array('cid' => $cid));

    // 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 ($item == false) {
        $output->Text(_STANDINGSITEMFAILED);
        return $output->GetOutput();
    }

    // Show Team table
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->LineBreak(2);

    $output->Text("<table border=0 width=100%><tr><td>\n");
    $output->Text("<table border=0 width=99% cellpadding=2 cellspacing=1 bgcolor=".$sepr.">\n");

    $output->Text("<tr bgcolor=".$hedr."><td align=center rowspan=3>");
    $output->BoldText(_STANDINGSTEAMNAME);
    $output->Text("</td><td align=center rowspan=3>");
    $output->BoldText(_STANDINGSTABPTS);
    $output->Text("</td><td align=center colspan=6>");
    $output->BoldText(_STANDINGSTABTOTALS);
    $output->Text("</td><td align=center colspan=6>");
    $output->BoldText(_STANDINGSTABHOME);
    $output->Text("</td><td align=center colspan=6>");
    $output->BoldText(_STANDINGSTABAWAY);
    $output->Text("</td></tr>");

    $output->Text("<tr bgcolor=".$tots."><td align=center colspan=4>");
    $output->BoldText(_STANDINGSTABGAMES);
    $output->Text("</td><td align=center colspan=2>");
    $output->BoldText(_STANDINGSTABPOINTS);
    $output->Text("<td align=center colspan=4>");
    $output->BoldText(_STANDINGSTABGAMES);
    $output->Text("</td><td align=center colspan=2>");
    $output->BoldText(_STANDINGSTABPOINTS);
    $output->Text("<td align=center colspan=4>");
    $output->BoldText(_STANDINGSTABGAMES);
    $output->Text("</td><td align=center colspan=2>");
    $output->BoldText(_STANDINGSTABPOINTS);

    $output->Text("</td></tr>");


    $output->Text("<tr bgcolor=".$cols."><td align=center>");
    $output->BoldText(_STANDINGSTABTOTG);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABTOTW);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABTOTL);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABTOTD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABTOTPD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABTOTPR);

    $output->Text("<td align=center>");
    $output->BoldText(_STANDINGSTABHG);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABHW);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABHL);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABHD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABHPD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABHPR);

    $output->Text("<td align=center>");
    $output->BoldText(_STANDINGSTABAG);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABAW);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABAL);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABAD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABAPD);
    $output->Text("</td><td align=center>");
    $output->BoldText(_STANDINGSTABAPR);
    $output->Text("</td></tr>");


    // Display details of the item.  Note the use of pnVarCensor() to remove
    // any words from the name that the administrator has deemed unsuitable for
    // the site.  Also note that a module variable is used here to determine
    // whether not not parts of the item information should be displayed in
    // bold type or not
    foreach ($item as $team)
    {
        $i++;
        $rowcol = (Floor($i/2)*2 == $i) ? $back1 : $back2;

        $output->Text("<tr bgcolor=".$rowcol."><td align=center>");
        $output->URL(pnModURL('Standings',
                              'user',
                              'displayteam',
                              array('tid' => $team[tid])),$team[team]);
        $output->Text("</td><td align=center>");
        $output->BoldText($team[pts]);
        $output->Text("</td><td align=center>");
        $output->Text($team[totg]);
        $output->Text("</td><td align=center>");
        $output->Text($team[totw]);
        $output->Text("</td><td align=center>");
        $output->Text($team[totl]);
        $output->Text("</td><td align=center>");
        $output->Text($team[totd]);
        $output->Text("</td><td align=center>");
        $output->Text($team[totpd]);
        $output->Text("</td><td align=center>");
        $output->Text($team[totpr]);
        $output->Text("</td><td align=center>");
        $output->Text($team[hg]);
        $output->Text("</td><td align=center>");
        $output->Text($team[hw]);
        $output->Text("</td><td align=center>");
        $output->Text($team[hl]);
        $output->Text("</td><td align=center>");
        $output->Text($team[hd]);
        $output->Text("</td><td align=center>");
        $output->Text($team[hpd]);
        $output->Text("</td><td align=center>");
        $output->Text($team[hpr]);
        $output->Text("</td><td align=center>");
        $output->Text($team[ag]);
        $output->Text("</td><td align=center>");
        $output->Text($team[aw]);
        $output->Text("</td><td align=center>");
        $output->Text($team[al]);
        $output->Text("</td><td align=center>");
        $output->Text($team[ad]);
        $output->Text("</td><td align=center>");
        $output->Text($team[apd]);
        $output->Text("</td><td align=center>");
        $output->Text($team[apr]);
        $output->Text("</td></tr>");
    }

    $output->Text("</table></td></tr>\n");
    $output->Text("</table>\n");


    // Add the footer message
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(standings_footer());
    $output->SetInputMode(_PNH_PARSEINPUT);

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


//////
/// generate the footer messages
//////
function standings_footer()
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    $dir = $modinfo['directory'];
    @include("modules/$dir/pnversion.php");

    $version = $modversion['version'];
    $name = $modversion['name'];
    $desc = $modversion['description'];

    $output = new pnHTML();


    $output->LineBreak(3);
    $output->TableStart();

    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text("<tr><td align=center>");
    $output->Text("<a href='http://sourceforge.net/projects/standings'>".$name . " " . $version."</a>");
    $output->LineBreak(1);
    $output->Text("[" . $desc . "]");
    $output->Text("</td></tr>");
    
    $output->TableEnd();

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

//////
/// generate menu fragment
//////
function standings_usermenu()
{

    // lets get the module's information
    $modid      = pnModGetIDFromName('Standings');
    $modinfo    = pnModGetInfo($modid);

    $img = "<img src='modules/".$modinfo['directory']. "/pnimages/standings.gif' border=0>";

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

    $cid = pnVarCleanFromInput('cid');

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

    // get the first available tournament in the db
    if (!isset($cid)) {
              $cid = pnModAPIFunc('Standings','user','getfirst');
              // if no tournaments in db
              if ($cid == false) {
                  return $output->GetOutput();
              }

    }


    // 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

    // Start options menu
    $output->Text(pnGetStatusMsg());


    // Menu options.  These options are all added in a single row, to add
    // multiple rows of options the code below would just be repeated
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->TableStart($img);

    $output->FormStart(pnModUrl('Standings','user','main'));

    $output->Text("<tr><td align='center' colspan='4'>"._STANDINGSSELTOURN);


    $tourns = pnModAPIFunc('Standings','user','getall');

    // 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 ($tourns == false) {
        $output->Text(_STANDINGSITEMFAILED);
        return $output->GetOutput();
    }

    // Prepare the multi-select Tournament menu
    $tourninfo = array();

    foreach ($tourns as $tourn)
    {
         if ($tourn['cid'] == $cid) {
         $tourninfo[] = array('id'       => $tourn['cid'],
                              'name'     => $tourn['title'],
                              'selected' => 1);
         } else {
         $tourninfo[] = array('id'       => $tourn['cid'],
                              'name'     => $tourn['title']);
         }
    }

    $output->FormSelectMultiple('cid', $tourninfo);
    $output->Text("&nbsp;&nbsp;&nbsp;&nbsp;");
    $output->FormSubmit(_STANDINGSSELTOURNAMENT);

    $output->Text("</td></tr>");
    $output->FormEnd();


    
    // Display menu options
    $output->Linebreak(2);
    $output->SetOutputMode(_PNH_RETURNOUTPUT);
    $columns = array();
    $columns[] = $output->URL(pnModURL('Standings',
                                       'user',
                                       'displayteams',
                                       array('cid' => $cid)),
                              _STANDINGSVIEWTEAMS);
    $columns[] = $output->URL(pnModURL('Standings',
                                       'user',
                                       'displayplayers',
                                       array('cid' => $cid)),
                              _STANDINGSVIEWPLAYERS);
    $columns[] = $output->URL(pnModURL('Standings',
                                       'user',
                                       'displaysched',
                                       array('cid' => $cid)),
                              _STANDINGSVIEWSCHED);
    $columns[] = $output->URL(pnModURL('Standings',
                                       'user',
                                       'displaystand',
                                       array('cid' => $cid)),
                              _STANDINGSVIEWRANK);

    $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