<?php

class ReviewsAdminView extends Slot {

	var $SectionID = 54;
	var $ModuleID = 2;
	var $reqfield = '<img src="/i/must.gif">&nbsp;';
	var $upload_formats = array(
		'image/jpeg' => 'jpg',
		'image/pjpeg' => 'jpg',
		'image/gif' => 'gif',
		'image/png' => 'gif',
	);
	var $upload_formats_check = array(
		'image/jpeg',
		'image/pjpeg',
		'image/gif',
		'image/png',
	);
	var $upload_settings = array(
		'prew_width' => '',
		'prew_height' => '',
		'big_width' => '118',
		'big_height' => '87',
		'middle_width' => '',
		'middle_height' => '',
		'small_width' => '',
		'small_height' => '',
		'3d_width' => '',
		'3d_height' => '',
		'image_width' => '',
		'image_height' => '',
	);
	

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

	function init() { 
		switch(@$this->LocalTarget[0]) {
			case 'Edit': case 'Delete':
				if(!empty($this->LocalTarget[1]) && validate(intval($this->LocalTarget[1]))) {
					$this->Action->processEvent($this->SectionID,'open_review',array('id' => $this->LocalTarget[1]),$this);
					if(!empty($this->PreparedTemplates['_error'])) header("Location: ".$this->Home.'/Registar/ReviewsAdmin'.$this->SID);
					else $this->Scheme = 'action';
				}
				else header("Location: ".$this->Home.'/Registar/ReviewsAdmin'.$this->SID);
			break;
			case 'Add': $this->Scheme = 'action'; break;
			default:                
				$request = array('conditions' => array(),'pageRecordsQty' => '20', 'sortColumn'=>'date' , 'sortType' =>'DESC');
				$request['curPageNumber'] = empty($this->LocalTarget[0]) || !validate(intval($this->LocalTarget[0]))? 1 : intval($this->LocalTarget[0]+1);
				$this->Action->processEvent($this->SectionID,'select_reviews',$request,$this);
				$this->getPageControl($this->Home.'/Registar/ReviewsAdmin');
			break;
		}
		if(!empty($this->Request)) {
			switch($this->getRequestField('step')) {
				case 'Add': case 'Edit':
					$this->validateForm()
					and $this->Action->processEvent($this->SectionID,'save_review',$this->getRequestField('form'),$this)
					and header("Location: ".$this->Home.'/Registar/ReviewsAdmin'.$this->SID);
				break;
				case 'unlock':
	 					header("Location: ".$this->Home.'/Registar/ReviewsAdmin'.$this->SID);
				break;				
				case 'Delete':
					$this->validateForm()
					and $this->Action->processEvent($this->SectionID,'delete_review',$this->getRequestField('form'),$this)
					and header("Location: ".$this->Home.'/Registar/ReviewsAdmin'.$this->SID);
				break;
			}
		}
		$this->setSchemeTemplate($this->Scheme);
	}

	function saveFiles($array) { //printArray($array);exit;
		$path = $this->ImagePath.'/reviews/'.$array['id'];
		if($this->getRequestField('step')=='add' || !file_exists($path)) {
			umask(0002); mkdir($path,0775);
		}
		
		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(!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);
			}
		}
		
		$this->saveImages($array,$path,'images/big','image_big',3,'jpg');
	}
	
	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 validateForm() {
		switch($this->getRequestField('step')) {
			case 'Add': case 'Edit':
				if(!is_AlphaNumDefis(stripslashes($this->Request['form']['url_name']),1,1024)) $this->errors['url_name'] = 'The review URL name is not valid (do not use slashes)';
					else $this->Request['form']['url_name']  = strtolower($this->Request['form']['url_name']);				
				if(!is_FullText(stripslashes($this->Request['form']['story_langs']['0']['title']),4,255)) $this->errors['title'] = 'The review title you entered is not a valid string';
				$this->Request['form']['sort_order'] = (int)$this->Request['form']['sort_order'];
				
				$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]);
									$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;
						}
					}
					else if(isset($this->Request['image_big']['name'][$i])) {
						$this->Request['form']['image'][$i]['_number'] = $i;
					}
				}
		
				
				// big image			
				$image = $this->getRequestField('image');
				if(!empty($image['name'])) {
					if(!$image['size']) $this->errors['image'] = 'Error uploading - image is empty';
						else {
								$size = GetImageSize($image['tmp_name']);
								if($size['0'] > $this->upload_settings['big_width']) $this->errors['big_image'] = 'Error uploading - width of image is not valid';
									else if($size['1'] > $this->upload_settings['big_height']) $this->errors['big_image'] = 'Error uploading - height of image is not valid';
										//else if($size['mime'] != 'image/jpg' && $size['mime'] != 'image/pjpeg' && $size['mime'] != 'image/jpeg') $this->errors['big_image'] = 'Error uploading - type of image is not valid';
										  else if (!in_array($size['mime'], $this->upload_formats_check)) $this->errors['big_image'] = 'Error uploading - type of image is not valid';
												else {
													$this->Request['form']['big']['image_type'] = $this->upload_formats[$size['mime']];
													$this->Request['form']['big']['_tmp_name'] = $image['tmp_name'];
												}
						}
				}			
				
			break;
		}
		if(count($this->errors) > 0) return FALSE;
		return TRUE;
	}

	function fillElements() {
		switch($this->Scheme) {
			case 'default': $this->fillList(); break;
			case 'action': $this->fillAction(); break;
		}
	}

	
	function fillList() { 
			foreach($this->PreparedTemplates['curPage'] as $key => $value) {
				$date = new DateTime($value['date']); 
				$HeaderDate = $date->format('F j, Y'); 
				$this->TempFillEls['reviews'][] = array(
					'title' => $value['story_langs']['0']['title'],
					'description' => $value['story_langs']['0']['short_text'],
					'id' => $value['id'],
					'date' => $HeaderDate,
					'sort_order' => $value['sort_order'],
				);
			}
	}

	function fillAction() {
		global $PHP_SELF;
		switch($this->LocalTarget[0]) {
			case 'Add': {
					$this->TempFillEls['reqfield'] = $this->reqfield;
					$this->TempFillEls['sub_action'] = 'Add';
					$this->TempFillEls['id'] = '';
					$this->TempFillEls['title'] = inputTextArea('form[story_langs][0][title]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['title']) : ''),$this->correctSize('65'),2);
					$this->TempFillEls['short_desc'] = inputTextArea('form[story_langs][0][short_text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['short_text']) : ''),$this->correctSize('65'),6);
					$this->TempFillEls['full_desc'] = inputTextArea('form[story_langs][0][text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['text']) : ''),$this->correctSize('65'),18);
					$this->TempFillEls['sort_order'] = inputText('form[sort_order]',(!empty($this->Request)? stripslashes($this->Request['form']['sort_order']) : ''),$this->correctSize('10'));		
					$this->TempFillEls['full_desc_name'] = 'form[story_langs][0][text]';
					$this->TempFillEls['image'] = inputFile('image');
					$this->TempFillEls['url_name'] = inputText('form[url_name]',(!empty($this->Request)? stripslashes($this->Request['form']['url_name']) : ''),$this->correctSize('65'));																																																		  //2010-12-17 13:56:31
					$this->TempFillEls['date'] =  inputText('form[date]',     !empty($this->Request['form']['date'])?    $this->Request['form']['date']  :   date ('Y-m-d')   , 19, '" style="width: 130px;" readonly', 19);
					$this->TempFillEls['image_buttons'] = array(array());
					if(!empty($this->PreparedTemplates)) {
						$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
						$this->TempFillEls['title'] = inputTextArea('form[story_langs][0][title]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['title']) : $this->PreparedTemplates['story_langs']['0']['title']),$this->correctSize('65'),2);
						$this->TempFillEls['short_desc'] =inputTextArea('form[story_langs][0][short_text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['short_text']) : $this->PreparedTemplates['story_langs']['0']['short_text']),$this->correctSize('65'),6);
						$this->TempFillEls['full_desc'] =inputTextArea('form[story_langs][0][text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['text']) : $this->PreparedTemplates['story_langs']['0']['text']),$this->correctSize('65'),18);
						$this->TempFillEls['sort_order'] =inputText('form[sort_order]',(!empty($this->Request)? stripslashes($this->Request['form']['sort_order']) : ucwords($this->PreparedTemplates['sort_order'])),$this->correctSize('10'));			
						$this->TempFillEls['picture'] = makeImage($this->ImagePath.'/1.gif',$this->ImageWPath.'/1.gif','','',array(),0,'','bigimg');
						$this->TempFillEls['url_name'] = inputText('form[url_name]',(!empty($this->Request)? stripslashes($this->Request['form']['url_name']) : ucwords($this->PreparedTemplates['url_name'])),$this->correctSize('65'));			
						$this->TempFillEls['date'] =  inputText('form[date]',     !empty($this->PreparedTemplates['date'])?    $this->PreparedTemplates['date']  :   date ('Y-m-d')   , 19, '" style="width: 130px;" readonly', 19);
					}
					$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' => 'Jpg, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
							//'middle_setting' => 'jpg, '.$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.']'),
							//'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)),
						);
					}
			break;
			}
			case 'Edit': {
					$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open_review');
					$path = '/reviews/'.$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 8: $files['middle'] = array('image_link' => $value['image_link'],'name' => 'middle.'.$value['imagetype']); break;
						}
					}
					$this->TempFillEls['reqfield'] = $this->reqfield;
					$this->TempFillEls['sub_action'] = 'Update';
					$this->TempFillEls['id'] = '';
					$this->TempFillEls['title'] = inputTextArea('form[story_langs][0][title]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['title']) : ''),$this->correctSize('65'),2);
					$this->TempFillEls['short_desc'] = inputTextArea('form[story_langs][0][short_text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['short_text']) : ''),$this->correctSize('65'),6);
					$this->TempFillEls['full_desc'] = inputTextArea('form[story_langs][0][text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['text']) : ''),$this->correctSize('65'),18);
					$this->TempFillEls['sort_order'] = inputText('form[sort_order]',(!empty($this->Request)? stripslashes($this->Request['form']['sort_order']) : ''),$this->correctSize('10'));		
					$this->TempFillEls['full_desc_name'] = 'form[story_langs][0][text]';
					$this->TempFillEls['image'] = inputFile('image');
					$this->TempFillEls['url_name'] = inputText('form[url_name]',(!empty($this->Request)? stripslashes($this->Request['form']['url_name']) : ''),$this->correctSize('65'));																																																		  //2010-12-17 13:56:31
					$this->TempFillEls['date'] =  inputText('form[date]',     !empty($this->Request['form']['date'])?    $this->Request['form']['date']  :   date ('Y-m-d')   , 19, '" style="width: 130px;" readonly', 19);
					$this->TempFillEls['image_buttons'] = array(array());
					if(!empty($this->PreparedTemplates)) {
						$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
						$this->TempFillEls['title'] = inputTextArea('form[story_langs][0][title]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['title']) : $this->PreparedTemplates['story_langs']['0']['title']),$this->correctSize('65'),2);
						$this->TempFillEls['short_desc'] =inputTextArea('form[story_langs][0][short_text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['short_text']) : $this->PreparedTemplates['story_langs']['0']['short_text']),$this->correctSize('65'),6);
						$this->TempFillEls['full_desc'] =inputTextArea('form[story_langs][0][text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['text']) : $this->PreparedTemplates['story_langs']['0']['text']),$this->correctSize('65'),18);
						$this->TempFillEls['sort_order'] =inputText('form[sort_order]',(!empty($this->Request)? stripslashes($this->Request['form']['sort_order']) : ucwords($this->PreparedTemplates['sort_order'])),$this->correctSize('10'));			
						$this->TempFillEls['picture'] = makeImage($this->ImagePath.$path.'/big.jpg',$this->ImageWPath.$path.'/big.jpg'.'?'.time());
						$this->TempFillEls['url_name'] = inputText('form[url_name]',(!empty($this->Request)? stripslashes($this->Request['form']['url_name']) : ucwords($this->PreparedTemplates['url_name'])),$this->correctSize('65'));			
						$this->TempFillEls['date'] =  inputText('form[date]',     !empty($this->PreparedTemplates['date'])?    $this->PreparedTemplates['date']  :   date ('Y-m-d')   , 19, '" style="width: 130px;" readonly', 19);
					}
					$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++) {
//print $this->ImagePath.$path.'/images/big/'.$files['image'][$i]['name'].'.jpg                        ';						
						$this->TempFillEls['images'][$i] = array(
							'num' => $i,
							'big_setting' => 'Jpg, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
//							'middle_setting' => 'jpg, '.$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.']'),
				//		'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)),
						);
					}
			break;
			}
			case 'Delete': {
					$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'open_review');
					$path = '/reviews/'.$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 8: $files['middle'] = array('image_link' => $value['image_link'],'name' => 'middle.'.$value['imagetype']); break;
						}
					}
					$this->TempFillEls['reqfield'] = $this->reqfield;
					$this->TempFillEls['sub_action'] = 'Delete';
					$this->TempFillEls['id'] = '';
					$this->TempFillEls['title'] = inputTextArea('form[story_langs][0][title]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['title']) : ''),$this->correctSize('65'),2);
					$this->TempFillEls['short_desc'] = inputTextArea('form[story_langs][0][short_text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['short_text']) : ''),$this->correctSize('65'),6);
					$this->TempFillEls['full_desc'] = inputTextArea('form[story_langs][0][text]',(!empty($this->Request)? stripslashes($this->Request['form']['story_langs']['0']['text']) : ''),$this->correctSize('65'),18);
					$this->TempFillEls['sort_order'] = inputText('form[sort_order]',(!empty($this->Request)? stripslashes($this->Request['form']['sort_order']) : ''),$this->correctSize('10'));		
					$this->TempFillEls['full_desc_name'] = 'form[story_langs][0][text]';
					$this->TempFillEls['image'] = '---';
					$this->TempFillEls['url_name'] = inputText('form[url_name]',(!empty($this->Request)? stripslashes($this->Request['form']['url_name']) : ''),$this->correctSize('65'));																																																		  //2010-12-17 13:56:31
					$this->TempFillEls['date'] =  inputText('form[date]',     !empty($this->Request['form']['date'])?    $this->Request['form']['date']  :   date ('Y-m-d')   , 19, '" style="width: 130px;" readonly', 19);
					$this->TempFillEls['image_buttons'] = array();
					if(!empty($this->PreparedTemplates)) {
						$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
						$this->TempFillEls['title'] = $this->PreparedTemplates['story_langs']['0']['title'];
						$this->TempFillEls['short_desc'] = $this->PreparedTemplates['story_langs']['0']['short_text'];
						$this->TempFillEls['full_desc'] = $this->PreparedTemplates['story_langs']['0']['text'];
						$this->TempFillEls['sort_order'] = ucwords($this->PreparedTemplates['sort_order']);			
						$this->TempFillEls['picture'] = makeImage($this->ImagePath.$path.'/big.jpg',$this->ImageWPath.$path.'/big.jpg'.'?'.time());
						$this->TempFillEls['url_name'] = ucwords($this->PreparedTemplates['url_name']);			
						$this->TempFillEls['date'] =  inputText('form[date]',     !empty($this->PreparedTemplates['date'])?    $this->PreparedTemplates['date']  :   date ('Y-m-d')   , 19, '" style="width: 130px;" readonly', 19);
					}
					$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' => 'Jpg, '.$this->upload_settings['big_width'].'x'.$this->upload_settings['big_height'],
//							'middle_setting' => 'jpg, '.$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,'','big_image'.$i.'img') : ' --- Empty --- ') : ' --- Empty --- ',
							//'middle_image' => !empty($files['image'][$i][2])? (file_exists($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.png')? makeImage($this->ImagePath.$path.'/images/middle/'.$files['image'][$i]['name'].'.png',$this->ImageWPath.$path.'/images/middle/'.$files['image'][$i]['name'].'.png'.'?'.time(),'','',array(),0,'','middle_image'.$i.'img') : ' --- Empty --- ') : ' --- Empty --- ',
							//'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 --- ',
						);
					}
			break;
			}
		}
		$this->TempFillEls['new_param_id_image'] = $number_image;
		$this->TempFillEls['action'] = $this->LocalTarget[0];
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'save_news');
		!empty($this->PreparedTemplates['_error']) and $this->errors['model'] = $this->globalLangContent['error_model'][$this->PreparedTemplates['_error']];
		if(count($this->errors) > 0) $this->errors['header'] = 'There were some errors.<br>Please see below for details.';
		foreach($this->errors as $k => $v) $this->TempFillEls[$k.'_error'] = $k=='header'? '<strong>'.$v.'</strong><p>' : $this->printError($v);
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'save_news');
		
	}

	
	
	
}
?>