<?php

class ErrorsLogView extends Slot {

	var $ModuleID = 4;
	var $SectionID = 40;
	var $target = array();
	var $request = array();
	var $order = array('Hits', 'Address', 'Date');

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

	function init() {
		global $TOOLS_PATH;
		$this->request['pageRecordsQty'] = 50;
		$this->request['curPageNumber'] = isset($this->LocalTarget[2]) ? $this->LocalTarget[2] + 1 : 1;
		if(!empty($this->Request)) {
			$this->Action->processEvent($this->SectionID,'clear_errors',array(),$this)
			and header('Location: '.$this->sHome.'/Registar/ErrorsLog'.(!empty($this->LocalTarget[0])? '/'.$this->LocalTarget[0] : '').(!empty($this->LocalTarget[1])? '/'.$this->LocalTarget[1] : '').$this->SID);
		}
		switch(@$this->LocalTarget[0]) {
			default:
			case 'Hits': $this->target[0] = 'Hits'; $this->request['order'] = 'hits'; break;
			case 'Address': $this->target[0] = 'Address'; $this->request['order'] = 'path'; break;
			case 'Date': $this->target[0] = 'Date'; $this->request['order'] = 'date'; break;
		}
		switch(@$this->LocalTarget[1]) {
			default:
			case 'DESC': $this->target[1] = 'DESC'; $this->request['direction'] = 'DESC'; break;
			case 'ASC': $this->target[1] = 'ASC'; $this->request['direction'] = 'ASC'; break;
		}
		$this->Action->processEvent($this->SectionID,'select_logs_errors', $this->request, $this);
		$this->getPageControl($this->sHome.'/Registar/ErrorsLog/'.$this->target[0].'/'.$this->target[1]);
	}

	function fillElements() {
		GLOBAL $REGISTRY;
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'select_logs_errors');
		$this->TempFillEls['order'] = $this->target[0];
		$this->TempFillEls['direction'] = $this->target[1];
		$this->TempFillEls['cur'] = isset($this->LocalTarget[2]) ? '/'.$this->LocalTarget[2] : '';
		foreach ($this->order as $value)
			$this->TempFillEls['to_'.strtolower($value).'_direction'] = $this->target[1];
		$this->TempFillEls['to_'.strtolower($this->target[0]).'_direction'] = $this->target[1] == 'ASC' ? 'DESC' : 'ASC';
		$this->TempFillEls[strtolower($this->target[0]).'_direction'] = $this->target[1] == 'ASC' ? '<img src="'.$REGISTRY['Globals']['static']['adminpicPath'].'/arrow_up.gif">' : '<img src="'.$REGISTRY['Globals']['static']['adminpicPath'].'/arrow_down.gif">';
		foreach($this->PreparedTemplates['curPage'] as $key => $value) {
			$this->TempFillEls['logs'][] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty'] * ($this->PreparedTemplates['curPageNumber'] - 1)) + ($key + 1),
				'path' => wordwrap($value['path'], 75, "<br />\n", 1),
				'hits' => $value['hits'],
				'date' => preg_replace('/\..*/', '', $value['date']),
			);
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_logs_errors');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'clear_errors');
	}
}
?>