|
|
|
|
|
|
| |
calendar class :
@package
@author Ben Yacoub Hatem <hatem@php.net>
@copyright Copyright PHPTunisie.net (c) 2004
@version $Id$ - 09/06/2004 06:39:31 - calendar.php
@access public
| <?php
class calendar{
/**
* Constructor
* @access protected
*/
function calendar(){
}
/**
* calendar::html_month_calendar()
*
* @param integer $m The month value, could be returned with $m = date("m");
* @return
**/
function html_month_calendar($m = "",$y = ""){
if (trim($m) == "") {
$m = date($m);
}
if (trim($y)=="") {
$y = date("Y");
}
$curr_month = date("m");
$d = date("d");
if ($m==1) {
$m_1 = 12;
$y_1 = $y-1;
} else {
$m_1 = $m-1;
$y_1 = $y;
}
$to = mktime(0,0,0,$m_1,0,$y_1);
$days_in_month = strftime ("%d",$to);
$from = mktime(0,0,0,$m,1,$y);
$from_a = getdate($from);
$to_a = getdate($to);
$calendar = "\n<table bgcolor=white cellpadding=2 cellspacing=0>
<tr>
<th>Dim</th>
<th>Lun</th>
<th>Mar</th>
<th>Mer</th>
<th>Jeu</th>
<th>Ven</th>
<th>Sam</th>
</tr>\n";
$Days = 0;
for($i = 1; $i <= 6; $i++){
$calendar .= "<tr>\n";
for($j = 0; $j <= 6 ; $j++){
if ($d == ($Days+1) and $curr_month==$m) {
$b1 = "<b>";$b2 = "</b>";
} else $b1 = "";$b2 = "";
if ($from_a["wday"]==$j and $Days==0) {
$Days++;
$calendar .= "<td>$b1 $Days $b2</td>";
} elseif($Days==0) {
$calendar .= "<td></td>";
} else {
$Days++;
if ($Days<=$days_in_month) {
$calendar .= "<td>$b1 $Days $b2</td>";
} else {
$calendar .= "<td></td>";
}
}
} // for
$calendar .= "</tr>\n";
} // for
$calendar .= "</table><center>\n";
return $calendar;
}
/**
*
* @access public
* @return void
**/
function html_year_calendar($y = ""){
if (trim($y)=="") {
$y = date("Y");
}
$year_calendar = "<table bgcolor=white cellpadding=2 cellspacing=0 width=100% border=1>\n<tr>\n";
for($i = 1; $i <= 12; $i++){
$year_calendar .= "<td valign=top>Mois $i <br>".$this->html_month_calendar($i,$y )."</td>";
if ($i == 3 or $i == 6 or $i == 9) {
$year_calendar .= "</tr>\n<tr>\n";
}
} // for
$year_calendar .= "</tr><table>";
return $year_calendar;
}
}
$cal = new calendar;
//echo $cal->html_month_calendar();
echo $cal->html_year_calendar();
?> | |
|
|
| pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | News management class Categories : PHP, PHP Classes, Beginner Guides | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself. Categories : PHP, PHP Classes, Templates, Complete Programs | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | MS Word Mail Merge Automation (COM) Categories : PHP, PHP Classes, COM | | | Very minimal templating engine Categories : PHP, PHP Classes, Templates | | | ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data. Categories : PHP, Linux, PHP Classes | |
| | | | Niels Oesten wrote : 1131
Works fine, but I really think you should have created it according to the standard ISO 8601. That is with Monday as the first day-of-week. Otherwise week numbers make no sense.
| | | | matthew waygood wrote :1132
Using system locale, you can set the month and weekday names to the current language. So a quick alteration to the code has been done to accoodate this.
<?php
/**
* calendar class :
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright PHPTunisie.net (c) 2004
* @version $Id$ - 09/06/2004 06:39:31 - calendar.php
* @access public
**/
class calendar{
/**
* Constructor
* @access protected
*/
function calendar(){
}
/**
* calendar::html_month_calendar()
*
* @param integer $m The month value, could be returned with $m = date("m");
* @return
**/
function html_month_calendar($m = "",$y = ""){
if (trim($m) == "") {
$m = date($m);
}
if (trim($y)=="") {
$y = date("Y");
}
$curr_month = date("m");
$d = date("d");
if ($m==1) {
$m_1 = 12;
$y_1 = $y-1;
} else {
$m_1 = $m-1;
$y_1 = $y;
}
$to = mktime(0,0,0,$m_1,0,$y_1);
$days_in_month = strftime ("%d",$to);
$from = mktime(0,0,0,$m,1,$y);
$from_a = getdate($from);
$to_a = getdate($to);
$calendar = "\n<table bgcolor=white cellpadding=2 cellspacing=0><tr>";
$sunday=strtotime("-".date("w")." days");
for($loop=0;$loop<7;$loop++)
{
$calendar.="<th>".strftime("%a" ,strtotime("+".$loop." days",$sunday))."</th>";
}
$calendar.="</tr>\n";
$Days = 0;
for($i = 1; $i <= 6; $i++){
$calendar .= "<tr>\n";
for($j = 0; $j <= 6 ; $j++){
if ($d == ($Days+1) and $curr_month==$m) {
$b1 = "<b>";$b2 = "</b>";
} else $b1 = "";$b2 = "";
if ($from_a["wday"]==$j and $Days==0) {
$Days++;
$calendar .= "<td>$b1 $Days $b2</td>";
} elseif($Days==0) {
$calendar .= "<td></td>";
} else {
$Days++;
if ($Days<=$days_in_month) {
$calendar .= "<td>$b1 $Days $b2</td>";
} else {
$calendar .= "<td></td>";
}
}
} // for
$calendar .= "</tr>\n";
} // for
$calendar .= "</table><center>\n";
return $calendar;
}
/**
*
* @access public
* @return void
**/
function html_year_calendar($y = ""){
if (trim($y)=="") {
$y = date("Y");
}
$year_calendar = "<table bgcolor=white cellpadding=2 cellspacing=0 width=100% border=1>\n<tr>\n";
for($i = 1; $i <= 12; $i++){
$month_name=strftime("%B" ,mktime(1,1,1,$i));
$year_calendar .= `<td valign="top" align="center">`.$month_name.`<br>`.$this->html_month_calendar($i,$y ).`</td>`;
if ($i == 3 or $i == 6 or $i == 9) {
$year_calendar .= "</tr>\n<tr>\n";
}
} // for
$year_calendar .= "</tr><table>";
return $year_calendar;
}
}
$cal = new calendar;
//echo $cal->html_month_calendar();
echo $cal->html_year_calendar();
?>
| |
|
|
|