diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php new file mode 100644 index 0000000..418844b --- /dev/null +++ b/app/controllers/UserController.php @@ -0,0 +1,21 @@ +id)) ? $user->create() : $user->updatePassword(); + } + catch(pdoexception $e) { + $_SESSION['msg'] = 'Erro!'; + echo $_SESSION['msg']; + //die(); + } + } + } + + $postAction = ('create','update','updatePassword','delete'); + + if(isset($_POST['action']) && in_array($_POST['action'], $postAction)) { + UserController::$_POST['action'](); + } \ No newline at end of file diff --git a/app/models/user.php b/app/models/user.php new file mode 100644 index 0000000..f588d1f --- /dev/null +++ b/app/models/user.php @@ -0,0 +1,52 @@ +id = array_key_exists('id', $attributes) ? $attributes['id'] : ""; + $this->name = array_key_exists('name', $attributes) ? $attributes['name'] : ""; + $this->marital_status = array_key_exists('marital_status', $attributes) ? $attributes['marital_status'] : ""; + $this->course = array_key_exists('course', $attributes) ? $attributes['course'] : ""; + $this->registration = array_key_exists('registration', $attributes) ? $attributes['registration'] : ""; + $this->rg = array_key_exists('rg', $attributes) ? $attributes['rg'] : ""; + $this->organ = array_key_exists('organ', $attributes) ? $attributes['organ'] : ""; + $this->cpf = array_key_exists('cpf', $attributes) ? $attributes['cpf'] : ""; + $this->email = array_key_exists('email', $attributes) ? $attributes['email'] : ""; + $this->address_id = array_key_exists('address_id', $attributes) ? $attributes['address_id'] : ""; + $this->position_id = array_key_exists('position_id', $attributes) ? $attributes['position_id'] : ""; + $this->company_id = array_key_exists('company_id', $attributes) ? $attributes['company_id'] : ""; + $this->start_date = array_key_exists('start_date', $attributes) ? $attributes['start_date'] : ""; + $this->end_date = array_key_exists('end_date', $attributes) ? $attributes['end_date'] : ""; + $this->level = array_key_exists('level', $attributes) ? $attributes['level'] : ""; + $this->password = array_key_exists('password', $attributes) ? $attributes['password'] : ""; + } + } + + public function create() { + $connect = self::start(); + $stm = $connect->prepare('INSERT INTO `user`(`name`, `email`, `password`, `level`)VALUES(:name, :email, :password, :level)'); + $stm->bindValue(':name', $this->name, PDO::PARAM_STR); + $stm->bindValue(':email', $this->email, PDO::PARAM_STR); + $stm->bindValue(':password', $this->password, PDO::PARAM_STR); + $stm->bindValue(':level', $this->level, PDO::PARAM_INT); + return $stm->execute(); + } + } diff --git a/app/views/add-user.php b/app/views/add-user.php index 95e55fb..fcd1008 100644 --- a/app/views/add-user.php +++ b/app/views/add-user.php @@ -9,6 +9,7 @@