VB icon

A Tiny Calendar

Email
Submitted on: 1/1/2015 4:27:00 PM
By: Tristan Couvares (from psc cd)  
Level: Advanced
User Rating: By 6 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 2001
 
     Impress your friends and corporate allies by putting this very tiny yet customizeable calendar somewhere on your page!!! Automagically generates this month's calendar!!! It rocks like a magikist!!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A Tiny Calendar
// Description:Impress your friends and corporate allies by putting this very tiny yet customizeable calendar somewhere on your page!!! Automagically generates this month's calendar!!! It rocks like a magikist!!
// By: Tristan Couvares (from psc cd)
//**************************************

<?php 
 $fontfamily = isset($fontfamily) ? $fontfamily : "Tahoma, Geneva, sans-serif"; 
 $defaultfontcolor = isset($defaultfontcolor) ? $defaultfontcolor : "#000000"; 
 $defaultbgcolor = isset($defaultbgcolor) ? $defaultbgcolor : "#FFFFFF"; 
 $todayfontcolor = isset($todayfontcolor) ? $todayfontcolor : "#FFFFFF"; 
 $todaybgcolor = isset($todaybgcolor) ? $todaybgcolor : "#CC0000"; 
 $monthcolor = isset($monthcolor) ? $monthcolor : "#333399"; 
 $relfontsize = isset($relfontsize) ? $relfontsize : "1"; 
 $cssfontsize = isset($cssfontsize) ? $cssfontsize : "7pt"; 
 $month = (isset($month)) ? $month : date("n",time()); 
 $textmonth = date("F",mktime(1,1,1,$month,1,$year)); 
 //if date("F",mktime(1,1,1,$month,1,$year)) doesn't work, then use this old implementation 
 //$monthnames = array("January","February","March","April","May","June","July","August","September","October","November","December"); 
 //$textmonth = $monthnames[$month - 1]; 
 $year = (isset($year)) ? $year : date("Y",time()); 
 $today = (isset($today))? $today : date("j", time()); // Make $today really big to avoid hilighting 
 $today = ($month == date("n",time()) && $year == date("Y",time())) ? $today : 32; //will only highlight today for this month & year 
 //this method of finding dates is old, but if date("t",mktime(1,1,1,$month,1,$year); doesn't work then use this 
// if ( (($month < 8) && ($month % 2 == 1)) || (($month > 7) && ($month % 2 == 0)) ) 
//$days = 31; 
// if ( (($month < 8) && ($month % 2 == 0)) || (($month > 7) && ($month % 2 == 1)) ) 
//$days = 30; 
// if ($month == 2) 
//$days = (date("L",time())) ? 29 : 28; 
 $days = date("t",mktime(1,1,1,$month,1,$year)); 
 $dayone = date("w",mktime(1,1,1,$month,1,$year)); 
 $daylast = date("w",mktime(1,1,1,$month,$days,$year)); 
 $dayarray = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); 
?> 
<table border="0" cellpadding="0" cellspacing="0" width="100%"> 
<tr> 
 <td bgcolor="<?php echo $defaultbgcolor ?>" colspan="7" valign="middle" align="center"><font color="<?php echo $monthcolor ?>" face="Arial, Helvetica, sans-serif" size="3"><b><?php echo $textmonth ?></b></font></td> 
</tr> 
<tr> 
<?php //printing the days of week 
for($i=0; $i <= 6; $i++): 
 $width = ($i == 0 || $i == 6) ? "15%" : "14%"; 
 //use the css (default) or the html version (commented out) underneath if you want full compatibility 
echo " <td valign=\"middle\" width=$width\" style=\"text-align:center; background:{$defaultbgcolor}; font:bold {$cssfontsize} {$fontfamily}; color:{$defaultfontcolor};\">$dayarray[$i]</td>\n"; 
//echo " <td bgcolor=\"$defaultbgcolor\" valign=\"middle\" align=\"center\" width=\"$width\"><font color=\"$fontcolor\" face=\"$fontfamily\" size=\"$relfontsize\">$i</font></td>\n"; 
 endfor; 
 echo "</tr>\n"; //done printing the top row of days 
 $span1 = $dayone; 
 $span2 = 6 - $daylast; 
 for($i = 1; $i <= $days; $i++): 
$dayofweek = date("w",mktime(1,1,1,$month,$i,$year)); 
$width = ($dayofweek == 0 || $dayofweek == 6) ? "15%" : "14%"; //sets the col width 
switch ($i): 
 case $today: //sets background color for today 
$fontcolor = $todayfontcolor; 
$bgcellcolor = $todaybgcolor; 
 break; 
default: //sets background color for other days 
$fontcolor = $defaultfontcolor; 
$bgcellcolor = $defaultbgcolor; 
 break; 
endswitch; 
//if($i == putdayhere): #use this for *special* days of the month, can be set ahead as well w/ &&... 
// $fontcolor = puthexcolorhere; 
// $bgcellcolor = puthexcolorhere; 
//endif; 
if($i == 1 || $dayofweek == 0): 
 echo " <tr bgcolor=\"$defaultbgcolor\">\n"; 
 if($span1 > 0 && $i == 1) 
echo " <td align=\"left\" bgcolor=\"$defaultbgcolor\" colspan=\"$span1\"><font face=\"null\" size=\"1\"> </font></td>\n"; 
endif; 
 
 //use the css (default) or the html version (commented out) underneath if you want full compatibility 
echo " <td valign=\"middle\" width=$width\" style=\"text-align:center; background:{$bgcellcolor}; font-family:{$fontfamily}; color:{$fontcolor}; font-size:{$cssfontsize}\">$i</td>\n"; 
//echo " <td bgcolor=\"$bgcellcolor\" valign=\"middle\" align=\"center\" width=\"$width\"><font color=\"$fontcolor\" face=\"$fontfamily\" size=\"$relfontsize\">$i</font></td>\n"; 
if($i == $days && $span2 > 0) 
 echo " <td align=\"left\" bgcolor=\"$defaultbgcolor\" colspan=\"$span2\"><font face=\"null\" size=\"1\"> </font></td>\n"; 
if($dayofweek == 6 || $i == $days) 
 echo " </tr>\n"; 
 endfor; 
 echo "</table>\n"; 
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.