<?php 

class PackageManagerView extends Slot {

	var $SectionID = 41;
	var $ModuleID = 4;
	var $servers = array();
	var $presets = array();
	var $packages = array();
	var $package = array(
		'id' => '',
		'uid' => '',
		'actioned' => 0,
		'name' => '',
		'comment' => '',
		'engine_version' => '',
		'items' => array(),
		'publish' => array(),
		'flush' => false,
	);
	var $publish_type = array();
	var $pages = array();
	var $layouts = array();
	var $menus = array();
	var $templates = array();
	var $files = array();
	var $importedfeeds = array();
	var $feeds = array();
	var $categories = array();
	var $publishable = true;
	var $access = true;
	var $report_type = array();
	var $life_time = 45; // Days
	var $report_receivers = array();
	var $publishable_page_types = array(1, 3, 6, 8, 9,);
	var $flush_pathes = array();
	var $MailTemplate = array();
	var $search_conditions = array(
		'not_older' => '0',
		'published' => '0',
		'inpublished' => '0',
		'contained' => array(),
	);
	var $founded_packages = array();
	var $search_time_intervals = array('X' => '0', '3 days' => '259200', '1 week' => '604800', '10 days' => '864000', '2 weeks' => '1209600', '3 weeks' => '1814400', '1 month' => '2592000', '2 months' => '5184000', '3 months' => '7776000',); // Seconds
	var $autoflush = array();
	var $old_packages = array();
	var $referer = '';

	function __construct($pquery) {
		parent::__construct($pquery);
	}

	function init() {
		GLOBAL $ROOT_PATH, $TOOLS_PATH, $CORE_PATH, $COMMON_VARS, $MailBroker, $REGISTRY;
		if(!empty($this->Request['form']['referer'])) $this->referer = $this->Request['form']['referer'];
		else{
			$this->referer = parse_url(getenv('HTTP_REFERER'));
			$this->referer = $this->referer['path'];
		}
		if(empty($this->referer) || strpos($this->referer, '/Registar/PackageManager') === 0) $this->referer = '/Registar/PackageManager';
		$this->packages = $this->Action->Server->getGuide('package');
		if(!empty($this->LocalTarget[0]) && !is_numeric($this->LocalTarget[0])){
			if(empty($this->LocalTarget[1])){
				if($this->LocalTarget[0] != 'Add' && $this->LocalTarget[0] != 'AddItem' && $this->LocalTarget[0] != 'Search' && $this->LocalTarget[0] != 'DeleteOld') return $this->terminateAction();
			}
			else if(!array_key_exists($this->LocalTarget[1], $this->packages)) return $this->terminateAction();
			if($this->LocalTarget[0] == 'AddItem' && empty($this->Request['form']['adds'])) return $this->terminateAction();
		}
		if($this->server_type == 'pro' && !empty($this->LocalTarget[0]) && !is_numeric($this->LocalTarget[0]) && $this->LocalTarget[0] != 'Lock' && $this->LocalTarget[0] != 'Unlock' && $this->LocalTarget[0] != 'Look' && $this->LocalTarget[0] != 'DeleteOld') return $this->terminateAction();
		switch(@$this->LocalTarget[0]) {
			case 'Lock': {
				$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->LocalTarget[1]), $this);
				if (empty($this->PreparedTemplates['access_flag'])) $this->Action->processEvent($this->SectionID, 'lock', array('id' => $this->LocalTarget[1], 'member' => $this->Action->Security->currentuser->id,), $this);
				return $this->terminateAction();
				break;
			}
			case 'Unlock': {
				$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->LocalTarget[1]), $this);
				if ($this->PreparedTemplates['access_flag'] == $this->Action->Security->currentuser->id) $this->Action->processEvent($this->SectionID, 'unlock', array('id' => $this->LocalTarget[1],), $this);
				return $this->terminateAction();
				break;
			}
			case 'Update': case 'Delete': {
				$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->LocalTarget[1]), $this);
				$actioned = $this->PreparedTemplates['actioned'];
				if($actioned && ($this->LocalTarget[0] == 'Update' || ($this->LocalTarget[0] == 'Delete' && $this->PreparedTemplates['last_date_published'] <= $this->life_time))) return $this->terminateAction();
				else{
					if (empty($this->PreparedTemplates['access_flag'])) $this->Action->processEvent($this->SectionID, 'lock', array('id' => $this->LocalTarget[1], 'member' => $this->Action->Security->currentuser->id,), $this);
					else if ($this->PreparedTemplates['access_flag'] != $this->Action->Security->currentuser->id) return $this->terminateAction();
				}
				if($this->LocalTarget[0] == 'Delete' || ($this->LocalTarget[0] == 'Update' && empty($this->Request))){
					if($actioned) $this->Action->processEvent($this->SectionID, 'get_actioned_package', array('id' => $this->LocalTarget[1], 'action' => $this->LocalTarget[0],), $this);
					else $this->Action->processEvent($this->SectionID, 'get_package', array('id' => $this->LocalTarget[1], 'action' => $this->LocalTarget[0],), $this);
					$this->package = $this->PreparedTemplates;
				}
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				if($this->LocalTarget[0] == 'Update') $this->initAdds();
				$this->clearAllTemplates();
				$this->Scheme = 'action';
				break;
			}
			case 'Add': {
				$this->package['actioned'] = 0;
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				$this->initAdds();
				$this->Action->processEvent($this->SectionID, 'select_presets', array(), $this);
				$this->servers = $this->PreparedTemplates;
				$this->clearAllTemplates();
				$this->Scheme = 'action';
				break;
			}
			case 'Duplicate': {
				$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->LocalTarget[1]), $this);
				if (!empty($this->PreparedTemplates['access_flag']) && $this->PreparedTemplates['access_flag'] != $this->Action->Security->currentuser->id) return $this->terminateAction();
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				$this->Action->processEvent($this->SectionID, 'get_package', array('id' => $this->LocalTarget[1], 'action' => $this->LocalTarget[0],), $this);
				$this->package = $this->PreparedTemplates;
				$this->package['id'] = '';
				$this->package['actioned'] = 0;
				$this->package['name'] = '';
				$this->package['publish'] = array();
				$this->initAdds();
				$this->clearAllTemplates();
				$this->Scheme = 'action';
				break;
			}
			case 'AddItem': {
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				$this->initAdds();
				if(empty($this->Request['sbtAddItem'])){
					$adds_keys = array_keys($this->Request['form']['adds']);
					$count = count($adds_keys);
					for ($i = 0; $i < $count; $i++) $this->Request['form']['adds'][$adds_keys[$i]] = array_unique($this->Request['form']['adds'][$adds_keys[$i]]);
					$this->Action->processEvent($this->SectionID, 'select', array('all_addable' => true, 'user' => $this->Action->Security->currentuser->id,), $this);
				}
				else if(empty($this->Request['form']['package'])) return $this->terminateAction();
				else{
					$preparedTemplates = array();
					$count = count($this->Request['form']['package']);
					for($i = 0; $i < $count; $i++){
						$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->Request['form']['package'][$i]), $this);
						$preparedTemplates[] = $this->PreparedTemplates;
					}
					$this->PreparedTemplates = $preparedTemplates;
					unset($preparedTemplates);
				}
				$this->Scheme = 'add';
				break;
			}
			case 'Look': {
				$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->LocalTarget[1], 'action' => $this->LocalTarget[0]), $this);
				$actioned = $this->PreparedTemplates['actioned'];
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				if($actioned) $this->Action->processEvent($this->SectionID, 'get_actioned_package', array('id' => $this->LocalTarget[1], 'check_for_update' => true), $this);
				else $this->Action->processEvent($this->SectionID, 'get_package', array('id' => $this->LocalTarget[1]), $this);
				$this->package = $this->PreparedTemplates;
				if($this->package['actioned']){
					$this->Action->processEvent($this->SectionID, 'select_report_types', array(), $this);
					$this->report_type = $this->PreparedTemplates;
				}
				$this->clearAllTemplates();
				$this->Scheme = 'action';
				break;
			}
			case 'DeleteOld': {
				$this->clearAllTemplates();
				$this->Scheme = 'deleteold';
				break;
			}
			case 'Publish': {
				$this->Action->processEvent($this->SectionID, 'get_access', array('id' => $this->LocalTarget[1], 'action' => $this->LocalTarget[0]), $this);
				$actioned = $this->PreparedTemplates['actioned'];
				if (empty($this->PreparedTemplates['access_flag'])) $this->Action->processEvent($this->SectionID, 'lock', array('id' => $this->LocalTarget[1], 'member' => $this->Action->Security->currentuser->id,), $this);
				else if ($this->PreparedTemplates['access_flag'] != $this->Action->Security->currentuser->id) return $this->terminateAction();
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				$this->Action->processEvent($this->SectionID, 'select_report_types', array(), $this);
				$this->report_type = $this->PreparedTemplates;
				if($actioned) $this->Action->processEvent($this->SectionID, 'get_actioned_package', array('id' => $this->LocalTarget[1]), $this);
				else $this->Action->processEvent($this->SectionID, 'get_package', array('id' => $this->LocalTarget[1]), $this);
				$this->package = $this->PreparedTemplates;
				$this->Action->processEvent($this->SectionID, 'select_presets', array('changed_urls_check' => true,), $this);
				$this->servers = $this->PreparedTemplates;
				$this->clearAllTemplates();
				$this->Scheme = 'action';
				break;
			}
			case 'Search': {
				$this->Action->processEvent($this->SectionID, 'select_publish_types', array(), $this);
				$this->publish_type = $this->PreparedTemplates;
				$this->clearAllTemplates();
				$this->Scheme = 'search';
				break;
			}
			default: {
				$request = array();
				$request['pageRecordsQty'] = 50;
				$request['curPageNumber'] = isset($this->LocalTarget[0]) ? $this->LocalTarget[0] + 1 : 1;
				$this->Action->processEvent($this->SectionID, 'select', $request, $this);
				$this->Scheme = 'default';
				break;
			}
		}
		if(empty($this->Request)){
			$this->setSchemeTemplate($this->Scheme);
			return;
		}
		switch(@$this->LocalTarget[0]) {
			case 'Update': case 'Add': case 'Duplicate': {
				if(isset($this->Request['form']['items'])) $this->Request['form']['items'] = array_values($this->Request['form']['items']);
				else $this->Request['form']['items'] = array();
				if(!isset($this->Request['form']['adds'])) $this->Request['form']['adds'] = array();
				$types = array_keys($this->Request['form']['adds']);
				$count_types = count($types);
				$count_items = count($this->Request['form']['items']);
				for($i = 0; $i < $count_types; $i++){
					$c = count($this->Request['form']['adds'][$types[$i]]);
					for ($j = 0; $j < $c; $j++){
						for ($k = 0; $k < $count_items; $k++)
							if($this->Request['form']['items'][$k]['object'] == $this->Request['form']['adds'][$types[$i]][$j] && $this->Request['form']['items'][$k]['type'] == $types[$i]) continue 2;
						$this->Request['form']['items'][$count_items] = array(
							'id' => ($count_items + 1),
							'ownerid' => @$this->Request['form']['id'],
							'type' => $types[$i],
							'object' => $this->Request['form']['adds'][$types[$i]][$j],
						);
						$count_items++;
					}
				}
				unset($this->Request['form']['adds']);
				$this->package = $this->Request['form'];
				if(empty($this->Request['form']['compose']) && $this->validateForm()){
					if ($this->Action->processEvent($this->SectionID, 'save', $this->package, $this)){
						if($this->Request['form']['andPublish']) {
							$this->referer = '/Registar/PackageManager/Publish/'.$this->PreparedTemplates['id'];
							return $this->terminateAction();
						}
						if($this->LocalTarget[0] == 'Update') $this->Action->processEvent($this->SectionID, 'unlock', $this->package, $this);
						return $this->terminateAction();
					}
					else $this->errors['validate'] = $this->PreparedTemplates['_error'];
				}
				else{
					$this->Action->processEvent($this->SectionID, 'get_package', array('id' => @$this->LocalTarget[1], 'action' => $this->LocalTarget[0], 'requested' => $this->package), $this);
					$this->package = $this->PreparedTemplates;
				}
				$this->clearAllTemplates();
				break;
			}
			case 'Delete': {
				$this->package['_error'] = '';
				if($this->Action->processEvent($this->SectionID, 'delete', $this->package, $this)) return $this->terminateAction();
				else $this->errors['validate'] = $this->PreparedTemplates['_error'];
				$this->clearAllTemplates();
				break;
			}
			case 'AddItem': {
				if(empty($this->Request['sbtAddItem'])) break;
				$packages = $this->PreparedTemplates;
				$count = count($packages);
				$types = array_keys($this->Request['form']['adds']);
				$count_types = count($types);
				for($l = 0; $l < $count; $l++){
					if(!empty($packages[$l]['actioned']) || (!empty($packages[$l]['access_flag']) && $packages[$l]['access_flag'] != $this->Action->Security->currentuser->id) || !isset($this->packages[$packages[$l]['id']])) continue;
					$this->Action->processEvent($this->SectionID, 'open', array('id' => $packages[$l]['id'], 'nopublish' => true,), $this);
					$package = $this->PreparedTemplates;
					$count_items = count($package['items']);
					for($i = 0; $i < $count_types; $i++){
						$c = count($this->Request['form']['adds'][$types[$i]]);
						for ($j = 0; $j < $c; $j++){
							for ($k = 0; $k < $count_items; $k++)
								if($package['items'][$k]['object'] == $this->Request['form']['adds'][$types[$i]][$j] && $package['items'][$k]['type'] == $types[$i]) continue 2;
							$this->Action->processEvent($this->SectionID, 'save_item', array('ownerid' => $package['id'], 'type' => $types[$i], 'object' => $this->Request['form']['adds'][$types[$i]][$j], 'parent' => '0',), $this);
						}
					}
					$this->Db->update('package', array('date_changed' => 'now'), array('id' => $this->PreparedTemplates['id']));
					$this->Action->processEvent($this->SectionID, 'log', array('type' => 4, 'entity' => 14, 'event' => 12, 'value' => 'Edit prepublishing package "'.$package['name'].'" ['.$package['id'].']'), $this);
				}
				$this->PreparedTemplates = $packages;
				break;
			}
			case 'Search': {
				if(!isset($this->Request['form']['contained'])) $this->Request['form']['contained'] = array();
				$this->search_conditions = $this->Request['form'];
				$this->Action->processEvent($this->SectionID, 'search', $this->search_conditions, $this);
				$this->founded_packages = $this->PreparedTemplates;
				break;
			}
			case 'DeleteOld': {
				$this->Action->processEvent($this->SectionID, 'delete_old_packages', array('life_time' => $this->life_time), $this);
				$this->old_packages = $this->PreparedTemplates;
				break;
			}
			case 'Publish': {
				$this->Scheme = 'publish';
				$this->Action->processEvent($this->SectionID, 'select_report_receivers', array(), $this);
				$this->report_receivers = $this->PreparedTemplates;
				$this->errors = array('validate' => array(), 'dump' => array(),);
				if(!isset($this->Request['form']['servers'])) $this->Request['form']['servers'] = array();
				if(!isset($this->Request['form']['groups'])) $this->Request['form']['groups'] = array();
				if(!isset($this->Request['form']['servers_flush'])) $this->Request['form']['servers_flush'] = array();
				if(!isset($this->Request['form']['groups_flush'])) $this->Request['form']['groups_flush'] = array();
				if(empty($this->Request['form']['servers']) && empty($this->Request['form']['groups'])) break;
				$this->initItemEmptyID();
				if(!$this->package['actioned']){
					$this->package['engine_version'] = $REGISTRY['Core']['EngineVersion'];
					if(!$this->validatePublish()) break;
					if (!$this->dumpPackage()) break;
					$this->package['actioned'] = 1;
					$this->Action->processEvent($this->SectionID, 'save', $this->package, $this);
				}
				$this->package['publish'] = array();
				eval(file_get_contents($CORE_PATH.'/signature.inc'));
				foreach($this->Request['form']['servers'] as $value){
					$this->package['publish'][$value] = array('ownerid' => $this->package['id'], 'host' => $value, 'date_published' => 'now', 'type' => 1, 'flush' => (in_array($value, $this->Request['form']['servers_flush']) ? 1 : 0), 'userid' => $this->Action->Security->currentuser->id, 'error' => array(), 'report' => array(), 'flush_pathes' => array(),);
					foreach($this->servers['1']['presets'] as $val){
						if ($val['id'] != $value) continue;
						$CheckRemoteServer = new CheckRemoteServer($val);
						if($CheckRemoteServer->preActionCheck($signature['type_server'], 30)){
							$this->presets[] = $val;
							if($CheckRemoteServer->getServerPriorityType() == 'pro') $this->package['publish'][$value]['final'] = 1;
						}
						else{
							foreach($CheckRemoteServer->errors as $v) $this->package['publish'][$value]['error'][] = array('error' => $v);
							$this->Action->processEvent($this->SectionID, 'save_publish', $this->package['publish'][$val['id']], $this);
							$this->package['publish'][$val['id']] = $this->PreparedTemplates;
							$this->addToMailTemplate(array('hostname' => $val['name'], 'hostpath' => $val['path'], 'result' => 'Failed',));
						}
						break;
					}
				}
				foreach($this->Request['form']['groups'] as $value){
					if(empty($this->servers[$value])) continue;
					$check = true;
					$flush = in_array($value, $this->Request['form']['groups_flush']) ? 1 : 0;
					foreach($this->servers[$value]['presets'] as $val){
						$this->package['publish'][$val['id']] = array('ownerid' => $this->package['id'], 'host' => $val['id'], 'date_published' => 'now', 'type' => 1, 'flush' => $flush, 'userid' => $this->Action->Security->currentuser->id,  'error' => array(), 'report' => array());
						$CheckRemoteServer = new CheckRemoteServer($val);
						if($CheckRemoteServer->preActionCheck($signature['type_server'], 30)){
							if($CheckRemoteServer->getServerPriorityType() == 'pro') $this->package['publish'][$val['id']]['final'] = 1;
						}
						else {
							$check = false;
							foreach($CheckRemoteServer->errors as $v) $this->package['publish'][$val['id']]['error'][] = array('error' => $v);
							$this->addToMailTemplate(array('hostname' => $val['name'], 'hostpath' => $val['path'], 'result' => 'Failed',));
						}
					}
					if($check) $this->presets = array_merge($this->presets, $this->servers[$value]['presets']);
					else foreach($this->servers[$value]['presets'] as $val){
						if(empty($this->package['publish'][$val['id']]['error'])){
							$this->package['publish'][$val['id']]['error'][] = array('error' => 'Some server from the same PreSet group doesn\'t responding');
							$this->addToMailTemplate(array('hostname' => $val['name'], 'hostpath' => $val['path'], 'result' => 'Failed',));
						}
						$this->Action->processEvent($this->SectionID, 'save_publish', $this->package['publish'][$val['id']], $this);
						$this->package['publish'][$val['id']] = $this->PreparedTemplates;
					}
				}
				$this->package['flush'] = false;
				foreach ($this->presets as $key => $value){
					if(empty($this->package['publish'][$value['id']]['error']) && $this->transferPackage($value)){
						if(!empty($this->package['publish'][$value['id']]['flush'])) $this->package['flush'] = true;
						$this->launchScript($value);
						$info = $this->getReport($value);
						$result = end($this->package['publish'][$value['id']]['report']);
						if($result['type'] == array_search('Good', $this->report_type)) $this->package['publish'][$value['id']]['successful'] = 1;
						$this->putRemoteReport($value, $info);
						$this->addToMailTemplate(array('hostname' => $value['name'], 'hostpath' => $value['path'], 'result' => @$this->package['publish'][$value['id']]['successful'] == 1 ? 'Successful' : 'Failed',));
						if(@$this->package['publish'][$value['id']]['successful'] == 1){
							$this->Action->processEvent($this->SectionID, 'delete_changed_url', array('preset' => $value['id'], 'objects' => $this->package['items']), $this);
							$this->Action->processEvent($this->SectionID, 'add_deleted_objects', array('preset' => $value['id'], 'objects' => $this->package['items']), $this);
						}
						$this->Action->processEvent($this->SectionID, 'log', array('type' => 4, 'entity' => 14, 'event' => 14, 'value' => 'Publish package "'.$this->package['name'].'" ['.$this->package['id'].'] to "'.$value['name'].'"'), $this);
					}
					$this->Action->processEvent($this->SectionID, 'save_publish', $this->package['publish'][$value['id']], $this);
					$this->package['publish'][$value['id']] = $this->PreparedTemplates;
				}
				$this->Action->processEvent($this->SectionID, 'unlock', array('id' => $this->LocalTarget[1],), $this);
				if(empty($this->flush_pathes)) $MailBroker->sendMail('publish', $this->report_receivers, $this->MailTemplate);
				else {
					if($this->package['flush']) $this->launchFlushPathsScript();
					$MailBroker->sendMail('publish', $this->report_receivers, $this->MailTemplate, '', false, array(array('type' => 'text/plain', 'filename' => $this->package['name'].'.txt', 'content' => implode("\r\n", $this->flush_pathes),),));
				}
				break;
			}
		}
		$this->setSchemeTemplate($this->Scheme);
	}
	
	function initAdds(){
		$this->Action->processEvent($this->SectionID, 'select_pages', array(), $this);
		$this->setPageArray($this->PreparedTemplates[0]);
		$this->layouts = $this->Action->Server->getGuide('layout');
		$this->templates = $this->Action->Server->getGuide('template');
		$this->menus['left'] = $this->Action->Server->getGuide('leftmenu');
		$this->menus['right'] = $this->Action->Server->getGuide('rightmenu');
		$this->menus['bottom'] = $this->Action->Server->getGuide('bottommenu');
		$this->menus['tabs'] = $this->Action->Server->getGuide('tabsmenu');
		$this->menus['sitemap'] = array('1' => 'Site Map',);
		$this->Action->processEvent($this->SectionID, 'select_files', array(), $this);
		$this->files = $this->PreparedTemplates;
		$this->subdomains = $this->Action->Server->getGuide('subdomain');
		$this->importedfeeds = $this->Action->Server->getGuide('importedfeed');
		$this->feeds = $this->Action->Server->getGuide('feed');
		$this->cities = $this->Action->Server->getGuide('city');
		$this->categories = $this->Action->Server->getGuide('category');
	}

	function fillElements() {
		switch($this->Scheme) {
			case 'default': $this->fillDefault(); break;
			case 'action': $this->fillAction(); break;
			case 'publish': $this->fillPublish(); break;
			case 'add': $this->fillAddItem(); break;
			case 'search': $this->fillSearch(); break;
			case 'deleteold': $this->fillDeleteOldPackages(); break;
		}
	}
	
	function validateForm(){
		if (in_array($this->Request['form']['name'], $this->packages) && array_search($this->Request['form']['name'], $this->packages) != $this->Request['form']['id'])
			$this->errors['other'] = 'Package with such name and different id already exists';
		if(!is_NumText($this->Request['form']['name'], 1, 128))
			$this->errors['name'] = 'Package Name is not valid';
		if(!is_NumText($this->Request['form']['comment'], 1, 256))
			$this->errors['comment'] = 'Comment is not valid';
		if (empty($this->Request['form']['items']))
			$this->errors['other'] = 'Package is empty';
		if(count($this->errors) > 0){
			$this->publishable = false; 
			return false;
		}
		else return true;
	}
	
	function validatePublish(){
		$flag = true;
		if(!empty($this->package['_error'])){
			$this->errors['validate'][] = array(
				'type' => 'Package',
				'id' => $this->package['id'],
				'name' => $this->package['name'],
				'_error' => $this->package['_error'],
			);
			return false;
		}
		if(!empty($this->package['access_flag']) && $this->package['access_flag'] != $this->Action->Security->currentuser->id){
			$this->errors['validate'][] = array(
				'type' => 'Package',
				'id' => $this->package['id'],
				'name' => $this->package['name'],
				'_error' => $this->package['_error'],
			);
			$flag = false;
		}
		$count = count($this->package['items']);
		for ($i = 0; $i < $count; $i++){
			if(!empty($this->package['items'][$i]['objectfields']['_error'])){
				$this->errors['validate'][] = array(
					'type' => $this->publish_type[$this->package['items'][$i]['type']]['title'],
					'id' => $this->package['items'][$i]['objectfields']['id'],
					'name' => $this->package['items'][$i]['objectfields']['name'],
					'_error' => $this->package['items'][$i]['objectfields']['_error'],
				);
				$flag = false;
				continue;
			}
			if(!empty($this->package['items'][$i]['objectfields']['access_flag']) && $this->package['items'][$i]['objectfields']['access_flag'] != $this->Action->Security->currentuser->id){
				$this->errors['validate'][] = array(
					'type' => $this->publish_type[$this->package['items'][$i]['type']]['title'],
					'id' => $this->package['items'][$i]['objectfields']['id'],
					'name' => $this->package['items'][$i]['objectfields']['name'],
					'_error' => 'Locked by '.$this->package['items'][$i]['objectfields']['username'].' ['.$this->package['items'][$i]['objectfields']['date_locked'].']',
				);
				$flag = false;
			}
		}
		return $flag;
	}

	function fillDefault() {
		GLOBAL $REGISTRY;
		$this->TempFillEls['btnAddPackage_vis'] = $this->server_type == 'pro' ? 'hidden' : 'visible';
		$current_time = time();
		$count = count($this->PreparedTemplates['curPage']);
		for ($i = 0; $i < $count; $i++){
			$this->TempFillEls['publish'][]['variable'] = 'publish['.$this->PreparedTemplates['curPage'][$i]['id'].']=[];';
			$count_pub = count($this->PreparedTemplates['curPage'][$i]['publish']);
			for ($j = 0; $j < $count_pub; $j++){
				$this->TempFillEls['publish'][]['variable'] = 'publish['.$this->PreparedTemplates['curPage'][$i]['id'].']['.$j.'] = [];';
				foreach ($this->PreparedTemplates['curPage'][$i]['publish'][$j] as $k => $v)
					$this->TempFillEls['publish'][]['variable'] = 'publish['.$this->PreparedTemplates['curPage'][$i]['id'].']['.$j.']["'.$k.'"]="'.$v.'";';
			}
			$pack_eng_v = explode('.', $this->PreparedTemplates['curPage'][$i]['engine_version']);
			$eng_v = explode('.', $REGISTRY['Core']['EngineVersion']);
			$btnPublish_vis = $this->PreparedTemplates['curPage'][$i]['actioned'] && ($pack_eng_v[0] != $eng_v[0] || $pack_eng_v[1] != $eng_v[1]) ? 'hidden' : 'visible';
			$this->TempFillEls['package'][$i] = array(
				'id' => $this->PreparedTemplates['curPage'][$i]['id'],
				'name' => $this->PreparedTemplates['curPage'][$i]['name'],
				'uid' => $this->PreparedTemplates['curPage'][$i]['uid'],
				'engine_version' => $this->PreparedTemplates['curPage'][$i]['actioned'] ? 'Engine Version: '.($this->PreparedTemplates['curPage'][$i]['engine_version'] ? $this->PreparedTemplates['curPage'][$i]['engine_version'] : 'not specified') : '',
				'btnPublish_vis' => $btnPublish_vis,
				'username' => $this->PreparedTemplates['curPage'][$i]['username'],
				'date_locked' => $this->PreparedTemplates['curPage'][$i]['date_locked'],
			);
			if(empty($this->PreparedTemplates['curPage'][$i]['access_flag'])) $this->TempFillEls['package'][$i]['lock_action'] = 'Lock';
			else{
				$this->TempFillEls['package'][$i]['lock_action'] = 'Unlock';
				$this->TempFillEls['package'][$i]['btnLock_class'] = 'marked';
			}
			if($this->PreparedTemplates['curPage'][$i]['actioned']){
				$this->TempFillEls['package'][$i]['btnDelete_vis'] = $this->PreparedTemplates['curPage'][$i]['last_date_published'] <= $this->life_time ? 'hidden' : '';
				$this->TempFillEls['package'][$i]['btnEdit_vis'] = 'hidden';
				$this->TempFillEls['package'][$i]['img'] = $this->PreparedTemplates['curPage'][$i]['final'] ? 'pack3' : 'pack2';
				$this->TempFillEls['package'][$i]['actioned'] = 'true';
			}
			else{
				$this->TempFillEls['package'][$i]['actioned'] = 'false';
				$this->TempFillEls['package'][$i]['img'] = 'pack1';
			}
			if($this->server_type == 'pro'){
				$this->TempFillEls['package'][$i]['btnEdit_disp'] = 'none';
				$this->TempFillEls['package'][$i]['btnPublish_disp'] = 'none';
				$this->TempFillEls['package'][$i]['btnDuplicate_disp'] = 'none';
			}
			if((!empty($this->PreparedTemplates['curPage'][$i]['access_flag']) && $this->PreparedTemplates['curPage'][$i]['access_flag'] != $this->Action->Security->currentuser->id)){
				$this->TempFillEls['package'][$i]['btnLock_disp'] = 'none';
				$this->TempFillEls['package'][$i]['btnEdit_disp'] = 'none';
				$this->TempFillEls['package'][$i]['btnDelete_disp'] = 'none';
				$this->TempFillEls['package'][$i]['btnPublish_disp'] = 'none';
				$this->TempFillEls['package'][$i]['btnDuplicate_disp'] = 'none';
			}
			else $this->TempFillEls['package'][$i]['msgLocked_disp'] = 'none';
		}
		$this->getPageControl($this->Home.'/Registar/PackageManager');
		$this->clearAllTemplates();
	}
	
	function fillAction() {
		GLOBAL $REGISTRY, $COMMON_VARS;
		if(!empty($this->package['_error'])){
			$this->publishable = false;
			$this->TempFillEls['other_error'] = $this->printError($this->package['_error']);
		}
		$this->TempFillEls['form_referer'] = inputHidden('form[referer]', $this->referer);
		$this->TempFillEls['referer'] = $this->referer;
		$this->TempFillEls['action'] = $this->LocalTarget[0];
		$this->TempFillEls['id'] = $this->package['id'];
		$this->TempFillEls['uid'] = $this->package['uid'];
		$this->TempFillEls['name'] = (empty($this->package['name']) ? '' : '"'.$this->package['name'].'"').(empty($this->package['id']) ? '' : ' ['.$this->package['id'].']');
		$this->TempFillEls['actioned'] = $this->package['actioned'] ? 'YES' : 'NO';
		$this->TempFillEls['engine_version'] = $this->package['engine_version'] ? $this->package['engine_version'] : '[not specified]';
		$this->TempFillEls['server_type'] = $this->server_type;
		$this->TempFillEls['form_id'] = inputHidden('form[id]', $this->package['id']);
		$this->TempFillEls['form_actioned'] = inputHidden('form[actioned]', $this->package['actioned']);
		$this->TempFillEls['form_name'] = inputText('form[name]', str_replace('"', '&quot;', $this->package['name']), '60', 'id="form_name" style="color: black;"');
		$this->TempFillEls['form_comment'] = inputText('form[comment]', str_replace('"', '&quot;', $this->package['comment']), '100', 'id="form_comment" style="color: black;"');
		// ITEMS
		$check_message = true;
		$candeleteitem = array('Update', 'Duplicate', 'Add');
		$count = count($this->package['items']);
		for($i = 0; $i < $count; $i++){
			if (!empty($this->package['items'][$i]['parent'])) continue;
			$totalcheck = true;
			if(!empty($this->package['items'][$i]['objectfields']['_error']) || (!empty($this->package['items'][$i]['objectfields']['access_flag']) && $this->package['items'][$i]['objectfields']['access_flag'] != $this->Action->Security->currentuser->id))
				$totalcheck = false;
			if($check_message && !empty($this->package['items'][$i]['objectfields']['message'])) $check_message = false;
			$this->TempFillEls['object'][$i]['title'] = $this->publish_type[$this->package['items'][$i]['type']]['title'];
			$this->TempFillEls['object'][$i]['id'] = $this->package['items'][$i]['objectfields']['id'];
			$this->TempFillEls['object'][$i]['name'] = wordwrap($this->package['items'][$i]['objectfields']['name'], 50, '<br>');
			$this->TempFillEls['object'][$i]['date_changed'] = $this->package['items'][$i]['objectfields']['date_changed'];
			$this->TempFillEls['object'][$i]['form_item_id'] = inputHidden('form[items]['.$this->package['items'][$i]['id'].'][id]', $this->package['items'][$i]['id']);
			$this->TempFillEls['object'][$i]['form_item_ownerid'] = inputHidden('form[items]['.$this->package['items'][$i]['id'].'][ownerid]', $this->package['id']);
			$this->TempFillEls['object'][$i]['form_item_type'] = inputHidden('form[items]['.$this->package['items'][$i]['id'].'][type]', $this->package['items'][$i]['type']);
			$this->TempFillEls['object'][$i]['btnDeleteItem_vis'] = in_array($this->LocalTarget[0], $candeleteitem) ? '' : 'hidden';
			switch ($this->publish_type[$this->package['items'][$i]['type']]['name']){
				case 'folders & files': $this->TempFillEls['object'][$i]['form_item_object'] = inputHidden('form[items]['.$this->package['items'][$i]['id'].'][object]', $this->package['items'][$i]['objectfields']['name']); break;
				case 'home target': case '404 page': case 'default script': case 'css': case 'sitemap xml': case 'redirects': $this->TempFillEls['object'][$i]['form_item_object'] = inputHidden('form[items]['.$this->package['items'][$i]['id'].'][object]', $this->publish_type[$this->package['items'][$i]['type']]['name']); break;
				default: $this->TempFillEls['object'][$i]['form_item_object'] = inputHidden('form[items]['.$this->package['items'][$i]['id'].'][object]', $this->package['items'][$i]['objectfields']['id']); break;
			}
			$includes_count = 0;
			$obgcheck_message = true;
			for($j = 0; $j < $count; $j++){
				if($this->package['items'][$j]['parent'] != $this->package['items'][$i]['id']) continue;
				$includes_count++;
				if(!empty($this->package['items'][$j]['objectfields']['_error']) || (!empty($this->package['items'][$j]['objectfields']['access_flag']) && $this->package['items'][$j]['objectfields']['access_flag'] != $this->Action->Security->currentuser->id))
					$totalcheck = false;
				if(!empty($this->package['items'][$j]['objectfields']['message'])) $obgcheck_message = false;
				$this->TempFillEls['object'][$i]['includes'][$j] = array(
					'subtitle' => $this->publish_type[$this->package['items'][$j]['type']]['title'],
					'subid' => $this->package['items'][$j]['objectfields']['id'],
					'subname' => $this->package['items'][$j]['objectfields']['name'],
					'subdate_changed' => $this->package['items'][$j]['objectfields']['date_changed'],
					'img' => empty($this->package['items'][$j]['objectfields']['_error']) && (empty($this->package['items'][$j]['objectfields']['access_flag']) || $this->package['items'][$j]['objectfields']['access_flag'] == $this->Action->Security->currentuser->id) ? (empty($this->package['items'][$j]['objectfields']['message']) ? 'tick1.gif' : 'attention.gif') : 'cross_red.gif',
					'reason' => empty($this->package['items'][$j]['objectfields']['_error']) ? (empty($this->package['items'][$j]['objectfields']['access_flag']) || $this->package['items'][$j]['objectfields']['access_flag'] == $this->Action->Security->currentuser->id ? (empty($this->package['items'][$j]['objectfields']['message']) ? '' : $this->package['items'][$j]['objectfields']['message']) : 'Locked by '.$this->package['items'][$j]['objectfields']['username'].' ['.$this->package['items'][$j]['objectfields']['date_locked'].']') : $this->package['items'][$j]['objectfields']['_error'],
				);
			}
			if($check_message) $check_message = $obgcheck_message;
			$this->TempFillEls['object'][$i]['noincludes'] = $includes_count ? 'false' : 'true';
			$this->TempFillEls['object'][$i]['img'] = $totalcheck && empty($this->package['items'][$i]['objectfields']['_error']) && (empty($this->package['items'][$i]['objectfields']['access_flag']) || $this->package['items'][$i]['objectfields']['access_flag'] == $this->Action->Security->currentuser->id) ? ($obgcheck_message && empty($this->package['items'][$i]['objectfields']['message']) ? 'tick1.gif' : 'attention.gif') : 'cross_red.gif';
			$this->TempFillEls['object'][$i]['reason'] = empty($this->package['items'][$i]['objectfields']['_error']) ? (empty($this->package['items'][$i]['objectfields']['access_flag']) || $this->package['items'][$i]['objectfields']['access_flag'] == $this->Action->Security->currentuser->id ? ($totalcheck ? (empty($this->package['items'][$i]['objectfields']['message']) ? ($obgcheck_message ? '' : 'Included Objects have been changed <big>&darr;</big>') : $this->package['items'][$i]['objectfields']['message']) : 'Included Objects problem <big>&darr;</big>') : 'Locked by '.$this->package['items'][$i]['objectfields']['username'].' ['.$this->package['items'][$i]['objectfields']['date_locked'].']') : $this->package['items'][$i]['objectfields']['_error'];
			$this->publishable = $this->publishable ? $totalcheck : $this->publishable;
		}
		if(!$this->package['actioned']) $this->TempFillEls['report_display'] = 'none';
		if($this->server_type == 'pro') $this->TempFillEls['alternative_display'] = 'none';
		switch ($this->LocalTarget[0]){
			case 'Update':
				$this->tempFillAddsEls();
				$this->TempFillEls['servers_display'] = 'none';
				break;
			case 'Delete':
				$this->TempFillEls['adds_display'] = 'none';
				$this->TempFillEls['compose_display'] = 'none';
				$this->TempFillEls['servers_display'] = 'none';
				break;
			case 'Add':
				if(empty($this->Request))
					$this->TempFillEls['publishlist_display'] = 'none';
				$this->TempFillEls['alternative_display'] = 'none';
				$this->tempFillAddsEls();
				$this->TempFillEls['servers_display'] = 'none';
				break;
			case 'Duplicate':
				$this->tempFillAddsEls();
				$this->TempFillEls['servers_display'] = 'none';
				$this->TempFillEls['alternative_display'] = 'none';
				break;
			case 'Look':
				$this->TempFillEls['compose_display'] = 'none';
				$this->TempFillEls['adds_display'] = 'none';
				$this->TempFillEls['servers_display'] = 'none';
				if(!empty($this->package['access_flag']) && $this->package['access_flag'] != $this->Action->Security->currentuser->id) $this->TempFillEls['alternative_display'] = 'none';
				if($this->package['actioned']) $this->fillPublish();
				break;
			case 'Publish':
				$this->TempFillEls['compose_display'] = 'none';
				$this->TempFillEls['adds_display'] = 'none';
				$this->TempFillEls['report_display'] = 'none';
				$this->tempFillServersEls();
				break;
		}
		$this->TempFillEls['deletable'] = $this->package['actioned'] ? ($this->package['last_date_published'] < $this->life_time ? 'false' : 'true') : 'true';
		$this->TempFillEls['img'] = $this->publishable ? 'tick1.gif' : 'cross_red.gif';
		$this->TempFillEls['publishable'] = var_export($this->publishable, true);
		$this->TempFillEls['notchanged'] = var_export($check_message, true);
		foreach ($this->errors as $k => $v) $this->TempFillEls[$k.'_error'] = $this->printError($v);
		$this->clearAllTemplates();
	}
	
	function fillPublish() {
		if($this->LocalTarget[0] != 'Look'){
			$this->TempFillEls['id'] = $this->package['id'];
			$this->TempFillEls['name'] = $this->package['name'];
			foreach($this->errors['validate'] as $value)
				$this->TempFillEls['validate_errors'][] = array(
					'type' => $value['type'],
					'id' => $value['id'],
					'name' => $value['name'],
					'error' => $value['_error'],
				);
			foreach($this->errors['dump'] as $key => $value) $this->TempFillEls['dump_errors'][]['error'] = $value;
			if(empty($this->errors['validate']) && empty($this->errors['dump'])) $this->TempFillEls['prepub_errors_display'] = 'none';
			else{
				$this->clearAllTemplates();
				return;
			}
		}
		$for_eyeless_yankee = array();
		foreach($this->package['publish'] as $key => $value){
			$this->TempFillEls['presets'][$key]['id'] = @$value['id'];
			$this->TempFillEls['presets'][$key]['type'] = $value['type'] == 1 ? 'Publishing to' : 'Inpublishing from';
			$this->TempFillEls['presets'][$key]['hostpath'] = @$value['hostpath'];
			if(!(@$value['successful'])) $for_eyeless_yankee[] = $this->TempFillEls['presets'][$key]['type'].' "'.$this->TempFillEls['presets'][$key]['hostpath'].'" FAILED!';
			$this->TempFillEls['presets'][$key]['hostid'] = $value['host'];
			$this->TempFillEls['presets'][$key]['username'] = @$value['username'];
			$this->TempFillEls['presets'][$key]['autoflush'] = empty($value['flush']) ? 'disabled' : 'enabled';
			$date_published = explode('.', $value['date_published']);
			$this->TempFillEls['presets'][$key]['date_published'] = $date_published[0];
			foreach($value['error'] as $val) $this->TempFillEls['presets'][$key]['pre_error'][]['error'] = $val['error'];
			if(!empty($value['error'])) $this->TempFillEls['presets'][$key]['script_result_display'] = 'none';
			foreach ($value['report'] as $val)
				$this->TempFillEls['presets'][$key]['report'][] = array(
					'time' => $val['datetime'],
					'message' => $val['message'],
					'type' => strtolower($this->report_type[$val['type']]),
				);
			if(empty($value['flush_pathes'])) $this->TempFillEls['presets'][$key]['flush_pathes_display'] = 'none';
			else {
				$c = count($value['flush_pathes']);
				$flush_pathes = array();
				for($j = 0; $j < $c; $j++) $flush_pathes[] = $value['flush_pathes'][$j]['path'];
				$this->TempFillEls['presets'][$key]['flush_pathes'] = inputTextArea('', implode("\r\n", $flush_pathes), 150, 12, 'readonly style="width: 830px; margin: 5px;"');
			}
			@$this->TempFillEls['presets'][$key]['script_result'] = $value['result'];
		}
		$this->TempFillEls['for_eyeless_yankee'] = implode('<br>', $for_eyeless_yankee);
		$this->TempFillEls['for_eyeless_yankee_disp'] = (!empty($this->Request) && !empty($for_eyeless_yankee)) ? 'inline' : 'none';
		if(empty($this->flush_pathes)) $this->TempFillEls['autoflush_disp'] = 'none';
		else{
			$this->TempFillEls['autoflush_disp'] = 'inline';
			if($this->package['flush']){
				$count = count($this->autoflush);
				$error_index = false;
				for ($i = 0; $i < $count; $i++){
					if($this->autoflush[$i]['code'] != '100'){
						$error_index = $i;
						break;
					}
				}
				if($error_index === false){
					$this->TempFillEls['autoflush_message'] = $this->autoflush[0]['message'];
					$this->TempFillEls['autoflush_color'] = 'steelblue';
				}
				else{
					$this->TempFillEls['autoflush_message'] = 'ERROR. '.$this->autoflush[$error_index]['message'].'<br>Please flush URLs manually.';
					$this->TempFillEls['autoflush_color'] = 'crimson';
				}
			}
			else{
				$this->TempFillEls['autoflush_message'] = 'Disabled.<br>Please flush URLs manually.';
				$this->TempFillEls['autoflush_color'] = 'darkorange';
			}
		}
		$this->clearAllTemplates();
	}
	
	function fillAddItem(){
		GLOBAL $COMMON_VARS, $REGISTRY, $ROOT_PATH;
		if(!empty($this->Request['sbtAddItem'])) $this->TempFillEls['sbtAddItemToNew_disabled'] = 'disabled';
		$this->TempFillEls['form_referer'] = inputHidden('form[referer]', $this->referer);
		$this->TempFillEls['referer'] = $this->referer;
		$this->TempFillEls['objects_count'] = count($this->Request['form']['adds'], COUNT_RECURSIVE) - count($this->Request['form']['adds']);
		$i = 0;
		foreach($this->Request['form']['adds'] as $key => $value) {
			foreach($value as $ind => $val){
				$this->TempFillEls['object'][$i] = array(
					'form_object' => inputCheckbox('form[adds]['.$key.'][]', true, 'onClick="setSubmitAbility(\'object\', this);" '.(empty($this->Request['sbtAddItem']) ? '' : 'disabled'), ($key == 5 ? str_replace($ROOT_PATH, '', $val) : $val)),
					'title' => $this->publish_type[$key]['title'],
					'id' => (!empty($val) && is_numeric($val)) ? '['.$val.']' : '&nbsp;',
				);
				$name = '';
				print '<li>'.$this->categories[$val].'<br>';
				switch($key){
					case 0: $name = $COMMON_VARS['css_file']; break;
					case 1: $name = @$this->layouts[$val]; break;
					case 2:
						foreach($this->menus as $menus)
							foreach ($menus as $menu_id => $menu_name)
								if($menu_id == $val){
									$name = $menu_name;
									break 2;
								}
						break;
					case 3: $name = @str_replace(" - ", '', $this->pages[$val]); break;
					case 4: $name = $COMMON_VARS['sitemap_file']; break;
					case 5: $name = str_replace($ROOT_PATH, '', $val); break;
					case 6: $name = @$this->templates[$val]; break;
					case 8: $name = $COMMON_VARS['redirects_file']; break;
					case 9:
						$this->TempFillEls['object'][$i]['id'] = '['.$REGISTRY['HomeTarget'].']';
						$name = @$this->pages[$REGISTRY['HomeTarget']];
						break;
					case 10:
						$this->TempFillEls['object'][$i]['id'] = '[10]';
						$name = '404 Page';
						break;
					case 11:
						$this->TempFillEls['object'][$i]['id'] = '[30]';
						$name = 'Script Editor';
						break;
					case 12: $name = @$this->subdomains[$val]; break;
					case 13: $name = @$this->importedfeeds[$val]; break;
					case 14: $name = @$this->cities[$val]; break;
					case 15: $name = @$this->feeds[$val]; break;
					case 16: $name = @$this->categories[$val]; break;
				}
				$this->TempFillEls['object'][$i]['name'] = $name;
				$i++;
			}
		}
		foreach($this->PreparedTemplates as $key => $value)
			$this->TempFillEls['package'][] = array(
				'form_package' => inputCheckbox('form[package][]', (empty($this->Request['sbtAddItem']) ? false : true), 'onClick="setSubmitAbility(\'package\', this);" '.(empty($this->Request['sbtAddItem']) ? '' : 'disabled'), $value['id']),
				'id' => $value['id'],
				'name' => $value['name'],
				'comment' => $value['comment'],
				'message' => empty($this->Request['sbtAddItem']) ? '' : (empty($value['actioned']) ? (empty($value['access_flag']) || $value['access_flag'] == $this->Action->Security->currentuser->id ? (isset($this->packages[$value['id']]) ? 'OK' : 'Package doesn\'t exist') : 'Locked by '.$value['username'].' ['.$value['date_locked'].']') : 'Package was published'),
				'type' => empty($this->Request['sbtAddItem']) ? '1' : ((empty($value['access_flag']) || $value['access_flag'] == $this->Action->Security->currentuser->id) && empty($value['actioned']) && isset($this->packages[$value['id']]) ? 'end' : 'error'),
			);
		$this->clearAllTemplates();
	}
	
	function fillSearch(){
		$no_object = array (0, 4, 8, 9, 10, 11);
		foreach($this->publish_type as $key => $value){
			$this->TempFillEls['publish_types'][]['variable'] = 'publish_types['.$key.'] = [];';
			$this->TempFillEls['publish_types'][]['variable'] = 'publish_types['.$key.']["name"] = "'.$value['name'].'";';
			$this->TempFillEls['publish_types'][]['variable'] = 'publish_types['.$key.']["title"] = "'.$value['title'].'";';
			$this->TempFillEls['publish_types'][]['variable'] = 'publish_types['.$key.']["no_object"] = '.(in_array($key, $no_object) ? 'true' : 'false').';';
		}
		foreach($this->search_time_intervals as $key => $value){
			$this->TempFillEls['not_older'][]['radio'] = '<nobr>'.inputRadio('form[not_older]', $value, ($this->search_conditions['not_older'] == $value ? true : false)).'&nbsp;'.$key.'&nbsp;</nobr>';
			$this->TempFillEls['published'][]['radio'] = '<nobr>'.inputRadio('form[published]', $value, ($this->search_conditions['published'] == $value ? true : false)).'&nbsp;'.$key.'&nbsp;</nobr>';
			$this->TempFillEls['inpublished'][]['radio'] = '<nobr>'.inputRadio('form[inpublished]', $value, ($this->search_conditions['inpublished'] == $value ? true : false)).'&nbsp;'.$key.'&nbsp;</nobr>';
		}
		foreach($this->search_conditions['contained'] as $type => $objects)
			foreach($objects as $object)
				$this->TempFillEls['contained'][] = array(
					'type' => $type,
					'object' => $object,
				);
		if(empty($this->Request['form'])) $this->TempFillEls['founded_packages_disp'] = 'none';
		else{
			if(empty($this->founded_packages)){
				$this->TempFillEls['message'] = 'No packages found that match search conditions';
				$this->TempFillEls['colnames_disp'] = 'none';
			}
			else $this->TempFillEls['packages'] = $this->founded_packages;
		}
		$this->clearAllTemplates();
	}
	
	function fillDeleteOldPackages() {//printArray($this->old_packages);
		$this->TempFillEls['life_time'] = $this->life_time;
		if(empty($this->old_packages)) $this->TempFillEls['tblOldPackages_disp'] = 'none';
		$count = count($this->old_packages);
		for ($i = 0; $i < $count; $i++){
			$this->TempFillEls['old_packages'][] = array(
				'id' => $this->old_packages[$i]['id'],
				'name' => (empty($this->old_packages[$i]['message']) && empty($this->old_packages[$i]['error'])) ? $this->old_packages[$i]['name'] : '<a href="'.$this->Home.'/Registar/PackageManager/Look/'.$this->old_packages[$i]['id'].'">'.$this->old_packages[$i]['name'].'</a>',
				'message' => $this->old_packages[$i]['message'].$this->old_packages[$i]['error'],
				'img' => empty($this->old_packages[$i]['error']) ? (empty($this->old_packages[$i]['message']) ? 'end' : 'attention') : 'error',
			);
		}
		$this->clearAllTemplates();
	}
	
	function setPageArray($array = array(), $level = 0) {
		foreach($array as $value)
			if(in_array($value['type'], $this->publishable_page_types)){
				$this->pages[$value['id']] = str_repeat(" - ", $level).$value['name'];
				if(!empty($this->PreparedTemplates[$value['id']]))
					$this->setPageArray($this->PreparedTemplates[$value['id']], $level + 1);
			}
	}
	
	function addToMailTemplate($template){
		$this->MailTemplate['presets'][] = array(
			'type' => 'Package',
			'name' => $this->package['name'],
			'id' => $this->package['id'],
			'comment' => $this->package['comment'],
			'comment_disp' => '',
			'host' => $_SERVER['SERVER_NAME'],
			'url' => 'http://'.$_SERVER['HTTP_HOST'].'/Registar/PackageManager/Look/'.$this->package['id'],
			'user' => $this->Action->Security->currentuser->username,
			'datetime' => date('Y-m-d H:i:s', time()),
			'hostname' => $template['hostname'],
			'hostpath' => $template['hostpath'],
			'result' => $template['result'],
		);
	}
	
	function tempFillAddsEls(){
		GLOBAL $COMMON_VARS;
		$this->TempFillEls['page_adds'] = '(<span id="page_adds_count">0</span> selected)<br>'.inputSelect('form[adds][3][]', $this->pages, $selected = '', $event = 'size=15 style="width: 440px;" multiple="multiple" id="page_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['subdomain_adds'] = '(<span id="subdomain_adds_count">0</span> selected)<br>'.inputSelect('form[adds][12][]', $this->subdomains, $selected = '', $event = 'size=8 style="width: 280px;" multiple="multiple" id="subdomain_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['layout_adds'] = '(<span id="layout_adds_count">0</span> selected)<br>'.inputSelect('form[adds][1][]', $this->layouts, $selected = '', $event = 'size=8 style="width: 280px;" multiple="multiple" id="layout_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['template_adds'] = '(<span id="template_adds_count">0</span> selected)<br>'.inputSelect('form[adds][6][]', $this->templates, $selected = '', $event = 'size=8 style="width: 280px;" multiple="multiple" id="template_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['importedfeed_adds'] = '(<span id="importedfeed_adds_count">0</span> selected)<br>'.inputSelect('form[adds][13][]', $this->importedfeeds, $selected = '', $event = 'size=8 style="width: 280px;" multiple="multiple" id="importedfeed_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['feed_adds'] = '(<span id="feed_adds_count">0</span> selected)<br>'.inputSelect('form[adds][15][]', $this->feeds, $selected = '', $event = 'size=8 style="width: 280px;" multiple="multiple" id="feed_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['leftmenu_adds'] = '(<span id="leftmenu_adds_count">0</span> selected)<br>'.inputSelect('form[adds][2][]', $this->menus['left'], $selected = '', $event = 'size=8 style="width: 180px;" multiple="multiple" id="leftmenu_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['rightmenu_adds'] = '(<span id="rightmenu_adds_count">0</span> selected)<br>'.inputSelect('form[adds][2][]', $this->menus['right'], $selected = '', $event = 'size=8 style="width: 180px;" multiple="multiple" id="rightmenu_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['bottommenu_adds'] = '(<span id="bottommenu_adds_count">0</span> selected)<br>'.inputSelect('form[adds][2][]', $this->menus['bottom'], $selected = '', $event = 'size=8 style="width: 180px;" multiple="multiple" id="bottommenu_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['tabsmenu_adds'] = '(<span id="tabsmenu_adds_count">0</span> selected)<br>'.inputSelect('form[adds][2][]', $this->menus['tabs'], $selected = '', $event = 'size=8 style="width: 180px;" multiple="multiple" id="tabsmenu_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['sitemapmenu_adds'] = inputCheckbox('form[adds][2][]', false, 'style="margin: 0; padding: 0;"', '1');
		$this->TempFillEls['file_adds'] = '(<span id="file_adds_count">0</span> selected)<br>'.inputSelect('form[adds][5][]', $this->files, $selected = '', $event = 'size=15 style="width: 440px;" multiple="multiple" id="file_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		$this->TempFillEls['city_adds'] = '(<span id="city_adds_count">0</span> selected)<br>'.inputSelect('form[adds][14][]', $this->cities, $selected = '', $event = 'size=8 style="width: 280px;" multiple="multiple" id="city_adds" onClick="changeSelectedCount(this.id);" onDblClick="setNotSelected(this);"');
		//.'<br><small>Presents only allowed for publishing files and folders.<br>Allowed file types: '.implode(', ', $COMMON_VARS['publish_file_types']).'<br>Engine files and folders are not allowed for publishing.<small>';
		$this->TempFillEls['hometarget_adds'] = inputCheckbox('form[adds][9][0]', false, '', 'home target');
		$this->TempFillEls['404page_adds'] = inputCheckbox('form[adds][10][0]', false, '', '404 page');
		$this->TempFillEls['defaultscript_adds'] = inputCheckbox('form[adds][11][0]', false, '', 'default script');
		$this->TempFillEls['css_adds'] = inputCheckbox('form[adds][0][0]', false, '', 'css');
		$this->TempFillEls['sitemap_adds'] = inputCheckbox('form[adds][4][0]', false, '', 'sitemap xml');
		$this->TempFillEls['redirects_adds'] = inputCheckbox('form[adds][8][0]', false, '', 'redirects');
	}
	
	function tempFillServersEls(){
		GLOBAL $COMMON_VARS, $signature;
		$ids = array_keys($this->servers);
		$count = count($ids);
		$index = 0;
		for ($i = 0; $i < $count; $i++){
			$c = count($this->servers[$ids[$i]]['presets']);
			if($this->servers[$ids[$i]]['id'] == 1){
				for ($j = 0; $j < $c; $j++){
					if(empty($this->servers[$ids[$i]]['presets'][$j]['deleted_objects']) && empty($this->servers[$ids[$i]]['presets'][$j]['changed_urls'])){
						$warning = false;
						$publish = true;
					}
					else{
						$warning = true;
						$publish = $this->areItemsConformToChangedURLs($this->servers[$ids[$i]]['presets'][$j]['deleted_objects'], $this->servers[$ids[$i]]['presets'][$j]['changed_urls']);
					}
					$this->TempFillEls['servers'][$index] = array(
						'img_id' => $this->servers[$ids[$i]]['id'].'_'.$this->servers[$ids[$i]]['presets'][$j]['id'],
						'img' => $warning ? 'cross_red' : 'tick1',
						'img_cursor' => $warning ? 'pointer' : 'auto',
						'checkbox' => inputCheckbox('form[servers][]', false, 'id="server_'.$this->servers[$ids[$i]]['id'].'_'.$this->servers[$ids[$i]]['presets'][$j]['id'].'" onClick = "CountCheckedPreset(this)"'.($publish ? '' : ' disabled'), $this->servers[$ids[$i]]['presets'][$j]['id']),
						'type' => '[SINGLE]',
						'name' => '['.$this->servers[$ids[$i]]['presets'][$j]['id'].'] '.$this->servers[$ids[$i]]['presets'][$j]['name'],
						'color' => $publish ? '' : 'gray',
						'flush' => inputCheckbox('form[servers_flush][]', false, 'id="server_'.$this->servers[$ids[$i]]['id'].'_'.$this->servers[$ids[$i]]['presets'][$j]['id'].'_flush" default_checked="'.(in_array($signature['type_server'], $COMMON_VARS['flush_on_server_types']) ? '1' : '0').'" disabled', $this->servers[$ids[$i]]['presets'][$j]['id']),
					);
					if($warning){
						$this->TempFillEls['servers'][$index]['link'] = 'See <a href="'.$this->Home.'/Registar/PackagesAlertsReport'.$this->SID.'">Packages Alerts Report</a> for details';
						$ind = 0;
						$this->TempFillEls['servers'][$index]['server_message'][]['message'] = 'server_message["'.$this->TempFillEls['servers'][$index]['img_id'].'"] = [];';
						$deleted_count = count($this->servers[$ids[$i]]['presets'][$j]['deleted_objects']);
						if($deleted_count){
							$this->TempFillEls['servers'][$index]['server_message'][]['message'] = 'server_message["'.$this->TempFillEls['servers'][$index]['img_id'].'"]['.$ind.'] = "Founded '.$deleted_count.' unpocessed deleted page'.($deleted_count > 1 ? 's' : '').'";';
							$ind++;
						}
						$changed_url_count = count($this->servers[$ids[$i]]['presets'][$j]['changed_urls']);
						for ($k = 0; $k < $changed_url_count; $k++){
							$this->TempFillEls['servers'][$index]['server_message'][]['message'] = 'server_message["'.$this->TempFillEls['servers'][$index]['img_id'].'"]['.$ind.'] = \'Page "'.addslashes($this->servers[$ids[$i]]['presets'][$j]['changed_urls'][$k]['module_name']).'" ['.$this->servers[$ids[$i]]['presets'][$j]['changed_urls'][$k]['module_id'].'] with changed URL is not published\';';
							$ind++;
						}
					}
					$index++;
				}
			}
			else{
				if(!$c) continue;
				$servers = array();
				$warning = false;
				$publish = true;
				$changed_url = array();
				$deleted_unique_count = 0;
				for ($j = 0; $j < $c; $j++){
					$servers[] = '['.$this->servers[$ids[$i]]['presets'][$j]['id'].'] '.$this->servers[$ids[$i]]['presets'][$j]['name'];
					if(!empty($this->servers[$ids[$i]]['presets'][$j]['deleted_objects']) || !empty($this->servers[$ids[$i]]['presets'][$j]['changed_urls'])){
						$warning = true;
						if($publish) $publish = $this->areItemsConformToChangedURLs($this->servers[$ids[$i]]['presets'][$j]['deleted_objects'], $this->servers[$ids[$i]]['presets'][$j]['changed_urls']);
					}
					$deleted_count = count($this->servers[$ids[$i]]['presets'][$j]['deleted_objects']);
					$deleted_unique = array();
					for($k = 0; $k < $deleted_count; $k++) $deleted_unique[$this->servers[$ids[$i]]['presets'][$j]['deleted_objects'][$k]['uid']] = true;
					$deleted_unique_count = count($deleted_unique);
					$changed_url_count = count($this->servers[$ids[$i]]['presets'][$j]['changed_urls']);
					for ($k = 0; $k < $changed_url_count; $k++) $changed_url[$this->servers[$ids[$i]]['presets'][$j]['changed_urls'][$k]['module_id']] = $this->servers[$ids[$i]]['presets'][$j]['changed_urls'][$k]['module_name'];
				}
				$this->TempFillEls['servers'][$index] = array(
					'img_id' => $this->servers[$ids[$i]]['id'],
					'img' => $warning ? 'cross_red' : 'tick1',
					'img_cursor' => $warning ? 'pointer' : 'auto',
					'checkbox' => inputCheckbox('form[groups][]', false, 'id="group_'.$this->servers[$ids[$i]]['id'].'" onClick = "CountCheckedPreset(this)"'.($publish ? '' : ' disabled'), $this->servers[$ids[$i]]['id']),
					'type' => '[GROUP]',
					'name' => $this->servers[$ids[$i]]['name'],
					'list' => '<nobr>'.implode(',</nobr> <nobr>', $servers).'</nobr>',
					'color' => $publish ? '' : 'gray',
					'flush' => inputCheckbox('form[groups_flush][]', false, 'id="group_'.$this->servers[$ids[$i]]['id'].'_flush" default_checked="'.(in_array($signature['type_server'], $COMMON_VARS['flush_on_server_types']) ? '1' : '0').'" disabled', $this->servers[$ids[$i]]['id']),
				);
				if($warning){
					$this->TempFillEls['servers'][$index]['link'] = 'See <a href="'.$this->Home.'/Registar/PackagesAlertsReport'.$this->SID.'">Packages Alerts Report</a> for details';
					$ind = 0;
					$this->TempFillEls['servers'][$index]['server_message'][]['message'] = 'server_message["'.$this->TempFillEls['servers'][$index]['img_id'].'"] = [];';
					if($deleted_unique_count){
						$this->TempFillEls['servers'][$index]['server_message'][]['message'] = 'server_message["'.$this->TempFillEls['servers'][$index]['img_id'].'"]['.$ind.'] = "Founded '.$deleted_unique_count.' unpocessed deleted page'.($deleted_unique_count > 1 ? 's' : '').'";';
						$ind++;
					}
					$keys = array_keys($changed_url);
					$changed_url_count = count($keys);
					for ($k = 0; $k < $changed_url_count; $k++){
						$this->TempFillEls['servers'][$index]['server_message'][]['message'] = 'server_message["'.$this->TempFillEls['servers'][$index]['img_id'].'"]['.$ind.'] = \'Page "'.addslashes($changed_url[$keys[$k]]).'" ['.$keys[$k].'] with changed URL is not published\';';
						$ind++;
					}
				}
				$index++;
			}
		}
	}
	
	function areItemsConformToChangedURLs($deleted_objects, $changed_urls){
		$count = count($this->package['items']);
		$pages = array();
		for ($i = 0; $i < $count; $i++)
			if(empty($this->package['items'][$i]['parent']) && ($this->package['items'][$i]['type'] == '3' || $this->package['items'][$i]['type'] == '9')) $pages[$this->package['items'][$i]['object']] = isset($this->package['items'][$i]['objectfields']['message']) ? $this->package['items'][$i]['objectfields']['message'] : '';
		if(empty($pages)) return true;
		if(!empty($deleted_objects)) return false;
		$count = count($changed_urls);
		for ($i = 0; $i < $count; $i++) if(isset($pages[$changed_urls[$i]['module_id']]) && empty($pages[$changed_urls[$i]['module_id']])) unset($pages[$changed_urls[$i]['module_id']]);
		return empty($pages) ? true : false;
	}
	
	function dumpPackage(){
		GLOBAL $ROOT_PATH, $COMMON_VARS;
		$PackageDump = new PackageDump($this->package, $ROOT_PATH.'/'.$COMMON_VARS['temp_package_dir']);
		$PackageDump->dumpPackage(true);
		$this->errors['dump'] = $PackageDump->errors;
		if(!empty($this->errors['dump'])) return false;
		$Archive = new Archive($ROOT_PATH.'/'.$COMMON_VARS['temp_package_dir'].'/', $ROOT_PATH.'/'.$COMMON_VARS['package_dir'].'/', $this->package['uid'].'.tar.gz', false);
		$Archive->setTarPath($COMMON_VARS['tar_dir']);
		$Archive->setRootPath($ROOT_PATH.'/');
		$Archive->setFilesNames(array($this->package['uid']));
		$Archive->setRemoveFilesFlag(true);
		$Archive->createArchive();
		$this->errors['dump'] = $Archive->errors;
		if(!empty($this->errors['dump'])) return false;
		$PackageDump->checkFile($ROOT_PATH.'/'.$COMMON_VARS['package_dir'].'/'.$this->package['uid'].'.tar.gz');
		$this->errors['dump'] = $PackageDump->errors;
		if (!empty($this->errors['dump'])) return false;
		return true;
	}
	
	function transferPackage($preset, $delete = false){
		GLOBAL $ROOT_PATH, $COMMON_VARS;
		$Transfer = new Transfer();
		$Transfer->setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
		$Transfer->min_speed = 3600;
		$Transfer->dest_path = 'ftp://'.$preset['ftp_user'].':'.$preset['ftp_password'].'@'.$preset['ftp_host'].'/%2f'.$preset['ftp_folder'].$COMMON_VARS['upload_dir'].'/';
		$Transfer->src_path = $ROOT_PATH.'/'.$COMMON_VARS['package_dir'].'/';
		$Transfer->file = $this->package['uid'].'.tar.gz';
		if($delete) $Transfer->delete = true;
		$Transfer->sendFile();
		$Transfer->close();
		if(!empty($Transfer->errors)){
			foreach($Transfer->errors as $value)
				$this->package['publish'][$preset['id']]['error'][] = array('error' => 'Transfer Package failed. '.$value);
			return false;
		}
		return true;
	}
	
	function launchScript($preset){
		$Transfer = new Transfer();
		$Transfer->setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
		$Transfer->dest_path = $preset['path'];
		$Transfer->file = 'receiver.php';
		$Transfer->variables = array(
			'type' => 'package',
			'uid' => $this->package['uid'],
			'username' => $this->Action->Security->currentuser->username,
			'hostpath' => $_SERVER['HTTP_HOST'],
			'engine_version' => $this->package['engine_version'],
			'flush' => $this->package['publish'][$preset['id']]['flush'],
		);
		$this->package['publish'][$preset['id']]['result'] = $Transfer->launchScript();
		if(empty($this->package['publish'][$preset['id']]['result']))
			$this->package['publish'][$preset['id']]['result'] = 'No debug result was retrieved from remote server';
		$Transfer->close();
		if (!empty($Transfer->errors)){
			foreach($Transfer->errors as $value)
				$this->package['publish'][$preset['id']]['error'][] = array('error' => 'Launch Script failed. '.$value);
			return false;
		}
		return true;
	}
	
	function getReport($preset){
		$Transfer = new Transfer();
		$Transfer->setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
		$Transfer->dest_path = $preset['path'];
		$SID = strtok($this->package['publish'][$preset['id']]['result'], "\r\n");
		$SID = explode('=', $SID);
		$Transfer->file = 'get_session.php';
		$Transfer->variables = array($SID[0] => $SID[1],);
		$report = $Transfer->launchScript();
		$Transfer->close();
		$packageid = 0;
		$publishid = 0;
		if(@eval('$report = '.$report.';') === false)
			$this->package['publish'][$preset['id']]['report'][] = array('datetime' => date('Y-m-d H:i:s', time()), 'message' => 'No publish report was retrieved from remote server', 'type' => 0);
		else{
			$count = count($report);
			for($i = 0; $i < $count; $i++){
				if($report['message_'.$i]['type'] == 8){
					$this->package['publish'][$preset['id']]['flush_pathes'][] = array('path' => $report['message_'.$i]['message'],);
					if(!in_array($report['message_'.$i]['message'], $this->flush_pathes)) $this->flush_pathes[] = $report['message_'.$i]['message'];
					continue;
				}
				if($report['message_'.$i]['type'] == 4){
					if(preg_match('/Package remote ID \[[0-9]+\]/i', $report['message_'.$i]['message'])){
						preg_match('/[0-9]+/', $report['message_'.$i]['message'], $matches);
						$packageid = $matches[0];
					}
					else if(preg_match('/Publish remote ID \[[0-9]+\]/i', $report['message_'.$i]['message'])){
						preg_match('/[0-9]+/', $report['message_'.$i]['message'], $matches);
						$publishid = $matches[0];
					}
				}
				$this->package['publish'][$preset['id']]['report'][] = $report['message_'.$i];
			}
		}
		if (!empty($Transfer->errors)){
			foreach($Transfer->errors as $value)
				$this->package['publish'][$preset['id']]['error'][] = array('error' => 'Getting Report failed. '.$value);
			return false;
		}
		return array('packageid' => $packageid, 'publishid' => $publishid,);
	}
	
	function putRemoteReport($preset, $info){
		if(empty($info['publishid'])) return false;
		$Database = new Database($preset['db_host'], $preset['db_name'], $preset['db_user'], $preset['db_password'], $preset['db_port']);
		if($Database->connect()){
			if(!$Database->update('packagepublish', array('result' => $this->package['publish'][$preset['id']]['result']), array('id' => $info['publishid'])))
				$this->package['publish'][$preset['id']]['report'][] = array('datetime' => date('Y-m-d H:i:s', time()), 'message' => 'Couldn\'t put publish debug result to remote database', 'type' => 6);
			$Database->close();
		}
		else return false;
	}
	
	function launchFlushPathsScript(){
		GLOBAL $TOOLS_PATH, $ROOT_PATH, $COMMON_VARS;
		include_once($TOOLS_PATH.'\FlushHandler.class.inc');
		$FlushHandler = new FlushHandler();
		$FlushHandler->setFlushPaths($this->flush_pathes);
		$FlushHandler->setEmails($this->report_receivers);
		$result = $FlushHandler->launchFlushScript();
		if($result != false && is_array($result)) $this->autoflush = $result;
		else {
			$this->addAutoflush();
			$this->autoflush[0]['message'] = $FlushHandler->getLastError();
		}
	}
	
	function addAutoflush($index = 0){
		$this->autoflush[$index] = array('filepath' => '', 'request' => '', 'code' => '', 'message' => '', 'time' => '', 'session' => '',);
	}
	
	function getItemMaxId(){
		$maxid = 0;
		foreach($this->package['items'] as $value)
			if($value['id'] > $maxid) $maxid = $value['id'];
		return $maxid;
	}
	
	function initItemEmptyID(){
		$maxid = $this->getItemMaxId();
		foreach($this->package['items'] as $key => $value)
			if(empty($value['id'])){
				$maxid++;
				$this->package['items'][$key]['id'] = $maxid;
			}
	}
	
	function terminateAction(){
		$this->clearAllTemplates();
		header('Location: '.$this->Home.$this->referer.$this->SID);
		return true;
	}
	
	function clearAllTemplates(){
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_package_types');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_publish_types');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_report_types');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_pages');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_files');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_presets');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_access');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save_publish');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save_item');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_package');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_report_receivers');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'search');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete_changed_url');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'add_deleted_objects');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete_old_packages');
	}
}
?>