Code:<?PHP
if ( !defined('MODULE_FILE') )
{
die("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
if (!defined('INDEX_FILE')) define('INDEX_FILE', true); // Set to FALSE to hide right blocks
###
### Main Page
###
function mainpage() {
include ('header.php');
$result = mysql_query("select match_id, home_team, away_team, home_score, away_score, cup, match_date from team_scores2 where status>0 order by match_date DESC");
echo "<center><H2><B>Live Cup Result Listings</b></h2></center>";
echo "<center><B>All results submitted through this system must be genuine match results only.</b><BR><BR><B></center>";
echo "<BR><table width=100%>";
$lastmatchdate="";
while (list($match_id, $home_team, $away_team, $home_score, $away_score, $cup, $match_date) = mysql_fetch_row($result))
{
if ($match_date!=$lastmatchdate)
{
$matchdate = date("Y-m-d", strtotime($match_date));
$displaymatchdate = date("d-m-Y", strtotime($match_date));
echo "<tr><td colspan=4 align=center><font size=2><b><a href=\"modules.php?name=Cup_results&op=showdate&date=$matchdate\">Click here for matches played on $displaymatchdate</a></b></font size=2></td></tr>";
}
$lastmatchdate=$match_date;
}
echo "</table>";
livefooter();
mysql_free_result($result);
include ('footer.php');
}
###
### Show Date Listing
###
function showdate($matchdate) {
include ('header.php');
$result = mysql_query("select match_id, home_team, away_team, home_score, away_score, cup, match_date, status, comments from team_scores2 where status>0 AND match_date='$matchdate' order by match_date, cup");
echo "<BR><center><table width=75% border=1 valign=top>";
$lastcup="9";
$lastmatchdate="";
while (list($match_id, $home_team, $away_team, $home_score, $away_score, $cup, $match_date, $status, $comments) = mysql_fetch_row($result))
{
if ($match_date!=$lastmatchdate)
{
$matchdate = date("Y-m-d", strtotime($match_date));
$displaymatchdate = date("d-m-Y", strtotime($match_date));
echo "<tr><td colspan=4 align=center bgcolor=\"#B1CFED\"><h2><b>Games Played On $displaymatchdate</b></h2></td></tr>";
}
if ($cup!=$lastcup)
{
echo "<tr><td colspan=4 align=center bgcolor=\"#EEF4FC\"><font size=4><b>cup $cup</b></font size=4></td></tr>";
}
if ($status==1)
{
echo "<tr><td bgcolor=\"#ffffff\" align=right width=43%><font size=4><a href=\"modules.php?name=Cup_results&op=teammatches&team=$home_team\">$home_team</a></font size=4></td><TD bgcolor=\"#ffffff\" align=center width=7%><font size=4>$home_score</font size=4></TD><TD bgcolor=\"#ffffff\" align=center width=7%><font size=4>$away_score</font size=4></TD><TD bgcolor=\"#ffffff\" align=left width=43%><font size=4><a href=\"modules.php?name=Cup_results&op=teammatches&team=$away_team\">$away_team</a></font size=4></td></tr>";
}
$thiscount=$thiscount+1;
$lastcup=$cup;
$lastmatchdate=$match_date;
}
livefooter();
mysql_free_result($result);
include ('footer.php');
}
###
### Show All Team Match Scores By date
###
function teammatches($team) {
include ('header.php');
$result = mysql_query("select match_id, home_team, away_team, home_score, away_score, cup, match_date, status, comments from team_scores2 where status>0 AND (home_team='$team' or away_team='$team') order by match_date");
echo "<BR><center><table width=90% border=1 valign=top>";
echo "<tr><td colspan=5 align=center bgcolor=\"#B1CFED\"><h3>Games Played By $team This Season</h3></td></tr>";
while (list($match_id, $home_team, $away_team, $home_score, $away_score, $cup, $match_date, $status, $comments) = mysql_fetch_row($result))
{
$matchdate = date("Y-m-d", strtotime($match_date));
$displaymatchdate = date("d-m-Y", strtotime($match_date));
echo "<tr><td bgcolor=\"#ffffff\" align=right width=20%><font size=4>$displaymatchdate</font></td><td bgcolor=\"#ffffff\" align=right width=33%><font size=4><a href=\"modules.php?name=Cup_results&op=teammatches&team=$home_team\">$home_team</a></font size=4></td><TD bgcolor=\"#ffffff\" align=center width=7%><font size=4>$home_score</font size=4></TD><TD bgcolor=\"#ffffff\" align=center width=7%><font size=4>$away_score</font size=4></TD><TD bgcolor=\"#ffffff\" align=left width=33%><font size=4><a href=\"modules.php?name=Cup_results&op=teammatches&team=$away_team\">$away_team</a></font size=4></td></tr>";
}
echo "</table></center>";
### Graph Progress
$result = mysql_query("select match_id, home_team, away_team, home_score, away_score, cup, match_date, status, comments from team_scores2 where status>0 AND (home_team='$team' or away_team='$team') order by match_date");
echo "<BR><center><table width=90% border=1 valign=top>";
echo "<tr><td colspan=3 align=center bgcolor=\"#B1CFED\"><h3>Progress This Season</h3></td></tr>";
echo "<tr><td bgcolor=\"#ffffff\" align=right><font size=4>Match Date</font size=4></td><td bgcolor=\"#ffffff\" align=right width=40%><font size=4>Games Against</font size=4></td><TD bgcolor=\"#ffffff\" align=left width=40%><font size=4>Games For</font size=4></td></tr>";
while (list($match_id, $home_team, $away_team, $home_score, $away_score, $cup, $match_date, $status, $comments) = mysql_fetch_row($result))
{
$matchdate = date("Y-m-d", strtotime($match_date));
$displaymatchdate = date("d-m-Y", strtotime($match_date));
$homewidth=$home_score*18;
$awaywidth=$away_score*18;
}
if ($team==$away_team)
{
echo "<tr><td bgcolor=\"#ffffff\" align=right><font size=4>$displaymatchdate</font></td><td bgcolor=\"#ffffff\" align=right width=40%>$home_score<img src=\"/images/reddot.jpg\" height=20 width=$homewidth></td><TD bgcolor=\"#ffffff\" align=left width=40%><img src=\"/images/greendot.jpg\" height=20 width=$awaywidth>$away_score</td></tr>";
}
else
{
echo "<tr><td bgcolor=\"#ffffff\" align=right><font size=4>$displaymatchdate</font></td><td bgcolor=\"#ffffff\" align=right width=40%>$away_score<img src=\"/images/reddot.jpg\" height=20 width=$awaywidth></td><TD bgcolor=\"#ffffff\" align=left width=40%><img src=\"/images/greendot.jpg\" height=20 width=$homewidth>$home_score</td></tr>";
}
{
echo "</table></center>";
livefooter();
mysql_free_result($result);
include ('footer.php');
}
}
###
### Result Form
###
function resultform($user) {
include ('header.php');
OpenTable();
### registered user or email address
$user2 = base64_decode($user);
$user2 = addslashes($user2);
$user2 = explode(":", $user2);
$username = "$user2[1]";
if (date("Y-m-d", strtotime("this sunday"))==date("Y-m-d", strtotime("today")))
{
$lastsunday = date("Y-m-d", strtotime("today"));
$displaylastsunday = date("d-m-Y", strtotime("today"));
}
else
{
$lastsunday = date("Y-m-d", strtotime("last sunday"));
$displaylastsunday = date("d-m-Y", strtotime("last sunday"));
}
if ($username=='')
{
die ("<font size=4>You must be logged in to submit a result...</font size=4>");
}
echo "<font size=4>Submit Cup Match Result. If 7-0, please indicate if a no show in the comments box.</font size=4>";
echo "<FORM ACTION=\"modules.php?name=Cup_results\" METHOD=\"POST\" NAME=\"Result\">";
echo "<B>Which Cup:</b></font><select name=\"which_cup\" size=\"1\">
<option>Select A Cup</option>
<option>Baxter</option>
<option>Forresters</option>
<option>Gifford</option>
<option>MacAverne</option>
<option>Workingmens</option>
</select><BR>
<b>Home Team:</b><input type=text NAME=\"home_team\"><br />
<B>Home Score:</b><select name=\"home_score\" size=\"1\">
<option>Select A Score</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select><BR>
<b>Away Team:</b><input type=text name=\"away_team\"><br />
<B>Away Score:</b><select name=\"away_score\" size=\"1\">
<option>Select A Score</option>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select><BR>
<B>Date:</b> <input type=text NAME=\"matchdate\" value=\"$displaylastsunday\" disabled><BR>
<B>Your Name:</b> <input type=text NAME=\"submitter\" size=30><BR>";
{
echo "<B>User ID: </b> <input type=text NAME=\"email\" size=30 value=\"".$username."\" disabled> As a registered user your results are prevalidated<BR>";
}
echo "
<textarea name=\"comments\" cols=60 rows=5></textarea>
<input type=hidden name=\"op\" value=\"submitted\">
<input type=hidden name=\"away-team\">
<input type=hidden NAME=\"matchdate\" value=\"$lastsunday\">
<input type=hidden NAME=\"which_cup\" value=\"\">
<input type=hidden name=\"home_team\">
<BR clear=all><INPUT TYPE=\"submit\" value=\"Submit\">";
echo "</form>";
livefooter();
CloseTable();
include ('footer.php');
}
### Add Result To Database
### Add Result To Database
### Add Result To Database
function submittedresult($home_team, $away_team, $home_score, $away_score, $cup, $match_date, $submitter, $email, $comments, $user) {
include ('header.php');
### registered user or email address
$user2 = base64_decode($user);
$user2 = addslashes($user2);
$user2 = explode(":", $user2);
$username = "$user2[1]";
if ($username!=''){$email=$username;}
#$cup=substr($cup,22,1);
## Get date of next sunday
if (date("Y-m-d", strtotime("this sunday"))==date("Y-m-d", strtotime("today")))
{
$lastsunday = date("Y-m-d", strtotime("today"));
}
else
{
$lastsunday = date("Y-m-d", strtotime("last sunday"));
}
$matchdate = date("Y-m-d", strtotime($match_date));
$displaymatchdate = date("d-m-Y", strtotime($match_date));
##
## Make sure all fields are filled in
##
if ($home_team=='' or $away_team=='' or $home_score=='' or $away_score=='' or $cup=='' or $match_date=='' or $email=='')
{
echo "Somehow you have got this far without filling in all the fields on the previous form. Please return to the previous page and fill in all the fields.";
exit;
}
# check to see if this result has been submitted twice
$result = mysql_query("select COUNT(*) from team_scores2 where home_team='$home_team' AND away_team='$away_team' AND match_date='$match_date' AND cup='$cup' AND home_score='$home_score' AND away_score='$away_score' AND submitter='$submitter' AND email='$email'");
$totalcount3=mysql_fetch_array($result);
$alreadylogged= $totalcount3[0];
if ($alreadylogged==0){
$result=mysql_query("insert into team_scores2 values (NULL, '$home_team', '$away_team', $home_score, $away_score, '$cup', '$matchdate', '$submitter', 0, '$email', '$comments')");
if (!$result) {
die('Could not write record: ' . mysql_error());
}
}
### Read back in
$result = mysql_query("select match_id from team_scores2 where home_team='$home_team' AND away_team='$away_team' AND match_date='$matchdate' AND cup='$cup' AND home_score='$home_score' AND away_score='$away_score' AND submitter='$submitter' AND email='$email' limit 1");
while (list($match_id) = mysql_fetch_row($result))
{
$this_match=$match_id;
$email2 = str_replace('.', ',', $email);
}
{
### Registered user. Send email and validate.
### Look up email address
$result = mysql_query("select user_email from nuke_users where username='$email'");
while (list($useremail) = mysql_fetch_row($result))
{
mail("$useremail", "Weston Pool League Result", "The following match result has been received and pre-validated.
cup: $cup
Home team: $home_team $home_score
Away team: $away_team $away_score
Match date: $displaymatchdate
Submitted By: $email
Email: $useremail
Comments: $comments
Thank you for your submission.
DO NOT DELETE THIS EMAIL. This is confirmation of receipt of your result and may be needed in cases of dispute.
", "From: NOREPLY@westonpoolleague.org.uk");
}
echo "<h2>Result Submission</h2>
cup: $cup<BR>
Home team: $home_team $home_score<BR>
Away team: $away_team $away_score<BR>
Match date: $displaymatchdate<BR>
Submitted By: $email<BR>
Email: $useremail<BR>
Comments: $comments
<BR><BR>";
echo "<font size=4>As a pregistered site user your result has now been accepted, you can see it by <a href=\"modules.php?name=Cup_results&op=showdate&date=$lastsunday\">clicking here</a>.<BR>.</font size=4>";
### Update result to live
# delete where details are the same and != match_id
mysql_query("delete from team_scores2 where (home_team='$home_team' AND away_team='$away_team' AND home_score='$home_score' AND away_score='$away_score' AND match_date='$match_date' AND match_id!='$this_match')");
# make validated link live
mysql_query("update team_scores2 set status='1' where match_id='$this_match'");
#mail result to RebelT
mail("webmaster@westonpoolleague.org.uk", "League Result $home_team v $away_team", "The following result has been submitted
Cup: $cup
Home team: $home_team $home_score
Away team: $away_team $away_score
Match date: $displaymatchdate
Submitted By: $email
Email: $useremail
Comments: $comments", "From: $useremail");
}
{
echo "<B>This result has already been submitted. Please check the <a href=\"modules.php?name=Cup_results&op=showdate&date=$lastsunday\">real time results service</a>.<BR><BR>";
}
livefooter();
include ('footer.php');
}
###
### Make Live
###
function makelive_result($id, $validate)
{
$email = str_replace(',', '.', $validate);
# read match in
$result = mysql_query("select home_team, away_team, home_score, away_score, match_date, email from team_scores2 where match_id='$id'");
while (list($home_team, $away_team, $home_score, $away_score, $match_date, $thisemail) = mysql_fetch_row($result))
{
# delete where details are the same and != match_id
if ($email==$thisemail){
mysql_query("delete from team_scores2 where (home_team='$home_team' AND away_team='$away_team' AND home_score='$home_score' AND away_score='$away_score' AND match_date='$match_date' AND match_id!='$id')"); }
}
# make validated link live
mysql_query("update team_scores2 set status='1' where match_id='$id' AND email='$email' AND status='0'");
if (mysql_affected_rows()==0)
{
$result = mysql_query("select COUNT(*) from team_scores2 where match_id='$id'");
$totalcount2=mysql_fetch_array($result);
$totalcount= $totalcount2[0];
# No such ID
if ($totalcount==0)
{
dispmessage('nosuchmatchID', $id);
}
else
{
$result = mysql_query("select home_team, away_team, home_score, away_score, cup, match_date, submitter, email, status, comments from team_scores2 where match_id='$id'");
while (list($home_team, $away_team, $home_score, $away_score, $cup, $match_date, $submitter, $thisemail, $status, $comments) = mysql_fetch_row($result))
{
# Already validated
if ($status=='1'){dispmessage('alreadyvalidated', $id);}
# SMS Entry
if ($status=='3'){dispmessage('smssubmission', $id);}
# Wrong email address
if ($email!=$thisemail){dispmessage('wrongemail', $id);}
}
}
}
else
{
$result = mysql_query("select home_team, away_team, home_score, away_score, cup, match_date, submitter, email, comments from team_scores2 where match_id='$id'");
while (list($home_team, $away_team, $home_score, $away_score, $cup, $match_date, $submitter, $email, $comments) = mysql_fetch_row($result))
{
$matchdate = date("Y-m-d", strtotime($match_date));
$displaymatchdate = date("d-m-Y", strtotime($match_date));
mail("webmaster@westonpoolleague.org.uk", "League Result $home_team v $away_team", "The following result has been verified.
cup: $cup
Home team: $home_team $home_score
Away team: $away_team $away_score
Match date: $displaymatchdate
Submitted By: $submitter
Email: $email
Comments: $comments", "From: form@westonpoolleague.org.uk");
dispmessage('authorised', $id);
}
}
}
###
### Errors and Confirmation
###
function dispmessage($messagetype, $id) {
include ('header.php');
if (date("Y-m-d", strtotime("this sunday"))==date("Y-m-d", strtotime("today")))
{
$lastsunday = date("Y-m-d", strtotime("today"));
}
else
{
$lastsunday = date("Y-m-d", strtotime("last sunday"));
}
if ($messagetype=="authorised")
{
echo "<h2><B>Result Validation</b></h2><BR><BR>";
echo "Thank you, your result was successfully verified and has been added to the database. You can view this result on the <a href=\"modules.php?name=Cup_results&op=showdate&date=$lastsunday\">real time results service by clicking here</a>.";
}
}
###
### Page Footer
###
function livefooter(){
echo "<BR><BR><center><table width=90% border=1><tr><td align=center width=50%><a href=\"modules.php?name=Cup_results&op=resultform\"><B>Add Result</b></a></td></table></center><BR><BR><BR><BR>";
}
###
### Main Entry
###
switch($_REQUEST['op']) {
case "resultform":
resultform($_REQUEST['user']);
break;
case "list":
listresults();
break;
case "makelive":
makelive_result($_REQUEST['id'], $_REQUEST['validate']);
break;
case "showdate":
showdate($_REQUEST['date']);
break;
case "teammatches":
teammatches($_REQUEST['team']);
break;
case "delete":
delete_result($_REQUEST['id'], $_REQUEST['validate']);
break;
case "submitted":
submittedresult($_REQUEST['hometeam'], $_REQUEST['awayteam'], $_REQUEST['home_score'], $_REQUEST['away_score'], $_REQUEST['cup'], $_REQUEST['match_date'], $_REQUEST['submitter'], $_REQUEST['email'], $_REQUEST['comments'], $_REQUEST['user']);
break;
default:
mainpage();
break;
}
?>
|