Skip to content
This repository has been archived by the owner on Mar 1, 2018. It is now read-only.

Userform#5 #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
require_once('../models/user.php');
public static function create(){
if ($_POST['name'] != '' && $_POST['marital_status'] != '' && $_POST['course'] != '' && $_POST['registration'] != '' && $_POST['rg'] != '' && $_POST['organ'] != '' && $_POST['cpf'] != '' && $_POST['email'] != '' && $_POST['password'] != '' && $_POST['address_id'] != '' && $_POST['position_id'] != '' && $_POST['company_id'] != '' && $_POST['start_date'] != '' && $_POST['end_date'] != '' && $_POST['level'] != '' ) {
$user = new User($_REQUEST);
try {
(empty($user->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']();
}
52 changes: 52 additions & 0 deletions app/models/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

class User extends Connect {

public $id;
public $name;
public $marital_status;
public $course;
public $registration;
public $rg;
public $organ;
public $cpf;
public $email;
public $password;
public $address_id;
public $position_id;
public $company_id;
public $start_date;
public $end_date;
public $level;

function __construct($attributes = array()) {
if(!empty($attributes)) {
$this->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();
}
}
1 change: 1 addition & 0 deletions app/views/add-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div>
<h1> Criar Usuário </h1>
<?php include('includes/user-form.inc'); ?>
<button>Enviar</button>
</div>
</body>
</html>
18 changes: 18 additions & 0 deletions app/views/editUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Editar perfil</title>
<meta charset="UTF-8">
</head>
<body>
<div class="header">
<p>Editar perfil</p>
<a href="editUser.php">Perfil</a>
<p>sair</p>
<img class="hamburger" src=""></img>
</div>
<?php include('includes/user-form.inc'); ?>
<?php include('includes/footer.inc'); ?>
</body>

</html>
54 changes: 36 additions & 18 deletions app/views/includes/user-form.inc
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
<form>
<label>Nome Completo</label>
<label>Estado Civil</label>
<label>E-mail</label>
<label>Senha</label>
<label>Curso</label>
<label>Telefone</label>
<label>Empresa Atual</label>
<label>Cargo Atual</label>
<label>Período de Participação</label>
<label>Cargos Ocupados</label>
<label>Projetos em que Participou</label>
<label></label>
<label></label>
<label></label>
<label></label>
<label></label>
<label></label>
<label></label>
<label for="name">Nome Completo</label>
<input name="name" type="text"></input>
</br>
<label for="email">E-mail</label>
<input name="email" type="text"></input>
</br>
<label for="rg">RG</label>
<input name="rg" type="text"></input>
</br>
<label for="organ">Órgão Expelidor</label>
<input name="organ" type="text"></input>
</br>
<label for="cpf">CPF</label>
<input name="cpf" type="text"></input>
</br>
<label for="complete_address">Endereço Completo</label>
<input name="complete_address" type="text"></input>
</br>
<label for="registration">Número de Matrícula</label>
<input name="registration" type="text"></input>
</br>
<label for="marital_status">Estado Civil</label>
<input name="marital_status" type="text"></input>
</br>
<label for="course">Curso</label>
<input name="course" type="text"></input>
</br>
<label for="start_date">Início do Período de Participação</label>
<input name="start_date" type="date"></input>
</br>
<label for="end_date">Fim do Período de Participação</label>
<input name="end_date" type="text"></input>
</br>
<label for="position">Cargo Atual</label>
<input name="position" type="text"></input>
</br>
</form>
38 changes: 20 additions & 18 deletions app/views/index.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>

<body>
<div class="header">
<p>Home</p>
<img class="hamburger" src=""></img>
</div>
<?php include('includes/navbar.inc'); ?>
<div id="today">Hoje</div>
<div id="byTime">
<?php for($i = 2016; $i>=1998; $i--): ?>
<div><?php echo $i;?></div>
<?php endfor; ?>
</div>
<?php include('includes/footer.inc'); ?>
</body>
<head>
<title>Home</title>
<meta charset="UTF-8">
</head>
<body>
<div class="header">
<p>Home</p>
<a href="editUser.php">Perfil</a>
<p>sair</p>
<img class="hamburger" src=""></img>
</div>
<?php include('includes/navbar.inc'); ?>
<div id="today">Hoje</div>
<div id="byTime">
<?php for($i = 2016; $i>=1998; $i--): ?>
<div><?php echo $i;?></div>
<?php endfor; ?>
</div>
<?php include('includes/footer.inc'); ?>
</body>

</html>