<?php

class PreSetManagerView extends Slot {

	var $SectionID = 8;
	var $ModuleID = 4;
	
	var $report = array(
		'db' => array(),
		'ftp' => array(),
		'signature' => array(),
		'http' => array(),
		'receiver' => array(
			'errors' => array(),
			'debug' => '',
			'report' => array(),
		),
	);

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

	function init() {
		switch(@$this->LocalTarget[0]) {
			default: {
				$this->Action->processEvent($this->SectionID, 'select', array(), $this);
				$this->Action->processEvent($this->SectionID, 'get_user', $this->PreparedTemplates, $this);
				$this->Scheme = 'default';
				break;
			}
			case 'Update': case 'Delete': case 'Unlock': {
				if($this->server_type != 'pro' || @$this->LocalTarget[0] == 'Check') {
					if(!empty($this->LocalTarget[1])) {
						if(empty($this->LocalTarget[2])){
							$this->Action->processEvent($this->SectionID, 'open_group', array('id' => $this->LocalTarget[1]), $this);
							$access_flag = true;
							foreach($this->PreparedTemplates['presets'] as $value)
								if(!empty($value['access_flag']) && $value['access_flag'] != $this->Action->Security->currentuser->id)
									$access_flag = false;
							if((empty($this->PreparedTemplates['access_flag']) || $this->PreparedTemplates['access_flag'] == $this->Action->Security->currentuser->id) && $access_flag && $this->PreparedTemplates['id'] != 1){
								if($this->LocalTarget[0] == 'Unlock')
									$this->Action->processEvent($this->SectionID, 'unlock_group', array('id' => $this->LocalTarget[1]), $this)
									and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
								else{
									$this->PreparedTemplates['member'] = $this->Action->Security->currentuser->id;
									$this->Action->processEvent($this->SectionID, 'lock_group', $this->PreparedTemplates, $this);
								}
								$this->Scheme = 'groupaction';
							}
							else
								header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						else{
							$this->Action->processEvent($this->SectionID, 'open', array('id' => $this->LocalTarget[2]), $this);
							if((empty($this->PreparedTemplates['groupslist'][$this->PreparedTemplates['ownerid']]['access_flag']) || $this->PreparedTemplates['groupslist'][$this->PreparedTemplates['ownerid']]['access_flag'] == $this->Action->Security->currentuser->id) && (empty($this->PreparedTemplates['access_flag']) || $this->PreparedTemplates['access_flag'] == $this->Action->Security->currentuser->id)){
								if($this->LocalTarget[0] == 'Unlock')
									$this->Action->processEvent($this->SectionID, 'unlock', array('id' => $this->LocalTarget[2]), $this)
									and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
								else{
									$this->PreparedTemplates['member'] = $this->Action->Security->currentuser->id;
									$this->Action->processEvent($this->SectionID, 'lock', $this->PreparedTemplates, $this);
								}
									$this->Scheme = 'action';
							}
							else
								header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
					}
					else header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
				}
				else{
					$this->Scheme = 'default';
					header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
					return;
				}
				break;
			}
			case 'Add': {
				if($this->server_type != 'pro') {
					$this->Action->processEvent($this->SectionID, 'get_guides', array(), $this);
					if(empty($this->LocalTarget[1]))
						$this->Scheme = 'groupaction';
					else{
						if(isset($this->PreparedTemplates['groupslist'][$this->LocalTarget[1]]) && (empty($this->PreparedTemplates['groupslist'][$this->LocalTarget[1]]['access_flag']) || $this->PreparedTemplates['groupslist'][$this->LocalTarget[1]]['access_flag'] == $this->Action->Security->currentuser->id))
							$this->Scheme = 'action';
						else
							header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
					}
				}
				else{
					$this->Scheme = 'default';
					header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
					return;
				}
				break;
			}
			case 'Check': {
				if(empty($this->LocalTarget[1]) || !is_numeric($this->LocalTarget[1])){
					$this->Scheme = 'default';
					header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
					return;
				}
				$this->Action->processEvent($this->SectionID, 'open', array('id' => $this->LocalTarget[1]), $this);
				$this->Scheme = 'check';
				break;
			}
		}
		if(!empty($this->Request)) {
			if($this->server_type != 'pro' || @$this->LocalTarget[0] == 'Check') {
				switch(@$this->LocalTarget[0]) {
					case 'Add': {
						if(empty($this->LocalTarget[1])){
							$this->validateGroupForm()
							and $this->Action->processEvent($this->SectionID, 'save_group', $this->getRequestField('form'), $this)
							and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						else if(array_key_exists($this->LocalTarget[1], $this->PreparedTemplates['groupslist'])){
							$this->validateForm()
							and $this->Action->processEvent($this->SectionID, 'save', $this->getRequestField('form'), $this)
							and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						else header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						break;
					}
					case 'Update': {
						if(empty($this->LocalTarget[2])){
							$this->validateGroupForm()
							and $this->Action->processEvent($this->SectionID, 'save_group', array_merge($this->PreparedTemplates ,$this->getRequestField('form')), $this)
							and $this->Action->processEvent($this->SectionID, 'unlock_group', array('id' => $this->LocalTarget[1]), $this)
							and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						else{
							$this->validateForm()
							and $this->Action->processEvent($this->SectionID, 'save', $this->getRequestField('form'), $this)
							and $this->Action->processEvent($this->SectionID, 'unlock', array('id' => $this->LocalTarget[2]), $this)
							and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						break;
					}
					case 'Delete': {
						if(empty($this->LocalTarget[2])){
							$this->Action->processEvent($this->SectionID, 'delete_group', $this->getRequestField('form'), $this)
							and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						else{
							$this->Action->processEvent($this->SectionID, 'delete', $this->getRequestField('form'), $this)
							and header('Location: '.$this->Home.'/Registar/PreSetManager'.$this->SID);
						}
						break;
					}
					case 'Check': {
						$this->checkPreSet($this->PreparedTemplates);
						break;
					}
				}
			}
			else header('Location: '.$this->Home.'/Registar/PreSetManager/'.$this->SID);
		}
		$this->setSchemeTemplate($this->Scheme);
	}

	function validateGroupForm(){
		if(!is_NumText($this->getRequestFormField('name'), 3, 64))
			$this->errors['name'] = 'PreSets Group Name is not valid';
		if(count($this->errors) > 0)
			return FALSE;
		return TRUE;
	}

	function validateForm() {
		if(!is_NumText($this->getRequestFormField('name'), 2, 64))
			$this->errors['name'] = 'PreSet Name is not valid';
		if(!isset($this->PreparedTemplates['groupslist'][$this->getRequestFormField('ownerid')]))
			$this->errors['ownerid'] = 'PreSet Group is not valid';
		if($this->getRequestFormField('db_host')!='localhost')
			if(!validate(checkURL($this->getRequestFormField('db_host'))))
				$this->errors['db_host'] = 'PreSet DataBase Host is not valid';
		if(!is_AlphaNumDefis($this->getRequestFormField('db_name'), 2, 64))
			$this->errors['db_name'] = 'PreSet DataBase Name is not valid';
		if(!is_AlphaNumDefis($this->getRequestFormField('db_user'), 2, 64))
			$this->errors['db_user'] = 'PreSet DataBase Username is not valid';
		if(!is_AlphaNumDefis($this->getRequestFormField('db_password'), 2, 64))
			$this->errors['db_password'] = 'PreSet DataBase Password is not valid';
		if(!is_Num($this->getRequestFormField('db_port'), 1, 5))
			$this->errors['db_port'] = 'PreSet DataBase Port is not valid';
		if(!is_AlphaNumDefis($this->getRequestFormField('ftp_user'), 2, 64))
			$this->errors['ftp_user'] = 'PreSet FTP Username is not valid';
		if(!is_AlphaNumDefis($this->getRequestFormField('ftp_password'), 2, 64))
			$this->errors['ftp_password'] = 'PreSet FTP Password is not valid';
		if(!validate(checkURL($this->getRequestFormField('ftp_host'))))
			$this->errors['ftp_host'] = 'PreSet FTP Host is not valid';
		if(!is_ANDSlash($this->getRequestFormField('ftp_folder'), 2, 128))
			$this->errors['ftp_folder'] = 'PreSet FTP Folder is not valid';
		else {
			if($this->Request['form']['ftp_folder']{0} != '/')
				$this->Request['form']['ftp_folder'] = '/'.$this->Request['form']['ftp_folder'];
			if(substr($this->Request['form']['ftp_folder'], -1) != '/')
				$this->Request['form']['ftp_folder'] = $this->Request['form']['ftp_folder'].'/';
		}
		$path = checkURL($this->getRequestFormField('path'));
		if(!empty($path)) {
			if(substr($path, -1) != '/')
				$path = $path.'/';
			$this->Request['form']['path'] = $path;
		}
		else
			$this->errors['path'] = 'PreSet Path to Script is not valid';
		if(count($this->errors) > 0)
			return FALSE;
		return TRUE;
	}

	function fillElements() {
		switch($this->Scheme) {
			case 'default': default: $this->fillSelect(); break;
			case 'action': $this->fillAction(); break;
			case 'groupaction': $this->fillGroupAction(); break;
			case 'check': $this->fillCheck(); break;
		}
	}

	function fillSelect() {
		foreach($this->PreparedTemplates as $key => $value) {
			$this->TempFillEls['pubBut'] = $this->server_type != 'pro'? 'visible' : 'hidden';
			$this->TempFillEls['presetsgroup'][$key]['id'] = $value['id'];
			$this->TempFillEls['presetsgroup'][$key]['pubBut'] = $this->server_type != 'pro'? 'visible' : 'hidden';
			$this->TempFillEls['presetsgroup'][$key]['name'] = $value['name'];
			if($value['canceled']) $this->TempFillEls['presetsgroup'][$key]['canceled'] = '(canceled for objects publication)';
			if ($value['id'] == '1'){
				$this->TempFillEls['presetsgroup'][$key]['update_group'] = 'display: none';
				$this->TempFillEls['presetsgroup'][$key]['delete_group'] = 'display: none';
			}
			$group_ability = 'true';
			$preset_ability = 'true';
			if (empty($value['access_flag'])){
				$this->TempFillEls['presetsgroup'][$key]['unlock_group'] = 'display: none';
				$this->TempFillEls['presetsgroup'][$key]['locked_id'] = 0;
			}
			else if($value['access_flag'] == $this->Action->Security->currentuser->id){
				$this->TempFillEls['presetsgroup'][$key]['locked_id'] = 0;
			}
			else {
				$this->TempFillEls['presetsgroup'][$key]['locked_id'] = $value['id'];
				$this->TempFillEls['presetsgroup'][$key]['username'] = $value['username'];
				$this->TempFillEls['presetsgroup'][$key]['date_locked'] = $value['date_locked'];
				$preset_ability = 'false';
			}
			if($this->server_type == 'pro') $this->TempFillEls['presetsgroup'][$key]['locked_id'] = 0;
			foreach($value['presets'] as $k => $v){
				if(empty($v['access_flag'])){
					$this->TempFillEls['presetsgroup'][$key]['presets'][]['unlocked'][] = array(
						'id' => $v['id'],
						'name' => $v['name'],
						'canceled' => $v['canceled'] ? '(canceled for objects publication)' : '',
						'ownerid' => $value['id'],
						'unlock_vis' => 'hidden',
						'preset_ability' => $preset_ability,
						'pubBut' => $this->server_type != 'pro'? 'visible' : 'hidden',
						'img' => $v['canceled'] ? 'pack1' : 'pack3',
					);
				}
				else if($v['access_flag'] == $this->Action->Security->currentuser->id){
					$this->TempFillEls['presetsgroup'][$key]['presets'][]['unlocked'][] = array(
						'id' => $v['id'],
						'name' => $v['name'],
						'canceled' => $v['canceled'] ? '(canceled for objects publication)' : '',
						'ownerid' => $value['id'],
						'unlock_vis' => $this->server_type != 'pro'? 'visible' : 'hidden',
						'preset_ability' => $preset_ability,
						'pubBut' => $this->server_type != 'pro'? 'visible' : 'hidden',
						'img' => $v['canceled'] ? 'pack1' : 'pack3',
					);
				}
				else {
					$this->TempFillEls['presetsgroup'][$key]['presets'][]['locked'][] = array(
						'id' => $v['id'],
						'name' => $v['name'],
						'canceled' => $v['canceled'] ? '(canceled for objects publication)' : '',
						'username' => $v['username'],
						'date_locked' => $v['date_locked'],
						'preset_ability' => $preset_ability,
						'pubBut' => $this->server_type != 'pro'? 'visible' : 'hidden',
						'img' => $v['canceled'] ? 'pack1' : 'pack3',
					);
					$group_ability = 'false';
				}
			}
			$this->TempFillEls['presetsgroup'][$key]['group_ability'] = $group_ability;
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_user');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_guides');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete');
	}

	function fillAction() {
		$this->TempFillEls['action'] = $this->LocalTarget[0];
		$array = array();
		foreach($this->PreparedTemplates['groupslist'] as $key => $value){
			if(empty($value['access_flag']) || $value['access_flag'] == $this->Action->Security->currentuser->id){
				$preset_access_flag = true;
				foreach($value['presets'] as $v)
					if(!empty($v['access_flag']) && $v['access_flag'] != $this->Action->Security->currentuser->id)
						$preset_access_flag = false;
				if($preset_access_flag)
					$array[$key] = $value['name'];
			}
		}
		switch($this->LocalTarget[0]){
			case 'Add': {
				if(empty($this->Request)){
					$this->TempFillEls['ownerid'] = inputSelect('form[ownerid]', $array, $this->LocalTarget[1], 'style="width: 200px;"');
					$this->TempFillEls['name'] = inputText('form[name]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['canceled'] = inputHidden('form[canceled]', '0').inputCheckbox('form[canceled]', false, '', '1');
					$this->TempFillEls['db_host'] = inputText('form[db_host]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['db_name'] = inputText('form[db_name]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['db_user'] = inputText('form[db_user]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['db_password'] = inputText('form[db_password]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['db_port'] = inputText('form[db_port]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_user'] = inputText('form[ftp_user]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_password'] = inputText('form[ftp_password]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_host'] = inputText('form[ftp_host]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_folder'] = inputText('form[ftp_folder]', '', 40, 'style="width: 200px;"');
					$this->TempFillEls['path'] = inputText('form[path]', '', 40, 'style="width: 200px;"');
				}
				else{
					$this->TempFillEls['name'] = inputText('form[name]', $this->getRequestFormField('name'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ownerid'] = inputSelect('form[ownerid]', $array, $this->getRequestFormField('ownerid'), 'style="width: 200px;"');
					$this->TempFillEls['canceled'] = inputHidden('form[canceled]', '0').inputCheckbox('form[canceled]', $this->getRequestFormField('canceled'), '', '1');
					$this->TempFillEls['db_host'] = inputText('form[db_host]', $this->getRequestFormField('db_host'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_name'] = inputText('form[db_name]', $this->getRequestFormField('db_name'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_user'] = inputText('form[db_user]', $this->getRequestFormField('db_user'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_password'] = inputText('form[db_password]', $this->getRequestFormField('db_password'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_port'] = inputText('form[db_port]', $this->getRequestFormField('db_port'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_user'] = inputText('form[ftp_user]', $this->getRequestFormField('ftp_user'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_password'] = inputText('form[ftp_password]', $this->getRequestFormField('ftp_password'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_host'] = inputText('form[ftp_host]', $this->getRequestFormField('ftp_host'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_folder'] = inputText('form[ftp_folder]', $this->getRequestFormField('ftp_folder'), 40, 'style="width: 200px;"');
					$this->TempFillEls['path'] = inputText('form[path]', $this->getRequestFormField('path'), 40, 'style="width: 200px;"');
				}
				break;
			}
			case 'Update': {
				$this->TempFillEls['sec_name'] = '"'.$this->PreparedTemplates['name'].'"';
				if(empty($this->Request)){
					$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
					$this->TempFillEls['name'] = inputText('form[name]', $this->PreparedTemplates['name'], 40, 'style="width: 200px;"');
					$this->TempFillEls['ownerid'] = inputSelect('form[ownerid]', $array, $this->PreparedTemplates['ownerid'], 'style="width: 200px;"');
					$this->TempFillEls['canceled'] = inputHidden('form[canceled]', '0').inputCheckbox('form[canceled]', $this->PreparedTemplates['canceled'], '', '1');
					$this->TempFillEls['db_host'] = inputText('form[db_host]', $this->PreparedTemplates['db_host'], 40, 'style="width: 200px;"');
					$this->TempFillEls['db_name'] = inputText('form[db_name]', $this->PreparedTemplates['db_name'], 40, 'style="width: 200px;"');
					$this->TempFillEls['db_user'] = inputText('form[db_user]', $this->PreparedTemplates['db_user'], 40, 'style="width: 200px;"');
					$this->TempFillEls['db_password'] = inputText('form[db_password]', $this->PreparedTemplates['db_password'], 40, 'style="width: 200px;"');
					$this->TempFillEls['db_port'] = inputText('form[db_port]', $this->PreparedTemplates['db_port'], 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_user'] = inputText('form[ftp_user]', $this->PreparedTemplates['ftp_user'], 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_password'] = inputText('form[ftp_password]', $this->PreparedTemplates['ftp_password'], 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_host'] = inputText('form[ftp_host]', $this->PreparedTemplates['ftp_host'], 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_folder'] = inputText('form[ftp_folder]', $this->PreparedTemplates['ftp_folder'], 40, 'style="width: 200px;"');
					$this->TempFillEls['path'] = inputText('form[path]', $this->PreparedTemplates['path'], 40, 'style="width: 200px;"');
					$this->TempFillEls['cancel_btn_name'] = ' Unlock &amp;';
					$this->TempFillEls['cancel_btn_unlock_path'] = '/Unlock/'.$this->PreparedTemplates['ownerid'].'/'.$this->PreparedTemplates['id'];
				}
				else{
					$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
					$this->TempFillEls['name'] = inputText('form[name]', $this->getRequestFormField('name'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ownerid'] = inputSelect('form[ownerid]', $array, $this->getRequestFormField('ownerid'), 'style="width: 200px;"');
					$this->TempFillEls['canceled'] = inputHidden('form[canceled]', '0').inputCheckbox('form[canceled]', $this->getRequestFormField('canceled'), '', '1');
					$this->TempFillEls['db_host'] = inputText('form[db_host]', $this->getRequestFormField('db_host'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_name'] = inputText('form[db_name]', $this->getRequestFormField('db_name'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_user'] = inputText('form[db_user]', $this->getRequestFormField('db_user'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_password'] = inputText('form[db_password]', $this->getRequestFormField('db_password'), 40, 'style="width: 200px;"');
					$this->TempFillEls['db_port'] = inputText('form[db_port]', $this->getRequestFormField('db_port'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_user'] = inputText('form[ftp_user]', $this->getRequestFormField('ftp_user'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_password'] = inputText('form[ftp_password]', $this->getRequestFormField('ftp_password'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_host'] = inputText('form[ftp_host]', $this->getRequestFormField('ftp_host'), 40, 'style="width: 200px;"');
					$this->TempFillEls['ftp_folder'] = inputText('form[ftp_folder]', $this->getRequestFormField('ftp_folder'), 40, 'style="width: 200px;"');
					$this->TempFillEls['path'] = inputText('form[path]', $this->getRequestFormField('path'), 40, 'style="width: 200px;"');
					$this->TempFillEls['cancel_btn_name'] = ' Unlock &amp;';
					$this->TempFillEls['cancel_btn_unlock_path'] = '/Unlock/'.$this->PreparedTemplates['ownerid'].'/'.$this->PreparedTemplates['id'];
				}
				break;
			}
			case 'Delete': {
				$this->TempFillEls['sec_name'] = '"'.$this->PreparedTemplates['name'].'"';
				$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
				$this->TempFillEls['name'] = inputText('form[name]', $this->PreparedTemplates['name'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['ownerid'] = inputSelect('form[ownerid]', $array, $this->PreparedTemplates['ownerid'], 'style="width: 200px;" disabled');
				$this->TempFillEls['canceled'] = inputCheckbox('form[canceled]', $this->PreparedTemplates['canceled'], 'disabled', '1');
				$this->TempFillEls['db_host'] = inputText('form[db_host]', $this->PreparedTemplates['db_host'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['db_name'] = inputText('form[db_name]', $this->PreparedTemplates['db_name'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['db_user'] = inputText('form[db_user]', $this->PreparedTemplates['db_user'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['db_password'] = inputText('form[db_password]', $this->PreparedTemplates['db_password'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['db_port'] = inputText('form[db_port]', $this->PreparedTemplates['db_port'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['ftp_user'] = inputText('form[ftp_user]', $this->PreparedTemplates['ftp_user'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['ftp_password'] = inputText('form[ftp_password]', $this->PreparedTemplates['ftp_password'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['ftp_host'] = inputText('form[ftp_host]', $this->PreparedTemplates['ftp_host'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['ftp_folder'] = inputText('form[ftp_folder]', $this->PreparedTemplates['ftp_folder'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['path'] = inputText('form[path]', $this->PreparedTemplates['path'], 40, 'style="width: 200px;" readonly');
				$this->TempFillEls['cancel_btn_name'] = ' Unlock &amp;';
				$this->TempFillEls['cancel_btn_unlock_path'] = '/Unlock/'.$this->PreparedTemplates['ownerid'].'/'.$this->PreparedTemplates['id'];
				break;
			}
		}
		!empty($this->PreparedTemplates['_error']) and $this->errors['model'] = $this->PreparedTemplates['_error'];
		if(count($this->errors) > 0)
			$this->errors['header'] = 'There were some errors.<br>Please see below for details';
		foreach($this->errors as $k => $v)
			$this->TempFillEls[$k.'_error'] = $this->printError($v).($k == 'header' ? '<p>' : '');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_user');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_guides');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete');
	}
	
	function fillGroupAction(){
		switch($this->LocalTarget[0]){
			case 'Add': {
					$this->TempFillEls['action'] = 'Add';
					$this->TempFillEls['sec_name'] = '';
					$this->TempFillEls['name'] = inputText('form[name]', (empty($this->Request) ? '' : $this->getRequestFormField('name')), 40, 'style="width: 200px;"');
					$this->TempFillEls['canceled'] = inputHidden('form[canceled]', '0').inputCheckbox('form[canceled]', (empty($this->Request) ? false : $this->getRequestFormField('canceled')), '', '1');
					$this->TempFillEls['id'] = '';
				break;
			}
			case 'Update': {
				$this->TempFillEls['action'] = $this->LocalTarget[0];
				$this->TempFillEls['sec_name'] = '"'.$this->PreparedTemplates['name'].'"';
				$this->TempFillEls['name'] = inputText('form[name]', (empty($this->Request) ? $this->PreparedTemplates['name'] : $this->getRequestFormField('name')), 40, 'style="width: 200px;"');
				$this->TempFillEls['canceled'] = inputHidden('form[canceled]', '0').inputCheckbox('form[canceled]', (empty($this->Request) ? $this->PreparedTemplates['canceled'] : $this->getRequestFormField('canceled')), '', '1');
				$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
				$this->TempFillEls['confirmation'] = 'true';
				$this->TempFillEls['cancel_btn_name'] = ' Unlock &amp;';
				$this->TempFillEls['cancel_btn_unlock_path'] = '/Unlock/'.$this->PreparedTemplates['id'];
				break;
			}
			case 'Delete': {
				$this->TempFillEls['action'] = $this->LocalTarget[0];
				$this->TempFillEls['sec_name'] = '"'.$this->PreparedTemplates['name'].'"';
				$this->TempFillEls['name'] = inputText('form[name]', $this->PreparedTemplates['name'], 40, 'style="width:200px;" readonly');
				$this->TempFillEls['canceled'] = inputCheckbox('form[canceled]', $this->PreparedTemplates['canceled'], 'disabled', '1');
				$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
				$this->TempFillEls['confirmation'] = 'confirmDelete()';
				$this->TempFillEls['cancel_btn_name'] = ' Unlock &amp;';
				$this->TempFillEls['cancel_btn_unlock_path'] = '/Unlock/'.$this->PreparedTemplates['id'];
				break;
			}
		}
		!empty($this->PreparedTemplates['_error']) and $this->errors['model'] = $this->PreparedTemplates['_error'];
		if(count($this->errors) > 0)
			$this->errors['header'] = 'There were some errors.<br>Please see below for details';
		foreach($this->errors as $k => $v)
			$this->TempFillEls[$k.'_error'] = $this->printError($v).($k == 'header' ? '<p>' : '');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_user');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'get_guides');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'lock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'unlock');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'save');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete_group');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'delete');
	}
	
	function fillCheck() {//printArray($this->PreparedTemplates);
		GLOBAL $REGISTRY;
		foreach ($this->PreparedTemplates as $key => $value)
			if(!is_array($value)) $this->TempFillEls[$key] = $value;
		$this->TempFillEls['group'] = $this->PreparedTemplates['groupslist'][$this->PreparedTemplates['ownerid']]['name'];
		$this->TempFillEls['canceled'] = $this->PreparedTemplates['canceled'] ? 'YES' : 'NO';
		if(empty($this->Request)) $this->TempFillEls['ReportBox_disp'] = 'none';
		if(empty($this->report['db'])){
			$this->TempFillEls['db'][]['message'] = 'No Problem';
			$this->TempFillEls['db_img'] = 'good';
		}
		else {
			foreach ($this->report['db'] as $value) $this->TempFillEls['db'][]['message'] = $value;
			$this->TempFillEls['db_img'] = 'bad';
		}
		if(empty($this->report['ftp'])) {
			$this->TempFillEls['ftp'][]['message'] = 'No Problem';
			$this->TempFillEls['ftp_img'] = 'good';
		}
		else {
			foreach ($this->report['ftp'] as $value) $this->TempFillEls['ftp'][]['message'] = $value;
			$this->TempFillEls['ftp_img'] = 'bad';
		}
		if(empty($this->report['signature'])) {
			$this->TempFillEls['signature'][]['message'] = 'No Problem';
			$this->TempFillEls['signature_img'] = 'good';
		}
		else {
			foreach ($this->report['signature'] as $value) $this->TempFillEls['signature'][]['message'] = $value;
			$this->TempFillEls['signature_img'] = 'bad';
		}
		if(empty($this->report['http'])) {
			$this->TempFillEls['http'][]['message'] = 'No Problem';
			$this->TempFillEls['http_img'] = 'good';
		}
		else {
			foreach ($this->report['http'] as $value) $this->TempFillEls['http'][]['message'] = $value;
			$this->TempFillEls['http_img'] = 'bad';
		}
		if(empty($this->report['receiver']['errors'])) {
			$this->TempFillEls['receiver'][]['message'] = 'No Problem';
			$this->TempFillEls['receiver_img'] = 'good';
		}
		else {
			foreach ($this->report['receiver']['errors'] as $value) $this->TempFillEls['receiver'][]['message'] = $value;
			$this->TempFillEls['receiver_img'] = 'bad';
		}
		if(empty($this->report['receiver']['report'])) {
			$this->TempFillEls['report'][]['message'] = 'No Receiver Script Report Retrieved';
			$this->TempFillEls['report_img'] = 'bad';
		}
		else {
			foreach ($this->report['receiver']['report'] as $value) $this->TempFillEls['report'][]['message'] = $value['datetime'].'&nbsp;&nbsp;&nbsp;'.$value['message'];
			$last = end($this->report['receiver']['report']);
			$this->TempFillEls['report'][]['message'] = 'Receiver Script Result: '.($last['type'] == 3 ? 'Successful' : 'Failed');
			$this->TempFillEls['report_img'] = $last['type'] == 3 ? 'good' : 'bad';
		}
		$this->TempFillEls['receiver_debug'] = empty($this->report['receiver']['debug']) ? 'No Receiver Script Debug retrieved' : $this->report['receiver']['debug'];
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open');
	}
	
	function checkPreSet($preset) {
		GLOBAL $TOOLS_PATH, $CORE_PATH;
		eval(file_get_contents($CORE_PATH.'/signature.inc'));
		include_once($TOOLS_PATH.'/CheckRemoteServer.class.inc');
		$CheckRemoteServer = new CheckRemoteServer($preset);
		$CheckRemoteServer->checkDBConnect();
		$this->report['db'] = $CheckRemoteServer->errors;
		$CheckRemoteServer->clearErrors();
		$CheckRemoteServer->checkFTPConnect();
		$this->report['ftp'] = $CheckRemoteServer->errors;
		$CheckRemoteServer->clearErrors();
		$CheckRemoteServer->checkSignature($signature['type_server']);
		$this->report['signature'] = $CheckRemoteServer->errors;
		$CheckRemoteServer->clearErrors();
		$CheckRemoteServer->checkHTTPConnect();
		$this->report['http'] = $CheckRemoteServer->errors;
		$CheckRemoteServer->clearErrors();
		$temp = $CheckRemoteServer->checkConnectToReceiver();
		$this->report['receiver']['errors'] = $CheckRemoteServer->errors;
		$this->report['receiver']['debug'] = $temp['debug'];
		$this->report['receiver']['report'] = $temp['report'];
	}
}
?>