<?php

class Obvestila {
	var $srvfeed;
	var $version_data = array();
	var $client_licence = array();
	var $mysql;
	
	function __construct($mysql){
		//Nastavi mysql
		$this->mysql = $mysql;
		
		$this->srvfeed = "http://feed.cms.zabec.net/";
		$this->GetFeedUrl();
		$this->GetNews();
		$this->GetObvezna();
	}


	function GetFeedUrl(){
		$result = $this->mysql->query("SELECT value FROM core_nastavitve WHERE var='obvestila_feed'");
		$fetch = $result->fetch();
		if($fetch['value'] != $this->srvfeed){
			$this->srvfeed = $fetch['value'];
		}
	}
	
	function GetNews(){
		//Preberi podatke za licenco
		$dom = new DOMDocument();
		$dom->load($this->srvfeed . "/obvestila.php?srv=" . $_SERVER['HTTP_HOST']);
		$nodes = $dom->getElementsByTagName("obvestilo");
		
		$result = $this->mysql->query("DELETE FROM core_obvestila");
	
		for($x = 0;$firstnode = $nodes->item($x)->childNodes;$x++){
			$size = $firstnode->length;
			$obvestilo = array();
			for ($i = 0; $i<$size; $i++){
				if ($firstnode->item($i)->nodeType == 1){
					$obvestilo[$firstnode->item($i)->nodeName] = $firstnode->item($i)->nodeValue;
				}
			}
			$result = $this->mysql->query("INSERT INTO core_obvestila (naziv,cas,opis,link) VALUES ('$obvestilo[naziv]','$obvestilo[cas]','$obvestilo[opis]','$obvestilo[link]');");
			unset($obvestilo);
		}
	}
	
	function GetObvezna(){
		//Preberi podatke za licenco
		$dom = new DOMDocument();
		$dom->load("http://feed.cms.zabec.net/obvezna.php");
		
		$nodes = $dom->getElementsByTagName("obvestilo");
	
		for($x = 0;$firstnode = $nodes->item($x)->childNodes;$x++){
			$size = $firstnode->length;
			$obvestilo = array();
			for ($i = 0; $i<$size; $i++){
				if ($firstnode->item($i)->nodeType == 1){
					$obvestilo[$firstnode->item($i)->nodeName] = $firstnode->item($i)->nodeValue;
				}
			}
			$result = $this->mysql->query("INSERT INTO core_obvestila (naziv,cas,opis,link,obvezno) VALUES ('$obvestilo[naziv]','$obvestilo[cas]','$obvestilo[opis]','$obvestilo[link]','1');");
			unset($obvestilo);
		}
	}

}

?>