PHP Classes
elePHPant
Icontem

File: example.xml.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Nathan Lucas  >  Calendar Frame  >  example.xml.php  >  Download  
File: example.xml.php
Role: Example script
Content type: text/plain
Description: /
Class: Calendar Frame
Generate month calendar data
Author: By
Last change: Added the SQL CREATE TABLE example.
Date: 7 years ago
Size: 1,764 bytes
 

Contents

Class file image Download
<?php
##
# MySQL CREATE TABLE for events
#
# CREATE TABLE `events` (
# `event_id` int(11) NOT NULL auto_increment,
# `event_dt` datetime NOT NULL,
# `event_title` varchar(40) NOT NULL,
# `description` tinytext,
# PRIMARY KEY (`event_id`)
# ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
##

require_once("./OOP/CalendarFrame.php");
header("Content-Type: application/xml");

$frame = new CalendarFrame();
$month = $frame->getMonth();

$conn = mysql_connect("localhost", "user", "pass");
mysql_select_db("db_name", $conn);

echo
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
echo
"<calendar date=\"".date(DATE_ISO8601, $month['stamp'])."\">\n";
echo
"\t<previous>".date(DATE_ISO8601, $month['previous'])."</previous>\n";
echo
"\t<next>".date(DATE_ISO8601, $month['next'])."</next>\n";
foreach (
$month['week'] as $week) {
    echo
"\t<week>\n";
    foreach (
$week['day'] as $day) {
       
$ds = date("Y-m-d", $day)." 00:00:00";
       
$de = date("Y-m-d", $day)." 23:59:59";
       
$inmonth = (date("n", $day) == date("n", $month['stamp'])) ? 1 : 0;
        echo
"\t\t<day inmonth=\"{$inmonth}\" date=\"".date(DATE_ISO8601, $day)."\">\n";
       
$sql = "SELECT * FROM events WHERE event_dt BETWEEN '{$ds}' AND '{$de}' ORDER BY event_dt";
       
$result = mysql_query($sql, $conn);
        while (
$row = mysql_fetch_object($result)) {
            echo
"\t\t\t<event id=\"{$row->event_id}\">\n";
            echo
"\t\t\t\t<time>".date(DATE_ISO8601, $row->event_dt)."</time>\n";
            echo
"\t\t\t\t<title>{$row->event_title}</title>\n";
            echo
"\t\t\t\t<description>{stripslashes($row->description)}</description>\n";
            echo
"\t\t\t</event>\n";
        }
       
mysql_free_result($result);
        echo
"\t\t</day>\n";
    }
    echo
"\t</week>\n";
}
echo
"</calendar>\n";
mysql_close($conn);
?>