<?php

/**
 * $Id$
 * Proste artykuly
 *
 */
class SimpleArticle_IndexController extends ModuleController implements ControllerInterface {

	const TITLE = 'Artykuły';

	/**
	 * Domyślna metoda
	 *
	 * @param array $param
	 */
	public function IndexAction($param) {

		$maxArtOnPage = 8;

		//Utils::ArrayDisplay($param);
		$data = array();
		if ($param['idCategory']) {
			//Utils::ArrayDisplay($param);

			switch ($param['idCategory']) {
				case '8':
					//Utils::ArrayDisplay($param);

					$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
					//$this->AddTitle($objArticle->GetTitle());
					$this->smarty->assign('titleGif', 'firma.gif');
					//Utils::ArrayDisplay($objArticle->GetDescriptionArray());

					$this->smarty->assign('objArticle', $objArticle);
					$this->partialTemplate = 'IndexCompany.tpl';
					$showList = false;
					$maxArtOnPage = 1000;

					break;
				case '5':
					//Utils::ArrayDisplay($param);
					$this->smarty->assign('titleGif', 'portfolio.gif');
					$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
					//$this->AddTitle($objArticle->GetTitle());
					//$this->smarty->assign('showGallery', true);
					//Utils::ArrayDisplay($objArticle->GetDescriptionArray());
					$this->smarty->assign('objArticle', $objArticle);
					$this->partialTemplate = 'IndexProject.tpl';
					$showList = true;
					$maxArtOnPage = 1000;
					break;
				case '9':
					//Utils::ArrayDisplay($param);
					$this->smarty->assign('titleGif', 'portfolio.gif');
					$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
					//$this->AddTitle($objArticle->GetTitle());
					$this->smarty->assign('showGallery', true);
					//Utils::ArrayDisplay($objArticle->GetDescriptionArray());
					$this->smarty->assign('objArticle', $objArticle);
					$this->partialTemplate = 'IndexProject.tpl';
					$showList = true;
					$maxArtOnPage = 15;
					break;
				case '3':
					$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
					//$this->AddTitle($objArticle->GetTitle());
					$this->smarty->assign('showGallery', true);
					//Utils::ArrayDisplay($objArticle->GetDescriptionArray());
					//$this->RunShared('CustomerBox', $param);
					$this->smarty->assign('objArticle', $objArticle);
					$this->partialTemplate = 'IndexProgram.tpl';
					$showList = true;
					$maxArtOnPage = 8;

					break;
				case '6':
					$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
					//$this->AddTitle($objArticle->GetTitle());
					$this->smarty->assign('showGallery', true);
					//Utils::ArrayDisplay($objArticle->GetDescriptionArray());
					//$this->RunShared('CustomerBox', $param);
					$this->smarty->assign('objArticle', $objArticle);
					$this->partialTemplate = 'IndexKnowledge.tpl';
					$showList = true;
					$maxArtOnPage = 8;

					break;
				case '11':
					$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
					//$this->AddTitle($objArticle->GetTitle());
					$this->smarty->assign('showGallery', true);
					//Utils::ArrayDisplay($objArticle->GetDescriptionArray());
					//$this->RunShared('CustomerBox', $param);
					$this->smarty->assign('objArticle', $objArticle);
					$this->partialTemplate = 'IndexProgram.tpl';
					$showList = true;
					$maxArtOnPage = 8;

					break;
				default:
					//$this->AddTitle('aktualności');
					$this->smarty->assign('titleGif', 'aktualnosci.gif');
					$this->partialTemplate = 'Index.tpl';
					$showList = true;
			}
		} else {
			$idsContent = '()';
			$categoryData = array();
		}




		if ($showList) {
			$data = array('mf_article.id_structure' => $param['idStructure']);
			$idsContent = '()';
			$categoryData = array();

			//Utils::ArrayDisplay($categoryData);

			$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' => '');


			//Utils::ArrayDisplay($data);

			$page = 1;

			if (isset($param['p']) && $param['p'] > 0) {
				$page = $param['p'];
			}
			SessionProxy::SetValue('__news_page_no__', $page);




			$offset = ($page - 1) * $maxArtOnPage;

			//Utils::ArrayDisplay($param);
			//Utils::ArrayDisplay($offset);



			try {

				if ($param['idCategory'] == 5) {
					$sortBy = 'mf_article.date_publication ASC';
				} else {
					$sortBy = 'mf_article.date_publication DESC';
				}
				$arrayObj = SimpleArticle_MfArticleDAL::GetList($data, sprintf(' %d OFFSET %d', $maxArtOnPage, $offset), $sortBy);
				$arrayObjCount = SimpleArticle_MfArticleDAL::GetResultOld($data, array(), null, null, true);
			} catch (Exception $e) {
				$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			}

			//$this->smarty->assign('tableModuleName', $tableModuleName);
			//$this->smarty->assign('lang', $lang);

			$this->smarty->assign('page', $page);
			$this->smarty->assign('maxPage', ceil($arrayObjCount / $maxArtOnPage));
			$this->smarty->assign('arrayObj', $arrayObj);
			$arrayName = array();
			foreach ($arrayObj as $objArt) {
				$arrayName[] = $objArt->GetTitle();
			}
			//Utils::ArrayDisplay($arrayName);

			$this->smarty->assign('articleList', $arrayObj);
			$this->smarty->assign('arrayName', $arrayName);

			//if ($param['idCategory'] == 3) {
			//$this->RunShared('FormCareer', $param);
			//if (SessionProxy::IsSetValue('sendFormInfo')) {
			//$this->addRedirectInfo( Dictionary::Translate('message_sent'),null, Router::GenerateUrl($param['urlParam'].'Label',array()),0);
			//}
			//}
		}
	}

	public function SubsiteAction($param) {
		//Utils::ArrayDisplay($param);
		$this->smarty->assign('hideSubMenu', true);
		switch ($param['idModule']) {
			case '14':
				$limit = 1000;
				if ($param['urlParam'] == 'skolresor') {
					$limit = 2;
				}
				break;
			case '18':
				$limit = 8;
				$this->partialTemplate = 'SubPremium.tpl';
				break;
			case '19':
				$limit = 1000;
				$this->partialTemplate = 'SubMore.tpl';
				$this->smarty->assign('hideSubMenu', true);
				$this->smarty->assign('forcedTitle', 'Usługi dodatkowe');
				break;
		}

		//		Utils::ArrayDisplay($param);
		try {
			$dalData = StructureDAL::GetDalDataObj();
			$dalData->setCondition(array('mf_structure.lang' => $param['lang'], 'mf_structure.publication' => '1', 'id_parent' => $param['idStructure']));
			$dalData->setSortBy('sort');
			$dalData->setLimit($limit);
			$dalData->setJoin(array('SimpleArticle_MfArticleDescription' => ' LEFT JOIN mf_article_description ON mf_article_description.id_mf_article=mf_structure.id_content'));
			$arrayObjSubsite = StructureDAL::GetResult($dalData);
			//Utils::ArrayDisplay($arrayObjSubsite);
			//			if ($param['idModule'] == 14 && count($arrayObjSubsite) > 0) {
			//
			//				$objSubsite = end($arrayObjSubsite);
			//				//Utils::ArrayDisplay($objSubsite);
			//				$dalData = StructureDAL::GetDalDataObj();
			//				$dalData->setCondition(array('mf_structure.lang' => $param['lang'], 'mf_structure.publication' => '1',  'id_parent' => $objSubsite->GetId()));
			//				$dalData->setSortBy('sort');
			//				//$dalData->setLimit(4);
			//				$arrayObjSubsiteMore = StructureDAL::GetResult($dalData);
			//				if (!is_array($arrayObjSubsiteMore)) {
			//					$arrayObjSubsiteMore = array();
			//				}
			//				array_pop($arrayObjSubsite);
			//				//Utils::ArrayDisplay($arrayObjSubsite);
			//				$arrayObjSubsite = array_merge($arrayObjSubsite, $arrayObjSubsiteMore);
			//			}
			$this->smarty->assign('arrayObjSubsite', $arrayObjSubsite);

			try {
				$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
				$this->AddTitle($objArticle->GetTitle());

				//Utils::ArrayDisplay($objArticle);
				$arrayImage = $objArticle->getArrayImage();
				//Utils::ArrayDisplay($arrayImage);

				$this->smarty->assign('arrayImage', $arrayImage);
				$this->smarty->assign('objArticle', $objArticle);

				//$this->AddBreadCrumb($objArticle->GetTitle(), '#');
			} catch (Exception $e) {
				//Utils::ArrayDisplay($e);
				$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			}

			//Utils::ArrayDisplay($arrayObjSubsite);
		} catch (Exception $e) {
			Utils::ArrayDisplay($e);
		}
	}

	/**
	 * Lista artykułów
	 *
	 * @param array $param
	 */
	public function ListAction($param) {


		$articleList = SimpleArticle_MfArticleDAL::GetList(10);

		//Utils::ArrayDisplay($articleList);
	}

	public function DownloadImageAction($param) {

		//$this->SetNoRender();

		$idImage = $param['idImage'];
		$idArticle = $param['idArticle'];

		$objImage = ImageDAL::GetResult(array('id_mf_image' => $idImage));
		if (count($objImage) > 0) {
			//Utils::ArrayDisplay($objImage[0]);
			//$pathImage = PATH_STATIC_CONTENT.'upload/Article/'.$idArticle.''.$objImage->GetPath();
			$pathImage = $objImage[0]->GetFullPathMaxId($idArticle);

			//Utils::ArrayDisplay($pathImage);

			header('Content-type: image/jpg');
			header('Content-Disposition: attachment; filename="' . $objImage[0]->GetPath() . '"');
			readfile($pathImage);
		}
	}

	public function RealizationAction($param) {
			$dalDataElements = SimpleArticle_MfArticleDAL::GetDalDataObj();
			$dalDataElements->setCondition(array('mf_article_description.lang' => $param['lang'], 'mf_article.publication' => '1', 'id_structure' => $param['idStructure']));
			$dalDataElements->setSortBy('mf_article.date_publication');
			$dalDataElements->setLimit(4);
			$dalDataElements->setJoin(array('SimpleArticle_MfArticleDescription' => ' LEFT JOIN mf_article_description ON mf_article_description.id_mf_article=mf_article.id_mf_article'));
			$arrayObjElements = SimpleArticle_MfArticleDAL::GetResult($dalDataElements, false);
			$this->smarty->assign('arrayObjElements', $arrayObjElements);
	}

	public function ProjectListAction($param) {
		//Utils::ArrayDisplay($param);
		if (isset($param['id'])) {
			//			if (!Utils::CheckPublication($param['id'], 'mf_article', 'id_mf_article')) {
			//
			//				$this->AddRedirect(URL_MAIN, 0);
			//			}
			try {
				$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
				//$this->AddTitle($objArticle->GetTitle());
				//Utils::ArrayDisplay($objArticle);
				$arrayImage = $objArticle->getArrayImage();
				//Utils::ArrayDisplay($arrayImage);

				$this->smarty->assign('arrayImage', $arrayImage);
				$this->smarty->assign('objArticle', $objArticle);

				//$this->AddBreadCrumb($objArticle->GetTitle(), '#');
			} catch (Exception $e) {
				//Utils::ArrayDisplay($e);
				$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			}
		} else {
			$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			throw new UserException('Nie podano id artykułu.');
		}

		$dalData = StructureDAL::GetDalDataObj();
		$dalData->setCondition(array('mf_structure.lang' => $param['lang'], 'mf_structure.publication' => '1', 'id_parent' => $param['idStructure']));
		$dalData->setSortBy('sort');
		$dalData->setLimit(4);
		$dalData->setJoin(array('SimpleArticle_MfArticleDescription' => ' LEFT JOIN mf_article_description ON mf_article_description.id_mf_article=mf_structure.id_content'));
		$arrayObjSubsite = StructureDAL::GetResult($dalData);

		foreach ($arrayObjSubsite as $objSubsite) {
			$dalDataElements = SimpleArticle_MfArticleDAL::GetDalDataObj();
			$dalDataElements->setCondition(array('mf_article_description.lang' => $param['lang'], 'mf_article.publication' => '1', 'id_structure' => $objSubsite->GetId()));
			$dalDataElements->setSortBy('mf_article.date_publication');
			$dalDataElements->setLimit(4);
			$dalDataElements->setJoin(array('SimpleArticle_MfArticleDescription' => ' LEFT JOIN mf_article_description ON mf_article_description.id_mf_article=mf_article.id_mf_article'));
			$arrayObjElements[$objSubsite->GetId()] = SimpleArticle_MfArticleDAL::GetResult($dalDataElements, false);
			
		}
		//Utils::ArrayDisplay($arrayObjElements);

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

	/**
	 *
	 * @param <type> $param
	 */
	public function ViewAction($param) {
//Utils::ArrayDisplay($param);
		$this->smarty->assign('showGallery', true);

		if (isset($param['idCategory'])) {
			$this->smarty->assign('idCategory', $param['idCategory']);


			switch ($param['idCategory']) {

				case '1':
					$this->partialTemplate = 'View.tpl';
					$this->smarty->assign('titleGif', 'portfolio.gif');
					break;
				case '2':
					$similarBox = true;
					$this->smarty->assign('showGallery', true);
					$this->smarty->assign('titleGif', 'aktualnosci.gif');
					$this->partialTemplate = 'News.tpl';
					$this->addScript('jQuery/jquery.jcarousel.min.js');
					$this->addScript('jQuery/jquery.lightbox-0.5.js');

					$this->addScript('gallery.js');
					$this->AddCSS('jquery.lightbox-0.5.css');
					$this->AddCSS('skin.css');
					break;
				case '11':
					$similarBox = true;
					$this->smarty->assign('titleGif', 'aktualnosci.gif');
					$this->partialTemplate = 'Program.tpl';
					break;
				case '19':
					$this->partialTemplate = 'Registration.tpl';
					break;
				case '3':
					$similarBox = true;
					$this->smarty->assign('titleGif', 'aktualnosci.gif');
					$this->partialTemplate = 'Program.tpl';
					break;
				case '9':
					$this->smarty->assign('titleGif', 'portfolio.gif');
					$this->smarty->assign('showGallery', true);
					$this->partialTemplate = 'Project.tpl';
					$this->addScript('jQuery/jquery.jcarousel.min.js');
					$this->addScript('jQuery/jquery.lightbox-0.5.js');

					$this->addScript('gallery.js');
					$this->AddCSS('jquery.lightbox-0.5.css');
					$this->AddCSS('skin.css');

					//$this->RunShared('CustomerBox', $param);

					//Utils::ArrayDisplay($param);
					$dataPAg = array('mf_article.id_structure' => $param['idStructure']);
					$dataPAg['mf_article_description.lang'] = $param['lang'];
					$dataPAg['mf_article.publication'] = 1;

					$date = Utils::GetNowDate();
					$dataPAg[' '] = array('value' => " mf_article.date_publication <= '$date' ", 'condition' => '');

					$arrayIds = SimpleArticle_MfArticleDAL::GetArrayIds($dataPAg, 'mf_article.date_publication DESC');
					$selected = array_search($param['id'], $arrayIds);
					$last = count($arrayIds) - 1;

					$this->smarty->assign('arrayIds', $arrayIds);
					$this->smarty->assign('selected', $selected);
					$this->smarty->assign('last', $last);


					break;
				default:
					$this->partialTemplate = 'View.tpl';
			}
		}




		if (isset($param['id'])) {
			//			if (!Utils::CheckPublication($param['id'], 'mf_article', 'id_mf_article')) {
			//
			//				$this->AddRedirect(URL_MAIN, 0);
			//			}
			try {
				$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
				//$this->AddTitle($objArticle->GetTitle());
				//Utils::ArrayDisplay($objArticle);
				$arrayImage = $objArticle->getArrayImage();
				//Utils::ArrayDisplay($arrayImage);

				$this->smarty->assign('arrayImage', $arrayImage);
				$this->smarty->assign('objArticle', $objArticle);

				//$this->AddBreadCrumb($objArticle->GetTitle(), '#');
			} catch (Exception $e) {
				//Utils::ArrayDisplay($e);
				$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			}
		} else {
			$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			throw new UserException('Nie podano id artykułu.');
		}

		//Archiwum
		//Utils::ArrayDisplay($param);
		$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($categoryData);

		$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' => '');

		$page = 1;

		if (isset($param['p']) && $param['p'] > 0) {
			$page = $param['p'];
		}
		SessionProxy::SetValue('__news_page_no__', $page);

		$maxArtOnPage = 10;

		$offset = ($page - 1) * $maxArtOnPage;

		//Utils::ArrayDisplay($data);
		$arrayObj = SimpleArticle_MfArticleDAL::GetList($data, sprintf(' %d OFFSET %d', $maxArtOnPage, $offset), 'mf_article.date_publication DESC');
		//$arrayObj = SimpleArticle_MfArticleDAL::GetResult($data, array(), sprintf(' %d OFFSET %d', $maxArtOnPage, $offset), 'mf_article.id_mf_article DESC');
		$arrayObjCount = SimpleArticle_MfArticleDAL::GetResultOld($data, array(), null, null, true);

		//$this->smarty->assign('tableModuleName', $tableModuleName);
		//$this->smarty->assign('lang', $lang);

//		if (isset($similarBox)) {
//			//Utils::ArrayDisplay($objArticle->getCustomerArrayId());
//			$param['arrayTag'] = $objArticle->getTagsArrayId();
//			$this->RunShared('SimilarBox', $param);
//		}
//		//Utils::ArrayDisplay($param['arrayTag']);
//		if (isset($similarBox)) {
//			//Utils::ArrayDisplay($objArticle->getCustomerArrayId());
//			$param['arrayTag'] = $objArticle->getCustomerArrayId();
//			$this->RunShared('CustomerProjectBox', $param);
//		}
		//Utils::ArrayDisplay($param['arrayTag']);
		$this->smarty->assign('page', $page);
		$this->smarty->assign('maxPage', ceil($arrayObjCount / $maxArtOnPage));
		$this->smarty->assign('arrayObj', $arrayObj);

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

	public function FormAction($param) {
		//Utils::ArrayDisplay($_SESSION);
		$this->addScript('jQuery/jquery.validate.js');
		if ($param['lang'] == 'pl') {
			$this->addScript('jQuery/messages_pl.js');
		}		
		$this->addScript('jQuery/validate.sendContact.js');
		$this->addScript('jQuery/extras.sendContact.js');

//		Utils::ArrayDisplay($param);
//		Utils::ArrayDisplay(__METHOD__);
		//		$this->AddScript("scriptaculous.js?load=effects");
		//		$this->AddScript("lightbox.js");
		//$this->AddScript("prototype.js");
		//$this->AddScript("Dosia.js");


		if (isset($param['id'])) {
			//			if (!Utils::CheckPublication($param['id'], 'mf_article', 'id_mf_article')) {
			//
			//				$this->AddRedirect(URL_MAIN, 0);
			//			}
			try {
				$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
				//$this->AddTitle($objArticle->GetTitle());
				$this->smarty->assign('objArticle', $objArticle);

				//$this->AddBreadCrumb($objArticle->GetTitle(), '#');
			} catch (Exception $e) {
				$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			}
		} else {
			$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			throw new UserException('Nie podano id artykułu.');
		}
		//Utils::ArrayDisplay($_POST);

		if (isset($_POST['send'])) {
			//$this->SetAjaxRender();
			$this->smarty->assign('error', '');
			//			$this->smarty->assign('wrongPhone', '');
			$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_name'));
			$validator->IsEmpty('email', Dictionary::Translate('required_email'));
			$validator->IsEmailAddress('email', Dictionary::Translate('invalid_email'));
			$validator->IsEmpty('message', Dictionary::Translate('required_message'));
			$validator->IsEmpty('g-recaptcha-response', Dictionary::Translate('required_field'));

			$out = $validator->GetErrorList();

			if (!empty($out)) {
				$errorList = true;
			}



			//Utils::ArrayDisplay($validator->GetErrorList());
			//Utils::ArrayDisplay($errorList);
			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('post', $post);
				//$this->smarty->assign('temat', $post['temat']);
				//$this->smarty->assign('name', $post['name']);

				$txtmessage = $this->smarty->fetch('partial/SimpleArticle/Index/MailTxt.tpl');

				$mail = new PHPMailer();
				$mail->PluginDir = 'core/lib/phpmailer/';
				$mail->CharSet = "utf-8";
				$mail->Subject = "Formularz";
				$mail->SMTPAuth = true;
				$mail->Mailer = 'mail';
				$mail->Host = Registry::Get('mail_host');
				$mail->Port = 587;
				$mail->IsHTML(true);
				$mail->From = Registry::Get('mail_from');
				$mail->FromName = "Ogiela";
//				$mail->Username = Registry::Get('user_smtp');
//				$mail->Password = Registry::Get('password_smtp');
				$mail->AddAddress(Registry::Get('address_to'), "Ogiela");
				$mail->AddBCC("maciej.kloch@gmail.com", "aem");

				$mail->Body = $txtmessage;

				$mail->Send();

				//Utils::ArrayDisplay($mail);

			$this->addRedirectInfo(Dictionary::Translate('message_sent'), 'ok', Router::GenerateUrl('current', array()), 0);
			}
		}


		$this->smarty->assign('titleGif', 'kontakt.gif');
	}
	
	public function FormSentActon($param) {
		
	}

	public function RegistrationAction($param) {
		//Utils::ArrayDisplay($param);
		$this->addScript('jQuery/jquery.validate.js');
		$this->addScript('Validate/validate.sendRegistration.js');
		$this->addScript('Validate/extras.sendRegistration.js');

		//		$this->AddScript("scriptaculous.js?load=effects");
		//		$this->AddScript("lightbox.js");
		//$this->AddScript("prototype.js");
		//$this->AddScript("Dosia.js");


		if (isset($param['id'])) {
			//			if (!Utils::CheckPublication($param['id'], 'mf_article', 'id_mf_article')) {
			//
			//				$this->AddRedirect(URL_MAIN, 0);
			//			}
			try {
				$objArticle = SimpleArticle_MfArticleDAL::GetById($param['id'], $param['lang']);
				//$this->AddTitle($objArticle->GetTitle());
				$this->smarty->assign('objArticle', $objArticle);

				//$this->AddBreadCrumb($objArticle->GetTitle(), '#');
			} catch (Exception $e) {
				$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			}
		} else {
			$this->AddRedirect(Router::GenerateUrl('Index', array('lang' => $param['lang'])), 0);
			throw new UserException('Nie podano id artykułu.');
		}
		//Utils::ArrayDisplay($_POST);

		if (isset($_POST['send'])) {
			//$this->SetAjaxRender();
			$this->smarty->assign('error', '');
			//			$this->smarty->assign('wrongPhone', '');
			$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_name'));
			$validator->IsEmpty('email', Dictionary::Translate('required_email'));
			$validator->IsEmailAddress('email', Dictionary::Translate('invalid_email'));
			$validator->IsEmpty('message', Dictionary::Translate('required_message'));

			$out = $validator->GetErrorList();

			if (!empty($out)) {
				$errorList = true;
			}



			//Utils::ArrayDisplay($validator->GetErrorList());
			//Utils::ArrayDisplay($errorList);
			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('temat', $post['temat']);
				//$this->smarty->assign('name', $post['name']);

				$txtmessage = $this->smarty->fetch('partial/SimpleArticle/Index/MailTxtRegistration.tpl');

				$mail = new PHPMailer();
				$mail->PluginDir = 'core/lib/phpmailer/';
				$mail->CharSet = "utf-8";
				$mail->Subject = "Rejestracja elektroniczna.";
				$mail->SMTPAuth = true;
				$mail->Mailer = 'smtp';
				$mail->Host = Registry::Get('mail_host');
				$mail->Port = 587;
				$mail->IsHTML(true);
				$mail->From = Registry::Get('mail_from');
				$mail->FromName = Registry::Get('from_name');
				$mail->Username = Registry::Get('user_smtp');
				$mail->Password = Registry::Get('password_smtp');
				$mail->AddAddress(Registry::Get('mail_to'), Registry::Get('mail_to_name'));
				$mail->AddBCC("maciek@kloch.pl", "aem");

				$mail->Body = $txtmessage;

				$mail->Send();

				//Utils::ArrayDisplay($mail);

				$this->addRedirectInfo(Dictionary::Translate('message_sent'), null, $post['url'], 0);
			}
		}


		$this->smarty->assign('titleGif', 'kontakt.gif');
	}

	public function TestAction($param) {
		Utils::ArrayDisplay('test');
		//$this->smarty->assign('indexSG', false);
		//$this->SetAjaxRender();
	}

	/**
	 * Wysyłka
	 *
	 * @param array $param
	 */
	public function AjaxSendMessageAction($param) {
		
	}

	/**
	 * Czesc wspolna wszystkich podstron
	 *
	 */
	public function preDispatch($param) {


		//Utils::ArrayDisplay($param);
		//$this->AddTitle(self::TITLE);

		$this->smarty->assign('urlMain', Config::Get('URL_MAIN') . '/pl');

		//

		$this->Run($param);



		$this->RunShared('MenuBox', $param);
	}

	public function postDispatch($param) {
		
	}

}

?>