<?php
class guestbook {
        private 
$file_name;
        private 
$xml;
        private 
$smarty;
        
        function 
__construct($filename$smarty) {
            
$this->file_name $filename;
            
$this->smarty $smarty;
            
$this->xml simplexml_load_file($this->file_name);
        }
        
        
        public function 
printFile() {                          
            
$mine_hilsner = array();
            
$i=0;         
            
/* Hent ut info om hver hilsen, lagre dette i assosiativ tabell og overfør til Smarty  */
            
foreach ($this->xml->hilsen as $hilsen) {

                
$mine_hilsner[$i] = array('tittel' => utf8_decode($hilsen->tittel), 'tekst' => utf8_decode($hilsen->tekst)
                                    , 
'web' => utf8_decode($hilsen->web), 'dato' => utf8_decode($hilsen->dato));
                
$i++;
            }
            
$this->smarty->assign('gjestebok_poster'array_reverse($mine_hilsner)); 
            
$this->smarty->display('visGjestebok.tpl');
        }
            
        public function 
addToFilehilsen $post) {  
            
            
$nytt_innlegg $this->xml->addChild('hilsen');
            
$nytt_innlegg->addChild("tittel",utf8_encode($post->visTittel()));
            
$nytt_innlegg->addChild("web",utf8_encode($post->visUrl()));
            
$nytt_innlegg->addChild("tekst",utf8_encode($post->visTekst()));
            
$nytt_innlegg->addChild("dato",utf8_encode($post->visDato()));
                       
            
$status $this->xml->asXml($this->file_name);
            if(!
$status) print ("Error during save of XML document");

        }

    }
?>