<?php

class OffermaticaReportView extends Slot {

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

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

	function init() {
		$this->request['pageRecordsQty'] = 50;
		$this->request['curPageNumber'] = isset($this->LocalTarget[3]) ? $this->LocalTarget[3] + 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 'Script': $this->target[0] = 'Script'; $this->request['order'] = 'script'; break;
			case 'Div': $this->target[0] = 'Div'; $this->request['order'] = 'div'; break;
			case 'Call': $this->target[0] = 'Call'; $this->request['order'] = 'call'; 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;
		}
		switch(@$this->LocalTarget[2]) {
			default: case 'Pages': $this->target[2] = 'Pages'; $this->request['type'] = 'pages'; break;
			case 'Layouts': $this->target[2] = 'Layouts'; $this->request['type'] = 'layouts'; break;
			case 'Templates': $this->target[2] = 'Templates'; $this->request['type'] = 'templates'; break;
			case 'DefaultJS': $this->target[2] = 'DefaultJS'; $this->request['type'] = 'default_js'; break;
		}
		$this->Action->processEvent($this->SectionID, 'select_offermatica', $this->request, $this);
		$this->getPageControl($this->Home.'/Registar/OffermaticaReport/'.$this->target[0].'/'.$this->target[1].'/'.$this->target[2]);
	}

	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['title'] = $this->target[2];
		$this->TempFillEls['cur'] = isset($this->LocalTarget[3]) ? '/'.$this->LocalTarget[3] : '';
		$tick1 = "<img src='".$REGISTRY['Globals']['static']['adminpicPath']."/tick2.gif' border='0'>";
		$tick2 = "<img src='".$REGISTRY['Globals']['static']['adminpicPath']."/tick1.gif' border='0'>";
		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">';
		if ($this->target[2] != 'Pages') $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">';
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'select_offermatica');
		foreach($this->PreparedTemplates['curPage'] as $key => $value) {
			$this->TempFillEls['logs'][] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty'] * ($this->PreparedTemplates['curPageNumber'] - 1)) + ($key + 1),
				'id' => $value['id'],
				'name' => $value['name'],
				'path' => $value['path'],
				'script' => (isset($value['script']) ? (isset($value['cont_s']) ? $tick1:'').(isset($value['jszone_s']) ? $tick2:'') : '&nbsp;'),
				'div' => (isset($value['div']) ? (isset($value['cont_d']) ? $tick1:'').(isset($value['jszone_d']) ? $tick2:'') : '&nbsp;'),
				'call' => (isset($value['call']) ? (isset($value['cont_c']) ? $tick1:'').(isset($value['jszone_c']) ? $tick2:'') : '&nbsp;'),
				'but1' => ($this->PreparedTemplates['type'] == 'pages') ? '<a href="'.$REGISTRY['Globals']['static']['homePath'].'/Registar/MetaManager/Page/'.$value['id'].'" class=adminlink>Edit JS Zone</a>' : '&nbsp;',
				'but2' => ($this->PreparedTemplates['type'] == 'pages') ? '<a href="'.$REGISTRY['Globals']['static']['homePath'].'/Registar/ContentManager/Update/'.$value['id'].'" class=adminlink>Edit Page</a>' : '&nbsp;'
			);
		}
		$this->TempFillEls['text'][] = array('ticks' => ($this->PreparedTemplates['type']=='pages') ? $tick1.' <b>- in page content;</b>  '.$tick2.' <b>- in JS zones</b>' : '');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_offermatica');
	}
}
?>