public function update() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } if (!isset($_GET['id'])) { header('Location: users.php'); } $userCollection = new UserCollection(); $user = $userCollection->getOne($_GET['id']); if (is_null($user)) { header('Location: users.php'); } $insertInfo = array('username' => $user->getUsername(), 'password' => '', 'email' => $user->getEmail(), 'description' => $user->getDescription()); $errors = array(); if (isset($_POST['editUser'])) { $insertInfo = array('username' => isset($_POST['username']) ? $_POST['username'] : '', 'password' => isset($_POST['password']) ? $_POST['password'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '', 'description' => isset($_POST['description']) ? $_POST['description'] : ''); $errors = $this->validateUserInput($insertInfo); if (empty($errors)) { $entity = new UsersEntity(); $entity->setId($_GET['id']); $entity->setUsername($insertInfo['username']); $entity->setPassword($insertInfo['password']); $entity->setEmail($insertInfo['email']); $entity->setDescription($insertInfo['description']); $userCollection->save($entity); $_SESSION['flashMessage'] = 'You have 1 affected row'; header('Location: index.php?c=user&m=index'); } } $data['insertInfo'] = $insertInfo; $data['errors'] = $errors; $this->loadView('users/update', $data); }
} $userCollection = new UserCollection(); $user = $userCollection->getOne($_GET['id']); if (is_null($user)) { header('Location: users.php'); } $insertInfo = array('username' => $user->getUsername(), 'password' => '', 'email' => $user->getEmail(), 'description' => $user->getDescription()); $errors = array(); if (isset($_POST['editUser'])) { $insertInfo = array('username' => isset($_POST['username']) ? $_POST['username'] : '', 'password' => isset($_POST['password']) ? $_POST['password'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '', 'description' => isset($_POST['description']) ? $_POST['description'] : ''); $errors = validateUserInput($insertInfo); if (empty($errors)) { $entity = new UsersEntity(); $entity->setId($_GET['id']); $entity->setUsername($insertInfo['username']); $entity->setPassword($insertInfo['password']); $entity->setEmail($insertInfo['email']); $entity->setDescription($insertInfo['description']); $userCollection->save($entity); $_SESSION['flashMessage'] = 'You have 1 affected row'; header('Location: users.php'); } } ?> <?php require_once 'common/sidebar.php'; ?> <!-- start: Content -->