<?php
namespace Modules\Orders\Details\GeneralDetails;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for Order details insert/update.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		$entityCfg=\Entity\Order::loadCFG();
		$changeRespAccessLevel = \App\UserAccess\CurrentUserAccessFast::getInstance()->getAccessOptionValue('reservationChangeResponsibleUser');

		$form = \Engine\Form\General::create();
		$form->addContainer(\Engine\Form\Container\Fieldset::create($this->lang['fieldsets']['sectionTitle']));

		$reservationCode = new \Engine\Form\Input\Text($this->lang['formFields']['reservationCode'], 'reservationCode', $this->values['reservationCode']);
		$reservationCode->importFromConfig($entityCfg['reservationCode']);
		$form->addElement($reservationCode);


		// Reservation Type
		$reservationType = new \App\Form\Input\Select_OrderType($this->lang['formFields']['reservationType'], 'resType', $this->values['resType']);
		$reservationType->setMandatory(\App\Config\OrderTypes::getInstance()->getMandatory());
		$reservationType->showDefaultOption();
		$reservationType->setDefaultOptionText($this->lang['chooseResServType']);
		$form->addElement($reservationType);


		// Services Type
		$servicesType = new \App\Form\Input\Select_OrderServicesType($this->lang['formFields']['servicesType'], 'servicesType', $this->values['servicesType']);
		$servicesType->setMandatory(\App\Config\OrderServicesTypes::getInstance()->getMandatory());
		$servicesType->showDefaultOption();
		$servicesType->setDefaultOptionText($this->lang['chooseResServType']);
		$form->addElement($servicesType);


		// Reservation Flag
		$flag = new \App\Form\Input\OrderFlag($this->lang['formFields']['flag'], 'flag', $this->values['flag']);
		$flag->setMandatory(\App\Config\OrderFlags::getInstance()->getMandatory());
		if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->getAccessOptionValue('Modules/Orders/Details/OrderFlag')) {
			$flag->setDisabled();
		}
		$flag->showDefaultOption();
		$flag->setDefaultOptionText($this->lang['otherInfo']['noFlags']);
		$form->addElement($flag);

		// MICE project
		$miceProject = new \App\Form\Input\Autocomplete_MiceProject($this->lang['formFields']['miceProject'], 'idMiceProject', $this->values['idMiceProject']);
		$form->addElement($miceProject);

		// Description
		$description = new \Engine\Form\Input\Textarea($this->lang['formFields']['description'], 'description', $this->values['description']);
		$description->importFromConfig($entityCfg['description']);
		$form->addElement($description);

		// Comments
		$comments = new \Engine\Form\Input\Textarea($this->lang['formFields']['comments'], 'comments', $this->values['comments']);
		$comments->importFromConfig($entityCfg['comments']);
		$form->addElement($comments);

		// Contact Person
		$contactPerson = new \App\Form\Input\Autocomplete_ContactPersonCorporate($this->lang['formFields']['contactPerson'], 'idContactPerson', $this->values['idContactPerson']);
		$form->addElement($contactPerson);

		// Responsible user
		$idUser = new \App\Form\Input\Autocomplete_User($this->lang['formFields']['respUser'], 'idUser', $this->values['idUser']);
		$idUser->importFromConfig($entityCfg['idUser']);
		if (!$changeRespAccessLevel) {
			$idUser->setDisabled(true);
		}
		$form->addElement($idUser);

		// Responsible office
		$idOffice = new \App\Form\Input\Autocomplete_Office($this->lang['formFields']['respOffice'], 'idOffice', $this->values['idOffice']);
		$idOffice->importFromConfig($entityCfg['idOffice']);
		if (!$changeRespAccessLevel) {
			$idOffice->setDisabled(true);
		}
		$form->addElement($idOffice);

		// Responsible department
		$idDepartment = new \App\Form\Input\Autocomplete_Department($this->lang['formFields']['respDept'], 'idDepartment', $this->values['idDepartment']);
		$idDepartment->importFromConfig($entityCfg['idDepartment']);
		$form->addElement($idDepartment);

		$form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1));

		return $form;
	}

}
