
Archives

|
';
/* table headings */
$headings = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$calendar.= '| '.implode(' | ',$headings).' | ';
/* days and weeks vars now ... */
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
/* row for week one */
$calendar.= '';
/* print "blank" days until the first of the current week */
for($x = 0; $x < $running_day; $x++):
$calendar.= '| | ';
$days_in_this_week++;
endfor;
$levents = "";
if ($handle = opendir("cal/events/")) {
// List all the files
while (false !== ($file = readdir($handle))) {
$filename = explode(".",$file);
$name = $filename[0];
$ext = $filename[1];
If ($ext==$filetype) { $levents .= $name . "#####";}
}
closedir($handle);
}
$eeevents = explode("#####",$levents);
asort($eeevents);
if ($month<10) {$month = "0".$month;}
for($xx = 0; $xx < count($eeevents)-1; $xx++){
$file = getcwd()."/cal/events/".$eeevents[$xx].".".$filetype;
$fh1 = fopen($file, 'r');
$data = fread($fh1, filesize($file));
fclose($fh1);
$indiv_events = explode(":::::",$data);
$e_id = $indiv_events[0];
$e_date = explode(",",$indiv_events[1]);
$eventdates .= $eeevents[$xx] . "," .$indiv_events[1]. "," .$indiv_events[2] . "=====";
}
$eventdatess = explode("=====",$eventdates);
for($list_day = 1; $list_day <= $days_in_month; $list_day++):
//if ($list_day<9) {$list_day = "0".$list_day;}
$calendar.= '';
/* add in the day number */
$calendar.= ' '.$list_day.' ';
if ($list_day<9) {$caldate = $year."-".$month."-0".$list_day;}
else {$caldate = $year."-".$month."-".$list_day;}
$caldatee = date("Y-m-d", strtotime( $caldate ) );
$ggg=0;
$time = array();
$date = array();
$file = array();
for($ccc = 0; $ccc < count($eventdatess)-1; $ccc++){
$eventdatesss = explode(",",$eventdatess[$ccc]);
for($cccc = 0; $cccc < count($eventdatesss); $cccc++){
If ($caldatee==$eventdatesss[$cccc]) {
$time[$ggg] = $eventdatesss[2];
$date[$ggg] = $eventdatesss[1];
$file[$ggg] = $eventdatesss[0];
$ggg++;
}
}
}
asort($time);
for($ccc = 0; $ccc < count($time); $ccc++){
$file11 = getcwd()."/cal/events/".$file[$ccc].".".$filetype;
$fh11 = fopen($file11, 'r');
$data11 = fread($fh11, filesize($file11));
fclose($fh11);
$eventt = explode(":::::",$data11);
if ($eventt[2]=="ALL DAY") {
$calendar.= "".ucwords($eventt[3])." ";
$calendar.= "
";
} else {
$calendar.= "".ucwords($eventt[3])." ";
$calendar.= date("g:i a", strtotime($eventt[2]));
$calendar.= "
";
}
}
//$calendar.= str_repeat('
',1);
/* END EVENTS*/
$calendar.= ' | ';
if($running_day == 6):
$calendar.= ' ';
if(($day_counter+1) != $days_in_month):
$calendar.= '';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
endfor;
/* finish the rest of the days in the week */
if($days_in_this_week < 8):
for($x = 1; $x <= (8 - $days_in_this_week); $x++):
$calendar.= '| | ';
endfor;
endif;
/* final row */
$calendar.= ' ';
/* end the table */
$calendar.= ' ';
/* all done, return result */
return $calendar;
}
echo " ";
/* sample usages */
$thismonth = date(m);
$thisyear = date(Y);
If ($_GET['y']!=$thisyear or $_GET['y']==0) {$y=$_GET['y'];$yy=$_GET['y'];} else {$y = $thisyear;$yy = $thisyear;}
$months = array('January','Febuary','March','April','May','June','July','August','September','October','November','December');
echo " ";
if (!isset($_GET['m'])) {
$m=date(m);
$mm=date(m)-1;
$mmm=date(m)+1;
$y=date(Y);$yy=date(Y);
if (date(m)==01) { $mm=12; $y=$y-1; }
if (date(m)==12) { $mmm=01;$yy=$yy+1; }
echo "
".date(F)." " .$thisyear. " 
| ";
echo draw_calendar(date(n),date(Y),$filetype);
}
else {
$mm=$_GET['m']-1;
$mmm=$_GET['m']+1;
if ($_GET['m']==01) { $mm=12; $y=$y-1; }
if ($_GET['m']==12) { $mmm=01;$yy=$yy+1; }
echo "
".$months[$_GET['m']-1]." " .$_GET['y']. " 
| |