The
Month Object
The methodology of the app includes
a month object. At the beginning of any page in which you wish
to make use of the calendar features, you should instantiate a month
object with
$mymonth = new month();
After this, methods are called on
the month object with the syntax
$mymonth->method_name([options]);
The month's constructor
function allows you to define it with a particular month and year, for
example:
$mymonth = new month("01","2000");
This would create
a month object for January, 2000. If you do not provide a month and year
when you create the object, the default is the current month (at the webserver.)
Once this has been
done, there are several other methods and class variables which are available
via the month object. They are:
$mymonth->print_month_name();
$mymonth->print_year();
$mymonth->print_datestring();
$mymonth->draw();
$mymonth->month_name;
$mymonth->month_number;
$mymonth->year;
$mymonth->nextmonth;
$mymonth->nextyear;
$mymonth->prevmonth;
$mymonth->prevyear;
Where the items ending
with () are methods. All of the above are fairly obvious with the exception
of the draw() method.
$mymonth->print_month_name():
This simply prints
the string value of the month, i.e., "January", "February",
etc. It is pretty redundant since there's a variable with the same information.
It does not take any arguments.
$mymonth->print_year():
This simply prints
the numeric value of the month, i.e., "01", "02",
etc. It is pretty redundant since there's a variable with the same information.
It does not take any arguments.
$mymonth->print_datestring():
This prints out a formatted
string in the form "January, 2000" or "August, 1776".
It does not take any arguments.
$mymonth->draw(<array([options])>):
This is by far the
most complicatd part of the class, being the method which actually generates
the html for the calendar. It takes an array as its argument, and this
array may contain many different values (in no particular order) which
will determine the look of the calendar generated. An example invocation
might be:
$mymonth->draw(array("cellspacing" => "2" , "cellpadding" => "2" ,
"top_row_align" => "center" , "table_height" => "300px" ,
"top_row_cell_height" => 20 , "bgcolor" => "#cccccc" ,
"row_align" => "left" , "row_valign" => "top" ,
"font_size" => "-1") );
There are many options
which can be put into the array above. They are (shown as "option"
=> "possible value"):
- "textcolor"
=> "#000000":
This is the color of the text on the calendar. The default value is
"#000000".
- "bgcolor"
=> "#ffffff": This
is the background color of the cells in the calendar. The default value
is "#cccccc".
- "font_face"
=> "Verdana, Arial":
This is the font face used in the calendar. The default value is "Verdana,
Arial, Helvetica".
- "font_size"
=> "-1":
This is the font size which will be used in the calendar. The default
value is "-1".
- "table_width"
=> "80":
This is the width, in percent, of the table that will contain the calendar
on the page. If you want to specify this in pixels instead of percent,
use the format "table_width" => "80px".
The default value is "100".
- "table_height"
=> "300":
This is the height, in pixels, of the table that will contain the calendar
on the page. For some reason, the calendar will not draw properly if
this is a percentage, so it is always interpreted as pixels. The default
value is "100".
- "cellpadding"
=> "0":
This is the cellpadding for the table. The default value is "0".
- "cellspacing"
=> "0":
This is the cellspacing for the table. The default value is "0".
- "top_row_align"
=> "left":
This is the horizontal alignment for the very top row of the calendar,
which contains the day names (Sunday, Monday, etc...). The default value
is "left".
- "top_row_valign"
=> "top":
This is the vertical alignment for the top row of the calendar. The
default value is "top".
- "row_align"
=> "left":
This is the horizontal alignment for the cells of the calendar's body.
The default value is "left".
- "row_valign"
=> "top":
This is the vertical alignment for the cells of the calendar's body.
The default value is "top".
- "top_row_cell_height"
=> "20":
This is the height, in pixels, of the top row of the calendar with the
day names. It's useful if you want it to be slimmer than the cells which
make up the main body (which you probably want.) The default value is
"".
$mymonth->month_name:
This variable contains
the name of the month described by $mymonth.
$mymonth->month_number:
This variable contains
the number of the month described by $mymonth.
$mymonth->year:
This variable contains
the year of the month described by $mymonth.
$mymonth->nextmonth:
This variable contains
the number of the month following $mymonth. It is zero padded, so lower
months will be represented by "01", "02", and so on.
It will wrap properly from "12" -> "01". It's particularly
useful for "next month" type links, where it could be used to
set a variable which would initialize a new month object on the
page linked to.
$mymonth->nextyear:
This variable contains
the year which will be current in the month following the current month.
Yes, the name is a little misleading. This is intended to be used with
$mymonth->nextmonth for linking to a "next month's calendar"
page. For example, you could include the following php code to generate
a link on a page:
echo "<a href=cal.php3?m=$mymonth->nextmonth&y=$mymonth->nextyear>Next</a>\n";
Then, on the page
linked to, you could use
$mymonth = new month($m,$y);
and the appropriate
month would be initialized.
$mymonth->prevmonth:
This variable contains
the number of the month preceding $mymonth. It is analagous to $mymonth->nextmonth,
and is used for the same types of things.
$mymonth->prevyear:
This variable is analagous
to $mymonth->nextyear, and is used similarly.
|