Location: PHPKode > projects > MyPHPSchool > MyPHPSchool-0.3.1/html/calendar/welcome.php
<?
	include ("../main.inc.php");
	list($ulvl, $loggedin) = check_auth();

//Originaly Based on http://www.goulburn.net.au/~hagus/

/*

10/4/01 - By Geoff:
	saved a few CPU cycles :)
	added some whitespace
	changed some formatting

10/5/01 - By Geoff:
	more formatting, graphics

10/9/01 - by Geoff:
	Fixed lots of formatting and 

*/

	$mysql_tablename = 'calendar';

	$currentday = date("j", time());
	$currentmonth = date("m", time());
	$currentyear = date("Y", time());

	$lastday = 1;

	if(!$month)
	{
		$month = $currentmonth;
		$year = $currentyear;
	}

	$date = date('F', mktime(0,0,0,$month,1,$year));

	print_header("MHS:Calendar:$date $year");

	echo "<center><font face=Arial size=5><b>";
	echo "$date";
	echo " $year<p><font size=3></b><p>";

	$firstday = date( 'w', mktime(0,0,0,$month,1,$year));

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

	if ($nextmonth == 13)
	{
		$nextmonth = 1;
		$nextyear = $year + 1;
	}

	$lastmonth = $month-1;
	$lastyear = $year;

	if ($lastmonth == 0)
	{
		$lastmonth = 12;
		$lastyear = $year-1;
	}

	echo "<table><tr>";
        echo "<td><form method=post action=welcome.php>
		<input type=submit value='<<'>
                <input type=hidden name=month value=$lastmonth>
                <input type=hidden name=year value=$lastyear></form></td>";

	if($ulvl > 30  && $loggedin)
	{
	        echo "<td><form method=post action=operate.php>
		        <input type=submit name=action value=\"Add item to calendar\">
			<input type=hidden name=month value=$month>
			<input type=hidden name=year value=$year>
			</form></td>";
	}

        echo "<td><form method=post action=welcome.php><input type=submit value='>>'>
                <input type=hidden name=month value=$nextmonth> 
                <input type=hidden name=year value=$nextyear></form></td></tr></table>";

	echo "<table width=700 border=1 cellpadding=1 cellspacing=1>
		<tr bgcolor=ccccff>
		<td align=center width=14%><h4>Sunday</h4></td>
		<td align=center width=14%><h4>Monday</h4></td>
		<td align=center width=14%><h4>Tuesday</h4></td>
		<td align=center width=14%><h4>Wednesday</h4></td>
		<td align=center width=14%><h4>Thursday</h4></td>
		<td align=center width=14%><h4>Friday</h4></td>
		<td align=center width=14%><h4>Saturday</h4></td></tr><tr>";

	for ($i=0; $i<7; $i++)
	{
		if ($i < $firstday)
		{
			echo "<td><br></td>";
		}
		else
		{
			$thisday = ($i+1)-$firstday;

			if ($currentyear > $year)
			{
				echo "<td align=left valign=top bgcolor=eeeeff>\n";
			}
			else if ($currentmonth > $month && $currentyear == $year)
			{
				echo "<td align=left valign=top bgcolor=eeeeff>\n";
			}
			else if ($currentmonth == $month && $currentday > $thisday && $currentyear == $year)
			{
				echo "<td align=left valign=top bgcolor=eeeeff>\n";
			}
			else
			{
				echo "<td align=left valign=top bgcolor=ffffff>\n";
			}

			echo "<a href=display.php?day=$thisday&month=$month&year=$year>$thisday</a><br>
				<font size=1>";

			$query2 = mysql_query("SELECT subject FROM $mysql_tablename WHERE stamp >= \"$year-$month-$thisday 00:00:00\" and stamp <= \"$year-$month-$thisday 23:59:59\" ORDER BY stamp");

			for ($j = 0; $j<mysql_num_rows($query2); $j++)
			{
				$results = mysql_fetch_array($query2);

				if ($results["subject"])
				{
					echo "<img height=8 width=8 src='dot.gif'> $results[subject] <br>";
				}
			}

			if (mysql_num_rows($query2) < 4)
			{
				for ($j=0; $j<(4-mysql_num_rows($query2)); $j++)
					echo "<br>";
			}
			echo "</td>";
		}
	}

	echo "</tr>\n";
	$nextday = ($i+1)-$firstday;

	for ($j=0; $j<5; $j++)
	{
		echo "<tr>";

		for ($k = 0; $k<7; $k++)
		{
			if ($nextday < $lastday)
			{
				if ($currentyear > $year)
                                {       
                                        echo "<td align=left valign=top 
bgcolor=eeeeff>";
                                }
				else if ($currentmonth > $month && $currentyear == $year)
                        	{       
                                        echo "<td align=left valign=top 
bgcolor=eeeeff>";
                        	}
                        	else if ($currentmonth == $month && $currentday > $nextday && $currentyear == $year)
                        	{
                                        echo "<td align=left valign=top 
bgcolor=eeeeff>";
                        	}
                        	else    
                        	{
                                        echo "<td align=left valign=top bgcolor=ffffff>";
                        	}

				echo "<a href=display.php?day=$nextday&month=$month&year=$year>$nextday</a><br>
					<font size=1>";

				$query3 = mysql_query("SELECT subject FROM $mysql_tablename WHERE stamp >= \"$year-$month-$nextday 00:00:00\" AND stamp <= \"$year-$month-$nextday 23:59:59\" ORDER BY stamp");

				for ($i = 0; $i<mysql_num_rows($query3)+4; $i++)
				{
					$results2 = mysql_fetch_array($query3);
					if ($results2["subject"])
					{
						echo "<img height=8 width=8 src='dot.gif'> $results2[subject] <br>";
					}
					else if ($i < 4)
					{
						echo "<br>";
					}
				}

				echo "</ul></td>";
				$nextday++;
			}
		}
		echo "</tr>\n";
	}

	echo "</table><font size=3>";

	echo "<table><tr>";
	echo "<td><form method=post action=welcome.php><input type=submit value='<<'>
		<input type=hidden name=month value=$lastmonth>
		<input type=hidden name=year value=$lastyear></form></td>";

	if($ulvl > 30 && $loggedin)
	{
        echo "<td><form method=post action=operate.php>
                <input type=submit name=action value=\"Add item to calendar\">
                <input type=hidden name=month value=$month>
                <input type=hidden name=year value=$year>  
                </form></td>";
	}

	echo "<td><form method=post action=welcome.php><input type=submit value='>>'>
		<input type=hidden name=month value=$nextmonth>
		<input type=hidden name=year value=$nextyear></form></td></tr></table>";

?>

Return current item: MyPHPSchool