Commit 48318083 authored by Gabriel Moreau's avatar Gabriel Moreau
Browse files

Create loan with db function

parent 4a432965
......@@ -14,20 +14,16 @@ $id_equipment = param_post('id_equipment');
if (empty($id_equipment))
$erreur = 'Nom de l\'appareil non précisé';
$nom = param_post('nom');
if (empty($nom))
$erreur = 'Nom de l\'appareil non précisé';
$equipe = param_post('equipe');
if (empty($equipe))
$id_equipe = param_post('equipe');
if (empty($id_equipe))
$erreur = 'Équipe non précisé';
$emprunt = param_post('emprunt');
if (empty($emprunt))
$date_emprunt = param_post('emprunt');
if (empty($date_emprunt))
$erreur = 'Date d\'emprunt non précisé';
//variables pouvant etre nulles
$retour = param_post('retour');
$date_retour = param_post('retour');
$commentaire = param_post('commentaire');
en_tete('Résultat demande d\'emprunt');
......@@ -41,10 +37,7 @@ if (!empty($erreur)) {
}
if ($pdo = connect_db()) {
$sql = 'SELECT * FROM pret WHERE nom = ? AND equipe = ?;';
$stmt = $pdo->prepare($sql);
$stmt->execute(array($nom, $equipe));
$pret = $stmt->fetchAll(PDO::FETCH_ASSOC);
$pret = get_loan_all_by_id_equipment($pdo, $id_equipment);
if (!empty($pret)) {
echo 'Erreur: l\'appareil est déjà emprunté';
pied_page();
......@@ -52,11 +45,9 @@ if ($pdo = connect_db()) {
}
// inscription
$sql = 'INSERT INTO pret (nom, equipe, emprunt, retour, commentaire) VALUES (?, ?, ?, ?, ?);';
$stmt = $pdo->prepare($sql);
$stmt->execute(array($nom, $equipe, $emprunt, $retour, $commentaire));
$id_loan = set_loan_new($pdo, $id_equipment, $id_equipe, $date_emprunt, $date_retour, $commentaire);
echo 'Ajout du pr&ecirc;t sur l\'appareil '.$nom.' valid&eacute;<br />';
echo 'Ajout du pr&ecirc;t sur l\'appareil '.$id_equipment.' valid&eacute;<br />';
echo '<br /><br /><a href="loan-list.php">Suite</a>';
} // end if connect
?>
......
......@@ -131,6 +131,31 @@ function get_category_by_id($pdo, $id) {
// ---------------------------------------------------------------------
function get_loan_all_by_id_equipment($pdo, $id_equipment) {
// recupere l'appareil via l'id qui est mis dans un champs texte (nom) !
$sql = 'SELECT * FROM pret WHERE nom = ?;';
$stmt = $pdo->prepare($sql);
$stmt->execute(array($id_equipment));
$result_fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result_fetch) > 0)
return $result_fetch[0];
return false;
}
// ---------------------------------------------------------------------
function get_loan_all_by_id($pdo, $id) {
$sql = 'SELECT * FROM pret WHERE id = ?;';
$stmt = $pdo->prepare($sql);
$stmt->execute(array($id));
$result_fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result_fetch) > 0)
return $result_fetch[0];
return false;
}
// ---------------------------------------------------------------------
function get_loan_listall($pdo) {
$sql = 'SELECT * FROM pret;';
$stmt = $pdo->prepare($sql);
......@@ -141,6 +166,15 @@ function get_loan_listall($pdo) {
// ---------------------------------------------------------------------
function set_loan_new($pdo, $id_equipment, $id_team, $date_begin, $date_end, $comment) {
$sql = 'INSERT INTO pret (nom, equipe, emprunt, retour, commentaire) VALUES (?, ?, ?, ?, ?);';
$stmt = $pdo->prepare($sql);
$stmt->execute(array($id_equipment, $id_team, $date_begin, $date_end, $comment));
return $pdo->lastInsertId();
}
// ---------------------------------------------------------------------
function get_supplier_by_id($pdo, $id) {
$sql = 'SELECT id, nom FROM fournisseurs WHERE id = ?;';
$stmt = $pdo->prepare($sql);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment