<?php
GLOBAL $TOOLS_PATH;
include_once($TOOLS_PATH.'/Archive.class.inc');
include_once($TOOLS_PATH.'/Transfer.class.inc');
include_once($TOOLS_PATH.'/Database.class.inc');
include_once($TOOLS_PATH.'/CheckRemoteServer.class.inc');

class DeletedObjectsProcessingReportView extends Slot {

	var $SectionID = 40;
	var $ModuleID = 4;
	var $report_type = array();
	var $target = array();
	var $request = array ();
	var $order = array('Id', 'User', 'DateProcessed', 'Host');

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

	function init() {
		if(@$this->LocalTarget[0] == 'View'){
			if(empty($this->LocalTarget[1]) || !is_numeric($this->LocalTarget[1])){
				header('Location: '.$this->Home.'/Registar/DeletedObjectsProcessingReport'.$this->SID);
				return;
			}
			$this->Action->processEvent($this->SectionID, 'select_report_types', array(), $this);
			$this->report_type = $this->PreparedTemplates;
			$this->Action->processEvent($this->SectionID, 'open_deleted_objects_processing', array('id' => $this->LocalTarget[1]), $this);
			if(!empty($this->PreparedTemplates['_error'])){
				header('Location: '.$this->Home.'/Registar/DeletedObjectsProcessingReport'.$this->SID);
				$this->clearAllTemplates();
				return;
			}
			$this->Scheme = 'view';
		}
		else{
			$this->Scheme = 'default';
			$this->request['pageRecordsQty'] = 50;
			$this->request['curPageNumber'] = isset($this->LocalTarget[2]) ? $this->LocalTarget[2] + 1 : 1;
			switch(@$this->LocalTarget[0]) {
				default:
				case 'DateProcessed': $this->target[0] = 'DateProcessed'; $this->request['order'] = 'date_processed'; break;
				case 'Id': $this->target[0] = 'Id'; $this->request['order'] = 'id'; break;
				case 'User': $this->target[0] = 'User'; $this->request['order'] = 'user'; break;
				case 'Host': $this->target[0] = 'Host'; $this->request['order'] = 'host'; 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_deleted_objects_processings', $this->request, $this);
			$this->getPageControl($this->Home.'/Registar/DeletedObjectsProcessingReport/'.$this->target[0].'/'.$this->target[1]);
		}
		$this->setSchemeTemplate($this->Scheme);
	}

	function fillElements() {
		switch($this->Scheme) {
			case 'view': $this->fillView(); break;
			case 'default': default: $this->fillDefault(); break;
		}
	}
	
	function fillDefault() {
		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">';
		$count = count($this->PreparedTemplates['curPage']);
		for($i = 0; $i < $count; $i++){
			$this->TempFillEls['logs'][$i] = $this->PreparedTemplates['curPage'][$i];
			$this->TempFillEls['logs'][$i]['number'] = $i + 1;
			$this->TempFillEls['logs'][$i]['direction_img'] = $this->PreparedTemplates['curPage'][$i]['type'] == 1 ? 'arrow_up' : 'arrow_down';
			$this->TempFillEls['logs'][$i]['success_img'] = $this->PreparedTemplates['curPage'][$i]['successful'] ? 'tick1' : 'cross_red';
		}
		$this->clearAllTemplates();
	}
	
	function fillView(){
		$this->TempFillEls = $this->PreparedTemplates;
		$this->TempFillEls['direction'] = $this->PreparedTemplates['type'] == 1 ? 'Outcoming' : 'Incoming';
		$date_processed = explode('.', $this->PreparedTemplates['date_processed']);
		$this->TempFillEls['date_processed'] = $date_processed[0];
		$this->TempFillEls['successful'] = $this->PreparedTemplates['successful'] ? 'YES' : 'NO';
		$count = count($this->PreparedTemplates['report']);
		for ($i = 0; $i < $count; $i++) $this->TempFillEls['report'][$i]['type'] = strtolower($this->report_type[$this->TempFillEls['report'][$i]['type']]);
		if(empty($this->PreparedTemplates['result'])) $this->TempFillEls['script_result_disp'] = 'none';
		$this->clearAllTemplates();
	}
	
	function clearAllTemplates(){
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_logs_deleted_objects_processings');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'select_report_types');
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID, 'open_deleted_objects_processing');
	}
}
?>