<?

/**
 * $Id: SharedController.php 1254 2008-09-09 08:39:51Z lule $
 *
 * Kontroler elementow wspolnych
 *
 */
class SharedController extends Controller {

	private $user;

	public function SetUser($user) {
		$this->user = $user;
	}

	private function IsUser() {

		$user = Registry::Get('user');

		$this->SetUser($user);

		if (is_object($this->user)) {
			return true;
		} else {
			return false;
		}
	}

	public function Auth($param) {
		$user = AuthDAL::GetUser();
		//Utils::ArrayDisplay($user);
		$this->user = $user;
		//Utils::ArrayDisplay($this);
		$this->smarty->assign('user', $user);
		Registry::Set('user', $user);
		if (!is_object($user)) {
			//return false;
			//Utils::ArrayDisplay(Router::GenerateUrl('Order', array()));

			die(header("Location: " . Router::GenerateUrl('Login', array())));
			//$this->addRedirectInfo('Proszę się zalogować',Router::GenerateUrl('Order', array()));
		}
	}

	/**
	 * Glowna metoda
	 *
	 */
	public function Index() {
		
	}

	public function MainBox($param) {
		$countArray = range(0, 3);
		//Utils::ArrayDisplay($param);
		$dalData = MfHomeSiteDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		$dalData->setLimit(4);

		$arrayObjHome = MfHomeSiteDAL::GetResult($dalData);

		//Utils::ArrayDisplay($countArray);
		$arrayToEdit = array();
		foreach ($countArray as $key => $element) {
			if (key_exists($key, $arrayObjHome)) {
				$arrayToEdit[] = $arrayObjHome[$key];
			} else {
				$arrayToEdit[] = MfHomeSiteDAL::GetEmptyObj();
			}
		}


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

	public function BanerBox($param) {
		$countArray = range(0, 9);
		//Utils::ArrayDisplay($param);
		$dalData = MfHomeSiteBanerDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang']));
		$dalData->setSortBy('sort');
		$dalData->setLimit(10);

		$arrayObjHome = MfHomeSiteBanerDAL::GetResult($dalData);

		//Utils::ArrayDisplay($arrayObjHome);
		$arrayToEdit = array();
		foreach ($countArray as $key => $element) {
			if (key_exists($key, $arrayObjHome)) {
				$arrayToEdit[] = $arrayObjHome[$key];
			} else {
				$arrayToEdit[] = MfHomeSiteBanerDAL::GetEmptyObj();
			}
		}

		$slideshowSpeed = Registry::Get('slideshow_speed');
		$this->smarty->assign('slideshowSpeed', $slideshowSpeed);
		$this->smarty->assign('arrayToEditBaner', $arrayToEdit);
	}

	public function Boxs($param) {

		//================Sponsorzy==========
		$objSponsor = MfArticleBoxDAL::GetById(1);
		$this->smarty->assign('objSponsor', $objSponsor);
		//===============Mecz=================

		$datePub = Utils::GetNowDate();
		$dateNext = Utils::GetDate('-2 day');
		$dalData = MfEventDAL::GetDalDataObj();
		$dalData->addCondition('    ', '', ' `date_publication` <="' . $datePub . '" AND `date_event` >= "' . $dateNext . '" ');
		$dalData->addCondition('type', 1);
		$dalData->setLimit(2);
		$dalData->setSortBy('date_event ASC');
		$arrayObjEvent = MfEventDAL::GetResult($dalData, FALSE);
		if (count($arrayObjEvent) > 1) {
			$objEventBox = current($arrayObjEvent);
			$this->smarty->assign('objEventBox', $objEventBox);
			$objTeam1 = MfTeamDAL::GetById($objEventBox->getTeam1());
			$objTeam2 = MfTeamDAL::GetById($objEventBox->getTeam2());
			$this->smarty->assign('objTeam1', $objTeam1);
			$this->smarty->assign('objTeam2', $objTeam2);
		}

		//Utils::ArrayDisplay($objTeam1);
		//Utils::ArrayDisplay($objTeam2);
		//===============Tabela===============
		$dalData = MfTeamDAL::GetDalDataObj();
		$dalData->addCondition('publication', 1);
		$dalData->setLimit(7);
		$dalData->setSortBy('points DESC, `sort` ASC');
		$arrayObjTeam = MfTeamDAL::GetResult($dalData, FALSE);
		$this->smarty->assign('arrayObjTeam', $arrayObjTeam);
	}

	public function UserBox($param) {
		$this->smarty->assign('userBox', null);
		$this->smarty->assign('1col', '1col');

		if ($this->IsUser()) {
			$this->smarty->assign('1col', null);
			$this->smarty->assign('userBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
		}
	}

	public function ProfileBox($param) {
		$this->smarty->assign('profileBox', null);
		$this->smarty->assign('1col', '1col');
		if ($this->IsUser()) {
			$this->smarty->assign('1col', null);
			$this->smarty->assign('profileBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
		}
	}

	public function PersonBox($param) {
		$data = array('mf_article.id_structure' => $param['idStructure']);


		$data['mf_article_description.lang'] = $param['lang'];
		$data['mf_article.publication'] = 1;
		$date = Utils::GetNowDate();
		$data[' '] = array('value' => " mf_article.date_publication <= '$date' ", 'condition' => '');

		$arrayObj = SimpleArticle_MfArticleDAL::GetList($data, null, 'mf_article.date_publication DESC');
		//Utils::ArrayDisplay($arrayObj);
		$this->smarty->assign('articleList', $arrayObj);
		$this->smarty->assign('personBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
	}

	/*
	 * Generacja trzech menu (TopMenu, BottomMenu i LeftMenu)
	 */

	public function MenuBox($param) {

		$arrayTree = array();
		$dalData = StructureDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang'], 'publication' => '1', 'publication_menu' => '1', 'location' => 1));
		$dalData->setSortBy('sort');
		//array('lang' => $param['lang'], 'publication' => '1', 'publication_menu' => '1'), array(), 0, 'sort'
		$result = StructureDAL::GetResult($dalData);
		//Utils::ArrayDisplay($result);
		//$result = StructureDAL::GetResult(array('lang' => $param['lang'], 'publication' => '1'), array(), 0, 'sort');
		$menu = array();
		$idAndParent = array();



		foreach ($result as $item) {
			$menu[$item->GetId()] = $item;
		}

		$level0 = '';
		$level1 = '';
		$level2 = '';
		$level3 = '';
		$level4 = '';

		$topParentId = 0;
		$bottomParentId = null;
		$leftParentId = null;

		$topMenuArray = array();
		$bottomMenuArray = array();
		$leftMenuArray = array();


//NOWE sprawdzenie 
		if (isset($param['idStructure']) && $param['idStructure'] != '' && isset($menu[$param['idStructure']])) { // sprawdzam czy jest klinięte menu
			$idStructure = $param['idStructure'];
			$clickedElement = $menu[$idStructure];
			$level0 = $clickedElement;
			if ($level0->GetIdParent() == 0) {
				//Utils::ArrayDisplay('jestem w top');
				$this->smarty->assign('topElement', $level0);
				$this->smarty->assign('active0', $param['idStructure']);
				SessionProxy::SetValue('active0', $param['idStructure']);
				$this->smarty->assign('active1', null);
				SessionProxy::SetValue('active1', null);
				$this->smarty->assign('active2', null);
				SessionProxy::SetValue('active2', null);
				$this->smarty->assign('active3', null);
				SessionProxy::SetValue('active3', null);
			} else {
				//Utils::ArrayDisplay('druga linia start');
				$level0 = $menu[$idStructure];
				$level1 = $menu[$level0->GetIdParent()];
				//Utils::ArrayDisplay($level0->GetIdParent() . '= 0');
				$this->SetBreadCrumbs(array());
					$this->AddBreadCrumb($level1->GetName(), $level1->GetUrlWithType());
					$this->AddBreadCrumb($level0->GetName(), $level0->GetUrlWithType());
				if ($level1->GetIdParent() == 0) {
					//Utils::ArrayDisplay('level1');
					$this->smarty->assign('topElement', $level1);
					$this->smarty->assign('active0', $level1->GetId());
					SessionProxy::SetValue('active0', $level1->GetId());
					$this->smarty->assign('active1', $idStructure);
					SessionProxy::SetValue('active1', $idStructure);
					$this->smarty->assign('active2', null);
					SessionProxy::SetValue('active2', null);
					$this->smarty->assign('active3', null);
					SessionProxy::SetValue('active3', null);
				} else {
					//Utils::ArrayDisplay('trzecia linia start');
					$level0 = $menu[$idStructure];
					$level1 = $menu[$level0->GetIdParent()];
					$level2 = $menu[$level1->GetIdParent()];
					$this->SetBreadCrumbs(array());
					$this->AddBreadCrumb($level2->GetName(), $level2->GetUrlWithType());
					$this->AddBreadCrumb($level1->GetName(), $level1->GetUrlWithType());
					$this->AddBreadCrumb($level0->GetName(), $level0->GetUrlWithType());
					if ($level2->GetIdParent() == 0) {
						//Utils::ArrayDisplay('level2');
						$this->smarty->assign('topElement', $level2);
						$this->smarty->assign('active0', $level2->GetId());
						SessionProxy::SetValue('active0', $level2->GetId());
						$this->smarty->assign('active1', $level1->GetId());
						SessionProxy::SetValue('active1', $level1->GetId());
						$this->smarty->assign('active2', $idStructure);
						SessionProxy::SetValue('active2', $idStructure);
						$this->smarty->assign('active3', null);
						SessionProxy::SetValue('active3', null);
					} else {
						//Utils::ArrayDisplay('czwarta linia start');
						$level0 = $menu[$idStructure];
						$level1 = $menu[$level0->GetIdParent()];
						$level2 = $menu[$level1->GetIdParent()];
						$level3 = $menu[$level2->GetIdParent()];
						$this->SetBreadCrumbs(array());
						$this->AddBreadCrumb($level3->GetName(), $level3->GetUrlWithType());
						$this->AddBreadCrumb($level2->GetName(), $level2->GetUrlWithType());
						$this->AddBreadCrumb($level1->GetName(), $level1->GetUrlWithType());
						$this->AddBreadCrumb($level0->GetName(), $level0->GetUrlWithType());
						if ($level3->GetIdParent() == 0) {
							//Utils::ArrayDisplay('level3');
							$this->smarty->assign('topElement', $level3);
							$this->smarty->assign('active0', $level3->GetId());
							SessionProxy::SetValue('active0', $level3->GetId());
							$this->smarty->assign('active1', $level2->GetId());
							SessionProxy::SetValue('active1', $level2->GetId());
							$this->smarty->assign('active2', $level1->GetId());
							SessionProxy::SetValue('active2', $level1->GetId());
							$this->smarty->assign('active3', $idStructure);
							SessionProxy::SetValue('active3', $idStructure);
						} else {
							
						}
					}
				}
			}
		} else {
			$this->smarty->assign('topElement', new Structure());
			$this->smarty->assign('active0', null);
			$this->smarty->assign('active1', null);
			$this->smarty->assign('active2', null);
			$this->smarty->assign('active3', null);
		}






///		
//		if (isset($param['idStructure']) && $param['idStructure'] != '' && key_exists($param['idStructure'], $menu)) {
//			if ($menu[$param['idStructure']]->GetIdParent() == 0) { //jesli klikniety link jest z top
//				$bottomParentId = $param['idStructure'];
//				$leftParentId = null;
//
//				$topElement = $menu[$param['idStructure']];
//				$level0 = $menu[$param['idStructure']];
//				$this->AddBreadCrumb($topElement->GetName(), $topElement->GetUrlWithType());
//				//Utils::ArrayDisplay($topElement);
//				$this->smarty->assign('topElement', $topElement);
//				$this->smarty->assign('active0', $param['idStructure']);
//				SessionProxy::SetValue('active0', $param['idStructure']);
//				$this->smarty->assign('active1', null);
//				SessionProxy::SetValue('active1', null);
//				$this->smarty->assign('active2', null);
//				SessionProxy::SetValue('active2', null);
//				$this->smarty->assign('active3', null);
//				SessionProxy::SetValue('active3', null);
//			} else { //jesli nie
//				$clicked = $menu[$param['idStructure']];
//				$parentId = $menu[$param['idStructure']]->GetIdParent();
//				$parent = $menu[$parentId];
//				//Utils::ArrayDisplay($clicked);
//				$this->AddBreadCrumb($parent->GetName(), $parent->GetUrlWithType());
//				$this->AddBreadCrumb($clicked->GetName(), $clicked->GetUrlWithType());
//				if ($parent->GetIdParent() == 0) { //jesli rodzic kliknietego jest z top
//					$bottomParentId = $parent->GetId();
//					$leftParentId = $clicked->GetId();
//					$clicked = $menu[$param['idStructure']];
//
//					$topElement = $menu[$clicked->GetIdParent()];
//					//Utils::ArrayDisplay($topElement);
//					$this->smarty->assign('topElement', $topElement);
//					$this->smarty->assign('active0', $clicked->GetIdParent());
//					SessionProxy::SetValue('active0', $clicked->GetIdParent());
//					$this->smarty->assign('active1', $clicked->GetId());
//					SessionProxy::SetValue('active1', $clicked->GetId());
//					$this->smarty->assign('active2', null);
//					SessionProxy::SetValue('active1', null);
//					$this->smarty->assign('active3', null);
//					SessionProxy::SetValue('active3', null);
//				} else { //jesli nie
//					$clicked = $menu[$param['idStructure']];
//					$leftParentId = $clicked->GetIdParent();
//					$parent = $menu[$clicked->GetIdParent()];
//					$bottomParentId = $parent->GetIdParent();
//
//					$topElement = $menu[$parent->GetIdParent()];
//					//Utils::ArrayDisplay($topElement);
//					//
//					$this->SetBreadCrumbs(array());
//					$this->AddBreadCrumb($topElement->GetName(), $topElement->GetUrlWithType());
//					$this->AddBreadCrumb($parent->GetName(), $parent->GetUrlWithType());
//					$this->AddBreadCrumb($clicked->GetName(), $clicked->GetUrlWithType());
//					//
//
//					$this->smarty->assign('topElement', $topElement);
//					$this->smarty->assign('active0', $parent->GetIdParent());
//					SessionProxy::SetValue('active0', $parent->GetIdParent());
//					$this->smarty->assign('active1', $clicked->GetIdParent());
//					SessionProxy::SetValue('active1', $clicked->GetIdParent());
//					$this->smarty->assign('active2', $clicked->GetId());
//					SessionProxy::SetValue('active2', $clicked->GetId());
//					$this->smarty->assign('active3', null);
//					SessionProxy::SetValue('active3', null);
//
//
//					//
//				}
//			}
//		} else {
//			$topParentId = 0;
//			$bottomParentId = null;
//			$leftParentId = null;
//			//Utils::ArrayDisplay($param);
//			//			if ($param['urlParam']) {
//			//				$this->smarty->assign('active0', SessionProxy::GetValue('active0'));
//			//				$this->smarty->assign('active0', SessionProxy::GetValue('active0'));
//			//				$this->smarty->assign('active0', SessionProxy::GetValue('active0'));
//			//			} else {
//			$this->smarty->assign('topElement', new Structure());
//			$this->smarty->assign('active0', null);
//			$this->smarty->assign('active1', null);
//			$this->smarty->assign('active2', null);
//			//}
//		}
		//Utils::ArrayDisplay($menu);
		//		foreach($menu as $item) {
		//			if($item->GetIdParent() == $topParentId) {
		//				$topMenuArray[] = $item;
		//			} else if($item->GetIdParent() == $bottomParentId && $bottomParentId != null) {
		//				$bottomMenuArray[] = $item;
		//			} else if($item->GetIdParent() == $leftParentId && $leftParentId != null) {
		//				$leftMenuArray[] = $item;
		//			}
		//		}


		foreach ($menu as $key => $obj) {

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

		//Utils::ArrayDisplay($arrayTree);
		//Utils::ArrayDisplay($this->GetBreadCrumbs());
		//		foreach($menu as $item) {
		//			if($item->GetIdParent() == 0) {
		//				$topMenuArray[] = $item;
		//			} else if($item->GetIdParent() == $bottomParentId && $bottomParentId != null) {
		//				$bottomMenuArray[$item->GetIdParent()][] = $item;
		//			} else if($item->GetIdParent() == $leftParentId && $leftParentId != null) {
		//				$leftMenuArray[] = $item;
		//			}
		//		}

		$returnTopArray = array();
		$returnLeftArray = array();
		$returnLeftArray = array();
		foreach ($topMenuArray as $topItem) {
			//Utils::ArrayDisplay($topItem->GetType());
			if ($topItem->GetType() == 1) {
				$returnTopArray[] = $topItem;
			}
			if ($topItem->GetType() == 2) {
				$returnLeftArray[] = $topItem;
			}
		}
		$topMenuArray = $returnTopArray;
		$menuLeftArray = $returnLeftArray;

		//Utils::ArrayDisplay($this->GetBreadCrumbs());
		//Utils::ArrayDisplay($arrayTree);
		//Utils::ArrayDisplay($bottomMenuArray);
		//Controller::AddBreadCrumb();

		$this->smarty->assign('breadCrumbs', $this->GetBreadCrumbs());
		$this->smarty->assign('lang', $param['lang']);
		$this->smarty->assign('arrayTree', $arrayTree);
		$this->smarty->assign('topMenuArray', $topMenuArray);
		$this->smarty->assign('bottomMenuArray', $bottomMenuArray);
		$this->smarty->assign('leftMenuArray', $leftMenuArray);
		$this->smarty->assign('menuLeftArray', $menuLeftArray);

//		$this->smarty->assign('topMenuBox', $this->smarty->fetch($this->templatePath.'TopMenuBox.tpl'));
//		if (count($menuLeftArray) > 0) {
//			$this->smarty->assign('leftMenuBox', $this->smarty->fetch($this->templatePath.'LeftMenuBox.tpl'));
//		} else {
//			$this->smarty->assign('leftMenuBox', false);
//		}
//		$this->smarty->assign('bottomMenuBox', $this->smarty->fetch($this->templatePath.'BottomMenuBox.tpl'));
//		$this->smarty->assign('contentMenuBox', $this->smarty->fetch($this->templatePath.'ContentMenuBox.tpl'));
//		$this->smarty->assign('menuLeftBox', $this->smarty->fetch($this->templatePath.'menuLeftBox.tpl'));
//		$this->smarty->assign('menuBottomBox', $this->smarty->fetch($this->templatePath.'menuBottomBox.tpl'));


		$this->smarty->assign('MenuTopTree', $this->smarty->fetch($this->templatePath . 'MenuTopTree.tpl'));
		$this->smarty->assign('MenuTopChildTree', $this->smarty->fetch($this->templatePath . 'MenuTopChildTree.tpl'));
		$this->smarty->assign('MenuBottomTree', $this->smarty->fetch($this->templatePath . 'MenuBottomTree.tpl'));
	}

	/*
	 * Box z lewej strony
	 *
	 * dla wprowadzeonego contentu moze być róży
	 * TODO: Dorobić parametryzacje i ponieranie odpowiedniej treści
	 */

	public function BoxLeft($param) {



		//Utils::ArrayDisplay($param);
		if (isset($param['idStructure'])) {
			$objElement = StructureDAL::GetById($param['idStructure']);
			//Utils::ArrayDisplay($objElement);
			$this->smarty->assign('objElement', $objElement);
			$this->smarty->assign('param', $param);
			$this->smarty->assign('boxLeft', $this->smarty->fetch($this->templatePath . 'BoxLeft.tpl'));
		} else {
			$this->smarty->assign('boxLeft', '');
			$objElement = new Structure();
		}

		$menu = StructureDAL::GetResultOld(array(), array(), 0, 'sort');

		$tree = StructureDAL::GetTree(array(), array());
		//Utils::ArrayDisplay($tree);

		$topMenuArray = array();
		$bottomMenuArray = array();
		$leftMenuArray = array();
		$mainIds = array();

		foreach ($menu as $item) {
			if ($item->GetIdParent() == 0) {
				$topMenuArray[] = $item;
				$mainIds[] = $item->GetId();
			} else {
				if (in_array($item->GetIdParent(), $mainIds)) {
					$bottomMenuArray[] = $item;
				} else {
					$leftMenuArray[] = $item;
				}
			}
		}

		if (isset($param['parentId']) && $param['parentId'] != '')
			$parentId = $param['parentId'];
		else
			$parentId = null;

		//if(isset($param['mainId']) && $param['mainId'] != '') $mainId = $param['mainId'];
		//else $mainId = null;
		//Utils::ArrayDisplay($bottomMenuArray);


		if (isset($param['id']) && $param['id'] != '')
			$id = $param['id'];
		else
			$id = null;


		$this->smarty->assign('objElement', $objElement);
		$this->smarty->assign('pageUrl', ''); //Router::GenerateUrl($param['urlDetailLabel'], array('id')));
		$this->smarty->assign('parentId', $parentId);
		//$this->smarty->assign('mainId', $mainId);
		$this->smarty->assign('id', $id);

		$this->smarty->assign('topMenuArray', $topMenuArray);
		$this->smarty->assign('bottomMenuArray', $bottomMenuArray);
		$this->smarty->assign('leftMenuArray', $leftMenuArray);

		//Utils::ArrayDisplay($bottomMenuArray);
		$this->smarty->assign('BoxLeft', $this->smarty->fetch($this->templatePath . 'BoxLeft.tpl'));
	}

	public function Newsletter() {
		$this->partialTemplate = 'Newsletter.tpl';
		$this->smarty->assign('NewsletterBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
	}

	public function BottomBox($param) {

		$dalData = StructureDAL::GetDalDataObj();
		$dalData->setCondition(array('lang' => $param['lang'], 'publication' => '1', 'publication_menu' => '1', 'type' => '2', 'id_parent' => '0'));
		$dalData->setSortBy('sort');
		//array('lang' => $param['lang'], 'publication' => '1', 'publication_menu' => '1'), array(), 0, 'sort'
		$result = StructureDAL::GetResult($dalData);
		//Utils::ArrayDisplay($result);
		//$result = StructureDAL::GetResult(array('lang' => $param['lang'], 'publication' => '1'), array(), 0, 'sort');
		$menu = array();
		$idAndParent = array();




		$this->smarty->assign('arrayBottomElement', $result);

		$this->partialTemplate = 'bottomBox.tpl';
		$this->smarty->assign('bottomBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
	}

	public function MetaDescription() {


		$this->partialTemplate = 'MetaDescription.tpl';
		$this->smarty->assign('MetaDescription', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
	}

	public function Footer() {
		
	}

	public function Banner($param) {

		$arrayBanner = HomeDAL::GetAll($param['lang']);
		//Utils::ArrayDisplay($arrayBanner);
		$this->smarty->assign('arrayBanner', $arrayBanner);
	}

	public function Consumer($param) {

		$arrayObjCustomer = CustomerDAL::GetAllCustomer();
		$this->smarty->assign('arrayObjCustomer', $arrayObjCustomer);
		$this->smarty->assign('consumerBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
	}

	public function News($param) {

		$param['idCategory'] = 2;
		$data = array();
		if ($param['idCategory']) {
			$idCategory = $param['idCategory'];
			$this->smarty->assign('idCategory', $idCategory);
			//			if ($idCategory == 2) {
			//				$idCategory = null;
			//			}
			$idsContent = MfLinkDAL::GetIdString('mf_article', 'mf_article_category', $idCategory, 1);
			$categoryData = array('mf_article.id_mf_article' => array('condition' => 'IN', 'value' => $idsContent));
		} else {
			$idsContent = '()';
			$categoryData = array();
		}
		//Utils::ArrayDisplay($idsContent);

		$data = array_merge($data, $categoryData);

		$data['mf_article_description.lang'] = $param['lang'];
		$data['mf_article.publication'] = 1;
		$date = Utils::GetNowDate();
		$data[' '] = array('value' => " mf_article.date_publication <= '$date' ", 'condition' => '');

		$dalData = SimpleArticle_MfArticleDAL::GetDalDataObj();
		$dalData->setCondition(array('mf_article_description.lang' => $param['lang'], 'mf_article.publication' => 1));
		$dalData->addCondition('mf_article.id_mf_article', $idsContent, ' IN ');
		$dalData->setJoin(array('SimpleArticle_MfArticleDescription' => ' LEFT JOIN mf_article_description ON mf_article.id_mf_article=mf_article_description.id_mf_article', 'Structure' => ' LEFT JOIN mf_structure ON mf_structure.id_mf_structure=mf_article.id_structure'));
		$sortBy = 'mf_article.date_publication DESC';
		$dalData->setSortBy($sortBy);
		$dalData->setLimit(3);
		$arrayObj = SimpleArticle_MfArticleDAL::GetResult($dalData, false);
//Utils::ArrayDisplay($arrayObj);
		//$arrayObj = SimpleArticle_MfArticleDAL::GetResultOld($data, array(), 2, 'mf_article.date_publication DESC', false, true);
		//Utils::ArrayDisplay($arrayObj[0]->GetStructure());



		$this->smarty->assign('moreNews', Dictionary::Translate('read_more'));
		$this->smarty->assign('arrayObjNewsIndex', $arrayObj);
//		Utils::ArrayDisplay($this->smarty->fetch($this->templatePath.$this->partialTemplate));
		$this->smarty->assign('newsBox', $this->smarty->fetch($this->templatePath . $this->partialTemplate));
	}

	/**
	 * Boks wyswietlajacy buhaje 
	 *
	 * @param unknown_type $param
	 */
	public function BullBox($param) {
		$this->smarty->assign('boxBuhajTop', isset($param['top']) ? $param['top'] : true);
		$this->smarty->assign('arrayObjBull', AnimalDAL::GetChosenBulls());
	}

	/**
	 * Boks wyswietlajacy knury
	 *
	 * @param unknown_type $param
	 */
	public function PigBox($param) {
		$this->smarty->assign('boxBuhajTop', isset($param['top']) ? $param['top'] : true);
		$this->smarty->assign('arrayObjPigs', PigDAL::GetChosenPigs());
	}

	public function PigBoxSearch($search) {
		$isAdvanced = isset($search['search']) ? $search['search'] : SessionProxy::GetValue('isPigAdvanced');
		if (isset($search['grow1']) && strlen($search['grow1']))
			$search['grow1'] = (float) $search['grow1'];
		if (isset($search['grow2']) && strlen($search['grow2']))
			$search['grow2'] = (float) $search['grow2'];
		if (isset($search['meat_proc1']) && strlen($search['meat_proc1']))
			$search['meat_proc1'] = (float) $search['meat_proc1'];
		if (isset($search['meat_proc2']) && strlen($search['meat_proc2']))
			$search['meat_proc2'] = (float) $search['meat_proc2'];
		if (isset($search['children_nr1']) && strlen($search['children_nr1']))
			$search['children_nr1'] = (float) $search['children_nr1'];
		if (isset($search['children_nr2']) && strlen($search['children_nr2']))
			$search['children_nr2'] = (float) $search['children_nr2'];
		$this->smarty->assign('isAdvanced', $isAdvanced);
		$this->smarty->assign('races', RaceDAL::getRaces(2));
		$this->smarty->assign('search', $search);
	}

	public function BullBoxSearch($search, $advanced = false) {
		//$this->smarty->assign('boxBuhajTop', true);
		//$this->smarty->assign('arrayObjPigs', PigDAL::GetChosenPigs());

		$searchable = StatDAL::GetSearchable();
		$this->smarty->assign('searchable', $searchable);
		$this->smarty->assign('races', RaceDAL::getRaces(1));

		$this->smarty->assign('advanced', $advanced);

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

	/**
	 * Boks wyswietlajacy pszczoły
	 *
	 * @param unknown_type $param
	 */
	public function BeeBox($param) {
		$pszczolyLabel = array('pl' => 'pszczolyLabel', 'en' => 'beesLabel', 'de' => 'bienenLabel', 'ua' => 'beesLabel', 'fr' => 'abeillesLabel');


		$this->smarty->assign('pszczolyLabel', $pszczolyLabel);
		$this->smarty->assign('lang', $param['lang']);
	}

	/**
	 * Boks wyswietlajacy króliki
	 *
	 * @param unknown_type $param
	 */
	public function RabbitBox($param) {
		$krolikiLabel = array('pl' => 'krolikiLabel', 'en' => 'rabbitsLabel', 'de' => 'kaninchenLabel', 'ua' => 'rabbitsLabel', 'fr' => 'lapinsLabel');
		$this->smarty->assign('krolikiLabel', $krolikiLabel);

		$this->smarty->assign('lang', $param['lang']);
	}

	/**
	 * Boks Special Offer
	 *
	 * @param unknown_type $param
	 */
	public function SpecialOfferBox($param) {

		$this->smarty->assign('lang', $param['lang']);
		$dalData = MfFileDAL::GetDalDataObj();
		$dalData->setLimit(30);
		$date = Utils::GetNowDate();
		$dalData->setCondition(array('date_publication' => array('value' => "'$date'", 'condition' => '<='), 'mf_file.publication' => 1, 'lang' => $param['lang']));
		$dalData->setSortBy("date_publication desc");
		$arrayObjFile = MfFileDAL::GetResult($dalData);
		//Utils::ArrayDisplay($arrayObjFile);
		$this->smarty->assign('arrayObjFile', $arrayObjFile);
	}

	/**
	 * tag cloud box
	 * 
	 * get random 30 tags and generate could with them
	 */
	public function TagCloudBox($param) {

		//Utils::ArrayDisplay(__METHOD__);
		$dalData = TagDAL::GetDalDataObj();
		$dalData->setLimit(30);
		$dalData->setCondition(array('counter' => array('value' => '0', 'condition' => '>'), 'type' => 1, 'lang' => $param['lang']));
		$dalData->setSortBy("counter desc");
		$dalData->setQueryFields(array("id_mf_tag", "tag", "counter", 'type'));
		$tagsArray = TagDAL::DefaultGetResult($dalData);
		foreach ($tagsArray as $key => $tag) {
			if ($tag->GetCounter() < 2) {
				//Utils::ArrayDisplay($tag);
				$conditions = array(
						'searchTags' => Utils::CleanStringQuery($tag->GetTag()),
				);
			}
		}
		// randomize output
		shuffle($tagsArray);
		$this->smarty->assign('tagCloud', MainController::GenerateTagCloud($tagsArray));
	}

	public function InfoFrame($param) {
		if (is_array($param)) {
			$this->smarty->assign('error', $param["type"]);
			$this->smarty->assign('info', $param["info"]);
		} else {
			$this->smarty->assign('error', false);
			$this->smarty->assign('info', $param);
		}
	}

	public function FormCareer($param) {

		$this->addScript('jQuery/jquery.validate.js');
		$this->addScript('jQuery/validate.sendCareer.js');
		$this->addScript('jQuery/extras.sendCareer.js');

		if (isset($_POST['send'])) {

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

			//Utils::ArrayDisplay($_POST);
			$post = Request::GetAllPost();
			$validator = new Validator($post);
			$errorList = '';
			$error = '';
			$empty = '';
			$wrongEmail = '';
			$wrongPhone = '';

			$validator->IsEmpty('name', Dictionary::Translate('required_field'));
			$validator->IsEmpty('last_name', Dictionary::Translate('required_field'));
			$validator->IsEmpty('email', Dictionary::Translate('required_field'));
			$validator->IsEmailAddress('email', Dictionary::Translate('required_field'));
			$validator->IsEmpty('phone', Dictionary::Translate('required_field'));
			//$validator->IsFile('file', Dictionary::Translate('required_file'));

			$out = $validator->GetErrorList();

			//Utils::ArrayDisplay($out);
			if (!empty($out)) {
				$errorList = true;
			}

			if ($errorList) {
				$this->smarty->assign('errorList', $validator->GetErrorList());
			} elseif ($wrongEmail) {
				
			} else {



				$this->smarty->assign('message', $post['message']);
				$this->smarty->assign('email', $post['email']);
				$this->smarty->assign('phone', $post['phone']);
				$this->smarty->assign('name', $post['name']);
				$this->smarty->assign('last_name', $post['last_name']);
				$this->smarty->assign('position', $post['position']);

				$txtmessage = $this->smarty->fetch('partial/Shared/MailCareer.tpl');
				//Utils::ArrayDisplay($txtmessage);

				$mail = new PHPMailer();
				$mail->CharSet = "utf-8";
				$mail->Subject = "Formularz - kariera - NTP CONSTRUCTION";
				$mail->SMTPAuth = true;
				$mail->Mailer = 'smtp';
				$mail->Host = Registry::Get('mail_host');
				$mail->Port = 587;
				$mail->IsHTML(true);
				$mail->From = Registry::Get('mail_from_career');
				$mail->FromName = "FromName";
				$mail->Username = Registry::Get('user_smtp');
				$mail->Password = Registry::Get('password_smtp');
				$mail->AddAddress(Registry::Get('address_to_career'), "Study Tours");


				$mail->Body = $txtmessage;

				//Utils::ArrayDisplay($_POST);
				//Utils::ArrayDisplay($_FILES);
				if ($_FILES['file']['tmp_name']) {

					$destName = Utils::TextToUrl($_FILES['file']['name']);
					if (file_exists(PATH_STATIC_CONTENT . 'upload/temp/' . $destName)) {
						$destName = '1_' . $destName;
					}

					move_uploaded_file($_FILES['file']['tmp_name'], PATH_STATIC_CONTENT . 'upload/temp/' . $destName);
				}
				$mail->AddAttachment(PATH_STATIC_CONTENT . 'upload/temp/' . $destName);

				$mail->Send();


				SessionProxy::SetValue("sendFormInfo", true);
				//$main = new MainController();
				//				$main->addRedirectInfo( Dictionary::Translate('message_sent'),null, Router::GenerateUrl($param['urlParam'].'Label',array()),0);
			}
		}
	}

	public function FormDownload($param) {

		$this->addScript('jQuery/jquery.validate.js');
		$this->addScript('jQuery/validate.sendFormDownload.js');
		$this->addScript('jQuery/extras.sendFormDownload.js');

		if (isset($_POST['send'])) {

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

			//Utils::ArrayDisplay($_POST);
			$post = Request::GetAllPost();
			$validator = new Validator($post);
			$errorList = '';
			$error = '';
			$empty = '';
			$wrongEmail = '';
			$wrongPhone = '';

			$validator->IsEmpty('name', Dictionary::Translate('required_field'));
			$validator->IsEmpty('last_name', Dictionary::Translate('required_field'));
			$validator->IsEmpty('email', Dictionary::Translate('required_field'));
			$validator->IsEmailAddress('email', Dictionary::Translate('required_field'));
			$validator->IsEmpty('phone', Dictionary::Translate('required_field'));
			//$validator->IsFile('file', Dictionary::Translate('required_file'));

			$out = $validator->GetErrorList();

			//Utils::ArrayDisplay($out);
			if (!empty($out)) {
				$errorList = true;
			}

			if ($errorList) {
				$this->smarty->assign('errorList', $validator->GetErrorList());
			} elseif ($wrongEmail) {
				
			} else {



				$this->smarty->assign('message', $post['message']);
				$this->smarty->assign('company', $post['company']);
				$this->smarty->assign('email', $post['email']);
				$this->smarty->assign('phone', $post['phone']);
				$this->smarty->assign('name', $post['name']);
				$this->smarty->assign('last_name', $post['last_name']);
				$this->smarty->assign('document_type', $post['document_type']);
				$this->smarty->assign('document_name', $post['document_name']);

				$txtmessage = $this->smarty->fetch('partial/Shared/MailDownload.tpl');
				//Utils::ArrayDisplay($txtmessage);

				$mail = new PHPMailer();
				$mail->CharSet = "utf-8";
				$mail->Subject = "Formularz - download - Study Tours";
				$mail->SMTPAuth = true;
				$mail->Mailer = 'smtp';
				$mail->Host = Registry::Get('mail_host');
				$mail->Port = 587;
				$mail->IsHTML(true);
				$mail->From = Registry::Get('mail_from_download');
				$mail->FromName = "Study Tours";
				$mail->Username = Registry::Get('user_smtp');
				$mail->Password = Registry::Get('password_smtp');
				$mail->AddAddress(Registry::Get('address_to_download'), "Study Tours");


				$mail->Body = $txtmessage;

				//Utils::ArrayDisplay($_POST);
				//Utils::ArrayDisplay($_FILES);
				if ($_FILES['file']['tmp_name']) {

					$destName = Utils::TextToUrl($_FILES['file']['name']);
					if (file_exists(PATH_STATIC_CONTENT . 'upload/temp/' . $destName)) {
						$destName = '1_' . $destName;
					}

					move_uploaded_file($_FILES['file']['tmp_name'], PATH_STATIC_CONTENT . 'upload/temp/' . $destName);
				}
				$mail->AddAttachment(PATH_STATIC_CONTENT . 'upload/temp/' . $destName);

				$mail->Send();


				SessionProxy::SetValue("sendFormInfo", true);
				//$main = new MainController();
				//				$main->addRedirectInfo( Dictionary::Translate('message_sent'),null, Router::GenerateUrl($param['urlParam'].'Label',array()),0);
			}
		}
	}

	public function GetUrlLang($param) {
		//Utils::ArrayDisplay($param);
		$lang = $param['lang'];
		if (isset($param['idStructure'])) {
			$idStructure = $param['idStructure'];
		} else {
			$idStructure = 0;
		}
		$db = Registry::Get('db');
		$sql = 'SELECT id_lang_pl, id_lang_de, id_lang_en, id_lang_ru FROM mf_link_lang  WHERE 1=1 ' .
						" AND id_lang_" . $lang . " = $idStructure" .
						" GROUP BY id_lang_pl";
		//Utils::ArrayDisplay($sql);
		$stmt = $db->execute($sql);
		if ($arrayLangId = $stmt->FetchArray()) {
			$labelPl = StructureDAL::GetLabel($arrayLangId['id_lang_pl']);
			$arrayUrl['pl'] = Router::UrlForLang($labelPl, 'pl');
			$labelEn = StructureDAL::GetLabel($arrayLangId['id_lang_en']);
			$arrayUrl['en'] = Router::UrlForLang($labelEn, 'en');
			$labelDe = StructureDAL::GetLabel($arrayLangId['id_lang_de']);
			$arrayUrl['de'] = Router::UrlForLang($labelDe, 'de');
			$labelRu = StructureDAL::GetLabel($arrayLangId['id_lang_ru']);
			$arrayUrl['ru'] = Router::UrlForLang($labelRu, 'ru');
		} else {
			$arrayUrl['pl'] = Router::UrlForLang(null, 'pl');
			$arrayUrl['en'] = Router::UrlForLang(null, 'en');
			$arrayUrl['de'] = Router::UrlForLang(null, 'de');
			$arrayUrl['ru'] = Router::UrlForLang(null, 'ru');
		}
		//Utils::ArrayDisplay($arrayUrl);

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

	public function CrmConfiguration($param) {
		
	}

	public function ZoneMenu($param) {


		$user = SessionProxy::GetValue(EnumSessionValue::USER_OBJECT);

		if (is_object($user)) {


			$this->smarty->assign('user', $user);
		} else {
			$this->SetNoRender();
		}
	}

	public function LogoBoxMedia($param) {


		$dalData = MfLogaDAL::GetDalDataObj();
		$dalData->addCondition('publication', 1);
		$dalData->addCondition('type', 2);
		$dalData->setSortBy('sort');
		$arrayObj = MfLogaDAL::GetResult($dalData);
		$this->smarty->assign('arrayObjLogoMedia', $arrayObj);
	}

	public function LogoBoxSponsor($param) {


		$dalData = MfLogaDAL::GetDalDataObj();
		$dalData->addCondition('publication', 1);
		$dalData->addCondition('type', 1);
		$dalData->setSortBy('sort');
		$arrayObj = MfLogaDAL::GetResult($dalData);
		$this->smarty->assign('arrayObjLogoSponsor', $arrayObj);
	}

	public function postDispatch($param) {
		
	}

	public function preDispatch() {
		
	}

}

?>
