<?php

class PackagesReportView extends Slot {
	
	var $SectionID = 40;
	var $ModuleID = 4;
	var $target = array();
	var $request = array ();
	var $order = array('Id', 'Name'/*, 'Comment'*/, 'DateChanged');
	
	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 'DateChanged': $this->target[0] = 'DateChanged'; $this->request['order'] = 'date_changed'; break;
			case 'Id': $this->target[0] = 'Id'; $this->request['order'] = 'id'; break;
			case 'Name': $this->target[0] = 'Name'; $this->request['order'] = 'name'; break;
			//case 'Comment': $this->target[0] = 'Comment'; $this->request['order'] = 'comment'; 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_packages', $this->request, $this);
		$this->getPageControl($this->Home.'/Registar/PackagesReport/'.$this->target[0].'/'.$this->target[1]);
		$this->setSchemeTemplate($this->Scheme);
	}
	
	function fillElements() {
		GLOBAL $REGISTRY;
		$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'][$key] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty'] * ($this->PreparedTemplates['curPageNumber'] - 1)) + ($key + 1),
				'id' => $value['id'],
				'name' => '<a href="/Registar/PackageManager/Look/'.$value['id'].'">'.$value['name'].'</a>',
				'comment' => wordwrap($value['comment'], 35, " ", 1),
				'date_changed' => $value['date_changed'],
			);
			foreach($value['publish'] as $ind => $val){//echo ($ind%2).'<br>';
				$this->TempFillEls['logs'][$key]['publish'][] = array(
					'bgcolor' => ($ind % 2) ? 'aliceblue' : 'white',
					'img' => $val['type'] == 1 ? 'arrow_up' : 'arrow_down',
					'host' => $val['hostpath'],
					'date' => $val['date_published'],
					'user' => $val['username'],
					'success_img' => $val['successful'] ? 'tick1' : 'cross_red',
				);
			}
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_logs_packages');
	}
	
}

?>