File: /home/awaldron/www/archive/5a_orig/calendar_edit.php
<?php
error_reporting(0);
if (phpversion() >= "4.2.0") {
extract($HTTP_POST_VARS);
extract($HTTP_GET_VARS);
}
require("_header.php");
$testdays = array("sun", "mon", "tue", "wed", "thu", "fri", "sat");
$mon_array = array("", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
$lmon_array = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
//////////////////////////////////////////////////////////////////////////////////////
function login() {
echo "<form action=\"calendar_edit.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"1\">\n";
echo "<P><table border=0>\n";
echo "<tr><td class=\"text\" align=\"right\"><b>Username:</b></td><td class=\"text\"><input type=\"text\" name=\"username\" size=20 maxlength=10></td></tr>\n";
echo "<tr><td class=\"text\" align=\"right\"><b>Password:</b></td><td class=\"text\"><input type=\"password\" name=\"password\" size=20 maxlength=10></td></tr>\n";
echo "</table>\n";
echo "<input type=\"submit\" value=\"Login\">\n";
echo "</form>\n";
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
function prompt_for_date() {
echo "<center><P><img src=\"images/t_calendar.gif\">\n";
echo "<form action=\"calendar_edit.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"2\">\n";
echo "<P><b>Please select the date you'd like to edit:</b>\n";
echo "<P><table border=0>\n";
echo " <tr><td class=\"text\">Month</td><td class=\"text\">Day</td><td class=\"text\">Year</td></tr>\n";
echo " <tr><td><select name=\"mmm\">\n";
echo " <option value=\"jan\">January</option>\n";
echo " <option value=\"feb\">February</option>\n";
echo " <option value=\"mar\">March</option>\n";
echo " <option value=\"apr\">April</option>\n";
echo " <option value=\"may\">May</option>\n";
echo " <option value=\"jun\">June</option>\n";
echo " <option value=\"jul\">July</option>\n";
echo " <option value=\"aug\">August</option>\n";
echo " <option value=\"sep\">September</option>\n";
echo " <option value=\"oct\">October</option>\n";
echo " <option value=\"nov\">November</option>\n";
echo " <option value=\"dec\">December</option>\n";
echo " </select>\n";
echo " </td>\n";
echo " <td><select name=\"dd\">\n";
for ($i=1; $i<=31; $i++)
{ echo " <option value=\"" . $i . "\">" . $i . "</option>\n"; }
echo " </select>\n";
echo " </td>\n";
echo " <td><select name=\"yyyy\">\n";
for ($j=2006; $j<=2010; $j++)
{ echo " <option value=\"" . $j . "\">" . $j . "</option>\n"; }
echo " </select>\n";
echo " </td></tr></table>\n";
echo "<P><input type=\"submit\" value=\"Get Date\"></form>\n";
} // END function prompt_for_date
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
function print_edit_form($mon, $day, $year, $dj1, $dj2, $dj3) {
echo "<center><P><img src=\"images/t_calendar.gif\">\n";
echo "<form action=\"calendar_edit.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"3\">\n";
echo "<input type=\"hidden\" name=\"mmm\" value=\"$mon\">\n";
echo "<input type=\"hidden\" name=\"dd\" value=\"$day\">\n";
echo "<input type=\"hidden\" name=\"yyyy\" value=\"$year\">\n";
$print_mon = ucfirst($mon);
echo "<P><b><u>$print_mon $day, $year</u></b>\n";
echo "<P><b>Please Note:</b>\n";
echo "<br>-- It is now okay to print \"<b>:</b>\" in the calendar --\n";
echo "<br>-- Use <b><BR></b> to break to a new line --\n";
echo "<P><b>Please make the necessary edits:</b>\n";
echo "<P><b>Dan:</b> <input type=\"text\" name=\"dan\" size=\"50\" maxlength=\"32\" value=\"$dj1\">\n";
echo "<P><b>Kevin:</b> <input type=\"text\" name=\"kev\" size=\"50\" maxlength=\"32\" value=\"$dj2\">\n";
echo "<P><b>Joe:</b> <input type=\"text\" name=\"joe\" size=\"50\" maxlength=\"32\" value=\"$dj3\">\n";
echo "<P><input type=\"submit\" value=\"Submit Changes\"></form>\n";
} // END function print_edit_form
//////////////////////////////////////////////////////////////////////////////////////
if ($stage == 1) {
if ($username == "dkoch" && $password == "flowers41") {
prompt_for_date();
} else {
echo "<center><P><img src=\"images/t_availability.gif\">\n";
echo "<P><b>Username and/or Password is incorrect, please try again:</b>\n";
login();
}
}
else if ($stage == 2) { // prompt user with update form
$datapath = "cgi-bin/calendar2/" . $yyyy . "/" . $mmm . ".dat";
$dates = file($datapath);
for ($k=0; $k<=count($dates); $k++) {
$line = explode("|||", $dates[$k]);
if ($line[0] == $dd) {
$dan = $line[1];
$kev = $line[2];
$joe = $line[3];
}
}
print_edit_form($mmm, $dd, $yyyy, $dan, $kev, $joe);
}
else if ($stage == 3) { // write the new data to the calendar file
$dan = stripslashes($dan);
$kev = stripslashes($kev);
$joe = stripslashes($joe);
$datapath = "cgi-bin/calendar2/" . $yyyy . "/" . $mmm . ".dat";
$dates = file($datapath);
$fp = fopen($datapath, "w");
for ($k=0; $k<count($dates); $k++) {
ltrim(chop($dates[k]));
$line = explode("|||", $dates[$k]);
if ($line[0] == $dd) {
$newline = $dd . "|||" . $dan . "|||" . $kev . "|||" . $joe . "\n";
fwrite($fp, $newline);
} else {
$newline = $line[0] . "|||" . $line[1] . "|||" . $line[2] . "|||" . $line[3];
fwrite($fp, $newline);
}
}
fclose($fp);
echo "<center><b>Updated Successfully</b></center>\n";
prompt_for_date();
}
else { // executed when user first enters the system
echo "<center><P><img src=\"images/t_calendar.gif\">\n";
login();
}
require("_footer.php");
?>