<?php
// Configuration file name, including full path
$configfile = "";
// shared.php: configuration info and standard functions
//
// This file is part of the SportsPHool application
// Copyright (C) 2000, 2001 Barry Scott Will <hide@address.com>
// See /license and /gpl.txt for licensing information
//
// This file is required at the beginning of each script in Sports PHool
// If you decide to move this file, you'll need to change the 'require'
// statement at the beginning of each script *or* auto_prepend this file
// (in which case you'll need to comment out those 'require' statements)
// If file doesn't exist, we can't use this installation yet
if(!file_exists($configfile)) die("<p><strong>You must first create the config.php file to use Sports PHool!</strong><br/>See the installation instructions for more information.</p>");
// Turn off register_globals to enable direct writing to $HTTP_SESSION_VARS
$x=ini_alter("register_globals", "0");
// Start up the session, and check to see if userID is already registered
// If not, set it to zero, and register all other session variables
$oldname = session_name("SPSESSID");
session_start();
if(!session_is_registered("userID")) {
session_register("userID");
$HTTP_SESSION_VARS["userID"]=0;
session_register("username");
session_register("fullname");
session_register("email");
session_register("profileID");
session_register("phoolID");
}
// If we don't have a username, set it to Guest
if($HTTP_SESSION_VARS["username"]=="") {
$HTTP_SESSION_VARS["username"]="Guest";
}
// Local script alias for userID
$playerID=$HTTP_SESSION_VARS["userID"];
// Clear $SYS array and then load configuration file
unset($SYS);
require($configfile);
$SYS["version"] = "0.9b";
// Create the names of the primary tables
$phooltbl = $SYS["prefix"] . "Phools";
$playertbl = $SYS["prefix"] . "Players";
$profiletbl = $SYS["prefix"] . "Profiles";
// Get HTML layout filenames
$header = $SYS["includes"] . "/layout/" . $SYS["layout_name"] . ".header.php";
$footer = $SYS["includes"] . "/layout/" . $SYS["layout_name"] . ".footer.php";
$mainnav = $SYS["includes"] . "/layout/" . $SYS["layout_name"] . ".mainnav.php";
$css = $SYS["assets"] . "/" . $SYS["layout_name"] . ".mainstyle.css";
// Start ADODB connection
require($SYS["includes"] . "/adodb/adodb.inc.php");
$conn = &ADONewConnection("mysql");
$conn->Connect($SYS["db_host"], $SYS["db_user"], $SYS["db_pass"], $SYS["db_data"]);
// If user has not yet been set, check for a cookie
//if($playerID==0 && isset($HTTP_COOKIE_VARS["sportsuser"])) {
// Log user in
// include("./cookie_login.php");
//}
// Get PHool information, if applicable
$profile=0; $phool=0; $weekID=0;
$phoolname=""; $profilename="";
if($HTTP_GET_VARS["gProfile"]) $HTTP_SESSION_VARS["profileID"]=$HTTP_GET_VARS["gProfile"];
if($HTTP_SESSION_VARS["profileID"]) {
$profile=$HTTP_SESSION_VARS["profileID"];
$qry="SELECT P.phoolID, P.phoolname, R.profilename, P.timezone FROM $phooltbl P, $profiletbl R WHERE P.phoolID=R.phoolID AND R.playerID=$playerID AND R.profileID=$profile";
if($rs=&$conn->Execute($qry)==FALSE){
die($conn->ErrorNo() . ": " . $conn->ErrorMsg());
}
$HTTP_SESSION_VARS["phoolID"]=$rs->fields["phoolID"];
$phoolname=$rs->fields["phoolname"];
$profilename=$rs->fields["profilename"];
$tz=$rs->fields["timezone"];
if($SYS["dst"]) $tz+=round($SYS["dst_offset"]/3600,1);
}
if($HTTP_GET_VARS["gPhool"]) $HTTP_SESSION_VARS["phoolID"]=$HTTP_GET_VARS["gPhool"];
if($HTTP_SESSION_VARS["phoolID"]) {
$phool=$HTTP_SESSION_VARS["phoolID"];
if($HTTP_GET_VARS["gWeek"]) {
$weekID=$HTTP_GET_VARS["gWeek"];
} else {
$weekID=getCurrentWeek($phool);
}
$qry="SELECT weekname, stopdate FROM " . $SYS["prefix"] . $phool . "Weeks WHERE weekID=$weekID";
$rs=&$conn->Execute($qry);
$weekname=$rs->fields["weekname"];
$stopdate=$rs->fields["stopdate"];
}
// Function to output JavaScript that converts GMT to client's local time
// Requires:
// $gmtimestamp = a Unix timestamp of the GMT you want converted
// $dtz = number of hours offset you want the time displayed if no JS
// Returns:
// nothing
function writeLocal($gmtimestamp) {
global $tz;
// JS uses microseconds
echo "<script type=\"text/javascript\">writeLocalDate(" . $gmtimestamp*1000 . ")</script>\n";
echo "<noscript> <!-- For clients with JavaScript disabled -->\n";
echo date("l, d F Y, h:ia", $gmtimestamp + ($tz*3600)) . " GMT $tz\n";
echo "</noscript>\n";
} // End function writeLocal
// Function to get current default week of a PHool
// Requires:
// $phool = ID of PHool
// Returns:
// $week = ID of current default week
function getCurrentWeek($phool) {
global $SYS, $conn;
// Set $week to 0(zero)
$week = 0;
// Get week table for this PHool
$weektbl = $SYS["prefix"] . $phool . "Weeks";
// Query finds all weeks where the startdate is less than current time
$qry = "SELECT weekID FROM " . $weektbl . " WHERE startdate<" .
$SYS["gmt"] . " ORDER BY startdate DESC";
$weeks = &$conn->Execute($qry);
// If query returned records, get default view week,
// which is first record returned by query
if(!$weeks->EOF) {
$week = $weeks->fields["weekID"];
}
return $week;
} // End function getCurrentWeek
// Function to output list of weeks as links
// Requires:
// $file = uri for link
// $userfunc = user function number for file (if applicable)
// $phoolID = PHool ID to include in links
// $currentweek = weekID of currently displayed week info
// $linebreak = number of links to put on a single line
// Returns:
// nothing
function switch_week($file, $userfunc, $currentphool, $currentweek, $linebreak=8) {
global $conn, $SYS;
$weektbl = $SYS["prefix"] . $currentphool . "Weeks";
// Get list of all weeks for current PHool
$qry = "SELECT weekID, weekname FROM $weektbl ORDER BY startdate ASC";
if($weeks=&$conn->Execute($qry)===FALSE) {
echo "<p><strong>Error retrieving weeks list:<br/>"
. $conn->ErrorNo() . ": " . $conn->ErrorMsg() . "</strong></p>";
return FALSE;
}
// We'll use this counter to keep weeks from scrolling off the right edge of the screen
$counter = 1;
echo "<p class=\"switchweek\">Switch to week:<br/>";
while (!$weeks->EOF) {
$id = $weeks->fields["weekID"]; $name = $weeks->fields["weekname"];
// If this is the currently viewed week, don't output a link
// and surround the week name with SPAN with a class "deadlink"
// You can control the appearance of the deadlink in mainstyle.css
if ($id==$currentweek) {
echo "<span class=\"deadlink\"> $name </span>\n";
} else {
echo "<a href=\"$file?userfunc=$userfunc&gPhool=$currentphool&gWeek=$id&". SID . "\"> $name </a>\n";
}
// If we've output $linebreak weeks, insert an HTML line break to keep the screen tidy
if(!($counter%$linebreak)) {
echo "<br />\n";
}
$counter++;
$weeks->MoveNext();
}
echo "</p>\n";
} // End function switch_week()
// Function to output SELECT list for changing profiles
// Requires:
// $file = uri for link
// $userfunc = user function number to send to file
// $playerID = ID of current player
// $currentprofile = ID of current profile
// Returns:
// nothing
function switch_profile($file, $userfunc, $player, $currentprofile) {
global $conn, $profiletbl, $SYS;
$qry="SELECT profilename, profileID FROM $profiletbl WHERE playerID=$player";
if($rs=&$conn->Execute($qry)===FALSE) {
echo "<p><strong>There was an error retrieving data. Please inform the site administrator of this error message:<br/>\n" . $conn->ErrorNo() . ": " . $conn->ErrorMsg() . "</strong></p>\n";
return;
}
if($rs->EOF) {
return FALSE;
}
echo "<form action=\"" . $SYS["base_href"] . "/switch_profile.php?" . SID . "\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"file\" value=\"$file\"/>\n";
echo "<input type=\"hidden\" name=\"userfunc\" value=\"$userfunc\"/>\n";
echo "<p>";
echo $rs->GetMenu2("newProfile", $currentprofile, TRUE);
echo " <input type=\"submit\" value=\"Switch profile\"/></p></form>\n";
return TRUE;
} // End function switch_profile()
?>