Location: PHPKode > projects > GolfstatsPHP > golfstatsphp_3.0/startgame.php
<?
include("dbasecon.inc.php");
include("session.inc.php");
include ("header.php");
include_once "sf.php";
include("userfunctions.inc.php");

$usersql= "Select * From users_tour
						where userid='$login_id'";
	 $userquery=mysql_query($usersql);
	 $userrow=mysql_fetch_array($userquery);	 			
	 $userexist=mysql_numrows($userquery);

	 extract($userrow);
	 
//get list of courses

$coursesql= "Select * From courses
						ORDER BY courseid ASC";
	 $coursequery=mysql_query($coursesql);
	 $courserow=mysql_fetch_array($coursequery);	 			
	 $courseexist=mysql_numrows($coursequery);

if ($HTTP_POST_VARS['setgame']) {

$error="Game has been set.";

//format date
$realdate="$year-$month-$day";
$realtime="$hour:$minute:00";

$insertsql="INSERT INTO gameorg (date, time, courseid,eventname, userid, noplayers, player1, player2, 
player3, player4, player5, player6, player7, player8, player9, player10, player11, player12, player13, player14, player15, player16) 
VALUES ('$realdate', '$realtime', '$courseid','$reqeventname', '$login_id', '$noplayers', '$login_id', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')";

	 $insertquery=mysql_query($insertsql);
$eventname=$reqeventname;
} //endif post vars set game


if ($HTTP_POST_VARS['updategame']) {

$error="Game has been updated.";

//format date
$realdate="$year-$month-$day";
$realtime="$hour:$minute:00";

$updatesql="UPDATE gameorg SET time= '$realtime', date='$realdate', eventname='$reqeventname' WHERE ID='$gameorgid'";
	 $updatequery=mysql_query($updatesql);


} //endif post vars update game


//ok, this is to EDIT!
if ($action) {

if ($action=="modify") {
///check
$checksql="Select * from gameorg where userid='$login_id' and id='$gameorgid'";
$checkquery=mysql_query($checksql);
$checkexist=mysql_numrows($checkquery);

if ($checkexist) {
$getgame="Select * from gameorg left join courses on gameorg.courseid = courses.courseid
				where gameorg.id='$gameorgid'";
$getgamequery=mysql_query($getgame);
	 $getgamerow=mysql_fetch_array($getgamequery);	 			
	 $getgameexist=mysql_numrows($getgamequery);

	 
$sqldate=explode("-",$getgamerow['date']);	 
$sqltime=explode(":",$getgamerow['time']);	 
	 
$year=$sqldate[0];	 
$month=$sqldate[1];
$day=$sqldate[2];
$hour=$sqltime[0];
$minute=$sqltime[1];

$coursenamegrey=$getgamerow['coursename'];
$noplayersgrey=$getgamerow['noplayers'];
$eventname=$getgamerow['eventname'];	 
} else {

echo "<font class='error'>Trying to edit a game you did not create. Your ID has been sent to the administrative staff.</font>";
$exit();
}//endif check



} else {};//endif action is edit

}//endif getvars action


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<? showheader("Game Organiser"); ?>
<font class="heading">Game Organiser</font>
<p>
<? echo "<font class='error'>$error</font>"; ?>
<p>

<form  method="post" action="<?=$PHP_SELF?>">
<table border="1" cellpadding="5" cellspacing="5">
<tr><td class=bg1>
User Name:
</td>
<td>
<? echo "$name $surname"; ?>
</td>
</tr>

<tr><td class=bg1>
Event Name:
</td>
<td>
<input type="text" maxlength="50" size="50" name="reqeventname" value="<? echo $eventname;?>"></td></td>
</tr>

<tr>
<td class=bg1>
Date:
</td>

<td>                          
						  <select name="day">
	<? 
		$listdayz = listdigits("31", "$day");
		echo "$listdayz";
	?>	
						  </select>

                          / 
						  <select name="month">
	<? 
		$listmonths = listdigits("12", "$month");
		echo "$listmonths";
	?>	
						  </select>

                          / 
                          <select name="year">
	<? 
	$thisyear=date('Y');
		$listyears2 = listyears2("0", "$thisyear");
		echo "$listyears2";
	?>
                          </select>
</td>
</tr>



<tr>
<td class=bg1>
Time:
</td>
<td>                          
						  <select name="hour">
	<? 
	if (!$hour) {$hour=7;}
		$listdayz2 = listdigits2("24", "$hour");
		echo "$listdayz2";
	?>	
						  </select>

                          :
						  <select name="minute">
	<? 
		$listmonths2 = listdigits2("60", "$minute");
		echo "$listmonths2";
	?>	
						  </select>

</td>
</tr>

<tr>
<td class=bg1>
Select Course:
</td>

<? if ($action=="modify") { ?>

<td> <? echo "$coursenamegrey"; ?>
<?  } else { ?>

<td>
<select name="courseid">

<?

//OK, populate the drop down on the row.

do {

$courseid_tmp=$courserow["courseid"];

if ($courseid_tmp == $courseid) {
$selected="SELECTED";

} else {
$selected="";
}

printf("<option value=\"%s\" $selected > %s -- %s",
$courserow["courseid"],  $courserow["courseid"], $courserow["coursename"]);

 																																																			 
																																															
}while ($courserow=mysql_fetch_array($coursequery));
 //endwhile


?>
</select>
</td>

<? } //endif actiuon modify
 ?>

</tr>
<tr>
<td class=bg1>
No. of Players:
</td>
<td> 

<? if ($action=="modify") { ?>

<? echo "$noplayersgrey"; ?>
<? } else { ?>
<select name='noplayers'>
	<? 
	if (!$noplayers) {$noplayers=4;}
		
		$listdayz = listdigits("16", "$noplayers");
		echo "$listdayz";
	?>	

</select>

<? } ?>




</td>
</tr>
<p>
<tr>
<td class=bg1>
<input type="Hidden" name="username" value="<?echo "$name &nbsp;"; echo "$surname";?>">
<input type="Hidden" name="gameorgid" value="<?echo "$gameorgid";?>">
<input type="Hidden" name="action" value="<?=$action;?>">

<? if ($action=="modify") { ?>
<input type="Submit" name="updategame" value="Update Game">


<? } else { ?>
<input type="Submit" name="setgame" value="Set Game">
<? } ?>
</td>
</tr>
</table>

<p>
</form>



<? showfooter(); ?>
Return current item: GolfstatsPHP