public function delete()
 {
     if (!$this->loggedIn()) {
         header('Location: index.php?c=login&m=login');
     }
     if (!isset($_GET['id'])) {
         header('Location: index.php?c=user&m=index');
     }
     $userCollection = new UserCollection();
     $user = $userCollection->getOne($_GET['id']);
     if (is_null($user)) {
         header('Location: index.php?c=user&m=index');
     }
     $userCollection->delete($user->getId());
     header('Location: index.php?c=user&m=index');
 }
Example #2
0
<?php

require_once 'common/header.php';
if (!loggedIn()) {
    header('Location: login.php');
}
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 = 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');
    }
}