<?php

class DownloadProductView extends Slot {

	var $ModuleID = 2;
	var $SectionID = 23;
	var $id = 0;
	var $info = array();
	var $nav_name = '';

	function __construct($pquery) {
		parent::__construct($pquery);
		$this->Cache = 0;
		$this->Passing = TRUE;
	}

	function init() {
		if(!empty($this->Target[2])) {
			$this->Action->processEvent($this->SectionID,'get_product_id_by_path',array('path' => $this->Target[2]),$this);
			if(empty($this->PreparedTemplates['id'])) header('Location: '.$this->Home.$this->SID);
			else $this->id = $this->PreparedTemplates['id'];
		}
		else header('Location: '.$this->Home.$this->SID);
		/*$this->Action->processEvent($this->SectionID,'open_meta',array('item' => $this->id,'module' => 2),$this);
		foreach($this->PreparedTemplates['meta_langs'] as $key => $value) {
			if($value['lang']==$this->LM->Langs[$this->language] && $value['content_type']==1) {
				$this->info['metainfo'][] = array(
					'title' => eregi_replace('"','',$value['title']),
					'description' => eregi_replace('"','',$value['description']),
					'keywords' =>eregi_replace('"','',$value['keywords']),
					'robots' => eregi_replace('"','',$value['robots']),
				);
			}
		}*/
		$this->Action->processEvent($this->SectionID,'open_download',array('id' => $this->id),$this);
		$this->info['name'] = !empty($this->PreparedTemplates['nav_name'])? $this->PreparedTemplates['nav_name'] : $this->PreparedTemplates['name'];
		//printArray($this->id);
		switch(@$this->Target[3]) {
				case 'downloadpicture': {
					$this->info['description'] = 'Product Picture';
					$this->info['url'] = makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'here');
					$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
					$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
					//if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/ATNNightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
					if($this->check3D($this->id)) $this->info['3d'] = array(array('link' => makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','3D View Package')));
					if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
					if($this->checkUG($this->id)) $this->info['ug'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','User Guide (PDF file)')));
				break;
				}
				case 'download3dzip': {
					$this->info['description'] = '3D View Package';
					if(!$this->check3D($this->id)) $this->Scheme = 'empty';
					else {
						$this->info['url'] = makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','here');
						$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
						$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
						if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
						//if($this->check3D($this->id)) $this->info['3d'] = array(array('link' => makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','3D View Package')));
						if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
						if($this->checkUG($this->id)) $this->info['ug'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','User Guide (PDF file)')));
					}
				break;
				}
				case 'downloadallzip': {
					$this->info['description'] = 'Full Information Package';
					$this->info['url'] = makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','here');
					//$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
					$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
					if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
					if($this->check3D($this->id)) $this->info['3d'] = array(array('link' => makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','3D View Package')));
					if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
					if($this->checkUG($this->id)) $this->info['ug'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','User Guide (PDF file)')));
				break;
				}
				/*case 'downloaduserguidepdf': {
					$this->info['description'] = 'User Guide';
					if(!$this->checkUG($this->id)) $this->Scheme = 'empty';
					else {
						$this->info['url'] = makeLink($this->Home.'/ATNNightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','here');
						$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
						$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
						if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/ATNNightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
						if($this->check3D($this->id)) $this->info['3d'] = array(array('link' => makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','3D View Package')));
						if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
						//if($this->checkUG($this->id)) $this->info['ug'] = array(array('link' => makeLink($this->Home.'/ATNNightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','User Guide (PDF file)')));
					}
				break;
				}*/
				case 'downloaduserguidepdf': {  //printArray($this->Target);exit;
					$this->info['description'] = 'User Guide';
					if(!$this->checkNewUG($this->id, $this->Target[4])) $this->Scheme = 'empty';
					else {
						$this->info['url'] = makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide_'.$this->Target[4].'.pdf','here');
						$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
						$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
						if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
						if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
					}
				break;
				}
				case 'downloadspecificationsheetpdf': { 
					$this->info['description'] = 'Specification Sheet';
					if(!$this->checkSS($this->id)) $this->Scheme = 'empty';
					else {
						$this->info['url'] = makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','here');
						$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
						$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
						//if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/ATNNightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
						if($this->check3D($this->id)) $this->info['3d'] = array(array('link' => makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','3D View Package')));
						if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
						if($this->checkUG($this->id)) $this->info['ug'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','User Guide (PDF file)')));
					}
				break;
				}
				case 'downloadhiresolutionimage': {
					$this->info['description'] = 'Hi Resolution Image';
					if(!$this->checkHR($this->id)) $this->Scheme = 'empty';
					else {
						$this->info['url'] = makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','here');
						$this->info['all'] = array(array('link' => makeLink($this->Home.'/DownloadAllZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_All.zip','Full Information Package')));
						$this->info['pic'] = array(array('link' => makeLink($this->Home.'/DownloadPicture/'.$this->PreparedTemplates['path'],'Product Picture')));
						if($this->checkSS($this->id)) $this->info['ss'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_SpecSheet.pdf','Specification Sheet (PDF file)')));
						if($this->check3D($this->id)) $this->info['3d'] = array(array('link' => makeLink($this->Home.'/3DZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_3D.zip','3D View Package')));
						//if($this->checkHR($this->id)) $this->info['hi'] = array(array('link' => makeLink($this->Home.'/Hi-ResolutionZip/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_HiResolutionImage.zip','Hi-Resolution Image')));
						if($this->checkUG($this->id)) $this->info['ug'] = array(array('link' => makeLink($this->Home.'/NightVisionPDF/'.$this->PreparedTemplates['path'].'/'.$this->PreparedTemplates['path'].'_UserGuide.pdf','User Guide (PDF file)')));
					}
				break;
				}
				default: $this->Scheme = 'empty'; break;
			}
		$this->setSchemeTemplate($this->Scheme);
	}

	function check3D($id = 0) {
		if(!file_exists($this->ImagePath.'/products/'.$id.'/3D/01.jpg')) return false;
		return true;
	}

	function checkUG($id = 0) {
		if(!file_exists($this->ImagePath.'/products/'.$id.'/ug.pdf')) return false;
		return true;
	}
	
	function checkNewUG($id = 0, $index) {
		if(!file_exists($this->ImagePath.'/products/'.$id.'/userguides/'.$index.'.pdf')) return false;
		return true;
	}

	function checkSS($id = 0) {
		if(!file_exists($this->ImagePath.'/products/'.$id.'/ss.pdf')) return false;
		return true;
	}

	function checkHR($id = 0) {
		if(!file_exists($this->ImagePath.'/products/'.$id.'/hi.tif')) return false;
		return true;
	}

	function fillElements() {
		$this->TempFillEls = $this->info;
	}
}
?>