<?php
 namespace Modules\Admin\UserProfile; class Controller extends \App\Mvc\Controller\Form\WindowAbstract { protected function actionIndex($R) { $msgs = \App\MessagesCollector::create(); global $S; $modelOutput = null; if ($R[$this->formSubmitButtonName]) { $modelOutput = $this->processFormData($R, $msgs); } if ($modelOutput) { $S['global']['lang'] = $R['language']; return new \Engine\Mvc\Response\HtmlRedirect(\Engine\Mvc\Dispatcher::getInstance()->getAppUrl($this->module, 'index')); } $view = new View_Index($this); if (!$R[$this->formSubmitButtonName]) { $formData=$this->getDefaultFormData($R); } else { $formData=$R; } $view->addInput('formData', $formData); $view->getMessagesCollector()->appendMessages($msgs); $view->addInput('formSubmitButtonName', $this->formSubmitButtonName); $this->preRenderOperations($view, $formData); return new \Engine\Mvc\Response\Html($view->render()); } protected function getDefaultFormData($R) { $user = \Entity\User::select(CURRENT_ID_USER); $formData['lastname'] = $user->lastName; $formData['firstname'] = $user->firstName; $formData['title'] = $user->titleCode; $formData['language'] = $user->language; $formData['series'] = $user->ID_series; $formData['number'] = $user->ID_number; $formData['issuedBy'] = $user->ID_releaseBy; $formData['issueDate'] = $user->ID_releaseDate; $formData['pnc'] = $user->PNC; $formData['address'] = $user->address; $formData['email'] = $user->email; $formData['emailSignature'] = $user->emailSignature; $formData['birthday'] = $user->birthday; $formData['tel'] = $user->telephone; return $formData; } protected function processFormData(Array $R, \App\MessagesCollector $msgs) { global $S; $return = null; try { \DB::startTransaction(); $user = \Entity\User::update(CURRENT_ID_USER); $user->language = $R['language']; if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('userCanUpdatePersonalData')) { $user->lastName = $R['lastname']; $user->firstName = $R['firstname']; $user->title = $R['title']; $user->ID_series = $R['series']; $user->ID_number = $R['number']; $user->ID_releaseBy = $R['issuedBy']; $user->ID_releaseDate = $R['issueDate'] ? $R['issueDate'] : null; $user->PNC = $R['pnc']; $user->birthday = $R['birthday'] ? $R['birthday'] : null; } if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('userCanUpdateContactData')) { $user->address = $R['address']; $user->email = $R['email']; $user->telephone = $R['tel']; } if (\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('userCanUpdateSignature')) { $user->emailSignature = $R['emailSignature']; } $user->save(); \DB::commitTransaction(); if ($S['global']['lang'] != $R['language']){ $return = true; } else { $return = false; } foreach ($user->getMessages()->getMessages() as $msg) { $msgs->addMessage($msg); } } catch (\App\Entity\Exception $e) { \DB::rollbackTransaction(); $msgs->appendMessages($e->getMessagesCollector()); } return $return; } }