Hello,
I downloaded the following calandar script and have embedded it into my schedule.php script. However, I can't seem to figure out how to call it. Any thoughts on which function I should call or how I can go about executing this script within my current php script?
Thanks,
Gary
<?
/* Author: Jason Loretz
j_loretz@yahoo.com
Description: A simple calendar.
License: NONE, Except to include this header.
Editing/Updating Programmers:
Chris Heald - 5/10/01 - cheald45@hotmail.com
Questions/comments welcome!
CHANGE LOG
Change log created - CMH 5/10/01
05/10/01 - CMH
Added 1 pixel transparent GIF to headers for absolute spacing
Added stylesheet to HTML header function
Added "highlight today" functionality
Changed foward and backward buttons to text links
Changed script references so that $PHP_SELF is used rather than a hardcoded script name
Fixed leftover row problem - caused a thick border at the bottom on months that ended on Sat.
Removed "created on" text
Changed "Thurs" to "Thu" and "Tues" to "Tue" for standardization
Changed date() parameters to literals to avoid warnings.
Compacted calendar for inclusion on a page. Size is now approximately 165 pixels wide.
01/08/02 - CMH
Fixed several warnings
Fixed severe issue with table rows on Saturday
Pared down day loop code - more efficient now
*/
// HTML Color Schemes
$header_bgcolor = "#000000";
$header_txtcolor = "#FFFFFF";
$title_bgcolor = "#660000";
$title_txtcolor = "#FFFFFF";
$text_bgcolor = "#FFFFFF";
$text_txtcolor = "#000000";
$date_bgcolor = "#FFFFFF";
$extra_bgcolor = "#CCCCCC";
$weekend_txtcolor = "#996666";
$highlight_today = 1; //1 = yes; 0 = no; - CMH 5/10/01
$today_bgcolor = "#660000"; //background color for today's date - CMH 5/10/01
$today_txtcolor = "#FFFFFF"; //foreground for today's date - CMH 5/10/01
$image_dir = "."; //path to the 1pix.gif picture used for spacing
$image_name = "1pix.gif";
$table_width = 150; //mostly irrevelant now, unless you want a table wider than [(7px * column_width) + borders]
$column_width = 22;
#######################
Program Functions
#######################
// Generate the month text for the numbers (returns a string)
function genMonth_Text($month) {
switch ($month) {
case 1: $month_text = "January"; break;
case 2: $month_text = "February"; break;
case 3: $month_text = "March"; break;
case 4: $month_text = "April"; break;
case 5: $month_text = "May"; break;
case 6: $month_text = "June"; break;
case 7: $month_text = "July"; break;
case 8: $month_text = "August"; break;
case 9: $month_text = "September"; break;
case 10: $month_text = "October"; break;
case 11: $month_text = "November"; break;
case 12: $month_text = "December"; break;
}
return ($month_text);
}
// Set Today's Month (returns numerical value)
function genSet_Month() {
$month = date("m",mktime(0,0,0,1,12,2));
return ($month);
}
// Set Today's Year (returns numerical value)
function genSet_Year() {
$year = date("Y",mktime(0,0,0,1,12,2));
return ($year);
}
// Generate the Stop Value (returns the number of days in the month)
function genSet_Stop($month,$year) {
if ($month == '12') {
$month = 1;
$year++;
} else {
$month++;
}
$stop = mktime(0,0,0,$month,0,$year);
$stop = date("d",$stop);
return ($stop);
}
// Generate the top HTML (returns HTML string)
function genTop_HTML() {
$string = "<html>\n<head>\n\t<title>phpCalendar.php</title>\n</head>\n" .
"<body bgcolor=\"#FFFFFF\">\n" .
"<center>\n" .
"<STYLE>
BODY {font-family:arial;}
TD {font-family:arial;
font-size:7pt;}
A.cal_nav {color:white;
text-decoration:none;}
A.cal_nav:hover {color:white;
text-decoration:underline;}
</STYLE>";
return ($string);
}
// Generate the end HTML (returns HTML string)
function genEnd_HTML() {
$string = "</center>\n" .
"</body>\n</html>";
return ($string);
}
// Generate the table header (returns HTML string)
function genTable_Header($table_width,$header_bgcolor) {
$string = "<table width=\"$table_width\" cellpadding=\"1\" cellspacing=\"0\">" .
"<tr><td bgcolor=\"$header_bgcolor\">\n" .
"<table width=\"$table_width\" cellpadding=\"0\" cellspacing=\"1\" BORDER=0>\n";
return ($string);
}
// Generate the table footer (returns HTML string)
function genTable_Footer() {
$string = "</table></td></tr></table>\n";
return ($string);
}
// Generates the information to be displayed
function genCalendar_Month($month,$year,$stop,
$column_width,$extra_bgcolor,$weekend_txtcolor,$date_bgcolor,
$header_bgcolor,$header_txtcolor,
$title_bgcolor, $title_txtcolor) {
global $PHP_SELF, $today_bgcolor, $today_txtcolor, $highlight_today, $image_dir, $image_name;
if ($month == 12) {
$prev_month = $month - 1;
$prev_year = $year;
$next_month = 1;
$next_year = $year + 1;
} elseif ($month == 1) {
$prev_month = 12;
$prev_year = $year - 1;
$next_month = $month + 1;
$next_year = $year;
} else {
$prev_month = $month - 1;
$prev_year = $year;
$next_month = $month + 1;
$next_year = $year;
}
$start = mktime(0,0,0,$month,1,$year);
$start = date("w",$start);
$month_text = genMonth_Text($month);
$date_string = $month_text . " - " . $year;
$string = "<tr><td colspan=\"1\" bgcolor=\"$header_bgcolor\" align=\"right\" valign=\"center\">\n" .
"<a href=\"$PHP_SELF?month=$prev_month&year=$prev_year&mode=month\" class=\"cal_nav\"><<</a>" .
"</td><td colspan=\"5\" bgcolor=\"$header_bgcolor\" align=\"center\">\n" .
"<font color=\"$header_txtcolor\" size=\"2\"><b>$date_string</b></font>\n" .
"</td><td colspan=\"1\" bgcolor=\"$header_bgcolor\" align=\"left\" valign=\"center\">\n" .
"<a href=\"$PHP_SELF?month=$next_month&year=$next_year&mode=month\" class=\"cal_nav\">>></a>" .
"</td></tr>\n" .
"<tr><td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Sun<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td>\n" .
"<td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Mon<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td>\n" .
"<td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Tue<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td>\n" .
"<td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Wed<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td>\n" .
"<td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Thu<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td>\n" .
"<td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Fri<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td>\n" .
"<td width=\"$column_width\" bgcolor=\"$title_bgcolor\" align=\"center\">" .
"<font color=\"$title_txtcolor\">Sat<IMG border=0 SRC=\"$image_dir/$image_name\" height=1 width=\"$column_width\"></font></td></tr>\n";
$string .= "<tr>";
for ($i = 0; $i < $start; $i++) {
$string .= "<td bgcolor=\"$extra_bgcolor\" align=\"center\"> </td>\n";
}
echo "Start: $start";
$frame = $start - 1; //date("w",$day);
for ($i = 1; $i <= $stop; $i++) {
$day = mktime(0,0,0,date("m",time()),$i,date("Y",time()));
$frame++;
if($frame > 6) {
$string .= "</TR>\n";
if($i < $stop)
$string .= "<TR>";
$frame = 0;
}
if(($month) == date("m",$day) && $year == date("Y",$day) && date("d",$day) == date("d",time()) && $highlight_today == 1) {
$string .= "<td width=\"$column_width\" bgcolor=\"$today_bgcolor\" align=\"center\">" .
"<b><FONT COLOR=\"$today_txtcolor\">$i</FONT></b></td>\n";
continue;
}
if ($frame == 6 || $frame == 0) {
$string .= "<td width=\"$column_width\" bgcolor=\"$date_bgcolor\" align=\"center\">" .
"<font color=\"$weekend_txtcolor\">" .
"<b>$i</b></font></td>";
} else {
$string .= "<td width=\"$column_width\" bgcolor=\"$date_bgcolor\" align=\"center\">" .
"<b>$i</b></td>\n";
}
}
for ($i = 1; $frame < 6; $frame++) {
$string .= "<td bgcolor=\"$extra_bgcolor\" align=\"center\"> </td>\n";
}
if ($frame < 6) { $string .= "</tr>\n"; }
return ($string);
}
######################
Script Execution
######################
print $top_html = genTop_HTML();
print $top_html = genTable_Header($table_width,$header_bgcolor);
if (@!$month) {
$month = genSet_Month();
$year = genSet_Year();
}
$day_number = genSet_Stop($month,$year);
print $mid_html = genCalendar_Month($month,$year,$day_number,
$column_width,$extra_bgcolor,
$weekend_txtcolor,$date_bgcolor,
$header_bgcolor,$header_txtcolor,
$title_bgcolor,$title_txtcolor);
print $end_html = genTable_Footer();
print $end_html = genEnd_HTML();
?>