<?

	class XSLTGenerator 
	{
		
		function XSLTGenerator()
		{}

		function execute()
		{
			global $cat_agents, $cat_skins, $cat_xslts;
	
			$s = '';
			$spool = array();

			foreach($cat_agents as $a) {
				eval('$agent = new '.$a.';');
				if(is_object($agent)) {
					$res = $agent->execute(); 
					if(is_array($res)) $p = array_merge($spool, $res);
					$spool = $p;
				};				
			}

			foreach($spool as $p) {
				if(is_object($p)) {
				  	$pat = $cat_xslts.'/root.xslt';						
					if(file_exists($pat)) {
						$p->applyXSLT(implode('',file($pat))); 
						$s .= $p->process();
						$p->pasteToFile("..");
						$s .= '<br>';
					};
				};
			}

			return $s;
		}

		function sync($table,$key,$val)
		{
			global $cat_skins, $cat_xslts;

			$a = new PublishAgent;
			if(is_object($a)) {
				$spool = array();
				eval('$spool = $a->'.$table.'Pub($key,$val);');	
				foreach($spool as $p) {
					if(is_object($p)) {
						foreach($cat_skins as $sk) {
							$pat = $cat_xslts.'/'.$sk.'.xslt';						
							if(file_exists($pat)) {
								$p->applyXSLT(implode('',file($pat))); 
								$s .= $p->process();
								$p->pasteToFile("../$sk");
							};
						}
					};
				}
			}

		}

		function clean($table,$key,$val)
		{
			global $cat_skins;

			$this->sync($table,$key,$val);
			$a = new PublishAgent;
			if(is_object($a)) {
				$l = $a->clean($table,$key,$val);			
				foreach($l as $f) {
					foreach($cat_skins as $sk) {
						if(file_exists('../'.$sk.'/'.$f)) unlink('../'.$sk.'/'.$f);
					}
				};
			};
		}

	};


?>