<?php
	function check_data_contact() {
		/*******************************************
			***      Create XML for Contact form     ***
			***             if not exist             ***
		********************************************/
		if (!file_exists(GSDATAPAGESPATH.'contact.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("Contacts");
			$dataval = $xml->addChild('url');
			$dataval->addCData("contact");
			$dataval = $xml->addChild('meta');
			$dataval->addCData("");
			$dataval = $xml->addChild('metad');
			$dataval->addCData("");
			$dataval = $xml->addChild('menu');
			$dataval->addCData("Contacts");
			$dataval = $xml->addChild('menuOrder');
			$dataval->addCData($curr_order);
			$dataval = $xml->addChild('menuStatus');
			$dataval->addCData("Y");
			$dataval = $xml->addChild('template');
			$dataval->addCData("contact.php");
			$dataval = $xml->addChild('parent');
			$dataval->addCData("");
			$dataval = $xml->addChild('content');
			$dataval->addCData("E-message sending form");
			$dataval = $xml->addChild('private');
			$dataval->addCData("");
			$dataval = $xml->addChild('author');
			$dataval->addCData(isset($USR1)?$USR1:$USR);
			$xml->asXML(GSDATAPAGESPATH.'contact.xml');
			if (function_exists('i18n_init')) {
				if (!file_exists(GSDATAPAGESPATH.'contact_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("Kontaktai");
					$dataval = $xml->addChild('url');
					$dataval->addCData("contact_lt");
					$dataval = $xml->addChild('meta');
					$dataval->addCData("");
					$dataval = $xml->addChild('metad');
					$dataval->addCData("");
					$dataval = $xml->addChild('menu');
					$dataval->addCData("Kontaktai");
					$dataval = $xml->addChild('menuOrder');
					$dataval->addCData("0");
					$dataval = $xml->addChild('menuStatus');
					$dataval->addCData("Y");
					$dataval = $xml->addChild('template');
					$dataval->addCData("contact.php");
					$dataval = $xml->addChild('parent');
					$dataval->addCData("");
					$dataval = $xml->addChild('content');
					$dataval->addCData("El. pranešimu siuntimo forma");
					$dataval = $xml->addChild('private');
					$dataval->addCData("");
					$dataval = $xml->addChild('author');
					$dataval->addCData(isset($USR1)?$USR1:$USR);
					$xml->asXML(GSDATAPAGESPATH.'contact_lt.xml');
				}
				if (!file_exists(GSDATAPAGESPATH.'contact_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("contact_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("Y");
					$dataval = $xml->addChild('template');
					$dataval->addCData("contact.php");
					$dataval = $xml->addChild('parent');
					$dataval->addCData("");
					$dataval = $xml->addChild('content');
					$dataval->addCData("E-форма отправки сообщений");
					$dataval = $xml->addChild('private');
					$dataval->addCData("");
					$dataval = $xml->addChild('author');
					$dataval->addCData(isset($USR1)?$USR1:$USR);
					$xml->asXML(GSDATAPAGESPATH.'contact_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("Contact");
				$datavap = $items->addChild('url');
				$datavap->addCData("contact");
				$datavap = $items->addChild('meta');
				$datavap->addCData("");
				$datavap = $items->addChild('metad');
				$datavap->addCData("");
				$datavap = $items->addChild('menu');
				$datavap->addCData("Contact");
				$datavap = $items->addChild('menuOrder');
				$datavap->addCData($curr_order);
				$datavap = $items->addChild('menuStatus');
				$datavap->addCData("Y");
				$datavap = $items->addChild('template');
				$datavap->addCData("contact.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("contact");
				$datavap = $items->addChild('filename');
				$datavap->addCData("contact.xml");
				if (function_exists('i18n_init')) {
					/*** LT ***/
					$items = $xml_pages->addChild('item');
					$items->addChild('pubDate', date(DATE_RFC2822));
					$datavap = $items->addChild('title');
					$datavap->addCData("Kontaktai");
					$datavap = $items->addChild('url');
					$datavap->addCData("contact_lt");
					$datavap = $items->addChild('meta');
					$datavap->addCData("");
					$datavap = $items->addChild('metad');
					$datavap->addCData("");
					$datavap = $items->addChild('menu');
					$datavap->addCData("Kontaktai");
					$datavap = $items->addChild('menuOrder');
					$datavap->addCData("0");
					$datavap = $items->addChild('menuStatus');
					$datavap->addCData("Y");
					$datavap = $items->addChild('template');
					$datavap->addCData("contact.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("contact_lt");
					$datavap = $items->addChild('filename');
					$datavap->addCData("contact_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("contact_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("Y");
					$datavap = $items->addChild('template');
					$datavap->addCData("contact.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("contact_ru");
					$datavap = $items->addChild('filename');
					$datavap->addCData("contact_ru.xml");
				}
				$xml_pages->asXML(GSDATAOTHERPATH.'pages.xml');
			}
			if (function_exists('i18n_init')) {
				$xml_file = @file_get_contents(GSDATAOTHERPATH.'i18n_menu_cache.xml');
				$xml_menu = simplexml_load_string($xml_file, 'SimpleXMLExtended');
				if ($xml_menu) {
					$items = $xml_menu->addChild('page');
					$datavam = $items->addChild('url');
					$datavam->addCData("contact");
					$datavam = $items->addChild('menuStatus');
					$datavam->addCData("Y");
					$datavam = $items->addChild('menuOrder');
					$datavam->addCData($curr_order);
					$datavam = $items->addChild('menu');
					$datavam->addCData("Contact");
					$datavam = $items->addChild('title');
					$datavam->addCData("Contact");
					$datavam = $items->addChild('parent');
					$datavam->addCData("");
					$datavam = $items->addChild('private');
					$datavam->addCData("");
					$datavam = $items->addChild('tags');
					$datavam->addCData("");
					$datavam = $items->addChild('menu_lt');
					$datavam->addCData("Kontaktai");
					$datavam = $items->addChild('title_lt');
					$datavam->addCData("Kontaktai");
					$datavam = $items->addChild('menu_ru');
					$datavam->addCData("Контакты");
					$datavam = $items->addChild('title_ru');
					$datavam->addCData("Контакты");
				}
				$xml_menu->asXML(GSDATAOTHERPATH.'i18n_menu_cache.xml');
			}
		}
	}
	
	function uncheck_data_contact() {
		if (file_exists(GSDATAPAGESPATH.'contact.xml')) {
			unlink(GSDATAPAGESPATH.'contact.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 != "contact.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 != "contact") {
						$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.'contact_lt.xml')) unlink(GSDATAPAGESPATH.'contact_lt.xml');
		if (file_exists(GSDATAPAGESPATH.'contact_ru.xml')) unlink(GSDATAPAGESPATH.'contact_ru.xml');
	}
?>