| pghurban 2004-04-10, 8:30 pm |
| Thanks to phpfreak for this wonderful script. i am happy to contribute
to this community. here's the whole script if anyone is
interested:
--------
<?php
session_start();
header("Cache-control: private");
if (!_SESSION['count']) {
__SESSION['count'] = 1;
}else {
_ _ _SESSION['count']++;
}
?>
<html>
<head>
<title>Events Calendar</title>
<style type="text/css">
<!--
.table.calendar {border: 3px solid #000000; border-collapse:
collapse; color: #000000; background: #FFFFFF; }
.td.calHead { color: white; background: #999999; }
.td.today { border: 1px solid white; color: #FFFFFF;
background: red; font-weight: bold;}
.td.monthdays {border: 1px solid #434470; color: #000000;
background: #FFFFFFF; }
.td.nonmonthdays { border: 1px solid white; color: #000000;
background: #EFEFEF;}
.td.desc { color: #AC925A;}
-->
</style>
<body bgcolor="#666666">
<?php
//Turn off all error reporting:
//error_reporting('0');
//ini_set('display_errors', '0');
// Gather variables from
// user input and break them
// down for usage in our script:
if(!isset(_REQUEST['date'])){
_ date = mktime(0,0,0,date('m'),
date('d'), date('Y'));
} else {
_ date = _REQUEST['date'];
}
day = date('d', date);
month = date('m', date);
year = date('Y', date);
//Get friendly day name
day_name = date('l', date);
// Get the first day of the month
month_start = mktime(0,0,0,month, 1, year);
// Get friendly month name
month_name = date('M', month_start);
// Figure out which day of the w
// the month starts on.
month_start_day = date('D', month_start);
switch(month_start_day){
_ _case "Sun": offset = 0; break;
_ _case "Mon": offset = 1; break;
_ _case "Tue": offset = 2; break;
_ _case "Wed": offset = 3; break;
_ _case "Thu": offset = 4; break;
_ _case "Fri": offset = 5; break;
_ _case "Sat": offset = 6; break;
}
// determine how many days are in the last month.
if(month == 1){
_ num_days_last = cal_days_in_month(0, 12, (year
-1));
} else {
_ num_days_last = cal_days_in_month(0, (month
-1), year);
}
// determine how many days are in the current month.
num_days_current = cal_days_in_month(0, month,
year);
// Build an array for the current days
// in the month
for(i = 1; i <= num_days_current;
i++){
_ _num_days_array[] = i;
}
// Build an array for the number of days
// in last month
for(i = 1; i <= num_days_last;
i++){
_ _num_days_last_array[] = i;
}
// If the offset from the starting day of the
// w happens to be Sunday, offset would be 0,
// so don't need an offset correction.
if(offset > 0){
_ _offset_correction =
array_slice(num_days_last_array, -offset,
offset);
_ _new_count = array_merge(offset_correction,
num_days_array);
_ _offset_count = count(offset_correction);
}
// The else statement is to prevent building the offset array.
else {
_ _offset_count = 0;
_ _new_count = num_days_array;
}
// count how many days we have with the two
// previous arrays merged together
current_num = count(new_count);
// Since we will have 5 HTML table rows (TR)
// with 7 table data entries (TD)
// we need to fill in 35 TDs
// so, we will have to figure out
// how many days to appened to the end
// of the final array to make it 35 days.
if(current_num > 35){
_ num_w s = 6;
_ outset = (42 - current_num);
} elseif(current_num < 35){
_ num_w s = 5;
_ outset = (35 - current_num);
}
if(current_num == 35){
_ num_w s = 5;
_ outset = 0;
}
// Outset Correction
for(i = 1; i <= outset; i++){
_ new_count[] = i;
}
// Now let's "chunk" the all_days array
// into w s. Each w has 7 days
// so we will array_chunk it into 7 days.
w s = array_chunk(new_count, 7);
// Build Previous and Next Links
previous_link = "<a
href=""._SERVER['PHP_SELF']."?date=";
if(month == 1){
_
previous_link .=
mktime(0,0,0,12,day,(year -1));
} else {
_
previous_link .= mktime(0,0,0,(month
-1),day,year);
}
previous_link
.= ""><img
src="images/prev_link.gif"
border="0"></a>";
next_link
= "<a
href=""._SERVER['PHP_SELF']."?date=";
if(month == 12){
_
next_link .= mktime(0,0,0,1,day,(year +
1));
} else {
_ next_link
.= mktime(0,0,0,(month
+1),day,year);
}
next_link .= ""><img
src="images/next_link.gif"
border="0"></a>";
// Build the heading
portion of the calendar table
echo "<table align="center"
border="0"
cellpadding="0"
cellspacing="7" width="350"
class="calendar">n".
_ _ "<tr>n".
_ _ "<td colspan="7">n".
_ _ "<table border="0"
cellpadding="0"
cellspacing="0"
align="center">n".
_ _ "<tr>n".
_ _ "<td class="calHead"
colspan="2" width="75"
align="left">previous_link</td>n".
_ _ "<td class="calHead"
colspan="3" width="150"
align="center">month_name
year</td>n".
_ _ "<td class="calHead"
colspan="2" width="75"
align="right">next_link</td>n".
_ _ "</tr>n".
_ _ "</table>n".
_ _ "</td>n".
_ _ "<tr>n".
_ _ "<td
align="right">S</td><td
align="right">M</td><td
align="right">T</td><td
align="right">W</td><td
align="right">T</td><td
align="right">F</td><td
align="right">S</td>n".
_ _ "</tr>n";
//
Now we break each key of the array
// into a w and create a new table
row for each
// w with the days of that w in the table data
i =
0;
foreach(w s AS w ){
_ _ _ echo "<tr>n";
_ _ _ foreach(w
as d){
_ _ _ _ if(i < offset_count){
_ _ _ _ _ _ day_link = "<a
href=""._SERVER['PHP_SELF']."?sessionid=".session_id()."&date=".mktime(0,0,0,month
-1,d,year)."">d</a>";
_ _ _ _ _ _ echo "<td align="right"
class="nonmonthdays">day_link</td>n";
_ _ _ _ }
_ _ _ _ if((i >=
offset_count) &&
(i < (num_w s * 7) -
outset)){
_ _ _ _ _
_day_link = "<a
href=""._SERVER['PHP_SELF']."?sessionid=".session_id()."&date=".mktime(0,0,0,month,d,year)."">d</a>";
_ _ _ _ _ if(date ==
mktime(0,0,0,month,d,year)){
_ _ _ _ _ _ _
echo "<td align="right"
class="today">d</td>n";
_ _ _ _ _ } else {
_ _ _ _ _ _ _ echo "<td align="right"
class="days">day_link</td>n";
_ _ _ _ _ }
_ _ _ _} elseif((outset
> 0)) {
_ _ _ _ _ _if((i >= (num_w s * 7) -
outset)){
_ _ _ _ _ _
_ day_link = "<a
href=""._SERVER['PHP_SELF']."?sessionid=".session_id()."&date=".mktime(0,0,0,month
+1,d,year)."">d</a>";
_ _ _ _ _ _ _ echo "<td align="right"
class="nonmonthdays">day_link</td>n";
_ _ _ _ _ }
_ _ _ _}
_ _ _
_i++;
_ _ _}
_ _ _echo "</tr>n"; _ _
}
// Close out your table and
that's it!
echo '</table><br>';
//Display events according to date.
echo
"<table cellspacing="0"
cellpadding="0" width="300"
align="center">";
echo "<tr><td
align="center">Events for day_name,
month_name day,
year:</td></tr>";
//Open mySQL connection
conn =
mysql_connect("localhost", "user",
"pwd") or die("Could not connect!");
//Connect to database
mysql_select_db("pghurban") or die("Could not
select
database");
//Query database
//sql = "SELECT * FROM events WHERE
eventDate =
FROM_UNIXTIME(date)";
date = date("Y-m-d", date);
sql = _
_" SELECT eventTitle, eventCost, eventDesc,"
_.
" TIME_FORMAT(eventStartTime, '%l%p' ) AS
startTime,"
_ _ _ _. "
TIME_FORMAT(eventEndTime, '%l%p' ) AS
endTime"
_. " FROM events"
_. "
WHERE eventDate = 'date' "
_. " ORDER BY eventStartTime";
result =
mysql_query(sql);
//Fecth rows according to timestamp
num_rows =
mysql_num_rows(result);
if(num_rows == 0){
echo "<tr><td
align="center">Sorry, no events
listed.</td></tr>";
}else{
while
(row=mysql_fetch_array(result)){
_title _= row["eventTitle"];
_desc
_= row["eventDesc"];
_start _= row['startTime'];
_end _ =
row['endTime'];
_cost _= row['eventCost'];
_ _
_echo
"<tr><td><b>title</b></td>";
_echo "<tr><td>Time: start -
end</td></tr>";
_echo "<tr><td>Cost: ";
_ if (cost > 0){
_ _echo
"cost</td></tr>";
_ } else {
_ _echo "Free!</td></tr>";
_ }
_echo
"<tr><td>desc<br><br></td></tr>";
}
}
echo "</table>";
echo "<div
align="center"><a
href="add_event.htm">Add
Event!</a></div>";
echo
"<p>Last modified: " . date ("F d Y
H:i:s.", getlastmod());
?>
</body>
</html>
#
# Table structure for table `events`
#
# Creation: Apr 07, 2004
at 11:20 PM
# Last update: Apr 08, 2004 at 03:30 PM
#
CREATE TABLE
`events` (
_`eventID` mediumint(8) unsigned NOT NULL auto_increment,
_`eventTitle` varchar(64) NOT NULL default '',
_`eventDate` date NOT NULL
default '0000-00-00',
_`eventStartTime` time NOT NULL default '00:00:00',
_`eventEndTime` time NOT NULL default '00:00:00',
_`eventCost`
smallint(6) default '0',
_`eventDesc` mediumtext NOT NULL,
_PRIMARY KEY
_(`eventID`)
) TYPE=MyISAM;
--------
----------------------------------------
The post originated from PHP
Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|