<?php

class SiteValidatorView extends Slot {

	var $SectionID = 39;
	var $ModuleID = 4;
	var $log;
	var $subjects = array('Registry','Menus','Layouts','Pages','Templates','Redirects');
	var $messages = array(	'file' => ' is refering to nonexistent file ',
							'braces' => ' includes invalid construction ');

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

	function init() {
		if(!empty($this->LocalTarget[0]) && $this->LocalTarget[0]=='Log') $this->Scheme = 'log';
		$this->setSchemeTemplate($this->Scheme);
	}

	function fillElements() {
		switch($this->Scheme) {
			default: $this->fillDefault();
			case 'log': $this->fillLog(); break;
		}
	}

	function fillDefault() {}

	function fillLog() {
		if(!empty($this->Request)) {
			$this->Action->processEvent($this->SectionID,'log',array('type' => 2,'entity' => 3,'event' => 7,'value' => 'Validate site','object' => 0),$this);
			foreach ($this->subjects as $val){
				print $this->colorize($val.': ','black','bold');
				$this->Action->processEvent($this->SectionID,'validate_site',array('subject' => $val),$this);
				$this->log = $this->PreparedTemplates;
				if (empty($this->log)) print ' OK<br>';
				else{
					print '<br>';
					foreach ($this->log as $key => $value) print $this->makeMessage($val,$value);
				}
			}
		}
	}
	
	function makeMessage($subject='',$values=array()){
		$mes = '';
		switch ($subject){
			case 'Registry': $mes = $this->colorize('Error:','red','bold').' Page "<a target="_blank" href="'.$values['edit_path'].'">'.$this->colorize($values['name'],'blue','bold').'</a>" is not possible to display. It has to be updated<br>'; break;
			case 'Menus': $mes = $this->colorize('Error:','red','bold').' Menu "<a target="_blank" href="'.$values['edit_path'].'">'.$this->colorize($values['name'],'blue','bold').'</a>"'.$this->messages['file'].$this->colorize($values['path'],'blue','normal').'<br>'; break;
			case 'Layouts': $mes = $this->colorize('Error:','red','bold').' Layout "<a target="_blank" href="'.$values['edit_path'].'">'.$this->colorize($values['name'],'blue','bold').'</a>"'.$this->messages[$values['type']].$this->colorize($values['path'],'blue','normal').'<br>'; break;
			case 'Pages': $mes = $this->colorize('Error:','red','bold').' Page "<a target="_blank" href="'.$values['edit_path'].'">'.$this->colorize($values['name'],'blue','bold').'</a>"'.$this->messages[$values['type']].$this->colorize($values['path'],'blue','normal').'<br>'; break;
			case 'Templates': $mes = $this->colorize('Error:','red','bold').' Template "<a target="_blank" href="'.$values['edit_path'].'">'.$this->colorize($values['name'],'blue','bold').'</a>"'.$this->messages[$values['type']].$this->colorize($values['path'],'blue','normal').'<br>'; break;
			case 'Redirects': $mes = $this->colorize('Error:','red','bold').' List of <a target="_blank" href="/Registar/RedirectEditor">'.$this->colorize('Redirects','blue','bold').'</a> contains redirect to nonexistent page '.$this->colorize($values['path'],'blue','normal').'<br>'; break;
		}
		return $mes;
	}
	
	function colorize($text='',$color='red',$bold='normal') {
		return '<span style="color:'.$color.';font-weight:'.$bold.';">'.$text.'</span>';
	}
}
?>