Location: PHPKode > projects > Run > Run-0.8.0.2/Run-0.8.0.2/runnersettings.php
<?php
include("system/environment.php");
include("system/functions.php");
?>

<html>
<?php
include("system/head.php");
?>

<body>

<div class="logo"><img src="system/imgs/runsmall.png"></div>

<?php
//get the data for the selected ID and put it into the array $edit
$editquery = mysql_query("select * from $mysqlTableRunners where Password='".$_COOKIE['CookieRun']."'");
$edit = mysql_fetch_assoc($editquery);

if ($_POST['submit']) {
//this part deals with checking if the data entered are OK or not
	//check if provided passwords are the same
	//if they are not print the whole form out with all values except passwords + a warning saying that the entered passwords do not match
	if ($_POST['Password'] != $_POST['RetypePassword']) {
		$passnomatch = 1;
	}

	//check if the date of birth entered is the correct date. since nothing else but what the form provides can be entered, this is neccessary for 28, 30, 31 day check for the selected month 
	if (checkdate($_POST['BirthMonth'], $_POST['BirthDay'], $_POST['BirthYear']) != 1) {
		$badbirthdate = 1;
	}

	//
	if (strlen($_POST['FirstName']) == 0 || strlen($_POST['LastName']) == 0) {
		$missing = 1;
	}


	//if either (1) passwords don't match, or an (3a) invalid date of birth has been entered, or if (4) password, (6) first name or (7) last name are missing, display the form below that will show what is wrong with that data or what data is missing - along with all other input data (except for passwords)
	if ($passnomatch == 1 || $badbirthdate == 1 || $missing == 1) {
?>


<div class="content">
<p class="header">Settings for <?php echo $user ?></p>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<table border="0">
<tr><td class="right">Username:</td>
<td class="left"><?php echo $user ?>
</td></tr>

<tr><td class="left" colspan="2">Leave empty to keep your current password.</td></tr>
<tr><td class="right">Password:</td>
<td class="left"><input type="password" name="Password" size="20" maxlength="40" value="<?php echo $_POST['Password']?>" class="form"></td></tr>
<tr><td class="right">Retype Password:</td>
<td class="left"><input type="password" name="RetypePassword" size="20" maxlength="40" value="<?php echo $_POST['RetypePassword']?>" class="form"></td></tr>
<?php
	if ($passnomatch == 1) {
		echo "<tr><td colspan=\"2\" class=\"left\"><span class=\"warning\">Entered passwords don't match. Retype both passwords.</span></td></tr>";
	} else {
		echo "<tr><td>&nbsp;</td></tr>";
	}
?>
<tr><td class="right">First Name:</td>
<td class="left"><input type="text" name="FirstName" size="20" maxlength="30" value="<?php echo stripslashes($_POST['FirstName'])?>" class="form"></td></tr>
<?php
	if (strlen($_POST['FirstName']) == 0) {
		echo "<tr><td colspan=\"2\" class=\"left\"><span class=\"warning\">You must enter your first name.</span></td></tr>";
	}
?>

<tr><td class="right">Last Name:</td>
<td class="left"><input type="text" name="LastName" size="20" maxlength="30" value="<?php echo stripslashes($_POST['LastName'])?>" class="form"></td></tr>
<?php
	if (strlen($_POST['LastName']) == 0) {
		echo "<tr><td colspan=\"2\" class=\"left\"><span class=\"warning\">You must enter your last name.</span></td></tr>";
	}
?>

<tr><td class="right">Date of Birth:</td>
<td class="left">
<select name="BirthDay" class="form">
<option value="<?php echo $_POST['BirthDay']?>"><?php echo strlen($_POST['BirthDay']) == 0 ? 'Day' : $_POST['BirthDay']; ?></option>
<?php
generateDays();
?>
</select>

<select name="BirthMonth" class="form">
<option value="<?php echo $_POST['BirthMonth']?>"><?php echo strlen($_POST['BirthMonth']) == 0 ? 'Month' : date("F", mktime(0, 0, 0, $_POST['BirthMonth'], 1, 0, 0)); ?></option>
<?php
generateMonths();
?>
</select>

<select name="BirthYear" class="form">
<option value="<?php echo $_POST['BirthYear']?>"><?php echo strlen($_POST['BirthYear']) == 0 ? 'Year' : $_POST['BirthYear']; ?></option>
<?php
generateYears();
?>
</select>
</td></tr>
<?php
	if ($badbirthdate == 1) {
		echo "<tr><td colspan=\"2\"><span class=\"warning\">The date you entered is not correct.</span></td></tr>";
	}
?>


<tr><td class="right">Gender:</td>
<td class="left"><input type="radio" name="Gender" value="F" <?php if ($_POST['Gender'] == "F") { echo "checked"; }?> class="form">Female<br>
<input type="radio" name="Gender" value="M" <?php if ($_POST['Gender'] == "M") { echo "checked"; }?> class="form">Male</td></tr>

<?php
//reformat date date from YYYY-MM-DD into array(YYYY, MMM, DD)
$membersince = explode("-", $edit['MemberSince']);
?>
<tr><td class="right">Member Since:</td>
<td class="left"><?php echo date("F", mktime(0, 0, 0, $membersince['1']+1, 0, 0)) . " " .  date("jS", mktime (0, 0, 0, 0, $membersince['2'], 0, 0)) . " " . $membersince['0']?>
</td></tr>

<tr><td class="right">Distance Unit:</td>
<td class="left">
<select name="DistanceUnit" class="form">
<?php
distanceUnits($_POST['DistanceUnit']);
?>
</select>
</td></tr>

<tr><td class="right">Temperature Unit:</td>
<td class="left">
<select name="TemperatureUnit" class="form">
<?php
temperatureUnits($_POST['TemperatureUnit']);
?>
</select>
</td></tr>

<tr><td class="right">Weight Unit:</td>
<td class="left">
<select name="WeightUnit" class="form">
<?php
weightUnits($_POST['WeightUnit']);
?>
</select>
</td></tr>

<tr><td class="right">View Mode:</td>
<td class="left"><input type="radio" name="ViewMode" value="0" <?php if ($_POST['ViewMode'] == "0") { echo "checked"; }?> class="form">Full<br>
<input type="radio" name="ViewMode" value="1" <?php if ($_POST['ViewMode'] == "1") { echo "checked"; }?> class="form">Summary</td></tr>

<tr><td class="right">Notes:</td>
<td class="left"><textarea name="Notes" rows="4" cols="30" wrap="virtual" class="form"><?php echo stripslashes(htmlentities($_POST['Notes']))?></textarea></td></tr>

<tr><td class="right"></td>
<td class="left"><input type="submit" name="submit" value="Submit" accesskey="s" class="form">&nbsp;<input type="submit" value="Wipe" accesskey="w" class="form"></td></tr>
<tr><td colspan="2" class="close"><a href="javascript:window.close();" title="Close This Window: Alt+C" accesskey="c" class="url"><u>C</u>lose</a></td></tr>

</table>
</form>
</div>


<?php
//if all entered data are OK, this part does the few final touches and finally enters everything into the database
	} else {
		//if the password was not changed leave it as it is. if it was then use sha1 to encrypt it.
		if ($_POST['Password'] == $edit['Password']) {
			$password = $edit['Password'];
		} else {
			//encrypt the password with sha1
			$password = sha1($_POST['Password']);
		}

		$measurements = measurementUnits($_POST['DistanceUnit'], $_POST['TemperatureUnit'], $_POST['WeightUnit']);

		$dateOfBirth = dateFormat($_POST['BirthDay'], $_POST['BirthMonth'], $_POST['BirthYear']);

		$viewMode = $_POST['ViewMode'] . "0-11111111111";

		//this is the query used to enter the submitted data into the database		
		if (strlen($_POST['Password']) == 0) {
			$query = "update $mysqlTableRunners set FirstName='".$_POST['FirstName']."', LastName='".$_POST['LastName']."', DateOfBirth='$dateOfBirth', Gender='".$_POST['Gender']."', Notes='".$_POST['Notes']."', Measurements='$measurements', ViewMode='$viewMode', Language='en' where RunnerID='".$edit['RunnerID']."'";
		} else {
			$query = "update $mysqlTableRunners set Password='".$password."', FirstName='".$_POST['FirstName']."', LastName='".$_POST['LastName']."', DateOfBirth='$dateOfBirth', Gender='".$_POST['Gender']."', Notes='".$_POST['Notes']."', Measurements='$measurements', ViewMode='$viewMode', Language='en' where RunnerID='".$edit['RunnerID']."'";
		}
		$result = mysql_query($query) or die(mysql_error());

		//after data has been input into the database, show this message for a brief period of time and then close the window
		echo "<html><head><meta http-equiv=\"refresh\" content=\"3; url=javascript:window.close()\"></head><body><div class=\"inputconfirm\">You have successfully edited <b>{$edit['RunnerID']}</b>'s data.</div></body></html>";

	}
} else {

//the form below is first shown when the window is opened, or in other words, before submit is clicked. it is an empty form.
?>

<div class="content">
<p class="header">Settings for <?php echo $user ?></p>

<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<table border="0">

<tr><td class="right">Username:</td>
<td class="left"><?php echo $user ?></td></tr>

<tr><td class="left" colspan="2">Leave empty to keep your current password.</td></tr>
<tr><td class="right">Password:</td>
<td class="left"><input type="password" name="Password" size="20" maxlength="40" value="" class="form"></td></tr>

<tr><td class="right">Retype Password:</td>
<td class="left"><input type="password" name="RetypePassword" size="20" maxlength="40" value="" class="form"></td></tr>
<tr><td>&nbsp;</td></tr>

<tr><td class="right">First Name:</td>
<td class="left"><input type="text" name="FirstName" size="20" maxlength="30" value="<?php echo stripslashes($edit['FirstName'])?>" class="form"></td></tr>

<tr><td class="right">Last Name:</td>
<td class="left"><input type="text" name="LastName" size="20" maxlength="30" value="<?php echo stripslashes($edit['LastName'])?>" class="form"></td></tr>

<?php
//reformat date date from YYYY-MM-DD into array(YYYY, MMM, DD)
$dateofbirth = explode("-", $edit['DateOfBirth']);
?>
<tr><td class="right">Date of Birth:</td>
<td class="left">
<select name="BirthDay" class="form">
<option value="<?php echo $dateofbirth['2']?>"><?php echo $dateofbirth['2']?></option>
<?php
generateDays();
?>
</select>

<select name="BirthMonth" class="form">
<option value="<?php echo $dateofbirth['1']?>"><?php echo date("F", mktime(0, 0, 0, $dateofbirth['1']+1, 0, 0))?></option>
<?php
generateMonths();
?>
</select>

<select name="BirthYear" class="form">
<option value="<?php echo $dateofbirth['0']?>"><?php echo $dateofbirth['0']?></option>
<?php
generateYears();
?>
</select>
</td></tr>

<tr><td class="right">Gender:</td>
<td class="left"><input type="radio" name="Gender" value="F" <?php if ($edit['Gender'] == "F") { echo "checked";}?> class="form">Female<br>
<input type="radio" name="Gender" value="M" <?php if ($edit['Gender'] == "M") { echo "checked";}?> class="form">Male</td></tr>

<?php
//reformat date date from YYYY-MM-DD into array(YYYY, MMM, DD)
$membersince = explode("-", $edit['MemberSince']);
?>
<tr><td class="right">Member Since:</td>
<td class="left"><?php echo date("F", mktime(0, 0, 0, $membersince['1']+1, 0, 0)) . " " .  date("jS", mktime (0, 0, 0, 0, $membersince['2'], 0, 0)) . " " . $membersince['0']?>
</td></tr>

<tr><td class="right">Distance Unit:</td>
<td class="left">
<select name="DistanceUnit" class="form">
<?php
distanceUnits($units['0']);
?>
</select>
</td></tr>

<tr><td class="right">Temperature Unit:</td>
<td class="left">
<select name="TemperatureUnit" class="form">
<?php
temperatureUnits($units['1']);
?>
</select>
</td></tr>

<tr><td class="right">Weight Unit:</td>
<td class="left">
<select name="WeightUnit" class="form">
<?php
weightUnits($units['2']);
?>
</select>
</td></tr>

<tr><td class="right">View Mode:</td>
<td class="left"><input type="radio" name="ViewMode" value="0" <?php if (substr($edit['ViewMode'], 0, 1) == "0") { echo "checked"; }?> class="form">Full<br>
<input type="radio" name="ViewMode" value="1" <?php if (substr($edit['ViewMode'], 0, 1) == "1") { echo "checked"; }?> class="form">Summary</td></tr>

<tr><td class="right">Notes:</td>
<td class="left"><textarea name="Notes" rows="4" cols="30" wrap="virtual" class="form"><?php echo htmlentities($edit['Notes'])?></textarea></td></tr>

<tr><td class="right"></td>
<td class="left"><input type="submit" name="submit" value="Submit" accesskey="s" class="form">&nbsp;<input type="submit" value="Wipe" accesskey="w" class="form"></td></tr>


<tr><td align="right" colspan="2"><a href="javascript:window.close();" title="Close This Window: Alt+C" accesskey="c" class="url"><u>C</u>lose</a></td></tr>

</table>
</form>

</div>

<?php
}
?>

</body>
</html>
Return current item: Run