<?php

//GLOBAL $Debug; $Debug =  true; 

//error_reporting(E_ALL);
global $TOOLS_PATH;
include_once($TOOLS_PATH.'\File.functions.inc');
class ProductsManagerView extends Slot {
	var $SectionID = 19;
	var $ModuleID = 2;
	var $articles = array();
	var $technologies = array();
	var $related = array();
	var $warranty = array();
	var $rate = array();
	var $level = array();
	var $policy = array();
	var $core = array();
	var $lens = array();
	var $brand = array();
	var $generation = array();
	var $categories = array();
	var $parentitems = array();
	var $products = array();
	var $accessories = array();
	var $kits = array();
	var $shipcosts = array();
	var $upload_formats = array(
		'image/jpeg' => 'jpg',
		'image/gif' => 'gif',
		'image/pjpeg' => 'jpg',
		'image/jpeg' => 'jpg',
		'image/png' => 'png',
	);
	var $upload_settings = array(
		'prew_width' => '',
		'prew_height' => '',
		'big_width' => '',
		'big_height' => '',
		'middle_width' => '',
		'middle_height' => '',
		'small_width' => '',
		'small_height' => '',
		'3d_width' => '',
		'3d_height' => '',
		'image_width' => '',
		'image_height' => '',
	);
	
	var $upload_size = array(
	    'small_w' => 60,
        'small_h' => 43,

        'prew_w' => 170,
        'prew_h' => 121,        
	
        'middle_w' => 675,
        'middle_h' => 482,        
	
        'big_w' => 1400,
        'big_h' => 1000,        
       
        'image_w' => 540,
        'image_h' => 350,
    );
	
	
	var $colors = array(
		'red' => '#DC143C',
		'yellow' => '#FF8C00',
		'green' => '#006400',
		'black' => '#000000',
		'blue' => '#4169E1',
	);
	var $terminated = false;

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

	function init() {
		global $TOOLS_PATH;
		$undo = 0;
		$products = $this->Db->SelectGuide(array('parentitem i','product g'),array('g.id','g.name'),array('g.item' => 'i.id','i.itemtype' => 1));
		$this->prod_colors = $this->Action->Server->getGuide('color');
		switch(@$this->LocalTarget[0]) {
			case 'CRList': {
				$this->customerreviews = $this->Db->SelectGuide(array('customerreview g'),array('g.id','g.name'),array('1' => '1'));
				foreach($this->customerreviews as $key => $value) {
					$this->TempFillEls['items'][] = array(
						'number' => $key,
						'name' => $value,
						'name2' => htmlspecialchars(strip_tags($value), ENT_QUOTES),
						'id' => @$this->LocalTarget[1],
						'form_name' => 'product',
					);
				}
				$this->Scheme = 'crlist';
			break;
			}
			case 'ViewAll': {
				if($this->server_type=='dev') {
					$request = $this->LocalTarget;
					$request['pageRecordsQty'] = 20;
					$request['curPageNumber'] = isset($this->LocalTarget[2])? $this->LocalTarget[2]+1 : 1;
					$this->Action->processEvent($this->SectionID,'select_productcomments',$request,$this);
					if(!empty($this->PreparedTemplates['_error'])) $this->Scheme = 'message';
					else {
						$this->getPageControl($this->Home.'/Registar/ProductsManager/ViewAll/'.$this->LocalTarget[1]);
						if(empty($this->PreparedTemplates['curPage'])) $this->Scheme = 'empty';
					}
					$this->Scheme = 'viewall';
				}
				else $this->Scheme = 'default';
			break;
			}
			case 'DeleteFile': {
				if(!empty($this->LocalTarget[1]) && in_array($this->LocalTarget[1],array_keys($products))) {
					switch(@$this->LocalTarget[2]) {
						case 'ug': {
							$this->Action->processEvent($this->SectionID,'delete_file',array('id' => $this->LocalTarget[1],'type' => 7),$this);
							if(empty($this->PreparedTemplates['_error'])) die('200');
							else die('400');
						break;
						}
						case 'ss': {
							$this->Action->processEvent($this->SectionID,'delete_file',array('id' => $this->LocalTarget[1],'type' => 6),$this);
							if(empty($this->PreparedTemplates['_error'])) die('200');
							else die('400');
						break;
						}
						case 'hi': {
							$this->Action->processEvent($this->SectionID,'delete_file',array('id' => $this->LocalTarget[1],'type' => 5),$this);
							if(empty($this->PreparedTemplates['_error'])) die('200');
							else die('400');
						break;
						}
						default: die('400'); break;
					}
				}
			break;
			}
			case 'Add': {
				$this->getGuides();
				$this->Action->processEvent($this->SectionID,'tree',array('full' => 0,'admin' => 1,'parent' => 0),$this);
				$this->Action->processEvent($this->SectionID,'open',array('id' => 0,'ship' => 1),$this);
				$this->Scheme = 'action';
			break;
			}
			case 'Update': case 'Duplicate': case 'Delete': {
				$this->getGuides();
				if($this->server_type=='dev') {
					if(!empty($this->LocalTarget[3]) && validate(intval($this->LocalTarget[3])) && $this->LocalTarget[2]=='Undo')
						$undo = 1;
					else $undo = 0;
//printArray($products);printArray($this->LocalTarget);exit;					
					if(!empty($this->LocalTarget[1]) && in_array($this->LocalTarget[1],array_keys($products))) {
						$array = array('id' => $this->LocalTarget[1],'ship' => 1);
						if($undo == 1) $array['undo'] = $this->LocalTarget[3];
						$this->Action->processEvent($this->SectionID,'getlock',array('product' => $this->LocalTarget[1],'member' => $this->Action->Security->currentuser->id),$this);
						if(!empty($this->PreparedTemplates['access_flag']) && $this->PreparedTemplates['access_flag'] != $this->Action->Security->currentuser->id) {
							header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
							$this->terminated = true;
							return;
						}
						else {
							if(empty($this->PreparedTemplates['access_flag'])) {
								$this->Action->processEvent($this->SectionID,'lock',array('product' => $this->LocalTarget[1],'member' => $this->Action->Security->currentuser->id),$this);
							}
							$this->Action->processEvent($this->SectionID,'tree',array('full' => 0,'admin' => 1,'parent' => 0),$this);
							$this->Action->processEvent($this->SectionID,'open',$array,$this);
							if(!empty($this->PreparedTemplates['_error'])) header('Location: '.$this->Home.'/Registar/CategoriesManager'.$this->SID);
							else $this->Scheme = 'action';
						}
					}
					else header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
				}
				else header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
			break;
			}
			case 'Unlock': {
				if (!isset($this->LocalTarget[1])) header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
				if($this->server_type=='dev' ) {
					$this->Action->processEvent($this->SectionID,'getlock',array('product' => $this->LocalTarget[1],'member' => $this->Action->Security->currentuser->id),$this);
					if(!empty($this->PreparedTemplates)){
						$this->Action->processEvent($this->SectionID,'unlock',array('product' => $this->LocalTarget[1],'member' => $this->Action->Security->currentuser->id),$this);
					}	
					header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
				}
				else $this->Scheme = 'default';
			break;
			}
			case 'Sort': {
				$this->Action->processEvent($this->SectionID,'list',array('full' => 0),$this);
				$this->Scheme = 'sort';
			break;
			}
			default: {
				if(!empty($this->LocalTarget[0])){
					header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
					$this->terminated = true;
					return;
				}
				$this->Action->processEvent($this->SectionID,'list',array('full' => 1),$this);
				$this->Scheme = 'default';
			break;
			}
		}
		if(!empty($this->Request)) {			//printArray($this->Request['form']); exit;
			switch($this->getRequestField('step')) {
				case 'add': case 'edit': {
					$this->Request['form']['id_user'] = $this->Action->Security->currentuser->id;
					if($undo == 1) $this->Request['form']['_undo_'] = $this->LocalTarget[3];
					$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open');
					$this->validateForm()
					and $this->Action->processEvent($this->SectionID,'save',$this->getRequestField('form'),$this)
					and header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);					
				break;
				}
				case 'delete': {
					include ($TOOLS_PATH.'\checker.php');
					$this->check = check_to_delete($this->getRequestFormField('id'),'Product');
					if(isset($this->check['pages']) && empty($this->check['pages']) &&
					isset($this->check['menues']) && empty($this->check['menues']) &&
					isset($this->check['layouts']) && empty($this->check['layouts']) &&
					isset($this->check['templates']) && empty($this->check['templates'])) {
						$this->Action->processEvent($this->SectionID,'delete',$this->getRequestField('form'),$this)
						and $this->clearUndo($this->getRequestFormField('id'))
						and header('Location: '.$this->Home.'/Registar/ProductsManager'.$this->SID);
					}
					else $this->Scheme = 'nodelete';
				break;
				}
				case 'sort': {
					//$this->sortingPages() and 
					$this->Action->processEvent($this->SectionID,'sort',$this->getRequestField('form'),$this)
					and header('Location: '.$this->Home.'/Registar/ProductsManager/Sort'.$this->SID);
				break;
				}
			}
		}
		$this->setSchemeTemplate($this->Scheme);
	}

	function makeImageLink($type,$id) {
		foreach($this->upload_formats as $value) {
			if(file_exists($this->ImagePath.'/products/'.$id.'/'.$type.'.'.$value))
				return makeImage($this->ImagePath.'/products/'.$id.'/'.$type.'.'.$value,$this->ImageWPath.'/products/'.$id.'/'.$type.'.'.$value,'','',array(),0,'',$type.'img');
		}
		return makeImage($this->ImagePath.'/1.gif',$this->ImageWPath.'/1.gif','','',array(),0,'',$type.'img');
	}

	function deleteFiles($array) {
		$path = $this->ImagePath.'/products/'.$array['id'];
		$output = shell_exec("rm -rf ".$path." 2>&1");
	}

	function saveFiles($array) {
		$path = $this->ImagePath.'/products/'.$array['id'];
		if($this->getRequestField('step')=='add' || !file_exists($path)) {
			umask(0002); mkdir($path,0775);
		}
		if(validate($this->getRequestFormField('duplicate_id'))) {
			$output = shell_exec("cp -r -a ".$this->ImagePath."/products/".$this->getRequestFormField('duplicate_id')."/* ".$path." 2>&1");
		}
		if(!file_exists($path.'/images')) {
			umask(0002); mkdir($path.'/images',0775);
			if(!file_exists($path.'/images/big')) {
				umask(0002); mkdir($path.'/images/big',0775);
			}
			if(!file_exists($path.'/images/middle')) {
				umask(0002); mkdir($path.'/images/middle',0775);
			}
			if(!file_exists($path.'/images/small')) {
				umask(0002); mkdir($path.'/images/small',0775);
			}
		}
		if(!file_exists($path.'/userguides')) {
			umask(0002); mkdir($path.'/userguides',0775);
		}
		
		if(!file_exists($path.'/3D')) {
			umask(0002); mkdir($path.'/3D',0775);
		}
		if(!empty($this->Request['big_image_link'])) {
			if(file_exists($path.'/big.jpg')) unlink($path.'/big.jpg');
		}
		else {
			if(!empty($this->Request['form']['big'])) {
				$image = $this->Request['form']['big'];
				if(!empty($image['_tmp_name'])) {
					if(file_exists($path.'/big.jpg')) unlink($path.'/big.jpg');
					copy($image['_tmp_name'],$path.'/big.jpg');
					chmod($path.'/big.jpg',0664);
				}
			}
		}
		if(isset($this->Request['prew_image_link']) &&  !empty($this->Request['prew_image_link'])) {
			if(file_exists($path.'/prew.jpg')) unlink($path.'/prew.jpg');
		}
		else {
			if(!empty($this->Request['form']['prew'])) {
				$image = $this->Request['form']['prew'];
				if(!empty($image['_tmp_name'])) {
					if(file_exists($path.'/prew.jpg')) unlink($path.'/prew.jpg');
					copy($image['_tmp_name'],$path.'/prew.jpg');
					chmod($path.'/prew.jpg',0664);
				}
			}
		}
		if(!empty($this->Request['middle_image_link'])) {
			if(file_exists($path.'/middle.jpg')) unlink($path.'/middle.jpg');
		}
		else {
			if(!empty($this->Request['form']['middle'])) {
				$image = $this->Request['form']['middle'];
				if(!empty($image['_tmp_name'])) {
					if(file_exists($path.'/middle.jpg')) unlink($path.'/middle.jpg');
					copy($image['_tmp_name'],$path.'/middle.jpg');
					convertimg( $path.'/middle.jpg', $path.'/middle.jpg', $this->upload_size['prew_w'], $this->upload_size['prew_h'],true);					
					chmod($path.'/middle.jpg',0664);
				}
			}
		}
		if(!empty($this->Request['form']['ug'])) {
			$image = $this->Request['form']['ug'];
			if(!empty($image['_tmp_name'])) {
				if(file_exists($path.'/ug.pdf')) unlink($path.'/ug.pdf');
				copy($image['_tmp_name'],$path.'/ug.pdf');
				chmod($path.'/ug.pdf',0664);
			}
		}
		if(!empty($this->Request['form']['ss'])) {
			$image = $this->Request['form']['ss'];
			if(!empty($image['_tmp_name'])) {
				if(file_exists($path.'/ss.pdf')) unlink($path.'/ss.pdf');
				copy($image['_tmp_name'],$path.'/ss.pdf');
				chmod($path.'/ss.pdf',0664);
			}
		}
		if(!empty($this->Request['form']['hi'])) {
			$image = $this->Request['form']['hi'];
			if(!empty($image['_tmp_name'])) {
				if(file_exists($path.'/hi.tif')) unlink($path.'/hi.tif');
				copy($image['_tmp_name'],$path.'/hi.tif');
				chmod($path.'/hi.tif',0664);
			}
		}
		/*$this->saveImages($array,$path,'3D','3d',4,'jpg');
		$this->saveImages($array,$path,'images/big','image_big',3,'jpg');
		$this->saveImages($array,$path,'images/middle','image_middle',3,'jpg');
		$this->saveImages($array,$path,'images/small','image_small',3,'jpg');*/
		$this->saveImages($array,$path,'userguides','userguide_big',7,'pdf');
		$this->saveBigMiddleSmallImages($array,$path,'images/big','image_big',3, 'jpg');
	}

	function saveBigMiddleSmallImages($object,$path,$folder,$array,$type,$ext) {
		if(!empty($this->Request[$array])) {
			$count = $max = 0;
			$images = array();
			if(!empty($object['_files'])) {
				foreach($object['_files'] as $value)
					if($value['filetype']==$type) $count+=1;
			}
			for($i = 1; $i <= $count; $i++) {
				if(isset($this->Request[$array]['name'][$i])) {
					if(!empty($this->Request[$array]['tmp_name'][$i])) {
						//---save uploaded image
						copy($this->Request[$array]['tmp_name'][$i], $path.'/'.$folder.'/'.date2pg($i).'.png');
						chmod($path.'/'.$folder.'/'.date2pg($i).'.png',0664);
						//--- BIG
						convertimg($path.'/'.$folder.'/'.date2pg($i).'.png',  $path.'/'.$folder.'/'.date2pg($i).'.'.$ext, $this->upload_size['big_w'], $this->upload_size['big_h'] ,true);
						chmod($path.'/'.$folder.'/'.date2pg($i).'.'.$ext,0664);
						//--- middle
						convertimg($path.'/'.$folder.'/'.date2pg($i).'.png',  $path.'/images/middle/'.date2pg($i).'.'.$ext, $this->upload_size['middle_w'], $this->upload_size['middle_h'],true);
						chmod($path.'/images/middle/'.date2pg($i).'.'.$ext,0664);
						//--- small
						convertimg($path.'/'.$folder.'/'.date2pg($i).'.png',  $path.'/images/small/'.date2pg($i).'.'.$ext, $this->upload_size['small_w'], $this->upload_size['small_h'],true );
						chmod($path.'/images/small/'.date2pg($i).'.'.$ext,0664);
					}
					$images[] = date2pg($i);
				}
				else if(file_exists($path.'/'.$folder.'/'.date2pg($i).'.'.$ext)) {
					if(file_exists($path.'/'.$folder.'/'.date2pg($i).'.'.$ext)) unlink($path.'/'.$folder.'/'.date2pg($i).'.'.$ext);
					if(file_exists($path.'/'.$folder.'/'.date2pg($i).'.png')) unlink($path.'/'.$folder.'/'.date2pg($i).'.png');					
					if(file_exists($path.'/images/middle/'.date2pg($i).'.'.$ext)) unlink($path.'/images/middle/'.date2pg($i).'.'.$ext);
					if(file_exists($path.'/images/small/'.date2pg($i).'.'.$ext)) unlink($path.'/images/small/'.date2pg($i).'.'.$ext);					
				}
			}
			$count = $max = count($images);
			for($i = 0; $i < $count; $i++)
				if(file_exists($path.'/'.$folder.'/'.$images[$i].'.'.$ext)) {
					rename($path.'/'.$folder.'/'.$images[$i].'.'.$ext,$path.'/'.$folder.'/'.date2pg($i+1).'.'.$ext);
					rename($path.'/images/middle/'.$images[$i].'.'.$ext,$path.'/images/middle/'.date2pg($i+1).'.'.$ext);
					rename($path.'/images/small/'.$images[$i].'.'.$ext,$path.'/images/small/'.date2pg($i+1).'.'.$ext);
				}
			foreach($this->Request[$array]['name'] as $key => $value) {
				if($key > $count) {
					if(!empty($this->Request[$array]['tmp_name'][$key])) {
						$max+=1;
						copy($this->Request[$array]['tmp_name'][$key], $path.'/'.$folder.'/'.date2pg($max).'.png');
						chmod($path.'/'.$folder.'/'.date2pg($max).'.png',0664);
						//----BIG
						convertimg($path.'/'.$folder.'/'.date2pg($max).'.png',  $path.'/'.$folder.'/'.date2pg($max).'.'.$ext, $this->upload_size['big_w'], $this->upload_size['big_h'],true);
						chmod($path.'/'.$folder.'/'.date2pg($max).'.'.$ext,0664);
						//----middle
						convertimg($path.'/'.$folder.'/'.date2pg($max).'.png',  $path.'/images/middle/'.date2pg($max).'.'.$ext, $this->upload_size['middle_w'], $this->upload_size['middle_h'],true);
						chmod($path.'/images/middle/'.date2pg($max).'.'.$ext,0664);
						//----small
						convertimg($path.'/'.$folder.'/'.date2pg($max).'.png',  $path.'/images/small/'.date2pg($max).'.'.$ext, $this->upload_size['small_w'], $this->upload_size['small_h'],true);
						chmod($path.'/images/small/'.date2pg($max).'.'.$ext,0664);
					}
				}
			}
		}
		else {
			chdir($path.'/'.$folder);
			$dir = dir('.');
			$dir->rewind();
			while($file = $dir->read()) if(is_file($file)) unlink($path.'/'.$folder.'/'.$file);
		}
	}
	
	
	function saveImages($object,$path,$folder,$array,$type,$ext) {
		if(!empty($this->Request[$array])) {
			$count = $max = 0;
			$images = array();
			if(!empty($object['_files'])) {
				foreach($object['_files'] as $value)
					if($value['filetype']==$type) $count+=1;
			}
			for($i = 1; $i <= $count; $i++) {
				if(isset($this->Request[$array]['name'][$i])) {
					if(!empty($this->Request[$array]['tmp_name'][$i])) {
						copy($this->Request[$array]['tmp_name'][$i],$path.'/'.$folder.'/'.date2pg($i).'.'.$ext);
						chmod($path.'/'.$folder.'/'.date2pg($i).'.'.$ext,0664);
					}
					$images[] = date2pg($i);
				}
				else if(file_exists($path.'/'.$folder.'/'.date2pg($i).'.'.$ext)) {
					unlink($path.'/'.$folder.'/'.date2pg($i).'.'.$ext);
				}
			}
			$count = $max = count($images);
			for($i = 0; $i < $count; $i++)
				if(file_exists($path.'/'.$folder.'/'.$images[$i].'.'.$ext))
					rename($path.'/'.$folder.'/'.$images[$i].'.'.$ext,$path.'/'.$folder.'/'.date2pg($i+1).'.'.$ext);
			foreach($this->Request[$array]['name'] as $key => $value) {
				if($key > $count) {
					if(!empty($this->Request[$array]['tmp_name'][$key])) {
						$max+=1;
						copy($this->Request[$array]['tmp_name'][$key],$path.'/'.$folder.'/'.date2pg($max).'.'.$ext);
						chmod($path.'/'.$folder.'/'.date2pg($max).'.'.$ext,0664);
					}
				}
			}
		}
		else {
			chdir($path.'/'.$folder);
			$dir = dir('.');
			$dir->rewind();
			while($file = $dir->read()) if(is_file($file)) unlink($path.'/'.$folder.'/'.$file);
		}
	}

	function clearUndo($id) {
		global $ROOT_PATH;
		if(file_exists($ROOT_PATH.'/undo/product/'.$id)) {
			chdir($ROOT_PATH.'/undo/product/'.$id);
			$dir = dir('.');
			$dir->rewind();
			while($file = $dir->read()) if(is_file($file)) unlink($ROOT_PATH.'/undo/product/'.$id.'/'.$file);
			rmdir($ROOT_PATH.'/undo/product/'.$id);
			$dir->close();
		}
		return true;
	}

	function deleteFile($array) {
		if(empty($this->PreparedTemplates['_error'])) {
			$path = $this->ImagePath.'/products/'.$array['id'];
			if(file_exists($path.'/'.$array['file'])) unlink($path.'/'.$array['file']);
			else $this->PreparedTemplates['_error'] = ' ';
		}
	}

	function fillElements() {
		switch($this->Scheme) {
			case 'action': $this->fillAction(); break;
			case 'viewall': $this->fillViewAll(); break;
			case 'sort': $this->fillSort(); break;
			default: $this->fillSelect(); break;
		}
	}

	function fillViewAll() {
		global $REGISTRY, $ROOT_PATH;
		foreach($this->PreparedTemplates['curPage'] as $ind => $val) {
			$tok = explode(".",$val['date']);
			$this->TempFillEls['comments'][] = array(
				'number' => ($this->PreparedTemplates['pageRecordsQty']*($this->PreparedTemplates['curPageNumber']-1))+($ind+1),
				'date' => $tok[0],
				'author' => $val['member'],
				'changed' => $val['value'],
				'version' => $val['version'],
				'button' =>  file_exists($ROOT_PATH.'/undo/product/'.$this->PreparedTemplates[1].'/'.$val['version'].'.inc')? array(array('id' => $this->PreparedTemplates[1],'version' => $val['version'])) : array(),
			);
		}
	}

	function setSortArray($array = array()) {
		foreach($array as $value) {
			$this->TempFillEls['pages'][$value['id']] = array(
				'id' => $value['id'],
				'name' => $value['name'],
				'sort_order' => $value['sort_order'],
				'name_color' => $this->colors[($value['unmodified'] > 30 ? 'black' : ($value['unmodified'] > 14 && $value['unmodified'] <= 30 ? 'green' : ($value['unmodified'] > 7 && $value['unmodified'] <= 14 ? 'yellow' : 'red')))],
			);
		}
	}

	function sortingPages() {
		uasort($this->Request['form'],'by_order');
		$i = 1;
		foreach($this->Request['form'] as $key => $value) {
			$sort[$key]['sort_order'] = $i*10;
			$i++;
		}
		$this->Request['form'] = $sort;
		return true;
	}

	function fillSort() {
		if($this->terminated) return;
		$this->TempFillEls['addBut'] = $this->server_type == 'dev' ? 'visible' : 'hidden';
		$this->TempFillEls['pubBut'] = $this->server_type == 'pro' ? 'hidden' : 'visible';
		$this->setSortArray($this->PreparedTemplates);
	}

	function fillSelect() {
		if($this->terminated) return;
		$this->TempFillEls['addBut'] = $this->server_type == 'dev' ? 'visible' : 'hidden';
		$this->TempFillEls['pubBut'] = $this->server_type == 'pro' ? 'hidden' : 'visible';
		$this->setTargetArray($this->PreparedTemplates);
	}

	function setDeleteTargetArray($array = array(),$k,$level = 1,$subitems = array()) {
		foreach($array as $key => $value) {
			$value['name'] = ucwords('<span class=first>'.substr($value['name'],0,1).'</span>'.substr($value['name'],1));
			if(in_array($value['id'],$this->categories)) {
				$this->TempFillEls['categories'][$value['id']] = array(
					'name' => $value['name'],
					'width' => 20,
					'width2' => 426,
					'width3' => 420,
				);
			}
			if(!empty($value['subcat'])) $this->setDeleteTargetArray($value['subcat'],$k,$level+1);
		}
	}

	function getGuides() {
		$this->articles =  mergeArrays(array('0' => ' --- Select Expert Opinion --- '),$this->Db->SelectGuide(array('article g'),array('g.id','g.title as name')));
		$this->technologies =  mergeArrays(array('0' => ' --- Select Technology --- '),$this->Db->SelectGuide(array('technology g'),array('g.id','g.name')));
//		$this->recomenduses =  mergeArrays(array('0' => ' --- Select Recomend Use --- '),$this->Db->SelectGuide(array('recomenduse g'),array('g.id','g.name')));
		$this->related =  mergeArrays(array('0' => ' --- Select Related Products --- '),$this->Db->SelectGuide(array('product g'),array('g.id','g.name'), array('is_active' => '1'), false, " id "   ));
		$this->warranty = mergeArrays(array('0' => ' --- Select Warranty --- '),$this->Action->Server->getGuide('warranty'));
		$this->rate = mergeArrays(array('0' => ' --- Select Rate --- '),$this->Action->Server->getGuide('rate'));
		$this->level = mergeArrays(array('0' => ' --- Select Level --- '),$this->Action->Server->getGuide('level'));
		$this->policy = mergeArrays(array('0' => ' --- Select Policy --- '),$this->Action->Server->getGuide('policy'));
		$this->core = mergeArrays(array('0' => ' --- Select Core Tech --- '),$this->Action->Server->getGuide('core'));
		$this->lens = mergeArrays(array('0' => ' --- Select Lens --- '),$this->Action->Server->getGuide('lens'));
		$this->brand = mergeArrays(array('0' => ' --- Select Brand --- '),$this->Action->Server->getGuide('brand'));
		//$this->generation = mergeArrays(array('0' => ' --- Select Generation --- '),$this->Action->Server->getGuide('generation'));
		$this->generation = mergeArrays(array('0' => ' --- Select Generation --- '),$this->LM->DB->SelectGuide('generation g',array('id','mask as name'))   );
		$this->categories = $this->Db->SelectGuide(array('categorylineitem g'),array('g.id','g.ownerid as name'),array('g.item' => (isset($this->LocalTarget[1])? $this->LocalTarget[1] : 0)));
		$this->parentitems = mergeArrays(array('0' => ' --- Select Parent Item --- '),$this->Db->SelectGuide(array('parentitem g'),array('g.id','g.name'),array('itemtype' => 1)));
		$this->products = mergeArrays(array('0' => ' --- Select Product --- '),$this->Db->SelectGuide(array('parentitem i','product g'),array('g.id','g.name'),array('g.item' => 'i.id','i.itemtype' => 1)));
		$this->accessories = $this->Db->SelectGuide(array('parentitem i','product g'),array('g.id','g.header as name'),array('g.item' => 'i.id','i.itemtype' => 2));
		$this->kits = $this->Db->SelectGuide(array('parentitem i','product g'),array('g.id','g.header as name'),array('g.item' => 'i.id','i.itemtype' => 3));
		$this->accessories = mergeArrays($this->accessories,$this->kits);
		$this->shipcosts = $this->Db->SelectGuide(array('shipcosttype g'), array('g.id','g.name'), array('1' => '1'),false, 'sort_order' );
		$this->export = mergeArrays(array('0' => ' --- Select Export Restriction --- '),$this->Db->SelectGuide(array('export g'),array('g.id','g.name'),array('1' => '1')));
		$this->customerreviews = mergeArrays(array('0' => ' --- Select Customer Review --- '),$this->Db->SelectGuide(array('customerreview g'),array('g.id','g.name'),array('1' => '1')));
	}

	function validateForm() { 
		if (empty($this->Request['form']['special_offer'])) $this->Request['form']['special_offer'] = ' ';  
		if(empty($this->Request['form']['categorylineitems'])) $this->errors['category'] = 'Please, select category(es)';
		if(!validate($this->getRequestFormField('name'))) $this->errors['name'] = 'Product Name is empty';
		if(!is_FullText($this->Request['form']['product_class'],1,60)) $this->errors['product_class'] = 'Product Class is not valid string';
		if(!validate($this->getRequestFormField('nav_name'))) $this->errors['nav_name'] = 'Product Navigation Name is empty';
		if(!validate($this->getRequestFormField('item',1))) $this->errors['item'] = 'Parent Item is empty';
		if(!validate($this->getRequestFormField('warranty',1))) $this->errors['warranty'] = 'Product Warranty is empty';
//		if(!validate($this->getRequestFormField('generation',1))) $this->errors['generation'] = 'Product Generation is empty';
		//if(!validate($this->getRequestFormField('export_restriction',1))) $this->errors['export_restriction'] = 'Export Restriction is empty';
		if(!validate($this->getRequestFormField('path'))) $this->errors['path'] = 'Product\'s URL is empty';
		else if(validate($this->getRequestFormField('path')) && !is_URLText($this->getRequestFormField('path'),1,255)) $this->errors['path'] = 'Product\'s URL is not valid';
		else if(validate($this->getRequestFormField('path')) && in_array($this->getRequestFormField('path'),array('.','..'))) $this->errors['path'] = 'Product\'s URL is not valid';
		else $this->Request['form']['path'] = stripslashes($this->getRequestFormField('path'));
		if(validate($this->getRequestField('root_check'))) {
			if(!validate($this->getRequestFormField('path2'))) $this->errors['path2'] = 'Product\'s Root URL is empty';
			else if(validate($this->getRequestFormField('path2')) && !is_URLText($this->getRequestFormField('path2'),1,255)) $this->errors['path2'] = 'Product\'s Root URL is not valid';
			else if(validate($this->getRequestFormField('path2')) && in_array($this->getRequestFormField('path2'),array('.','..'))) $this->errors['path2'] = 'Product\'s Root URL is not valid';
			else if($this->getRequestFormField('path2')==$this->getRequestFormField('path')) $this->errors['path2'] = 'Root URL matches the URL';
			else $this->Request['form']['path2'] = stripslashes($this->getRequestFormField('path2'));
		}
		else $this->Request['form']['path2'] = '';
		if (!empty($this->Request['form']['video_desc'])) $this->Request['form']['video_desc'] = str_replace("\r\n","", $this->getRequestFormField('video_desc'));
		if(!is_AlphaNum($this->getRequestFormField('pid'),1,32)) $this->errors['pid'] = 'Item # is empty or is not valid';
		foreach($this->Request['form']['parameters'] as $key => $value) {
			if(empty($value['name']) && empty($value['value'])) unset($this->Request['form']['parameters'][$key]);
			else $this->Request['form']['parameters'][$key]['sort_order'] = intval($value['sort_order']);
		}
/*		foreach($this->Request['form']['features'] as $key => $value) {
			if(empty($value['value'])) unset($this->Request['form']['features'][$key]);
			else $this->Request['form']['features'][$key]['sort_order'] = intval($value['sort_order']);

		}*/
		$this->customerreviews = $this->Db->SelectGuide(array('customerreview g'),array('g.id','g.name'),array('1' => '1'));
		empty($this->Request['form']['customerreviewitems']) and $this->Request['form']['customerreviewitems'] = array();
		$cr_ids = array();
		$i = 1;
		foreach($this->Request['form']['customerreviewitems'] as $key => $value) {
			if(!in_array($value['object'],array_keys($this->customerreviews)) || in_array($value['object'],$cr_ids)) unset($this->Request['form']['customerreviewitems'][$key]);
			else {
				$this->Request['form']['customerreviewitems'][$key]['sort_order'] = $i*10;
				$cr_ids[] = $value['object'];
				$i++;
			}
		}
		empty($this->Request['form']['reviews']) and $this->Request['form']['reviews'] = array();
		foreach($this->Request['form']['reviews'] as $key => $value) {
			if(!empty($value['image_title']) && !is_AdvCleanText($value['image_title'],1,512)) $this->errors['review'][$key]['image_title'] = 'Image Title is not valid';
			if(!empty($value['image_alt']) && !is_AdvCleanText($value['image_alt'],1,512)) $this->errors['review'][$key]['image_alt'] = 'Image Alt is not valid';
			if(!empty($value['description']) && !is_FullText($value['description'],1,512)) $this->errors['review'][$key]['description'] = 'Description is not valid';
			$url = checkURL($value['url']);
			if(empty($url)) $this->errors['review'][$key]['url'] = 'Review URL is not valid';
			else $this->Request['form']['reviews'][$key]['url'] = $url;
			$url = checkURL($value['image_url']);
			if(empty($url)) $this->errors['review'][$key]['image_url'] = 'Image URL is not valid';
			else $this->Request['form']['reviews'][$key]['image_url'] = $url;
			$this->Request['form']['reviews'][$key]['sort_order'] = intval($value['sort_order']);
		}
/*		$current = 0;
		if(!empty($this->Request['form']['prices'])) {
			foreach($this->Request['form']['prices'] as $key => $value) {
				if(empty($value['value']) || !is_numeric($value['value']) || (double)$value['value'] < 0.01) $this->Request['form']['prices'][$key]['value'] = '0.00';
				if(!empty($value['current'])) $current++;
			}
			if($current==0) $this->errors['price'] = 'Please, check current price';
			if($current > 1) $this->errors['price'] = 'Only one price can be current';
		} else $this->errors['price'] = 'Price is empty. Please, enter price';*/

		foreach($this->Request['form']['shipcosts'] as $key => $value) {
			if(empty($value['value'])) $this->Request['form']['shipcosts'][$key]['value'] = '0.00';
		}
		empty($this->Request['form']['productlineitems']) and $this->Request['form']['productlineitems'] = array();
		empty($this->Request['form']['articlelineitems']) and $this->Request['form']['articlelineitems'] = array();
		empty($this->Request['form']['technologylineitems']) and $this->Request['form']['technologylineitems'] = array();
		empty($this->Request['form']['recomenduselineitems']) and $this->Request['form']['recomenduselineitems'] = array();
		empty($this->Request['form']['relatedlineitems']) and $this->Request['form']['relatedlineitems'] = array();
		foreach($this->Request['form']['productlineitems'] as $key => $value)
			if(empty($value['lineitem']['id'])) unset($this->Request['form']['productlineitems'][$key]);
		foreach($this->Request['form']['articlelineitems'] as $key => $value)
			if(empty($value['lineitem']['id'])) unset($this->Request['form']['articlelineitems'][$key]);
		foreach($this->Request['form']['technologylineitems'] as $key => $value)
			if(empty($value['lineitem']['id'])) unset($this->Request['form']['technologylineitems'][$key]);
			
		foreach($this->Request['form']['recomenduselineitems'] as $key => $value)
			if(empty($value['lineitem']['id'])) unset($this->Request['form']['recomenduselineitems'][$key]);
			
		foreach($this->Request['form']['relatedlineitems'] as $key => $value)
			if(empty($value['lineitem']['id'])) unset($this->Request['form']['relatedlineitems'][$key]);

		if(!validate($this->getRequestField('middle_image_link'))) {
			$image = $this->getRequestField('middle_image');
			if(!empty($image['name'])) {
				if(!$image['size']) $this->errors['middle_image'] = 'Error uploading - image is empty';
				else {
					$size = GetImageSize($image['tmp_name']);
//					if($size['0'] != $this->upload_settings['middle_width']) $this->errors['middle_image'] = 'Error uploading - width of image is not valid';
//					else if($size['1'] != $this->upload_settings['middle_height']) $this->errors['middle_image'] = 'Error uploading - height of image is not valid';
//					else if($size['mime']!='image/jpg') $this->errors['middle_image'] = 'Error uploading - type of image is not valid';
//					else {
						$this->Request['form']['middle']['image_type'] = 'jpg';//$this->upload_formats[$size['mime']];
						$this->Request['form']['middle']['_tmp_name'] = $image['tmp_name'];
						$this->Request['form']['middle']['image_link'] = $this->getRequestField('middle_image_link');
//					}
				}
			}
			else if($this->LocalTarget[0]=='Add') $this->errors['middle_image'] = 'Error uploading - image is empty';
			else {
				foreach($this->PreparedTemplates['files'] as $value) {
					if($value['filetype']==8 && validate($value['image_link'])) $this->errors['middle_image'] = 'Error uploading - image is empty';
				}
			}
		}
		else {
			if($this->getRequestField('middle_image_link')==$this->getRequestFormField('id')) $this->errors['middle_image'] = 'Error uploading - Product can\'t use itself as a link to image';
			$this->Request['form']['middle']['image_type'] = ' ';
			$this->Request['form']['middle']['image_link'] = $this->getRequestField('middle_image_link');
		}
		
		
		$image = $this->getRequestField('ug_image');
		if(!empty($image['name'])) {
			if(!$image['size']) $this->errors['ug_image'] = 'Error uploading - file is empty';
			elseif($image['type'] != 'application/pdf') $this->errors['ug_image'] = 'Error uploading - type of file is not valid';
			if(empty($this->errors['ug_image'])) {
				$this->Request['form']['ug']['image_type'] = 'pdf';
				$this->Request['form']['ug']['_tmp_name'] = $image['tmp_name'];
				$this->Request['form']['ug']['image_link'] = 0;
			}
		}
		$image = $this->getRequestField('ss_image');
		if(!empty($image['name'])) {
			if(!$image['size']) $this->errors['ss_image'] = 'Error uploading - file is empty';
			elseif($image['type'] != 'application/pdf') $this->errors['ss_image'] = 'Error uploading - type of file is not valid';
			if(empty($this->errors['ss_image'])) {
				$this->Request['form']['ss']['image_type'] = 'pdf';
				$this->Request['form']['ss']['_tmp_name'] = $image['tmp_name'];
				$this->Request['form']['ss']['image_link'] = 0;
			}
		}
		$image = $this->getRequestField('hi_image');
		if(!empty($image['name'])) {
			if(!$image['size']) $this->errors['hi_image'] = 'Error uploading - file is empty';
			else {
				$size = GetImageSize($image['tmp_name']);
				if($size['mime'] != 'image/tiff') $this->errors['hi_image'] = 'Error uploading - type of file is not valid';
			}
			if(empty($this->errors['hi_image'])) {
				$this->Request['form']['hi']['image_type'] = 'tif';
				$this->Request['form']['hi']['_tmp_name'] = $image['tmp_name'];
				$this->Request['form']['hi']['image_link'] = 0;
			}
		}
		//printArray($this->Request['3d']);
		$number_3d = !empty($this->Request['3d'])? array_max(array_keys($this->Request['3d']['name'])) : 0;
		if(!empty($this->Request['3d']) && count($this->Request['3d']['name']) != 32) $this->errors['model'] = 'Error uploading 3d Series - Amount of images must be 32';
		for($i = 1; $i <= $number_3d; $i++) {
			if(!empty($this->Request['3d']['name'][$i])) {
				if(!$this->Request['3d']['size'][$i]) $this->errors['3d'][$i] = 'Error uploading - image is empty';
				else {
					$size = GetImageSize($this->Request['3d']['tmp_name'][$i]);
					if($size['mime'] != 'image/jpg' && $size['mime'] != 'image/pjpeg' && $size['mime'] != 'image/jpeg') $this->errors['3d'][$i] = 'Error uploading - type of image is not valid';
					elseif($size['0'] != $this->upload_settings['3d_width']) $this->errors['3d'][$i] = 'Error uploading - width of image is not valid';
					elseif($size['1'] != $this->upload_settings['3d_height']) $this->errors['3d'][$i] = 'Error uploading - height of image is not valid';
					else {
						$this->Request['form']['3d'][$i]['image_type'] = 'jpg';
						$this->Request['form']['3d'][$i]['_tmp_name'] = $this->Request['3d']['tmp_name'][$i];
						$this->Request['form']['3d'][$i]['_number'] = $i;
					}
				}
			}
			else if(isset($this->Request['3d']['name'][$i])){
				$this->Request['form']['3d'][$i]['_number'] = $i;
			}
		}

		$number_image = !empty($this->Request['image_big'])? array_max(array_keys($this->Request['image_big']['name'])) : 0;
		for($i = 1; $i <= $number_image; $i++) {
			if(!empty($this->Request['image_big']['name'][$i])) {
				if(!$this->Request['image_big']['size'][$i]) $this->errors['image_big'][$i] = 'Error uploading - big image is empty';
				else {
					/*$size = GetImageSize($this->Request['image_big']['tmp_name'][$i]);
					if($size['mime'] != 'image/jpg' && $size['mime'] != 'image/pjpeg' && $size['mime'] != 'image/jpeg') $this->errors['image_big'][$i] = 'Error uploading - type of big image is not valid';
					else if($size['0'] != $this->upload_settings['image_width']) $this->errors['image_big'][$i] = 'Error uploading - width of big image is not valid';
					else if($size['1'] != $this->upload_settings['image_height']) $this->errors['image_big'][$i] = 'Error uploading - height of big image is not valid';
					else {*/
/*						if(empty($this->Request['image_middle']['name'][$i])) $this->errors['image_middle'][$i] = 'Error uploading - middle image is empty';
						else {
							if(!$this->Request['image_middle']['size'][$i]) $this->errors['image_middle'][$i] = 'Error uploading - middle image is empty';
							else {
								$size = GetImageSize($this->Request['image_middle']['tmp_name'][$i]);
								if($size['mime']!='image/jpg') $this->errors['image_middle'][$i] = 'Error uploading - type of middle image is not valid';
								else if($size['0'] != $this->upload_settings['middle_width']) $this->errors['image_middle'][$i] = 'Error uploading - width of middle image is not valid';
								else if($size['1'] != $this->upload_settings['middle_height']) $this->errors['image_middle'][$i] = 'Error uploading - height of middle image is not valid';
								else {*/
									$this->Request['form']['image'][$i]['image_type'] = 'jpg';
									$this->Request['form']['image'][$i]['_tmp_name'] = $this->Request['image_big']['tmp_name'][$i];
									$this->Request['form']['image'][$i]['_number'] = $i;
									$this->Request['form']['image'][$i]['sort_order'] = $this->Request["image_big_sort_order"][$i];
								//}
							//}
						//}
					//}
				}
			}
			else if(!empty($this->Request['image_middle']['name'][$i])) $this->errors['image_middle'][$i] = 'Error uploading - big image is empty';
			else if(isset($this->Request['image_big']['name'][$i])) { //	illustrations
				$this->Request['form']['image'][$i]['_number'] = $i;
				if (isset($this->Request["image_big_sort_order"][$i])) $this->Request['form']['image'][$i]['sort_order'] = $this->Request["image_big_sort_order"][$i];  
			}
		}


		$number_userguide = !empty($this->Request['userguide_big'])? array_max(array_keys($this->Request['userguide_big']['name'])) : 0;
		for($i = 1; $i <= $number_userguide; $i++) {
			if(!empty($this->Request['userguide_big']['name'][$i])) {
				if(!$this->Request['userguide_big']['size'][$i]) $this->errors['userguide_big'][$i] = 'Error uploading - userguide is empty';
				else {
						$this->Request['form']['userguide'][$i]['image_type'] = 'pdf';
						$this->Request['form']['userguide'][$i]['_tmp_name'] = $this->Request['userguide_big']['tmp_name'][$i];
						$this->Request['form']['userguide'][$i]['_number'] = $i;
						$this->Request['form']['userguide'][$i]['sort_order'] = $this->Request["userguide_big_sort_order"][$i];
						$this->Request['form']['userguide'][$i]['description'] = $this->Request["userguide_description"][$i];
				}
			}
			else if(isset($this->Request['userguide_big']['name'][$i])) { //	userguide
				$this->Request['form']['userguide'][$i]['_number'] = $i;
				if (isset($this->Request["userguide_big_sort_order"][$i])) $this->Request['form']['userguide'][$i]['sort_order'] = $this->Request["userguide_big_sort_order"][$i];  
				if (isset($this->Request["userguide_description"][$i]))    $this->Request['form']['userguide'][$i]['description'] = $this->Request["userguide_description"][$i];
			}
		}
		
		
		if($this->LocalTarget[0] == 'Update')
			if(!is_FullText($this->getRequestFormField('comment'),5,4096)) $this->errors['comment'] = 'Comment is empty or is not valid';
		if(count($this->errors)>0) return FALSE;
		return TRUE;
	}

	function fillAction() {
		global $ROOT_PATH;
		switch($this->LocalTarget[0]) {
			case 'Add': {
				$this->TempFillEls = array(
					'subaction' => 'Add',
					'subprocess' => 'adding',
					'step' => 'add',
					'is_active' => inputHidden('form[is_active]',0).inputCheckbox('form[is_active]',(!empty($this->Request)? $this->getRequestFormField('is_active') : 1),' class=check'),
					'export' => inputHidden('form[export]',0).inputCheckbox('form[export]',(!empty($this->Request)? $this->getRequestFormField('export') : 1),' class=check'),
					'callforquote' => inputHidden('form[callforquote]',0).inputCheckbox('form[callforquote]',(!empty($this->Request)? $this->getRequestFormField('callforquote') : 1),' class=check'),
					'grade_tube' => inputHidden('form[grade_tube]',0).inputCheckbox('form[grade_tube]',(!empty($this->Request)? $this->getRequestFormField('grade_tube') : 0),' class=check'),
					'root_check' => inputCheckbox('root_check',(!empty($this->Request)? $this->getRequestField('root_check') : ($this->getRequestFormField('path2')? 1 : 0)),' onClick="javascript:correctRootPath();"'),
					'pid' => inputText('form[pid]',$this->getRequestFormField('pid'),55,'style="width:400px;"'),
					'name' => inputTextArea('form[name]',$this->getRequestFormField('name'),55,1,'style="width:400px;height:16px"'),
					'nav_name' => inputTextArea('form[nav_name]',$this->getRequestFormField('nav_name'),55,1,'style="width:400px;height:16px"'),
					'item' => inputSelect('form[item][id]',$this->parentitems,$this->getRequestFormField('item',1),'style="width:400px;"'),
					'path' => inputText('form[path]',$this->getRequestFormField('path'),55,'style="width:400px;"'),
					'path2' => inputText('form[path2]',$this->getRequestFormField('path2'),75,'style="width:460px;display:'.(validate($this->getRequestField('root_check')) || $this->getRequestFormField('path2')? 'inline' : 'none').'"'),
					'generation' => inputSelect('form[generation][id]',$this->generation,$this->getRequestFormField('generation',1),'style="width:400px;"'),
					'warranty' => inputSelect('form[warranty][id]',$this->warranty,$this->getRequestFormField('warranty',1),'style="width:260px;"'),
					'rate' => inputSelect('form[rate][id]',$this->rate,$this->getRequestFormField('rate',1),'style="width:260px;"'),
					'level' => inputSelect('form[level][id]',$this->level,$this->getRequestFormField('level',1),'style="width:260px;"'),
					'policy' => inputSelect('form[policy][id]',$this->policy,$this->getRequestFormField('policy',1),'style="width:260px;"'),
					'core' => inputSelect('form[core][id]',$this->core,$this->getRequestFormField('core',1),'style="width:400px;"'),
					'lens' => inputSelect('form[lens][id]',$this->lens,$this->getRequestFormField('lens',1),'style="width:260px;"'),
					'brand' => inputSelect('form[brand][id]',$this->brand,$this->getRequestFormField('brand',1),'style="width:400px;"'),
					'export_restriction' => inputSelect('form[export_restriction][id]',$this->export,$this->getRequestFormField('export_restriction',1),'style="width:360px;"'),
					'short_desc' => inputTextArea('form[short_desc]',$this->getRequestFormField('short_desc'),110,5,'style="width:730px;"'),
					'special_offer' => inputTextArea('form[special_offer]',$this->getRequestFormField('special_offer'),110,5,'style="width:730px;"'),
					//'add_description' => inputTextArea('form[add_description]',(!empty($this->Request) ? $this->Request['form']['add_description'] : $this->PreparedTemplates['add_description']) ,110,45,'style="width:730px;"'),
					'distance_chart_activity' => inputHidden('form[distance_chart_activity]',0).inputCheckbox('form[distance_chart_activity]',(!empty($this->Request)? $this->getRequestFormField('distance_chart_activity') : $this->PreparedTemplates['distance_chart_activity']),' class=check' ),	
//					'series' => inputText('form[series]',(!empty($this->Request)? $this->Request['form']['series'] : $this->PreparedTemplates['series']),55,'style="width:300px;"'),
					'video_desc' => inputTextArea('form[video_desc]',$this->getRequestFormField('video_desc'),110,5,'style="width:730px;"'),				
					'full_desc' => inputTextArea('form[full_desc]',$this->getRequestFormField('full_desc'),110,10,'style="width:730px;"'),
					'product_class' => inputText('form[product_class]',$this->getRequestFormField('product_class'),55,'style="width:250px;"'),
					'prew_image' => validate($this->getRequestField('prew_image_link'))? $this->makeImageLink('prew',$this->getRequestField('prew_image_link')) : makeImage($this->ImagePath.'/1.gif',$this->ImageWPath.'/1.gif','','',array(),0,'','prewimg'),
					'prew_upload' => inputFile('prew_image'),
					'prew_setting' => 'Jpg, '.$this->upload_settings['prew_width'].'x'.$this->upload_settings['prew_height'],
					//'prew_image_link' => inputSelect('prew_image_link',$this->products,$this->getRequestField('prew_image_link'),'style="width:400px;" onchange="selectImage(\'prew\')"'),
					'prew_display' => validate($this->getRequestField('prew_image_link'))? 'none' : 'inline',
					'middle_image' => validate($this->getRequestField('middle_image_link'))? $this->makeImageLink('middle',$this->getRequestField('middle_image_link')) : makeImage($this->ImagePath.'/1.gif',$this->ImageWPath.'/1.gif','','',array(),0,'','middleimg'),
					'middle_upload' => inputFile('middle_image'),
					'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					//'middle_image_link' => inputSelect('middle_image_link',$this->products,$this->getRequestField('middle_image_link'),'style="width:400px;" onchange="selectImage(\'middle\')"'),
					'middle_display' => validate($this->getRequestField('middle_image_link'))? 'none' : 'inline',
					'big_image' => validate($this->getRequestField('big_image_link'))? $this->makeImageLink('big',$this->getRequestField('big_image_link')) : makeImage($this->ImagePath.'/1.gif',$this->ImageWPath.'/1.gif','','',array(),0,'','bigimg'),
					'big_upload' => inputFile('big_image'),
					'big_setting' => 'png, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
					//'big_image_link' => inputSelect('big_image_link',$this->products,$this->getRequestField('big_image_link'),'style="width:400px;" onchange="selectImage(\'big\')"'),
					'big_display' => validate($this->getRequestField('big_image_link'))? 'none' : 'inline',
					'ug_image' => '&nbsp;',
					'ug_upload' => inputFile('ug_image'),
					'ss_image' => '&nbsp;',
					'ss_upload' => inputFile('ss_image'),
					'hi_image' => '&nbsp;',
					'hi_upload' => inputFile('hi_image'),
					'param_buttons' => array(array()),
					'price_buttons' => array(array()),
					'image_buttons' => array(array()),
					'3d_buttons' => array(array()),
					'link_buttons' => array(array()),
					'feature_buttons' => array(array()),
					'review_buttons' => array(array()),
					'cr_buttons' => array(array()),
					'product_color' => inputSelect('form[color][id]',$this->prod_colors,$this->getRequestFormField('color',1),'style="width:250px;"'),
				);
				//-----   userguides
				$number_userguide = !empty($this->Request['userguide_big']) && count($this->Request['userguide_big']['name']) > 1? count($this->Request['userguide_big']['name']) : 1 ;
				for($i = 1; $i <= $number_userguide; $i++) {
					$this->TempFillEls['userguides'][$i] = array(
						'num' => $i,
						'big_userguide' => '&nbsp;',					
						'userguide_big_upload' => inputFile('userguide_big['.$i.']'),
						'sort_order' =>inputText('userguide_big_sort_order['.$i.']', $i ,'3'),
						'description'=> inputTextArea('userguide_description['.$i.']',  !empty($this->Request['userguide_description'][$i])?$this->Request['userguide_description'][$i]: '',38,2,'style="width:295px;"'),
						'userguide_big_error' => !empty($this->errors['userguide_big'][$i])? $this->printError($this->errors['userguide_big'][$i]) : '',
						'delete_userguide' => array(array('num' => $i)),
					);
				}
				
				$number_image = !empty($this->Request['image_big']) && count($this->Request['image_big']['name']) > 1? count($this->Request['image_big']['name']) : 1;
				for($i = 1; $i <= $number_image; $i++) {
					$this->TempFillEls['images'][$i] = array(
						'num' => $i,
						'big_setting' => 'png, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
						'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					'small_setting' => 'jpg, '.$this->upload_settings['small_width'].'x'.$this->upload_settings['small_height'],
						'big_image' => '&nbsp;',
						'middle_image' => '&nbsp;',
					'small_image' => '&nbsp;',
						'image_big_upload' => inputFile('image_big['.$i.']'),
				'sort_order' =>inputText('image_big_sort_order['.$i.']',  $i, '3'),
						'image_middle_upload' => inputFile('image_middle['.$i.']'),
					'image_small_upload' => inputFile('image_small['.$i.']'),
						'image_big_error' => !empty($this->errors['image_big'][$i])? $this->printError($this->errors['image_big'][$i]) : '',
						'image_middle_error' => !empty($this->errors['image_middle'][$i])? $this->printError($this->errors['image_middle'][$i]) : '',
					'image_small_error' => !empty($this->errors['image_small'][$i])? $this->printError($this->errors['image_small'][$i]) : '',
						'delete_image' => array(array('num' => $i)),
					);
				}
				$number_param = !empty($this->Request['form']['parameters']) && count($this->Request['form']['parameters']) > 10? count($this->Request['form']['parameters']) : 10;
				for($i = 1; $i <= $number_param; $i++) {
					$this->TempFillEls['parameters'][$i] = array(
						'num' => $i,
						'name' => inputTextArea('form[parameters]['.$i.'][name]',@$this->Request['form']['parameters'][$i]['name'],38,1,'style="width:300px;"'),
						'value' => inputTextArea('form[parameters]['.$i.'][value]',@$this->Request['form']['parameters'][$i]['value'],45,1,'style="width:340px;"'),
						'sort_order' => inputText('form[parameters]['.$i.'][sort_order]',(!empty($this->Request)? (!empty($this->Request['form']['parameters'][$i]['sort_order'])? $this->Request['form']['parameters'][$i]['sort_order'] : $i*10) : $i*10),2,'style="width:30px;"'),
						'is_front' => inputCheckbox('form[parameters]['.$i.'][is_front]',@$this->Request['form']['parameters'][$i]['is_front'],'class=check',1),
						'delete_param' => array(array('num' => $i)),
					);
				}
				$number_feature = !empty($this->Request['form']['features']) && count($this->Request['form']['features']) > 3? count($this->Request['form']['features']) : 3;
				for($i = 1; $i <= $number_feature; $i++) {
					$this->TempFillEls['features'][$i] = array(
						'num' => $i,
						'value' => inputTextArea('form[features]['.$i.'][value]',@$this->Request['form']['features'][$i]['value'],65,1,'style="width:650px;"'),
						'sort_order' => inputText('form[features]['.$i.'][sort_order]',(!empty($this->Request)? (!empty($this->Request['form']['features'][$i]['sort_order'])? $this->Request['form']['features'][$i]['sort_order'] : $i*10) : $i*10),2,'style="width:30px;"'),
						'delete_feature' => array(array('num' => $i)),
					);
				}
				$number_review = !empty($this->Request['form']['reviews']) && count($this->Request['form']['reviews']) > 0? count($this->Request['form']['reviews']) : 0;
				for($i = 1; $i <= $number_review; $i++) {
					$this->TempFillEls['reviews'][$i] = array(
						'num' => $i,
						'url' => inputTextArea('form[reviews]['.$i.'][url]',@$this->Request['form']['reviews'][$i]['url'],32,2,'style="width:320px;"'),
						'image_url' => inputTextArea('form[reviews]['.$i.'][image_url]',@$this->Request['form']['reviews'][$i]['image_url'],32,2,'style="width:320px;"'),
						'image_alt' => inputTextArea('form[reviews]['.$i.'][image_alt]',@$this->Request['form']['reviews'][$i]['image_alt'],32,2,'style="width:320px;"'),
						'image_title' => inputTextArea('form[reviews]['.$i.'][image_title]',@$this->Request['form']['reviews'][$i]['image_title'],32,2,'style="width:320px;"'),
						'description' => inputTextArea('form[reviews]['.$i.'][description]',@$this->Request['form']['reviews'][$i]['description'],32,2,'style="width:320px;"'),
						'sort_order' => inputText('form[reviews]['.$i.'][sort_order]',(!empty($this->Request)? (!empty($this->Request['form']['reviews'][$i]['sort_order'])? $this->Request['form']['reviews'][$i]['sort_order'] : $i*10) : $i*10),2,'style="width:30px;"'),
						'delete_review' => array(array('num' => $i)),
						'moduletype' => inputHidden('form[reviews]['.$i.'][moduletype]',3),
					);
					if(!empty($this->errors['review'][$i]))
						foreach($this->errors['review'][$i] as $key => $value) $this->TempFillEls['reviews'][$i][$key.'_error'] = $this->printError($value);
				}
				$number_cr = !empty($this->Request['form']['customerreviewitems']) && count($this->Request['form']['customerreviewitems']) > 0? count($this->Request['form']['customerreviewitems']) : 0;
				for($i = 1; $i <= $number_cr; $i++) {
					$this->TempFillEls['cr_items'][$i] = array(
						'num' => $i,
						'sort_order' => inputText('form[customerreviewitems]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['sort_order'] : $i*10),2,'style="width:30px;"'),
						'delete_cr' => array(array('num' => $i)),
						'object' => inputHidden('form[customerreviewitems]['.$i.'][object]', (!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['object'] : 0)),
						'name' => inputText('form[customerreviewitems]['.$i.'][name]', htmlspecialchars(strip_tags($this->customerreviews[(!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['object'] : '')]), ENT_QUOTES),2,'disabled="true" style="width:480px;"'),
						'type' => inputHidden('form[customerreviewitems]['.$i.'][moduletype]', 3),
						'change_cr' => array(array('num' => $i)),
					);
					if(!empty($this->errors['cr'][$i]))
						foreach($this->errors['cr'][$i] as $key => $value) $this->TempFillEls['cr_items'][$i][$key.'_error'] = $this->printError($value);
				}
				$number_price = !empty($this->Request['form']['prices']) && count($this->Request['form']['prices']) > 1? count($this->Request['form']['prices']) : 1;
				for($i = 1; $i <= $number_price; $i++) {
					$this->TempFillEls['prices'][$i] = array(
						'num' => $i,
						'name' => 'Price '.$i,
						'value' => inputText('form[prices]['.$i.'][value]',@$this->Request['form']['prices'][$i]['value'],15,'style="width:150px;"'),
						'current' => inputHidden('form[prices]['.$i.'][current]',0).inputCheckbox('form[prices]['.$i.'][current]',(!empty($this->Request)? @$this->Request['form']['prices'][$i]['current'] : 1),' class=check'),
						'delete_price' => array(array('num' => $i)),
					);
				}
				$this->setCollections('related','relatedlineitems'); 
				$this->setCollections('articles','articlelineitems');
				$this->setCollections('technologies','technologylineitems');
				foreach($this->shipcosts as $key => $value) {
					$this->TempFillEls['costs'][$key] = array(
						'value' => inputText('form[shipcosts]['.$key.'][value]',@$this->Request['form']['shipcosts'][$key]['value'],15,'style="width:150px;"'),
						'id' => inputHidden('form[shipcosts]['.$key.'][type][id]',$key),
						'name' => $value,
					);
				}
				$number_link = !empty($this->Request['form']['links']) && count($this->Request['form']['links']) > 3? count($this->Request['form']['links']) : 3;
				for($i = 1; $i <= $number_link; $i++) {
					$this->TempFillEls['links'][$i] = array(
						'name' => inputTextArea('form[links]['.$i.'][description]',@$this->Request['form']['links'][$i]['description'],55,2,'style="width:350px;"'),
						'js' => inputCheckbox('form[links]['.$i.'][js]',@$this->Request['form']['links'][$i]['js'],' class=check',1),
						'type' => inputSelect('form[links]['.$i.'][linktype]',array('1' => 'Scope Applications','2' => 'Featured Retailers'),@$this->Request['form']['links'][$i]['linktype']),
						'link' => inputTextArea('form[links]['.$i.'][link]',@$this->Request['form']['links'][$i]['link'],55,2,'style="width:300px;"'),
						'url' => inputTextArea('form[links]['.$i.'][url]',@$this->Request['form']['links'][$i]['url'],55,2,'style="width:350px;"'),
						'id' => inputHidden('form[links]['.$i.'][moduletype]',2),
						'key' => $i,
						'delete_link' => array(array('num' => $i)),
					);
				}
				$i = 1;
				foreach($this->accessories as $k => $v) {
					$this->TempFillEls['accessories'][$k] = array(
						'num' => $i++.'.',
						'name' => inputCheckbox('form[productlineitems]['.$k.'][lineitem][id]', @$this->Request['form']['productlineitems'][$k]['lineitem']['id'],'  id="acc_active_'.$k.'"    class=check',$k)."&nbsp;".$this->accessories[$k],
						'type' => implode(' ',radioButtons(array('1' => 'Optional','0' => 'Included'),'form[productlineitems]['.$k.'][optional]',@$this->Request['form']['productlineitems'][$k]['optional'],'    onclick="if(this.value==1) document.getElementById(\'acc_'.$k.'\').style.background = \'lightgreen\'; else document.getElementById(\'acc_'.$k.'\').style.background = \'lightblue\';   "     class=check')),
						'forsale' => inputCheckbox('form[productlineitems]['.$k.'][forsale]', @$this->Request['form']['productlineitems'][$k]['forsale'],' class=check'),
						'id' => $k,
						'backcolor' =>  ((!empty($this->Request) && isset($this->Request['form']['productlineitems'][$k]['optional']) && $this->Request['form']['productlineitems'][$k]['optional'] )? 'lightblue' : 'lightblue'   ),		//lightgreen included
					);
				}
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'tree');
				$this->setCategories($this->PreparedTemplates);
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID, 'save');
			break;
			}
			case 'Update': {
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open');
				$path = '/products/'.$this->PreparedTemplates['id'];
				$files = array('prew' => array(),'big' => array(),'image' => array(),'3d' => array(),'hi' => array(),'ss' => array(),'ug' => array(),'middle' => array());
				//printArray($this->PreparedTemplates['files']);exit;
				foreach($this->PreparedTemplates['files'] as $key => $value) {
					switch($value['filetype']) {
						//case 3: $files['image'][$value['number']] = array('name' => date2pg($value['number']),'ext' => $value['imagetype']); break;
						case 3: $files['image'][$value['number']] = array('name' => date2pg($value['number']),'ext' => $value['imagetype'], 'sort_order' => $value['sort_order']); break;
						case 6: $files['ss'] = 		array('name' => 'ss.'.$value['imagetype']); break;
						case 7: 
							$files['ug'] = 		array('name' => 'ug.'.$value['imagetype'], 'sort_order' => $value['sort_order']  ); 
							$files['userguide'][$value['number']] = array( 'name' => date2pg($value['number']), 'sort_order' => $value['sort_order'], 'description' => $value['description'] );
						break;
						case 8: $files['middle'] =	array('image_link' => $value['image_link'],'name' => 'middle.'.$value['imagetype']); break;
					}
				}
				$this->TempFillEls = array(
					'subaction' => 'Update',
					'subprocess' => 'editing',
					'step' => 'edit',
					'is_active' => inputHidden('form[is_active]',0).inputCheckbox('form[is_active]',(!empty($this->Request)? $this->getRequestFormField('is_active') : $this->PreparedTemplates['is_active']),' class=check'),
					'export' => inputHidden('form[export]',0).inputCheckbox('form[export]',(!empty($this->Request)? $this->getRequestFormField('export') : $this->PreparedTemplates['export']),' class=check'),
					'callforquote' => inputHidden('form[callforquote]',0).inputCheckbox('form[callforquote]',(!empty($this->Request)? $this->getRequestFormField('callforquote') : $this->PreparedTemplates['callforquote']),' class=check'),
					'grade_tube' => inputHidden('form[grade_tube]',0).inputCheckbox('form[grade_tube]',(!empty($this->Request)? $this->getRequestFormField('grade_tube') : $this->PreparedTemplates['grade_tube']),' class=check'),				
					'root_check' => inputCheckbox('root_check',(!empty($this->Request)? $this->getRequestField('root_check') : ($this->PreparedTemplates['path2']? 1 : 0)),' onClick="javascript:correctRootPath();"'),
					'pid' => inputText('form[pid]',(!empty($this->Request)? $this->getRequestFormField('pid') : $this->PreparedTemplates['pid']),55,'style="width:400px;"'),
					'name' => inputTextArea('form[name]',(!empty($this->Request)? $this->getRequestFormField('name') : $this->PreparedTemplates['name']),55,1,'style="width:400px;height:16px"'),
					'nav_name' => inputTextArea('form[nav_name]',(!empty($this->Request)? $this->getRequestFormField('nav_name') : $this->PreparedTemplates['nav_name']),55,1,'style="width:400px;height:16px"'),
					'item' => inputSelect('form[item][id]',$this->parentitems,(!empty($this->Request)? $this->getRequestFormField('item',1) : $this->PreparedTemplates['item']['id']),'style="width:400px;"'),
					'path' => inputText('form[path]',(!empty($this->Request)? $this->getRequestFormField('path') : $this->PreparedTemplates['path']),55,'style="width:400px;"'),
					'path2' => inputText('form[path2]',(!empty($this->Request)? $this->getRequestFormField('path2') : $this->PreparedTemplates['path2']),75,'style="width:460px;display:'.(validate($this->getRequestField('root_check')) || !empty($this->PreparedTemplates['path2'])? 'inline' : 'none').'"'),
					'warranty' => inputSelect('form[warranty][id]',$this->warranty,(!empty($this->Request)? $this->getRequestFormField('warranty',1) : $this->PreparedTemplates['warranty']['id']),'style="width:260px;"'),
					'rate' => inputSelect('form[rate][id]',$this->rate,(!empty($this->Request)? $this->getRequestFormField('rate',1) : $this->PreparedTemplates['rate']['id']),'style="width:260px;"'),
					'level' => inputSelect('form[level][id]',$this->level,(!empty($this->Request)? $this->getRequestFormField('level',1) : $this->PreparedTemplates['level']['id']),'style="width:260px;"'),
					'policy' => inputSelect('form[policy][id]',$this->policy,(!empty($this->Request)? $this->getRequestFormField('policy',1) : $this->PreparedTemplates['policy']['id']),'style="width:260px;"'),
					'core' => inputSelect('form[core][id]',$this->core,(!empty($this->Request)? $this->getRequestFormField('core',1) : $this->PreparedTemplates['core']['id']),'style="width:400px;"'),
					'lens' => inputSelect('form[lens][id]',$this->lens,(!empty($this->Request)? $this->getRequestFormField('lens',1) : $this->PreparedTemplates['lens']['id']),'style="width:260px;"'),
					'brand' => inputSelect('form[brand][id]',$this->brand,(!empty($this->Request)? $this->getRequestFormField('brand',1) : $this->PreparedTemplates['brand']['id']),'style="width:400px;"'),
					'generation' => inputSelect('form[generation][id]',$this->generation,(!empty($this->Request)? $this->getRequestFormField('generation',1) : $this->PreparedTemplates['generation']['id']),'style="width:400px;"'),
					'product_class' => inputText('form[product_class]',(!empty($this->Request)? $this->Request['form']['product_class'] : $this->PreparedTemplates['product_class']),55,'style="width:250px;"'),
					'short_desc' => inputTextArea('form[short_desc]',(!empty($this->Request)? $this->Request['form']['short_desc'] : $this->PreparedTemplates['short_desc']),110,5,'style="width:730px;"'),
					'special_offer' => inputTextArea('form[special_offer]',(!empty($this->Request)? $this->Request['form']['special_offer'] : $this->PreparedTemplates['special_offer']),110,5,'style="width:730px;"'),
					'distance_chart_activity' => inputHidden('form[distance_chart_activity]',0).inputCheckbox('form[distance_chart_activity]',(!empty($this->Request)? $this->getRequestFormField('distance_chart_activity') : $this->PreparedTemplates['distance_chart_activity']),' class=check' ),
					'full_desc' => inputTextArea('form[full_desc]',(!empty($this->Request)? $this->Request['form']['full_desc'] : $this->PreparedTemplates['full_desc']),110,10,'style="width:730px;"'),
					'video_desc' => inputTextArea('form[video_desc]',(!empty($this->Request)? $this->Request['form']['video_desc'] : $this->PreparedTemplates['video_desc']),110,5,'style="width:730px;"'),				
					'export_restriction' => inputSelect('form[export_restriction][id]',$this->export,(!empty($this->Request)? $this->getRequestFormField('export_restriction',1) : $this->PreparedTemplates['export_restriction']['id']),'style="width:360px;"'),
					'id' => $this->PreparedTemplates['id'],
					'edit_id' => '"'.$this->PreparedTemplates['name'].'" ['.$this->PreparedTemplates['id'].']',
					'prew_image' => isset($files['prew']['name'])?(  (!empty($files['prew']['image_link']))  ?											$this->makeImageLink('prew',$files['prew']['image_link']) : 
											makeImage($this->ImagePath.$path.'/'.$files['prew']['name'], $this->ImageWPath.$path.'/'.$files['prew']['name'].'?'.time(), '', '', array(), 0, array('200'),'prewimg')
										      ): '',
					'prew_upload' => inputFile('prew_image'),
					'prew_setting' => 'Jpg, '.$this->upload_settings['prew_width'].'x'.$this->upload_settings['prew_height'],
					'prew_display' => (!empty($this->Request)? validate($this->getRequestField('prew_image_link')) : !empty($files['prew']['image_link']))? 'none' : 'inline',
					'middle_image' => isset($files['middle']['name'])?   !empty($files['middle']['image_link'])? $this->makeImageLink('middle',$files['middle']['image_link']) : makeImage($this->ImagePath.$path.'/'.$files['middle']['name'],$this->ImageWPath.$path.'/'.$files['middle']['name'].'?'.time(),'','',array(),0, array('200'),'middleimg')
															      :'',
					'middle_upload' => inputFile('middle_image'),
					'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					'middle_display' => (!empty($this->Request)? validate($this->getRequestField('middle_image_link')) : !empty($files['middle']['image_link']))? 'none' : 'inline',
					'ug_image' => !empty($files['ug'])? (file_exists($this->ImagePath.$path.'/'.$files['ug']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['ug']['name'],makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif',$this->PreparedTemplates['name'].' - User\'s Guide'),array(),'','id=\'ug_icon\'') : '&nbsp;') : '&nbsp;',
					'ug_upload' => inputFile('ug_image'),
					'ss_image' => !empty($files['ss'])? (file_exists($this->ImagePath.$path.'/'.$files['ss']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['ss']['name'],makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif',$this->PreparedTemplates['name'].' - Specification Sheet'),array(),'','id=\'ss_icon\'') : '&nbsp;') : '&nbsp;',
					'ss_upload' => inputFile('ss_image'),
					'hi_image' => !empty($files['hi'])? (file_exists($this->ImagePath.$path.'/'.$files['hi']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['hi']['name'],makeImage($this->ImagePath.'/../registarImg/tif.gif',$this->ImageWPath.'/../registarImg/tif.gif',$this->PreparedTemplates['name'].' - Hi-Res. Image'),array(),'','id=\'hi_icon\'') : '&nbsp;') : '&nbsp;',
					'hi_upload' => inputFile('hi_image'),
					'ug_delete' => !empty($files['ug'])? (file_exists($this->ImagePath.$path.'/'.$files['ug']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'ss_delete' => !empty($files['ss'])? (file_exists($this->ImagePath.$path.'/'.$files['ss']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'hi_delete' => !empty($files['hi'])? (file_exists($this->ImagePath.$path.'/'.$files['hi']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'param_buttons' => array(array()),
					'price_buttons' => array(array()),
					'image_buttons' => array(array()),
					'userguide_buttons' => array(array()),
					'3d_buttons' => array(array()),
					'link_buttons' => array(array()),
					'feature_buttons' => array(array()),
					'review_buttons' => array(array()),
					'cr_buttons' => array(array()),
					'product_color' => inputSelect('form[color][id]',$this->prod_colors,(!empty($this->Request)? $this->getRequestFormField('color',1) : $this->PreparedTemplates['color']['id']),'style="width:250px;"'),
				);
						
				//-----   userguides 
				$number_userguide = !empty($this->Request['userguide_big']) && count($this->Request['userguide_big']['name']) > 1? count($this->Request['userguide_big']['name']) : (!empty($files['userguide']) && count($files['userguide']) > 1? count($files['userguide']) : 1);
				for($i = 1; $i <= $number_userguide; $i++) {
					$this->TempFillEls['userguides'][$i] = array(
						'num' => $i,
						'big_userguide' =>  !empty($files['userguide'])? (file_exists($this->ImagePath.$path.'/userguides/'.$files['userguide'][$i]['name'].'.pdf')? makeLink($this->ImageWPath.$path.'/userguides/'.$files['userguide'][$i]['name'].'.pdf',makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif', ' User\'s Guide'),array(),'','id=\'ug_icon\'') : '&nbsp;') : '&nbsp;',					
						'userguide_big_upload' => inputFile('userguide_big['.$i.']'),
						'sort_order' =>inputText('userguide_big_sort_order['.$i.']',  !empty($this->Request['userguide_big_sort_order'][$i])?$this->Request['userguide_big_sort_order'][$i]: (isset($files['userguide'][$i]['sort_order'])?$files['userguide'][$i]['sort_order']:'1') ,'3'),
						'description'=>inputTextArea('userguide_description['.$i.']',  !empty($this->Request['userguide_description'][$i])?$this->Request['userguide_description'][$i]:(isset($files['userguide'][$i]['description'])?$files['userguide'][$i]['description']:''),38,2,'style="width:295px;"'),
						'to_sort' => !empty($this->Request['userguide_big_sort_order'][$i]) ? $this->Request['userguide_big_sort_order'][$i]: (isset($files['userguide'][$i]['sort_order'])?$files['userguide'][$i]['sort_order']:'1') ,					
						'userguide_big_error' => !empty($this->errors['userguide_big'][$i])? $this->printError($this->errors['userguide_big'][$i]) : '',
						'delete_userguide' => array(array('num' => $i)),
					);
				}
				uasort($this->TempFillEls['userguides'],'by_to_sort');
				//-----
				
				$number_image = !empty($this->Request['image_big']) && count($this->Request['image_big']['name']) > 1? count($this->Request['image_big']['name']) : (!empty($files['image']) && count($files['image']) > 1? count($files['image']) : 1);
				for($i = 1; $i <= $number_image; $i++) {
					$this->TempFillEls['images'][$i] = array(
						'num' => $i,
						'big_setting' => 'png, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
						'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					'small_setting' => 'jpg, '.$this->upload_settings['small_width'].'x'.$this->upload_settings['small_height'],
						'big_image' => !empty($files['image'][$i])? (file_exists($this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg', $this->ImageWPath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '280', '1' => '100' ) ,'big_image'.$i.'img') : '&nbsp;') : '&nbsp;',
						'middle_image' => !empty($files['image'][$i])? (file_exists($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '280', '1' => '100' ),'middle_image'.$i.'img') : '&nbsp;') : '&nbsp;',
					'small_image' => !empty($files['image'][$i])? (file_exists($this->ImagePath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '140', '1' => '50' ),'small_image'.$i.'img') : '&nbsp;') : '&nbsp;',
						'image_big_upload' => inputFile('image_big['.$i.']'),
						'image_middle_upload' => inputFile('image_middle['.$i.']'),
					
				'sort_order' =>inputText('image_big_sort_order['.$i.']',  !empty($this->Request['image_big_sort_order'][$i])?$this->Request['image_big_sort_order'][$i]: (isset($files['image'][$i]['sort_order'])?$files['image'][$i]['sort_order']:'1') ,'3'),
			'to_sort' => !empty($this->Request['image_big_sort_order'][$i]) ? $this->Request['image_big_sort_order'][$i]: (isset($files['image'][$i]['sort_order'])?$files['image'][$i]['sort_order']:'1') ,
					'image_small_upload' => inputFile('image_small['.$i.']'),
						'image_big_error' => !empty($this->errors['image_big'][$i])? $this->printError($this->errors['image_big'][$i]) : '',
						'image_middle_error' => !empty($this->errors['image_middle'][$i])? $this->printError($this->errors['image_middle'][$i]) : '',
					'image_small_error' => !empty($this->errors['image_small'][$i])? $this->printError($this->errors['image_small'][$i]) : '',
						'delete_image' => array(array('num' => $i)),
					);
				}
				uasort($this->TempFillEls['images'],'by_to_sort');
//printArray($this->TempFillEls['images']);exit;
				$number_param = !empty($this->Request['form']['parameters']) && count($this->Request['form']['parameters']) > 10? count($this->Request['form']['parameters']) : (!empty($this->PreparedTemplates['parameters']) && count($this->PreparedTemplates['parameters']) > 10? count($this->PreparedTemplates['parameters']) : 10);
				for($i = 1; $i <= $number_param; $i++) {
					$this->TempFillEls['parameters'][$i] = array(
						'num' => $i,
						'name' => inputTextArea('form[parameters]['.$i.'][name]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['name'] : (isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['name'] : '')),38,1,'style="width:295px;"'),
						'value' => inputTextArea('form[parameters]['.$i.'][value]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['value'] : (isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['value'] : '')),45,1,'style="width:330px;"'),
						'sort_order' => inputText('form[parameters]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['sort_order'] : (isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'is_front' => inputCheckbox('form[parameters]['.$i.'][is_front]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['is_front'] : @$this->PreparedTemplates['parameters'][$i-1]['is_front']),'class=check',1),
						'delete_param' => array(array('num' => $i)),
					);
				}
				$number_feature = !empty($this->Request['form']['features']) && count($this->Request['form']['features']) > 3? count($this->Request['form']['features']) : (!empty($this->PreparedTemplates['features']) && count($this->PreparedTemplates['features']) > 3? count($this->PreparedTemplates['features']) : 3);
				for($i = 1; $i <= $number_feature; $i++) {
					$this->TempFillEls['features'][$i] = array(
						'num' => $i,
						'value' => inputTextArea('form[features]['.$i.'][value]',(!empty($this->Request)? @$this->Request['form']['features'][$i]['value'] : (isset($this->PreparedTemplates['features'][$i-1])? $this->PreparedTemplates['features'][$i-1]['value'] : '')),65,1,'style="width:650px;"'),
						'sort_order' => inputText('form[features]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['features'][$i]['sort_order'] : (isset($this->PreparedTemplates['features'][$i-1])? $this->PreparedTemplates['features'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'delete_feature' => array(array('num' => $i)),
					);
				}
				$number_review = !empty($this->Request['form']['reviews']) && count($this->Request['form']['reviews']) > 0? count($this->Request['form']['reviews']) : (!empty($this->PreparedTemplates['reviews']) && count($this->PreparedTemplates['reviews']) > 0? count($this->PreparedTemplates['reviews']) : 0);
				for($i = 1; $i <= $number_review; $i++) {
					$this->TempFillEls['reviews'][$i] = array(
						'num' => $i,
						'url' => inputTextArea('form[reviews]['.$i.'][url]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['url'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['url'] : '')),32,2,'style="width:320px;"'),
						'image_url' => inputTextArea('form[reviews]['.$i.'][image_url]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['image_url'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_url'] : '')),32,2,'style="width:320px;"'),
						'image_alt' => inputTextArea('form[reviews]['.$i.'][image_alt]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['image_alt'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_alt'] : '')),32,2,'style="width:320px;"'),
						'image_title' => inputTextArea('form[reviews]['.$i.'][image_title]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['image_title'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_title'] : '')),32,2,'style="width:320px;"'),
						'description' => inputTextArea('form[reviews]['.$i.'][description]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['description'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['description'] : '')),32,2,'style="width:320px;"'),
						'sort_order' => inputText('form[reviews]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['sort_order'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'delete_review' => array(array('num' => $i)),
						'moduletype' => inputHidden('form[reviews]['.$i.'][moduletype]',3),
					);
					if(!empty($this->errors['review'][$i]))
						foreach($this->errors['review'][$i] as $key => $value) $this->TempFillEls['reviews'][$i][$key.'_error'] = $this->printError($value);
				}
				$number_cr = !empty($this->Request['form']['customerreviewitems']) && count($this->Request['form']['customerreviewitems']) > 0? count($this->Request['form']['customerreviewitems']) : (!empty($this->PreparedTemplates['customerreviewitems']) && count($this->PreparedTemplates['customerreviewitems']) > 0? count($this->PreparedTemplates['customerreviewitems']) : 0);
				for($i = 1; $i <= $number_cr; $i++) {
					$this->TempFillEls['cr_items'][$i] = array(
						'num' => $i,
						'sort_order' => inputText('form[customerreviewitems]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['sort_order'] : (isset($this->PreparedTemplates['customerreviewitems'][$i-1])? $this->PreparedTemplates['customerreviewitems'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'delete_cr' => array(array('num' => $i)),
						'object' => inputHidden('form[customerreviewitems]['.$i.'][object]', (!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['object'] : $this->PreparedTemplates['customerreviewitems'][$i-1]['object'])),
						'name' => inputText('form[customerreviewitems]['.$i.'][name]', htmlspecialchars(strip_tags($this->customerreviews[(!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['object'] : $this->PreparedTemplates['customerreviewitems'][$i-1]['object'])]), ENT_QUOTES),2,'disabled="true" style="width:480px;"'),
						'type' => inputHidden('form[customerreviewitems]['.$i.'][moduletype]', 3),
						'change_cr' => array(array('num' => $i)),
					);
					if(!empty($this->errors['cr'][$i]))
						foreach($this->errors['cr'][$i] as $key => $value) $this->TempFillEls['cr_items'][$i][$key.'_error'] = $this->printError($value);
				}
				$number_price = !empty($this->Request['form']['prices']) && count($this->Request['form']['prices']) > 1? count($this->Request['form']['prices']) : (!empty($this->PreparedTemplates['prices']) && count($this->PreparedTemplates['prices']) > 1? count($this->PreparedTemplates['prices']) : 1);
				for($i = 1; $i <= $number_price; $i++) {
					$this->TempFillEls['prices'][$i] = array(
						'num' => $i,
						'name' => 'Price '.$i,
						'value' => inputText('form[prices]['.$i.'][value]',(!empty($this->Request)? @$this->Request['form']['prices'][$i]['value'] : $this->PreparedTemplates['prices'][($i-1)]['value']),15,'style="width:150px;"'),
						'current' => inputHidden('form[prices]['.$i.'][current]',0).inputCheckbox('form[prices]['.$i.'][current]',(!empty($this->Request)? @$this->Request['form']['prices'][$i]['current'] : $this->PreparedTemplates['prices'][($i-1)]['current']),' class=check'),
						'delete_price' => array(array('num' => $i)),
					);
				}
				//$this->setCollections('recomenduses','recomenduselineitems');
				$this->setCollections('related','relatedlineitems');
				$this->setCollections('articles','articlelineitems');
				$this->setCollections('technologies','technologylineitems');
				foreach($this->shipcosts as $key => $value) {
					$this->TempFillEls['costs'][$key] = array(
						//'value' => inputText('form[shipcosts]['.$key.'][value]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key)),15,'style="width:150px;"'),
						'value_zone1' => inputText('form[shipcosts]['.$key.'][value_zone1]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value_zone1'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key, 1)),15,'style="width:150px;"'),
						'value_zone2' => inputText('form[shipcosts]['.$key.'][value_zone2]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value_zone2'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key, 2)),15,'style="width:150px;"'),
						'value_zone3' => inputText('form[shipcosts]['.$key.'][value_zone3]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value_zone3'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key, 3)),15,'style="width:150px;"'),
						'id' => inputHidden('form[shipcosts]['.$key.'][type][id]',$key),
						'name' => $value,
					);
				}
				$i = 1;
				foreach($this->accessories as $k => $v) {
					$i_path2 = file_exists($this->ImagePath.'/products/'.$k.'/middle.jpg')? '/products/'.$k.'/middle.jpg' : '';
					$li = FALSE;
					$checked = 0;
					$forsale = 0;
					foreach($this->PreparedTemplates['productlineitems'] as $key => $value) {
						if($value['lineitem']['id']==$k) {
							$li = TRUE;
							if($value['optional']) $checked = 1;
							if($value['forsale']) $forsale = 1;
						}
					}
//printArray($this->Request['form']['productlineitems']);exit;
					$this->TempFillEls['accessories'][$k] = array(
						'num' => $i++.'.',
						'name' => inputCheckbox('form[productlineitems]['.$k.'][lineitem][id]',		(!empty($this->Request)? @$this->Request['form']['productlineitems'][$k]['lineitem']['id'] : $li),'  id="acc_active_'.$k.'"   class=check',$k)."&nbsp;".$this->accessories[$k],
						'type' => implode(' ',radioButtons(array('1' => 'Optional','0' => 'Included'),'form[productlineitems]['.$k.'][optional]',(!empty($this->Request)? @$this->Request['form']['productlineitems'][$k]['optional'] : $checked),' class=check      onclick="if(this.value==1) document.getElementById(\'acc_'.$k.'\').style.background = \'lightgreen\'; else document.getElementById(\'acc_'.$k.'\').style.background = \'lightblue\';   "         ')),

						'forsale' => inputCheckbox('form[productlineitems]['.$k.'][forsale]', (!empty($this->Request)? @$this->Request['form']['productlineitems'][$k]['forsale'] : $forsale),' class=check'),
						'visible' => ($i_path2=='')? 'none':'visible',
						'id' => $k,					
						'image_link' => $this->ImageWPath.$i_path2,

//						'backcolor' =>  ((!empty($this->Request) && $this->Request['form']['productlineitems'][$k]['optional'] )? 'lightblue' : ($checked?'lightgreen':'lightblue')   ),		//lightgreen included
						'backcolor' =>  ((!empty($this->Request) && isset($this->Request['form']['productlineitems'][$k]['optional']) && $this->Request['form']['productlineitems'][$k]['optional'] )? 'lightblue' : ($checked?'lightgreen':'lightblue')   ),		//lightgreen included
					);
				}
				
				$number_link = !empty($this->Request['form']['links']) && count($this->Request['form']['links']) > 3? count($this->Request['form']['links']) : (count($this->PreparedTemplates['links']) > 3? count($this->PreparedTemplates['links']) : 3);
				for($i = 1; $i <= $number_link; $i++) {
					$this->TempFillEls['links'][$i] = array(
						'name' => inputTextArea('form[links]['.$i.'][description]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['description'] : @$this->PreparedTemplates['links'][$i-1]['description']),55,2,'style="width:350px;"'),
						'js' => inputCheckbox('form[links]['.$i.'][js]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['js'] : @$this->PreparedTemplates['links'][$i-1]['js']),'class=check',1),
						'type' => inputSelect('form[links]['.$i.'][linktype]',array('1' => 'Scope Applications','2' => 'Featured Retailers'),(!empty($this->Request)? @$this->Request['form']['links'][$i]['linktype'] : @$this->PreparedTemplates['links'][$i-1]['linktype'])),
						'link' => inputTextArea('form[links]['.$i.'][link]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['link'] : @$this->PreparedTemplates['links'][$i-1]['link']),55,2,'style="width:300px;"'),
						'url' => inputTextArea('form[links]['.$i.'][url]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['url'] : @$this->PreparedTemplates['links'][$i-1]['url']),55,2,'style="width:350px;"'),
						'id' => inputHidden('form[links]['.$i.'][moduletype]',2),
						'key' => $i,
						'delete_link' => array(array('num' => $i)),
					);
				}
				if(!empty($this->LocalTarget[3]) && validate(intval($this->LocalTarget[3])) && $this->LocalTarget[2]=='Undo')
					$this->TempFillEls['undo'] = '(Undo v.'.$this->LocalTarget[3].')';
				$this->TempFillEls['textareaValidJS']='if(parseInt(document.getElementById("comment").value.length+"-")<5){
							//document.getElementById("comment").focus();
							alert("Comment is empty or is not valid");
							return false;
							}';
				$this->TempFillEls['ViewAllButton']='<input type="button" name="View_All" class=adminsubmit value="View All" onclick="open(\'/Registar/ProductsManager/ViewAll/'.$this->PreparedTemplates['id'].'\',\'displayWindow\',\'width=950,height=600,scrollbars=yes\');">';
				$this->TempFillEls['textareaComment']='<textarea name=form[comment] id=comment cols=80 rows=5>'.(!empty($this->Request['form']['comment'])? $this->Request['form']['comment'] :  date("M d, Y H:i:s")  ).'</textarea>';
				$selected = $this->Db->SelectAny("select cc.*,m.username as member from productcomment cc, member m where m.id=cc.member and cc.ownerid = ".$this->PreparedTemplates['id']." order by cc.version DESC LIMIT 10 OFFSET 0");
				if(!empty($selected)) {
					foreach($selected as $ind => $val) {
						$tok = explode(".",$val['date']);
						$this->TempFillEls['comment'][] = array(
							'number' => ($ind+1),
							'date' => $tok[0],
							'author' => $val['member'],
							'changed' => $val['value'],
							'version' => $val['version'],
							'button' => $ind!=0 && file_exists($ROOT_PATH.'/undo/product/'.$this->PreparedTemplates['id'].'/'.$val['version'].'.inc')? array(array('id' => $this->PreparedTemplates['id'],'version' => $val['version'])) : array(),
						);
					}
				}
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'tree');
				$this->setCategories($this->PreparedTemplates);
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID, 'save');
			break;
			}
			case 'Duplicate': {
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open');
				$path = '/products/'.$this->PreparedTemplates['id'];
				$files = array('prew' => array(),'big' => array(),'image' => array(),'3d' => array(),'hi' => array(),'ss' => array(),'ug' => array(),'middle' => array());
				foreach($this->PreparedTemplates['files'] as $key => $value) {
					switch($value['filetype']) {
						case 2: $files['big'] = array('image_link' => $value['image_link'],'name' => 'big.'.$value['imagetype']); break;
//						case 3: $files['image'][$value['number']] = array('name' => date2pg($value['number']),'ext' => $value['imagetype']); break;
						case 3: $files['image'][$value['number']] = array('name' => date2pg($value['number']),'ext' => $value['imagetype'], 'sort_order' => $value['sort_order']); break;
						case 4: $files['3d'][$value['number']] = array('name' => date2pg($value['number']).'.'.$value['imagetype']); break;
						case 5: $files['hi'] = array('name' => 'hi.'.$value['imagetype']); break;
						case 6: $files['ss'] = array('name' => 'ss.'.$value['imagetype']); break;
						case 7: 
								$files['ug'] = array('name' => 'ug.'.$value['imagetype']);
								$files['userguide'][$value['number']] = array( 'name' => date2pg($value['number']), 'sort_order' => $value['sort_order'], 'description' => $value['description'] ); 
						break;
						case 8: $files['middle'] = array('image_link' => $value['image_link'],'name' => 'middle.'.$value['imagetype']); break;
					}
				}
				
				$this->TempFillEls = array(
					'subaction' => 'Duplicate',
					'subprocess' => 'duplicating',
					'step' => 'add',
					'is_active' => inputHidden('form[is_active]',0).inputCheckbox('form[is_active]',(!empty($this->Request)? $this->getRequestFormField('is_active') : $this->PreparedTemplates['is_active']),' class=check'),
					'export' => inputHidden('form[export]',0).inputCheckbox('form[export]',(!empty($this->Request)? $this->getRequestFormField('export') : $this->PreparedTemplates['export']),' class=check'),
					'callforquote' => inputHidden('form[callforquote]',0).inputCheckbox('form[callforquote]',(!empty($this->Request)? $this->getRequestFormField('callforquote') : $this->PreparedTemplates['callforquote']),' class=check'),
					'grade_tube' => inputHidden('form[grade_tube]',0).inputCheckbox('form[grade_tube]',(!empty($this->Request)? $this->getRequestFormField('grade_tube') : $this->PreparedTemplates['grade_tube']),' class=check'),				
					'root_check' => inputCheckbox('root_check',(!empty($this->Request)? $this->getRequestField('root_check') : ($this->PreparedTemplates['path2']? 1 : 0)),' onClick="javascript:correctRootPath();"'),
					'pid' => inputText('form[pid]',(!empty($this->Request)? $this->getRequestFormField('pid') : $this->PreparedTemplates['pid']),55,'style="width:400px;"'),
					'name' => inputTextArea('form[name]',(!empty($this->Request)? $this->getRequestFormField('name') : $this->PreparedTemplates['name']),55,1,'style="width:400px;height:16px"'),
					'nav_name' => inputTextArea('form[nav_name]',(!empty($this->Request)? $this->getRequestFormField('nav_name') : $this->PreparedTemplates['nav_name']),55,1,'style="width:400px;height:16px"'),
					'item' => inputSelect('form[item][id]',$this->parentitems,(!empty($this->Request)? $this->getRequestFormField('item',1) : $this->PreparedTemplates['item']['id']),'style="width:400px;"'),
					'path' => inputText('form[path]',(!empty($this->Request)? $this->getRequestFormField('path') : $this->PreparedTemplates['path']),55,'style="width:400px;"'),
					'path2' => inputText('form[path2]',(!empty($this->Request)? $this->getRequestFormField('path2') : $this->PreparedTemplates['path2']),75,'style="width:460px;display:'.(validate($this->getRequestField('root_check')) || !empty($this->PreparedTemplates['path2'])? 'inline' : 'none').'"'),
					'warranty' => inputSelect('form[warranty][id]',$this->warranty,(!empty($this->Request)? $this->getRequestFormField('warranty',1) : $this->PreparedTemplates['warranty']['id']),'style="width:260px;"'),
					'rate' => inputSelect('form[rate][id]',$this->rate,(!empty($this->Request)? $this->getRequestFormField('rate',1) : $this->PreparedTemplates['rate']['id']),'style="width:260px;"'),
					'level' => inputSelect('form[level][id]',$this->level,(!empty($this->Request)? $this->getRequestFormField('level',1) : $this->PreparedTemplates['level']['id']),'style="width:260px;"'),
					'policy' => inputSelect('form[policy][id]',$this->policy,(!empty($this->Request)? $this->getRequestFormField('policy',1) : $this->PreparedTemplates['policy']['id']),'style="width:260px;"'),
					'core' => inputSelect('form[core][id]',$this->core,(!empty($this->Request)? $this->getRequestFormField('core',1) : $this->PreparedTemplates['core']['id']),'style="width:400px;"'),
					'lens' => inputSelect('form[lens][id]',$this->lens,(!empty($this->Request)? $this->getRequestFormField('lens',1) : $this->PreparedTemplates['lens']['id']),'style="width:400px;"'),
					'brand' => inputSelect('form[brand][id]',$this->brand,(!empty($this->Request)? $this->getRequestFormField('brand',1) : $this->PreparedTemplates['brand']['id']),'style="width:400px;"'),
					'generation' => inputSelect('form[generation][id]',$this->generation,(!empty($this->Request)? $this->getRequestFormField('generation',1) : $this->PreparedTemplates['generation']['id']),'style="width:400px;"'),
					'export_restriction' => inputSelect('form[export_restriction][id]',$this->export,(!empty($this->Request)? $this->getRequestFormField('export_restriction',1) : $this->PreparedTemplates['export_restriction']['id']),'style="width:400px;"'),
					
					/*'device_simulator_image' => $this->PreparedTemplates['device_simulator_image'],										
					'device_simulator_input' => inputText('form[device_simulator_link]',(!empty($this->Request)? $this->Request['form']['device_simulator_link'] : $this->PreparedTemplates['device_simulator_link']),55,'style="width:300px;"'),
					'device_simulator_link' =>  $this->PreparedTemplates['device_simulator_link'], */
					
					'short_desc' => inputTextArea('form[short_desc]',(!empty($this->Request)? $this->Request['form']['short_desc'] : $this->PreparedTemplates['short_desc']),110,5,'style="width:730px;"'),
					'special_offer' => inputTextArea('form[special_offer]',(!empty($this->Request)? $this->Request['form']['special_offer'] : $this->PreparedTemplates['special_offer']),110,5,'style="width:730px;"'),				
//					'short_desc2' => inputTextArea('form[short_desc2]',(!empty($this->Request)? $this->Request['form']['short_desc2'] : $this->PreparedTemplates['short_desc2']),110,5,'style="width:730px;"'),
					'video_desc' => inputTextArea('form[video_desc]',(!empty($this->Request)? $this->Request['form']['video_desc'] : $this->PreparedTemplates['video_desc']),110,5,'style="width:730px;"'),				
					'full_desc' => inputTextArea('form[full_desc]',(!empty($this->Request)? $this->Request['form']['full_desc'] : $this->PreparedTemplates['full_desc']),110,10,'style="width:730px;"'),
					'product_class' => inputText('form[product_class]',(!empty($this->Request)? $this->Request['form']['product_class'] : $this->PreparedTemplates['product_class']),55,'style="width:250px;"'),
					'edit_id' => '"'.$this->PreparedTemplates['name'].'" ['.$this->PreparedTemplates['id'].']',
					'duplicate_id' => $this->PreparedTemplates['id'],
				//	'prew_image' => !empty($files['prew']['image_link'])? $this->makeImageLink('prew',$files['prew']['image_link']) : makeImage($this->ImagePath.$path.'/'.$files['prew']['name'],$this->ImageWPath.$path.'/'.$files['prew']['name'].'?'.time(),'','',array(),0,'','prewimg'),
					'prew_upload' => inputFile('prew_image'),
					'prew_setting' => 'Jpg, '.$this->upload_settings['prew_width'].'x'.$this->upload_settings['prew_height'],
					//'prew_image_link' => inputSelect('prew_image_link',$this->products,(!empty($this->Request)? $this->getRequestField('prew_image_link') : $files['prew']['image_link']),'style="width:400px;" onchange="selectImage(\'prew\')"'),
					'prew_display' => (!empty($this->Request)? validate($this->getRequestField('prew_image_link')) : !empty($files['prew']['image_link']))? 'none' : 'inline',
					'middle_image' => !empty($files['middle']['image_link'])? $this->makeImageLink('middle',$files['middle']['image_link']) : makeImage($this->ImagePath.$path.'/'.$files['middle']['name'],$this->ImageWPath.$path.'/'.$files['middle']['name'].'?'.time(),'','',array(),0,'','middleimg'),
					'middle_upload' => inputFile('middle_image'),
					'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					//'middle_image_link' => inputSelect('middle_image_link',$this->products,(!empty($this->Request)? $this->getRequestField('middle_image_link') : $files['middle']['image_link']),'style="width:400px;" onchange="selectImage(\'middle\')"'),
					'middle_display' => (!empty($this->Request)? validate($this->getRequestField('middle_image_link')) : !empty($files['middle']['image_link']))? 'none' : 'inline',
					//'big_image' => !empty($files['big']['image_link'])? $this->makeImageLink('big',$files['big']['image_link']) : makeImage($this->ImagePath.$path.'/'.$files['big']['name'],$this->ImageWPath.$path.'/'.$files['big']['name'].'?'.time(),'','',array(),0,'','bigimg'),
					//'big_upload' => inputFile('big_image'),
					//'big_setting' => 'Jpg, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
					//'big_image_link' => inputSelect('big_image_link',$this->products,(!empty($this->Request)? $this->getRequestField('big_image_link') : $files['big']['image_link']),'style="width:400px;" onchange="selectImage(\'big\')"'),
					//'big_display' => (!empty($this->Request)? validate($this->getRequestField('big_image_link')) : !empty($files['big']['image_link']))? 'none' : 'inline',
					'ug_image' => !empty($files['ug'])? (file_exists($this->ImagePath.$path.'/'.$files['ug']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['ug']['name'],makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif',$this->PreparedTemplates['name'].' - User\'s Guide'),array(),'','id=\'ug_icon\'') : '&nbsp;') : '&nbsp;',
					'ug_upload' => inputFile('ug_image'),
					'ss_image' => !empty($files['ss'])? (file_exists($this->ImagePath.$path.'/'.$files['ss']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['ss']['name'],makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif',$this->PreparedTemplates['name'].' - Specification Sheet'),array(),'','id=\'ss_icon\'') : '&nbsp;') : '&nbsp;',
					'ss_upload' => inputFile('ss_image'),
					'hi_image' => !empty($files['hi'])? (file_exists($this->ImagePath.$path.'/'.$files['hi']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['hi']['name'],makeImage($this->ImagePath.'/../registarImg/tif.gif',$this->ImageWPath.'/../registarImg/tif.gif',$this->PreparedTemplates['name'].' - Hi-Res. Image'),array(),'','id=\'hi_icon\'') : '&nbsp;') : '&nbsp;',
					'hi_upload' => inputFile('hi_image'),
					'ug_delete' => !empty($files['ug'])? (file_exists($this->ImagePath.$path.'/'.$files['ug']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'ss_delete' => !empty($files['ss'])? (file_exists($this->ImagePath.$path.'/'.$files['ss']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'hi_delete' => !empty($files['hi'])? (file_exists($this->ImagePath.$path.'/'.$files['hi']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'param_buttons' => array(array()),
					'price_buttons' => array(array()),
					'image_buttons' => array(array()),
					'3d_buttons' => array(array()),
					'link_buttons' => array(array()),
					'feature_buttons' => array(array()),
					'review_buttons' => array(array()),
					'cr_buttons' => array(array()),
					'product_color' => inputSelect('form[color][id]',$this->prod_colors,(!empty($this->Request)? $this->getRequestFormField('color',1) : $this->PreparedTemplates['color']['id']),'style="width:250px;"'),
				);
				//-----   userguides 
				$number_userguide = !empty($this->Request['userguide_big']) && count($this->Request['userguide_big']['name']) > 1? count($this->Request['userguide_big']['name']) : (!empty($files['userguide']) && count($files['userguide']) > 1? count($files['userguide']) : 1);
				for($i = 1; $i <= $number_userguide; $i++) {
					$this->TempFillEls['userguides'][$i] = array(
						'num' => $i,
						'big_userguide' =>  !empty($files['userguide'])? (file_exists($this->ImagePath.$path.'/userguides/'.$files['userguide'][$i]['name'].'.pdf')? makeLink($this->ImageWPath.$path.'/userguides/'.$files['userguide'][$i]['name'].'.pdf',makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif', ' User\'s Guide'),array(),'','id=\'ug_icon\'') : '&nbsp;') : '&nbsp;',					
						'userguide_big_upload' => inputFile('userguide_big['.$i.']'),
						'sort_order' =>inputText('userguide_big_sort_order['.$i.']',  !empty($this->Request['userguide_big_sort_order'][$i])?$this->Request['userguide_big_sort_order'][$i]: (isset($files['userguide'][$i]['sort_order'])?$files['userguide'][$i]['sort_order']:'1') ,'3'),
						'description'=>inputTextArea('userguide_description['.$i.']',  !empty($this->Request['userguide_description'][$i])?$this->Request['userguide_description'][$i]:(isset($files['userguide'][$i]['description'])?$files['userguide'][$i]['description']:''),38,2,'style="width:295px;"'),
						'userguide_big_error' => !empty($this->errors['userguide_big'][$i])? $this->printError($this->errors['userguide_big'][$i]) : '',
						'delete_userguide' => array(array('num' => $i)),
					);
				}
				//-----
				
				$number_image = !empty($this->Request['image_big']) && count($this->Request['image_big']['name']) > 1? count($this->Request['image_big']['name']) : (!empty($files['image']) && count($files['image']) > 1? count($files['image']) : 1);
				for($i = 1; $i <= $number_image; $i++) {
					$this->TempFillEls['images'][$i] = array(
						'num' => $i,
						'big_setting' => 'png, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
						'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					'small_setting' => 'jpg, '.$this->upload_settings['small_width'].'x'.$this->upload_settings['small_height'],
						'big_image' => !empty($files['image'][$i])? (file_exists($this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '280', '1' => '100' ),'big_image'.$i.'img') : '&nbsp;') : '&nbsp;',
						'middle_image' => !empty($files['image'][$i])? (file_exists($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '280', '1' => '100' ),'middle_image'.$i.'img') : '&nbsp;') : '&nbsp;',
					'small_image' => !empty($files['image'][$i])? (file_exists($this->ImagePath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '140', '1' => '50' ),'small_image'.$i.'img') : '&nbsp;') : '&nbsp;',
						'image_big_upload' => inputFile('image_big['.$i.']'),
				'sort_order' =>inputText('image_big_sort_order['.$i.']',  !empty($this->Request['image_big_sort_order'][$i])?$this->Request['image_big_sort_order'][$i]: $files['image'][$i]['sort_order']   ,'3'),					
						'image_middle_upload' => inputFile('image_middle['.$i.']'),
					'image_small_upload' => inputFile('image_small['.$i.']'),
						'image_big_error' => !empty($this->errors['image_big'][$i])? $this->printError($this->errors['image_big'][$i]) : '',
						'image_middle_error' => !empty($this->errors['image_middle'][$i])? $this->printError($this->errors['image_middle'][$i]) : '',
					'image_small_error' => !empty($this->errors['image_small'][$i])? $this->printError($this->errors['image_small'][$i]) : '',
						'delete_image' => array(array('num' => $i)),
					);
				}
				$number_param = !empty($this->Request['form']['parameters']) && count($this->Request['form']['parameters']) > 10? count($this->Request['form']['parameters']) : (!empty($this->PreparedTemplates['parameters']) && count($this->PreparedTemplates['parameters']) > 10? count($this->PreparedTemplates['parameters']) : 10);
				for($i = 1; $i <= $number_param; $i++) {
					$this->TempFillEls['parameters'][$i] = array(
						'num' => $i,
						'name' => inputTextArea('form[parameters]['.$i.'][name]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['name'] : (isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['name'] : '')),38,1,'style="width:300px;"'),
						'value' => inputTextArea('form[parameters]['.$i.'][value]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['value'] : (isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['value'] : '')),45,1,'style="width:340px;"'),
						'sort_order' => inputText('form[parameters]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['sort_order'] : (isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'is_front' => inputCheckbox('form[parameters]['.$i.'][is_front]',(!empty($this->Request)? @$this->Request['form']['parameters'][$i]['is_front'] : @$this->PreparedTemplates['parameters'][$i-1]['is_front']),'class=check',1),
						'delete_param' => array(array('num' => $i)),
					);
				}
				$number_feature = !empty($this->Request['form']['features']) && count($this->Request['form']['features']) > 3? count($this->Request['form']['features']) : (!empty($this->PreparedTemplates['features']) && count($this->PreparedTemplates['features']) > 3? count($this->PreparedTemplates['features']) : 3);
				for($i = 1; $i <= $number_feature; $i++) {
					$this->TempFillEls['features'][$i] = array(
						'num' => $i,
						'value' => inputTextArea('form[features]['.$i.'][value]',(!empty($this->Request)? @$this->Request['form']['features'][$i]['value'] : (isset($this->PreparedTemplates['features'][$i-1])? $this->PreparedTemplates['features'][$i-1]['value'] : '')),65,1,'style="width:650px;"'),
						'sort_order' => inputText('form[features]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['features'][$i]['sort_order'] : (isset($this->PreparedTemplates['features'][$i-1])? $this->PreparedTemplates['features'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'delete_feature' => array(array('num' => $i)),
					);
				}
				$number_review = !empty($this->Request['form']['reviews']) && count($this->Request['form']['reviews']) > 0? count($this->Request['form']['reviews']) : (!empty($this->PreparedTemplates['reviews']) && count($this->PreparedTemplates['reviews']) > 0? count($this->PreparedTemplates['reviews']) : 0);
				for($i = 1; $i <= $number_review; $i++) {
					$this->TempFillEls['reviews'][$i] = array(
						'num' => $i,
						'url' => inputTextArea('form[reviews]['.$i.'][url]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['url'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['url'] : '')),32,2,'style="width:320px;"'),
						'image_url' => inputTextArea('form[reviews]['.$i.'][image_url]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['image_url'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_url'] : '')),32,2,'style="width:320px;"'),
						'image_alt' => inputTextArea('form[reviews]['.$i.'][image_alt]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['image_alt'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_alt'] : '')),32,2,'style="width:320px;"'),
						'image_title' => inputTextArea('form[reviews]['.$i.'][image_title]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['image_title'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_title'] : '')),32,2,'style="width:320px;"'),
						'description' => inputTextArea('form[reviews]['.$i.'][description]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['description'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['description'] : '')),32,2,'style="width:320px;"'),
						'sort_order' => inputText('form[reviews]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['reviews'][$i]['sort_order'] : (isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'delete_review' => array(array('num' => $i)),
						'moduletype' => inputHidden('form[reviews]['.$i.'][moduletype]',3),
					);
					if(!empty($this->errors['review'][$i]))
						foreach($this->errors['review'][$i] as $key => $value) $this->TempFillEls['reviews'][$i][$key.'_error'] = $this->printError($value);
				}
				$number_cr = !empty($this->Request['form']['customerreviewitems']) && count($this->Request['form']['customerreviewitems']) > 0? count($this->Request['form']['customerreviewitems']) : (!empty($this->PreparedTemplates['customerreviewitems']) && count($this->PreparedTemplates['customerreviewitems']) > 0? count($this->PreparedTemplates['customerreviewitems']) : 0);
				for($i = 1; $i <= $number_cr; $i++) {
					$this->TempFillEls['cr_items'][$i] = array(
						'num' => $i,
						'sort_order' => inputText('form[customerreviewitems]['.$i.'][sort_order]',(!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['sort_order'] : (isset($this->PreparedTemplates['customerreviewitems'][$i-1])? $this->PreparedTemplates['customerreviewitems'][$i-1]['sort_order'] : $i*10)),2,'style="width:30px;"'),
						'delete_cr' => array(array('num' => $i)),
						'object' => inputHidden('form[customerreviewitems]['.$i.'][object]', (!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['object'] : $this->PreparedTemplates['customerreviewitems'][$i-1]['object'])),
						'name' => inputText('form[customerreviewitems]['.$i.'][name]', htmlspecialchars(strip_tags($this->customerreviews[(!empty($this->Request)? @$this->Request['form']['customerreviewitems'][$i]['object'] : $this->PreparedTemplates['customerreviewitems'][$i-1]['object'])]), ENT_QUOTES),2,'disabled="true" style="width:480px;"'),
						'type' => inputHidden('form[customerreviewitems]['.$i.'][moduletype]', 3),
						'change_cr' => array(array('num' => $i)),
					);
					if(!empty($this->errors['cr'][$i]))
						foreach($this->errors['cr'][$i] as $key => $value) $this->TempFillEls['cr_items'][$i][$key.'_error'] = $this->printError($value);
				}
				$number_price = !empty($this->Request['form']['prices']) && count($this->Request['form']['prices']) > 1? count($this->Request['form']['prices']) : (!empty($this->PreparedTemplates['prices']) && count($this->PreparedTemplates['prices']) > 1? count($this->PreparedTemplates['prices']) : 1);
				for($i = 1; $i <= $number_price; $i++) {
					$this->TempFillEls['prices'][$i] = array(
						'num' => $i,
						'name' => 'Price '.$i,
						'value' => inputText('form[prices]['.$i.'][value]',(!empty($this->Request)? @$this->Request['form']['prices'][$i]['value'] : $this->PreparedTemplates['prices'][($i-1)]['value']),15,'style="width:150px;"'),
						'current' => inputHidden('form[prices]['.$i.'][current]',0).inputCheckbox('form[prices]['.$i.'][current]',(!empty($this->Request)? @$this->Request['form']['prices'][$i]['current'] : $this->PreparedTemplates['prices'][($i-1)]['current']),' class=check'),
						'delete_price' => array(array('num' => $i)),
					);
				}
				$this->setCollections('related','relatedlineitems');
				$this->setCollections('articles','articlelineitems');
				$this->setCollections('technologies','technologylineitems');
				foreach($this->shipcosts as $key => $value) {
					$this->TempFillEls['costs'][$key] = array(
						//'value' => inputText('form[shipcosts]['.$key.'][value]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key)),15,'style="width:150px;"'),
						'value_zone1' => inputText('form[shipcosts]['.$key.'][value_zone1]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value_zone1'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key, 1)),15,'style="width:150px;"'),
						'value_zone2' => inputText('form[shipcosts]['.$key.'][value_zone2]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value_zone2'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key, 2)),15,'style="width:150px;"'),
						'value_zone3' => inputText('form[shipcosts]['.$key.'][value_zone3]',(!empty($this->Request)? @$this->Request['form']['shipcosts'][$key]['value_zone3'] : $this->getShipCost($this->PreparedTemplates['shipcosts'],$key, 3)),15,'style="width:150px;"'),
						'id' => inputHidden('form[shipcosts]['.$key.'][type][id]',$key),
						'name' => $value,
					);
				}
				$i = 1;
				foreach($this->accessories as $k => $v) {
					$li = FALSE;
					$checked = 0;
					$forsale = 0;
					foreach($this->PreparedTemplates['productlineitems'] as $key => $value) {
						if($value['lineitem']['id']==$k) {
							$li = TRUE;
							if($value['optional']) $checked = 1;
							if($value['forsale']) $forsale = 1;
						}
					}
					$this->TempFillEls['accessories'][$k] = array(
						'num' => $i++.'.',
						'name' => inputCheckbox('form[productlineitems]['.$k.'][lineitem][id]',(!empty($this->Request)? @$this->Request['form']['productlineitems'][$k]['lineitem']['id'] : $li),'  id="acc_active_'.$k.'"    class=check',$k)."&nbsp;".$this->accessories[$k],
						'type' => implode(' ',radioButtons(array('1' => 'Optional','0' => 'Included'),'form[productlineitems]['.$k.'][optional]',(!empty($this->Request)? @$this->Request['form']['productlineitems'][$k]['optional'] : $checked),'     onclick="if(this.value==1) document.getElementById(\'acc_'.$k.'\').style.background = \'lightgreen\'; else document.getElementById(\'acc_'.$k.'\').style.background = \'lightblue\';   "      class=check')),
						'forsale' => inputCheckbox('form[productlineitems]['.$k.'][forsale]',  (!empty($this->Request)? @$this->Request['form']['productlineitems'][$k]['forsale'] : $forsale),' class=check' ),
						'id' => $k,
						'backcolor' =>  ((!empty($this->Request) && isset($this->Request['form']['productlineitems'][$k])  && $this->Request['form']['productlineitems'][$k]['optional'] )? 'lightblue' : ($checked?'lightgreen':'lightblue')   ),		//lightgreen included
					);
				}
				$number_link = !empty($this->Request['form']['links']) && count($this->Request['form']['links']) > 3? count($this->Request['form']['links']) : (count($this->PreparedTemplates['links']) > 3? count($this->PreparedTemplates['links']) : 3);
				for($i = 1; $i <= $number_link; $i++) {
					$this->TempFillEls['links'][$i] = array(
						'name' => inputTextArea('form[links]['.$i.'][description]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['description'] : @$this->PreparedTemplates['links'][$i-1]['description']),55,2,'style="width:350px;"'),
						'js' => inputCheckbox('form[links]['.$i.'][js]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['js'] : @$this->PreparedTemplates['links'][$i-1]['js']),'class=check',1),
						'type' => inputSelect('form[links]['.$i.'][linktype]',array('1' => 'Scope Applications','2' => 'Featured Retailers'),(!empty($this->Request)? @$this->Request['form']['links'][$i]['linktype'] : @$this->PreparedTemplates['links'][$i-1]['linktype'])),
						'link' => inputTextArea('form[links]['.$i.'][link]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['link'] : @$this->PreparedTemplates['links'][$i-1]['link']),55,2,'style="width:300px;"'),
						'url' => inputTextArea('form[links]['.$i.'][url]',(!empty($this->Request)? @$this->Request['form']['links'][$i]['url'] : @$this->PreparedTemplates['links'][$i-1]['url']),55,2,'style="width:350px;"'),
						'id' => inputHidden('form[links]['.$i.'][moduletype]',2),
						'key' => $i,
						'delete_link' => array(array('num' => $i)),
					);
				}
				if(!empty($this->LocalTarget[3]) && validate(intval($this->LocalTarget[3])) && $this->LocalTarget[2]=='Undo')
					$this->TempFillEls['undo'] = '(Undo v.'.$this->LocalTarget[3].')';
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'tree');
				$this->setCategories($this->PreparedTemplates);
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID, 'save');
			break;
			}
			case 'Delete': {
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open');
				$path = '/products/'.$this->PreparedTemplates['id'];
				$files = array('prew' => array(),'big' => array(),'image' => array(),'3d' => array(),'hi' => array(),'ss' => array(),'ug' => array(),'middle' => array());
				foreach($this->PreparedTemplates['files'] as $key => $value) {
					switch($value['filetype']) {
						//case 1: $files['prew'] = array('image_link' => $value['image_link'],'name' => 'prew.'.$value['imagetype']); break;
						case 2: $files['big'] = array('image_link' => $value['image_link'],'name' => 'big.'.$value['imagetype']); break;
						case 3: $files['image'][$value['number']] = array('name' => date2pg($value['number']),'ext' => $value['imagetype']); break;
						case 4: $files['3d'][$value['number']] = array('name' => date2pg($value['number']).'.'.$value['imagetype']); break;
						case 5: $files['hi'] = array('name' => 'hi.'.$value['imagetype']); break;
						case 6: $files['ss'] = array('name' => 'ss.'.$value['imagetype']); break;
						case 7: 
							$files['ug'] = array('name' => 'ug.'.$value['imagetype']);
							$files['userguide'][$value['number']] = array( 'name' => date2pg($value['number']), 'sort_order' => $value['sort_order'], 'description' => $value['description'] ); 
							break;
						case 8: $files['middle'] = array('image_link' => $value['image_link'],'name' => 'middle.'.$value['imagetype']); break;
					}
				}
				$this->TempFillEls = array(
					'subaction' => 'Delete',
					'subprocess' => 'deleting',
					'step' => 'delete',
					'id' => $this->PreparedTemplates['id'],
					'edit_id' => '"'.$this->PreparedTemplates['name'].'" ['.$this->PreparedTemplates['id'].']',
					'is_active' => $this->PreparedTemplates['is_active']? 'Yes' : 'No',
					'export' => $this->PreparedTemplates['export']? 'Yes' : 'No',
					'callforquote' => $this->PreparedTemplates['callforquote']? 'Yes' : 'No',
					'grade_tube' => $this->PreparedTemplates['grade_tube']? 'Yes' : 'No',				
					'root_check' => $this->PreparedTemplates['path2']? ' Yes -> ' : ' No',
					'pid' => $this->PreparedTemplates['pid'],
					'name' => $this->PreparedTemplates['name'],
					'nav_name' => $this->PreparedTemplates['nav_name'],
					'item' => $this->parentitems[$this->PreparedTemplates['item']['id']],
					'path' => $this->PreparedTemplates['path'],
					'path2' => $this->PreparedTemplates['path2'],
					'warranty' => $this->warranty[$this->PreparedTemplates['warranty']['id']],
					'brand' => $this->brand[$this->PreparedTemplates['brand']['id']],
					'rate' => $this->rate[$this->PreparedTemplates['rate']['id']],
					'level' => $this->level[$this->PreparedTemplates['level']['id']],
					'policy' => $this->policy[$this->PreparedTemplates['policy']['id']],
					'core' => $this->core[$this->PreparedTemplates['core']['id']],
					'lens' => $this->lens[$this->PreparedTemplates['lens']['id']],
					'generation' => $this->generation[$this->PreparedTemplates['generation']['id']],
					'short_desc' => $this->PreparedTemplates['short_desc'],
					'special_offer' => $this->PreparedTemplates['special_offer'],
					'full_desc' => $this->PreparedTemplates['full_desc'],
					'video_desc' => $this->PreparedTemplates['video_desc'],				
					'product_class' => $this->PreparedTemplates['product_class'],
					'export_restriction' => !empty($this->PreparedTemplates['export_restriction']['id'])? $this->export[$this->PreparedTemplates['export_restriction']['id']] : ' --- Empty --- ',
					'prew_setting' => 'Jpg, '.$this->upload_settings['prew_width'].'x'.$this->upload_settings['prew_height'],
					'prew_display' => 'inline',
					'middle_image' => !empty($files['middle']['image_link'])? $this->makeImageLink('middle',$files['middle']['image_link']) : makeImage($this->ImagePath.$path.'/'.$files['middle']['name'],$this->ImageWPath.$path.'/'.$files['middle']['name'].'?'.time(),'','',array(),0,'','middleimg'),
					'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					'middle_display' => 'inline',
					'ug_image' => !empty($files['ug'])? (file_exists($this->ImagePath.$path.'/'.$files['ug']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['ug']['name'],makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif',$this->PreparedTemplates['name'].' - User\'s Guide'),array(),'','id=\'ug_icon\'') : '&nbsp;') : '&nbsp;',
					'ss_image' => !empty($files['ss'])? (file_exists($this->ImagePath.$path.'/'.$files['ss']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['ss']['name'],makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif',$this->PreparedTemplates['name'].' - Specification Sheet'),array(),'','id=\'ss_icon\'') : '&nbsp;') : '&nbsp;',
					'hi_image' => !empty($files['hi'])? (file_exists($this->ImagePath.$path.'/'.$files['hi']['name'])? makeLink($this->ImageWPath.$path.'/'.$files['hi']['name'],makeImage($this->ImagePath.'/../registarImg/tif.gif',$this->ImageWPath.'/../registarImg/tif.gif',$this->PreparedTemplates['name'].' - Hi-Res. Image'),array(),'','id=\'hi_icon\'') : '&nbsp;') : '&nbsp;',
					'ug_delete' => !empty($files['ug'])? (file_exists($this->ImagePath.$path.'/'.$files['ug']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'ss_delete' => !empty($files['ss'])? (file_exists($this->ImagePath.$path.'/'.$files['ss']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'hi_delete' => !empty($files['hi'])? (file_exists($this->ImagePath.$path.'/'.$files['hi']['name'])? array(array('id' => $this->PreparedTemplates['id'])) : array()) : array(),
					'param_buttons' => array(),
					'price_buttons' => array(),
					'image_buttons' => array(),
					'3d_buttons' => array(),
					'link_buttons' => array(),
					'feature_buttons' => array(),
					'product_color' => @$this->prod_colors[$this->PreparedTemplates['color']['id']],
				);
				
				//-----   userguides 
				$number_userguide = !empty($files['userguide']) && count($files['userguide']) > 1? count($files['userguide']) : 1;
				for($i = 1; $i <= $number_userguide; $i++) {
					$this->TempFillEls['userguides'][$i] = array(
						'num' => $i,
						'big_userguide' =>  !empty($files['userguide'])? (file_exists($this->ImagePath.$path.'/userguides/'.$files['userguide'][$i]['name'].'.pdf')? makeLink($this->ImageWPath.$path.'/userguides/'.$files['userguide'][$i]['name'].'.pdf',makeImage($this->ImagePath.'/../registarImg/pdf.gif',$this->ImageWPath.'/../registarImg/pdf.gif', ' User\'s Guide'),array(),'','id=\'ug_icon\'') : '&nbsp;') : '&nbsp;',					
						'description'=> $files['userguide'][$i]['description'],
					);
				}
				//-----
								
				$number_image = !empty($files['image']) && count($files['image']) > 1? count($files['image']) : 1;
				for($i = 1; $i <= $number_image; $i++) {
					$this->TempFillEls['images'][$i] = array(
						'num' => $i,
						'big_setting' => 'png, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
						'middle_setting' => 'png, '.$this->upload_settings['middle_width'].'x'.$this->upload_settings['middle_height'],
					'small_setting' => 'jpg, '.$this->upload_settings['small_width'].'x'.$this->upload_settings['small_height'],
						'big_image' => !empty($files['image'][$i][1])? (file_exists($this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '280', '1' => '100' ),'big_image'.$i.'img') : ' --- Empty --- ') : ' --- Empty --- ',
						'middle_image' => !empty($files['image'][$i][2])? (file_exists($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/middle/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '280', '1' => '100' ),'middle_image'.$i.'img') : ' --- Empty --- ') : ' --- Empty --- ',
					'small_image' => !empty($files['image'][$i][2])? (file_exists($this->ImagePath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg')? makeImage($this->ImagePath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg',$this->ImageWPath.$path.'/images/small/'.$files['image'][$i]['name'].'.jpg'.'?'.time(),'','',array(),0, array('0' => '140', '1' => '50' ),'small_image'.$i.'img') : ' --- Empty --- ') : ' --- Empty --- ',
					);
				}
				$number_param = !empty($this->PreparedTemplates['parameters']) && count($this->PreparedTemplates['parameters']) > 10? count($this->PreparedTemplates['parameters']) : 10;
				for($i = 1; $i <= $number_param; $i++) {
					$this->TempFillEls['parameters'][$i] = array(
						'num' => $i,
						'name' => isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['name'] : ' --- Empty --- ',
						'value' => isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['value'] : ' --- Empty --- ',
						'sort_order' => isset($this->PreparedTemplates['parameters'][$i-1])? $this->PreparedTemplates['parameters'][$i-1]['sort_order'] : $i*10,
						'is_front' =>  !empty($this->PreparedTemplates['parameters'][$i-1]['is_front'])? 'Yes' : 'No',
					);
				}
				$number_feature = !empty($this->PreparedTemplates['features']) && count($this->PreparedTemplates['features']) > 3? count($this->PreparedTemplates['features']) : 3;
				for($i = 1; $i <= $number_feature; $i++) {
					$this->TempFillEls['features'][$i] = array(
						'num' => $i,
						'value' => isset($this->PreparedTemplates['features'][$i-1])? $this->PreparedTemplates['features'][$i-1]['value'] : ' --- Empty --- ',
						'sort_order' => isset($this->PreparedTemplates['features'][$i-1])? $this->PreparedTemplates['features'][$i-1]['sort_order'] : $i*10,
					);
				}
				$number_review = !empty($this->PreparedTemplates['reviews']) && count($this->PreparedTemplates['reviews']) > 0? count($this->PreparedTemplates['reviews']) : 0;
				for($i = 1; $i <= $number_review; $i++) {
					$this->TempFillEls['reviews'][$i] = array(
						'num' => $i,
						'url' => isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['url'] : ' --- Empty --- ',
						'image_url' => isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_url'] : ' --- Empty --- ',
						'image_alt' => isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_alt'] : ' --- Empty --- ',
						'image_title' => isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['image_title'] : ' --- Empty --- ',
						'description' => isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['description'] : ' --- Empty --- ',
						'sort_order' => isset($this->PreparedTemplates['reviews'][$i-1])? $this->PreparedTemplates['reviews'][$i-1]['sort_order'] : $i*10,
					);
				}
				$number_cr = !empty($this->PreparedTemplates['customerreviewitems']) && count($this->PreparedTemplates['customerreviewitems']) > 0? count($this->PreparedTemplates['customerreviewitems']) : 0;
				for($i = 1; $i <= $number_cr; $i++) {
					$this->TempFillEls['cr_items'][$i] = array(
						'num' => $i,
						'sort_order' => isset($this->PreparedTemplates['customerreviewitems'][$i-1])? $this->PreparedTemplates['customerreviewitems'][$i-1]['sort_order'] : $i*10,
						'name' => strip_tags($this->customerreviews[$this->PreparedTemplates['customerreviewitems'][$i-1]['object']]),
					);
				}
				$number_price = !empty($this->PreparedTemplates['prices']) && count($this->PreparedTemplates['prices']) > 1? count($this->PreparedTemplates['prices']) : 1;
				for($i = 1; $i <= $number_price; $i++) {
					$this->TempFillEls['prices'][$i] = array(
						'num' => $i,
						'name' => 'Price '.$i,
						'value' => $this->PreparedTemplates['prices'][($i-1)]['value'],
						'current' => $this->PreparedTemplates['prices'][($i-1)]['current']? 'Yes' : 'No',
					);
				}
				//$this->setCollections('recomenduses','recomenduselineitems',true);
				$this->setCollections('related','relatedlineitems',true);
				$this->setCollections('articles','articlelineitems',true);
				$this->setCollections('technologies','technologylineitems',true);
				/*foreach($this->shipcosts as $key => $value) {
					$this->TempFillEls['costs'][$key] = array(
						'value' => $this->getShipCost($this->PreparedTemplates['shipcosts'],$key),
						'name' => $value,
					);
				}*/
				$i = 1;
				foreach($this->accessories as $k => $v) {
					$li = FALSE;
					$checked = 0;
					$forsale = 0;
					foreach($this->PreparedTemplates['productlineitems'] as $key => $value) {
						if($value['lineitem']['id']==$k) {
							$li = TRUE;
							if($value['optional']) $checked = 1;
							if($value['forsale'])  $forsale = 1;
						}
					}
					$this->TempFillEls['accessories'][$k] = array(
						'num' => $i++.'.',
						'name' => ($li? '+ ' : '- ').$this->accessories[$k],
						'type' => $li? ($checked? 'Optional' : 'Included') : '&nbsp;',
						'forsale' => $li? ($forsale? 'For Sale' : '') : '&nbsp;',

						'backcolor' =>  ($checked? 'lightblue' : 'lightgreen'),		//lightgreen included
					);
				}
				$larray = array('1' => 'Scope Applications','2' => 'Featured Retailers');
				$number_link = !empty($this->PreparedTemplates['links']) && count($this->PreparedTemplates['links']) > 3? count($this->PreparedTemplates['links']) : 3;
				for($i = 1; $i <= $number_link; $i++) {
					$this->TempFillEls['links'][$i] = array(
						'name' => !empty($this->PreparedTemplates['links'][$i-1]['description'])? $this->PreparedTemplates['links'][$i-1]['description'] : '&nbsp;',
						'js' => !empty($this->PreparedTemplates['links'][$i-1]['js'])? 'Yes' : 'No',
						'type' => !empty($this->PreparedTemplates['links'][$i-1]['linktype'])? $larray[@$this->PreparedTemplates['links'][$i-1]['linktype']] : '--- Empty ---',
						'link' => !empty($this->PreparedTemplates['links'][$i-1]['link'])? $this->PreparedTemplates['links'][$i-1]['link'] : '&nbsp;',
						'url' => !empty($this->PreparedTemplates['links'][$i-1]['url'])? $this->PreparedTemplates['links'][$i-1]['url'] : '&nbsp;',
						'key' => $i,
					);
				}
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'tree');
				$this->setCategories($this->PreparedTemplates,1,true);
				$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID, 'delete');
			break;
			}
		}
		//$this->TempFillEls['new_param_id_3d'] = $number_3d;
		$this->TempFillEls['new_param_id_image'] = $number_image;
		$this->TempFillEls['new_param_id_userguide'] = $number_userguide;
		
		$this->TempFillEls['new_param_id_param'] = $number_param;
		$this->TempFillEls['new_param_id_price'] = $number_price;
		$this->TempFillEls['new_param_id_link'] = $number_link;
		$this->TempFillEls['new_param_id_feature'] = $number_feature;
		$this->TempFillEls['new_param_id_review'] = $number_review;
		$this->TempFillEls['new_param_id_cr'] = $number_cr;
		!empty($this->PreparedTemplates['_error']) and $this->errors['model'] = $this->PreparedTemplates['_error'];
		if(count($this->errors) > 0) $this->errors['header'] = $this->globalLangContent['error_view']['header_error'];
		foreach($this->errors as $k => $v) $this->TempFillEls[$k.'_error'] = $k=='header'? $this->printError($v).'<p>' : $this->printError($v);
	}

	function setCollections($array,$collection,$del=FALSE) {
		${$array} = array();
		$cols = !empty($this->Request)? @$this->Request['form'][$collection] : @$this->PreparedTemplates[$collection];
		$cols = is_array($cols)? $cols : array();
		foreach($this->{$array} as $key => $value) {
			foreach($cols as $k => $v)
				if($v['lineitem']['id']==$key) {
					${$array}[$key] = $key;
					continue;
				}
		}
		if($del) {
			$result = array();
			foreach(${$array} as $value) $result[] = $this->{$array}[$value];
			$this->TempFillEls[$array] = implode(', ',$result);
		}
		else $this->TempFillEls[$array] = inputSelect('form['.$collection.'][][lineitem][id]',$this->{$array},${$array},'style="width:560px;" multiple="multiple" size=25');
	}

	function setTargetArray($array = array()) {
		uasort($array,'by_category');		
//printArray($array);exit;		
		$btnEdit_vis = $this->server_type == 'dev' ? 'visible' : 'hidden';
		
		$tmp = "";
		$cat = array();
		foreach($array as $value) {
			if ($tmp != $value['category'] ) {
				$cat = array(array('category_name' => $value['category'] ));
				$tmp = $value['category'];
			} else $cat = array();
			
			$locked = empty($value['access_flag']) || $value['access_flag'] == $this->Action->Security->currentuser->id ? false : true;
			$presets_count = explode('/', $value['published_count']);
			$c = count($value['publish']);
			$this->TempFillEls['pages'][$value['id']] = array(
				'id' => $value['id'],
				'name' => $value['name'],
				'category' => $cat, 			
				'path' => $value['path'][0]=='/'?$value['path']:'/'.$value['path'],  //$value['path'],
				'name_color' => $this->colors[($value['unmodified'] > 30 ? 'black' : ($value['unmodified'] > 14 && $value['unmodified'] <= 30 ? 'green' : ($value['unmodified'] > 7 && $value['unmodified'] <= 14 ? 'yellow' : 'red')))],
				'published_count' => $value['published_count'],
				'published_count_cursor' => $c ? 'pointer' : 'auto',
				'published_count_color' => $this->colors[($presets_count[0] >= $presets_count[1] ? 'green' : (empty($presets_count[0]) ? 'red' : 'blue'))],
				'chbAdds_disabled' => $locked ? 'disabled' : '',
				'date_changed' => $value['date_changed'],
				'btnUnlock_vis' => $value['access_flag'] == $this->Action->Security->currentuser->id ? 'visible' : 'hidden',
				'btnEdit_vis' => $btnEdit_vis,
				'chbAdds_vis' => $this->TempFillEls['pubBut'],
				'btnUnlock_disp' => $locked ? 'none' : '',
				'btnEdit_disp' => $locked ? 'none' : '',
				'locked_message_disp' => $locked ? '' : 'none',
				'user_name' => $value['username'],
				'date_locked' => $value['date_locked'],
			);
		}
	}

	function getShipCost($array,$type,$zone) {
		foreach($array as $value) {
			if($value['type']['id']==$type) return $value['value_zone'.$zone];
		}
		return '';
	}
	
	function setCategories($array = array(),$level = 1,$del = FALSE,$levels = array()) {
		$i = 0;
		foreach($array as $value) {
			$levels[$level] = $i==sizeof($array)-1? 1 : 0;
			$this->TempFillEls['pages'][$value['id']] = array(
				'id' => $value['id'],
				'ownerid' => $value['ownerid'],
				'name' => $value['name'],
				'input' => !empty($value['subcat'])? '&nbsp;' : ($del? (in_array($value['id'],$this->categories)? '<b>+</b>' : '&nbsp;') : inputCheckbox('form[categorylineitems]['.$value['id'].'][id]',(!empty($this->Request)? @$this->Request['form']['categorylineitems'][$value['id']]['id'] : (in_array($value['id'],$this->categories)? 1 : 0)),' class=check',$value['id'])),
				'width' => intval($level*25),
				'width2' => 790 - intval($level*25),
				'start_div' => '<div id=page'.$value['id'].(!empty($value['subcat'])? ' style="display: none;"' : '').'>',
				'minus' => !empty($value['subcat'])? '_minus' : '',
			);
			if(!empty($value['subcat'])) {
				$this->TempFillEls['pages'][$value['id']]['header'] = array(array(
					'id' => $value['id'],
					'ownerid' => $value['ownerid'],
					'name' => $value['name'],
					'input' => !empty($value['subcat'])? '&nbsp;' : ($del? (in_array($value['id'],$this->categories)? '<b>+</b>' : '&nbsp;') : inputCheckbox('form[categorylineitems]['.$value['id'].'][id]',(!empty($this->Request)? @$this->Request['form']['categorylineitems'][$value['id']]['id'] : (in_array($value['id'],$this->categories)? 1 : 0)),' class=check',$value['id'])),
					'width' => intval($level*25),
					'width2' => 790 - intval($level*25),
				));
				$this->TempFillEls['pages'][$value['id']]['onclick'] = array(array('id' => $value['id']));
				$this->setCategories($value['subcat'],$level+1,$del,$levels);
			}
			else {
				if($level==1) $this->TempFillEls['pages'][$value['id']]['end_div'] = '</div>';
				//else $this->TempFillEls['pages'][$value['id']]['end_div'] = !empty($levels[$level])? (!empty($levels[$level-1])? (!empty($levels[$level-2])? (!empty($levels[$level-3])? str_repeat('</div>',4) : str_repeat('</div>',3)) : str_repeat('</div>',3)) : str_repeat('</div>',2)) : '</div>';
				else $this->TempFillEls['pages'][$value['id']]['end_div'] = !empty($levels[$level])? (!empty($levels[$level-1])? (!empty($levels[$level-2])? str_repeat('</div>',4) : str_repeat('</div>',3)) : str_repeat('</div>',2)) : '</div>';
			}
			$i++;
		}
	}
	
	
	
	
	
	function getCategoryPath($id, $p = ''){
		global $Paths;
		$selected = $this->Db->SelectAny('SELECT path2 FROM category where id='.$id);
		if(empty($selected[0]['path2'])) {
			if(empty($Paths)) {
				$selected = $this->Db->SelectAny('SELECT id, sys_name, ownerid, path2 FROM category');
				foreach($selected as $value)
					$Paths[$value['id']] = array(
						'path' => $value['sys_name'],
						'parent' => $value['ownerid'],
						'path2' => $value['path2'],
					);
			}
			while(1){
				if(empty($Paths[$id])) return null;
				//if(empty($Paths[$id]['parent'])) { return '/'.$Paths[$id]['path'].$p;     }
				if(empty($Paths[$id]['parent']))   { return $p;     }
				if(!empty($Paths[$id]['path2'])) { return '/'.$Paths[$id]['path2'].$p;    }
				$p = '/'.$Paths[$id]['path'].$p;
				$id = $Paths[$id]['parent'];
			}
		}	else return '/'.$selected[0]['path2'];
	}
	
	
	
	

	function getCategory($id) {
		global $REGISTRY;
		foreach($REGISTRY['VirtualSlotTarget']['main'] as $k => $v) 
			if( $v  == 'ProductView:object?id='.$id ){
				$this->productURL = $k;
				break;
			}
			if (!isset($this->productURL)) return "";
        $urlparts = explode('/', $this->productURL);
        array_pop($urlparts);
        $this->categoryURL = implode($urlparts, '/'); 
        foreach($REGISTRY['VirtualSlotTarget']['main'] as $k => $v)  if( equals($k, $this->categoryURL)){ $value = $v;break;}
        $query = explode('?',$value);
        $target = explode(':',array_shift($query));
        $properties = array_shift($query);
        $pair = explode('=',$properties);
        $name = array_shift($target);
        return $pair[1];

	}
	
}
?>