Application de gestion d'employés ب PHP MVC و PDO الجزء الرابع
نظرة سريعة بالفيديو
1- إضافة الملف add.php
//
<?php
if(isset($_POST['submit'])){
$newEmploye = new EmployesController();
$newEmploye->addEmploye();
}
?>
<div class="container">
<div class="row my-4">
<div class="col-md-8 mx-auto">
<div class="card">
<div class="card-header">Ajouter un employé</div>
<div class="card-body bg-light">
<a href="<?php echo BASE_URL;?>" class="btn btn-sm btn-secondary mr-2 mb-2">
<i class="fas fa-home"></i>
</a>
<form method="post">
<div class="form-group">
<label for="nom">Nom*</label>
<input type="text" name="nom" class="form-control" placeholder="Nom">
</div>
<div class="form-group">
<label for="prenom">Prénom*</label>
<input type="text" name="prenom" class="form-control" placeholder="Prénom">
</div>
<div class="form-group">
<label for="mat">Matricule*</label>
<input type="text" name="mat" class="form-control" placeholder="Matricule">
</div>
<div class="form-group">
<label for="depart">Département*</label>
<input type="text" name="depart" class="form-control" placeholder="Département">
</div>
<div class="form-group">
<label for="poste">Poste*</label>
<input type="text" name="poste" class="form-control" placeholder="Poste">
</div>
<div class="form-group">
<label for="date_emb">Date Embauche*</label>
<input type="date" name="date_emb" class="form-control">
</div>
<div class="form-group">
<select class="form-control" name="statut">
<option value="1">Active</option>
<option value="0">Résilié</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" name="submit">Valider</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
2- إضافة الملف update.php
//
<?php
if(isset($_POST['id'])){
$exitEmploye = new EmployesController();
$employe = $exitEmploye->getOneEmploye();
}else{
Redirect::to('home');
}
if(isset($_POST['submit'])){
$exitEmploye = new EmployesController();
$exitEmploye->updateEmploye();
}
?>
<div class="container">
<div class="row my-4">
<div class="col-md-8 mx-auto">
<div class="card">
<div class="card-header">Modifier un employé</div>
<div class="card-body bg-light">
<a href="<?php echo BASE_URL;?>" class="btn btn-sm btn-secondary mr-2 mb-2">
<i class="fas fa-home"></i>
</a>
<form method="post">
<div class="form-group">
<label for="nom">Nom*</label>
<input type="text" name="nom" class="form-control" placeholder="Nom"
value="<?php echo $employe->nom; ?>"
>
</div>
<div class="form-group">
<label for="prenom">Prénom*</label>
<input type="text" name="prenom" class="form-control" placeholder="Prénom"
value="<?php echo $employe->prenom; ?>"
>
</div>
<div class="form-group">
<label for="mat">Matricule*</label>
<input type="text" name="mat" class="form-control" placeholder="Matricule"
value="<?php echo $employe->matricule; ?>">
</div>
<div class="form-group">
<label for="depart">Département*</label>
<input type="text" name="depart" class="form-control" placeholder="Département"
value="<?php echo $employe->depart; ?>">
<input type="hidden" name="id" value="<?php echo $employe->id;?>">
</div>
<div class="form-group">
<label for="poste">Poste*</label>
<input type="text" name="poste" class="form-control" placeholder="Poste"
value="<?php echo $employe->poste; ?>">
</div>
<div class="form-group">
<label for="date_emb">Date Embauche*</label>
<input type="date" name="date_emb" class="form-control">
</div>
<div class="form-group">
<select class="form-control" name="statut">
<option value="1" <?php echo $employe->statut ? 'selected' : ''; ?>>Active</option>
<option value="0"
<?php echo !$employe->statut ? 'selected' : ''; ?>
>Résilié</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" name="submit">Valider</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
3- إضافة الملف delete.php
//
<?php
if(isset($_POST['id'])){
$exitEmploye = new EmployesController();
$exitEmploye->deleteEmploye();
}
?>
4- إضافة الملف home.php
//
<?php
if(isset($_POST['find'])){
$data = new EmployesController();
$employes = $data->findEmployes();
}else{
$data = new EmployesController();
$employes = $data->getAllEmployes();
}
?>
<div class="container">
<div class="row my-4">
<div class="col-md-10 mx-auto">
<?php include('./views/includes/alerts.php');?>
<div class="card">
<div class="card-body bg-light">
<a href="<?php echo BASE_URL;?>add" class="btn btn-sm btn-primary mr-2 mb-2">
<i class="fas fa-plus"></i>
</a>
<a href="<?php echo BASE_URL;?>" class="btn btn-sm btn-secondary mr-2 mb-2">
<i class="fas fa-home"></i>
</a>
<a href="<?php echo BASE_URL;?>logout" title="Déconnexion" class="btn btn-link mr-2 mb-2">
<i class="fas fa-user mr-2"> <?php echo $_SESSION['username'];?></i>
</a>
<form method="post" class="float-right mb-2 d-flex flex-row">
<input type="text" class="form-control" name="search" placeholder="Recherche">
<button class="btn btn-info btn-sm" name="find" type="submit"><i class="fas fa-search"></i></button>
</form>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Nom & Prénom</th>
<th scope="col">Matricule</th>
<th scope="col">Département</th>
<th scope="col">Poste</th>
<th scope="col">Date Embauche</th>
<th scope="col">Statut</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php foreach($employes as $employe):?>
<tr>
<th scope="row"><?php echo $employe['nom'].' '.$employe['prenom']; ?></th>
<td><?php echo $employe['matricule'];?></td>
<td><?php echo $employe['depart'];?></td>
<td><?php echo $employe['poste'];?></td>
<td><?php echo $employe['date_emb'];?></td>
<td>
<?php echo $employe['statut']
?
'<span class="badge badge-success">Active</span>'
:
'<span class="badge badge-danger">Resilié</span>';
;?></td>
<td class="d-flex flex-row">
<form method="post" class="mr-1" action="update">
<input type="hidden" name="id" value="<?php echo $employe['id'];?>">
<button class="btn btn-sm btn-warning"><i class="fa fa-edit"></i></button>
</form>
<form method="post" class="mr-1" action="delete">
<input type="hidden" name="id" value="<?php echo $employe['id'];?>">
<button class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></button>
</form>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
5- إضافة الملف .htaccess
//
Options All -Indexes
RewriteEngine On
RewriteBase /gestion-employes-chaine/
RewriteRule ^([-a-zA-Z0-9]+)$ index.php?page=$1