<?php

class AdminController extends Zend_Controller_Action {

	public function init() {}	
	
	
	public function indexAction() {	

		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth == true ){
			$this->_helper->redirector('panel','admin');
		}		
		
		$v = $this->_request->getParams();
		
		if( $information->changePasswordSuccess ){
			$this->view->changePasswordSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->successLogout ){
			$this->view->successLogout = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->errorLogin ){
			$this->view->errorLogin = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->errorLoginBlock ){
			$this->view->errorLoginBlock = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( isset($v['admin_login']) && isset($v['admin_pass']) ){
			// logowanie
			$Admin = new Admin();
			$select = $Admin->select();		
			$select->where('admin_login = ?', $v['admin_login']);	
			$select->where('admin_pass = ?', hash('sha256',$v['admin_pass']));			
			$select->where('admin_lock = ?', 0);			
			$row = $Admin->fetchRow($select);
			
			if( isset($row) ){
				// zalogowany
				if( $row['admin_lock'] == 1 ){
					$information->errorLoginBlock = true;
				}else{
				
					$HistoryLog = new HistoryLog();
					$data = array(
						'admin_id'      => $row['admin_id'],
						'history_log_date' => date("Y-m-d H:i:s"),
						'history_log_ip'      => Zend_Registry::get('users_ip'),
						'history_log_host'      => Zend_Registry::get('users_host')
					);
					$HistoryLog->insert($data);	
					
					$admin->admin_id = $row['admin_id'];
					$admin->admin_auth = true;
					$information->successLogin = true; 
				}
			}else{
				// blad logowania				
				$information->errorLogin = true; 
			}
			
			$this->_helper->redirector('panel','admin');			
		}
	
	}
	
	public function logoutAction() {
		Zend_Session::namespaceUnset('admin');	
		$information = new Zend_Session_Namespace('information');	
		$information->successLogout = true; 
		$this->_helper->redirector('index','admin');	
	}
	
	public function panelAction() {

		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->successLogin ){
			$this->view->successLogin = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->logoutClientSuccess ){
			$this->view->logoutClientSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
	}
	
	
	
	public function historyAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$v = $this->_request->getParams();
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$HistoryLog = new HistoryLog();	
		$dataCount = count($HistoryLog->fetchAll('admin_id = '.$admin->admin_id , 'history_log_date DESC')); 
			$p = ($page-1)*$limit;		
		$data = $HistoryLog->fetchAll('admin_id = '.$admin->admin_id , 'history_log_date DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('history');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
	}
	
	
	public function infoAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->errorOldPassword ){
			$this->view->errorOldPassword = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $information->errorPassword ){
			$this->view->errorPassword = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();	
		
		$Admin = new Admin();		
		
		if( isset($v['admin_changepass']) ){
			// zmiana has�a			
			$err = 0;			
			
			/* sprawdzanie czy hasla sa identyczne */	
			if( $v['admin_pass_new'] != $v['admin_pass'] ){
				$err++;
				$information->errorPassword = true; 
				$this->_helper->redirector('info','admin');
			}
			/* sprawdzanie czy hasla sa identyczne - koniec */			
			
			$select = $Admin->select();		
			$select->where('admin_id = ?', $admin->admin_id);	
			$select->where('admin_pass = ?', hash('sha256',$v['admin_pass_old']));					
			$row = $Admin->fetchRow($select);
			
			
			if( !isset($row) ){
				$err++;
				$information->errorOldPassword = true; 
				$this->_helper->redirector('info','admin');
			}
			
			if( $err == 0 ){				
				$data = array(
					'admin_pass' => hash('sha256',$v['admin_pass']),
					'admin_edit' => Lib_Date::datetime(),
					'admin_changepass' => Lib_Date::datetime()
				);
				$Admin->update( $data , 'admin_id='.$admin->admin_id );
				$information->changePasswordSuccess = true; 
				$this->_helper->redirector('logout','admin');		
			}
		}		
		
		$select = $Admin->select();		
		$select->where('admin_id = ?', $admin->admin_id);	
		$row = $Admin->fetchRow($select);
		
		$this->view->accountAdmin = $row;
	}
	
	
	public function usersAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$v = $this->_request->getParams();
		
		
		if( $information->addUserSuccess ){
			$this->view->addUserSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Admin = new Admin();	
		$dataCount = count($Admin->fetchAll(null , 'admin_ins DESC')); 
			$p = ($page-1)*$limit;		
		$data = $Admin->fetchAll(null , 'admin_ins DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('users');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;			
		
	}
	
	
	public function usersaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Admin = new Admin();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_adduser']) ){
		
			$data = array(
				'admin_login' => $v['admin_login'],
				'admin_pass' => hash('sha256',$v['admin_pass']),
				'admin_firstname' => $v['admin_firstname'],
				'admin_secondname' => $v['admin_secondname'],
				'admin_email' => $v['admin_email'],
				'admin_ins' => Lib_Date::datetime(),
				'admin_edit' => Lib_Date::datetime(),
				'admin_changepass' => Lib_Date::datetime()
			);
			$idIns = $Admin->insert($data);
			
			$information->addUserSuccess = true; 
			$this->_helper->redirector('users','admin');		
			
		}		

	}
	
	
	public function checkloginAction() {
		header("Content-Type:text/plain");
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$valid = 0;
		// $valid = 0 - nie istnieje w bazie
		// $valid = 1 - istnieje w bazie
		
		$Admin = new Admin();	
		$select = $Admin->select();		
		$select->where('admin_login = ?', $v['admin_login']);					
		$row = $Admin->fetchRow($select);
		unset($Admin);		

		if( isset($row) ) $valid = 1;
		else $valid = 0;
			
		echo $valid;
	}
	
	public function usersremoveAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$Admin = new Admin();
		$where = array(
			'admin_id = ?' => $v['id'],
			'admin_noedit = ?' => 0
		);
		$Admin->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('users','admin');		
	}
	
	public function userseditAction() {	
		$v = $this->_request->getParams();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$Admin = new Admin();			
		
		
		
		if( $information->editUserChangeStatus ){
			$this->view->editUserChangeStatus = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->editUserChangePass ){
			$this->view->editUserChangePass = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->editUserSuccess ){
			$this->view->editUserSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		if( isset($v['admin_changestatususer']) ){
			$data = array(
				'admin_lock' => $v['admin_lock'],
				'admin_edit' => Lib_Date::datetime()
			);
			$Admin->update( $data , 'admin_id='.$v['id'].' AND admin_noedit = 0' );
			$information->editUserChangeStatus = true; 
			$this->_helper->redirector('usersedit','admin',null,array('id' => $v['id']));
		}
		
		
		
		if( isset($v['admin_resetpassuser']) ){
			$data = array(
				'admin_pass' => hash('sha256',$v['admin_pass']),
				'admin_edit' => Lib_Date::datetime(),
				'admin_changepass' => Lib_Date::datetime()
			);
			$Admin->update( $data , 'admin_id='.$v['id'].' AND admin_noedit = 0' );
			$information->editUserChangePass = true; 
			$this->_helper->redirector('usersedit','admin',null,array('id' => $v['id']));
		}
		
		
		if( isset($v['admin_edituser']) ){		
			$data = array(
				'admin_firstname' => $v['admin_firstname'],
				'admin_secondname' => $v['admin_secondname'],
				'admin_email' => $v['admin_email'],
				'admin_edit' => Lib_Date::datetime()
			);
			$Admin->update( $data , 'admin_id='.$v['id'].' AND admin_noedit = 0' );
						
			$information->editUserSuccess = true; 
			$this->_helper->redirector('usersedit','admin',null,array('id' => $v['id']));			
		}		
		
		
		
		$select = $Admin->select();
		$select->where('admin_id = ?', $v['id']);	
		$row = $Admin->fetchRow($select);
		$this->view->userData = $row;				
	}

	
	
	public function usershistoryAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$v = $this->_request->getParams();
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$HistoryLog = new HistoryLog();	
		$dataCount = count($HistoryLog->fetchAll('admin_id = '.$v['id'] , 'history_log_date DESC')); 
			$p = ($page-1)*$limit;		
		$data = $HistoryLog->fetchAll('admin_id = '.$v['id'] , 'history_log_date DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('usershistory');
		$Lib_Page->setPrefix('page');
		$Lib_Page->setGet('/id/'.$v['id']);
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
		$Admin = new Admin();
		$select = $Admin->select();
		$select->where('admin_id = ?', $v['id']);	
		$row = $Admin->fetchRow($select);
		$this->view->userData = $row;
		
	}

	
	
	public function clienthistoryAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$v = $this->_request->getParams();
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$HistoryClientLog = new HistoryClientLog();	
		$dataCount = count($HistoryClientLog->fetchAll('client_id = '.$v['id'] , 'history_client_log_date DESC')); 
			$p = ($page-1)*$limit;		
		$data = $HistoryClientLog->fetchAll('client_id = '.$v['id'] , 'history_client_log_date DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('clienthistory');
		$Lib_Page->setPrefix('page');
		$Lib_Page->setGet('/id/'.$v['id']);
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
		$Client = new Client();
		$select = $Client->select();
		$select->where('client_id = ?', $v['id']);	
		$row = $Client->fetchRow($select);
		$this->view->userData = $row;
		
	}
	
	public function categoryAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 25;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Category = new Category();	
		$dataCount = count($Category->fetchAll(null , 'category_name ASC')); 
			$p = ($page-1)*$limit;		
		$data = $Category->fetchAll(null , 'category_name ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('category');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	
	public function categoryaddparentAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Category = new Category();		
		$v = $this->_request->getPost();

		$where = '';
		if( isset($v['category_edit_id']) ){
			$where = 'category_id != '.$v['category_edit_id'].' AND ';
			$this->view->category_edit_id = $v['category_edit_id'];
		}
		
		$data = $Category->fetchAll($where.' category_type = '.$v['category_type'].' AND category_parent_id = '.$v['category_id'], " category_name ASC ");
		$this->view->dataCategory = $data;
		$this->view->idCategory = $v['category_id'];
		$this->view->category_type = $v['category_type'];
	}
	
	public function categoryaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Category = new Category();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addcategory']) ){
		
			$data = array(
				'category_name' => htmlspecialchars($v['category_name']),
				'category_type' => $v['category_type'],
				'category_image' => isset($v['category_image'])?$v['category_image']:'',
				'category_parent_id' => $v['category_parent_id'],
				'category_ins' => Lib_Date::datetime()
			);
			$idIns = $Category->insert($data);
			
			$information->addCategorySuccess = true; 
			$this->_helper->redirector('categoryedit','admin',null,array('id' => $idIns));	
			
		}		
	}
	
	public function categoryeditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->addCategorySuccess ){
			$this->view->addCategorySuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $information->editCategorySuccess ){
			$this->view->editCategorySuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$Category = new Category();		
		
		$v = $this->_request->getParams();
		
		if( isset($v['admin_editcategory']) ){
			$data = array(
				'category_name' => htmlspecialchars($v['category_name']),
				'category_mt_title' => htmlspecialchars($v['category_mt_title']),
				'category_mt_description' => htmlspecialchars($v['category_mt_description']),
				'category_mt_keywords' => htmlspecialchars($v['category_mt_keywords']),
				'category_image' => isset($v['category_image'])?$v['category_image']:'',
				'category_parent_id' => $v['category_parent_id'],
				'category_edit' => Lib_Date::datetime()
			);
			$Category->update( $data , 'category_id='.$v['id'] );
			
			foreach( $v['category_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".htmlspecialchars($value)."' WHERE language_variable LIKE 'category_name_".$v['id']."' AND language_panel LIKE 'category' ";

				$db->query($zap);
			
			}
			
			foreach( $v['category_desc_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".htmlspecialchars($value)."' WHERE language_variable LIKE 'category_desc_".$v['id']."' AND language_panel LIKE 'category' ";

				$db->query($zap);
			
			}
						
			$information->editCategorySuccess = true; 
			$this->_helper->redirector('categoryedit','admin',null,array('id' => $v['id']));	

		}		
		
		$select = $Category->select();		
		$select->where('category_id = ?', $v['id']);	
		$row = $Category->fetchRow($select);
		
		$this->view->rowCategory = $row;
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'category_name_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('category', 'category_name_".$v['id']."', '".$row->category_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'category_name_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'category_desc_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('category', 'category_desc_".$v['id']."', '".$row->category_desc."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'category_name_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}			
			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function categoryaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/category/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_category'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function categoryphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/category/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	public function categoryremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('category','admin');
		}			
		
		$Category = new Category();
		
		$select = $Category->select();		
		$select->where('category_id = ?', $v['id']);	
		$row = $Category->fetchRow($select);
		
		$Lib_Category = new Lib_Category();
		$dataCategoryParent = $Lib_Category->parentListD($v['id'], $row->category_type);
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		foreach($dataCategoryParent as $k => $val){		
		//	 echo$val['category_name'].'<br />';
			
			$where = array(
				'category_id = ?' => $val['category_id']
			);
			$Category->delete($where);
	
			// usuwanie tlumaczen
			foreach( $dataLang as $k1 => $val1 ){
				$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'category_name_".$val['category_id']."' LIMIT 1";
				$db->query($zap);
			}
		}
		
		$where = array(
			'category_id = ?' => $v['id']
		);
		$Category->delete($where);
		foreach( $dataLang as $k1 => $val1 ){
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'category_name_".$v['id']."' LIMIT 1";
			$db->query($zap);	
		}		
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('category','admin');		
	}
	
	public function productAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 100;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Product = new Product();	
		$dataCount = count($Product->fetchAll('product_shop = 0' , 'product_name ASC')); 
			$p = ($page-1)*$limit;		
		$data = $Product->fetchAll('product_shop = 0' , 'product_name ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('product');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	public function productaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Product = new Product();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addproduct']) ){
		
			$data = array(
				'product_name' => $v['product_name'],
				'product_code' => $v['product_code'],
				'product_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_image_1' => isset($v['product_image_1'])?$v['product_image_1']:'',
				'product_image_2' => isset($v['product_image_2'])?$v['product_image_2']:'',
				'product_image_3' => isset($v['product_image_3'])?$v['product_image_3']:'',
				'product_image_4' => isset($v['product_image_4'])?$v['product_image_4']:'',
				'product_image_5' => isset($v['product_image_5'])?$v['product_image_5']:'',
				'product_image_6' => isset($v['product_image_6'])?$v['product_image_6']:'',
				'product_image_7' => isset($v['product_image_7'])?$v['product_image_7']:'',
				'product_image_8' => isset($v['product_image_8'])?$v['product_image_8']:'',
				'category_id' => $v['category_id0'],
				'category_id1' => $v['category_id1'],
			//	'category_id2' => $v['category_id2'],
				'product_ins' => Lib_Date::datetime()
			);
			$idIns = $Product->insert($data);
			
			$information->addProductSuccess = true; 
			$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
	}
	
	public function productaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/product/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function productaddphotooptionAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/options/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		$this->view->opt = $v['opt']; 
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function productaddphoto2Action() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getParams();	
	
		$upload_path_img = "public/uploads/product/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000).$v['num']);
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product_'.$v['num']];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
		
		$this->view->num = $v['num'];  
	}
	
	public function productaddphotosizeAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/size/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product_'.$v['type']];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		$this->view->type = $v['type'];  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	
	public function productaddcategoryAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Category = new Category();		
		$v = $this->_request->getPost();

		$where = '';
		
		$data = $Category->fetchAll($where.' category_type = '.$v['category_type'].' AND category_parent_id = '.$v['category_id'], " category_name ASC ");
		$this->view->dataCategory = $data;
		$this->view->idCategory = $v['category_id'];
		$this->view->category_type = $v['category_type'];
	}
	
	public function productremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$Product = new Product();
		$where = array(
			'product_id = ?' => $v['id']
		);
		$Product->delete($where);			
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		foreach( $dataLang as $k1 => $val1 ){
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'product_name_".$v['id']."' LIMIT 1";
			$db->query($zap);	
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'product_description_".$v['id']."' LIMIT 1";
			$db->query($zap);	
		}	
		
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('product','admin');		
	}
	
	public function producteditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->addProductSuccess ){
			$this->view->addProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $information->editProductSuccess ){
			$this->view->editProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['admin_editproduct']) ){
		
			$data = array(
				'product_name' => $v['product_name'],
				'product_code' => $v['product_code'],
				'product_price_scheme' => $v['product_price_scheme'],
				'product_price' => $v['product_price'],
				'product_pack1' => $v['product_pack1'],
				'product_pack2' => $v['product_pack2'],
				'product_pack3' => $v['product_pack3'],
				'product_pack4' => $v['product_pack4'],
				'product_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_image_1' => isset($v['product_image_1'])?$v['product_image_1']:'',
				'product_image_2' => isset($v['product_image_2'])?$v['product_image_2']:'',
				'product_image_3' => isset($v['product_image_3'])?$v['product_image_3']:'',
				'product_image_4' => isset($v['product_image_4'])?$v['product_image_4']:'',
				'product_image_5' => isset($v['product_image_5'])?$v['product_image_5']:'',
				'product_image_6' => isset($v['product_image_6'])?$v['product_image_6']:'',
				'product_image_7' => isset($v['product_image_7'])?$v['product_image_7']:'',
				'product_image_8' => isset($v['product_image_8'])?$v['product_image_8']:'',
				'category_id' => $v['category_id0'],
				'category_id1' => $v['category_id1'],
				'product_body' => isset($v['product_body'])?$v['product_body']:0,
				'product_front' => isset($v['product_front'])?$v['product_front']:0,
				'product_front_2' => isset($v['product_front_2'])?$v['product_front_2']:0,
				'product_front_price_praf1' => isset($v['product_front_price_praf1'])?$v['product_front_price_praf1']:0,
				'product_front_price_praf2' => isset($v['product_front_price_praf2'])?$v['product_front_price_praf2']:0,
				'product_type' => isset($v['product_type'])?$v['product_type']:0,
				'product_accessories' => isset($v['product_accessories'])?$v['product_accessories']:0,
				'product_accessories_0' => isset($v['product_accessories_0'])?$v['product_accessories_0']:0,
				'product_accessories_1' => isset($v['product_accessories_1'])?$v['product_accessories_1']:0,
				'product_accessories_2' => isset($v['product_accessories_2'])?$v['product_accessories_2']:0,
				'product_accessories_3' => isset($v['product_accessories_3'])?$v['product_accessories_3']:0,
				'product_legs' => isset($v['product_legs'])?$v['product_legs']:0,
				'product_handles' => isset($v['product_handles'])?$v['product_handles']:0,
				'product_options' => isset($v['product_options'])?$v['product_options']:0,	
				
				'product_options2' => isset($v['product_options2'])?$v['product_options2']:0,

				'product_options2_img1' => isset($v['product_options_img1_img'])?$v['product_options_img1_img']:'',
				'product_options2_img2' => isset($v['product_options_img2_img'])?$v['product_options_img2_img']:'',
				'product_options2_img3' => isset($v['product_options_img3_img'])?$v['product_options_img3_img']:'',
				'product_options2_img4' => isset($v['product_options_img4_img'])?$v['product_options_img4_img']:'',
				'product_options2_img5' => isset($v['product_options_img5_img'])?$v['product_options_img5_img']:'',

				
				'product_options_1' => isset($v['product_options_1'])?$v['product_options_1']:0,
				'product_options_1_img' => isset($v['product_options_1_img'])?$v['product_options_1_img']:'',
				'product_options_2' => isset($v['product_options_2'])?$v['product_options_2']:0,
				'product_options_2_img' => isset($v['product_options_2_img'])?$v['product_options_2_img']:'',
				'product_options_3' => isset($v['product_options_3'])?$v['product_options_3']:0,
				'product_options_3_img' => isset($v['product_options_3_img'])?$v['product_options_3_img']:'',
				'product_options_4' => isset($v['product_options_4'])?$v['product_options_4']:0,
				'product_options_4_img' => isset($v['product_options_4_img'])?$v['product_options_4_img']:'',
				
				'product_options_wd' => isset($v['product_options_wd'])?$v['product_options_wd']:0,
				'product_options_ww0' => isset($v['product_options_ww0'])?$v['product_options_ww0']:0,
				'product_options_ww1' => isset($v['product_options_ww1'])?$v['product_options_ww1']:0,
				'product_options_rp' => isset($v['product_options_rp'])?$v['product_options_rp']:0,				
				'product_rim1' => isset($v['product_rim1'])?$v['product_rim1']:0,
				'product_rim1_price' => isset($v['product_rim1_price'])?$v['product_rim1_price']:0,
				'product_rim2' => isset($v['product_rim2'])?$v['product_rim2']:0,
				'product_rim2_price' => isset($v['product_rim2_price'])?$v['product_rim2_price']:0,
				'product_rim3' => isset($v['product_rim3'])?$v['product_rim3']:0,
				'product_rim3_price' => isset($v['product_rim3_price'])?$v['product_rim3_price']:0,
				'product_rim4' => isset($v['product_rim4'])?$v['product_rim4']:0,
				'product_rim4_price' => isset($v['product_rim4_price'])?$v['product_rim4_price']:0,
				'product_rim_default' => isset($v['product_rim_default'])?$v['product_rim_default']:0,
				'product_rim2_default' => isset($v['product_rim2_default'])?$v['product_rim2_default']:0,
				'product_edit' => Lib_Date::datetime()
			);
			$Product->update( $data , 'product_id='.$v['id'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_name_".$v['id']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_description_".$v['id']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
						
			$information->editProductSuccess = true; 
			$this->_helper->redirector('productedit','admin',null,array('id' => $v['id']));	
		
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_name_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_name_".$v['id']."', '".$row->product_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_name_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_description_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_description_".$v['id']."', '".$row->product_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_description_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function producteditnamesAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		
		$Product = new Product();
		$ProductFieldname = new ProductFieldname();		
		
		
		$select = $ProductFieldname->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $ProductFieldname->fetchRow($select);
		
		if( !isset($row) ){
			$data = array(
				'product_id' => $v['id']
			);
			$idIns = $ProductFieldname->insert($data);			
		}
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->editnamesProductSuccess ){
			$this->view->editnamesProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		

		
		
		if( isset($v['admin_editnamesproduct']) ){
		
		/*
			$fieldnames = array_reverse($v['fieldnames']);
			foreach( $fieldnames as $key => $val ){
				echo 'ALTER TABLE `product_fieldname` ADD `'.$key.'` VARCHAR(100) NOT NULL AFTER `product_fieldname_size`;<br />';
			}
		*/
		
			foreach( $v['fieldnames'] as $key => $val ){
				$data[$key] = trim($val);
			}
			$ProductFieldname->update( $data , 'product_id='.$v['id'] );
			
		//	var_dump($data);

			$information->editnamesProductSuccess = true; 
			$this->_helper->redirector('producteditnames','admin',null,array('id' => $v['id']));	
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);		
		$this->view->ProductInfo = $row;
	/**/
		$select = $ProductFieldname->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $ProductFieldname->fetchRow($select);
		$row = $row->toArray();
		$this->view->ProductFieldnameInfo = $row;	
	/**/
	//	var_dump($row);die();	
	//	$this->view->ProductFieldnameInfo = '123';	
		
	}
	
	public function producteditmtAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		
		$Product = new Product();
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( isset($v['admin_editmtproduct']) ){
		
			$data = array(
				'product_mt_title' => $v['product_mt_title'],
				'product_mt_description' => $v['product_mt_description'],
				'product_mt_keywords' => $v['product_mt_keywords']
			);
			$Product->update( $data , 'product_id='.$v['id'] );

			$information->editnamesProductSuccess = true; 
			$this->_helper->redirector('producteditmt','admin',null,array('id' => $v['id']));	
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);		
		$this->view->ProductInfo = $row;
		
	}
	
	public function producteditlinkedAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		
		$Product = new Product();
		$ProductLinked = new ProductLinked();				
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		if( $information->editlinkedProductSuccess ){
			$this->view->editlinkedProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( isset($v['admin_editlinkedproduct']) ){
		
			$where = array(
				'product_id = ?' => $v['id']
			);
			$ProductLinked->delete($where);
			
			foreach( $v['product_id'] as $key => $val ){
			
				$data = array(
					'product_id' => $v['id'],
					'product_linked_pid' => $key
				);
			
				$idIns = $ProductLinked->insert($data);
			}
			
			$information->editlinkedProductSuccess = true; 
			$this->_helper->redirector('producteditlinked','admin',null,array('id' => $v['id']));	
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);		
		$this->view->ProductInfo = $row;
		
		$ask = '
			SELECT *, p.product_id AS product_id FROM product p LEFT JOIN product_linked pl ON p.product_id = pl.product_linked_pid AND pl.product_id = '.$v['id'].' 
			WHERE p.product_id != '.$v['id'].'
			AND p.product_shop = 0
			ORDER BY p.product_name ASC
		';
		
		$dataLinked = $db->query($ask)->fetchAll();	
		$this->view->dataLinked = $dataLinked;
		
	}
	
	public function producteditelementAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		
		$Product = new Product();
		$ProductElement = new ProductElement();
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		
		
		if( $information->addProductElementSuccess ){
			$this->view->addProductElementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		if( isset($v['saveElement']) ){
		
			$where = array(
				'product_id = ?' => $v['id']
			);
			$ProductElement->delete($where);
		
		
			foreach( $v['product_element_name'] as $key => $val ){
				$data = array(
					'product_id' => $v['id'],
					'product_element_name' => isset($v['product_element_name'][$key])?$v['product_element_name'][$key]:'',
					'product_element_code' => isset($v['product_element_code'][$key])?$v['product_element_code'][$key]:'',
					'product_element_equation1' => isset($v['product_element_equation1'][$key])?$v['product_element_equation1'][$key]:'',
					'product_element_pcv1' => isset($v['product_element_pcv1'][$key])?$v['product_element_pcv1'][$key]:0,
					'product_element_equation2' => isset($v['product_element_equation2'][$key])?$v['product_element_equation2'][$key]:'',
					'product_element_pcv2' => isset($v['product_element_pcv2'][$key])?$v['product_element_pcv2'][$key]:0,
					'product_element_panel' => $v['product_element_panel'][$key],
					'product_element_quantity' => isset($v['product_element_quantity'][$key])?$v['product_element_quantity'][$key]:0,
					'product_element_drawer' => $v['product_element_drawer'][$key],
					'product_element_drawerAmount' => isset($v['product_element_drawerAmount'][$key])?$v['product_element_drawerAmount'][$key]:0,
					'product_element_shelf' => isset($v['product_element_shelf'][$key])?$v['product_element_shelf'][$key]:0
				);
				$idIns = $ProductElement->insert($data);
		//		var_dump($data);echo'<hr />';
			}
				
			$information->addProductElementSuccess = true; 
			$this->_helper->redirector('producteditelement','admin',null,array('id' => $v['id']));
		
		}
		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);		
		$this->view->ProductInfo = $row;
		
		$data = $ProductElement->fetchAll('product_id = '.$v['id'] , 'product_element_id ASC'); 		
		$this->view->dataTableProductElement = $data;		
	}
	
	public function producteditelementaddelementAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		
		$Product = new Product();
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);		
		$this->view->ProductInfo = $row;
		
		$this->view->elementName = time().'_'.rand(0,time());
	}
	
	public function producteditsizeAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		
		if( $information->editProductSuccess ){
			$this->view->editProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		if( isset($v['admin_editproduct']) ){
		
			$data = array(
			
				'product_def_only' => isset($v['product_def_only'])?$v['product_def_only']:0,
				
				'product_height_def_only' => isset($v['product_height_def_only'])?$v['product_height_def_only']:0,
				'product_width_def_only' => isset($v['product_width_def_only'])?$v['product_width_def_only']:0,
				'product_depth_def_only' => isset($v['product_depth_def_only'])?$v['product_depth_def_only']:0,
				'product_shelfamount_def_only' => isset($v['product_shelfamount_def_only'])?$v['product_shelfamount_def_only']:0,				
				
				'product_height_img' => isset($v['product_height_img'])?$v['product_height_img']:'',
				'product_height_min' => isset($v['product_height_min'])?$v['product_height_min']:0,
				'product_height_max' => isset($v['product_height_max'])?$v['product_height_max']:0,
				'product_height_default' => isset($v['product_height_default'])?$v['product_height_default']:0,
				
				'product_width_img' => isset($v['product_width_img'])?$v['product_width_img']:'',
				'product_width_min' => isset($v['product_width_min'])?$v['product_width_min']:0,
				'product_width_max' => isset($v['product_width_max'])?$v['product_width_max']:0,
				'product_width_default' => isset($v['product_width_default'])?$v['product_width_default']:0,
				
				'product_depth_img' => isset($v['product_depth_img'])?$v['product_depth_img']:'',
				'product_depth_min' => isset($v['product_depth_min'])?$v['product_depth_min']:0,
				'product_depth_max' => isset($v['product_depth_max'])?$v['product_depth_max']:0,
				'product_depth_default' => isset($v['product_depth_default'])?$v['product_depth_default']:0,
				
				'product_shelf' => isset($v['product_shelf'])?$v['product_shelf']:0,
				'product_shelfamount_img' => isset($v['product_shelfamount_img'])?$v['product_shelfamount_img']:'',
				'product_shelfamount_min' => isset($v['product_shelfamount_min'])?$v['product_shelfamount_min']:0,
				'product_shelfamount_max' => isset($v['product_shelfamount_max'])?$v['product_shelfamount_max']:0,
				'product_shelfamount_default' => isset($v['product_shelfamount_default'])?$v['product_shelfamount_default']:0,
				
				'product_wysszerA' => isset($v['product_wysszerA'])?$v['product_wysszerA']:0,
				'product_wysszerAamount_default' => isset($v['product_wysszerAamount_default'])?$v['product_wysszerAamount_default']:0,
				'product_wysszerAamount_img' => isset($v['product_wysszerAamount_img'])?$v['product_wysszerAamount_img']:'',
				'product_wysszerAamount_def_only' => isset($v['product_wysszerAamount_def_only'])?$v['product_wysszerAamount_def_only']:0,
				'product_wysszerAamount_min' => isset($v['product_wysszerAamount_min'])?$v['product_wysszerAamount_min']:0,
				'product_wysszerAamount_max' => isset($v['product_wysszerAamount_max'])?$v['product_wysszerAamount_max']:0,
				
				'product_wysszerB' => isset($v['product_wysszerB'])?$v['product_wysszerB']:0,
				'product_wysszerBamount_default' => isset($v['product_wysszerBamount_default'])?$v['product_wysszerBamount_default']:0,
				'product_wysszerBamount_img' => isset($v['product_wysszerBamount_img'])?$v['product_wysszerBamount_img']:'',
				'product_wysszerBamount_def_only' => isset($v['product_wysszerBamount_def_only'])?$v['product_wysszerBamount_def_only']:0,
				'product_wysszerBamount_min' => isset($v['product_wysszerBamount_min'])?$v['product_wysszerBamount_min']:0,
				'product_wysszerBamount_max' => isset($v['product_wysszerBamount_max'])?$v['product_wysszerBamount_max']:0,
				
				'product_wysszerC' => isset($v['product_wysszerC'])?$v['product_wysszerC']:0,
				'product_wysszerCamount_default' => isset($v['product_wysszerCamount_default'])?$v['product_wysszerCamount_default']:0,
				'product_wysszerCamount_img' => isset($v['product_wysszerCamount_img'])?$v['product_wysszerCamount_img']:'',
				'product_wysszerCamount_def_only' => isset($v['product_wysszerCamount_def_only'])?$v['product_wysszerCamount_def_only']:0,
				'product_wysszerCamount_min' => isset($v['product_wysszerCamount_min'])?$v['product_wysszerCamount_min']:0,
				'product_wysszerCamount_max' => isset($v['product_wysszerCamount_max'])?$v['product_wysszerCamount_max']:0,
				
				'product_wysszerD' => isset($v['product_wysszerD'])?$v['product_wysszerD']:0,
				'product_wysszerDamount_default' => isset($v['product_wysszerDamount_default'])?$v['product_wysszerDamount_default']:0,
				'product_wysszerDamount_img' => isset($v['product_wysszerDamount_img'])?$v['product_wysszerDamount_img']:'',
				'product_wysszerDamount_def_only' => isset($v['product_wysszerDamount_def_only'])?$v['product_wysszerDamount_def_only']:0,
				'product_wysszerDamount_min' => isset($v['product_wysszerDamount_min'])?$v['product_wysszerDamount_min']:0,
				'product_wysszerDamount_max' => isset($v['product_wysszerDamount_max'])?$v['product_wysszerDamount_max']:0,
				
				'product_wysszerE' => isset($v['product_wysszerE'])?$v['product_wysszerE']:0,
				'product_wysszerEamount_default' => isset($v['product_wysszerEamount_default'])?$v['product_wysszerEamount_default']:0,
				'product_wysszerEamount_img' => isset($v['product_wysszerEamount_img'])?$v['product_wysszerEamount_img']:'',
				'product_wysszerEamount_def_only' => isset($v['product_wysszerEamount_def_only'])?$v['product_wysszerEamount_def_only']:0,
				'product_wysszerEamount_min' => isset($v['product_wysszerEamount_min'])?$v['product_wysszerEamount_min']:0,
				'product_wysszerEamount_max' => isset($v['product_wysszerEamount_max'])?$v['product_wysszerEamount_max']:0,
				
				'product_edit' => Lib_Date::datetime()
			);
			$Product->update( $data , 'product_id='.$v['id'] );
						
			$information->editProductSuccess = true; 
			$this->_helper->redirector('producteditsize','admin',null,array('id' => $v['id']));	
		
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
	}
	
	public function productphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/product/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	public function productphotooptionAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/options/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		$this->view->opt = $v['opt'];  
	}
	
	public function productphoto2Action() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/product/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		$this->view->num = $v['num'];  
		
	}
	
	public function productphotosizeAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/size/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		$this->view->type = $v['type'];  
	}
	
	public function producteditstandardsizeAction() {
		$v = $this->_request->getParams();		
	
		$this->view->module_id = $v['module_id'];
		$this->view->product_id = $v['product_id'];
		
		if( $v['module_id'] == 'widthStandard' ){
			$Model = new ProductWidth();
			$field = 'product_width_value';
		}
		
		if( $v['module_id'] == 'heightStandard' ){
			$Model = new ProductHeight();
			$field = 'product_height_value';
		}
		
		if( $v['module_id'] == 'depthStandard' ){
			$Model = new ProductDepth();
			$field = 'product_depth_value';
		}
		
		if( $v['module_id'] == 'shelfamountStandard' ){
			$Model = new ProductShelfamount();
			$field = 'product_shelfamount_value';
		}
		
		if( $v['module_id'] == 'WysszarAStandard' ){
			$Model = new ProductWysszerA();
			$field = 'product_wysszera_value';
		}
		
		if( $v['module_id'] == 'WysszarBStandard' ){
			$Model = new ProductWysszerB();
			$field = 'product_wysszerb_value';
		}
		
		if( $v['module_id'] == 'WysszarCStandard' ){
			$Model = new ProductWysszerC();
			$field = 'product_wysszerc_value';
		}
		
		if( $v['module_id'] == 'WysszarDStandard' ){
			$Model = new ProductWysszerD();
			$field = 'product_wysszerd_value';
		}
		
		if( $v['module_id'] == 'WysszarEStandard' ){
			$Model = new ProductWysszerE();
			$field = 'product_wysszere_value';
		}
		
		
		if( isset($v['add']) ){		
			$data = array(
				'product_id' => $v['product_id'],
				$field => $v['add']
			);
			$idIns = $Model->insert($data);		
		}
		
		
		if( isset($v['remove']) ){	
			$where = array(
				'product_id = ?' => $v['product_id'],
				$field.' = ?' => $v['remove']
			);
			$Model->delete($where);		
		}
		
		
		
		$data = $Model->fetchAll('product_id = '.$v['product_id'] , $field.' ASC'); 		
		$this->view->dataTable = $data;			
		$this->view->field = $field;		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function shopAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Product = new Product();	
		$dataCount = count($Product->fetchAll('product_shop = 1' , 'product_name ASC')); 
			$p = ($page-1)*$limit;		
		$data = $Product->fetchAll('product_shop = 1' , 'product_name ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('shop');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	public function shopaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Product = new Product();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addproduct']) ){
		
			$data = array(
				'product_name' => $v['product_name'],
				'product_code' => $v['product_code'],
				'product_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_image_1' => isset($v['product_image_1'])?$v['product_image_1']:'',
				'product_image_2' => isset($v['product_image_2'])?$v['product_image_2']:'',
				'product_image_3' => isset($v['product_image_3'])?$v['product_image_3']:'',
				'product_image_4' => isset($v['product_image_4'])?$v['product_image_4']:'',
				'product_image_5' => isset($v['product_image_5'])?$v['product_image_5']:'',
				'product_image_6' => isset($v['product_image_6'])?$v['product_image_6']:'',
				'product_image_7' => isset($v['product_image_7'])?$v['product_image_7']:'',
				'product_image_8' => isset($v['product_image_8'])?$v['product_image_8']:'',
				'category_id' => $v['category_id3'],
				'product_ins' => Lib_Date::datetime(),
				'product_shop' => 1
			);
			$idIns = $Product->insert($data);
			
			$information->addProductSuccess = true; 
			$this->_helper->redirector('shopedit','admin',null,array('id' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
	}
	
	public function shopremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$Product = new Product();
		$where = array(
			'product_id = ?' => $v['id']
		);
		$Product->delete($where);			
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		foreach( $dataLang as $k1 => $val1 ){
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'product_name_".$v['id']."' LIMIT 1";
			$db->query($zap);	
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'product_description_".$v['id']."' LIMIT 1";
			$db->query($zap);	
		}	
		
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('shop','admin');		
	}
	
	public function shopeditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->addProductSuccess ){
			$this->view->addProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $information->editProductSuccess ){
			$this->view->editProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['admin_editproduct']) ){
		
			$data = array(
				'product_name' => $v['product_name'],
				'product_mt_title' => $v['product_mt_title'],
				'product_mt_description' => $v['product_mt_description'],
				'product_mt_keywords' => $v['product_mt_keywords'],
				'product_code' => $v['product_code'],
				'product_price' => $v['product_price'],
				'product_pack1' => $v['product_pack1'],
				'product_pack2' => $v['product_pack2'],
				'product_pack3' => $v['product_pack3'],
				'product_pack4' => $v['product_pack4'],
				'product_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_image_1' => isset($v['product_image_1'])?$v['product_image_1']:'',
				'product_image_2' => isset($v['product_image_2'])?$v['product_image_2']:'',
				'product_image_3' => isset($v['product_image_3'])?$v['product_image_3']:'',
				'product_image_4' => isset($v['product_image_4'])?$v['product_image_4']:'',
				'product_image_5' => isset($v['product_image_5'])?$v['product_image_5']:'',
				'product_image_6' => isset($v['product_image_6'])?$v['product_image_6']:'',
				'product_image_7' => isset($v['product_image_7'])?$v['product_image_7']:'',
				'product_image_8' => isset($v['product_image_8'])?$v['product_image_8']:'',
				'category_id' => $v['category_id3'],
				'product_shop_status' => isset($v['product_shop_status'])?$v['product_shop_status']:0,				
				'product_edit' => Lib_Date::datetime()
			);
			$Product->update( $data , 'product_id='.$v['id'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_name_".$v['id']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_description_".$v['id']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
						
			$information->editProductSuccess = true; 
			$this->_helper->redirector('shopedit','admin',null,array('id' => $v['id']));	
		
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_name_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_name_".$v['id']."', '".$row->product_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_name_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_description_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_description_".$v['id']."', '".$row->product_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_description_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function producteditbodyAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['color_schema']) ){
		
			$f = new Lib_Color();
			$f->changeColorSchema($v['id'],$v['color_schema_id']);
			$data = array(
				'color_schema_id' => $v['color_schema_id']
			);
			$Product->update($data, 'product_id='.$v['id']);
			
			$this->_helper->redirector('producteditbody','admin',null,array('id' => $v['id']));				
		}	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductBody = new ProductBody();
		
		$data = $ProductBody->fetchAll('product_body_typebody = 0 AND product_id = '.$v['id'] , 'product_body_name ASC'); 		
		$this->view->dataTable = $data;		
		
		$data2 = $ProductBody->fetchAll('product_body_typebody = 1 AND product_id = '.$v['id'] , 'product_body_name ASC'); 		
		$this->view->dataTable2 = $data2;	


			
		$ColorSchema = new ColorSchema();	
		$data = $ColorSchema->fetchAll('color_schema_type = 0', 'color_schema_name ASC'); 		
		$this->view->ColorSchema = $data;		
		
	}
	
	
	public function producteditbodyaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditbody';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductBody = new ProductBody();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_body_name' => $v['product_name'],
				'product_body_code' => $v['product_code'],
				'product_body_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_body_price' => $v['product_price']
			);
			$idIns = $ProductBody->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('producteditbodyedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	public function producteditbodydefaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductBody = new ProductBody();
		
		$select = $ProductBody->select();		
		$select->where('product_body_id = ?', $v['idp']);	
		$row = $ProductBody->fetchRow($select);
		
			
		$zap = "UPDATE `product_body` SET product_body_default='0' WHERE product_id = '".$v['id']."' AND product_body_typebody = '".$row->product_body_typebody."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_body` SET product_body_default='1' WHERE product_body_id = '".$v['idp']."' AND  product_id = '".$v['id']."' AND product_body_typebody = '".$row->product_body_typebody."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('producteditbody','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	
	public function producteditbodyeditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditbody';
		
		$MapFiltrBody = new MapFiltrBody();	
		
		$dataMapFiltrBody = $MapFiltrBody->fetchAll(); 		
		$this->view->dataTableMapFiltrBody = $dataMapFiltrBody;
		
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductBody = new ProductBody();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_body_typebody' => isset($v['product_typebody'])?$v['product_typebody']:0,
				'product_body_option1' => isset($v['product_option1'])?$v['product_option1']:0,
				'product_body_option2' => isset($v['product_option2'])?$v['product_option2']:0,
				'product_body_option3' => isset($v['product_option3'])?$v['product_option3']:0,
				'product_body_option4' => isset($v['product_option4'])?$v['product_option4']:0,
				'product_body_option5' => isset($v['product_option5'])?$v['product_option5']:0,
				'product_body_option6' => isset($v['product_option6'])?$v['product_option6']:0,
				'product_body_option7' => isset($v['product_option7'])?$v['product_option7']:0,
				'product_body_option8' => isset($v['product_option8'])?$v['product_option8']:0,
				'product_body_name' => $v['product_name'],
				'product_body_code' => $v['product_code'],
				'product_body_type' => isset($v['product_type'])?$v['product_type']:0,
				'product_body_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_body_price' => $v['product_price']
			);
			$ProductBody->update( $data , 'product_body_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_bodyname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_bodydescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('producteditbodyedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductBody = new ProductBody();
		
		$select = $ProductBody->select();		
		$select->where('product_body_id = ?', $v['idp']);	
		$row = $ProductBody->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_bodyname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_bodyname_".$v['idp']."', '".$row->product_body_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_bodyname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_bodydescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_bodydescription_".$v['idp']."', '".$row->product_body_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_bodydescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function producteditbodyaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/body/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function producteditbodyphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/body/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function producteditbodyremoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditbody';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductBody = new ProductBody();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_body_id = ?' => $v['idp']
		);
		$ProductBody->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('producteditbody','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function producteditfront2Action() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['color_schema']) ){
		
			$f = new Lib_Color();
			$f->changeColorSchema($v['id'],$v['color_schema_id'],5);
			$data = array(
				'color_schema_id6' => $v['color_schema_id']
			);
			$Product->update($data, 'product_id='.$v['id']);
			
			$this->_helper->redirector('producteditfront2','admin',null,array('id' => $v['id']));				
		}	
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductFront2 = new ProductFront2();
		
		$data = $ProductFront2->fetchAll('product_id = '.$v['id'] , 'product_front_2_name ASC'); 		
		$this->view->dataTable = $data;		

			
		$ColorSchema = new ColorSchema();	
		$data = $ColorSchema->fetchAll('color_schema_type = 1', 'color_schema_name ASC'); 		
		$this->view->ColorSchema = $data;	
	}
	
	
	public function producteditfront2addAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditfront2';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductFront2 = new ProductFront2();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_front_2_name' => $v['product_name'],
				'product_front_2_code' => $v['product_code'],
				'product_front_2_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_front_2_price' => $v['product_price']
			);
			$idIns = $ProductFront2->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('producteditfront2edit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	public function producteditfront2defaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductFront2 = new ProductFront2();
		
		$select = $ProductFront2->select();		
		$select->where('product_front_2_id = ?', $v['idp']);	
		$row = $ProductFront2->fetchRow($select);
		
			
		$zap = "UPDATE `product_front_2` SET product_front_2_default='0' WHERE product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_front_2` SET product_front_2_default='1' WHERE product_front_2_id = '".$v['idp']."' AND  product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('producteditfront2','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function producteditfront2editAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditfront2';
		
		$MapFiltrFront = new MapFiltrFront();	
		
		$dataMapFiltrFront = $MapFiltrFront->fetchAll(); 		
		$this->view->dataTableMapFiltrFront = $dataMapFiltrFront;
		
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductFront2 = new ProductFront2();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_front_2_option1' => isset($v['product_option1'])?$v['product_option1']:0,
				'product_front_2_option2' => isset($v['product_option2'])?$v['product_option2']:0,
				'product_front_2_option3' => isset($v['product_option3'])?$v['product_option3']:0,
				'product_front_2_option4' => isset($v['product_option4'])?$v['product_option4']:0,
				'product_front_2_option5' => isset($v['product_option5'])?$v['product_option5']:0,
				'product_front_2_option6' => isset($v['product_option6'])?$v['product_option6']:0,
				'product_front_2_option7' => isset($v['product_option7'])?$v['product_option7']:0,
				'product_front_2_option8' => isset($v['product_option8'])?$v['product_option8']:0,
				'product_front_2_option9' => isset($v['product_option9'])?$v['product_option9']:0,
				'product_front_2_option10' => isset($v['product_option10'])?$v['product_option10']:0,
				'product_front_2_option11' => isset($v['product_option11'])?$v['product_option11']:0,
				'product_front_2_option12' => isset($v['product_option12'])?$v['product_option12']:0,
				'product_front_2_option13' => isset($v['product_option13'])?$v['product_option13']:0,
				'product_front_2_option14' => isset($v['product_option14'])?$v['product_option14']:0,
				'product_front_2_option15' => isset($v['product_option15'])?$v['product_option15']:0,
				'product_front_2_name' => $v['product_name'],
				'product_front_2_code' => $v['product_code'],
				'product_front_2_type' => isset($v['product_type'])?$v['product_type']:0,
				'product_front_2_type_2' => isset($v['product_type_2'])?$v['product_type_2']:0,
				'product_front_2_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_front_2_price' => $v['product_price']
			);
			$ProductFront2->update( $data , 'product_front_2_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_front_2_name_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_front_2_description_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('producteditfront2edit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductFront2 = new ProductFront2();
		
		$select = $ProductFront2->select();		
		$select->where('product_front_2_id = ?', $v['idp']);	
		$row = $ProductFront2->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_front_2_name_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_front_2_name_".$v['idp']."', '".$row->product_front_2_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_front_2_name_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_front_2_description_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_front_2_description_".$v['idp']."', '".$row->product_front_2_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_front_2_description_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	
	public function producteditfront2removeAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditfront2';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductFront2 = new ProductFront2();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_front_2_id = ?' => $v['idp']
		);
		$ProductFront2->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('producteditfront2','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function producteditfrontAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['color_schema']) ){
		
			$f = new Lib_Color();
			$f->changeColorSchema($v['id'],$v['color_schema_id'],1);
			$data = array(
				'color_schema_id2' => $v['color_schema_id']
			);
			$Product->update($data, 'product_id='.$v['id']);
			
			$this->_helper->redirector('producteditfront','admin',null,array('id' => $v['id']));				
		}	
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductFront = new ProductFront();
		
		$data = $ProductFront->fetchAll('product_id = '.$v['id'] , 'product_front_name ASC'); 		
		$this->view->dataTable = $data;		

			
		$ColorSchema = new ColorSchema();	
		$data = $ColorSchema->fetchAll('color_schema_type = 1', 'color_schema_name ASC'); 		
		$this->view->ColorSchema = $data;	
	}
	
	
	public function producteditfrontaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditfront';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductFront = new ProductFront();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_front_name' => $v['product_name'],
				'product_front_code' => $v['product_code'],
				'product_front_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_front_price' => $v['product_price']
			);
			$idIns = $ProductFront->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('producteditfrontedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	public function producteditfrontdefaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductFront = new ProductFront();
		
		$select = $ProductFront->select();		
		$select->where('product_front_id = ?', $v['idp']);	
		$row = $ProductFront->fetchRow($select);
		
			
		$zap = "UPDATE `product_front` SET product_front_default='0' WHERE product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_front` SET product_front_default='1' WHERE product_front_id = '".$v['idp']."' AND  product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('producteditfront','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function producteditfronteditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditfront';
		
		$MapFiltrFront = new MapFiltrFront();	
		
		$dataMapFiltrFront = $MapFiltrFront->fetchAll(); 		
		$this->view->dataTableMapFiltrFront = $dataMapFiltrFront;
		
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductFront = new ProductFront();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_front_option1' => isset($v['product_option1'])?$v['product_option1']:0,
				'product_front_option2' => isset($v['product_option2'])?$v['product_option2']:0,
				'product_front_option3' => isset($v['product_option3'])?$v['product_option3']:0,
				'product_front_option4' => isset($v['product_option4'])?$v['product_option4']:0,
				'product_front_option5' => isset($v['product_option5'])?$v['product_option5']:0,
				'product_front_option6' => isset($v['product_option6'])?$v['product_option6']:0,
				'product_front_option7' => isset($v['product_option7'])?$v['product_option7']:0,
				'product_front_option8' => isset($v['product_option8'])?$v['product_option8']:0,
				'product_front_option9' => isset($v['product_option9'])?$v['product_option9']:0,
				'product_front_option10' => isset($v['product_option10'])?$v['product_option10']:0,
				'product_front_option11' => isset($v['product_option11'])?$v['product_option11']:0,
				'product_front_option12' => isset($v['product_option12'])?$v['product_option12']:0,
				'product_front_option13' => isset($v['product_option13'])?$v['product_option13']:0,
				'product_front_option14' => isset($v['product_option14'])?$v['product_option14']:0,
				'product_front_option15' => isset($v['product_option15'])?$v['product_option15']:0,
				'product_front_name' => $v['product_name'],
				'product_front_code' => $v['product_code'],
				'product_front_type' => isset($v['product_type'])?$v['product_type']:0,
				'product_front_type_2' => isset($v['product_type_2'])?$v['product_type_2']:0,
				'product_front_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_front_price' => $v['product_price']
			);
			$ProductFront->update( $data , 'product_front_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_frontname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_frontdescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('producteditfrontedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductFront = new ProductFront();
		
		$select = $ProductFront->select();		
		$select->where('product_front_id = ?', $v['idp']);	
		$row = $ProductFront->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_frontname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_frontname_".$v['idp']."', '".$row->product_front_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_frontname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_frontdescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_frontdescription_".$v['idp']."', '".$row->product_front_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_frontdescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function producteditfrontaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/front/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function producteditfrontphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/front/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function producteditfrontremoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditfront';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductFront = new ProductFront();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_front_id = ?' => $v['idp']
		);
		$ProductFront->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('producteditfront','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function productedittypeAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['color_schema']) ){
		
			$f = new Lib_Color();
			$f->changeColorSchema($v['id'],$v['color_schema_id'],2);
			$data = array(
				'color_schema_id3' => $v['color_schema_id']
			);
			$Product->update($data, 'product_id='.$v['id']);
			
			$this->_helper->redirector('productedittype','admin',null,array('id' => $v['id']));				
		}
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductType = new ProductType();
		
		$data = $ProductType->fetchAll('product_id = '.$v['id'] , 'product_type_name ASC'); 		
		$this->view->dataTable = $data;		


			
		$ColorSchema = new ColorSchema();	
		$data = $ColorSchema->fetchAll('color_schema_type = 2', 'color_schema_name ASC'); 		
		$this->view->ColorSchema = $data;	
	}
	
	
	public function productedittypeaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedittype';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductType = new ProductType();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_type_name' => $v['product_name'],
				'product_type_code' => $v['product_code'],
				'product_type_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_type_price' => $v['product_price']
			);
			$idIns = $ProductType->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('productedittypeedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	
	public function productedittype2addAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedittype';
		
		$Product = new Product();	
		$ProductType = new ProductType();	
		$ProductType2 = new ProductType2();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;			
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		

		if( isset($v['admin_add']) ){		
			$data = array(
				'product_type_id' => $v['idp'],
				'product_type2_name' => $v['product_name'],
				'product_type2_code' => $v['product_code'],
				'product_type2_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_type2_price' => $v['product_price']
			);
			$idIns = $ProductType2->insert($data);
			
			$information->addSuccess = true; 
			$this->_helper->redirector('productedittype2edit','admin',null,array('id' => $v['id'], 'idp' => $v['idp'], 'idp2' => $idIns));
		}		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);		
		$this->view->rowProduct = $row;	
		
		$select = $ProductType->select();		
		$select->where('product_type_id = ?', $v['idp']);	
		$row = $ProductType->fetchRow($select);		
		$this->view->rowProductType = $row;		
	}
	
	
	public function productedittypedefaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductType = new ProductType();
		
		$select = $ProductType->select();		
		$select->where('product_type_id = ?', $v['idp']);	
		$row = $ProductType->fetchRow($select);
		
			
		$zap = "UPDATE `product_type` SET product_type_default='0' WHERE product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_type` SET product_type_default='1' WHERE product_type_id = '".$v['idp']."' AND  product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('productedittype','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function productedittype2defaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();		
			
		$zap = "UPDATE `product_type2` SET product_type2_default='0' WHERE product_type_id = '".$v['idp']."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_type2` SET product_type2_default='1' WHERE product_type_id = '".$v['idp']."' AND  product_type2_id = '".$v['idp2']."' ";
		$db->query($zap);
		
		$this->_helper->redirector('productedittypeedit','admin',null,array('id' => $v['id'],'idp' => $v['idp']));		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function productedittypeeditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedittype';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}	
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductType = new ProductType();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_type_name' => $v['product_name'],
				'product_type_code' => $v['product_code'],
				'product_type_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_type_price' => $v['product_price']
			);
			$ProductType->update( $data , 'product_type_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_typename_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_typedescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('productedittypeedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductType = new ProductType();
		
		$select = $ProductType->select();		
		$select->where('product_type_id = ?', $v['idp']);	
		$row = $ProductType->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		
		
		
		
		
		$ProductType2 = new ProductType2();		
		$data = $ProductType2->fetchAll('product_type_id = '.$v['idp'] , 'product_type2_name ASC'); 		
		$this->view->dataTableProductType2 = $data;	
		
		
		
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_typename_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_typename_".$v['idp']."', '".$row->product_type_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_typename_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_typedescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_typedescription_".$v['idp']."', '".$row->product_type_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_typedescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	
	public function productedittype2editAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedittype';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductType = new ProductType();	
		$ProductType2 = new ProductType2();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_type2_name' => $v['product_name'],
				'product_type2_code' => $v['product_code'],
				'product_type2_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_type2_price' => $v['product_price']
			);
			$ProductType2->update( $data , 'product_type2_id='.$v['idp2'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_type2name_".$v['idp2']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_type2description_".$v['idp2']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('productedittype2edit','admin',null,array('id' => $v['id'], 'idp' => $v['idp'], 'idp2' => $v['idp2']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductType = new ProductType();		
		$select = $ProductType->select();		
		$select->where('product_type_id = ?', $v['idp']);	
		$row = $ProductType->fetchRow($select);		
		$this->view->rowElementType = $row;
		
		$ProductType2 = new ProductType2();		
		$select = $ProductType2->select();		
		$select->where('product_type2_id = ?', $v['idp2']);	
		$row = $ProductType2->fetchRow($select);		
		$this->view->rowElement = $row;			
		$this->view->rowElementType2 = $row;	

		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_type2name_".$v['idp2']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_type2name_".$v['idp2']."', '".$row->product_type2_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_type2name_".$v['idp2']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_type2description_".$v['idp2']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_type2description_".$v['idp2']."', '".$row->product_type2_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_type2description_".$v['idp2']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function productedittypeaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/type/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function productedittypephotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/type/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function productedittyperemoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedittype';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductType = new ProductType();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_type_id = ?' => $v['idp']
		);
		$ProductType->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('productedittype','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	public function productedittype2removeAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedittype';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductType2 = new ProductType2();
		$where = array(
			'product_type_id = ?' => $v['idp'],
			'product_type2_id = ?' => $v['idp2']
		);
		$ProductType2->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('productedittypeedit','admin',null,array('id' => $v['id'],'idp' => $v['idp']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function producteditaccessoriesAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['color_schema']) ){
		
			$f = new Lib_Color();
			$f->changeColorSchema($v['id'],$v['color_schema_id'],4);
			$data = array(
				'color_schema_id5' => 0 //$v['color_schema_id']
			);
			$Product->update($data, 'product_id='.$v['id']);
			
			$this->_helper->redirector('producteditaccessories','admin',null,array('id' => $v['id']));				
		}
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductAccessories = new ProductAccessories();
		
		$data1 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '0' AND product_id = ".$v['id'] , 'product_accessories_name ASC'); 		
		$this->view->dataTable = $data1;	
		
		$data2 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '1' AND product_id = ".$v['id'] , 'product_accessories_name ASC'); 			
		$this->view->dataTable1 = $data2;	
		
		$data3 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '2' AND product_id = ".$v['id'] , 'product_accessories_name ASC'); 			
		$this->view->dataTable2 = $data3;	
		
		$data4 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '3' AND product_id = ".$v['id'] , 'product_accessories_name ASC'); 			
		$this->view->dataTable3 = $data4;	


			
		$ColorSchema = new ColorSchema();	
		$data = $ColorSchema->fetchAll('color_schema_type = 4', 'color_schema_name ASC'); 		
		$this->view->ColorSchema = $data;		
	}
	
	
	public function producteditaccessoriesaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditaccessories';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductAccessories = new ProductAccessories();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_accessories_name' => $v['product_name'],
				'product_accessories_code' => $v['product_code'],
				'product_accessories_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_accessories_price' => $v['product_price']
			);
			$idIns = $ProductAccessories->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('producteditaccessoriesedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	public function producteditaccessoriesdefaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductAccessories = new ProductAccessories();
		
		$select = $ProductAccessories->select();		
		$select->where('product_accessories_id = ?', $v['idp']);	
		$row = $ProductAccessories->fetchRow($select);
		
			
		$zap = "UPDATE `product_accessories` SET product_accessories_default='0' WHERE product_id = '".$v['id']."' AND product_accessories_typeaccessories = '".$row->product_accessories_typeaccessories."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_accessories` SET product_accessories_default='1' WHERE product_accessories_id = '".$v['idp']."' AND  product_id = '".$v['id']."' AND product_accessories_typeaccessories = '".$row->product_accessories_typeaccessories."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('producteditaccessories','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function producteditaccessorieseditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditaccessories';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductAccessories = new ProductAccessories();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_accessories_typeaccessories' => isset($v['product_typeaccessories'])?$v['product_typeaccessories']:0,
				'product_accessories_name' => $v['product_name'],
				'product_accessories_code' => $v['product_code'],
				'product_accessories_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_accessories_price' => $v['product_price']
			);
			$ProductAccessories->update( $data , 'product_accessories_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_accessoriesname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_accessoriesdescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('producteditaccessoriesedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductAccessories = new ProductAccessories();
		
		$select = $ProductAccessories->select();		
		$select->where('product_accessories_id = ?', $v['idp']);	
		$row = $ProductAccessories->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_accessoriesname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_accessoriesname_".$v['idp']."', '".$row->product_accessories_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_accessoriesname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_accessoriesdescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_accessoriesdescription_".$v['idp']."', '".$row->product_accessories_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_accessoriesdescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function producteditaccessoriesaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/accessories/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function producteditaccessoriesphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/accessories/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function producteditaccessoriesremoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditaccessories';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductAccessories = new ProductAccessories();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_accessories_id = ?' => $v['idp']
		);
		$ProductAccessories->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('producteditaccessories','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function producteditlegsAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductLegs = new ProductLegs();
		
		$data = $ProductLegs->fetchAll('product_id = '.$v['id'] , 'product_legs_name ASC'); 		
		$this->view->dataTable = $data;		
	}
	
	
	public function producteditlegsaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditlegs';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductLegs = new ProductLegs();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_legs_name' => $v['product_name'],
				'product_legs_code' => $v['product_code'],
				'product_legs_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_legs_price' => $v['product_price']
			);
			$idIns = $ProductLegs->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('producteditlegsedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	public function producteditlegsdefaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductLegs = new ProductLegs();
		
		$select = $ProductLegs->select();		
		$select->where('product_legs_id = ?', $v['idp']);	
		$row = $ProductLegs->fetchRow($select);
		
			
		$zap = "UPDATE `product_legs` SET product_legs_default='0' WHERE product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_legs` SET product_legs_default='1' WHERE product_legs_id = '".$v['idp']."' AND  product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('producteditlegs','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function producteditlegseditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditlegs';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductLegs = new ProductLegs();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_legs_name' => $v['product_name'],
				'product_legs_code' => $v['product_code'],
				'product_legs_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_legs_price' => $v['product_price']
			);
			$ProductLegs->update( $data , 'product_legs_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_legsname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_legsdescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('producteditlegsedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductLegs = new ProductLegs();
		
		$select = $ProductLegs->select();		
		$select->where('product_legs_id = ?', $v['idp']);	
		$row = $ProductLegs->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_legsname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_legsname_".$v['idp']."', '".$row->product_legs_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_legsname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_legsdescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_legsdescription_".$v['idp']."', '".$row->product_legs_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_legsdescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function producteditlegsaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/legs/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function producteditlegsphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/legs/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function producteditlegsremoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditlegs';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductLegs = new ProductLegs();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_legs_id = ?' => $v['idp']
		);
		$ProductLegs->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('producteditlegs','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function productedithandlesAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['color_schema']) ){
		
			$f = new Lib_Color();
			$f->changeColorSchema($v['id'],$v['color_schema_id'],3);
			$data = array(
				'color_schema_id4' => $v['color_schema_id']
			);
			$Product->update($data, 'product_id='.$v['id']);
			
			$this->_helper->redirector('productedithandles','admin',null,array('id' => $v['id']));				
		}
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductHandles = new ProductHandles();
		
		$data = $ProductHandles->fetchAll('product_id = '.$v['id'] , 'product_handles_name ASC'); 		
		$this->view->dataTable = $data;		


			
		$ColorSchema = new ColorSchema();	
		$data = $ColorSchema->fetchAll('color_schema_type = 3', 'color_schema_name ASC'); 		
		$this->view->ColorSchema = $data;	
	}
	
	
	public function productedithandlesaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedithandles';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductHandles = new ProductHandles();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_handles_name' => $v['product_name'],
				'product_handles_code' => $v['product_code'],
				'product_handles_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_handles_price' => $v['product_price']
			);
			$idIns = $ProductHandles->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('productedithandlesedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	public function productedithandlesdefaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ProductHandles = new ProductHandles();
		
		$select = $ProductHandles->select();		
		$select->where('product_handles_id = ?', $v['idp']);	
		$row = $ProductHandles->fetchRow($select);
		
			
		$zap = "UPDATE `product_handles` SET product_handles_default='0' WHERE product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$zap = "UPDATE `product_handles` SET product_handles_default='1' WHERE product_handles_id = '".$v['idp']."' AND  product_id = '".$v['id']."' ";
		$db->query($zap);
		
		$information->addSuccess = true; 
		$this->_helper->redirector('productedithandles','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function productedithandleseditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedithandles';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductHandles = new ProductHandles();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_handles_typehandles' => isset($v['product_typehandles'])?$v['product_typehandles']:0,
				'product_handles_name' => $v['product_name'],
				'product_handles_code' => $v['product_code'],
				'product_handles_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_handles_price' => $v['product_price']
			);
			$ProductHandles->update( $data , 'product_handles_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_handlesname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_handlesdescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('productedithandlesedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductHandles = new ProductHandles();
		
		$select = $ProductHandles->select();		
		$select->where('product_handles_id = ?', $v['idp']);	
		$row = $ProductHandles->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_handlesname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_handlesname_".$v['idp']."', '".$row->product_handles_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_handlesname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_handlesdescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_handlesdescription_".$v['idp']."', '".$row->product_handles_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_handlesdescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function productedithandlesaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/handles/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function productedithandlesphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/handles/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function productedithandlesremoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'productedithandles';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductHandles = new ProductHandles();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_handles_id = ?' => $v['idp']
		);
		$ProductHandles->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('productedithandles','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function producteditoptionsAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductOptions = new ProductOptions();
		
		$data = $ProductOptions->fetchAll('product_id = '.$v['id'] , 'product_options_name ASC'); 		
		$this->view->dataTable = $data;		
	}
	
	
	public function producteditoptionsaddAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditoptions';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductOptions = new ProductOptions();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_options_name' => $v['product_name'],
				'product_options_code' => $v['product_code'],
				'product_options_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_options_price' => $v['product_price']
			);
			$idIns = $ProductOptions->insert($data);
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('producteditoptionsedit','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		
	}
	
	
	public function producteditoptionseditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditoptions';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		if( $information->addSuccess ){
			$this->view->addSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ProductOptions = new ProductOptions();		
				
		if( isset($v['admin_add']) ){
		
			$data = array(
				'product_id' => $v['id'],
				'product_options_name' => $v['product_name'],
				'product_options_code' => $v['product_code'],
				'product_options_image' => isset($v['product_image'])?$v['product_image']:'',
				'product_options_price' => $v['product_price']
			);
			$ProductOptions->update( $data , 'product_options_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_optionsname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'product_optionsdescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			$information->addSuccess = true; 
			$this->_helper->redirector('producteditoptionsedit','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->rowProduct = $row;
		
		$ProductOptions = new ProductOptions();
		
		$select = $ProductOptions->select();		
		$select->where('product_options_id = ?', $v['idp']);	
		$row = $ProductOptions->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_optionsname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_optionsname_".$v['idp']."', '".$row->product_options_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_optionsname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_optionsdescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_optionsdescription_".$v['idp']."', '".$row->product_options_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'product_optionsdescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function producteditoptionsaddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/options/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_product'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function producteditoptionsphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/options/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	public function producteditoptionsremoveAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditoptions';
		$Product = new Product();	
		
		$select = $Product->select();		
		$select->where('product_id = ?', $v['id']);	
		$row = $Product->fetchRow($select);
		
		$this->view->ProductInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductOptions = new ProductOptions();
		$where = array(
			'product_id = ?' => $v['id'],
			'product_options_id = ?' => $v['idp']
		);
		$ProductOptions->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('producteditoptions','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function clientAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}		

		$where = null;
		
		
		
		
		
		if( isset($v['client_email']) ){
			$key = 'client_email';
			$pole = $v[$key];
			
			if( $where != null ) $where = $where." AND client_login LIKE '%".$pole."%'";
			else $where = "client_login LIKE '%".$pole."%'";
		
			$searchFilter[$key] = $pole;
		}
		
		if( isset($v['client_name']) ){
			$key = 'client_name';
			$pole = $v[$key];
			
			if( $where != null ) $where = $where." AND (client_company LIKE '%".$pole."%' OR client_firstname LIKE '%".$pole."%' OR client_secondname LIKE '%".$pole."%')";
			else $where = "(client_company LIKE '%".$pole."%' OR client_firstname LIKE '%".$pole."%' OR client_secondname LIKE '%".$pole."%')";
		
			$searchFilter[$key] = $pole;
		}
		
		
		if( isset($v['client_adress']) ){
			$key = 'client_adress';
			$pole = $v[$key];
			
			if( $where != null ) $where = $where." AND client_address LIKE '%".$pole."%'";
			else $where = "client_address LIKE '%".$pole."%'";
		
			$searchFilter[$key] = $pole;
		}
		
		
		if( isset($v['client_city']) ){
			$key = 'client_city';
			$pole = $v[$key];
			
			if( $where != null ) $where = $where." AND client_city LIKE '%".$pole."%'";
			else $where = "client_city LIKE '%".$pole."%'";
		
			$searchFilter[$key] = $pole;
		}
		
		
		
		$this->view->searchFilter = $searchFilter;		
		
		
		
		$limit = 50;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Client = new Client();	
		$dataCount = count($Client->fetchAll($where , 'client_ins DESC')); 
			$p = ($page-1)*$limit;		
		$data = $Client->fetchAll($where , 'client_ins DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('client');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	public function clientremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('client','admin');
		}			
		
		$Client = new Client();
		
		$select = $Client->select();			
		$where = array(
			'client_id = ?' => $v['id']
		);
		$Client->delete($where);
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('client','admin');		
	}
	
	public function clienteditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->editClientSuccess ){
			$this->view->editClientSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$Client = new Client();		
		
		$v = $this->_request->getParams();
		
		if( isset($v['admin_editclient']) ){
			$data = array(
				'client_company' => isset($v['client_company'])?$v['client_company']:'',
				'client_nip' => isset($v['client_nip'])?$v['client_nip']:'',
				'client_type' => isset($v['client_type'])?$v['client_type']:0,
				'client_firstname' => $v['client_firstname'],
				'client_secondname' => $v['client_secondname'],
				'client_address' => $v['client_address'],
				'client_zipcode' => $v['client_zipcode'],
				'client_city' => $v['client_city'],
				'client_country' => $v['client_country'],
				'client_phone' => $v['client_phone'],
				'client_edit' => Lib_Date::datetime(),
				'client_info' => isset($v['client_info'])?$v['client_info']:'',
				'client_opinion' => isset($v['client_opinion'])?$v['client_opinion']:0,
				'client_rabat_1' => isset($v['client_rabat_1'])?$v['client_rabat_1']:1,
				'client_rabat_2' => isset($v['client_rabat_2'])?$v['client_rabat_2']:1,
				'client_rabat_3' => isset($v['client_rabat_3'])?$v['client_rabat_3']:1,
				'client_rabat_4' => isset($v['client_rabat_4'])?$v['client_rabat_4']:1,
				'client_rabat_5' => isset($v['client_rabat_5'])?$v['client_rabat_5']:1
			);
			$Client->update( $data , 'client_id='.$v['id'] );
						
			$information->editClientSuccess = true; 
			$this->_helper->redirector('clientedit','admin',null,array('id' => $v['id']));
		}		
		
		$select = $Client->select();		
		$select->where('client_id = ?', $v['id']);	
		$row = $Client->fetchRow($select);
		//var_dump($row);
		$this->view->rowClient = $row;
		//$this->_helper->viewRenderer->setNoRender();
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function orderAction() {
		$db = Zend_Registry::get('db');	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 50;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Order = new Order();	
		
		
		
			
		$select = $db->select();
		$select->from('order')->join('client', 'client.client_id = order.client_id');		
		$select->order(array('order_ins DESC'));//->limit($limit,$p);
		$stmt = $db->query($select);
		$dataCount = count($stmt->fetchAll()); 
			
		$p = ($page-1)*$limit;	
			
		$select = $db->select();
		$select->from('order')->join('client', 'client.client_id = order.client_id');		
		$select->order(array('order_ins DESC'))->limit($limit,$p);
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();
		//$data = $Order->fetchAll(null , 'order_ins DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('order');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	public function ordereditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->editOrderSuccess ){
			$this->view->editOrderSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addOrderFileSuccess ){
			$this->view->addOrderFileSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->removeOrderFileSuccess ){
			$this->view->removeOrderFileSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$Order = new Order();
		$Client = new Client();		
		$OrderFile = new OrderFile();
		
		$v = $this->_request->getParams();
		
		if( isset($v['order_status']) ){
			$data = array(
				'order_status' => $v['order_status'],
				'order_status_2' => $v['order_status_2'],
				'order_pay' => $v['order_pay'],
				'order_datasend' => isset($v['order_datasend'])?$v['order_datasend']:'0000-00-00',
				'order_nr' => isset($v['order_nr'])?$v['order_nr']:'',
				'order_infoshop' => isset($v['order_infoshop'])?$v['order_infoshop']:'',
				'order_infoshop_insite' => isset($v['order_infoshop_insite'])?$v['order_infoshop_insite']:''
			);
			$Order->update( $data , 'order_id='.$v['id'] );
						
			$information->editOrderSuccess = true; 
			$this->_helper->redirector('orderedit','admin',null,array('id' => $v['id']));
		}		
		
		
		if( isset($v['order_file_submit']) ){	
		
			
		// ===========================================================================	
			if( $_FILES["order_file"]["tmp_name"] ){
			
		
			$upload_path = "orderfile/";
			$filename_name = $v['id'].'_'.hash('sha256',$admin->admin_id.time().rand(0,100000));
			move_uploaded_file($_FILES["order_file"]["tmp_name"], $upload_path.$filename_name);
			
			$data = array(
				'order_id' => $v['id'],
				'order_file_filename' => $_FILES["order_file"]["name"],
				'order_file_filesize' => $_FILES["order_file"]["size"],
				'order_file_filetype' => $_FILES["order_file"]["type"],
				'order_file_file' => $filename_name,
				'order_file_ins' => Lib_Date::datetime()
			);
			$idInsDA = $OrderFile->insert($data);
			
						
			$information->addOrderFileSuccess = true; 
			$this->_helper->redirector('orderedit','admin',null,array('id' => $v['id']));
			
			
			}
		// ===========================================================================
		
		}
		
		$select = $Order->select();		
		$select->where('order_id = ?', $v['id']);	
		$row = $Order->fetchRow($select);
		$this->view->rowOrder = $row;
		
			
		$select = $db->select();
		$select->from('order_product')->join('product', 'product.product_id = order_product.product_id');		
		$select->where('order_product.order_id = '.$v['id']);//->limit($limit,$p);
		$select->order(array('order_product_id DESC'));//->limit($limit,$p);
		$stmt = $db->query($select);
		$data = $stmt->fetchAll(); 
		$this->view->dataProductOrder = $data;	
		
			
		$select = $db->select();
		$select->from('order_file');		
		$select->where('order_file.order_id = '.$v['id']);//->limit($limit,$p);
		$select->order(array('order_file_id DESC'));//->limit($limit,$p);
		$stmt = $db->query($select);
		$data = $stmt->fetchAll(); 
		$this->view->dataOrderFile = $data;	
		
		
		$select = $Client->select();		
		$select->where('client_id = ?', $row->client_id);	
		$row = $Client->fetchRow($select);
		$this->view->rowClient = $row;		
	}
	
	public function orderfileopenAction(){
		$admin = new Zend_Session_Namespace('admin');
		$v = $this->_request->getParams();
		$information = new Zend_Session_Namespace('information');
		
		$OrderFile = new OrderFile();
		$select = $OrderFile->select();
		$select->where('order_file_id = ?', $v['id']);	
		$row = $OrderFile->fetchRow($select);
		
		if ( isset($row->order_file_file) ) { 			
		
			$file = 'orderfile/'.$row->order_file_file;
			header('Content-Type: '.$row->order_file_filetype);
			header('Content-Disposition: inline; filename="'.$row->order_file_filename.'"');
			header('Content-Length: '.filesize($file));	
	
			ob_clean();
			flush();
			@readfile($file);
			exit;
		}else{
			$this->_helper->redirector('index','admin');			
		}
		
        $this->_helper->viewRenderer->setNoRender();
	}
	
	public function orderfileremoveAction(){
		$admin = new Zend_Session_Namespace('admin');
		$v = $this->_request->getParams();
		$information = new Zend_Session_Namespace('information');
		
		$OrderFile = new OrderFile();			
		$where = array(
			'order_file_id = ?' => $v['idf']
		);
		$OrderFile->delete($where);
		
		$information->removeOrderFileSuccess = true; 
		$this->_helper->redirector('orderedit','admin',null,array('id' => $v['id']));;	
		
        $this->_helper->viewRenderer->setNoRender();
	}
	
	public function ordereditproductAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
	
		$select = $db->select();
		$select->from('order_product');		
		$select->where('order_product.order_product_id = '.$v['order_product_id']);
		$select->where('order_product.product_id = '.$v['product_id']);
		$stmt = $db->query($select);
		$data = $stmt->fetchAll(); 
		
		$this->view->product = $data[0];	
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function contentAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Content = new Content();	
		$dataCount = count($Content->fetchAll(null , 'content_short ASC')); 
			$p = ($page-1)*$limit;		
		$data = $Content->fetchAll(null , 'content_short ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('content');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	public function contenteditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->editContentSuccess ){
			$this->view->editContentSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$Content = new Content();		
		
		$v = $this->_request->getParams();
		
		if( isset($v['admin_editcontent']) ){
			$data = array(
				'content_short' => $v['content_short'],
				'content_mt_title' => $v['content_mt_title'],
				'content_mt_description' => $v['content_mt_description'],
				'content_mt_keywords' => $v['content_mt_keywords']
			);
			$Content->update( $data , 'content_id='.$v['id'] );
			
			foreach( $v['content_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'content_name_".$v['id']."' AND language_panel LIKE 'contents' ";

				$db->query($zap);
			
			}
			
			foreach( $v['content_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'content_description_".$v['id']."' AND language_panel LIKE 'contents' ";

				$db->query($zap);
			
			}
						
			$information->editContentSuccess = true; 
			$this->_helper->redirector('contentedit','admin',null,array('id' => $v['id']));	

		}		
		
		$select = $Content->select();		
		$select->where('content_id = ?', $v['id']);	
		$row = $Content->fetchRow($select);
		
		$this->view->rowContent = $row;
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'content_name_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('contents', 'content_name_".$v['id']."', '".$row->content_short."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'content_name_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'content_description_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('contents', 'content_description_".$v['id']."', '".$row->content_short."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'content_description_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	
	
	
	
	
	
	public function colorAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 100;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Color = new Color();	
		$dataCount = count($Color->fetchAll(null , 'color_name ASC')); 
			$p = ($page-1)*$limit;		
		$data = $Color->fetchAll(null , 'color_name ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('color');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	
	
	
	
	
	
	public function colorschemaAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$ColorSchema = new ColorSchema();	
		$dataCount = count($ColorSchema->fetchAll(null , 'color_schema_name ASC')); 
			$p = ($page-1)*$limit;		
		$data = $ColorSchema->fetchAll(null , 'color_schema_name ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('colorschema');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	
	
	
	
	
	
	public function coloraddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Color = new Color();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addcolor']) ){
		
			$data = array(
				'color_name' => $v['color_name'],
				'color_img' => isset($v['product_image'])?$v['product_image']:'',
				'category_id' => $v['category_id4']
			);
			$idIns = $Color->insert($data);
			
			$information->addProductSuccess = true; 
			$this->_helper->redirector('coloredit','admin',null,array('id' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
	}
	
	public function colorschemaaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ColorSchema = new ColorSchema();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addcolorschema']) ){
		
			$data = array(
				'color_schema_name' => $v['color_schema_name'],
				'color_schema_type' => $v['color_schema_type']
			);
			$idIns = $ColorSchema->insert($data);
			
			$information->addProductSuccess = true; 
			$this->_helper->redirector('colorschemaedit','admin',null,array('id' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
	}
	
	public function colorschemaeditAction() {	
		$v = $this->_request->getParams();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$ColorSchema = new ColorSchema();	
		
		if( isset($v['admin_editcolorschema']) ){		
			$data = array(
				'color_schema_name' => $v['color_schema_name']
			);
			$ColorSchema->update($data, 'color_schema_id='.$v['id']);
			
			$information->editProductSuccess = true; 
			$this->_helper->redirector('colorschemaedit','admin',null,array('id' => $v['id']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		$this->view->rowColorSchema = $row;
		
		
		if( $row['color_schema_type'] == 0 ){
			// body - korpus
			$ColorSchemaProduct = new ColorSchemaProductBody();		
			$data = $ColorSchemaProduct->fetchAll('color_schema_id = '.$row['color_schema_id'], "color_schema_product_body_name ASC");
			$this->view->dataCSP = $data;			
		}
		
		if( $row['color_schema_type'] == 1 ){
			// front
			$ColorSchemaProduct = new ColorSchemaProductFront();		
			$data = $ColorSchemaProduct->fetchAll('color_schema_id = '.$row['color_schema_id'], "color_schema_product_front_name ASC");
			$this->view->dataCSP = $data;			
		}
		
		if( $row['color_schema_type'] == 2 ){
			// typy
			$ColorSchemaProduct = new ColorSchemaProductType();		
			$data = $ColorSchemaProduct->fetchAll('color_schema_id = '.$row['color_schema_id'], "color_schema_product_type_name ASC");
			$this->view->dataCSP = $data;			
		}
		
		if( $row['color_schema_type'] == 3 ){
			// uchwyty
			$ColorSchemaProduct = new ColorSchemaProductHandles();		
			$data = $ColorSchemaProduct->fetchAll('color_schema_id = '.$row['color_schema_id'], "color_schema_product_handles_name ASC");
			$this->view->dataCSP = $data;			
		}
		
		if( $row['color_schema_type'] == 4 ){
			// akcesoria
			$ColorSchemaProduct = new ColorSchemaProductAccessories();		
			$data = $ColorSchemaProduct->fetchAll('color_schema_id = '.$row['color_schema_id'], "color_schema_product_accessories_name ASC");
			$this->view->dataCSP = $data;			
		}
	}
	
	
	public function colorschemaeditaddcolorAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		
		$ColorSchema = new ColorSchema();	
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		$this->view->ColorSchemaInfo = $row;
		
		if( $row['color_schema_type'] == 0 ){
			$SchemaType = 'body';
		}
		if( $row['color_schema_type'] == 1 ){
			$SchemaType = 'front';
		}
		if( $row['color_schema_type'] == 2 ){
			$SchemaType = 'type';
		}
		if( $row['color_schema_type'] == 3 ){
			$SchemaType = 'handles';
		}
		if( $row['color_schema_type'] == 4 ){
			$SchemaType = 'accessories';
		}
		$this->view->SchemaType = $SchemaType;
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
			
				
		if( isset($v['admin_add']) ){
		
			if( $row['color_schema_type'] == 0 ){
				$ColorSchemaProductBody = new ColorSchemaProductBody();	
				$data = array(
					'color_schema_id' => $v['id'],
					'color_schema_product_body_name' => $v['product_name'],
					'color_schema_product_body_code' => $v['product_code'],
					'color_schema_product_body_image' => isset($v['product_image'])?$v['product_image']:'',
					'color_schema_product_body_price' => $v['product_price'],
					'color_schema_product_body_lead_time' => isset($v['product_leadtime'])?$v['product_leadtime']:0
				);
				$idIns = $ColorSchemaProductBody->insert($data);
			}
			
			if( $row['color_schema_type'] == 1 ){
				$ColorSchemaProductFront = new ColorSchemaProductFront();	
				$data = array(
					'color_schema_id' => $v['id'],
					'color_schema_product_front_name' => $v['product_name'],
					'color_schema_product_front_code' => $v['product_code'],
					'color_schema_product_front_image' => isset($v['product_image'])?$v['product_image']:'',
					'color_schema_product_front_price' => $v['product_price'],
					'color_schema_product_front_lead_time' => isset($v['product_leadtime'])?$v['product_leadtime']:0
				);
				$idIns = $ColorSchemaProductFront->insert($data);			
			}
			
			if( $row['color_schema_type'] >= 2 ){
			
				if( $row['color_schema_type'] == 2 ) $ColorSchemaProduct_Schema = new ColorSchemaProductType();	
				if( $row['color_schema_type'] == 3 ) $ColorSchemaProduct_Schema = new ColorSchemaProductHandles();	
				if( $row['color_schema_type'] == 4 ) $ColorSchemaProduct_Schema = new ColorSchemaProductAccessories();	
				
				$data = array(
					'color_schema_id' => $v['id'],
					'color_schema_product_'.$SchemaType.'_name' => $v['product_name'],
					'color_schema_product_'.$SchemaType.'_code' => $v['product_code'],
					'color_schema_product_'.$SchemaType.'_image' => isset($v['product_image'])?$v['product_image']:'',
					'color_schema_product_'.$SchemaType.'_price' => $v['product_price']
				);
				$idIns = $ColorSchemaProduct_Schema->insert($data);			
			}
			
			$information->addSuccess = true; 
			//$this->_helper->redirector('productedit','admin',null,array('id' => $idIns));	
			$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		$this->view->rowColorSchema = $row;
		
		
	}
	
	
	public function colorschemaediteditcolortype2addAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		
		$ColorSchema = new ColorSchema();
		$ColorSchemaProductType = new ColorSchemaProductType();	
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);		
		$this->view->ColorSchemaInfo = $row;
		
		$select = $ColorSchemaProductType->select();		
		$select->where('color_schema_product_type_id = ?', $v['idp']);	
		$row = $ColorSchemaProductType->fetchRow($select);		
		$this->view->ColorSchemaProductTypeInfo = $row;		
		
		
		$SchemaType = 'type2';		
		$this->view->SchemaType = $SchemaType;
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
			
				
		if( isset($v['admin_add']) ){
			
			$ColorSchemaProduct_Schema = new ColorSchemaProductType2();	
				
			$data = array(
				'color_schema_product_type_id' => $v['idp'],
				'color_schema_product_'.$SchemaType.'_name' => $v['product_name'],
				'color_schema_product_'.$SchemaType.'_code' => $v['product_code'],
				'color_schema_product_'.$SchemaType.'_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_'.$SchemaType.'_price' => $v['product_price']
			);
			$idIns = $ColorSchemaProduct_Schema->insert($data);		
			
			$this->_helper->redirector('colorschemaediteditcolortype2edit','admin',null,array('id' => $v['id'], 'idp' => $v['idp'], 'idp2' => $idIns));	
		}
			
		
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		$this->view->rowColorSchema = $row;
		
		
	}
	
	
	public function colorschemaediteditcolorAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$ColorSchema = new ColorSchema();	
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$rowColorSchemaInfo = $ColorSchema->fetchRow($select);
		
		$this->view->ColorSchemaInfo = $rowColorSchemaInfo;		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		
		
		
		
		if( $rowColorSchemaInfo['color_schema_type'] == 0 ){
		// =========================================================================================================
		// body - korpus
		
		
		$MapFiltrBody = new MapFiltrBody();	
		
		$dataMapFiltrBody = $MapFiltrBody->fetchAll(); 		
		$this->view->dataTableMapFiltrBody = $dataMapFiltrBody;
		
		
		
		
		$ColorSchemaProductBody = new ColorSchemaProductBody();
		
		
		if( isset($v['admin_add']) ){
		
			$data = array(
				'color_schema_id' => $v['id'],
				'color_schema_product_body_typebody' => isset($v['product_typebody'])?$v['product_typebody']:0,
				'color_schema_product_body_option1' => isset($v['product_option1'])?$v['product_option1']:0,
				'color_schema_product_body_option2' => isset($v['product_option2'])?$v['product_option2']:0,
				'color_schema_product_body_option3' => isset($v['product_option3'])?$v['product_option3']:0,
				'color_schema_product_body_option4' => isset($v['product_option4'])?$v['product_option4']:0,
				'color_schema_product_body_option5' => isset($v['product_option5'])?$v['product_option5']:0,
				'color_schema_product_body_option6' => isset($v['product_option6'])?$v['product_option6']:0,
				'color_schema_product_body_option7' => isset($v['product_option7'])?$v['product_option7']:0,
				'color_schema_product_body_option8' => isset($v['product_option8'])?$v['product_option8']:0,
				'color_schema_product_body_name' => $v['product_name'],
				'color_schema_product_body_code' => $v['product_code'],
				'color_schema_product_body_type' => isset($v['product_type'])?$v['product_type']:0,
				'color_schema_product_body_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_body_price' => $v['product_price'],
				'color_schema_product_body_lead_time' => isset($v['product_leadtime'])?$v['product_leadtime']:0
			);
			$ColorSchemaProductBody->update( $data , 'color_schema_product_body_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_bodyname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_bodydescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
			//$information->addSuccess = true; 
			$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}		
		
		
		
		
		
		
		
		
		$select = $ColorSchemaProductBody->select();		
		$select->where('color_schema_product_body_id = ?', $v['idp']);	
		$row = $ColorSchemaProductBody->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodyname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_bodyname_".$v['idp']."', '".$row->color_schema_product_body_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodyname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodydescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_bodydescription_".$v['idp']."', '".$row->color_schema_product_body_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodydescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;		
		
		// =========================================================================================================
		
		
		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchemaInfo['color_schema_type'] == 1 ){	
		// =========================================================================================================
		// front
		
		$MapFiltrFront = new MapFiltrFront();	
		
		$dataMapFiltrFront = $MapFiltrFront->fetchAll(); 		
		$this->view->dataTableMapFiltrFront = $dataMapFiltrFront;
		
		$ColorSchemaProductFront = new ColorSchemaProductFront();
		
		
		
		if( isset($v['admin_add']) ){
		
			$data = array(
				'color_schema_id' => $v['id'],
				'color_schema_product_front_option1' => isset($v['product_option1'])?$v['product_option1']:0,
				'color_schema_product_front_option2' => isset($v['product_option2'])?$v['product_option2']:0,
				'color_schema_product_front_option3' => isset($v['product_option3'])?$v['product_option3']:0,
				'color_schema_product_front_option4' => isset($v['product_option4'])?$v['product_option4']:0,
				'color_schema_product_front_option5' => isset($v['product_option5'])?$v['product_option5']:0,
				'color_schema_product_front_option6' => isset($v['product_option6'])?$v['product_option6']:0,
				'color_schema_product_front_option7' => isset($v['product_option7'])?$v['product_option7']:0,
				'color_schema_product_front_option8' => isset($v['product_option8'])?$v['product_option8']:0,
				'color_schema_product_front_option9' => isset($v['product_option9'])?$v['product_option9']:0,
				'color_schema_product_front_option10' => isset($v['product_option10'])?$v['product_option10']:0,
				'color_schema_product_front_option11' => isset($v['product_option11'])?$v['product_option11']:0,
				'color_schema_product_front_option12' => isset($v['product_option12'])?$v['product_option12']:0,
				'color_schema_product_front_option13' => isset($v['product_option13'])?$v['product_option13']:0,
				'color_schema_product_front_option14' => isset($v['product_option14'])?$v['product_option14']:0,
				'color_schema_product_front_option15' => isset($v['product_option15'])?$v['product_option15']:0,
				'color_schema_product_front_name' => $v['product_name'],
				'color_schema_product_front_code' => $v['product_code'],
				'color_schema_product_front_type' => isset($v['product_type'])?$v['product_type']:0,
				'color_schema_product_front_type_2' => isset($v['product_type_2'])?$v['product_type_2']:0,
				'color_schema_product_front_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_front_price' => $v['product_price'],
				'color_schema_product_front_lead_time' => isset($v['product_leadtime'])?$v['product_leadtime']:0
			);
			$ColorSchemaProductFront->update( $data , 'color_schema_product_front_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_frontname_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_frontdescription_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
			
			//$information->addSuccess = true; 
			$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}
		
		
		
		
		
		
		$select = $ColorSchemaProductFront->select();		
		$select->where('color_schema_product_front_id = ?', $v['idp']);	
		$row = $ColorSchemaProductFront->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontname_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_frontname_".$v['idp']."', '".$row->color_schema_product_front_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontname_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontdescription_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_frontdescription_".$v['idp']."', '".$row->color_schema_product_front_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontdescription_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;	
		
		
		// =========================================================================================================
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchemaInfo['color_schema_type'] == 2 ){	
		// =========================================================================================================
		// typy
		
		$schemaName = 'type';
		$ColorSchema_Model = new ColorSchemaProductType();
		
		
		
		if( isset($v['admin_add']) ){
		
			$data = array(
				'color_schema_id' => $v['id'],
				'color_schema_product_'.$schemaName.'_name' => $v['product_name'],
				'color_schema_product_'.$schemaName.'_code' => $v['product_code'],
			//	'color_schema_product_'.$schemaName.'_type' => isset($v['product_type'])?$v['product_type']:0,
				'color_schema_product_'.$schemaName.'_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_'.$schemaName.'_price' => $v['product_price']
			);
			$ColorSchema_Model->update( $data , 'color_schema_product_'.$schemaName.'_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
			
			//$information->addSuccess = true; 
			$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}
		
		
		
		
		
		
		$select = $ColorSchema_Model->select();		
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $v['idp']);	
		$row = $ColorSchema_Model->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."name_".$v['idp']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."description_".$v['idp']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;	
		
		
		
		
		$ColorSchemaProduct = new ColorSchemaProductType2();		
		$data = $ColorSchemaProduct->fetchAll('color_schema_product_type_id = '.$v['idp'], "color_schema_product_type2_name ASC");
		$this->view->dataTableProductType2 = $data;	
		
		
		
		
		
		
		// =========================================================================================================
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchemaInfo['color_schema_type'] == 3 ){
		// =========================================================================================================
		// uchwyty
		
		$schemaName = 'handles';
		$ColorSchema_Model = new ColorSchemaProductHandles();
		
		
		
		if( isset($v['admin_add']) ){
		
			$data = array(
				'color_schema_id' => $v['id'],
				'color_schema_product_'.$schemaName.'_name' => $v['product_name'],
				'color_schema_product_'.$schemaName.'_code' => $v['product_code'],
				'color_schema_product_'.$schemaName.'_type' => isset($v['product_type'])?$v['product_type']:0,
				'color_schema_product_'.$schemaName.'_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_'.$schemaName.'_price' => $v['product_price']
			);
			$ColorSchema_Model->update( $data , 'color_schema_product_'.$schemaName.'_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
			
			//$information->addSuccess = true; 
			$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}
		
		
		
		
		
		
		
		$select = $ColorSchema_Model->select();		
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $v['idp']);	
		$row = $ColorSchema_Model->fetchRow($select);
				
		$this->view->rowElement = $row;
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."name_".$v['idp']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."description_".$v['idp']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;	
		
		
		// =========================================================================================================
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchemaInfo['color_schema_type'] == 4 ){
		// =========================================================================================================
		// akcesoria
		
		$schemaName = 'accessories';
		$ColorSchema_Model = new ColorSchemaProductAccessories();
		
		
		if( isset($v['admin_add']) ){
		
			$data = array(
				'color_schema_id' => $v['id'],
				'color_schema_product_'.$schemaName.'_name' => $v['product_name'],
				'color_schema_product_'.$schemaName.'_code' => $v['product_code'],
				'color_schema_product_'.$schemaName.'_type' => isset($v['product_type'])?$v['product_type']:0,
				'color_schema_product_'.$schemaName.'_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_'.$schemaName.'_price' => $v['product_price']
			);
			$ColorSchema_Model->update( $data , 'color_schema_product_'.$schemaName.'_id='.$v['idp'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
			
			//$information->addSuccess = true; 
			$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
			//$this->_helper->redirector('product','admin');	
			
		}
		
		
		
		
		
		
		$select = $ColorSchema_Model->select();		
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $v['idp']);	
		$row = $ColorSchema_Model->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."name_".$v['idp']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."description_".$v['idp']."', '".$row->{color_schema_product_.$schemaName._name}."');";
				
				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			
			}


		//	var_dump($dataLangTra);
		//	die('p_11_'.rand(0,10000));
			
		
		}
		
		$this->view->dataLang = $dataLangTra;	
		
		
		// =========================================================================================================
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		$this->view->rowColorSchema = $row;
		
		
	}	
	
	
	public function colorschemaediteditcolortype2editAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		
		$ColorSchema = new ColorSchema();	
		$ColorSchemaProductType = new ColorSchemaProductType();	
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$rowColorSchemaInfo = $ColorSchema->fetchRow($select);		
		$this->view->ColorSchemaInfo = $rowColorSchemaInfo;	
		
		$select = $ColorSchemaProductType->select();		
		$select->where('color_schema_product_type_id = ?', $v['idp']);	
		$row = $ColorSchemaProductType->fetchRow($select);		
		$this->view->ColorSchemaProductTypeInfo = $row;		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		$schemaName = 'type2';
		$ColorSchema_Model = new ColorSchemaProductType2();
		
		
		
		if( isset($v['admin_add']) ){
		
			$data = array(
				'color_schema_product_type_id' => $v['idp'],
				'color_schema_product_'.$schemaName.'_name' => $v['product_name'],
				'color_schema_product_'.$schemaName.'_code' => $v['product_code'],
			//	'color_schema_product_'.$schemaName.'_type' => isset($v['product_type'])?$v['product_type']:0,
				'color_schema_product_'.$schemaName.'_image' => isset($v['product_image'])?$v['product_image']:'',
				'color_schema_product_'.$schemaName.'_price' => $v['product_price']
			);
			$ColorSchema_Model->update( $data , 'color_schema_product_'.$schemaName.'_id='.$v['idp2'] );
			
			foreach( $v['product_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."name_".$v['idp2']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			
			foreach( $v['product_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_schema_product_".$schemaName."description_".$v['idp2']."' AND language_panel LIKE 'product' ";

				$db->query($zap);
			
			}
			$f = new Lib_Color();
			$f->updateColorType($v['idp2']);
			
			//$information->addSuccess = true; 
			$this->_helper->redirector('colorschemaediteditcolortype2edit','admin',null,array('id' => $v['id'], 'idp' => $v['idp'], 'idp2' => $v['idp2']));	
			//$this->_helper->redirector('product','admin');	
			
		}
		
		
		
		
		
		
		$select = $ColorSchema_Model->select();		
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $v['idp2']);	
		$row = $ColorSchema_Model->fetchRow($select);
		
		$this->view->rowElement = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp2']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."name_".$v['idp2']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$v['idp2']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp2']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'color_schema_product_".$schemaName."description_".$v['idp2']."', '".$row->{color_schema_product_.$schemaName._name}."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$v['idp2']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;	
		
		
		
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		$this->view->rowColorSchema = $row;
		
	}	
	
	
	public function colorschemaeditremovecolorAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$this->view->actionName = 'producteditbody';
		$ColorSchema = new ColorSchema();	
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		if( $row['color_schema_type'] == 0 ){		
			$ProductBody = new ProductBody();
			$ColorSchemaProductBody = new ColorSchemaProductBody();
			$where = array(
				'color_schema_id = ?' => $v['id'],
				'color_schema_product_body_id = ?' => $v['idp']
			);
			$ProductBody->delete($where);
			$ColorSchemaProductBody->delete($where);
		}

		if( $row['color_schema_type'] == 1 ){
			$ProductFront = new ProductFront();
			$ColorSchemaProductFront = new ColorSchemaProductFront();
			$where = array(
				'color_schema_id = ?' => $v['id'],
				'color_schema_product_front_id = ?' => $v['idp']
			);
			$ProductFront->delete($where);
			$ColorSchemaProductFront->delete($where);		
		}

		if( $row['color_schema_type'] == 2 ){
			$ProductType = new ProductType();
			$ColorSchemaProductType = new ColorSchemaProductType();
			$where = array(
				'color_schema_id = ?' => $v['id'],
				'color_schema_product_type_id = ?' => $v['idp']
			);
			$ProductType->delete($where);
			$ColorSchemaProductType->delete($where);		
		}

		if( $row['color_schema_type'] == 3 ){
			$ProductHandles = new ProductHandles();
			$ColorSchemaProductHandles = new ColorSchemaProductHandles();
			$where = array(
				'color_schema_id = ?' => $v['id'],
				'color_schema_product_handles_id = ?' => $v['idp']
			);
			$ProductHandles->delete($where);
			$ColorSchemaProductHandles->delete($where);		
		}

		if( $row['color_schema_type'] == 4 ){
			$ProductAccessories = new ProductAccessories();
			$ColorSchemaProductAccessories = new ColorSchemaProductAccessories();
			$where = array(
				'color_schema_id = ?' => $v['id'],
				'color_schema_product_accessories_id = ?' => $v['idp']
			);
			$ProductAccessories->delete($where);
			$ColorSchemaProductAccessories->delete($where);		
		}
		
		//$information->removeSuccess = true; 
		$this->_helper->redirector('colorschemaedit','admin',null,array('id' => $v['id']));	
		
	
	}
	
	
	public function colorschemaediteditcolortype2removeAction() {	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
				
		$ProductType2 = new ProductType2();
		$ColorSchemaProductType2 = new ColorSchemaProductType2();
		
		$where = array(
			'color_schema_product_type_id = ?' => $v['idp'],
			'color_schema_product_type2_id = ?' => $v['idp2']
		);
		$ColorSchemaProductType2->delete($where);	
		
		$where = array(
			'color_schema_id = ?' => $v['id'],
			'color_schema_product_type2_id = ?' => $v['idp2']
		);
		$ProductType2->delete($where);
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
		
	}
	
	public function colorschemaeditdefaultcolorAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ColorSchema = new ColorSchema();
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$rowColorSchema = $ColorSchema->fetchRow($select);
		
			
			
		if( $rowColorSchema['color_schema_type'] == 0 ){	
			$ColorSchema_Type = new ColorSchemaProductBody();
			$schemaName = 'body';
			$Product_E = new ProductBody();	
		}
			
		if( $rowColorSchema['color_schema_type'] == 1 ){	
			$ColorSchema_Type = new ColorSchemaProductFront();
			$schemaName = 'front';
			$Product_E = new ProductFront();	
		}
			
		if( $rowColorSchema['color_schema_type'] == 2 ){	
			$ColorSchema_Type = new ColorSchemaProductType();
			$schemaName = 'type';
			$Product_E = new ProductType();	
		}
			
		if( $rowColorSchema['color_schema_type'] == 3 ){	
			$ColorSchema_Type = new ColorSchemaProductHandles();
			$schemaName = 'handles';
			$Product_E = new ProductHandles();	
		}
			
		if( $rowColorSchema['color_schema_type'] == 4 ){	
			$ColorSchema_Type = new ColorSchemaProductAccessories();
			$schemaName = 'accessories';
			$Product_E = new ProductAccessories();	
		}
			
			
		$select = $ColorSchema_Type->select();		
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $v['idp']);	
		$row = $ColorSchema_Type->fetchRow($select);		
			
		$zap = "UPDATE `color_schema_product_".$schemaName."` SET color_schema_product_".$schemaName."_default='0' WHERE color_schema_id = '".$v['id']."' ";
		$db->query($zap);
			
		$zap = "UPDATE `color_schema_product_".$schemaName."` SET color_schema_product_".$schemaName."_default='1' WHERE color_schema_product_".$schemaName."_id = '".$v['idp']."' AND  color_schema_id = '".$v['id']."' ";
		$db->query($zap);
					
		$data = array(
			'product_'.$schemaName.'_default' => 0
		);
		$Product_E->update($data, 'color_schema_id='.$v['id']);
			
		$f = new Lib_Color();
		$f->updateColor($v['id'],$v['idp']);
			
			
			
	/*		
		if( $row['color_schema_type'] == 0 ){	
		
			$ColorSchemaProductBody = new ColorSchemaProductBody();
			$select = $ColorSchemaProductBody->select();		
			$select->where('color_schema_product_body_id = ?', $v['idp']);	
			$row = $ColorSchemaProductBody->fetchRow($select);
		
			$zap = "UPDATE `color_schema_product_body` SET color_schema_product_body_default='0' WHERE color_schema_id = '".$v['id']."' AND color_schema_product_body_typebody = '".$row->color_schema_product_body_typebody."' ";
			$db->query($zap);
			
			$zap = "UPDATE `color_schema_product_body` SET color_schema_product_body_default='1' WHERE color_schema_product_body_id = '".$v['idp']."' AND  color_schema_id = '".$v['id']."' AND color_schema_product_body_typebody = '".$row->color_schema_product_body_typebody."' ";			
			$db->query($zap);
			
			$ProductBody = new ProductBody();			
			$data = array(
				'product_body_default' => 0
			);
			$ProductBody->update($data, 'color_schema_id='.$v['id']);
			
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
			
		}
			
		if( $row['color_schema_type'] == 1 ){	
		
			$ColorSchemaProductFront = new ColorSchemaProductFront();
			$select = $ColorSchemaProductFront->select();		
			$select->where('color_schema_product_front_id = ?', $v['idp']);	
			$row = $ColorSchemaProductFront->fetchRow($select);		
			
			$zap = "UPDATE `color_schema_product_front` SET color_schema_product_front_default='0' WHERE color_schema_id = '".$v['id']."' ";
			$db->query($zap);
			
			$zap = "UPDATE `color_schema_product_front` SET color_schema_product_front_default='1' WHERE color_schema_product_front_id = '".$v['idp']."' AND  color_schema_id = '".$v['id']."' ";
			$db->query($zap);
			
			$ProductFront = new ProductFront();			
			$data = array(
				'product_front_default' => 0
			);
			$ProductFront->update($data, 'color_schema_id='.$v['id']);
			
			$f = new Lib_Color();
			$f->updateColor($v['id'],$v['idp']);
		
		}
	*/	
		//$information->addSuccess = true; 
		$this->_helper->redirector('colorschemaedit','admin',null,array('id' => $v['id']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function colorschemaediteditcolortype2defaultAction() {
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		
		$v = $this->_request->getParams();
	
		$ColorSchema = new ColorSchema();		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$rowColorSchema = $ColorSchema->fetchRow($select);
			
		$ColorSchema_Type = new ColorSchemaProductType2();
		$schemaName = 'type2';
		$Product_E = new ProductType2();	

		$select = $ColorSchema_Type->select();		
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $v['idp']);	
		$row = $ColorSchema_Type->fetchRow($select);		
			
		$zap = "UPDATE `color_schema_product_".$schemaName."` SET color_schema_product_".$schemaName."_default='0' WHERE color_schema_product_type_id = '".$v['idp']."' ";
		$db->query($zap);
			
		$zap = "UPDATE `color_schema_product_".$schemaName."` SET color_schema_product_".$schemaName."_default='1' WHERE color_schema_product_".$schemaName."_id = '".$v['idp2']."' AND  color_schema_product_type_id = '".$v['idp']."' ";
		$db->query($zap);
					
		$data = array(
			'product_'.$schemaName.'_default' => 0
		);
		$Product_E->update($data, 'color_schema_id='.$v['id']);
			
		$f = new Lib_Color();
		$f->updateColor($v['id'],$v['idp']);
			
		$this->_helper->redirector('colorschemaediteditcolor','admin',null,array('id' => $v['id'], 'idp' => $v['idp']));	
		
		$this->_helper->viewRenderer->setNoRender();
	}
		
			
	
	
	public function coloraddcategoryAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$Category = new Category();		
		$v = $this->_request->getPost();

		$where = '';
		
		$data = $Category->fetchAll($where.' category_type = '.$v['category_type'].' AND category_parent_id = '.$v['category_id'], " category_name ASC ");
		$this->view->dataCategory = $data;
		$this->view->idCategory = $v['category_id'];
		$this->view->category_type = $v['category_type'];
	}
	
	public function coloraddphotoAction() {
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			die();
		}		
	
		$v = $this->_request->getPost();
	
		$upload_path_img = "public/uploads/color/";
		$filename_name = hash('sha256',$admin->admin_id.time().rand(0,100000));
		$filename_format = 'jpeg';
		
		$encodedData = $v['image_color'];	//str_replace(' ','+',$v['client_profile_p1']);
		$img = base64_decode($encodedData);
		file_put_contents( $upload_path_img.$filename_name.'.'.$filename_format, $img );
		
		$image = imagecreatefromjpeg($upload_path_img.$filename_name.'.'.$filename_format);
		list($w, $h) = getimagesize($upload_path_img.$filename_name.'.'.$filename_format);
		
		$rozmiar = 100;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 180;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$rozmiar = 200;		
		$new_width = $rozmiar; $new_height = $h * $new_width /$w; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_w'.$new_width.'.'.$filename_format);		
		$new_height = $rozmiar; $new_width = $w * $new_height /$h; $image_new = imagecreatetruecolor($new_width, $new_height);
		system("/usr/bin/convert ".$upload_path_img.$filename_name.'.'.$filename_format." -resize ".$new_width."x".$new_height." ".$upload_path_img.$filename_name.'_h'.$new_height.'.'.$filename_format);
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
		
		if( $w < 200 OR $h < 200 ){
			$this->view->errorSize = true;
		}		
	}
	
	public function colorremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$Color = new Color();
		$where = array(
			'color_id = ?' => $v['id']
		);
		$Color->delete($where);			
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		foreach( $dataLang as $k1 => $val1 ){
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'color_name_".$v['id']."' LIMIT 1";
			$db->query($zap);	
			$zap = "DELETE FROM `lang_".$val1['lang_suffix']."` WHERE `language_variable` LIKE 'color_description_".$v['id']."' LIMIT 1";
			$db->query($zap);	
		}	
		
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('color','admin');	
	}
	
	public function colorschemaremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();
		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$ColorSchema = new ColorSchema();
		
		
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $v['id']);	
		$row = $ColorSchema->fetchRow($select);
		
		$where = array(
			'color_schema_id = ?' => $v['id']
		);
		$ColorSchema->delete($where);		
		
		if( $row['color_schema_type'] == 0 ){	
			$ProductBody = new ProductBody();
			$ProductBody->delete($where);
		}else{
			$ProductFront = new ProductFront();
			$ProductFront->delete($where);		
		}
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('colorschema','admin');	
	}
	
	public function coloreditAction() {	
		$db = Zend_Registry::get('db');
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$v = $this->_request->getParams();
		$this->view->idProduct = $v['id'];
		$request = Zend_Controller_Front::getInstance()->getRequest();
		$this->view->actionName = $request->getActionName();
		$Color = new Color();	
		
		$select = $Color->select();		
		$select->where('color_id = ?', $v['id']);	
		$row = $Color->fetchRow($select);
		
		$this->view->ColorInfo = $row;	
		
		
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		
		if( $information->addProductSuccess ){
			$this->view->addProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $information->editProductSuccess ){
			$this->view->editProductSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( isset($v['admin_editcolor']) ){
		
			$data = array(
				'color_name' => $v['color_name'],
				'color_img' => isset($v['product_image'])?$v['product_image']:'',
				'category_id' => $v['category_id4']
			);
			$Color->update( $data , 'color_id='.$v['id'] );
			
			foreach( $v['color_name_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_name_".$v['id']."' AND language_panel LIKE 'color' ";

				$db->query($zap);
			
			}
			
			foreach( $v['color_description_translate'] as $key => $value ){
			
				$zap = "UPDATE `lang_".$key."` SET language_value='".$value."' WHERE language_variable LIKE 'color_description_".$v['id']."' AND language_panel LIKE 'color' ";

				$db->query($zap);
			
			}
						
			$information->editProductSuccess = true; 
			$this->_helper->redirector('coloredit','admin',null,array('id' => $v['id']));	
		
		}		
		
		$select = $Color->select();		
		$select->where('color_id = ?', $v['id']);	
		$row = $Color->fetchRow($select);
		
		$this->view->rowColor = $row;
		
		
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		
		$dataLangTra = array();
		$i = -1;
		foreach( $dataLang as $k => $val ){
			$i++;
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_name_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('color', 'color_name_".$v['id']."', '".$row->color_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_name_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value'] = $dataLangRow[0]['language_value'];
			}
			
			
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_description_".$v['id']."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$dataLangTra[$i]['lang_name'] = $val['lang_name'];
			$dataLangTra[$i]['lang_suffix'] = $val['lang_suffix'];
			
			if( isset($dataLangRow[0]) ){
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}else{
			
				$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('color', 'color_description_".$v['id']."', '".$row->color_name."');";

				$db->query($zap);
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_description_".$v['id']."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$dataLangTra[$i]['language_value_2'] = $dataLangRow[0]['language_value'];
			}


			
		
		}
		
		$this->view->dataLang = $dataLangTra;
		
	}
	
	public function colorphotoAction() {
		$v = $this->_request->getParams();		
	
		$upload_path_img = "public/uploads/color/";
		$filename_name = $v['filename'];
		$filename_format = 'jpeg';	
		
		$this->view->photoName = $filename_name; 
		$this->view->photoUrl = $upload_path_img.$filename_name.'_w100.'.$filename_format;
		$this->view->photoWidth = $w; 
		$this->view->photoHeight = $h;  
	}
	
	
	
	public function configAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}
		
		$TypePack = new TypePack();		
		$TypeTransport = new TypeTransport();	
		$TypeLeadTime = new TypeLeadTime();		
		$Config = new Config();		
		
		if( isset($v['config_typepack']) ){		
			foreach( $v['value'] as $key => $val ){
				$data = array(
					'value' => isset($val)?$val:0,
					'def' => 0
				);

				$TypePack->update( $data , 'id='.$key );
			}
			$data = array(
				'def' => 1
			);
			$TypePack->update( $data , 'id='.$v['def'] );

			$this->_helper->redirector('config','admin');
		}

		
		if( isset($v['config_typetransport']) ){
			foreach( $v['value'] as $key => $val ){
				$data = array(
					'value' => isset($val)?$val:0,
					'def' => 0
				);
				
				$TypeTransport->update( $data , 'id='.$key );			
			}
			$data = array(
				'def' => 1
			);
			$TypeTransport->update( $data , 'id='.$v['def'] );
			$this->_helper->redirector('config','admin');
		}

		
		if( isset($v['config_typeleadtime']) ){
			foreach( $v['value'] as $key => $val ){
				$data = array(
					'value' => isset($val)?$val:0,
					'def' => 0
				);
				
				$TypeLeadTime->update( $data , 'id='.$key );			
			}
			$data = array(
				'def' => 1
			);
			$TypeLeadTime->update( $data , 'id='.$v['def'] );
			$this->_helper->redirector('config','admin');
		}

		
		if( isset($v['config_config']) ){
			foreach( $v['value'] as $key => $val ){
				$data = array(
					'config_value' => isset($val)?$val:''
				);
				$Config->update( $data , 'config_id='.$key );
			}			
			$this->_helper->redirector('config','admin');
		}

		
		if( isset($v['config_config_nextid']) ){		
			$ask = "ALTER TABLE `order` AUTO_INCREMENT = ".$v['next_id'];
			$db->query($ask);
			$this->_helper->redirector('config','admin');
		}
		
		$sql = "SHOW TABLE STATUS WHERE `Name` = 'order'";
		$dataNextId = $db->query($sql)->fetch();
		$this->view->next_id = $dataNextId['Auto_increment'];  
		
		$dataTypePack = $TypePack->fetchAll(null, 'sort ASC');
		$this->view->dataTypePack = $dataTypePack;  
		
		$dataTypeTransport = $TypeTransport->fetchAll(null, 'sort ASC');
		$this->view->dataTypeTransport = $dataTypeTransport;
		
		$dataTypeLeadTime = $TypeLeadTime->fetchAll(null, 'sort ASC');
		$this->view->dataTypeLeadTime = $dataTypeLeadTime;
		
		$dataConfig = $Config->fetchAll(null, 'config_id ASC');
		$this->view->dataConfig = $dataConfig;  
	}	
	
	
	
	public function voucherAction(){
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}
		
		$Voucher = new Voucher();
		
		if( $v['gen'] ){
			$codes = '';
			for( $ii = 0; $ii != $v['i']; $ii++ ){
				$code = Lib_Code::generateCode();
				$data = array(
					'voucher_code' => $code,
					'voucher_rabate' => str_replace(",",".",$v['r']),
					'voucher_date_ins' => Lib_Date::datetime()
				);
				$idIns = $Voucher->insert($data);
				
				$codes = $codes.$idIns.'-'.$code.', ';
			}
			
			$this->view->codes = $codes;
			$this->view->r = $v['r'];
		}
		
		$limit = 50;
		$limitpage = 10;
		$page = $this->_request->getParams();
		
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
		$p = ($page-1)*$limit;
		$dataCount = count($Voucher->fetchAll(null, 'voucher_date_ins DESC'));
		$dataVoucher = $Voucher->fetchAll(null, 'voucher_date_ins DESC', $limit,$p);
		$this->view->dataVoucher = $dataVoucher;
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('voucher');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
	
	}		
	
	
	public function exportAction()
	{
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();
		$admin = new Zend_Session_Namespace('admin');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}

		
		header("Content-type: text/csv");
		header("Content-Disposition: attachment; filename=eksport-".$v['id'].".csv");
		header("Pragma: no-cache");
		header("Expires: 0");
		
		
		$ask = '
			SELECT 
			*,
			DATE(order_ins) AS order_data
			FROM `order`
			WHERE 
				order_id = '.$v['id'].'
			LIMIT 1
		';
		$dataAllOrder = $db->query($ask)->fetch();
		$clientName = $dataAllOrder['order_send_client_firstname'].' '.$dataAllOrder['order_send_client_secondname'];
		
		$ask = '
			SELECT 
			*,
			op.order_product_id AS order_product_id,
			op.product_options_1 AS order_product_options_1,
			op.product_options_2 AS order_product_options_2,
			op.product_options_3 AS order_product_options_3,
			op.product_options_4 AS order_product_options_4
			FROM order_product op, product p
			WHERE 
				p.product_id = op.product_id			
				AND op.order_id = '.$v['id'].'
			ORDER BY
				op.order_product_id DESC
		';
		$dataAll = $db->query($ask)->fetchAll();
		
		
		$elementNr = 0;
		$lpSzafki = 0; $lastLpSzafki = 0;
		foreach( $dataAll as $key => $val ){
		
			$ask = '
				SELECT 
				*
				FROM product_element pe
				WHERE 
					pe.product_id = '.$val['product_id'].'
				ORDER BY
					pe.product_element_id ASC
			';
			$dataAllElement = $db->query($ask)->fetchAll();
		
			for( $iTemp = 0; $iTemp != $val['order_product_amount']; $iTemp++ ){
			
				$lpElement = 0;
				foreach( $dataAllElement as $keyElement => $valElement ){
				
					$powtorzen = 1;
					
					if( $valElement['product_element_drawer'] == 1 ){
						$powtorzen = $valElement['product_element_drawerAmount'];
					}
					
					if( $valElement['product_element_shelf'] == 1 ){
						$powtorzen = $val['order_product_shelfamount'];
					}
				
					for($pn = 0; $pn < $powtorzen; $pn++){
					if( $lastLpSzafki != $val['order_product_id'] ){
						$lastLpSzafki = $val['order_product_id'];
						$lpSzafki++;
					}

					$elementNr++;
					$lpElement++;
				/*	
					echo'<hr/>';
					var_dump($val);echo'<br /><br />';
					var_dump($valElement);echo'<br /><br />';
					*/
					echo
						$elementNr.";"
						.$lpSzafki.";"
						.$lpElement.";"
						.$valElement['product_element_name'].";"
						.$valElement['product_element_code'].";"
						.Lib_Equation::calculate('product_element_equation1',$val,$valElement).";"					
						.$valElement['product_element_pcv1'].";"
						.Lib_Equation::calculate('product_element_equation2',$val,$valElement).";"					
						.$valElement['product_element_pcv2'].";"					
						.Lib_Export::colorElement($val,$valElement['product_element_panel']).";"
						.Lib_Lang::consta(front_configurator_body_rim.$val['product_rim_id']).";"
						.Lib_Lang::consta(front_configurator_body_rim.$val['product_rim2_id']).";"			
						.$valElement['product_element_quantity'].";"	
						.Lib_Export::colorElement($val,1).";"				
						.Lib_Export::colorElement($val,2).";"				
						.Lib_Export::colorElement($val,3).";"
						.$v['id'].";"
						.$clientName.";"
						.$dataAllOrder['order_data'].";"	
						.Lib_Lang::consta(type_transport_.$dataAllOrder['order_id_transport']).";"		
						.$val['product_code'].";"				
						.$val['product_name'].";"			
						.$val['order_product_height'].";"			
						.$val['order_product_width'].";"			
						.$val['order_product_depth'].";"			
						.Lib_Export::parametrOption($val['order_product_options_1']).";"			
						.Lib_Export::parametrOption($val['order_product_options_2']).";"			
						.Lib_Export::parametrOption($val['order_product_options_3']).";"			
						.Lib_Export::parametrOption($val['order_product_options_4']).";"		
						.Lib_Export::parametr($val,'A').";"			
						.Lib_Export::parametr($val,'B').";"			
						.Lib_Export::parametr($val,'C').";"			
						.Lib_Export::parametr($val,'D').";"			
						.Lib_Export::parametr($val,'E').";"		
						.Lib_Export::parametrShelf($val).";"	
						.Lib_Export::parametrType($val).";"	
						.Lib_Export::parametrElement('product_handles','product_handles_id',$val['product_handles_id'],'product_handles_code').";"
						.Lib_Export::parametrElement('product_accessories','product_accessories_id',$val['product_accessories_id'],'product_accessories_code').";"
						.Lib_Export::parametrElement('product_accessories','product_accessories_id',$val['product_accessories2_id'],'product_accessories_code').";"
						.Lib_Export::parametrElement('product_accessories','product_accessories_id',$val['product_accessories3_id'],'product_accessories_code').";"
						.Lib_Export::parametrElement('product_accessories','product_accessories_id',$val['product_accessories4_id'],'product_accessories_code').";"
						.Lib_Export::parametrElement('product_legs','product_legs_id',$val['product_legs_id'],'product_legs_code').";"	
						.Lib_Export::parametrOptions($val,'options').";"
						.Lib_Export::parametrOptions($val,'options2').";"

						.$v['id']."-".$elementNr.";"						
						."\n";
				
					}
				}
			}	
			
		}
		
		

		
	/*
		$ask = '
			SELECT 
			*,
			op.order_product_id AS order_product_id,
			op.product_options_1 AS order_product_options_1,
			op.product_options_2 AS order_product_options_2,
			op.product_options_3 AS order_product_options_3,
			op.product_options_4 AS order_product_options_4
			FROM order_product op, product p, product_element pe
			WHERE 
				p.product_id = op.product_id
				AND p.product_id = pe.product_id				
				AND op.order_id = '.$v['id'].'
			ORDER BY
				op.order_product_id DESC,
				pe.product_element_id ASC
		';
		$dataAll = $db->query($ask)->fetchAll();
		
		
		$elementNr = 0;
		$lpSzafki = 0; $lastLpSzafki = 0;
		$lpElement = 0; $lastLpElement = 0;
		foreach( $dataAll as $key => $val ){
		
			for( $iTemp = 0; $iTemp != $val['order_product_amount']; $iTemp++ ){
				
				if( $lastLpSzafki != $val['order_product_id'] ){
					$lastLpSzafki = $val['order_product_id'];
					$lpSzafki++;
				}
				
				if( $lastLpElement == $val['order_product_id'] ){
					$lastLpElement = $val['order_product_id'];
					$lpElement++;
				}
			
				$elementNr++;
				echo
					$elementNr.";"
					.$lpSzafki.";"
					.$val['product_element_name'].";"
					.$val['product_element_code'].";"
					.Lib_Equation::calculate('product_element_equation1',$val).";"					
					.$val['product_element_pcv1'].";"
					.Lib_Equation::calculate('product_element_equation2',$val).";"					
					.$val['product_element_pcv2'].";"
					."\n";
				
			}	
				
		}
	*/	
		$this->_helper->viewRenderer->setNoRender();
	}


















	
	
	
	
	
	
	
	public function schemaAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		$v = $this->_request->getParams();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$SchemaProduct = new SchemaProduct();	
		$dataCount = count($SchemaProduct->fetchAll(null , 'schema_product_name ASC')); 
			$p = ($page-1)*$limit;		
		$data = $SchemaProduct->fetchAll(null , 'schema_product_name ASC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('admin');
		$Lib_Page->setAction('schema');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
	}
	
	public function schemaaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}		
		
		$SchemaProduct = new SchemaProduct();		
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addcolorschema']) ){
		
			$data = array(
				'schema_product_name' => $v['schema_product_name'],
				'schema_product_type' => $v['schema_product_type']
			);
			$idIns = $SchemaProduct->insert($data);
			
			$information->addProductSuccess = true; 
			$this->_helper->redirector('schemaedit','admin',null,array('id' => $idIns));	
			//$this->_helper->redirector('product','admin');	
			
		}		
	}
	
	public function schemaremoveAction() {	
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();
		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}			
		
		$SchemaProduct = new SchemaProduct();
		
		$select = $SchemaProduct->select();		
		$select->where('schema_product_id = ?', $v['id']);	
		$row = $SchemaProduct->fetchRow($select);
		
		$where = array(
			'schema_product_id = ?' => $v['id']
		);
		$SchemaProduct->delete($where);		
		
		if( $row['schema_product_type'] == 0 ){	
			$SchemaProductType = new SchemaProductType();
			$SchemaProductType->delete($where);
		}
		
		if( $row['schema_product_type'] == 1 ){	
			$SchemaProductHandles = new SchemaProductHandles();
			$SchemaProductHandles->delete($where);		
		}
		
		if( $row['schema_product_type'] == 2 ){	
			$SchemaProductAccessories = new SchemaProductAccessories();
			$SchemaProductAccessories->delete($where);		
		}
		
		$information->removeSuccess = true; 
		$this->_helper->redirector('schema','admin');	
	}
	












		
	
	
	
	
	
	
	
	
	public function loginclientAction() {	
		$v = $this->_request->getParams();
		$client = new Zend_Session_Namespace('client');	
		$information = new Zend_Session_Namespace('information');
		Zend_Session::namespaceUnset('client');
		Zend_Session::namespaceUnset('basket');
		Zend_Session::namespaceUnset('order');
		
		$Client = new Client();
		$select = $Client->select();		
		$select->where('client_id = ?', $v['id']);			
		$row = $Client->fetchRow($select);
		
		if( isset($row) ){
			// zalogowany
			$client->time = time();	
			$client->client_auth = true;
			$client->client_login = $row['client_login'];
			$client->client_id = $row['client_id'];	
			$client->client_firstname = $row['client_firstname'];
			$client->client_secondname = $row['client_secondname'];	

			$client->login_in_admin = true;
			
	//		$basket = new Zend_Session_Namespace('basket');
	//		$order = new Zend_Session_Namespace('order');
	//		$basket->product = json_decode($row['client_basket'],true);
	//		$order->product = json_decode($row['client_order'],true);				
		}
		
		$this->_helper->redirector('index','index');		
	}
	
	public function logoutclientAction() {	
		$client = new Zend_Session_Namespace('client');	
		$information = new Zend_Session_Namespace('information');
		Zend_Session::namespaceUnset('client');
		$information->logoutClientSuccess = true;
		$this->_helper->redirector('panel','admin');		
	}

	
	
	
	
	
	
	
}

// $this->_helper->viewRenderer->setNoRender();

/*


	
	
	public function funAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','admin');
		}	
		
		
	}


*/

