public function update() { if (isset($_REQUEST['person_id'])) { // Load the user for editing try { $user = new Person($_REQUEST['person_id']); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; header('Location: ' . BASE_URL . '/users'); exit; } } else { $user = new Person(); } // Handle POST data if (isset($_POST['username'])) { try { $user->handleUpdateUserAccount($_POST); $user->save(); header('Location: ' . BASE_URL . '/users'); exit; } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } // Display the form if ($user->getId()) { $this->template->blocks[] = new Block('people/personInfo.inc', array('person' => $user, 'disableButtons' => true)); } $this->template->blocks[] = new Block('users/updateUserForm.inc', array('person' => $user)); }
public function update(array $params) { if (!empty($_REQUEST['id'])) { try { $person = new Person($_REQUEST['id']); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } else { $person = new Person(); } if (isset($person)) { if (isset($_POST['username'])) { try { $person->handleUpdateUserAccount($_POST); // We might have populated this person's information from LDAP // We need to do a new lookup in the system, to see if a person // with their email address already exists. // If they already exist, we should add the account info to that // person record. if (!$person->getId() && $person->getEmail()) { try { $existingPerson = new Person($person->getEmail()); $existingPerson->handleUpdateUserAccount($_POST); } catch (\Exception $e) { } } if (isset($existingPerson)) { $existingPerson->save(); } else { $person->save(); } header('Location: ' . BASE_URL . '/users'); exit; } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } return new \Application\Views\Users\UpdateView(['user' => $person]); } else { return new \Applications\Views\NotFoundView(); } }