<?php

$servers 
= array('Moray','Catfish');

class 
voxinfo{

    function 
voxinfo$servers = array(),$serverurl "http://voxtremestatus.com/index.php?XML"){
        
$this->serverswanted $servers;
        
$this->url $serverurl;
    }

    function 
doit($template){
        if( 
$this->getinfo() ){
            
$this->displayresults($template);
            return 
true;
        }else{
            return 
false;
        }
    }

    function 
getinfo(){
        
$url $this->url;
        
$iwant "";
        
$xml = @file($url);
        if( 
$xml ){
            
$xml join(""$xml);
            
$this->parse($xml);
            return 
true;
        }else{
            return 
false;
        }
    }

    function 
parse(&$xml){
        
$parser xml_parser_create();
        
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
        
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
        
xml_parse_into_struct($parser,$xml,$values,$tags);
        
xml_parser_free($parser);
        
$this->announcements = array();
        
$this->servers = array();
    
$nsw count($this->serverswanted);
        foreach(
$values as $v){
      
            switch( 
$v["tag"]){
                case 
"announcement":
                    if(
$nsw == || $v["attributes"]["server"] == 'All Servers' || preg_match("/(".join("|"$this->serverswanted).")/is"$v["attributes"]["server"]) )
                        
$this->announcements[$v["attributes"]["date"].' ('.$v["attributes"]["server"].')'] = $v["attributes"]["text"];
                    break;
                case 
"server":
                    if( 
$nsw == || preg_match("/(".join("|"$this->serverswanted).")/is"$v["attributes"]["name"]) )
                        
$this->servers[$v["attributes"]["name"]] = $v["attributes"];
                    break;
            }
        }
        
$this->numservers count($this->servers);
        
$this->numannouncements count($this->announcements);
    }

    function 
displayresults($template){
        if( 
preg_match("/<announcements>(.*?)<\/announcements>/is"$template$matches) ){
            
$tpla $matches[1];
        }else{
            
$tpla "";
        }
        if( 
preg_match("/<servers>(.*?)<\/servers>/is"$template$matches) ){
            
$tpls $matches[1];
        }else{
            
$tpls "";
        }
        
ob_start();
        
$this->displayannouncements($tpla);
        
$a ob_get_contents();
        
ob_end_clean();
        
ob_start();
        
$this->displayservers($tpls);
        
$s ob_get_contents();
        
ob_end_clean();
        echo 
preg_replace(array("/<announcements>.*?<\/announcements>/is""/<servers>.*?<\/servers>/is"),
                    array(
$a$s), $template);
    }

    function 
displayannouncements($template){
        if(
count($this->announcements)==0) {
            echo 
str_replace(array('{date}''{announcement}'), array('No announcements'''), $template);
        }
        else {
            foreach(
$this->announcements as $date => $text){
                echo 
str_replace(array('{date}''{announcement}'), array($date$text), $template);
            }
        }
    }

    function 
displayservers($template){
        
$search = array("{name}""{uptime}""{FTP}""{HTTP}""{ip}""{SMTP}""{POP3}""{MySql}");
        foreach( 
$this->servers as $name=>$values){
            echo 
str_replace($search, array($values["name"], $values["uptime"], $values["FTP"], $values["HTTP"], $values["ip"],
                    
$values["SMTP"], $values["POP3"], $values["MySql"]), $template);
        }
    }


}


$tpl '
<table border=1" align="center" width="600">
<tr><td colspan="7" align="center"><b>Announcements</b></td></tr>
<announcements><tr><td colspan="7">{date}: {announcement}</td></tr></announcements>
<tr><td colspan="7"><br><br></td></tr>
<tr><td><b><u>Server</u></b></td>
<td><b><u>ftp</u></b></td>
<td><b><u>http</u></b></td>
<td><b><u>smtp</u></b></td>
<td><b><u>pop3</u></b></td>
<td><b><u>mysql</u></b></td>
<td><b><u>uptime</u></b></td></tr>
<servers>
<tr>
<td><b>{name}</b><br><i><ip></i></td>
<td>{FTP}</td>
<td>{HTTP}</td>
<td>{SMTP}</td>
<td>{POP3}</td>
<td>{MySql}</td>
<td>{uptime}</td>
</tr>
</servers>
</table>
'
;

?>
<html>
<body>
<p align="center">Current Time : <?php echo gmdate("D, d M Y H:i:s"time()); ?> GMT</p>
<table border="0" cellpadding="3" cellspacing="2" width="100%">
  <tr><td align="center">Alerts & Notices for <?=implode(', '$servers); ?></td></tr>
    <tr><td align="center">

<?

  $vi = new voxinfo($servers);
  if( !$vi->doit($tpl) ) echo "Sorry, an error occurred!";

?>
        </td>
    </tr>
</table>
</body>
</html>