<?php

namespace Engine\Form;

/**
 * An form that submits displays the whole form in an iframe container
 * @author Lucian
 */
class Iframe extends \Engine\Form\General
{
	public $class = 'iframeContent';

	protected $serverMessages = [];

	// implement a "defaultContainer" algorithm
	protected $defaultContainer = null;

	public function sendMessage($messageArr)
	{
		$this->serverMessages[] = $messageArr;
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Container\GeneralAbstract::getTemplateParams()
	 */
	public function getTemplateParams($templateClass = null, $parentElement = null)
	{
		$params = parent::getTemplateParams($templateClass, $parentElement);

		global $R;
		/**
		 * determine which layout should be used by looking at $R['__formField_renderDestination'].
		 * This is automatically appended from JS when displaying an iframe.
		 * It will be missing in popups URLs, so the user wont notice a different URL than the one in the iframe
		 */
		$params['baseLayout'] = ($R['__formField_renderDestination']=='iframe' ? "iframe" : "popup");
		$params['baseSmartyLayout'] = ($params['baseLayout']=='iframe' ? SMARTY_LAYOUT_OLD_MAIN_IFRAME : SMARTY_LAYOUT_OLD_MAIN_POPUP);


		$params['serverMessages'] = $this->serverMessages;

		return $params;
	}

}
