<?php
class JSReportView extends Slot {

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

	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;
			case 'Path': $this->target[0] = 'Path'; $this->request['order'] = 'path'; 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_js', $this->request, $this);
		$this->getPageControl($this->Home.'/Registar/JSReport/'.$this->target[0].'/'.$this->target[1]);
	}

	function fillElements() {
		global $REGISTRY;
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'select_logs_js');
		$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) {
			//printArray($val);
			if(!empty($val['meta']))
				foreach($val['meta'] as $key_=>$val_)
					$val['meta'][$key_] = '&lt;&nbsp;'.wordwrap($val_, 45, '<br>', 1);
			if(!empty($val['js']))
				foreach($val['js'] as $key_=>$val_)
					$val['js'][$key_] = '&lt;&nbsp;'.wordwrap($val_, 45, '<br>', 1);
			$val['path'] = wordwrap($val['path'], 45, '<br>', 1);
			$this->TempFillEls['logs'][] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty']*($this->PreparedTemplates['curPageNumber']-1))+($ind+1),
				'id' => $val['id'],
				'name' => '<a href="/Registar/ContentManager/Update/'.$val['id'].'">'.$val['name'].'</a>',
				'path' => $val['path'],
				'js' => (!empty($val['meta'])? '<div style="color:#CB8A02">In js zone</div>'.implode('<br/>',$val['meta']) : '').(!empty($val['js'])? '<div style="color:#CB8A02">In body page</div>'.implode('<br/>',$val['js']) : ''),
			);
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_logs_js');
	}
	
}
?>