# Here is a datepicker that I wrote in PHP. Comments welcome !
# It's supposed to give you an endless calender and a link with the
# resulting timestamp when a day is clicked. I might add a time-field
# later. I know the code is not perfect, since I am not :-) If you have
# suggestions, please post them here. I have been searching for other,
# ready-made stuff, but could not find any. So I wrote this myself, since
# I did not want to use any Java etc, only HTML.
# Copy and paste this to a file, name it "datepicker.inc.php" and run it.
# It works as far as I could
<?php
$timestamp = $_GET['timestamp'];
# this reads the feedback if another year or month is selected.
if (empty($timestamp)) {$timestamp = strtotime("now");}
# if nothing is given, select current time/date
getdatepicker($timestamp, "./index.php?action=editphones", 1);
# call the function
function getdatepicker($month_ts, $linkout, $firstwday)
{
# in: ev. timestamp, link to follow if a day is clicked,
# and first week of the day for you (0-5, 0 is Sunday)
$weekarray = array
("Su","Mo","Tu","We","Th","Fr","Sa","Su","Mo","Tu","We","Th","Fr","Sa");
$datum=getdate($month_ts);
$thatday=$datum[mday];
$thatmonth=date("M", $month_ts);
$thatyear=date("Y", $month_ts);
$firstofmonth_ts=strtotime("1 $thatmonth $thatyear", $month_ts);
$numberofdays=date(t, $month_ts);
$firstmonthday=date(w, $firstofmonth_ts);
$output = "$output<Table border=1>\n";
$nextmonth_ts=strtotime("+1 month", $month_ts);
$lastmonth_ts=strtotime("-1 month", $month_ts);
$nextyear_ts=strtotime("+1 year", $month_ts);
$lastyear_ts=strtotime("-1 year", $month_ts);
$output="$output<TR>\n <TD colspan=7>\n <Table width=\"100%\">";
$output="$output<TR><TD align=center>\n<A HREF=\"./datepicker.inc.php?
timestamp=$lastmonth_ts\"><</A>";
$output="$output $thatmonth <A HREF=\"./datepicker.inc.php?timestamp=
$nextmonth_ts\">></A></TD>\n";
$output="$output <TD align=center><A HREF=\"./datepicker.inc.php?
timestamp=$lastyear_ts\"><</A>";
$output="$output $thatyear <A HREF=\"./datepicker.inc.php?timestamp=
$nextyear_ts\">></A></TD></TR>";
$output="$output </Table>\n</TD></TR>\n\n";
$output="$output<TR>\n";
for ($x=$firstwday;$x<=($firstwday+6);$x++)
{$output = "$output<TD align=center><B>$weekarray[$x]</B></TD>\n";}
$output="$output</TR>\n\n<TR>";
$firstweek=true;
for($x=0;$x<$numberofdays;$x++)
# iterate through all days of the month
{
$day_ts=strtotime("+$x day",$firstofmonth_ts);
$weekday=date("w", $day_ts);
$day=date("j", $day_ts);
if ($firstweek==true) {$firstweekgap=$t;}
if ($weekday==$firstwday)
#first day of the week new line start
{
if ($firstweek==true) {$output2 = "$output2</TR>\n\n";}
$firstweek=false;
$t=0; # set first day of week
$output2 = "$output2<TR>\n";
}
$t++;
$output2="$output2 <TD align=center><A HREF=\"$linkout?timestamp=
$day_ts\" target=\"tree\">$day</A></TD>\n";
if ($t==7)
#last day of the week display
{$output2="$output2</TR>\n\n";}
}
$gap=7-$firstweekgap;
if (($gap>0) AND ($gap<7))
{$output="$output\n<TD colspan=\"$gap\"></TD>\n$output2";}
else
{$output="$output$output2";}
$output="$output</TR></Table>\n";
echo $output;
}
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php