Dear All The calendar will be used to see when something is booked and you can assign messages to it as well which the general user cannot see. In this respects I have created 2 pages - welcome .php for the general viewer and admin_welcome for the updating of the calendar.
What I would like to do is to be able to enter multiple dates in at the same time - either saying from a start date for so many days or from a start date to an end date. After spending hours looking at the code and in this forum I cannot seem to get it right - basically I cannot do it. I was wondering if someone could have a look and tell me where I am going wrong. (scripts at bottom of page) ng at www.matrix-hosting.co.uk/prestige/welcome.php for the general view and www.matrix-hosting.co.uk/prestige/admin_welcome.php for the admin side. Any help would be appreciated Ray P.S. if any one also knows how to get it to display a 2 or 3 months at a time or even a year this would also be a bonus as I have tried to do this as well. The Scipts: mySQL Database File CREATE TABLE tablename ( id int(11) DEFAULT '0' NOT NULL auto_increment, username varchar(255), stamp datetime, subject varchar(255), description blob, PRIMARY KEY (id) ); welcome.php (this is what the end user sees) <? $mysql_hostname = 'localhost'; $mysql_username = ''; $mysql_password = ''; $mysql_database = ''; $mysql_tablename = ''; $currentday = date("j", time()); $currentmonth = date("m", time()); $currentyear = date("Y", time()); $lastday = 1; $database = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); if (!$month) { $month = date("m", time()); $year = date("Y", time()); } mysql_select_db($mysql_database, $database); echo "<center><font face=Arial size=2><b>"; echo date('F', mktime(0,0,0,$month,1,$year)); 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>"; 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=175 cellpadding=1 cellspacing=1 border=1>"; echo "<tr><td width=25><font size=2><b>Sun</b></font></td><td width=25><font size=2><b>Mon</b></font></td> <td width=25><font size=2><b>Tue</b></font></td><td width=25><font size=2><b>Wed</b></font></td> <td width=25><font size=2><b>Thu</b></font></td><td width=25><font size=2><b>Fri</b></font></td> <td width=25><font size=2><b>Sat</b></font></td></b></font></tr>"; for ($i=0; $i<7; $i++) { if ($i < $firstday) { echo "<td></td>"; } else { $thisday = ($i+1)-$firstday; if ($currentyear > $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else if ($currentmonth > $month && $currentyear == $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else if ($currentmonth == $month && $currentday > $thisday && $currentyear == $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else { echo "<td valign=top align=center bgcolor=white>"; } echo "<font size=2><b>$thisday</b></font><br> <font size=3>"; $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 "<font color=red><b>$results[subject]</b></font>"; } } if (mysql_num_rows($query2) < 4) { for ($j=0; $j<(4-mysql_num_rows($query2)); $j++) echo ""; } 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 valign=top align=center bgcolor=dddddd>"; } else if ($currentmonth > $month && $currentyear == $year) { echo "<td valign=top bgcolor=dddddd>"; } else if ($currentmonth == $month && $currentday > $nextday && $currentyear == $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else { echo "<td valign=top align=center bgcolor=white>"; } echo "<font size=2><b>$nextday</b></font><br> <font size=3>"; $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 "<font color=red><b>$results2[subject]</b></font>"; } else if ($i < 4) { echo ""; } } echo "</td>"; $nextday++; } } echo "</tr>\n"; } echo "</table><font size=3>"; ?> admin_welcome.php (this is what the admin uses) <? $mysql_hostname = 'localhost'; $mysql_username = ''; $mysql_password = ''; $mysql_database = ''; $mysql_tablename = ''; $currentday = date("j", time()); $currentmonth = date("m", time()); $currentyear = date("Y", time()); $lastday = 1; $database = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); if (!$month) { $month = date("m", time()); $year = date("Y", time()); } mysql_select_db($mysql_database, $database); echo "<center><font face=Arial size=2><b>"; echo date('F', mktime(0,0,0,$month,1,$year)); 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=admin_welcome.php><input type=submit value='<<'> <input type=hidden name=month value=$lastmonth> <input type=hidden name=year value=$lastyear></form></td>"; echo "<td><form method=post action=admin_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=175 cellpadding=1 cellspacing=1 border=1>"; echo "<tr><td width=25><font size=2><b>Sun</b></font></td><td width=25><font size=2><b>Mon</b></font></td> <td width=25><font size=2><b>Tue</b></font></td><td width=25><font size=2><b>Wed</b></font></td> <td width=25><font size=2><b>Thu</b></font></td><td width=25><font size=2><b>Fri</b></font></td> <td width=25><font size=2><b>Sat</b></font></td></tr>"; for ($i=0; $i<7; $i++) { if ($i < $firstday) { echo "<td></td>"; } else { $thisday = ($i+1)-$firstday; if ($currentyear > $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else if ($currentmonth > $month && $currentyear == $year) { echo "<td valign=top bgcolor=dddddd>"; } else if ($currentmonth == $month && $currentday > $thisday && $currentyear == $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else { echo "<td valign=top align=center bgcolor=white>"; } echo "<font size=2><b><a href=display.php?day=$thisday&month=$month&year=$year>$thisday</a></b></font ><br> <font size=3>"; $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 "<font color=red><b>$results[subject]</b></font>"; } } if (mysql_num_rows($query2) < 4) { for ($j=0; $j<(4-mysql_num_rows($query2)); $j++) echo ""; } 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 valign=top align=center bgcolor=dddddd>"; } else if ($currentmonth > $month && $currentyear == $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else if ($currentmonth == $month && $currentday > $nextday && $currentyear == $year) { echo "<td valign=top align=center bgcolor=dddddd>"; } else { echo "<td valign=top align=center bgcolor=white>"; } echo "<font size=2><b><a href=display.php?day=$nextday&month=$month&year=$year>$nextday</a></b></font ><br> <font size=3>"; $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 "<font color=red><b>$results2[subject]</b></font>"; } else if ($i < 4) { echo ""; } } echo "</td>"; $nextday++; } } echo "</tr>\n"; } echo "</table><font size=3>"; echo "<table><tr>"; 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>"; ?> operate.php (this is the page to add / delete etc) <? $mysql_hostname = 'localhost'; $mysql_username = ''; $mysql_password = ''; $mysql_database = ''; $mysql_tablename = ''; $database = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $database); $lastday = 1; while (checkdate($month,$lastday,$year)) { $lastday++; } switch ($action) { case "Delete marked": if (!$id) { echo "<p>You can't delete nothing from the table."; break; } echo "We are about to delete id $id from $mysql_tablename<p>"; $query = mysql_query("SELECT username FROM $mysql_tablename WHERE id = $id"); $row = mysql_fetch_array($query); if ( !$REMOTE_USER ) { mysql_query("DELETE FROM $mysql_tablename WHERE id = '$id'"); echo "Item Deleted"; } else { if ( strcmp($row[username], $REMOTE_USER) == 0 ) { mysql_query("DELETE FROM $mysql_tablename WHERE id = '$id'"); echo "Item Deleted"; } else { echo "You aren't the original user, you can't delete this"; } } break; case "Modify marked": if (!$id) { echo "<p>You can't modify nothing."; break; } echo "We are about to modify id $id from $mysql_tablename"; $query = mysql_query("SELECT *, RIGHT(stamp, 8) AS thetime, SUBSTRING(stamp FROM 9 FOR 2) AS theday FROM $mysql_tablename WHERE id = '$id'"); $row = mysql_fetch_array($query); $row[description] = ereg_replace("<br>", "", $row[description]); echo "<form method=post action=operate.php> <input type=hidden name=id value='$row[id]'> <table> <tr> <td><b>Username</td>"; if ( !$REMOTE_USER ) { echo "<td><input type=text name=username size=20 value='$row[username]'></td></tr>"; } else { if ( strcmp($REMOTE_USER, $row[username]) == 0) { echo "<td>$REMOTE_USER<input type=hidden name=username value='$REMOTE_USER'></td></tr>"; } else { echo "<td>Since you are not the original user, you can't change this</td></tr> </table></form>"; break; } } echo " <tr> <td><b>Day</td> <td><select name=day size=1>"; for ($i=1; $i<$lastday; $i++) { if ($i == $row[theday]) 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></tr> <tr><td><b>Time (hh:mm:ss)</td> <td><input type=text name=time value='$row[thetime]'></td></tr> <tr><td><b>Subject (255 chars max)</td> <td><input type=text name=subject value=\"$row[subject]\"></td></tr> <tr><td><b>Description</td> <td><textarea wrap=virtual rows=5 cols=50 name=description>$row[description]</textarea></td></tr> </table> <input type=hidden name=action value=Addsucker> <input type=hidden name=modify value=Modify> <input type=submit value=\"Submit item\"> </form>"; break; case "Add item to calendar": 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=operate.php> <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; $i<$year+10; $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>Booked</td> <td><input type=radio name=subject value=X checked></td></tr> <tr><td><b>Internal Notes</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>"; break; case "Addsucker": if ($modify) { 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 (username, stamp, subject, description) VALUES ('$username', '$year-$month-$day $time', '$subject', '$description')"); if ($temp != 0) echo "Item added ..."; else { echo "Item may not have been added ..."; echo mysql_error(); } break; } echo "<p><form method=get action=admin_welcome.php><input type=submit value='Back to Admin Calendar'> <input type=hidden name=month value=$month><input type=hidden name=year value=$year></form>"; echo "<p><form method=get action=welcome.php><input type=submit value='Back to User Calendar'> <input type=hidden name=month value=$month><input type=hidden name=year value=$year></form>"; ?> modify.php (the modify page when you click on the dates in the admin calendar) <? $mysql_hostname = 'localhost'; $mysql_username = ''; $mysql_password = ''; $mysql_database = ''; $mysql_tablename = ''; $tablename = date('Fy', mktime(0,0,0,$month,1,$year)); $monthname = date('F', mktime(0,0,0,$month,1,$year)); echo "<font face=Arial size=2><b><center>$day $monthname $year</center></b><p>"; echo "<font size=3>"; $database = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $database); $query = mysql_query("SELECT * FROM $mysql_tablename WHERE stamp >= \"$year-$month-$day 00:00:00\" AND stamp <= \"$year-$month-$day 23:59:59\" ORDER BY stamp", $database); echo "<form method=post action=operate.php> <table cellpadding=1 cellspacing=1 border=1 width=80%> <tr><td><font size=2><b>Select</b></font></td><td><font size=2><b>Username</b></font></b></font></td><td><font size=2><b>Time</b></font></td><td><font size=2><b>Subject</b></font></td> <td><b>Description</td></tr>"; while ($row = mysql_fetch_array($query)) { $i++; echo "<tr><td><input type=radio name=id value=$row[id]></td> <td><font size=2><b>$row[username]</b></font></td><td><font color=red size=2><b>$row[stamp]</b></font></td> <td><font size=2><b>$row[subject]</b></font></td><td><font size=2><b>$row[description]</b></font></td></tr>"; } echo "</table><p> <input type=hidden name=day value=$day> <input type=hidden name=month value=$month> <input type=hidden name=year value=$year> <input type=submit name=action value=\"Delete marked\"> <input type=submit name=action value=\"Modify marked\"> </form>"; ?> display.php (the display page for modifying) <? $mysql_hostname = 'localhost'; $mysql_username = ''; $mysql_password = ''; $mysql_database = ''; $mysql_tablename = ''; $monthname = date('F', mktime(0,0,0,$month,1,$year)); echo "<font face=Arial size=2><b><center>$day $monthname $year</b><p>"; $database = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $database); $lastseconds = mktime(0,0,0,$month,$day,$year)-(24*60*60); $lastday = date('j', $lastseconds); $lastmonth = date('m', $lastseconds); $lastyear = date('Y', $lastseconds); $nextseconds = mktime(0,0,0,$month,$day,$year)+(24*60*60); $nextday = date('j', $nextseconds); $nextmonth = date('m', $nextseconds); $nextyear = date('Y', $nextseconds); $query = mysql_query("SELECT * FROM $mysql_tablename WHERE stamp >= \"$year-$month-$day 00:00:00\" AND stamp <= \"$year-$month-$day 23:59:59\" ORDER BY stamp", $database); while ($row = mysql_fetch_array($query)) { echo " <table cellpadding=1 cellspacing=1 border=1> <tr><td><font size=2><b>Poster</b></font></td><td><font size=2><b>Time</b></font></td><td><font size=2><b>Subject</b></font></td></tr> <tr><td><font size=2><b>$row[username]</b></font></a></td> <td><font color=red size=2><b>$row[stamp]</b></font></td> <td><font size=2><b>$row[subject]</b></font></td></tr> <tr><td colspan=3><font size=2><b>$row[description]</b></font></td></tr></table><p>"; } echo "<center><table><tr>"; echo "<td><form method=post action=display.php><input type=submit value='<<'> <input type=hidden name=day value=$lastday> <input type=hidden name=month value=$lastmonth> <input type=hidden name=year value=$lastyear></form></td>"; echo " <td><form method=post action=operate.php> <input type=hidden name=month value=$month> <input type=hidden name=year value=$year> <input type=hidden name=day value=$day> <input type=submit name='action' value='Add item to calendar'> </form></td> <td><form method=post action=modify.php> <input type=hidden name=month value=$month> <input type=hidden name=day value=$day> <input type=hidden name=year value=$year> <input type=submit value='Delete or Modify'> </form></td> <td><form method=post action=admin_welcome.php> <input type=submit value='Return to Admin Calendar'> <input type=hidden name=day value=$day> <input type=hidden name=month value=$month> <input type=hidden name=year value=$year> </form> </td> "; echo "<td><form method=post action=display.php><input type=submit value='>>'> <input type=hidden name=day value=$nextday> <input type=hidden name=month value=$nextmonth> <input type=hidden name=year value=$nextyear></form></td></tr></table>"; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php