calendar problem please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saranda
Forum Newbie
Posts: 15
Joined: Wed May 10, 2006 6:18 pm

calendar problem please help

Post by saranda »

i have this calendar downloaded but i have the problem of using it


<?php
/*
#= ------------------------
#= Calendar is intended to be used as an include
#= The point at which you include it will cause a calendar to appear with
#= links on the days which generate URLs back to the page calling, with
#= GET parameters in the URL for month, day and year. Your own code should
#= then make use of those parameters.
#=
*/


// day and month name constants
// (change for internationalisation)
$monthnames = Array("January","February","March","April","May","June","July","August","September","October","November","December");
$shortdaynames = Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
$longdaynames = Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

// build some templates
// (change this section to alter the way the calendar looks)
$templates["calendar_section"] = "<!-- Calendar by http://www.pluggedout.com -->\n"
."<style>\n"
.".calendar_heading{font-family:Arial;font-size:11px;font-weight:bold;}\n"
.".calendar_day_heading{font-family:Arial;font-size:11px;}\n"
.".calendar_day_off{font-family:Arial;font-size:11px;}\n"
.".calendar_day_on{font-family:Arial;font-size:11px;}\n"
.".calendar_link{font-family:Arial;fony-size:11px;text-decoration:none;}\n"
."</style>\n"
."<table width='200' border='0' cellspacing='1' cellpadding='2' bgcolor='#dddddd'>\n"
."<tr><td colspan='7' bgcolor='#ffffff'>\n"
." <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>\n"
." <td align='center'><span class='calendar_heading'><a class='calendar_link' href='<!--link_month_prev-->'>&laquo;</a></span></td>\n"
." <td align='center'><span class='calendar_heading'><a class='calendar_link' href='<!--link_month_current-->'><!--month_name-->&nbsp;<!--year--></a></span></td>\n"
." <td align='center'><span class='calendar_heading'><a class='calendar_link' href='<!--link_month_next-->'>&raquo;</a></span></td>\n"
." </tr></table>\n"
."</td></tr>\n"
."<tr>\n<!--calendar_day_headings--></tr>\n"
."<tr>\n<!--calendar_days--></tr>\n"
."</table>\n";
$templates["calendar_day_heading"] = "<td width='12%' class='calendar_day_heading' align='center'><!--day--></td>\n";
$templates["calendar_day_empty"] = "<td bgcolor='#ffffff' align='center'><span class='calendar_day'>&nbsp;</span></td>\n";
$templates["calendar_day_on"] = "<td align='center' class='calendar_day_on' bgcolor='#eeeeee'><!--day--></td>";
$templates["calendar_day_off"] = "<td align='center' class='calendar_day_off'><!--day--></td>";
$templates["calendar_sep"] = "</tr>\n<tr>";


// DO NOT CHANGE THE CALENDAR FUNCTION (BELOW) UNLESS YOU REALLY HAVE TO

// Function : html_calendar
// Description : Returns the html to represent the calendar.
// Arguments : $month - Month of the year (01 to 12)
// $year - Year (yyyy)
// Returns : html data
// Author : Jonathan Beckett
// Last Change : 2005-02-12
function html_calendar($month,$year) {

// validate data
if ($month==""){
// if we have no month, make it THIS month
$month = date("n");
}

if ($year==""){
// if we have no year, make it THIS year
$year = date("Y");
}


global $templates;
global $monthnames;
global $shortdaynames;

define ('ADAY', (60*60*24));

// make arrays of values representing the first of the month
$datearray = getdate(mktime(0,0,0,$month,1,$year));
$start = mktime(0,0,0,$month,1,$year);

$firstdayarray = getdate($start);

// work out the URLs for previous and next buttons
// default
$prev_month = $month - 1;
$prev_year = $year;
$next_month = $month + 1;
$next_year = $year;

// handle exceptions
// end of year
if ($month==12) {
$prev_month = $month - 1;
$prev_year = $year;
$next_month = 1;
$next_year = $year + 1;
}
// start of year
if ($month==1) {
$prev_month = 12;
$prev_year = $year - 1;
$next_month = $month + 1;
$next_year = $year;
}
$url_next = $_SERVER["PHP_SELF"]."?month=".$next_month."&year=".$next_year;
$url_prev = $_SERVER["PHP_SELF"]."?month=".$prev_month."&year=".$prev_year;


// get template for entire calendar area
$html = $templates["calendar_section"];

// do the replacements
$html = str_replace("<!--link_month_prev-->",$url_prev,$html);
$html = str_replace("<!--link_month_current-->",$_SERVER["PHP_SELF"]."?year=".$year."&month=".$month,$html);
$html = str_replace("<!--link_month_next-->",$url_next,$html);

$html = str_replace("<!--month_name-->",$datearray["month"],$html);
$html = str_replace("<!--year-->",$year,$html);

// get templates for various squares
$t_day_heading = $templates["calendar_day_heading"];
$t_day_empty = $templates["calendar_day_empty"];
$t_day_on = $templates["calendar_day_on"];
$t_day_off = $templates["calendar_day_off"];
$t_calendar_sep = $templates["calendar_sep"];

foreach($shortdaynames as $day)
{
$day_heading = $t_day_heading;
$day_heading = str_replace("<!--day-->",$day,$day_heading);
$day_headings .= $day_heading;
}

$html = str_replace("<!--calendar_day_headings-->",$day_headings,$html);

// Create the rows of days
for( $count=0;$count<(6*7);$count++)
{
$dayarray = getdate($start);
if((($count) % 7) == 0) {
if($dayarray['mon'] != $datearray['mon']) break;
$html_days .= $t_calendar_sep;
}

if($count < $firstdayarray['wday'] || $dayarray['mon'] != $month) {

$html_days .= $t_day_empty;

} else {

// build the html for a day within the calendar
$date_url = $_SERVER["PHP_SELF"]."?year=".$dayarray["year"]."&month=".$dayarray["mon"]."&day=".$dayarray["mday"];
$html_day = $t_day_on;
$html_day = str_replace("<!--day-->","<a class='calendar_link' href='".$date_url."'>".$dayarray[mday]."</a>",$html_day);

$html_days .= $html_day;

$start += ADAY;

// check that day has moved on (to solve the daylight savings problem)
$testday = getdate($start);
if ($testday["yday"]==$dayarray["yday"]){
$start += (ADAY/2);
}
}
}

// put the days into the calendar
$html = str_replace("<!--calendar_days-->",$html_days,$html);

return $html;
}


// example use (you could strip this out and include the calendar script elsewhere

print html_calendar($_GET["month"],$_GET["year"]);

?>



when starting it i recive this errors..



Notice: Undefined index: month in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 204

Notice: Undefined index: year in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 204

Notice: Undefined variable: day_headings in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 158

Notice: Undefined variable: html_days in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 169

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181

Notice: Use of undefined constant mday - assumed 'mday' in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpAE.tmp on line 181
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

change your error reporting level, or fix all the warnings, warning are caused by using variable concentration on variables that have not been defined or declared. Also the code is not written very well, it does to many things that it doesn't need to do and it does those things in a very unorthodox way...

Last Note...

When posting please put code inside PHP tags, it makes it easier to read.

yj!
saranda
Forum Newbie
Posts: 15
Joined: Wed May 10, 2006 6:18 pm

Post by saranda »

can you tell me how to fix this thing cause i am a beginer in php and i need this calendar very much ...

pls help...
saranda
Forum Newbie
Posts: 15
Joined: Wed May 10, 2006 6:18 pm

Post by saranda »

<?
I have fixed somthing but i am still geting som error in script .. now i am onli reciving this..

Notice: Undefined index: month in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpB5.tmp on line 204

Notice: Undefined index: year in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpB5.tmp on line 204

Notice: Undefined variable: day_headings in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpB5.tmp on line 158

Notice: Undefined variable: html_days in C:\Documents and Settings\kujtim\Desktop\Te ndryshme\calendar\New Folder\calendar\calendar\phpB5.tmp on line 169


/*
#= Copyright (c) 2004 Jonathan Beckett
#= You are free to use and modify this script as long as this header
#= section stays intact. This file is part of the Calendar project.
#=
#= This program is free software; you can redistribute it and/or modify
#= it under the terms of the GNU General Public License as published by
#= the Free Software Foundation; either version 2 of the License, or
#= (at your option) any later version.
#=
#= This program is distributed in the hope that it will be useful,
#= but WITHOUT ANY WARRANTY; without even the implied warranty of
#= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#= GNU General Public License for more details.
#=
#= You should have received a copy of the GNU General Public License
#= along with CMS files; if not, write to the Free Software
#= Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#===========================================================================
#=
#= Example Usage Guidelines
#= ------------------------
#= Calendar is intended to be used as an include
#= The point at which you include it will cause a calendar to appear with
#= links on the days which generate URLs back to the page calling, with
#= GET parameters in the URL for month, day and year. Your own code should
#= then make use of those parameters.
#=
*/


// day and month name constants
// (change for internationalisation)
$monthnames = Array("January","February","March","April","May","June","July","August","September","October","November","December");
$shortdaynames = Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
$longdaynames = Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

// build some templates
// (change this section to alter the way the calendar looks)
$templates["calendar_section"] = "<!-- Calendar by http://www.pluggedout.com -->\n"
."<style>\n"
.".calendar_heading{font-family:Arial;font-size:11px;font-weight:bold;}\n"
.".calendar_day_heading{font-family:Arial;font-size:11px;}\n"
.".calendar_day_off{font-family:Arial;font-size:11px;}\n"
.".calendar_day_on{font-family:Arial;font-size:11px;}\n"
.".calendar_link{font-family:Arial;fony-size:11px;text-decoration:none;}\n"
."</style>\n"
."<table width='200' border='0' cellspacing='1' cellpadding='2' bgcolor='#dddddd'>\n"
."<tr><td colspan='7' bgcolor='#ffffff'>\n"
." <table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>\n"
." <td align='center'><span class='calendar_heading'><a class='calendar_link' href='<!--link_month_prev-->'>&laquo;</a></span></td>\n"
." <td align='center'><span class='calendar_heading'><a class='calendar_link' href='<!--link_month_current-->'><!--month_name-->&nbsp;<!--year--></a></span></td>\n"
." <td align='center'><span class='calendar_heading'><a class='calendar_link' href='<!--link_month_next-->'>&raquo;</a></span></td>\n"
." </tr></table>\n"
."</td></tr>\n"
."<tr>\n<!--calendar_day_headings--></tr>\n"
."<tr>\n<!--calendar_days--></tr>\n"
."</table>\n";
$templates["calendar_day_heading"] = "<td width='12%' class='calendar_day_heading' align='center'><!--day--></td>\n";
$templates["calendar_day_empty"] = "<td bgcolor='#ffffff' align='center'><span class='calendar_day'>&nbsp;</span></td>\n";
$templates["calendar_day_on"] = "<td align='center' class='calendar_day_on' bgcolor='#eeeeee'><!--day--></td>";
$templates["calendar_day_off"] = "<td align='center' class='calendar_day_off'><!--day--></td>";
$templates["calendar_sep"] = "</tr>\n<tr>";


// DO NOT CHANGE THE CALENDAR FUNCTION (BELOW) UNLESS YOU REALLY HAVE TO

// Function : html_calendar
// Description : Returns the html to represent the calendar.
// Arguments : $month - Month of the year (01 to 12)
// $year - Year (yyyy)
// Returns : html data
// Author : Jonathan Beckett
// Last Change : 2005-02-12
function html_calendar($month,$year) {

// validate data
if ($month==""){
// if we have no month, make it THIS month
$month = date("n");
}

if ($year==""){
// if we have no year, make it THIS year
$year = date("Y");
}


global $templates;
global $monthnames;
global $shortdaynames;

define ('ADAY', (60*60*24));

// make arrays of values representing the first of the month
$datearray = getdate(mktime(0,0,0,$month,1,$year));
$start = mktime(0,0,0,$month,1,$year);

$firstdayarray = getdate($start);

// work out the URLs for previous and next buttons
// default
$prev_month = $month - 1;
$prev_year = $year;
$next_month = $month + 1;
$next_year = $year;

// handle exceptions
// end of year
if ($month==12) {
$prev_month = $month - 1;
$prev_year = $year;
$next_month = 1;
$next_year = $year + 1;
}
// start of year
if ($month==1) {
$prev_month = 12;
$prev_year = $year - 1;
$next_month = $month + 1;
$next_year = $year;
}
$url_next = $_SERVER["PHP_SELF"]."?month=".$next_month."&year=".$next_year;
$url_prev = $_SERVER["PHP_SELF"]."?month=".$prev_month."&year=".$prev_year;


// get template for entire calendar area
$html = $templates["calendar_section"];

// do the replacements
$html = str_replace("<!--link_month_prev-->",$url_prev,$html);
$html = str_replace("<!--link_month_current-->",$_SERVER["PHP_SELF"]."?year=".$year."&month=".$month,$html);
$html = str_replace("<!--link_month_next-->",$url_next,$html);

$html = str_replace("<!--month_name-->",$datearray["month"],$html);
$html = str_replace("<!--year-->",$year,$html);

// get templates for various squares
$t_day_heading = $templates["calendar_day_heading"];
$t_day_empty = $templates["calendar_day_empty"];
$t_day_on = $templates["calendar_day_on"];
$t_day_off = $templates["calendar_day_off"];
$t_calendar_sep = $templates["calendar_sep"];

foreach($shortdaynames as $day)
{
$day_heading = $t_day_heading;
$day_heading = str_replace("<!--day-->",$day,$day_heading);
$day_headings .= $day_heading;
}

$html = str_replace("<!--calendar_day_headings-->",$day_headings,$html);

// Create the rows of days
for( $count=0;$count<(6*7);$count++)
{
$dayarray = getdate($start);
if((($count) % 7) == 0) {
if($dayarray['mon'] != $datearray['mon']) break;
$html_days .= $t_calendar_sep;
}

if($count < $firstdayarray['wday'] || $dayarray['mon'] != $month) {

$html_days .= $t_day_empty;

} else {

// build the html for a day within the calendar
$date_url = $_SERVER["PHP_SELF"]."?year=".$dayarray["year"]."&month=".$dayarray["mon"]."&day=".$dayarray["mday"];
$html_day = $t_day_on;
$html_day = str_replace("<!--day-->","<a class='calendar_link' href='".$date_url."'>".$dayarray['mday']."</a>",$html_day);

$html_days .= $html_day;

$start += ADAY;

// check that day has moved on (to solve the daylight savings problem)
$testday = getdate($start);
if ($testday["yday"]==$dayarray["yday"]){
$start += (ADAY/2);
}
}
}

// put the days into the calendar
$html = str_replace("<!--calendar_days-->",$html_days,$html);

return $html;
}


// example use (you could strip this out and include the calendar script elsewhere

print html_calendar($_GET["month"],$_GET["year"]);

?>
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Code: Select all

<?

$monthnames = array ( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
$shortdaynames = array ( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' );
$longdaynames = array ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );

$templates = array ( 
'calendar_section' => "<!-- Calendar by http://www.pluggedout.com -->
<style>
 .calendar_heading{font-family:Arial;font-size:11px;font-weight:bold;}
 .calendar_day_heading{font-family:Arial;font-size:11px;}
 .calendar_day_off{font-family:Arial;font-size:11px;}
 .calendar_day_on{font-family:Arial;font-size:11px;}
 .calendar_link{font-family:Arial;fony-size:11px;text-decoration:none;}
</style>
  <table width='200' border='0' cellspacing='1' cellpadding='2' bgcolor='#dddddd'>
   <tr>
    <td colspan='7' bgcolor='#ffffff'>
     <table width='100%' border='0' cellspacing='0' cellpadding='0'>
      <tr>
       <td align='center'>
        <span class='calendar_heading'><a class='calendar_link' href='<!--link_month_prev-->'>&laquo;</a></span>
       </td>
       <td align='center'>
        <span class='calendar_heading'><a class='calendar_link' href='<!--link_month_current-->'><!--month_name-->&nbsp;<!--year--></a></span>
       </td> 
       <td align='center'>
        <span class='calendar_heading'><a class='calendar_link' href='<!--link_month_next-->'>&raquo;</a></span>
       </td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <!--calendar_day_headings-->
   </tr>
   <tr>
    <!--calendar_days-->
   </tr>
  </table>", 
'calendar_day_heading' => "<td width='12%' class='calendar_day_heading' align='center'><!--day--></td>", 
'calendar_day_empty' => "<td bgcolor='#ffffff' align='center'><span class='calendar_day'>&nbsp;</span></td>", 
'calendar_day_on' => "<td align='center' class='calendar_day_on' bgcolor='#eeeeee'><!--day--></td>", 
'calendar_day_off' => "<td align='center' class='calendar_day_off'><!--day--></td>", 
'calendar_sep' => "</tr>
<tr>"
);

function html_calendar ( $month, $year )
{
	global $templates;
	global $monthnames;
	global $shortdaynames;

	define ( 'ADAY', ( 60 * 60 * 24 ) );

	$datearray = getdate ( mktime ( 0, 0, 0, $month, 1, $year ) );
	$start = mktime ( 0, 0, 0, $month, 1, $year);

	$firstdayarray = getdate ( $start );

	$prev_month = ( $month == 1 ? 12 : ( $month - 1 ) );

	$prev_year = ( $month == 1 ? ( $year - 1 ) : $year );

	$next_month = ( $month == 12 ? 1 : ( $month + 1 ) );

	$next_year = ( $month == 12 ? ( $year + 1 ) : $year );

	$url_next = $_SERVER['PHP_SELF'] . "?month=" . $next_month . "&year=" . $next_year ; 
	$url_prev = $_SERVER['PHP_SELF'] . "?month=" . $prev_month . "&year=" . $prev_year ; 

	$html = $templates['calendar_section'];

	$old = array ( 
		'<!--link_month_prev-->', 
		'<!--link_month_current-->', 
		'<!--link_month_next-->', 
		'<!--month_name-->', 
		'<!--year-->' 
	);

	$new = array ( 
		$_SERVER['PHP_SELF'] . "?month=" . $prev_month . "&year=" . $prev_year, 
		$_SERVER['PHP_SELF'] . "?year=" . $year . "&month=" . $month, 
		$_SERVER['PHP_SELF'] . "?month=" . $next_month . "&year=" . $next_year, 
		$datearray['month'], 
		$year
	);

	$html = str_replace ( $old, $new, $html );

	$t_day_heading = $templates['calendar_day_heading'];
	$t_day_empty = $templates['calendar_day_empty'];
	$t_day_on = $templates['calendar_day_on'];
	$t_day_off = $templates['calendar_day_off'];
	$t_calendar_sep = $templates['calendar_sep'];

	$day_headings = '';

	foreach($shortdaynames as $day)
	{
		$day_headings .= str_replace ( '<!--day-->', $day, $t_day_heading );
	}

	$html = str_replace ( '<!--calendar_day_headings-->', $day_headings, $html );

	$html_days = '';

	for( $count = 0; $count < 42; $count++ )
	{
		$dayarray = getdate ( $start );

		if ( ( ( $count ) % 7 ) == 0 )
		{
			if ( $dayarray['mon'] != $datearray['mon'] )
			{
				break;
			}

			$html_days .= $t_calendar_sep;
		}

		if ( $count < $firstdayarray['wday'] || $dayarray['mon'] != $month )
		{
			$html_days .= $t_day_empty;
		}
		else
		{
			$date_url = $_SERVER['PHP_SELF'] . "?year=" . $dayarray['year'] . "&month=" . $dayarray['mon'] . "&day=" . $dayarray['mday'];

			$html_days .= str_replace ( '<!--day-->', "<a class='calendar_link' href='" . $date_url . "'>" . $dayarray['mday'] . "</a>", $t_day_on );

			$start += ADAY; 

			$testday = getdate ( $start );

			if ( $testday['yday'] == $dayarray['yday'] )
			{
				$start += ( ADAY / 2 );
			}
		}
	}

	return ( str_replace ( '<!--calendar_days-->', $html_days, $html ) );
}

// min, max years allowed, change to the values you want to use....

$min_year = 2000;
$max_year = 2007;

$i_month = ( ! empty ( $_GET['month'] ) && $_GET['month'] >= 1 && $_GET['month'] <= 12 ? $_GET['month'] : 1 );

$i_year = ( ! empty ( $_GET['year'] ) && $_GET['year'] >= $min_year && $_GET['year'] <= $max_year ? $_GET['year'] : $min_year );

print html_calendar ( $i_month, $i_year );

?>
If you don't know what needs fixing, get a debugger, that can help you find all your problems. If you just use code given to you, you will never learn how to code better. I only spent a few mintues on this, but it should fix all your problems. I would still write it differently, all I did was dump all the code that did nothing, in others words I changed many things!

yj!
saranda
Forum Newbie
Posts: 15
Joined: Wed May 10, 2006 6:18 pm

Post by saranda »

thnx for advice ..... and for help to

but now wen i start te script the calendar starts in the year 2000 and month 1 this doesn't solv my problem..
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

do you know any PHP? just curious..might wanna consider buying a begginers book or if this is mission critical pay someone.either way your URL has to read index.php?year=(insert year)&month=(insert month) in order to show the right year.
Post Reply