<?php
class TemplatesReportView extends Slot {

	var $ModuleID = 4;
	var $SectionID = 40;
	var $target = array();
	var $request = array ();
	var $order = array('Id', 'Name',);

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

	function init() {
		$this->request['pageRecordsQty'] = 50;
		$this->request['curPageNumber'] = isset($this->LocalTarget[2]) ? $this->LocalTarget[2] + 1 : 1;
		switch(@$this->LocalTarget[0]) {
			default:
			case 'Id': $this->target[0] = 'Id'; $this->request['order'] = 'id'; break;
			case 'Name': $this->target[0] = 'Name'; $this->request['order'] = 'name'; break;
		}
		switch(@$this->LocalTarget[1]) {
			default:
			case 'ASC': $this->target[1] = 'ASC'; $this->request['direction'] = 'ASC'; break;
			case 'DESC': $this->target[1] = 'DESC'; $this->request['direction'] = 'DESC'; break;
		}
		$this->Action->processEvent($this->SectionID, 'select_logs_templates', $this->request, $this);
		$this->getPageControl($this->Home.'/Registar/TemplatesReport/'.$this->target[0].'/'.$this->target[1]);
	}

	function fillElements() {
		GLOBAL $REGISTRY;
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID, 'select_logs_templates');
		$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 $ind => $val) {
			$this->TempFillEls['logs'][] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty'] * ($this->PreparedTemplates['curPageNumber'] - 1)) + ($ind + 1),
				'id' => $val['id'],
				'name' => '<a href="/Registar/TemplateManager/Update/'.$val['id'].'">'.$val['name'].'</a>',
				'page' => implode('<br/>', $val['page_name']),
				'path' => implode('<br/>', $val['path']),
			);
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_logs_templates');
	}
	
}
?>