public function __construct(\Smarty $smarty, \PDO $pdo)
 {
     $this->smarty = $smarty;
     $this->pdo = $pdo;
     // alway show login button
     $this->smarty->assign('show_login', true);
     if (isset($_SESSION['user'])) {
         $userRepository = new UserRepository($this->pdo);
         $this->smarty->assign('show_login', false);
         $this->smarty->assign('user', $userRepository->getUser($_SESSION['user']));
     } elseif ($_SERVER['REQUEST_METHOD'] != 'POST' && $_GET['section'] != 'user' && $_GET['action'] != 'login' && !isset($_SESSION['user'])) {
         // you shall not pass! LOGIN!
         header('location: index.php?section=user&action=login');
     }
 }
 public function add()
 {
     $this->smarty->assign('header', 'Gebruiker aanmaken!');
     $this->smarty->assign('message', '');
     $this->smarty->assign('username', '');
     $this->smarty->assign('company_id', '');
     $customerRepository = new CustomerRepository($this->pdo);
     $customers = $customerRepository->getCustomers();
     $this->smarty->assign('customers', $customers);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $customer_id = $_POST['customer_id'];
         if (empty($customer_id)) {
             $this->smarty->assign('message', 'Je hebt geen Customer geselecteerd, dat moet');
             $this->smarty->display('user/add.tpl');
         }
         $customer = $customerRepository->getCustomer($customer_id);
         $userRepository = new UserRepository($this->pdo);
         $user = $userRepository->addUser($_POST['username'], $_POST['password'], $customer);
         header('location: index.php?section=customer&action=index');
     } else {
         $this->smarty->display('user/add.tpl');
     }
 }