Location: PHPKode > projects > GolfstatsPHP > golfstatsphp_3.0/course.php
<?

include("dbasecon.inc.php");

include("session.inc.php");

include ("header.php");

include ("coursefunctions.inc.php");

if ($login_id <> "$guestid") {



if ($HTTP_POST_VARS['SubmitCourse']) {



//first check see if course already exist



$coursechecksql="select * from courses where courseid='$reqcourseid'";

				$coursecheckquery=mysql_query($coursechecksql);

				$coursecheckrow=mysql_fetch_array($coursecheckquery);

				$coursecheckexist=mysql_numrows($coursecheckquery);

				



if (!$coursecheckexist) {				

$hole=0;

$holepar=0;

$front9=0;

$back9=0;

$coursepar=0;

$courselength=0;

$front9length=0;

$back9length=0;



do {

$hole++;

$parhole=parhole.$hole.a;

$lengthhole=lengthhole.$hole.a;

//1. count the fron, back 9 and total par

$holepar=${$parhole};



//2.count the front, back 9 ,total courselength

$holelength=${$lengthhole};



if ($hole<=9) {

$front9=$front9+$holepar;

$front9length=$front9length+$holelength;

}else {

$back9=$back9+$holepar;

$back9length=$back9length+$holelength;



}





 

} while ($hole<18);



$coursepar=$back9+$front9;

$courselength=$back9length+$front9length;



//echo $front9length;



 $scoreaddsql = "INSERT INTO courses (owner, courseid, coursename, courseaddress, coursestate, courserating, 

 sloperating, coursepar, courselength, front9length, front9, back9, back9length, coursephone, coursefax, 

 courseweb, coursenotes, parhole1, indexhole1, lengthhole1, parhole2, indexhole2, lengthhole2, parhole3,

  indexhole3, lengthhole3, parhole4, indexhole4, lengthhole4, parhole5, indexhole5, lengthhole5, parhole6, 

	indexhole6, lengthhole6, parhole7, indexhole7, lengthhole7, parhole8, indexhole8, lengthhole8, parhole9, 

	indexhole9, lengthhole9, parhole10, indexhole10, lengthhole10, parhole11, indexhole11, lengthhole11, parhole12,

	 indexhole12, lengthhole12, parhole13, indexhole13, lengthhole13, parhole14, indexhole14, lengthhole14, 

	 parhole15, indexhole15, lengthhole15, parhole16, indexhole16, lengthhole16, parhole17, indexhole17, 

	 lengthhole17, parhole18, indexhole18, lengthhole18) 

	 VALUES 

	 ('$login_id', '$reqcourseid', '$reqcoursename', '$courseaddress1', '$coursestate1', '$reqcourserating', 

	 '$reqsloperating', '$coursepar','$courselength' , '$front9length', '$front9', '$back9', '$back9length', 

	 '$coursephone1', '$coursefax1', '$courseweb1', '$coursenotes1', '$parhole1a', '$indexhole1a', '$lengthhole1a', 

	 '$parhole2a', '$indexhole2a', '$lengthhole2a','$parhole3a', '$indexhole3a', '$lengthhole3a',

	 '$parhole4a', '$indexhole4a', '$lengthhole4a','$parhole5a', '$indexhole5a', '$lengthhole5a',

	 '$parhole6a', '$indexhole6a', '$lengthhole6a','$parhole7a', '$indexhole7a', '$lengthhole7a',

	 '$parhole8a', '$indexhole8a', '$lengthhole8a','$parhole9a', '$indexhole9a', '$lengthhole9a',

	 '$parhole10a', '$indexhole10a', '$lengthhole10a','$parhole11a', '$indexhole11a', '$lengthhole11a',

	 '$parhole12a', '$indexhole12a', '$lengthhole12a','$parhole13a', '$indexhole13a', '$lengthhole13a',

	 '$parhole14a', '$indexhole14a', '$lengthhole14a','$parhole15a', '$indexhole15a', '$lengthhole15a',

	 '$parhole16a', '$indexhole16a', '$lengthhole16a','$parhole17a', '$indexhole17a', '$lengthhole17a',

	 '$parhole18a', '$indexhole18a', '$lengthhole18a')";

	 	 	 

$scoreaddresult=mysql_query($scoreaddsql);



$error="$reqcoursename has been added to the database.";





} else {



$error="The Course ID exist! Please input another course id.";



} //endif courseexist







}//endif submit course













//get list of courses



$coursesql="select * from courses   

					where courses.owner = '$login_id' 

					order by courses.coursename desc";



				$coursequery=mysql_query($coursesql);

				$courserow=mysql_fetch_array($coursequery);

				$courseexist=mysql_numrows($coursequery);



				



?>



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



<? showheader("Course Manager"); ?>



<? echo "<p class='error'>".$error."<p>"; ?>



<b class="error">Click on the Course ID to edit</b><p>





<form  method="post" action="<? echo $PHP_SELF; ?>">



<u><b>Courses created: <? echo $courseexist; ?></b></u>



<p>

<?

if ($courseexist) {



?>



<table border=1>

<tr class="menu-bg">

<td>Course ID</td><td>Course</td><td>Location</td><td>Course Rating</td><td>Slope Rating</td><td>Par</td><td>Length</td>

</tr>









<?



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

do {

extract($courserow);

echo "<tr><td class='menu-bg2'><a href='course2.php?courseid=$courseid&action=change'>$courseid</a></td><td>$coursename</td><td>$coursestate</td>";

echo "<td>$courserating</td><td>$sloperating</td><td>$coursepar</td>";

echo "<td>$courselength $measureshort</td>"; 

//noticable stuff here is the javascript embedded function in the delete button onClick!





echo "</tr>";



 																																																			 

																																															

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

 //endwhile





echo "</table>";

 

} else {



echo "<b>You have not created any courses.</b>"; 

}

?>





<p>

<input type="Submit" name="add" value="Add New Course">

</form>

<p>





<?



if (($add) || ($coursecheckexist)) {



?>

<table border=0 width=90%>

<tr>

<td width=50%>

<FORM action="<?=$PHP_SELF?>" method=post onSubmit="return checkrequired(this)">

            

            <TABLE border=0 cellPadding=1 cellSpacing=1>

              <TBODY>

              <TR>

                <TD class='menu-bg'>Course Name</TD>

                <TD><INPUT maxlength=50 size=50 name=reqcoursename value=<? echo $reqcoursename; ?> ></TD></TR>

								<TR>

                <TD class='menu-bg'>Course ID</TD>

                <TD><INPUT name=reqcourseid maxlength=5 size=5 value=<? echo $reqcourseid; ?>></TD></TR>

              <TR>

                <TD class='menu-bg'>Website</TD>

                <TD><INPUT maxlength=100 size=50 name=courseweb1  value="<?  if (!$courseweb1) { echo 'http://'; } else {echo $courseweb1;} ?>"></TD></TR>

              <TR>

                <TD class='menu-bg'>Address</TD>

                <TD><INPUT maxlength=100 size=50 name=courseaddress1 value=<? echo $courseaddress1; ?>></TD></TR>

              <TR>

                <TD class='menu-bg'>State</TD>

                <TD><INPUT maxlength=50 size=50 name=coursestate1 value=<? echo $coursestate1; ?>></TD></TR>

              <TR>

                <TD class='menu-bg'>Telephone</TD>

                <TD><INPUT name=coursephone1 maxlength=15 value=<? echo $coursephone1; ?>></TD></TR>

              <TR>

                <TD class='menu-bg'>Fax</TD>

                <TD><INPUT name=coursefax1 maxlength=15 value=<? echo $coursefax1; ?>></TD></TR>

                  <TR>





       </TABLE>



</td>

<td>

            <TABLE border=0 cellPadding=1 cellSpacing=1>



<TD class='menu-bg'>Notes</TD>

                <TD><TEXTAREA name=coursenotes1 rows="10" cols="50"><? if (!$coursenotes1) { echo "Green Fees (members/non-members), membership etc"; } else {echo "$coursenotes1";} ?></TEXTAREA></TD></TR>

              <TR>

                <TD>&nbsp;</TD>

                <TD></TD></TR></TBODY>



</table>



</td>

</tr>								

</table>







<form name="newHoleForm" method="post" action="?p=6.1" onSubmit="return verify(this);">

	<table border="1" cellspacing="1" cellpadding="1">

		<tr class='menu-bg'> 

			<td colspan="3">Hole</td>

			<td align="center">1</td>

			<td align="center">2</td>

			<td align="center">3</td>

			<td align="center">4</td>

			<td align="center">5</td>

			<td align="center">6</td>

			<td align="center">7</td>

			<td align="center">8</td>

			<td align="center">9</td>

			<td align="center">10</td>

			<td align="center">11</td>

			<td align="center">12</td>

			<td align="center">13</td>

			<td align="center">14</td>

			<td align="center">15</td>

			<td align="center">16</td>

			<td align="center">17</td>

			<td align="center">18</td>

		</tr>

		<tr> 

			<td colspan="3" class='menu-bg'>Par</td>



			<?

			$holecount=0;

			do {

			$holecount++;		

			$parholecount=parhole.$holecount.a;

			echo "<td align='center'><select name=\"$parholecount\">";

	    if (!${$parholecount}) { ${$parholecount}=4;}			

		$listpars = listpars("5", "${$parholecount}");

		echo "$listpars";

		echo "</select></td>";			

			} while ($holecount<18);

			

			?>

				</tr>

		<tr class='menu-bg'> 

			<td>Slope Rt.</td>

			<td>Course Rt.</td>

			<td>&nbsp;</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

			<td><?echo $measure;?> | Index</td>

		</tr>

		<tr> 

			<td><input type="text" size="3" name="reqsloperating" value="<? echo $reqsloperating; ?>"></td>

			<td><input type="text" size="3" name="reqcourserating" value="<? echo $reqcourserating; ?>"></td>

			<td>&nbsp;</td>



			

						<?

			$holecount=0;

			do {

			$holecount++;		

			$parholecount=parhole.$holecount.a;

			$lengthholecount=lengthhole.$holecount.a;

			$indexholecount=indexhole.$holecount.a;

			echo "<td><input type='text' maxlength='3' size='3' name=\"$lengthholecount\" value='${$lengthholecount}'>";

			echo "<br><select name=\"$indexholecount\">";

			

				    if (!${$indexholecount}) { ${$indexholecount}=1;}			

		$listindex = listindex("18", "${$indexholecount}");

		echo "$listindex";

		echo "</select></td>";			



			} while ($holecount<18);

			

			?>



			

		</tr>

	</table>

<p>

<center>

<INPUT name="SubmitCourse" type="submit" value="Submit Course">

</center>

</form>









<?























}





if ($action=="change") {



}



?>











<?
} else {


showheader("Score Manager");
echo "Guest cannot add courses. Please <a href='signup.php'>register</a> for free!";

} //endif loginid<>guestid
?>










<? showfooter(); ?>

Return current item: GolfstatsPHP