<?php
class EventXML {
 public function __construct($first_node){
  $this->sql_date_format = "%W %M %e, %Y";
  $this->php_date_format = "l F j, Y";
  $this->first_node      = $first_node;
  
  $this->openXML();
  $this->getEvents();
  $this->closeXML();
 }
 
 
 private function createXMLAttribute($title, $attribute, $value){
  echo "<".$title." ".$attribute."='".$value."'>";
 }
 
 
 private function closeXMLAttribute($title){
  echo "</".$title.">";
 }
 
 private function createXMLNode($title, $value){
  echo "<".$title.">".$value."</".$title.">";
 }
 
 
 private function openXML(){
  echo '<?xml version="1.0" encoding="iso-8859-1"?>';
  echo '<'.$this->first_node.'>';
 }
 
 
 private function getEvents(){
     global $db;
    
  $get = $db->query("SELECT event_id, event_name, event_location, event_content, event_date FROM cms_event WHERE event_active='1' ORDER BY event_date ASC");
  while($event = $db->fetch($get)){
   $event_date = date($this->php_date_format, $event['event_date']);
   
   $this->createXMLAttribute('event', 'id', $event['event_id']);
   $this->createXMLNode('name', $event['event_name']);
   $this->createXMLNode('location', $event['event_location']);
   $this->createXMLNode('content', $event['event_content']);
   $this->createXMLNode('date', $event_date);
   $this->closeXMLAttribute('event');
  }
 }
 
 
 private function closeXML(){
  echo '</'.$this->first_node.'>';
 }
}

/*******************************************/

require('include/globals.php');
header('Content-Type: text/xml');
$event = new EventXML('event_calendar');
?>