<?php
namespace Modules\Bsp\Listing; class View_FormAdmin extends \App\Mvc\View_Popup_GeneralAbstract { protected $renderingTemplate=SMARTY_LAYOUT_MAIN_POPUP_FORM; public function render() { $form = null; if (!$this->closePopup) { $form = $this->getForm(); } if ($form) { $form->getMessagesObj()->addFromMessageCollector($this->messagesCollector); $this->setOutputVar('form', $form); } else { \MessageStack::GetObject()->addFromMessageCollector($this->messagesCollector); } $this->setOutputVar('closePopup', $this->closePopup); return $this->render_smarty($this->renderingTemplate); } public function getForm() { if ($this->input['currentStep']=='uploadFiles') { return $this->getForm_uploadFiles(); } elseif($this->input['currentStep']=='submitData') { return $this->getForm_fillData(); } } public function getForm_uploadFiles() { $form = \Engine\Form\General::create(); $fieldset = \Engine\Form\Container\Fieldset::create($this->lang['insert']['uploadFiles']); $form->addContainer($fieldset); $file = new \Engine\Form\Input\File($this->lang['insert']['file'], 'file'); $file->setMandatory(true); $form->addElement($file); $bspTraverserFactory = \App\Bsp\Parser\BspTraverserFactory::getInstance(); foreach (array_filter($bspTraverserFactory->getFileFormats()->getAll(), function($fmt){ return !$fmt->hidden && $fmt->handlesSingleFile; }) as $fmt) { $possibleFileTypes[$fmt->code] = $fmt->label; } $fileType = new \Engine\Form\Input\Select($this->lang['insert']['fileType'], 'fileType', $this->input['formData']['fileType'], $possibleFileTypes); $fileType->setMandatory(true); $form->addElement($fileType); $form->addElement(new \Engine\Form\Input\Hidden('', 'step', 'uploadFiles')); $form->addElement(new \Engine\Form\Input\Hidden('', 'stepSubmitted', 1)); return $form; } public function getForm_fillData() { $form = \Engine\Form\General::create(); $fieldset = \Engine\Form\Container\Fieldset::create($this->lang['insert']['fillData']); $form->addContainer($fieldset); $file = new \Engine\Form\Input\Text($this->lang['insert']['file'], null, $this->input['fileName']); if ($this->input['fileData']) { $fdetails = []; if ($this->input['fileData']['agent']) { $fdetails[]= sprintf($this->lang['insert']['file_agent'], $this->input['fileData']['agent']); } if ($this->input['fileData']['rowsCount']) { $fdetails[]= sprintf($this->lang['insert']['file_rows'], number_format($this->input['fileData']['rowsCount']), number_format($this->input['fileData']['ticketsCount'])); } $fdetails[]= sprintf($this->lang['insert']['file_dates'], \Engine\DateTime::createFromIsoDate($this->input['fileData']['dates']['minTicketDate'])->formatDateStd(), \Engine\DateTime::createFromIsoDate($this->input['fileData']['dates']['maxTicketDate'])->formatDateStd() ); if ($this->input['fileData']['totals']) { $cdetails = []; foreach ($this->input['fileData']['totals'] as $currency=>$totals) { $cdetails[]= sprintf("%s %s", number_format($totals['balancePayable'], 2), $currency); } $fdetails[]= sprintf($this->lang['insert']['file_totals'], implode(", ", $cdetails)); } $file->setDetails(implode(", ", $fdetails)); } $form->addElement($file->setDisabled()); $filePeriod = new \Engine\Form\Input\DateInterval($this->lang['insert']['interval'], 'interval', [ 'start' => $this->input['formData']['interval']['start'], 'end' => $this->input['formData']['interval']['end'], ]); if ($this->input['fileData']['interval']['start'] && $this->input['fileData']['interval']['end']) { $filePeriod->setDetails(sprintf("%s - %s", \Engine\DateTime::createFromIsoDate($this->input['fileData']['interval']['start'])->formatDateStd(), \Engine\DateTime::createFromIsoDate($this->input['fileData']['interval']['end'])->formatDateStd() )); } $filePeriod->setMandatory(); $form->addElement($filePeriod); if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Bsp/Listing-completeAccess')) { $office = new \App\Form\Input\Autocomplete_OfficeAndIataCode($this->lang['insert']['office'], 'office', $this->input['formData']['office']); $office->setMandatory(); $form->addElement($office); } else { $office = new \App\Form\Input\Autocomplete_OfficeAndIataCode($this->lang['insert']['office'], null, ['id'=>sprintf("%s:%s", CURRENT_ID_OFFICE, \Entity\Office::select(CURRENT_ID_OFFICE)->iataCode[0])]); $office->setMandatory(); $office->setDisabled(); $form->addElement($office); $form->addElement(new \Engine\Form\Input\Hidden('', 'office[id]', sprintf("%s:%s", CURRENT_ID_OFFICE, \Entity\Office::select(CURRENT_ID_OFFICE)->iataCode[0]))); } $description = new \Engine\Form\Input\Textarea($this->lang['insert']['description'], 'description', $this->input['formData']['description']); $form->addElement($description); $form->addElement(new \Engine\Form\Input\Hidden('', 'step', 'submitData')); $form->addElement(new \Engine\Form\Input\Hidden('', 'stepSubmitted', 1)); return $form; } } 