Location: PHPKode > projects > PortalXP - Teacher Edition > PortalXP/PortalXP/admin/addcalendar.php
<?php

	require ("config.php");
	$database = mysql_connect($hostname, $user, $password);
	mysql_select_db(portalxp, $database);

	$lastday = 1;
	while (checkdate($month,$lastday,$year))
	{
		$lastday++;
	}

if (isset($submit)) {

			{
				mysql_query("DELETE FROM $mysql_tablename WHERE id = '$id'");
				ereg_replace("<br>", "", $description);
			}
			$description = nl2br($description);
			$description = addslashes($description);
			$subject = addslashes($subject);

			$temp = mysql_query("INSERT INTO $mysql_tablename (stamp, subject, description) VALUES ('$year-$month-$day $time', '$subject', '$description')");
			if ($temp != 0)
				echo "Item added ...";
			else
			{
				echo "Item may not have been added ...";
				echo mysql_error();
			}


} else {

			echo "Adding item to calendar";
			$query = mysql_query("SELECT max(id) as id FROM $mysql_tablename");
			if ($query)
			{
				$result = mysql_fetch_array($query);
				$result["id"]++;
			}
			else
			{
				$result["id"] = 0;
			}
			echo "<form method=post action=<?php echo $PHP_SELF?>>
				<input type=hidden name=id value=$result[id]>
				<table>
				<tr>	<td><b>Username</td>";

			if ( !$REMOTE_USER )
			{
				echo "<td><input type=text name=username size=20></td></tr>";
			}
			else
			{
				echo "<td>$REMOTE_USER<input type=hidden name=username value='$REMOTE_USER'></td></tr>";
			}
			
			echo "	<tr><td><b>Day</td>
					<td><select name=day size=1>";
			for ($i=1; $i<$lastday; $i++)
			{
				if ($i == $day)
					echo "<option value=$i selected>$i</option>";
				else    
					echo "<option value=$i>$i</option>";
			}
			echo "</select><select size=1 name=month>";
			for ($i=1; $i<13; $i++)
			{
				$nm = date("F", mktime(0,0,0,$i,1,$year));
				if ($i == $month)
					echo "<option value=$i selected>$nm</option>";
				else
					echo "<option value=$i>$nm</option>";
			}
			echo "</select><select size=1 name=year>";
			for ($i=$year-2; $i<$year+5; $i++)
			{
				if ($i == $year)
					echo "<option value=$i selected>$i</option>";
				else
					echo "<option value=$i>$i</option>";
			}
			echo "</select></td></tr>
					<tr><td><b>Time (hh:mm:ss)</td>
					<td><input type=text name=time></td></tr>
					<tr><td><b>Subject (255 chars max)</td>
					<td><input type=text name=subject></td></tr>
					<tr><td><b>Description</td>
					<td><textarea wrap=virtual rows=5 cols=50 name=description></textarea></td></tr>
				</table>
				<input type=hidden name=action value=Addsucker>
				<input type=submit value=\"Submit item\">
				</form>";


			
}

	echo "<p><form method=get action=welcome.php><input type=submit value='Back to Calendar'>
		<input type=hidden name=month value=$month><input type=hidden name=year value=$year></form>";
?>
Return current item: PortalXP - Teacher Edition