<?php
/*
	DevSaver Web Framework
	Copyright (c) 2013-2016 DevSaver. 
	All rights reserved.
		web:  www.devsaver.com
		mail: support@devsaver.com				
*/


if ($_GET["action"] == "export") {

		$modules = $this->db->QFetchRowArray(
			"SELECT * FROM 
				{$this->tables['core:modules']} 
			");

		if (is_Array($modules)) {
			foreach ($modules as $key => $val) {

				$settings = $this->db->QFetchRowArray("
					SELECT * FROM 
						{$this->tables['core:modules_settings']} 
					WHERE 
						module='{$val[module_code]}' AND 
						type=2 
					ORDER BY setting ASC
				");

				if (is_array($settings)) {
					$l = array();
					$s = array();

					foreach ($settings as $k => $v) {
						if (stristr($v["setting"] , "lang_")) {
							$l[$v["setting"]] = $v["value"];
						} else {
							$s[$v["setting"]] = $v["value"];
						}						
					}

					$html = "
			<data>
				<settings>
";

					if (is_array($s)) {
						foreach ($s as $k => $v) {
							$html .="\n\t\t\t\t\t<{$k}>{$v}</{$k}>";
						}						
					}
					$html .= "
				</settings>";
					
					$html .= "
				<language>";

					if (is_array($l)) {
						foreach ($l as $k => $v) {
							if($v != strip_tags($v)) {
								$v = "<![CDATA[{$v}]]>";
							}

							$html .="\n\t\t\t\t\t<{$k}>{$v}</{$k}>";
						}						
					}

					$html .= "
				</language>";

					$html .= "
			</data>
";
				

					CFile::Save("xml/" . $val["module_code"] . ".xml" , $html);
				}
				
				

			}
			
		}
		

		$modules = $this->db->QFetchRowArray(
			"SELECT * FROM 
				{$this->tables['core:user_modules']} 
			");

		if (is_Array($modules)) {
			foreach ($modules as $key => $val) {

				

				$settings = $this->db->QFetchRowArray("
					SELECT * FROM 
						{$this->tables['core:modules_settings']} 
					WHERE 
						module='{$val[mod_id]}' AND 
						type=2 
					ORDER BY setting ASC
				");

				if (is_array($settings)) {
					$l = array();
					$s = array();

					foreach ($settings as $k => $v) {
						if (stristr($v["setting"] , "lang_")) {
							$l[$v["setting"]] = $v["value"];
						} else {
							$s[$v["setting"]] = $v["value"];
						}						
					}

				if ($val["mod_id"] == "2090") {

				}


					$html = "
			<data>
				<settings>
";

					if (is_array($s)) {
						foreach ($s as $k => $v) {
							$html .="\n\t\t\t\t\t<{$k}>{$v}</{$k}>";
						}						
					}
					$html .= "
				</settings>";
					
					$html .= "
				<language>";

					if (is_array($l)) {
						foreach ($l as $k => $v) {
							if($v != strip_tags($v)) {
								$v = "<![CDATA[{$v}]]>";
							}

							$html .="\n\t\t\t\t\t<{$k}>{$v}</{$k}>";
						}						
					}

					$html .= "
				</language>";

					$html .= "
			</data>
";
				

					CFile::Save("xml/_" . $val["mod_id"] . ".xml" , $html);
				}
				
				

			}
			
		}


}



?>