Esempio n. 1
0
 public static function post()
 {
     if (isset($_POST['edit'])) {
         $page = new Page();
         $page->data['title'] = 'Profiel';
         ProfileController::buildProfileTopView($page, true, false);
         $page->addView('profile/ProfileEnabledFormBottomView');
         ProfileController::buildMembershipDetailsView($page);
         $page->showWithMenu();
     } elseif (isset($_POST['save'])) {
         $page = new Page();
         $page->data['title'] = 'Profiel';
         $errMsgs = ProfileTopViewValidator::validate($_POST);
         if (empty($errMsgs)) {
             //If no error: create a new user from posted data and try to save it
             $newUser = ProfileController::createUserFromPost();
             try {
                 UserDB::updateUser($_SESSION['Stippers']['Profile']['user'], $newUser);
                 $page->data['SuccessMessageNoDescriptionWithLinkView']['successTitle'] = 'Gegevens succesvol bijgewerkt';
                 $page->data['SuccessMessageNoDescriptionWithLinkView']['redirectUrl'] = $_SERVER['REQUEST_URI'];
                 $page->addView('success/SuccessMessageNoDescriptionWithLinkView');
             } catch (UserDBException $ex) {
                 //Show correct error message for errors
                 if ($ex->getCode() == UserDBException::USEROUTOFDATE) {
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Gegevens niet bijgewerkt';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Iemand anders heeft je gegevens in tussentijd al gewijzigd.';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                     $page->addView('error/ErrorMessageWithDescriptionWithLinkView');
                 } else {
                     ProfileController::buildProfileTopView($page, true, true);
                     if ($ex->getCode() == UserDBException::EMAILALREADYEXISTS) {
                         $page->data['ProfileTopView']['errMsgs']['global'] = '<h2 class="error_message" id="profile_form_error_message">Dit e-mailadres is al in gebruik.</h2>';
                     } else {
                         $page->data['ProfileTopView']['errMsgs']['global'] = '<h2 class="error_message" id="profile_form_error_message">Kan gegevens niet bijwerken, probeer het opnieuw.</h2>';
                     }
                     $page->addView('profile/ProfileEnabledFormBottomView');
                 }
             }
         } else {
             //If we had an error we show the views with enabled controls and take data from POST
             ProfileController::buildProfileTopView($page, true, true);
             $page->addView('profile/ProfileEnabledFormBottomView');
             $page->data['ProfileTopView']['errMsgs'] = array_merge($page->data['ProfileTopView']['errMsgs'], $errMsgs);
             ProfileController::buildMembershipDetailsView($page);
         }
         $page->showWithMenu();
     } else {
         ProfileController::get();
     }
 }