Location: PHPKode > projects > Standings module for sports > pnuserapi.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 API
// ----------------------------------------------------------------------------

//////
/// get all Tournaments
//////
function standings_userapi_getall($args)
{
    //
    extract($args);

    // Optional arguments.
    if (!isset($startnum)) {
        $startnum = 1;
    }
    if (!isset($numitems)) {
        $numitems = -1;
    }

    if ((!isset($startnum)) ||
        (!isset($numitems))) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    $items = array();

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

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourntable = $pntable['stand_tourn'];
    $standtourncolumn = &$pntable['stand_tourn_column'];

    // Get items - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the SelectLimit() command allows for simpler debug
    // operation if it is ever needed
    $sql = "SELECT $standtourncolumn[cid],
                   $standtourncolumn[title],
                   $standtourncolumn[description],
                   $standtourncolumn[ppv],
                   $standtourncolumn[ppd],
                   $standtourncolumn[ppl]
            FROM $standtourntable
            ORDER BY $standtourncolumn[title]";
    $result = $dbconn->SelectLimit($sql, $numitems, $startnum-1);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        pnSessionSetVar('errormsg', _GETFAILED);
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($cid, $title, $description, $ppv, $ppd, $ppl) = $result->fields;
        if (pnSecAuthAction(0, 'Standings::Tournament', "$title::$cid", ACCESS_READ)) {
            $items[] = array('cid' => $cid,
                             'title' => $title,
                             'description' => $description,
                             'ppv' => $ppv,
                             'ppd' => $ppd,
                             'ppl' => $ppl);
        }
    }

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the items
    return $items;
}

//////
/// get a specific Tournament
//////
function standings_userapi_get($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($cid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourntable = $pntable['stand_tourn'];
    $standtourncolumn = &$pntable['stand_tourn_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standtourncolumn[title],
                   $standtourncolumn[description],
                   $standtourncolumn[ppv],
                   $standtourncolumn[ppd],
                   $standtourncolumn[ppl]
            FROM $standtourntable
            WHERE $standtourncolumn[cid] = " . pnVarPrepForStore($cid);
    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Obtain the item information from the result set
    list($title, $description, $ppv, $ppd, $ppl) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Security check - important to do this as early on as possible to avoid
    // potential security holes or just too much wasted processing.  Although
    // this one is a bit late in the function it is as early as we can do it as
    // this is the first time we have the relevant information
    if (!pnSecAuthAction(0, 'Standings::Tournament', "$title::$cid", ACCESS_READ)) {
        return false;
    }

    // Create the item array
    $item = array('cid' => $cid,
                  'title' => $title,
                  'description' => $description,
                  'ppv' => $ppv,
                  'ppd' => $ppd,
                  'ppl' => $ppl);

    // Return the item array
    return $item;
}

//////
/// get all Teams for a given $cid Tournament
//////
function standings_userapi_getteams($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($cid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standteamtable = $pntable['stand_team'];
    $standteamcolumn = &$pntable['stand_team_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standteamcolumn[tid],
                   $standteamcolumn[team],
                   $standteamcolumn[city],
                   $standteamcolumn[contact],
                   $standteamcolumn[phone],
                   $standteamcolumn[paddress],
                   $standteamcolumn[email],
                   $standteamcolumn[homepage],
                   $standteamcolumn[pts],
                   $standteamcolumn[totg],
                   $standteamcolumn[totw],
                   $standteamcolumn[totl],
                   $standteamcolumn[totd],
                   $standteamcolumn[totpd],
                   $standteamcolumn[totpr],
                   $standteamcolumn[hg],
                   $standteamcolumn[hw],
                   $standteamcolumn[hl],
                   $standteamcolumn[hd],
                   $standteamcolumn[hpd],
                   $standteamcolumn[hpr],
                   $standteamcolumn[ag],
                   $standteamcolumn[aw],
                   $standteamcolumn[al],
                   $standteamcolumn[ad],
                   $standteamcolumn[apd],
                   $standteamcolumn[apr]
            FROM $standteamtable
            WHERE $standteamcolumn[cid] = " . pnVarPrepForStore($cid) . 
            " ORDER BY $standteamcolumn[pts] DESC";

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($tid, $team, $city, $contact, $phone, $paddress, $email, $homepage, $pts, $totg, $totw, $totl, $totd,
         $totpd, $totpr, $hg, $hw, $hl, $hd, $hpd, $hpr, $ag, $aw, $al, $ad, $apd, $apr) = $result->fields;
        if (pnSecAuthAction(0, 'Standings::Team', "$team::$tid", ACCESS_READ)) {
               $item[] = array(    'tid' => $tid,
                                  'team' => $team,
                                  'city' => $city,
                               'contact' => $contact,
                                 'phone' => $phone,
                              'paddress' => $paddress,
                                 'email' => $email,
                              'homepage' => $homepage,
                                   'pts' => $pts,
                                  'totg' => $totg,
                                  'totw' => $totw,
                                  'totl' => $totl,
                                  'totd' => $totd,
                                 'totpd' => $totpd,
                                 'totpr' => $totpr,
                                    'hg' => $hg,
                                    'hw' => $hw,
                                    'hl' => $hl,
                                    'hd' => $hd,
                                   'hpd' => $hpd,
                                   'hpr' => $hpr,
                                    'ag' => $ag,
                                    'aw' => $aw,
                                    'al' => $al,
                                    'ad' => $ad,
                                   'apd' => $apd,
                                   'apr' => $apr
                              );

        }
    }

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get all Players for a given $cid Tournament
//////
function standings_userapi_getplayerst($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($cid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standplayerstable = $pntable['stand_players'];
    $standplayerscolumn = &$pntable['stand_players_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standplayerscolumn[pid],
                   $standplayerscolumn[tid],
                   $standplayerscolumn[name],
                   $standplayerscolumn[fname],
                   $standplayerscolumn[number],
                   $standplayerscolumn[role],
                   $standplayerscolumn[birth],
                   $standplayerscolumn[height],
                   $standplayerscolumn[weight],
                   $standplayerscolumn[notes],
                   $standplayerscolumn[from]
            FROM $standplayerstable 
            WHERE $standplayerscolumn[cid] = " . pnVarPrepForStore($cid) .
            " ORDER BY $standplayerscolumn[fname] ASC";

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($pid, $tid, $name, $fname, $number, $role, $birth, $height, $weigth, $notes, $from)= $result->fields;
        if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
               $item[] = array(    'pid' => $pid,
                                   'tid' => $tid,
                                  'name' => $name,
                                 'fname' => $fname,
                                'number' => $number,
                                  'role' => $role,
                                 'birth' => $birth,
                                'heigth' => $heigth,
                                'weigth' => $weigth,
                                 'notes' => $notes,
                                  'from' => $from
                              );

        }
    }

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get all Players for a given $tid Team
//////
function standings_userapi_getplayers($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($tid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standplayerstable = $pntable['stand_players'];
    $standplayerscolumn = &$pntable['stand_players_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standplayerscolumn[pid],
                   $standplayerscolumn[number],
                   $standplayerscolumn[name],
                   $standplayerscolumn[fname],
                   $standplayerscolumn[role],
                   $standplayerscolumn[birth],
                   $standplayerscolumn[height],
                   $standplayerscolumn[weight],
                   $standplayerscolumn[notes],
                   $standplayerscolumn[from]
            FROM $standplayerstable
            WHERE $standplayerscolumn[tid] = " . pnVarPrepForStore($tid) . 
            " ORDER BY $standplayerscolumn[fname] DESC";

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($pid, $number, $name, $fname, $role, $birth, $height, $weight, $notes, $from) = $result->fields;
        if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
               $item[] = array(    'pid' => $pid,
                                'number' => $number,
                                  'name' => $name,
                                 'fname' => $fname,
                                  'role' => $role,
                                 'birth' => $birth,
                                'height' => $height,
                                'weight' => $weight,
                                'notes'  => $notes,
                                  'from' => $from
                              );

        }
    }

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get all calendar schedules for a given $cid Tournament
//////
function standings_userapi_getcals($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($cid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourncaltable = $pntable['stand_tourncal'];
    $standtourncalcolumn = &$pntable['stand_tourncal_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standtourncalcolumn[tcid],
                   $standtourncalcolumn[rid],
                   $standtourncalcolumn[date],
                   $standtourncalcolumn[time],
                   $standtourncalcolumn[teama],
                   $standtourncalcolumn[teamb],
                   $standtourncalcolumn[scorea],
                   $standtourncalcolumn[scoreb],
                   $standtourncalcolumn[q1a],
                   $standtourncalcolumn[q1b],
                   $standtourncalcolumn[q2a],
                   $standtourncalcolumn[q2b],
                   $standtourncalcolumn[q3a],
                   $standtourncalcolumn[q3b],
                   $standtourncalcolumn[q4a],
                   $standtourncalcolumn[q4b],
                   $standtourncalcolumn[ot1a],
                   $standtourncalcolumn[ot1b],
                   $standtourncalcolumn[ot2a],
                   $standtourncalcolumn[ot2b],
                   $standtourncalcolumn[ot3a],
                   $standtourncalcolumn[ot3b],
                   $standtourncalcolumn[offic1],
                   $standtourncalcolumn[offic2],
                   $standtourncalcolumn[offic3]
            FROM $standtourncaltable
            WHERE $standtourncalcolumn[cid] = " . pnVarPrepForStore($cid) . 
            " ORDER BY $standtourncalcolumn[rid]";

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($tcid, $rid, $date, $time, $teama, $teamb, $scorea, $scoreb,
             $q1a, $q1b, $q2a, $q2b, $q3a, $q3b, $q4a, $q4b, $ot1a, $ot1b, $ot2a, $ot2b,
             $ot3a, $ot3b, $offic1, $offic2, $offic3) = $result->fields;

        if (pnSecAuthAction(0, 'Standings::Tournament', "::$cid", ACCESS_READ)) {
               $item[] = array(   'tcid' => $tcid,
                                   'rid' => $rid,
                                  'date' => $date,
                                  'time' => $time,
                                 'teama' => $teama,
                                 'teamb' => $teamb,
                                 'scorea' => $scorea,
                                 'scoreb' => $scoreb,
                                 'q1a' => $q1a,
                                 'q1b' => $q1b,
                                 'q2a' => $q2a,
                                 'q2b' => $q2b,
                                 'q3a' => $q3a,
                                 'q3b' => $q3b,
                                 'q4a' => $q4a,
                                 'q4b' => $q4b,
                                 'ot1a' => $ot1a,
                                 'ot1b' => $ot1b,
                                 'ot2a' => $ot2a,
                                 'ot2b' => $ot2b,
                                 'ot3a' => $ot3a,
                                 'ot3b' => $ot3b,
                                 'offic1' => $offic1,
                                 'offic2' => $offic2,
                                 'offic3' => $offic3
                              );

        }
    }

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get all calendar schedules for a given $tid Team
//////
function standings_userapi_getteamcal($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($tid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourncaltable = $pntable['stand_tourncal'];
    $standtourncalcolumn = &$pntable['stand_tourncal_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standtourncalcolumn[tcid],
                   $standtourncalcolumn[rid],
                   $standtourncalcolumn[date],
                   $standtourncalcolumn[time],
                   $standtourncalcolumn[teama],
                   $standtourncalcolumn[teamb],
                   $standtourncalcolumn[scorea],
                   $standtourncalcolumn[scoreb]
            FROM $standtourncaltable
            WHERE $standtourncalcolumn[teama] = " . pnVarPrepForStore($tid) . 
            " OR $standtourncalcolumn[teamb] = " . pnVarPrepForStore($tid) .
            " ORDER BY $standtourncalcolumn[rid]";

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($tcid, $rid, $date, $time, $teama, $teamb, $scorea, $scoreb) = $result->fields;
        $opp = ($teama == $tid) ? $teamb : $teama;
        $home = ($teama == $tid) ? 1 : 0;

        if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
               $item[] = array(   'tcid' => $tcid,
                                   'rid' => $rid,
                                  'date' => $date,
                                  'time' => $time,
                                   'opp' => $opp,
                                  'home' => $home,
                                 'scorea' => $scorea,
                                 'scoreb' => $scoreb
                              );

        }
    }

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get a specific Tournament schedule
//////
function standings_userapi_getcal($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($tcid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourncaltable = $pntable['stand_tourncal'];
    $standtourncalcolumn = &$pntable['stand_tourncal_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standtourncalcolumn[rid],
                   $standtourncalcolumn[date],
                   $standtourncalcolumn[time],
                   $standtourncalcolumn[teama],
                   $standtourncalcolumn[teamb],
                   $standtourncalcolumn[scorea],
                   $standtourncalcolumn[scoreb],
                   $standtourncalcolumn[q1a],
                   $standtourncalcolumn[q1b],
                   $standtourncalcolumn[q2a],
                   $standtourncalcolumn[q2b],
                   $standtourncalcolumn[q3a],
                   $standtourncalcolumn[q3b],
                   $standtourncalcolumn[q4a],
                   $standtourncalcolumn[q4b],
                   $standtourncalcolumn[ot1a],
                   $standtourncalcolumn[ot1b],
                   $standtourncalcolumn[ot2a],
                   $standtourncalcolumn[ot2b],
                   $standtourncalcolumn[ot3a],
                   $standtourncalcolumn[ot3b],
                   $standtourncalcolumn[offic1],
                   $standtourncalcolumn[offic2],
                   $standtourncalcolumn[offic3]
            FROM $standtourncaltable
            WHERE $standtourncalcolumn[tcid] = " . pnVarPrepForStore($tcid);
    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Obtain the item information from the result set
    list($rid, $date, $time, $teama, $teamb, $scorea, $scoreb,
             $q1a, $q1b, $q2a, $q2b, $q3a, $q3b, $q4a, $q4b, $ot1a, $ot1b, $ot2a, $ot2b,
             $ot3a, $ot3b, $offic1, $offic2, $offic3) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Security check - important to do this as early on as possible to avoid
    // potential security holes or just too much wasted processing.  Although
    // this one is a bit late in the function it is as early as we can do it as
    // this is the first time we have the relevant information
    if (!pnSecAuthAction(0, 'Standings::Tournament', "::", ACCESS_READ)) {
        return false;
    }

    // Create the item array
    $item = array('rid'    => $rid,
                  'date'   => $date,
                  'time'   => $time,
                  'teama'  => $teama,
                  'teamb'  => $teamb,
                  'scorea' => $scorea,
                  'scoreb' => $scoreb,
                     'q1a' => $q1a,
                     'q1b' => $q1b,
                     'q2a' => $q2a,
                     'q2b' => $q2b,
                     'q3a' => $q3a,
                     'q3b' => $q3b,
                     'q4a' => $q4a,
                     'q4b' => $q4b,
                    'ot1a' => $ot1a,
                    'ot1b' => $ot1b,
                    'ot2a' => $ot2a,
                    'ot2b' => $ot2b,
                    'ot3a' => $ot3a,
                    'ot3b' => $ot3b,
                  'offic1' => $offic1,
                  'offic2' => $offic2,
                  'offic3' => $offic3
                   );

    // Return the item array
    return $item;
}

//////
/// get all Scouts for a given Team ID 
/// and Tournament Calendar ID
//////
function standings_userapi_getscouts($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (((!isset($tid)) || (!isset($tcid)))) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standscoutstable = $pntable['stand_scouts'];
    $standscoutscolumn = &$pntable['stand_scouts_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standscoutscolumn[sid],
                   $standscoutscolumn[pid],
                   $standscoutscolumn[date],
                   $standscoutscolumn[rid],
                   $standscoutscolumn[start],
                   $standscoutscolumn[mins],
                   $standscoutscolumn[fgm],
                   $standscoutscolumn[fga],
                   $standscoutscolumn[tpm],
                   $standscoutscolumn[tpa],
                   $standscoutscolumn[ftm],
                   $standscoutscolumn[fta],
                   $standscoutscolumn[or],
                   $standscoutscolumn[dr],
                   $standscoutscolumn[ass],
                   $standscoutscolumn[ste],
                   $standscoutscolumn[blk],
                   $standscoutscolumn[blkr],
                   $standscoutscolumn[to],
                   $standscoutscolumn[pf],
                   $standscoutscolumn[pfr],
                   $standscoutscolumn[pts]
            FROM $standscoutstable
            WHERE $standscoutscolumn[tid] = " . pnVarPrepForStore($tid) . 
            " AND $standscoutscolumn[tcid] = " . pnVarPrepForStore($tcid) . 
            " ORDER BY $standscoutscolumn[sid]";


    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($sid, $pid, $date, $rid, $start, $mins, $fgm, $fga, $tpm, $tpa, $ftm, $fta,
             $or, $dr, $ass, $ste, $blk, $blkr, $to, $pf, $pfr, $pts) = $result->fields;

        if (pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
               $item[] = array(    'sid' => $sid,
                                   'pid' => $pid,
                                  'date' => $date,
                                   'rid' => $rid,
                                 'start' => $start,
                                  'mins' => $mins,
                                   'fgm' => $fgm,
                                   'fga' => $fga,
                                   'tpm' => $tpm,
                                   'tpa' => $tpa,
                                   'ftm' => $ftm,
                                   'fta' => $fta,
                                    'or' => $or,
                                    'dr' => $dr,
                                   'ass' => $ass,
                                   'ste' => $ste,
                                   'blk' => $blk,
                                  'blkr' => $blkr,
                                    'to' => $to,
                                    'pf' => $pf,
                                   'pfr' => $pfr,
                                   'pts' => $pts);

        }
    }
    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get all Scouts for a given Player ID 
//////
function standings_userapi_getplayerscouts($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if ((!isset($pid))) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standscoutstable = $pntable['stand_scouts'];
    $standscoutscolumn = &$pntable['stand_scouts_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standscoutscolumn[sid],
                   $standscoutscolumn[pid],
                   $standscoutscolumn[tcid],
                   $standscoutscolumn[date],
                   $standscoutscolumn[rid],
                   $standscoutscolumn[start],
                   $standscoutscolumn[mins],
                   $standscoutscolumn[fgm],
                   $standscoutscolumn[fga],
                   $standscoutscolumn[tpm],
                   $standscoutscolumn[tpa],
                   $standscoutscolumn[ftm],
                   $standscoutscolumn[fta],
                   $standscoutscolumn[or],
                   $standscoutscolumn[dr],
                   $standscoutscolumn[ass],
                   $standscoutscolumn[ste],
                   $standscoutscolumn[blk],
                   $standscoutscolumn[blkr],
                   $standscoutscolumn[to],
                   $standscoutscolumn[pf],
                   $standscoutscolumn[pfr],
                   $standscoutscolumn[pts]
            FROM $standscoutstable
            WHERE $standscoutscolumn[pid] = " . pnVarPrepForStore($pid) . 
            " ORDER BY $standscoutscolumn[rid]";


    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    for (; !$result->EOF; $result->MoveNext()) {
        list($sid, $pid, $tcid, $date, $rid, $start, $mins, $fgm, $fga, $tpm, $tpa, $ftm, $fta,
             $or, $dr, $ass, $ste, $blk, $blkr, $to, $pf, $pfr, $pts) = $result->fields;

        if (pnSecAuthAction(0, 'Standings::Team', "::", ACCESS_READ)) {
               $item[] = array(    'sid' => $sid,
                                   'pid' => $pid,
                                  'tcid' => $tcid,
                                  'date' => $date,
                                   'rid' => $rid,
                                 'start' => $start,
                                  'mins' => $mins,
                                   'fgm' => $fgm,
                                   'fga' => $fga,
                                   'tpm' => $tpm,
                                   'tpa' => $tpa,
                                   'ftm' => $ftm,
                                   'fta' => $fta,
                                    'or' => $or,
                                    'dr' => $dr,
                                   'ass' => $ass,
                                   'ste' => $ste,
                                   'blk' => $blk,
                                  'blkr' => $blkr,
                                    'to' => $to,
                                    'pf' => $pf,
                                   'pfr' => $pfr,
                                   'pts' => $pts);

        }
    }
    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the item array
    return $item;
}

//////
/// get a specific Team
//////
function standings_userapi_getteam($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($tid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standteamtable = $pntable['stand_team'];
    $standteamcolumn = &$pntable['stand_team_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standteamcolumn[cid],
                   $standteamcolumn[team],
                   $standteamcolumn[city],
                   $standteamcolumn[shorts],
                   $standteamcolumn[tshirt],
                   $standteamcolumn[contact],
                   $standteamcolumn[phone],
                   $standteamcolumn[paddress],
                   $standteamcolumn[email],
                   $standteamcolumn[homepage],
                   $standteamcolumn[pts],
                   $standteamcolumn[totg],
                   $standteamcolumn[totw],
                   $standteamcolumn[totl],
                   $standteamcolumn[totd],
                   $standteamcolumn[totpd],
                   $standteamcolumn[totpr],
                   $standteamcolumn[hg],
                   $standteamcolumn[hw],
                   $standteamcolumn[hl],
                   $standteamcolumn[hd],
                   $standteamcolumn[hpd],
                   $standteamcolumn[hpr],
                   $standteamcolumn[ag],
                   $standteamcolumn[aw],
                   $standteamcolumn[al],
                   $standteamcolumn[ad],
                   $standteamcolumn[apd],
                   $standteamcolumn[apr]
            FROM $standteamtable
            WHERE $standteamcolumn[tid] = " . pnVarPrepForStore($tid);
    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Obtain the item information from the result set
    list($cid, $team, $city, $shorts, $tshirt, $contact, $phone, $paddress, $email, $homepage, $pts, $totg, $totw, $totl, $totd,
         $totpd, $totpr, $hg, $hw, $hl, $hd, $hpd, $hpr, $ag, $aw, $al, $ad, $apd, $apr) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Security check - important to do this as early on as possible to avoid
    // potential security holes or just too much wasted processing.  Although
    // this one is a bit late in the function it is as early as we can do it as
    // this is the first time we have the relevant information
    if (!pnSecAuthAction(0, 'Standings::Team', "$team::$tid", ACCESS_READ)) {
        return false;
    }

    // Create the item array
    $item = array('tid' => $tid,
                  'cid' => $cid,
                  'team' => $team,
                  'city' => $city,
                  'shorts' => $shorts,
                  'tshirt' => $tshirt,
                  'contact' => $contact,
                  'phone' => $phone,
                  'paddress' => $paddress,
                  'email' => $email,
                  'homepage' => $homepage,
                  'pts' => $pts,
                  'totg' => $totg,
                  'totw' => $totw,
                  'totl' => $totl,
                  'totd' => $totd,
                  'totpd' => $totpd,
                  'totpr' => $totpr,
                  'hg' => $hg,
                  'hw' => $hw,
                  'hl' => $hl,
                  'hd' => $hd,
                  'hpd' => $hpd,
                  'hpr' => $hpr,
                  'ag' => $ag,
                  'aw' => $aw,
                  'al' => $al,
                  'ad' => $ad,
                  'apd' => $apd,
                  'apr' => $apr
                  );

    // Return the item array
    return $item;
}

//////
/// get a specific Player
//////
function standings_userapi_getplayer($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($pid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standplayerstable = $pntable['stand_players'];
    $standplayerscolumn = &$pntable['stand_players_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standplayerscolumn[tid],
                   $standplayerscolumn[name],
                   $standplayerscolumn[fname],
                   $standplayerscolumn[number],
                   $standplayerscolumn[role],
                   $standplayerscolumn[birth],
                   $standplayerscolumn[height],
                   $standplayerscolumn[weight],
                   $standplayerscolumn[notes],
                   $standplayerscolumn[from]
            FROM $standplayerstable
            WHERE $standplayerscolumn[pid] = " . pnVarPrepForStore($pid);
    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Obtain the item information from the result set
    list($tid, $name, $fname, $number, $role, $birth, $height, $weight, $notes, $from) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Security check - important to do this as early on as possible to avoid
    // potential security holes or just too much wasted processing.  Although
    // this one is a bit late in the function it is as early as we can do it as
    // this is the first time we have the relevant information
    if (!pnSecAuthAction(0, 'Standings::Team', "::$tid", ACCESS_READ)) {
        return false;
    }

    // Create the item array
    $item = array('tid' => $tid,
                  'name' => $name,
                  'fname' => $fname,
                  'number' => $number,
                  'role' => $role,
                  'birth' => $birth,
                  'height' => $height,
                  'weight' => $weight,
                  'notes' => $notes,
                  'from' => $from
                  );

    // Return the item array
    return $item;
}

//////
/// get Scout for a given scout ID 
//////
function standings_userapi_getscout($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($sid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standscoutstable = $pntable['stand_scouts'];
    $standscoutscolumn = &$pntable['stand_scouts_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standscoutscolumn[sid],
                   $standscoutscolumn[pid],
                   $standscoutscolumn[date],
                   $standscoutscolumn[rid],
                   $standscoutscolumn[start],
                   $standscoutscolumn[mins],
                   $standscoutscolumn[fgm],
                   $standscoutscolumn[fga],
                   $standscoutscolumn[tpm],
                   $standscoutscolumn[tpa],
                   $standscoutscolumn[ftm],
                   $standscoutscolumn[fta],
                   $standscoutscolumn[or],
                   $standscoutscolumn[dr],
                   $standscoutscolumn[ass],
                   $standscoutscolumn[ste],
                   $standscoutscolumn[blk],
                   $standscoutscolumn[blkr],
                   $standscoutscolumn[to],
                   $standscoutscolumn[pf],
                   $standscoutscolumn[pfr],
                   $standscoutscolumn[pts]
            FROM $standscoutstable
            WHERE $standscoutscolumn[sid] = " . pnVarPrepForStore($sid);

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Check for no rows found, and if so return
    if ($result->EOF) {
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    list($sid, $pid, $date, $rid, $start, $mins, $fgm, $fga, $tpm, $tpa, $ftm, $fta,
             $or, $dr, $ass, $ste, $blk, $blkr, $to, $pf, $pfr, $pts) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    if (!pnSecAuthAction(0, 'Standings::Team', "::", ACCESS_READ)) {
        return false;
    }

               $item = array(    'sid' => $sid,
                                   'pid' => $pid,
                                  'date' => $date,
                                   'rid' => $rid,
                                 'start' => $start,
                                  'mins' => $mins,
                                   'fgm' => $fgm,
                                   'fga' => $fga,
                                   'tpm' => $tpm,
                                   'tpa' => $tpa,
                                   'ftm' => $ftm,
                                   'fta' => $fta,
                                    'or' => $or,
                                    'dr' => $dr,
                                   'ass' => $ass,
                                   'ste' => $ste,
                                   'blk' => $blk,
                                  'blkr' => $blkr,
                                    'to' => $to,
                                    'pf' => $pf,
                                   'pfr' => $pfr,
                                   'pts' => $pts);


    // Return the item array
    return $item;
}

//////
/// utility function to count the current number of game rounds
/// in a given cid tournament
//////
function standings_userapi_getroundcount($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, 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
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($cid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }
    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourncaltable = $pntable['stand_tourncal'];
    $standtourncalcolumn = &$pntable['stand_tourncal_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT $standtourncalcolumn[rid]
            FROM $standtourncaltable
            WHERE $standtourncalcolumn[cid]=" . pnVarPrepForStore($cid) ."
            ORDER BY $standtourncalcolumn[rid] DESC LIMIT 1";
    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Obtain the number of items
    list($roundcount) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the number of items
    return $roundcount;
}


//////
/// utility function to count the number of items held by this module
//////
function standings_userapi_countitems()
{
    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standingstable = $pntable['Standings'];
    $standingscolumn = &$pntable['Standings_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT COUNT(1)
            FROM $standingstable";
    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Obtain the number of items
    list($numitems) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the number of items
    return $numitems;
}

//////
/// utility function to count the number of teams in a given Tournament
//////
function standings_userapi_teamcount($args)
{
    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    extract($args);

    // Argument check - make sure that all required arguments are present, if
    // not then set an appropriate error message and return
    if (!isset($cid)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }

    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standteamstable = $pntable['stand_team'];
    $standteamcolumn = &$pntable['stand_team_column'];

    // Get item - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the Execute() command allows for simpler debug operation
    // if it is ever needed
    $sql = "SELECT COUNT(1)
            FROM $standteamstable
            WHERE $standteamcolumn[cid] = " . pnVarPrepForStore($cid);

    $result = $dbconn->Execute($sql);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        return false;
    }

    // Obtain the number of items
    list($numitems) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the number of items
    return $numitems;
}

//////
/// get first Tournament
//////
function standings_userapi_getfirst()
{


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

    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn() we
    // currently just want the first item, which is the official database
    // handle.  For pnDBGetTables() we want to keep the entire tables array
    // together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    // It's good practice to name the table and column definitions you are
    // getting - $table and $column don't cut it in more complex modules
    $standtourntable = $pntable['stand_tourn'];
    $standtourncolumn = &$pntable['stand_tourn_column'];

    // Get items - the formatting here is not mandatory, but it does make the
    // SQL statement relatively easy to read.  Also, separating out the sql
    // statement from the SelectLimit() command allows for simpler debug
    // operation if it is ever needed
    $sql = "SELECT $standtourncolumn[cid]
            FROM $standtourntable
            ORDER BY $standtourncolumn[cid]";

    $result = $dbconn->SelectLimit($sql, 1, 0);

    // Check for an error with the database code, and if so set an appropriate
    // error message and return
    if ($dbconn->ErrorNo() != 0) {
        pnSessionSetVar('errormsg', _GETFAILED);
        return false;
    }

    // Put items into result array.  Note that each item is checked
    // individually to ensure that the user is allowed access to it before it
    // is added to the results array
    list($cid) = $result->fields;

    // All successful database queries produce a result set, and that result
    // set should be closed when it has been finished with
    $result->Close();

    // Return the items
    return $cid;
}

?>
Return current item: Standings module for sports