<?php

//global $Debug;  $Debug = true;
class LayoutManagerView extends Slot {

	var $SectionID = 6;
	var $ModuleID = 4;
	var $upload_formats = array(
		'image/gif' => 'gif',
	);
	var $colors = array(
		'red' => '#DC143C',
		'yellow' => '#FF8C00',
		'green' => '#006400',
		'black' => '#000000',
		'blue' => '#4169E1',
	);

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

	function init() {
		global $TOOLS_PATH;
		$undo = 0;
		unset($this->Action->Server->Guides['layout']);
		$this->layouts = $this->Action->Server->getGuide('layout');
		$this->Scheme = 'default';
		switch(@$this->LocalTarget[0]) {
			case 'Spellcheck': $this->Scheme = $this->server_type=='dev'? 'spellcheck' : 'default'; break;
			case 'Spellword': $this->Scheme = $this->server_type=='dev'? 'spellword' : 'default'; break;
			case 'Spelladd': $this->Scheme = $this->server_type=='dev'? 'spelladd' : 'default'; break;
			case 'ViewAll':
				if($this->server_type=='dev') {
					$request = $this->LocalTarget;
					$request['pageRecordsQty'] = 20;
					$request['curPageNumber'] = isset($this->LocalTarget[2])? $this->LocalTarget[2]+1 : 1;
					$this->Action->processEvent($this->SectionID,'select_layoutcomments',$request,$this);
					if(!empty($this->PreparedTemplates['_error'])) $this->Scheme = 'message';
					else {
						$this->getPageControl($this->Home.'/Registar/LayoutManager/ViewAll/'.$this->LocalTarget[1]);
						if(empty($this->PreparedTemplates['curPage'])) $this->Scheme = 'empty';
					}
					$this->Scheme = 'viewall';
				}
				else $this->Scheme = 'default';
			break;
			case 'Update': case 'Duplicate': case 'Delete':
				if($this->server_type=='dev') {
					if(!empty($this->LocalTarget[3]) && validate(intval($this->LocalTarget[3])) && $this->LocalTarget[2]=='Undo')
						$undo = 1;
					else $undo = 0;
					if(!empty($this->LocalTarget[1]) && in_array($this->LocalTarget[1],array_keys($this->layouts))) {
						$array = array('id' => $this->LocalTarget[1]);
						if($undo == 1) $array['undo'] = $this->LocalTarget[3];
						$this->Action->processEvent($this->SectionID,'getlock',array('layout' => $this->LocalTarget[1],'member' => $this->Action->Security->currentuser->id),$this);
						if(!empty($this->PreparedTemplates['access_flag']) && $this->PreparedTemplates['access_flag']!=$this->Action->Security->currentuser->id) {
							header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
						}
						else{
							if(empty($this->PreparedTemplates['access_flag'])) 
								$this->Action->processEvent($this->SectionID,'lock',array('layout' => $this->LocalTarget[1],'member' => $this->Action->Security->currentuser->id),$this);
							$this->Action->processEvent($this->SectionID,'open',$array,$this);
							if(!empty($this->PreparedTemplates['_error'])) header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
							$this->Scheme = 'action';
						}
					}
					else header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
				}
				else header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
			break;
			case 'Add':
				if($this->server_type=='dev') $this->Scheme = 'action';
				else $this->Scheme = 'default';
			break;
			case 'Unlock':
				if($this->server_type=='dev' ) {
					if (isset($this->LocalTarget[1])) {
						$idLyaout=$this->LocalTarget[1];
						$this->Action->processEvent($this->SectionID,'getlock',array('layout' => $idLyaout,'member' => $this->Action->Security->currentuser->id),$this);
					}
					if(!empty($this->PreparedTemplates)){
						$this->Action->processEvent($this->SectionID,'unLock',array('layout' => $idLyaout,'member' => $this->Action->Security->currentuser->id),$this);
					}	
					header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
				}
				else $this->Scheme = 'default';
			break;
			default: $this->Action->processEvent($this->SectionID, 'select', array(), $this); break;
		}
		if(!empty($this->Request)) {
//	var_dump($this->Request);exit;
			switch(@$this->LocalTarget[0]) {
				case 'Add': case 'Update': case 'Duplicate':
					if($this->server_type=='dev') {
						$this->Request['form']['id_user']=$this->Action->Security->currentuser->id;
						if($undo ==1) $this->Request['form']['_undo_'] = $this->LocalTarget[3];
						$this->validateForm()
						and $this->Action->processEvent($this->SectionID,'save',$this->getRequestField('form'),$this)
						and header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
					}
					else header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
				break;
				case 'Delete':
					if($this->server_type=='dev') {
						include($TOOLS_PATH.'\checker.php');
						$this->check = check_to_delete($this->getRequestFormField('id'),'Layout');
						if(empty($this->check)) {
							$this->Action->processEvent($this->SectionID,'delete',$this->getRequestField('form'),$this)
							and $this->clearUndo($this->getRequestFormField('id'))
							and header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
						}
						else $this->Scheme = 'nodelete';
					}
					else header('Location: '.$this->Home.'/Registar/LayoutManager'.$this->SID);
				break;
			}
		}
		$this->setSchemeTemplate($this->Scheme);
	}

	function clearUndo($id) {
		global $ROOT_PATH;
		if(file_exists($ROOT_PATH.'/undo/layout/'.$id)) {
			chdir($ROOT_PATH.'/undo/layout/'.$id);
			$dir = dir('.');
			$dir->rewind();
			while($file = $dir->read()) if(is_file($file)) unlink($ROOT_PATH.'/undo/layout/'.$id.'/'.$file);
			rmdir($ROOT_PATH.'/undo/layout/'.$id);
			$dir->close();
		}
		return true;
	}

	function validateForm() {
		global $REGISTRY;
		if(!is_AlphaNumDefis($this->getRequestFormField('name'),1,64)) $this->errors['name'] = 'Layout Name is not valid';
		if(!validate($this->getRequestFormField('value'))) $this->errors['value'] = 'Layout is not valid';
		$this->Request['form']['value'] = str_replace('&amp;','&',$this->Request['form']['value']);

		if($this->LocalTarget[0] != 'Add' && $this->LocalTarget[0] != 'Duplicate') if(!is_AdvCleanText($this->getRequestFormField('comment'),5,4096)) $this->errors['comment'] = 'Comment is empty or is not valid';
		$virtuals = $files = $objects = $statics =array();
		$this->contenttypes = $this->Action->Server->getGuide('contenttype');
		$this->_contenttypes = getValuesToKeys($this->contenttypes);
		preg_match_all("/\{([^}]+)\}/",$this->getRequestFormField('value'),$m);
		empty($m[1]) and $m[1] = array();
		foreach($m[1] as $key => $value) {
			if(!preg_match("/^[:?=a-zA-Z0-9_-]{1,}$/",$value) && !preg_match('/^Template\*[a-zA-Z0-9_-]{1,256}\*(\d+)\*(\d+)\*(\d+)$/',$value)) $this->errors['slot'][] = $m[0][$key].' is not valid variable';
			else if(preg_match("/[:?]/",$value)) {
				$slot = explode(':',$value);
				$slot2 = explode('?',$slot[1]);
				if(count($slot) > 2 || !in_array($slot2[0],array('virtual','object','static')) || empty($slot[0]) || !preg_match("/^[a-zA-Z0-9_-]{1,}$/",$slot[0])) $this->errors['slot'][] = $m[0][$key].' is not valid slot';
				else {
					switch($slot[1]) {
						case 'virtual': $virtuals[] = $slot[0]; break;
						case 'object': $objects[] = $slot[0]; break;
						case 'static': $statics[] = $slot[0]; break;
					}
				}
			}
		}
		!empty($this->errors['slot']) and $this->errors['model'] = !empty($this->errors['model'])? $this->errors['model'].'<br>'.implode('<br>',$this->errors['slot']) : implode('<br>',$this->errors['slot']);
		foreach($virtuals as $key => $value) {
			if(!in_array($value,array_keys($REGISTRY['VirtualSlotTarget']))) $this->errors['virtual'][]=$value.':virtual is not exists virtual slot';
		}
		if(!empty($this->errors['virtual'])) $this->errors['model'] = !empty($this->errors['model'])? $this->errors['model'].'<br>'.implode('<br>',$this->errors['virtual']) : implode('<br>',$this->errors['virtual']);
		else {
			foreach($virtuals as $key => $value) {
				if(in_array($value,$this->contenttypes))
					$this->Request['form']['layoutcontenttype'][$key]['type'] = $this->_contenttypes[$value];
			}
		}
		$dh = opendir($REGISTRY['Core']['ObjectsPath'].'/');
		while(false !== ($filename = readdir($dh))) {
			if(preg_match("/^\w{1,}\.class\.inc$/",$filename))
				$files[] = substr($filename,0,strpos($filename, '.'));
		}
		foreach($objects as $key => $value) {
			if(!in_array($value,$files)) $this->errors['object'][] = $value.':object is not exists object slot';
		}
		!empty($this->errors['object']) and  $this->errors['model'] = !empty($this->errors['model'])? $this->errors['model'].'<br>'.implode('<br>',$this->errors['object']) : implode('<br>',$this->errors['object']);
		foreach($statics as $key => $value) {
			if(!in_array($value,array_keys($REGISTRY['Globals']['static']))) $this->errors['static'][]=$value.':static is not exists static slot';
		}
		!empty($this->errors['static']) and $this->errors['model'] = !empty($this->errors['model'])? $this->errors['model'].'<br>'.implode('<br>',$this->errors['static']) : implode('<br>',$this->errors['static']);
		preg_match_all("/\{()\}/",$this->getRequestFormField('value'),$m);
		!empty($m[0]) and $this->errors['model'] = !empty($this->errors['model'])? $this->errors['model'].'<br>{} is not valid variable' : '<br>{} is not valid variable';
		if(count($this->errors) > 0) return FALSE;
		return TRUE;
	}

	function fillElements() {
		switch($this->Scheme) {
			case 'nodelete': $this->fillNoDelete(); break;
			case 'default': default: $this->fillSelect(); break;
			case 'action': $this->fillAction(); break;
			case 'viewall': $this->fillViewAll(); break;
			case 'spellcheck': $this->fillSpellcheck(); break;
			case 'spellword': $this->fillSpellword(); break;
			case 'spelladd': $this->fillSpelladd(); break;
		}
	}

	function fillSpelladd() {
		$word = @$this->LocalTarget[1];
		global $REGISTRY, $CORE_PATH;
		require_once($CORE_PATH.'\Tools\spell_checker.php');
		$cp = new PSpell();
		$cp->addWord($word);
	}

	function fillSpellword() {
		global $REGISTRY, $CORE_PATH;
		$word = @$this->LocalTarget[1];
		$this->TempFillEls['word'] = $word;
		$this->TempFillEls['check'] = $check = $REGISTRY['Request']['Query']['check'];
		$this->TempFillEls['id'] = $REGISTRY['Request']['Query']['id'];
		$this->TempFillEls['div'] = $REGISTRY['Request']['Query']['div'];
		require_once($CORE_PATH.'\Tools\spell_checker.php');
		$cp = new PSpell();
		if(empty($this->LocalTarget[2])) {
			$words = $cp->getSuggestions($word);
			foreach($words as $value) $this->TempFillEls['suggestion'][0]['words'][]['value'] = makeLink('javascript:void(0);',$value,array(),'','style="text-decoration:none;font-weight:normal" onclick="replaceWord(\''.addslashes($word).'\',\''.addslashes($value).'\',\''.$check.'\','.$this->TempFillEls['id'].',\''.$this->TempFillEls['div'].'\')"');
		}
		else $this->TempFillEls['open_edit'][0]['link'] = makeLink($REGISTRY['Request']['Query']['url'],'Go to edit this mistake',array(),'','target="_blank" style="text-decoration:none;color:red"');
	}

	function fillSpellcheck() {
		global $REGISTRY, $CORE_PATH, $ROOT_PATH;
		require_once($CORE_PATH.'\Tools\spell_checker.php');
		$cp = new PSpell();
		$cp->spellCheck($this->Request['file'],'Layout');
		if(!empty($cp->count)) {
			$this->TempFillEls['error'] = array(array());
			$i = 1;
			$check = 0;
			if(!empty($this->Request['check']) && $this->Request['check']=='submit') $check = 1;
			foreach($cp->errorMsg as $key => $value) {
				if(!empty($value['count'])) {
					$div = eregi_replace(' ','',$key);
					$this->TempFillEls['objects'][$key] = array(
						'object' => $key,
						'count'  => $value['count'],
						'objecttype' => $div,
						'div' => $i,
					);
					foreach($value['errors'] as $error) {
						$this->TempFillEls['objects'][$key]['errors'][] = array(
							'url_word' => urlencode($error['word']).'?&check='.$check.'&div='.$div.'&id='.$i,
							'word' => $error['word'],
							'string' => $error['string'],
							'div' => $i,
						);
						$i++;
					}
				}
			}
		}
		else {
			$this->TempFillEls['ok'] = array(array());
			if(!empty($this->Request['check']) && $this->Request['check']=='submit') $this->TempFillEls['submit'] = array(array());
		}
	}

	function fillViewAll() {
		global $REGISTRY, $ROOT_PATH;
		foreach($this->PreparedTemplates['curPage'] as $ind => $val) {
			$tok = explode(".",$val['date']);
			$this->TempFillEls['comments'][] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty']*($this->PreparedTemplates['curPageNumber']-1))+($ind+1),
				'date' => $tok[0],
				'author' => $val['member'],
				'changed' => $val['value'],
				'version' => $val['version'],
				'button' =>  file_exists($ROOT_PATH.'/undo/layout/'.$this->PreparedTemplates[1].'/'.$val['version'].'.inc')? array(array('id' => $this->PreparedTemplates[1],'version' => $val['version'])) : array(),
			);
		}
	}

	function fillSelect() {
		$this->TempFillEls['addBut'] = $btnEdit_vis = $this->server_type == 'dev' ? 'visible' : 'hidden';
		$this->TempFillEls['pubBut'] = $this->server_type == 'pro' ? 'hidden' : 'visible';
		$count = count($this->PreparedTemplates);
		for ($i = 0; $i < $count; $i++){
			$locked = empty($this->PreparedTemplates[$i]['access_flag']) || $this->PreparedTemplates[$i]['access_flag'] == $this->Action->Security->currentuser->id ? false : true;
			$presets_count = explode('/', $this->PreparedTemplates[$i]['published_count']);
			$c = count($this->PreparedTemplates[$i]['publish']);
			$this->TempFillEls['layouts'][$i] = array(
				'id' => $this->PreparedTemplates[$i]['id'],
				'name' => $this->PreparedTemplates[$i]['name'],
				'name_color' => $this->colors[($this->PreparedTemplates[$i]['unmodified'] > 30 ? 'black' : ($this->PreparedTemplates[$i]['unmodified'] > 14 && $this->PreparedTemplates[$i]['unmodified'] <= 30 ? 'green' : ($this->PreparedTemplates[$i]['unmodified'] > 7 && $this->PreparedTemplates[$i]['unmodified'] <= 14 ? 'yellow' : 'red')))],
				'published_count' => $this->PreparedTemplates[$i]['published_count'],
				'published_count_cursor' => $c ? 'pointer' : 'auto',
				'published_count_color' => $this->colors[($presets_count[0] >= $presets_count[1] ? 'green' : (empty($presets_count[0]) ? 'red' : 'blue'))],
				'chbAdds_disabled' => $locked ? 'disabled' : '',
				'date_changed' => $this->PreparedTemplates[$i]['date_changed'],
				'btnUnlock_vis' => $this->PreparedTemplates[$i]['access_flag'] == $this->Action->Security->currentuser->id ? 'visible' : 'hidden',
				'btnEdit_vis' => $btnEdit_vis,
				'chbAdds_vis' => $this->TempFillEls['pubBut'],
				'btnUnlock_disp' => $locked ? 'none' : '',
				'btnEdit_disp' => $locked ? 'none' : '',
				'locked_message_disp' => $locked ? '' : 'none',
				'user_name' => $this->PreparedTemplates[$i]['username'],
				'date_locked' => $this->PreparedTemplates[$i]['date_locked'],
			);
			$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']=[];';
			$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]=[];';
			for($j = 0; $j < $c; $j++){
				$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]['.$j.']=[];';
				$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]['.$j.']["package_id"]='.$this->PreparedTemplates[$i]['publish'][$j]['package_id'].';';
				$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]['.$j.']["package_name"]="'.$this->PreparedTemplates[$i]['publish'][$j]['package_name'].'";';
				$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]['.$j.']["username"]="'.$this->PreparedTemplates[$i]['publish'][$j]['username'].'";';
				$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]['.$j.']["hostpath"]="'.$this->PreparedTemplates[$i]['publish'][$j]['hostpath'].'";';
				$this->TempFillEls['layouts'][$i]['publish'][]['variable'] = 'layouts['.$this->PreparedTemplates[$i]['id'].']["publish"]['.$j.']["date_published"]="'.$this->PreparedTemplates[$i]['publish'][$j]['date_published'].'";';
			}
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select');
	}

	function fillNoDelete() {
		$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
		$this->TempFillEls['sec_name'] = '" '.$this->PreparedTemplates['name'].' "';
		empty($this->check) and $this->check = array();
		foreach($this->check as $key => $value) {
			$this->TempFillEls['Pages'][0]['pitems'][] = array(
				'item' => makeLink($this->Home.$value['path'],$value['name']),
				'id' => $value['id'],
			);
		}
	}

	function fillAction() {
		global $CORE_PATH, $ROOT_PATH;
		//printArray($this->PreparedTemplates);
		$this->TempFillEls['action'] = $this->LocalTarget[0];
		if(!empty($this->LocalTarget[3]) && validate(intval($this->LocalTarget[3])) && $this->LocalTarget[2]=='Undo')
			$this->TempFillEls['undo'] = '(Undo v.'.$this->LocalTarget[3].')';
		$this->TempFillEls['sec_name'] = !empty($this->Request)? ($this->LocalTarget[0]!='Duplicate'? '" '.$this->getRequestFormField('name').' "' : '" '.$this->PreparedTemplates['name'].' "') : ($this->LocalTarget[0]!='Add'? '" '.$this->PreparedTemplates['name'].' "' : '');
		$this->TempFillEls['id'] = $this->LocalTarget[0]!='Add' && $this->LocalTarget[0]!='Duplicate'? $this->PreparedTemplates['id'] : '';
		$this->TempFillEls['name'] = inputText('form[name]',(!empty($this->Request)? $this->getRequestFormField('name') : ($this->LocalTarget[0]!='Add' && $this->LocalTarget[0]!='Duplicate'? $this->PreparedTemplates['name'] : '')),40,'style="width:200px;"'.($this->LocalTarget[0]=='Delete'? ' readonly=true' : ''));
//		$this->TempFillEls['value'] = inputTextArea('form[value]',(!empty($this->Request)? $this->getRequestFormField('value') : ($this->LocalTarget[0]!='Add'? $this->PreparedTemplates['value'] : $this->setBlank())),200,70,'style="width:890px;"'.($this->LocalTarget[0]=='Delete'? ' readonly=true' : ''));
		$this->TempFillEls['value'] = inputTextArea('form[value]',(!empty($this->Request)? preg_replace('/&([#a-zA-Z0-9]{1,8}+);/', '&amp;$1;', $this->getRequestFormField('value')) : ($this->LocalTarget[0]!='Add'? preg_replace('/&([#a-zA-Z0-9]{1,8}+);/', '&amp;$1;', $this->PreparedTemplates['value']) : $this->setBlank())),200,70,'style="width:890px;"'.($this->LocalTarget[0]=='Delete'? ' readonly=true' : ''));

		if($this->LocalTarget[0] == 'Update'){
			$this->TempFillEls['textareaValidJS']='if(parseInt(document.getElementById("comment").value.length+"-")<5){
						//document.getElementById("comment").focus();
						alert("Comment is empty or is not valid");
						return false;
						}';
			$this->TempFillEls['ViewAllButton']='<input type="button" name="View_All" class=adminsubmit value="View All" onclick="open(\'/Registar/LayoutManager/ViewAll/'.$this->PreparedTemplates['id'].'\',\'displayWindow\',\'width=950,height=600,scrollbars=yes\');">';
			$this->TempFillEls['textareaComment']='<textarea name=form[comment] id=comment cols=80 rows=5>'.(!empty($this->Request['form']['comment'])? $this->Request['form']['comment'] : '').'</textarea>';
			$selected = $this->Db->SelectAny("select lc.*,m.username as member from layoutcomment lc, member m where m.id=lc.member and lc.ownerid = ".$this->PreparedTemplates['id']." order by lc.version DESC LIMIT 10 OFFSET 0");
			if(!empty($selected)) {
				foreach($selected as $ind => $val) {
					$tok = explode(".",$val['date']);
					$this->TempFillEls['comment'][] = array(
						'number' => ($ind+1),
						'date' => $tok[0],
						'author' => $val['member'],
						'changed' => $val['value'],
						'version' => $val['version'],
						'button' => $ind!=0 && file_exists($ROOT_PATH.'/undo/layout/'.$this->PreparedTemplates['id'].'/'.$val['version'].'.inc')? array(array('id' => $this->PreparedTemplates['id'],'version' => $val['version'])) : array(),
					);
				}
			}
		}
		else if($this->LocalTarget[0] == 'Delete'){
			$selected = $this->Db->SelectAny("select lc.*,m.username as member from layoutcomment lc, member m where m.id=lc.member and lc.ownerid = ".$this->PreparedTemplates['id']." order by lc.version DESC LIMIT 10 OFFSET 0");
			if(!empty($selected)) {
				$this->TempFillEls['ViewAllButton']='<input type="button" name="View_All" class=adminsubmit value="View All" onclick="open(\'/Registar/LayoutManager/ViewAll/'.$this->PreparedTemplates['id'].'\',\'displayWindow\',\'width=950,height=600,scrollbars=yes\');">';
				foreach($selected as $ind => $val){
					$tok = explode(".",$val['date']);
					$this->TempFillEls['comment'][] = array(
						'number' => ($ind+1),
						'date' => $tok[0],
						'author' => $val['member'],
						'changed' => $val['value'],
						'version' => $val['version'],
						'button' => $ind!=0 && file_exists($ROOT_PATH.'/undo/layout/'.$this->PreparedTemplates['id'].'/'.$val['version'].'.inc')? array(array('id' => $this->PreparedTemplates['id'],'version' => $val['version'])) : array(),
					);
				}
			}
		}
		$this->TempFillEls['spell'] = $this->LocalTarget[0]=='Delete'? array() : array(array());
		$this->TempFillEls['spell_checked'] = $this->getSpellCookie()? 'checked' : '';
		!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,'open');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'save');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'delete');
	}

	function setBlank() {
		global $CORE_PATH;
		$template = $CORE_PATH.'\Templates\LayoutManagerView/blank.layout.html';
		return file_get_contents($template);
	}

	function setSpellCookie($value) {
		setcookie("spell_check",$value,time()+86400*365,"/");
	}

	function getSpellCookie() {
		return isset($_COOKIE['spell_check']) && $_COOKIE['spell_check']==1? TRUE : FALSE;
	}

}
?>