mischien een stomme vraag, maar in onderstaan script wil ik de achtergrond kleur veranderen alleen als ik dat doe verandert alleen de achtrgrond van de tabel en niet die van de pagina. het gaat om onderstaand scriptje
<?php
// alter these variables to alter the color
$headerColor = "#CCCCCC";
$bgColor = "#999999";
$borderColor = "#EEEEE0";
$filledColor = "#CC9900";
// alter this to alter size as percentage of screen
$calSize = "40%";
session_register ("log");
define ("DEBUG_ON", true);
//debugging function
function DebugDie ( $file ,$line, $msg = "")
{
if (DEBUG_ON)
die ("Error file : $file, line : $line $msg<br>\n");
else
die ("Failed to run script");
}
//controls the logic for loggin in
// displays the login form if not correctly logged in
function login ()
{
global $user, $password, $log;
if ( !isset ($log) )
{
if ($user && $password)
{
if (check_login($user, $password))
{
$log["logged_in"] = TRUE;
$log["user"] = $user;
}
else
{
echo "<center><FONT COLOR = 'red'>Invalid log in</FONT?></center>
<br>
\n";
show_login_form();
exit();
}
}
else
{
show_login_form();
exit();
}
}
}
?>
<?php
//----------------------------------------------------------------
// displays form for log in
function show_login_form()
{
global $PHP_SELF;
global $yearSelect, $monthSelect, $daySelect, $textEntry, $bgColor ;
echo "<form action = '$PHP_SELF' method = 'post'>\n";
echo "<table bgcolor='$bgColor' align = center>\n";
echo " <tr>";
echo " <td align = 'center' colspan = '2'>";
echo "<b>Calendar Login</b>";
echo "</td></tr>\n";
echo "<tr>\n";
echo " <td>Name</td>\n";
echo " <td><input type ='text' name = 'user' value = '' maxlength='6'><br></td>\n";
echo " </tr>";
echo " <tr>";
echo " <td>Password</td>\n";
echo " <td><input type ='password' name = 'password' value = '' maxlength='6'></td>\n";
echo " </tr>";
echo " <tr>";
echo "<input type = 'hidden' name = 'yearSelect', value = '$yearSelect'>\n";
echo "<input type = 'hidden' name = 'monthSelect', value = '$monthSelect'>\n";
echo "<input type = 'hidden' name = 'daySelect', value = '$daySelect'>\n";
echo "<input type = 'hidden' name = 'textEntry' value = '".stripslashes($textEntry)."'>\n";
echo " <td align = 'center' colspan = '2' ><input type ='submit' name='user_id' value ='Log in'></td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
}
// change the values of "demo" to whatever you want the user name
// and password to be
//-------------------------------------------------------------------
function check_login ($nm, $pw)
{
if ($nm == "demo" && $pw == "demo")
{
$check = TRUE;
}
else
{
$check = FALSE;
}
return $check;
}
//--------------------------------------------------------
class MyCalendar
{
var $daysInMonth = array
(1=>31,
2=>28,
3=>31,
4=>30,
5=>31,
6=>30,
7=>31,
8=>31,
9=>30,
10=>31,
11=>30,
12=>31);
var $monthName = array
(1=>"January",
2=>"February",
3=>"March",
4=>"April",
5=>"May",
6=>"June",
7=>"July",
8=>"August",
9=>"September",
10=>"October",
11=>"November",
12=>"December");
//-----------------------------------------------------------------------------
function isLeap($yr)
{
return date("L", mktime(0,0,0,1,1,$yr));
}
//-----------------------------------------------------------------------------
// Given the month and year returns the number of days in the month
function getDaysInMonth ($yr, $mn)
{
$mn = intval ($mn);
$yr = intval ($yr);
if ($this->isLeap($yr) && $mn == 2)
return 29;
return $this->daysInMonth[$mn];
}
//-----------------------------------------------------------------------------
// This function accepts values for month and year and returns an array
// of 2 time stamps representing first and last day of month
function getDateRange ($mn, $yr)
{
$mn = intval ($mn);
$yr = intval ($yr);
$last = $this->getDaysInMonth ($yr, $mn);
$start = mktime (0,0,0, $mn,1, $yr);
$end = mktime (0,0,0, $mn,$last, $yr);
$start = date ("Y-m-d", $start);
$end = date ("Y-m-d", $end);
return array ($start, $end );
}
//-----------------------------------------------------------------------------
function getFirstDayInMonth ($yr, $mn)
{
$mn = intval ($mn);
$yr = intval ($yr);
return date("w", mktime(0,0,0,$mn,1,$yr));
}
//-----------------------------------------------------------------------------
function getMonthName ($mn)
{
$mn = intval ($mn);
return $this->monthName[$mn];
}
//-----------------------------------------------------------------------------
function getCurrentMonth()
{
return intval(Date('m'));
}
//-----------------------------------------------------------------------------
function getCurrentYear ()
{
return intval(Date("Y"));
}
//-----------------------------------------
function month_events($yr, $mn)
{
$f_array = array();
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
if ((!file_exists("caldata$yr$mn.inc"))|| (!filesize ("caldata$yr$mn.inc")))
{
echo "<center>No events listed for this month<br>\n";
return;
}
$f_array = file ("caldata$yr$mn.inc") or DebugDie (__FILE__, __LINE__, "Failed to open file for reading caldata$yr$mn.inc");
sort ($f_array);
if (count($f_array) ==0 )
{
echo "<center>No events listed for this month</center><br>\n";
return;
}
echo "<table border='1' width = '80%' cellpadding='4' align='center' bgcolor='#dddddd' bordercolor='#996699'>\n";
for ($row = 0; $row < count ($f_array); $row++)
{
echo "<tr>\n";
echo "<td width = '20%'>\n";
echo substr ($f_array[$row], 0, 10);
echo "</td>\n";
echo "<td>\n";
$retStr = substr ($f_array[$row], 11, strlen ($f_array[$row]) -10);
echo chunk_split ($retStr, 60,"<br>");
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
//-----------------------------------------------------------------------------
//gets the entries in the calendar for the given month and year
// returns an array of days that have entries in the calendar
function getEntryArray($yr, $mn)
{
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
$entryArray = array();
if ((!file_exists("caldata$yr$mn.inc")) || (!filesize("caldata$yr$mn.inc")))
{
return $entryArray;
}
$start_end_dates = $this->getDateRange ($mn, $yr);
$fp = fopen ("caldata$yr$mn.inc", "r") or DebugDie (__FILE__, __LINE__);
flock ($fp, 1);
while (!feof($fp))
{
$str = fgets ($fp, 1024);
if (strlen ($str) > 10)
{
$date_entry = substr ($str, 0, 10);
if ($date_entry >= $start_end_dates[0] && $date_entry <=$start_end_dates[1]);
$day = explode ("-",$date_entry);
array_push($entryArray, $day[2]);
}
}
flock ($fp, 3);
fclose ($fp);
clearstatcache();
return $entryArray;
}
//-----------------------------------------------------------------------------
// gets event for particular day from the file
function showUserDayEvent($yr, $mn, $day)
{
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
if (strlen ($day) <2)
{
$day = "0".$day;
}
if ( (!filesize ("caldata$yr$mn.inc"))|| (!file_exists("caldata$yr$mn.inc")))
{
return "";
}
$retStr = "";
$dtstr = $yr."-".$mn."-".$day;
$fp = fopen ("caldata$yr$mn.inc", "r") or DebugDie (__FILE__, __LINE__,"Failed to open file for reading, caldata$yr$mn.inc");;
flock ($fp,1);
while (!feof($fp))
{
$str = fgets ($fp, 1024);
if (strlen ($str) > 10)
{
$date_entry = substr ($str, 0, 10);
if (!strcmp ($date_entry, $dtstr))
{
$retStr = substr ($str, 11, strlen ($str) -10);
}
}
}
flock ($fp,3);
fclose($fp);
clearstatcache();
return str_replace("<br>", "\r\n", $retStr);
}
//----------------------------------------------------------------------------
// update entry by a particular user
// put all entries in an array
// if the date in the file == date of $txt then
// replace entry otherwise add to array and rewrite array to file
function update_entry ($yr, $mn, $day, $txt)
{
$txt = stripslashes ("$txt");
$f_array = array();
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
if (strlen ($day) <2)
{
$day = "0".$day;
}
$dtstr = $yr."-".$mn."-".$day;
// if first entry need to create file if entry is not all spaces
if ((!file_exists("caldata$yr$mn.inc"))|| (!filesize ("caldata$yr$mn.inc")))
{
if (!strlen (trim ($txt)))
{
return;
}
else
{
$fp = fopen ("caldata$yr$mn.inc", "w");
flock ($fp,1);
$temp = $dtstr." ".$txt;
$temp = str_replace("\r\n", "<br>", trim ($temp));
fputs ($fp, $temp."\n");
flock ($fp,3);
fclose ($fp);
clearstatcache();
return;
}
}
$f_array = file ("caldata$yr$mn.inc") or DebugDie (__FILE__, __LINE__, "Failed to open file for reading caldata$yr$mn.inc");
$found = false;
for ($j = 0; $j< count ($f_array); $j++)
{
$date_entry = substr ($f_array[$j], 0, 10);
if (!strcmp ( $date_entry , $dtstr))
{
$found = true;
$f_array[$j] = $date_entry." ".$txt;
}
}
if (!$found)
{
array_push ($f_array, $dtstr." ".$txt);
}
$fp = fopen ("caldata$yr$mn.inc", "w") or DebugDie (__FILE__, __LINE__, "Failed to open file for writing");
flock ($fp,1);
for ($line = 0; $line < count ($f_array); $line++)
{
if (strlen (trim ($f_array[$line])) >10)
{
$temp = str_replace("\r\n", "<br>", trim ($f_array[$line]));
fputs ($fp ,$temp."\n");
}
}
flock ($fp,3);
fclose ($fp);
clearstatcache();
}
//-----------------------------------------------------------------------------
// Draws the calander table
function drawTable ($yr, $mn)
{
global $PHP_SELF, $headerColor, $bgColor, $borderColor, $filledColor, $calSize;
$entries = $this->getDaysInMonth ($yr, $mn);
$firstSq = $this->getFirstDayInMonth ($yr, $mn);
$daysArray = $this->getEntryArray($yr, $mn);
echo "<div align='center'>";
echo "<table width = '$calSize' border='1' cellspacing='4' align='center' bgcolor='$headerColor' bordercolor='$borderColor'>\n";
echo "<tr>\n";
echo "<td width = '14%'><b>Sun</b></td>\n<td width = '14%'><b>Mon</b></td>\n<td width = '14%'><b>Tue</b></td>\n<td width = '14%'><b>Wed</b></td>\n<td width = '14%'><b>Thu</b></td>\n<td width = '14%'><b>Fri</b></td>\n<td width = '14%'><b>Sat</b></td>\n";
echo "</tr>\n";
// some of the first sqaures may be blank i.e if month doesn't
// start on Sunday. so use $count to determine if square is blank
$count = 0 - $firstSq ;
for ($r=0; $r<6; $r++)
{
echo "<tr>\n";
for ($c=0; $c<7; $c++)
{
$count++;
if ($count < 1 || $count > $entries)
{
echo " <td bgcolor= '$bgColor' width = '14%'><center>-</center></td>\n";
continue;
}
else if (!in_array ($count, $daysArray))
{
echo "<td bgcolor= '$bgColor' width = '14%'>\n<center>";
}
else
{
echo "<td bgcolor='$filledColor' width = '14%'>\n<center>";
}
echo "<a href = '$PHP_SELF?daySelect=$count&monthSelect=$mn&yearSelect=$yr'>$count</a>";
echo "</center>\n</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
\n";
echo "</div>";
}
function display_cal ()
{
global $monthSelect,$yearSelect;
// if year and month not selected give default
if (!$monthSelect)
{
$monthSelect=$this->getCurrentMonth();
}
if (!$yearSelect)
{
$yearSelect=$this->getCurrentYear();
}
$this->drawSelectionBox($yearSelect,$monthSelect);
$this->drawTable ($yearSelect,$monthSelect);
}
//----------------------------------------------------------------
// draws the month and year selection boxes and the calendar table
function drawSelectionBox ($yearSelect,$monthSelect)
{
global $PHP_SELF;
// output the form to select month and year
echo "<form method='post' action='$PHP_SELF'>";
echo "<div align='center'>";
// draw a select box for months. Set the default value shown to the one previously
// selected e.g if user selects April then submits, the select box will
// default to April for selected value
echo "<select name='monthSelect'>";
for ($m = 1; $m<13; $m++)
{
$str = "<option value=$m";
if ($m == $monthSelect)
{
$str = $str." selected>".$this->getMonthName($m)."</option>";
}
else
{
$str = $str.">".$this->getMonthName($m)."</option>";
}
echo $str."\n";
}
echo " </select>";
// draw a select box for years.
echo "<select name='yearSelect'>";
for ($yr = 2001; $yr<2004; $yr++)
{
$str = "<option value=$yr";
if ($yr == $yearSelect)
{
$str = $str." selected>".$yr."</option>";
}
else
{
$str = $str.">".$yr."</option>";
}
echo $str."\n";
}
echo "</select>";
echo "<input type='submit' name='drawCal' value='Change'>";
echo "</div>";
echo "</form>\n";
echo "<center><a href = $PHP_SELF?month_events='1'&yearSelect=$yearSelect&monthSelect=$monthSelect>month event view</a></center>\n";
}
//----------------------------------------------------------------
//
function display_edit_form()
{
global $PHP_SELF, $monthSelect, $yearSelect, $daySelect , $log, $bgColor;
echo "<div align = 'center'>\n";
echo "<form action = '$PHP_SELF' method = 'post'>\n";
echo "<table border = '1' bgcolor='$bgColor'>\n";
//display selected date
$mn_nm = $this->getMonthName ($monthSelect);
echo "<tr><td>$mn_nm $daySelect $yearSelect</td></tr>\n";
$textEntry = ($this->showUserDayEvent($yearSelect, $monthSelect, $daySelect));
echo "<tr><td><textarea name='textEntry' cols='40' rows='5'>".stripslashes($textEntry)."</textarea></td></tr>\n";
echo "<input type = 'hidden' name = 'yearSelect', value = '$yearSelect'>\n";
echo "<input type = 'hidden' name = 'monthSelect', value = '$monthSelect'>\n";
echo "<input type = 'hidden' name = 'daySelect', value = '$daySelect'>\n";
echo "<tr><td><input type='submit' name='editEntry' value='add/edit'></tr></td>\n";
echo "</table>\n";
echo "</form>\n";
echo "</div>\n";
}
}// end calendar class
//--------------------------------------------------------------
//instantiate calendar
if (!isset($c))
{
$c = new MyCalendar();
}
if (isset($drawCal))
{
$c->display_cal ();
// $c->month_events($yearSelect, $monthSelect);
}
// if updating entry from entry form then check logged in and update entry
else if (isset($editEntry) || isset($user_id) )
{
login ();
$c->update_entry($yearSelect, $monthSelect, $daySelect, $textEntry);
$c->display_cal ();
$c->display_edit_form ();
}
//they have just selected a day href
else if (isset($daySelect) && !isset($editEntry) && !isset($drawCal))
{
$c->display_cal ();
$c->display_edit_form ();
}
else if (isset ($month_events))
{
$c->drawSelectionBox($yearSelect, $monthSelect);
$c->month_events($yearSelect, $monthSelect);
}
else
{
$c->display_cal ();
}
<?php
// alter these variables to alter the color
$headerColor = "#CCCCCC";
$bgColor = "#999999";
$borderColor = "#EEEEE0";
$filledColor = "#CC9900";
// alter this to alter size as percentage of screen
$calSize = "40%";
session_register ("log");
define ("DEBUG_ON", true);
//debugging function
function DebugDie ( $file ,$line, $msg = "")
{
if (DEBUG_ON)
die ("Error file : $file, line : $line $msg<br>\n");
else
die ("Failed to run script");
}
//controls the logic for loggin in
// displays the login form if not correctly logged in
function login ()
{
global $user, $password, $log;
if ( !isset ($log) )
{
if ($user && $password)
{
if (check_login($user, $password))
{
$log["logged_in"] = TRUE;
$log["user"] = $user;
}
else
{
echo "<center><FONT COLOR = 'red'>Invalid log in</FONT?></center>
<br>
\n";
show_login_form();
exit();
}
}
else
{
show_login_form();
exit();
}
}
}
?>
<?php
//----------------------------------------------------------------
// displays form for log in
function show_login_form()
{
global $PHP_SELF;
global $yearSelect, $monthSelect, $daySelect, $textEntry, $bgColor ;
echo "<form action = '$PHP_SELF' method = 'post'>\n";
echo "<table bgcolor='$bgColor' align = center>\n";
echo " <tr>";
echo " <td align = 'center' colspan = '2'>";
echo "<b>Calendar Login</b>";
echo "</td></tr>\n";
echo "<tr>\n";
echo " <td>Name</td>\n";
echo " <td><input type ='text' name = 'user' value = '' maxlength='6'><br></td>\n";
echo " </tr>";
echo " <tr>";
echo " <td>Password</td>\n";
echo " <td><input type ='password' name = 'password' value = '' maxlength='6'></td>\n";
echo " </tr>";
echo " <tr>";
echo "<input type = 'hidden' name = 'yearSelect', value = '$yearSelect'>\n";
echo "<input type = 'hidden' name = 'monthSelect', value = '$monthSelect'>\n";
echo "<input type = 'hidden' name = 'daySelect', value = '$daySelect'>\n";
echo "<input type = 'hidden' name = 'textEntry' value = '".stripslashes($textEntry)."'>\n";
echo " <td align = 'center' colspan = '2' ><input type ='submit' name='user_id' value ='Log in'></td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
}
// change the values of "demo" to whatever you want the user name
// and password to be
//-------------------------------------------------------------------
function check_login ($nm, $pw)
{
if ($nm == "demo" && $pw == "demo")
{
$check = TRUE;
}
else
{
$check = FALSE;
}
return $check;
}
//--------------------------------------------------------
class MyCalendar
{
var $daysInMonth = array
(1=>31,
2=>28,
3=>31,
4=>30,
5=>31,
6=>30,
7=>31,
8=>31,
9=>30,
10=>31,
11=>30,
12=>31);
var $monthName = array
(1=>"January",
2=>"February",
3=>"March",
4=>"April",
5=>"May",
6=>"June",
7=>"July",
8=>"August",
9=>"September",
10=>"October",
11=>"November",
12=>"December");
//-----------------------------------------------------------------------------
function isLeap($yr)
{
return date("L", mktime(0,0,0,1,1,$yr));
}
//-----------------------------------------------------------------------------
// Given the month and year returns the number of days in the month
function getDaysInMonth ($yr, $mn)
{
$mn = intval ($mn);
$yr = intval ($yr);
if ($this->isLeap($yr) && $mn == 2)
return 29;
return $this->daysInMonth[$mn];
}
//-----------------------------------------------------------------------------
// This function accepts values for month and year and returns an array
// of 2 time stamps representing first and last day of month
function getDateRange ($mn, $yr)
{
$mn = intval ($mn);
$yr = intval ($yr);
$last = $this->getDaysInMonth ($yr, $mn);
$start = mktime (0,0,0, $mn,1, $yr);
$end = mktime (0,0,0, $mn,$last, $yr);
$start = date ("Y-m-d", $start);
$end = date ("Y-m-d", $end);
return array ($start, $end );
}
//-----------------------------------------------------------------------------
function getFirstDayInMonth ($yr, $mn)
{
$mn = intval ($mn);
$yr = intval ($yr);
return date("w", mktime(0,0,0,$mn,1,$yr));
}
//-----------------------------------------------------------------------------
function getMonthName ($mn)
{
$mn = intval ($mn);
return $this->monthName[$mn];
}
//-----------------------------------------------------------------------------
function getCurrentMonth()
{
return intval(Date('m'));
}
//-----------------------------------------------------------------------------
function getCurrentYear ()
{
return intval(Date("Y"));
}
//-----------------------------------------
function month_events($yr, $mn)
{
$f_array = array();
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
if ((!file_exists("caldata$yr$mn.inc"))|| (!filesize ("caldata$yr$mn.inc")))
{
echo "<center>No events listed for this month<br>\n";
return;
}
$f_array = file ("caldata$yr$mn.inc") or DebugDie (__FILE__, __LINE__, "Failed to open file for reading caldata$yr$mn.inc");
sort ($f_array);
if (count($f_array) ==0 )
{
echo "<center>No events listed for this month</center><br>\n";
return;
}
echo "<table border='1' width = '80%' cellpadding='4' align='center' bgcolor='#dddddd' bordercolor='#996699'>\n";
for ($row = 0; $row < count ($f_array); $row++)
{
echo "<tr>\n";
echo "<td width = '20%'>\n";
echo substr ($f_array[$row], 0, 10);
echo "</td>\n";
echo "<td>\n";
$retStr = substr ($f_array[$row], 11, strlen ($f_array[$row]) -10);
echo chunk_split ($retStr, 60,"<br>");
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
//-----------------------------------------------------------------------------
//gets the entries in the calendar for the given month and year
// returns an array of days that have entries in the calendar
function getEntryArray($yr, $mn)
{
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
$entryArray = array();
if ((!file_exists("caldata$yr$mn.inc")) || (!filesize("caldata$yr$mn.inc")))
{
return $entryArray;
}
$start_end_dates = $this->getDateRange ($mn, $yr);
$fp = fopen ("caldata$yr$mn.inc", "r") or DebugDie (__FILE__, __LINE__);
flock ($fp, 1);
while (!feof($fp))
{
$str = fgets ($fp, 1024);
if (strlen ($str) > 10)
{
$date_entry = substr ($str, 0, 10);
if ($date_entry >= $start_end_dates[0] && $date_entry <=$start_end_dates[1]);
$day = explode ("-",$date_entry);
array_push($entryArray, $day[2]);
}
}
flock ($fp, 3);
fclose ($fp);
clearstatcache();
return $entryArray;
}
//-----------------------------------------------------------------------------
// gets event for particular day from the file
function showUserDayEvent($yr, $mn, $day)
{
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
if (strlen ($day) <2)
{
$day = "0".$day;
}
if ( (!filesize ("caldata$yr$mn.inc"))|| (!file_exists("caldata$yr$mn.inc")))
{
return "";
}
$retStr = "";
$dtstr = $yr."-".$mn."-".$day;
$fp = fopen ("caldata$yr$mn.inc", "r") or DebugDie (__FILE__, __LINE__,"Failed to open file for reading, caldata$yr$mn.inc");;
flock ($fp,1);
while (!feof($fp))
{
$str = fgets ($fp, 1024);
if (strlen ($str) > 10)
{
$date_entry = substr ($str, 0, 10);
if (!strcmp ($date_entry, $dtstr))
{
$retStr = substr ($str, 11, strlen ($str) -10);
}
}
}
flock ($fp,3);
fclose($fp);
clearstatcache();
return str_replace("<br>", "\r\n", $retStr);
}
//----------------------------------------------------------------------------
// update entry by a particular user
// put all entries in an array
// if the date in the file == date of $txt then
// replace entry otherwise add to array and rewrite array to file
function update_entry ($yr, $mn, $day, $txt)
{
$txt = stripslashes ("$txt");
$f_array = array();
if (strlen ($mn) <2)
{
$mn = "0".$mn;
}
if (strlen ($day) <2)
{
$day = "0".$day;
}
$dtstr = $yr."-".$mn."-".$day;
// if first entry need to create file if entry is not all spaces
if ((!file_exists("caldata$yr$mn.inc"))|| (!filesize ("caldata$yr$mn.inc")))
{
if (!strlen (trim ($txt)))
{
return;
}
else
{
$fp = fopen ("caldata$yr$mn.inc", "w");
flock ($fp,1);
$temp = $dtstr." ".$txt;
$temp = str_replace("\r\n", "<br>", trim ($temp));
fputs ($fp, $temp."\n");
flock ($fp,3);
fclose ($fp);
clearstatcache();
return;
}
}
$f_array = file ("caldata$yr$mn.inc") or DebugDie (__FILE__, __LINE__, "Failed to open file for reading caldata$yr$mn.inc");
$found = false;
for ($j = 0; $j< count ($f_array); $j++)
{
$date_entry = substr ($f_array[$j], 0, 10);
if (!strcmp ( $date_entry , $dtstr))
{
$found = true;
$f_array[$j] = $date_entry." ".$txt;
}
}
if (!$found)
{
array_push ($f_array, $dtstr." ".$txt);
}
$fp = fopen ("caldata$yr$mn.inc", "w") or DebugDie (__FILE__, __LINE__, "Failed to open file for writing");
flock ($fp,1);
for ($line = 0; $line < count ($f_array); $line++)
{
if (strlen (trim ($f_array[$line])) >10)
{
$temp = str_replace("\r\n", "<br>", trim ($f_array[$line]));
fputs ($fp ,$temp."\n");
}
}
flock ($fp,3);
fclose ($fp);
clearstatcache();
}
//-----------------------------------------------------------------------------
// Draws the calander table
function drawTable ($yr, $mn)
{
global $PHP_SELF, $headerColor, $bgColor, $borderColor, $filledColor, $calSize;
$entries = $this->getDaysInMonth ($yr, $mn);
$firstSq = $this->getFirstDayInMonth ($yr, $mn);
$daysArray = $this->getEntryArray($yr, $mn);
echo "<div align='center'>";
echo "<table width = '$calSize' border='1' cellspacing='4' align='center' bgcolor='$headerColor' bordercolor='$borderColor'>\n";
echo "<tr>\n";
echo "<td width = '14%'><b>Sun</b></td>\n<td width = '14%'><b>Mon</b></td>\n<td width = '14%'><b>Tue</b></td>\n<td width = '14%'><b>Wed</b></td>\n<td width = '14%'><b>Thu</b></td>\n<td width = '14%'><b>Fri</b></td>\n<td width = '14%'><b>Sat</b></td>\n";
echo "</tr>\n";
// some of the first sqaures may be blank i.e if month doesn't
// start on Sunday. so use $count to determine if square is blank
$count = 0 - $firstSq ;
for ($r=0; $r<6; $r++)
{
echo "<tr>\n";
for ($c=0; $c<7; $c++)
{
$count++;
if ($count < 1 || $count > $entries)
{
echo " <td bgcolor= '$bgColor' width = '14%'><center>-</center></td>\n";
continue;
}
else if (!in_array ($count, $daysArray))
{
echo "<td bgcolor= '$bgColor' width = '14%'>\n<center>";
}
else
{
echo "<td bgcolor='$filledColor' width = '14%'>\n<center>";
}
echo "<a href = '$PHP_SELF?daySelect=$count&monthSelect=$mn&yearSelect=$yr'>$count</a>";
echo "</center>\n</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
\n";
echo "</div>";
}
function display_cal ()
{
global $monthSelect,$yearSelect;
// if year and month not selected give default
if (!$monthSelect)
{
$monthSelect=$this->getCurrentMonth();
}
if (!$yearSelect)
{
$yearSelect=$this->getCurrentYear();
}
$this->drawSelectionBox($yearSelect,$monthSelect);
$this->drawTable ($yearSelect,$monthSelect);
}
//----------------------------------------------------------------
// draws the month and year selection boxes and the calendar table
function drawSelectionBox ($yearSelect,$monthSelect)
{
global $PHP_SELF;
// output the form to select month and year
echo "<form method='post' action='$PHP_SELF'>";
echo "<div align='center'>";
// draw a select box for months. Set the default value shown to the one previously
// selected e.g if user selects April then submits, the select box will
// default to April for selected value
echo "<select name='monthSelect'>";
for ($m = 1; $m<13; $m++)
{
$str = "<option value=$m";
if ($m == $monthSelect)
{
$str = $str." selected>".$this->getMonthName($m)."</option>";
}
else
{
$str = $str.">".$this->getMonthName($m)."</option>";
}
echo $str."\n";
}
echo " </select>";
// draw a select box for years.
echo "<select name='yearSelect'>";
for ($yr = 2001; $yr<2004; $yr++)
{
$str = "<option value=$yr";
if ($yr == $yearSelect)
{
$str = $str." selected>".$yr."</option>";
}
else
{
$str = $str.">".$yr."</option>";
}
echo $str."\n";
}
echo "</select>";
echo "<input type='submit' name='drawCal' value='Change'>";
echo "</div>";
echo "</form>\n";
echo "<center><a href = $PHP_SELF?month_events='1'&yearSelect=$yearSelect&monthSelect=$monthSelect>month event view</a></center>\n";
}
//----------------------------------------------------------------
//
function display_edit_form()
{
global $PHP_SELF, $monthSelect, $yearSelect, $daySelect , $log, $bgColor;
echo "<div align = 'center'>\n";
echo "<form action = '$PHP_SELF' method = 'post'>\n";
echo "<table border = '1' bgcolor='$bgColor'>\n";
//display selected date
$mn_nm = $this->getMonthName ($monthSelect);
echo "<tr><td>$mn_nm $daySelect $yearSelect</td></tr>\n";
$textEntry = ($this->showUserDayEvent($yearSelect, $monthSelect, $daySelect));
echo "<tr><td><textarea name='textEntry' cols='40' rows='5'>".stripslashes($textEntry)."</textarea></td></tr>\n";
echo "<input type = 'hidden' name = 'yearSelect', value = '$yearSelect'>\n";
echo "<input type = 'hidden' name = 'monthSelect', value = '$monthSelect'>\n";
echo "<input type = 'hidden' name = 'daySelect', value = '$daySelect'>\n";
echo "<tr><td><input type='submit' name='editEntry' value='add/edit'></tr></td>\n";
echo "</table>\n";
echo "</form>\n";
echo "</div>\n";
}
}// end calendar class
//--------------------------------------------------------------
//instantiate calendar
if (!isset($c))
{
$c = new MyCalendar();
}
if (isset($drawCal))
{
$c->display_cal ();
// $c->month_events($yearSelect, $monthSelect);
}
// if updating entry from entry form then check logged in and update entry
else if (isset($editEntry) || isset($user_id) )
{
login ();
$c->update_entry($yearSelect, $monthSelect, $daySelect, $textEntry);
$c->display_cal ();
$c->display_edit_form ();
}
//they have just selected a day href
else if (isset($daySelect) && !isset($editEntry) && !isset($drawCal))
{
$c->display_cal ();
$c->display_edit_form ();
}
else if (isset ($month_events))
{
$c->drawSelectionBox($yearSelect, $monthSelect);
$c->month_events($yearSelect, $monthSelect);
}
else
{
$c->display_cal ();
}