<?php
	function check_data_search() {
		/*******************************************
			***      Create XML for Search page      ***
			***             if not exist             ***
		********************************************/
		if (!file_exists(GSDATAPAGESPATH.'search.xml')) {
			global $pagesArray, $USR, $USR1;
			$pagesSorted = subval_sort($pagesArray, 'menuOrder');
			if (count($pagesSorted) != 0) {
				$menu_order = 0;
				foreach ($pagesSorted as $page) {
					if($menu_order < (int)$page['menuOrder']) $curr_order = (int)$page['menuOrder'];
				}
				$curr_order = $curr_order + 1;
			}
			else $curr_order = 0;
			$xml = @new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
			$xml->addChild('pubDate', date(DATE_RFC2822));
			$dataval = $xml->addChild('title');
			$dataval->addCData("Search");
			$dataval = $xml->addChild('url');
			$dataval->addCData("search");
			$dataval = $xml->addChild('meta');
			$dataval->addCData("");
			$dataval = $xml->addChild('metad');
			$dataval->addCData("");
			$dataval = $xml->addChild('menu');
			$dataval->addCData("");
			$dataval = $xml->addChild('menuOrder');
			$dataval->addCData("0");
			$dataval = $xml->addChild('menuStatus');
			$dataval->addCData("");
			$dataval = $xml->addChild('template');
			$dataval->addCData("search.php");
			$dataval = $xml->addChild('parent');
			$dataval->addCData("");
			$dataval = $xml->addChild('content');
			$dataval->addCData("");
			$dataval = $xml->addChild('private');
			$dataval->addCData("");
			$dataval = $xml->addChild('author');
			$dataval->addCData(isset($USR1)?$USR1:$USR);
			$xml->asXML(GSDATAPAGESPATH.'search.xml');
			if (function_exists('i18n_init')) {
				if (!file_exists(GSDATAPAGESPATH.'search_lt.xml')) {
					$xml = @new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
					$xml->addChild('pubDate', date(DATE_RFC2822));
					$dataval = $xml->addChild('title');
					$dataval->addCData("Paieška");
					$dataval = $xml->addChild('url');
					$dataval->addCData("search_lt");
					$dataval = $xml->addChild('meta');
					$dataval->addCData("");
					$dataval = $xml->addChild('metad');
					$dataval->addCData("");
					$dataval = $xml->addChild('menu');
					$dataval->addCData("");
					$dataval = $xml->addChild('menuOrder');
					$dataval->addCData("0");
					$dataval = $xml->addChild('menuStatus');
					$dataval->addCData("");
					$dataval = $xml->addChild('template');
					$dataval->addCData("search.php");
					$dataval = $xml->addChild('parent');
					$dataval->addCData("");
					$dataval = $xml->addChild('content');
					$dataval->addCData("");
					$dataval = $xml->addChild('private');
					$dataval->addCData("");
					$dataval = $xml->addChild('author');
					$dataval->addCData(isset($USR1)?$USR1:$USR);
					$xml->asXML(GSDATAPAGESPATH.'search_lt.xml');
				}
				if (!file_exists(GSDATAPAGESPATH.'search_ru.xml')) {
					$xml = @new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
					$xml->addChild('pubDate', date(DATE_RFC2822));
					$dataval = $xml->addChild('title');
					$dataval->addCData("?????");
					$dataval = $xml->addChild('url');
					$dataval->addCData("search_ru");
					$dataval = $xml->addChild('meta');
					$dataval->addCData("");
					$dataval = $xml->addChild('metad');
					$dataval->addCData("");
					$dataval = $xml->addChild('menu');
					$dataval->addCData("");
					$dataval = $xml->addChild('menuOrder');
					$dataval->addCData("0");
					$dataval = $xml->addChild('menuStatus');
					$dataval->addCData("");
					$dataval = $xml->addChild('template');
					$dataval->addCData("search.php");
					$dataval = $xml->addChild('parent');
					$dataval->addCData("");
					$dataval = $xml->addChild('content');
					$dataval->addCData("");
					$dataval = $xml->addChild('private');
					$dataval->addCData("");
					$dataval = $xml->addChild('author');
					$dataval->addCData(isset($USR1)?$USR1:$USR);
					$xml->asXML(GSDATAPAGESPATH.'search_ru.xml');
				}
			}
			
			$xml_file = @file_get_contents(GSDATAOTHERPATH.'pages.xml');
			$xml_pages = simplexml_load_string($xml_file, 'SimpleXMLExtended');
			if ($xml_pages) {
				$items = $xml_pages->addChild('item');
				$items->addChild('pubDate', date(DATE_RFC2822));
				$datavap = $items->addChild('title');
				$datavap->addCData("Search");
				$datavap = $items->addChild('url');
				$datavap->addCData("search");
				$datavap = $items->addChild('meta');
				$datavap->addCData("");
				$datavap = $items->addChild('metad');
				$datavap->addCData("");
				$datavap = $items->addChild('menu');
				$datavap->addCData("");
				$datavap = $items->addChild('menuOrder');
				$datavap->addCData("0");
				$datavap = $items->addChild('menuStatus');
				$datavap->addCData("");
				$datavap = $items->addChild('template');
				$datavap->addCData("search.php");
				$datavap = $items->addChild('parent');
				$datavap->addCData("");
				$datavap = $items->addChild('private');
				$datavap->addCData("");
				$datavap = $items->addChild('author');
				$datavap->addCData(isset($USR1)?$USR1:$USR);
				$datavap = $items->addChild('slug');
				$datavap->addCData("search");
				$datavap = $items->addChild('filename');
				$datavap->addCData("search.xml");
				if (function_exists('i18n_init')) {
					/*** LT ***/
					$items = $xml_pages->addChild('item');
					$items->addChild('pubDate', date(DATE_RFC2822));
					$datavap = $items->addChild('title');
					$datavap->addCData("Paieška");
					$datavap = $items->addChild('url');
					$datavap->addCData("search_lt");
					$datavap = $items->addChild('meta');
					$datavap->addCData("");
					$datavap = $items->addChild('metad');
					$datavap->addCData("");
					$datavap = $items->addChild('menu');
					$datavap->addCData("");
					$datavap = $items->addChild('menuOrder');
					$datavap->addCData("0");
					$datavap = $items->addChild('menuStatus');
					$datavap->addCData("");
					$datavap = $items->addChild('template');
					$datavap->addCData("search.php");
					$datavap = $items->addChild('parent');
					$datavap->addCData("");
					$datavap = $items->addChild('private');
					$datavap->addCData("");
					$datavap = $items->addChild('author');
					$datavap->addCData(isset($USR1)?$USR1:$USR);
					$datavap = $items->addChild('slug');
					$datavap->addCData("search_lt");
					$datavap = $items->addChild('filename');
					$datavap->addCData("search_lt.xml");
					/*** RU ***/
					$items = $xml_pages->addChild('item');
					$items->addChild('pubDate', date(DATE_RFC2822));
					$datavap = $items->addChild('title');
					$datavap->addCData("?????");
					$datavap = $items->addChild('url');
					$datavap->addCData("search_ru");
					$datavap = $items->addChild('meta');
					$datavap->addCData("");
					$datavap = $items->addChild('metad');
					$datavap->addCData("");
					$datavap = $items->addChild('menu');
					$datavap->addCData("");
					$datavap = $items->addChild('menuOrder');
					$datavap->addCData("0");
					$datavap = $items->addChild('menuStatus');
					$datavap->addCData("");
					$datavap = $items->addChild('template');
					$datavap->addCData("search.php");
					$datavap = $items->addChild('parent');
					$datavap->addCData("");
					$datavap = $items->addChild('private');
					$datavap->addCData("");
					$datavap = $items->addChild('author');
					$datavap->addCData(isset($USR1)?$USR1:$USR);
					$datavap = $items->addChild('slug');
					$datavap->addCData("search_ru");
					$datavap = $items->addChild('filename');
					$datavap->addCData("search_ru.xml");
				}
				$xml_pages->asXML(GSDATAOTHERPATH.'pages.xml');
			}
		}
	}
	
	function uncheck_data_search() {
		if (file_exists(GSDATAPAGESPATH.'search.xml')) {
			unlink(GSDATAPAGESPATH.'search.xml');
			$xml_file = @file_get_contents(GSDATAOTHERPATH.'pages.xml');
			$xml_pages = simplexml_load_string($xml_file, 'SimpleXMLExtended');
			$xml_pages_new = @new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><channel></channel>');
			if ($xml_pages) {
				foreach ($xml_pages as $item) {
					if ($item->template != "search.php") {
						$from_dom = dom_import_simplexml($item);
						$to_dom = dom_import_simplexml($xml_pages_new);
						$to_dom->appendChild($to_dom->ownerDocument->importNode($from_dom, true));
					}
				}
				$xml_pages_new->asXML(GSDATAOTHERPATH.'pages.xml');
			}
			$xml_file = @file_get_contents(GSDATAOTHERPATH.'i18n_menu_cache.xml');
			$xml_menu = simplexml_load_string($xml_file, 'SimpleXMLExtended');
			$xml_menu_new = @new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><pages></pages>');
			if ($xml_menu) {
				foreach ($xml_menu as $item) {
					if ($item->url != "search") {
						$from_dom = dom_import_simplexml($item);
						$to_dom = dom_import_simplexml($xml_menu_new);
						$to_dom->appendChild($to_dom->ownerDocument->importNode($from_dom, true));
					}
				}
				$xml_menu_new->asXML(GSDATAOTHERPATH.'i18n_menu_cache.xml');
			}
		}
		if (file_exists(GSDATAPAGESPATH.'search_lt.xml')) unlink(GSDATAPAGESPATH.'search_lt.xml');
		if (file_exists(GSDATAPAGESPATH.'search_ru.xml')) unlink(GSDATAPAGESPATH.'search_ru.xml');
	}
?>