public function add()
{
if (isset($_POST['save_user_btn'])) {
$row = [];
if ($_GET['id']) {
$row['id'] = $_GET['id'];
} else {
$row['create_date'] = date('Y-m-d H:i:s');
}
$row['email'] = $_POST['email'];
$row['user_name'] = $_POST['user_name'];
$row['user_surname'] = $_POST['user_surname'];
$row['user_group_id'] = $_POST['user_group_id'];
if ($_POST['user_password']) {
$row['user_password'] = md5($_POST['user_password']);
}
$this->model('backend_users')->insert($row);
if ($_POST['user_password']) {
$this->logOut();
$this->auth(registry::get('user')['email'], md5($_POST['user_password']));
registry::remove('user');
$this->checkAuth();
}
header('Location: ' . SITE_DIR . 'users/');
exit;
}
$this->render('user_groups', $this->model('user_groups')->getAll());
if ($_GET['id']) {
$this->render('user', $this->model('backend_users')->getById($_GET['id']));
}
$this->view('users' . DS . 'add');
}