<?php
/**
 * Produkty 
 * 
 *
 */
class ProductCategoryController extends MainController implements ControllerInterface {


	const AVATAR_DEST_DIR = '/upload/Product';
	const AVATAR_TEMP_DIR = '/upload/temp';
	const NO_PHOTO_IMG_BIG = "image/Admin/cropperNoPhotoBig.gif";
	const NO_PHOTO_IMG_SMALL = "image/Admin/przekatne.gif";
	const MAX_AVATAR_FILE_SIZE = 5; //Rozmiar w mb
	const CROPPER_BIG_PHOTO_MAX_WIDTH = 800;
	const CROPPER_BIG_PHOTO_MAX_HEIGHT = 800;
	const PHOTO_WIDTH = 800;
	const PHOTO_HEIGHT = 600;

	const IMAGE_MINI_WIDTH = 240;
	const IMAGE_MINI_HEIGHT = 180;
	const IMAGE_NORMAL_WIDTH = 800;
	const IMAGE_NORMAL_HEIGHT = 600;


	public function IndexAction($param) {
		//Utils::ArrayDisplay($param);
		$dalData = MfProductCategoryDAL::GetDalDataObj();
		$dalData->setJoin(array('MfProductCategoryDescription' => ' LEFT JOIN mf_product_category_description ON mf_product_category.id_mf_product_category=mf_product_category_description.id_mf_product_category '));
		$dalData->setCondition(array('lang' => $param['lang']));
		$arrayObjProductCategory = MfProductCategoryDAL::GetResult($dalData);

		$param['runSharedVariable'] = 'linkedAttribute';
		$this->RunModuleController( 'ProductCategoryController', 'LinkedAttribute', $param, true);
		//
		//		$param['runSharedVariable'] = 'unlinkedAttribute';
		//		$this->RunModuleController( 'ProductCategoryController', 'UnlinkedAttribute', $param, true);
		foreach ($arrayObjProductCategory as $item) {
			$menu[$item->GetId()] = $item;
		}
		foreach ($menu as $key => $obj) {

			if ($obj->GetIdParent() != 0) {
				if (key_exists($obj->GetIdParent(), $menu)) {
					$menu[$obj->GetIdParent()]->SetHaveChildren(true);
					$menu[$obj->GetIdParent()]->AddChildren(array($obj->GetId() => $obj));
				} else {
					$arrayTree[$key] = $obj;
				}

			}
			if ($obj->GetIdParent() == 0) {
				//Utils::ArrayDisplay('ones');
				$arrayTree[$key] = $obj;
			}
		}
		foreach ($menu as $key => $obj) {

		}


		//Utils::ArrayDisplay($arrayTree);

		$this->smarty->assign('menuProductCategory', $arrayTree);
		$this->smarty->assign('arrayObjProductCategory', $arrayObjProductCategory);
		//Utils::ArrayDisplay($arrayObjProductCategory);
	}

	public function LinkedAttributeAction($param) {
		//Utils::ArrayDisplay($param);
		if (isset($param['idCategory'])) {
			$idsAttribute = MfProductLinkDAL::GetIdStringDestinaion('mf_product_category', 'mf_product_attribute', $param['idCategory'], 'pl');
			$dalData = MfProductAttributeDAL::GetDalDataObj();
			$dalData->setCondition(array('lang' => $param['lang']));
			$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idsAttribute.') ', ' ');
			$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));
			$dalData->setSortBy(' FIELD(mf_product_attribute.id_mf_product_attribute, '.$idsAttribute.')');

			$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);
			$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
			$this->smarty->assign('idCategory', $param['idCategory']);
		} else {
			$this->smarty->assign('arrayObjAttribute', array());
			$this->smarty->assign('clikCategory', true);
		}
	}

	public function SaveSortAction($param) {
		$this->SetNoRender();
		//Utils::ArrayDisplay($param);
		if (Request::GetPost('doSaveSort')) {
			$arrayAttrSort = Request::GetPost('attr');
			$idCategory = Request::GetPost('idCategory');
			//Utils::ArrayDisplay($arrayAttrSort);
			//source_type 	id_source 	destination_type 	id_destination
			//mf_product_category 	2 	mf_product_attribute 	6 	0
			foreach ($_POST['attr'] as $idAttr => $sort) {
				//Utils::ArrayDisplay($idAttr);
				$dalData = MfProductLinkDAL::GetDalDataObj();
				$dalData->setCondition(array('source_type' => 'mf_product_category', 'id_source' => $idCategory, 'destination_type'=> 'mf_product_attribute', 'id_destination' => $idAttr, 'lang' => 'pl'));
				$arrayAttrLink = MfProductLinkDAL::GetResult($dalData);

				//Utils::ArrayDisplay($arrayAttrLink);

				foreach ($arrayAttrLink as $link) {
					$link->setWeight($sort);
					//Utils::ArrayDisplay($link);
					MfProductLinkDAL::Save($link);
				}
			}
			//	Utils::ArrayDisplay($_POST);

		}

		$this->AddRedirectInfo('Zapisano', 'ok', Router::GenerateUrl('editCategory', array('ProductCategory' => 'index', 'idCategory' => $idCategory)));



	}

	public function UnlinkedAttributeAction($param) {
		//Utils::ArrayDisplay($param);
		if (isset($param['idCategory'])) {
			$idsAttribute = MfProductLinkDAL::GetIdStringDestinaion('mf_product_category', 'mf_product_attribute', $param['idCategory'], $param['lang']);
			$dalData = MfProductAttributeDAL::GetDalDataObj();
			$dalData->setCondition(array('lang' => 'pl'));
			$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute NOT IN ('.$idsAttribute.') ', ' ');
			$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

			$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);
			$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
		} else {
			$this->smarty->assign('arrayObjAttribute', array());
			$this->smarty->assign('clikCategory', true);
		}
	}

	public function IndexStructureAction($param) {

		$idCategory = SessionProxy::GetValue('idCategory');
		$this->smarty->assign('idCategory', $idCategory);

		$idsProduct = MfProductLinkDAL::GetIdStringDestinaion('mf_product_category', 'mf_product',$idCategory, $param['lang']);

		$dalData = MfProductDAL::GetDalDataObj();
		$dalData->setJoin(array('MfProductDescription' => ' LEFT JOIN mf_product_description ON mf_product.id_mf_product=mf_product_description.id_mf_product '));
		$dalData->setCondition(array('lang' => $param['lang']));
		//Utils::ArrayDisplay('ss'.$idsProduct);
		$dalData->addCondition('   ', 'mf_product.id_mf_product IN (' .$idsProduct. ') ', ' ');
		$arrayObj = MfProductDAL::GetResult($dalData);

		$this->smarty->assign('arrayObj', $arrayObj);
		if (isset($param['methodToRun']) && $param['methodToRun'] == 'Add') {
			$this->smarty->assign('add', true);
		}

	}

	public function AddAction($param) {



		// Pobiernie rodziców kategorii
		$dalData = MfProductCategoryDAL::GetDalDataObj();
		$dalData->setJoin(array('MfProductCategoryDescription' => ' LEFT JOIN mf_product_category_description ON mf_product_category.id_mf_product_category=mf_product_category_description.id_mf_product_category '));
		$dalData->setCondition(array('lang' => $param['lang'], 'mf_product_category.id_parent' => 0));
		$arrayObjProductCategory = MfProductCategoryDAL::GetResult($dalData);

		//$param['runSharedVariable'] = 'linkedAttribute';
		//$this->RunModuleController( 'ProductCategoryController', 'LinkedAttribute', $param, true);
		//
		//		$param['runSharedVariable'] = 'unlinkedAttribute';
		//		$this->RunModuleController( 'ProductCategoryController', 'UnlinkedAttribute', $param, true);

		//Utils::ArrayDisplay($arrayObjProductCategory);
		$this->smarty->assign('arrayObjProductCategory', $arrayObjProductCategory);
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		$dalData = MfProductAttributeDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		//	$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idsAttribute.') ', ' ');
		$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

		//Utils::ArrayDisplay($dalData);
		$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);
		//$objProductAttribute = MfProductAttributeDAL::GetResultByLink('mf_product_category', $idCategory, 'mf_product_attribute');
		//Utils::ArrayDisplay($arrayObjAttribue);
		$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
		$this->smarty->assign('arrayObjAttributeLinked', array());
		$objCategoryProduct = MfProductCategoryDAL::GetEmptyObj();

		if (Request::GetPost('doCategoryAdd')) {
			//Utils::ArrayDisplay(Request::GetAllPost());

			$out = array();
			$validator  = new Validator(Request::GetAllPost());
			$data = Request::GetAllPost();

			$validator->IsEmpty('name', 'Pole nazwa musi zostać wypełnione.');

			$out = $validator->GetErrorList();

			$publication = Request::Get('publication');
			$publication ? $publication = 1 : $publication = '0';

			//$objProduct = new MfProduct();
			//$objCategoryProduct->setDate($data['datepublication']." ".$data['timepublication'].":00:00");

			$objCategoryProduct->setPublication($publication);
			$objCategoryProduct->setIdParent($data['idParent']);
			$objCategoryProduct->setWeight($data['weight']);
			$objCategoryProductDesc = new MfProductCategoryDescription();
			$objCategoryProductDesc->setDatePublication("0000-00-00 00:00:00");
			$objCategoryProductDesc->setLang('pl');
			$objCategoryProductDesc->setName($data['name']);
			$objCategoryProductDesc->setPublication($publication);

			//$arrayObjAttributeWithValue = array();

			//Utils::ArrayDisplay($arrayObjAttribute);

			if(empty($out)) {


				$idCategoryProduct = MfProductCategoryDAL::Save($objCategoryProduct);
				$objCategoryProductDesc->setIdMfProductCategory($idCategoryProduct);
				$objCategoryProductDescEn = $objCategoryProductDesc;
				//$objCategoryProductDescEn->setLang('en');
				$objCategoryProductDescRu = $objCategoryProductDesc;
				//$objCategoryProductDescRu->setLang('ru');


				MfProductCategoryDescriptionDAL::Save($objCategoryProductDesc);
				///Utils::ArrayDisplay($objCategoryProductDesc);
				$objCategoryProductDescEn->setLang('en');
				$objCategoryProductDescEn->setId(-1);
				MfProductCategoryDescriptionDAL::Save($objCategoryProductDescEn);
				//Utils::ArrayDisplay($objCategoryProductDesc);
				$objCategoryProductDescRu->setLang('ru');
				$objCategoryProductDescRu->setId(-1);
				MfProductCategoryDescriptionDAL::Save($objCategoryProductDescRu);
				//Utils::ArrayDisplay($objCategoryProductDesc);
				if (isset($data['attr'])) {

					foreach ($data['attr'] as $attrKey => $attrId ) {
						$objMfProductLink = new MfProductLink();
						$objMfProductLink->setDestinationType('mf_product_attribute');
						$objMfProductLink->setSourceType('mf_product_category');
						$objMfProductLink->setIdDestination($attrId);
						$objMfProductLink->setIdSource($idCategoryProduct);
						$objMfProductLink->setLang('pl');
						$objMfProductLink->setPublication(1);
						MfProductLinkDAL::Save($objMfProductLink);
					}

				}
				$this->AddRedirectInfo('Zapisano', 'ok', Router::GenerateUrl('editCategory', array('ProductCategory' => 'index')));
			} else {

				if (isset($data['attr'])) {
					$idAttrLinked = implode(', ',$data['attr']);
				} else {
					$idAttrLinked = '-1';
				}
				$dalData = MfProductAttributeDAL::GetDalDataObj();
				$dalData->setCondition(array('lang' => $param['lang']));
				$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idAttrLinked.') ', ' ');
				$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

				//Utils::ArrayDisplay($dalData);
				$arrayObjAttributeLinked = MfProductAttributeDAL::GetResult($dalData);
				//$objProductAttribute = MfProductAttributeDAL::GetResultByLink('mf_product_category', $idCategory, 'mf_product_attribute');
				//Utils::ArrayDisplay($arrayObjAttributeLinked);

				$dalData = MfProductAttributeDAL::GetDalDataObj();
				$dalData->setCondition(array('lang' => $param['lang']));
				$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute NOT IN ('.$idAttrLinked.') ', ' ');
				$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

				//Utils::ArrayDisplay($dalData);
				$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);

				$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
				$this->smarty->assign('arrayObjAttributeLinked', $arrayObjAttributeLinked);


				$objCategoryProduct->SetDescriptionObj($objCategoryProductDesc);
				$this->smarty->assign('objCategoryProduct',$objCategoryProduct);


				$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
				$this->smarty->assign('info','Pola obowiązkowe muszą zostać wypełnione.');
				$this->smarty->assign('type','error');

				foreach ($out as $item) {
					$error[$item['field']] = $item['msg'];


				}
				$this->smarty->assign('error',$error);


			}



		}
	}


	public function EditAction($param) {


		// Pobiernie rodziców kategorii
		$dalData = MfProductCategoryDAL::GetDalDataObj();
		$dalData->setJoin(array('MfProductCategoryDescription' => ' LEFT JOIN mf_product_category_description ON mf_product_category.id_mf_product_category=mf_product_category_description.id_mf_product_category '));
		$dalData->setCondition(array('lang' => $param['lang'], 'mf_product_category.id_parent' => 0, '  ' => array('value' => ' mf_product_category.id_mf_product_category NOT IN('.$param['id'].')' ,'condition' => '')));
		$arrayObjProductCategory = MfProductCategoryDAL::GetResult($dalData);

		//$param['runSharedVariable'] = 'linkedAttribute';
		//$this->RunModuleController( 'ProductCategoryController', 'LinkedAttribute', $param, true);
		//
		//		$param['runSharedVariable'] = 'unlinkedAttribute';
		//		$this->RunModuleController( 'ProductCategoryController', 'UnlinkedAttribute', $param, true);

		//Utils::ArrayDisplay($arrayObjProductCategory);
		$this->smarty->assign('arrayObjProductCategory', $arrayObjProductCategory);
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


		$idsAttribute = MfProductLinkDAL::GetIdStringDestinaion('mf_product_category', 'mf_product_attribute', $param['id'], 'pl');
		$dalData = MfProductAttributeDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute NOT IN ('.$idsAttribute.') ', ' ');
		$dalData->setSortBy(' FIELD(mf_product_attribute.id_mf_product_attribute, '.$idsAttribute.')');
		$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

		//Utils::ArrayDisplay($dalData);
		$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);

		$dalData = MfProductAttributeDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idsAttribute.') ', ' ');
		$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));
		$dalData->setSortBy(' FIELD(mf_product_attribute.id_mf_product_attribute, '.$idsAttribute.')');
		//Utils::ArrayDisplay($dalData);
		$arrayObjAttributeLinked = MfProductAttributeDAL::GetResult($dalData);
		//$objProductAttribute = MfProductAttributeDAL::GetResultByLink('mf_product_category', $idCategory, 'mf_product_attribute');
		//Utils::ArrayDisplay($arrayObjAttribue);
		$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
		$this->smarty->assign('arrayObjAttributeLinked', $arrayObjAttributeLinked);
		$objCategoryProduct = MfProductCategoryDAL::GetById($param['id'], $param['lang']);
		$this->smarty->assign('objCategoryProduct', $objCategoryProduct);

		if (Request::GetPost('doCategoryEdit')) {
			//Utils::ArrayDisplay(Request::GetAllPost());

			$out = array();
			$validator  = new Validator(Request::GetAllPost());
			$data = Request::GetAllPost();

			$validator->IsEmpty('name', 'Pole nazwa musi zostać wypełnione.');

			$out = $validator->GetErrorList();

			$publication = Request::Get('publication');
			$publication ? $publication = 1 : $publication = '0';

			//$objProduct = new MfProduct();
			//$objCategoryProduct->setDate($data['datepublication']." ".$data['timepublication'].":00:00");
			$objCategoryProduct->setDatePublication("0000-00-00 00:00:00");
			$objCategoryProduct->setPublication($publication);
			$objCategoryProduct->setIdParent($data['idParent']);

			$objCategoryProduct->setWeight($data['weight']);
			$objCategoryProductDesc = $objCategoryProduct->getDescriptionObj();
			$objCategoryProductDesc->setDatePublication("0000-00-00 00:00:00");
			$objCategoryProductDesc->setLang($param['lang']);
			$objCategoryProductDesc->setName($data['name']);
			$objCategoryProductDesc->setPublication($publication);

			//$arrayObjAttributeWithValue = array();

			//Utils::ArrayDisplay($arrayObjAttribute);

			if(empty($out)) {

				//Utils::ArrayDisplay($data);
				$idCategoryProduct = MfProductCategoryDAL::Save($objCategoryProduct);
				$objCategoryProductDesc->setIdMfProductCategory($idCategoryProduct);
				MfProductCategoryDescriptionDAL::Save($objCategoryProductDesc);


				MfProductLinkDAL::DeleteFromLink($idCategoryProduct, 'mf_product_category', null, 'mf_product_attribute');

				foreach ($data['attr'] as $attrKey => $attrId ) {
					$objMfProductLink = new MfProductLink();
					$objMfProductLink->setDestinationType('mf_product_attribute');
					$objMfProductLink->setSourceType('mf_product_category');
					$objMfProductLink->setIdDestination($attrId);
					$objMfProductLink->setIdSource($idCategoryProduct);
					$objMfProductLink->setLang('pl');
					$objMfProductLink->setPublication(1);
					$objMfProductLink->setWeight($data['linked_attr_weight'][$attrId]);
					//Utils::ArrayDisplay($objMfProductLink);
					MfProductLinkDAL::Save($objMfProductLink);
				}

				$this->AddRedirectInfo('Zapisano', 'ok', Router::GenerateUrl('editCategory', array('ProductCategory' => 'index')));
			} else {

				if (isset($data['attr'])) {
					$idAttrLinked = implode(', ',$data['attr']);
				} else {
					$idAttrLinked = '-1';
				}
				$dalData = MfProductAttributeDAL::GetDalDataObj();
				$dalData->setCondition(array('lang' => $param['lang']));
				$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute IN ('.$idAttrLinked.') ', ' ');
				$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

				//Utils::ArrayDisplay($dalData);
				$arrayObjAttributeLinked = MfProductAttributeDAL::GetResult($dalData);
				//$objProductAttribute = MfProductAttributeDAL::GetResultByLink('mf_product_category', $idCategory, 'mf_product_attribute');
				//Utils::ArrayDisplay($arrayObjAttributeLinked);

				$dalData = MfProductAttributeDAL::GetDalDataObj();
				$dalData->setCondition(array('lang' => $param['lang']));
				$dalData->addCondition('   ', 'mf_product_attribute.id_mf_product_attribute NOT IN ('.$idAttrLinked.') ', ' ');
				$dalData->setJoin(array('MfProductAttributeDescription' => ' LEFT JOIN mf_product_attribute_description ON mf_product_attribute.id_mf_product_attribute=mf_product_attribute_description.id_mf_product_attribute '));

				//Utils::ArrayDisplay($dalData);
				$arrayObjAttribute = MfProductAttributeDAL::GetResult($dalData);

				$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
				$this->smarty->assign('arrayObjAttributeLinked', $arrayObjAttributeLinked);


				$objCategoryProduct->SetDescriptionObj($objCategoryProductDesc);
				$this->smarty->assign('objCategoryProduct',$objCategoryProduct);


				$this->smarty->assign('arrayObjAttribute', $arrayObjAttribute);
				$this->smarty->assign('info','Pola obowiązkowe muszą zostać wypełnione.');
				$this->smarty->assign('type','error');

				foreach ($out as $item) {
					$error[$item['field']] = $item['msg'];


				}
				$this->smarty->assign('error',$error);


			}



		}
	}


	public function AjaxAddLinkAttrAction($param) {
		//$array
	}



	public function DeleteAction($param) {
		$isLinked = MfProductLinkDAL::IsLinked($param['id'], 'mf_product_category', null, 'mf_product');
		$delete = true;
		$error = '';
		if ($isLinked > 0 ) {
			$delete = false;
		}

		$arrayLang = (Router::$arrayLang);
		unset($arrayLang[$param['lang']]);
		$langString = implode(',', $arrayLang);

		$isLang = MfProductCategoryDAL::CheakDescLang($param['id'], $param['lang']);

		//		if ($isLang) {
		//			$delete = false;
		//		}

		if ($delete) {

			foreach (Router::$arrayLang as $lang) {
				$objCategory = MfProductCategoryDAL::GetById($param['id'], $lang);
				$objCategoryDesc = $objCategory->getDescriptionObj();
				$dalDataDesc = MfProductCategoryDescriptionDAL::GetDalDataObj();
				$dalDataDesc->setObj($objCategoryDesc);
				MfProductCategoryDescriptionDAL::Delete($dalDataDesc);
			}




			$dalData = MfProductCategoryDAL::GetDalDataObj();
			$dalData->setObj($objCategory);
			MfProductCategoryDAL::Delete($dalData);
			$this->AddRedirectInfo('Element został usunięty', 'ok', Router::GenerateUrl('editCategory', array('ProductCategory' => 'Index')));
		} else {
			if ($isLinked) {
				$error .= 'Kategoria jest powiązana z produktem.';
			}
			//			if ($isLang) {
			//				$error .= $error ? '<br/><br/>' : '';
			//				$error .= 'Kategoria posiada wersję jezykową';
			//			}
			$this->AddRedirectInfo($error, 'error', Router::GenerateUrl('editCategory', array('ProductCategory' => 'Index')));
		}
	}


	/**
     * Wspolna metoda
     *
     */
	public function preDispatch($param) {


		$this->RunShared('Auth', $param);
		$this->Run($param);
		$this->AddScript('structure.js');
		$admin = AuthDAL::GetAdmin();
		$this->user = $admin;

		$this->smarty->assign('titleAdmin', 'Administracja');

		$struct = array(
		//'User' => array('User' => 'Index'),
		'Słowniki' => array('Dictionary' => 'Index'),
		'Zmienne serwisu' => array('Setup' => 'Index'),
		'Kategorie produktów' => array('ProductCategory' => 'Index'),
		'Serie produktów' => array('ProductSeries' => 'Index'),
		'Materiał produktów' => array('ProductSpec' => 'Index', 'type' => 2),
		'Kolor produktów' => array('ProductSpec' => 'Index', 'type' => 1),
		'Żarówki produktów' => array('ProductSpec' => 'Index', 'type' => 3),
		//'Parametry produktów' => array('ProductAttribute' => 'Index')


		);

		$this->smarty->assign('structure',$this->renderStruct($struct));

	}

	private function renderStruct($struct){
		$return = '';

		foreach($struct AS $k => $row){
			$return .= '<li><a href="' . Router::GenerateUrl('dictpig',$row).'">'.$k.'</a></li>';
		}

		$html = '<ul>';
		$html .= $return;
		$html .= '</ul>';


		return $html;
	}

	public function PostDispatch($param) {

	}


}

?>