0% found this document useful (0 votes)
2 views

code

The document contains PHP code for a car repair management system, including classes for 'Voiture' (Car) with properties and methods, as well as SQL commands for creating and managing related database tables. It features forms for adding and editing car details, connecting to a MySQL database, and displaying repair information. The code also includes session management for user authentication and interaction with the database to retrieve and manipulate car and repair records.

Uploaded by

aracasablanca7
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

code

The document contains PHP code for a car repair management system, including classes for 'Voiture' (Car) with properties and methods, as well as SQL commands for creating and managing related database tables. It features forms for adding and editing car details, connecting to a MySQL database, and displaying repair information. The code also includes session management for user authentication and interaction with the database to retrieve and manipulate car and repair records.

Uploaded by

aracasablanca7
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

// EXercice 1 : POO

// 1.

class Voiture

private string $Matricule;

private string $Marque;

private string $Annee;

private int $NumClient;

public function __construct($matr, $marq, $ann, $nc)

$this->Matricule = $matr;

$this->Marque = $marq;

$this->Annee = $ann;

$this->NumClient = $nc;

public function getAnnee():

return $this->Annee;

public function getMarque():

return $this->Marque;

public function getMatricule():

{
return $this->Matricule;

public function getNumClient():

return $this->NumClient;

public function setAnnee($Annee):

$this->Annee = $Annee;

public function setMarque( $Marque):

$this->Marque = $Marque;

public function setMatricule( $Matricule):

$this->Matricule = $Matricule;

public function setNumClient($NumClient): {

$this->NumClient = $NumClient;

public function __toString():

return nl2br("Matricule : $this->Matricule \t Marque : $this->Marque \t Annee : $this->Annee \t


NumClient : $this->NumClient");
}

###########################

PRIMARY KEY (Matricule),

FOREIGN KEY (NumClient) REFERENCES Client(NumClient)

);

CREATE TABLE Reparation(

NumRep INT AUTO_INCREMENT,

Matricule INT,

Description TEXT,

DateRep Date,

Cout int,

PRIMARY KEY (NumRep),

FOREIGN KEY (Matricule) REFERENCES Voiture(Matricule)

);

-- Inserting data into the Client table

INSERT INTO Client (RaisonSociale, Adresse) VALUES

('ABC Company', '123 Main Street'),

('XYZ Corporation', '456 Park Avenue'),

('Example Ltd.', '789 Elm Road'),

('Test Industries', '321 Oak Lane'),

('Sample Company', '555 Maple Avenue');


-- Inserting data into the Voiture table

INSERT INTO Voiture (Marque, Annee, NumClient) VALUES

('Honda Accord', '2018-01-01', 1),

('Ford Mustang', '2020-05-15', 3),

('Toyota Camry', '2019-10-10', 2),

('BMW 3 Series', '2022-02-28', 4),

('Chevrolet Malibu', '2017-06-30', 1);

-- Inserting data into the Reparation table

INSERT INTO Reparation (Matricule, Description, DateRep, Cout) VALUES

(1, 'Engine Tune-up', '2022-03-15', 200),

(2, 'Brake Pad Replacement', '2023-01-10', 150),

(3, 'Oil Change', '2022-09-05', 50),

(4, 'Transmission Repair', '2023-04-20', 500),

(5, 'Tire Rotation and Alignment', '2022-06-12', 100);

////////////////////////////////////////////////////////////////////////////////////
##################

connection.php

##################

<?php

$dsn = "mysql:host=localhost; dbname=carrepdb";

$user = "root";

$pass = "";

$conn = new PDO($dsn, $user, $pass);

?>

<html lang="en">

<head>

<title>connection.php</title>

<!-- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"


rel="stylesheet"-->

<!-- integrity="sha384-
rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">-->

<link href="../bootstrap.min.css" rel="stylesheet">

</head>

<body>

<div class="w-50 me-auto ms-auto">

<h2 class="text-center">Connection page</h2>

<form class="mt-3" method="post">


<input placeholder="Num_Client" name="nc" type="number" min="1" class="form-control w-
100"><br>

<input placeholder="Matricule" name="matr" type="number" class="form-control w-


100"><br>

<button class="btn btn-primary w-100" name="Connect">Connect</button>

</form>

</div>

</body>

</html>

<?php

if (isset($_POST["Connect"])) {

if (!empty($_POST["nc"]) and !empty($_POST["matr"])) {

$sql = "SELECT * FROM voiture WHERE Matricule = ? AND NumClient = ?";

$stmt = $conn->prepare($sql);

$stmt->execute([$_POST["matr"], $_POST["nc"]]);

if ($stmt->rowCount() == 1) {

session_start();

$_SESSION["client"] = $stmt->fetch();

header("location:Reparation.php");

} else {

echo "<script>";

echo "alert('error')";

echo "</script>";

##################################################################################
#######################
##############

Reparation.php

#############

<?php

$dsn = "mysql:host=localhost; dbname=carrepdb";

$user = "root";

$pass = "";

$conn = new PDO($dsn, $user, $pass);

session_start();

$data = $_SESSION["client"];

?>

<html lang="en">

<head>

<title>Reparation.php</title>

<!-- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"


rel="stylesheet"-->

<!-- integrity="sha384-
rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">-->

<link href="../bootstrap.min.css" rel="stylesheet">

</head>

<body>

<div class="">

<h3>Info de la voiture</h3>

<ul>

<li>Matricule : <?PHP echo $data["Matricule"] ?></li>

<li>Marque :<?PHP echo $data["Marque"] ?></li>

<li>Annee : <?PHP echo $data["Annee"] ?></li>

<li>NumClient : <?PHP echo $data["NumClient"] ?></li>

</ul>
</div>

<div class="">

<table class="table table-bordered bord m-1 text-center ">

<thead>

<th>NumRep</th>

<th>Matricule</th>

<th>Description</th>

<th>DateRep</th>

<th>Cout</th>

</thead>

<tbody>

<?PHP

$sql = "SELECT * FROM reparation WHERE Matricule = ?";

$stmt = $conn->prepare($sql);

$stmt->execute([$data["Matricule"]]);

$repData = $stmt->fetch();

?>

<tr>

<td><?PHP echo $repData["NumRep"] ?></td>

<td><?PHP echo $repData["Matricule"] ?></td>

<td><?PHP echo $repData["Description"] ?></td>

<td><?PHP echo $repData["DateRep"] ?></td>

<td><?PHP echo $repData["Cout"] ?></td>

</tr>

</tbody>

</table>

</div>

</body>

</html>
##################################################################################
#######################

##############

Liste Voiture.php

#############

<?php

$dsn = "mysql:host=localhost; dbname=carrepdb";

$user = "root";

$pass = "";

$conn = new PDO($dsn, $user, $pass);

?>

<html lang="en">

<head>

<title>Liste Voiture.php</title>

<!-- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"


rel="stylesheet"-->

<!-- integrity="sha384-
rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">-->

<link href="../bootstrap.min.css" rel="stylesheet">

</head>

<body>

<h2 class="text-center">Ajouter un nouvelle voiture</h2>

<div class="w-75">

<form class="p-3" method="post">

<input placeholder="Marque" name="marque" type="text" class="form-control w-25"><br>

<input placeholder="Annee" name="annee" type="date" class="form-control w-25"><br>

<input placeholder="Nom Client" name="numClient" type="number" class="form-control w-


25" min="1"><br>
<button class="btn btn-primary" name="add">Add</button>

</form>

</div>

<div class="">

<table class="table table-bordered bord m-1 text-center ">

<thead>

<th>Matricule</th>

<th>Marque</th>

<th>Annee</th>

<th>NumClient</th>

<th>Delete</th>

<th>Modifier</th>

</thead>

<tbody>

<?PHP

$sql = "SELECT * FROM voiture";

$stmt = $conn->prepare($sql);

$stmt->execute();

foreach ($stmt->fetchAll() as $element) {

?>

<tr>

<td><?PHP echo $element["Matricule"] ?></td>

<td><?PHP echo $element["Marque"] ?></td>

<td><?PHP echo $element["Annee"] ?></td>

<td><?PHP echo $element["NumClient"] ?></td>

<td>
<a class=" btn btn-danger" href="del.php?matricule=<?PHP echo $element["Matricule"]
?>"

onclick="return confirm('delete this element ?!')">Delete

this element</a>

</td>

<td>

<a class=" btn btn-primary" href="edit.php?matricule=<?PHP echo


$element["Matricule"] ?>">

Modifier this element

</a>

</td>

</tr>

<?PHP

?>

</tbody>

</table>

</div>

</body>

</html>

<?php

if (isset($_POST["add"])) {

if (!empty($_POST["numClient"]) and !empty($_POST["annee"]) and !empty($_POST["marque"])) {

$sql = "INSERT INTO voiture VALUES(null,?,?,?)";

$stmt = $conn->prepare($sql);

$stmt->execute([$_POST["marque"], $_POST["annee"], $_POST["numClient"]]);

header("location:" . $_SERVER["PHP_SELF"]);

##################################################################################
#######################
##############

edit.php

#############

<?php

$dsn = "mysql:host=localhost; dbname=carrepdb";

$user = "root";

$pass = "";

$conn = new PDO($dsn, $user, $pass);

$matricule = $_GET["matricule"];

?>

<?php

$sql = "SELECT * FROM voiture WHERE Matricule = ?";

$stmt = $conn->prepare($sql);

$stmt->execute([$matricule]);

$data = $stmt->fetch();

?>

<html lang="en">

<head>

<title>Edit Voiture Donnes</title>

<!-- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"


rel="stylesheet"-->

<!-- integrity="sha384-
rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">-->

<link href="../bootstrap.min.css" rel="stylesheet">

</head>

<body>
<h2 class="text-center">modifier un voiture</h2>

<div class="w-75">

<form class="p-3" method="post">

<p>Edit Voiture Matricule : <?PHP echo $matricule ?></p>

<input value="<?PHP echo $data["Marque"] ?>" placeholder="Modifier Marque"


name="marque" type="text"

class="form-control w-25"><br>

<input value="<?PHP echo $data["Annee"] ?>" placeholder="ModifierAnnee" name="annee"


type="date"

class="form-control w-25"><br>

<input value="<?PHP echo $data["NumClient"] ?>" placeholder="Modifier Nom Client"


name="numClient" type="number"

class="form-control w-25"

min="1"><br>

<button class="btn btn-secondary" name="modify">Modify</button>

</form>

</div>

<?php

if (isset($_POST["modify"])) {

if (!empty($_POST["numClient"]) and !empty($_POST["annee"]) and !empty($_POST["marque"])) {

$sql = "UPDATE voiture SET Marque = ?, Annee = ?, NumClient = ? WHERE Matricule = ?";

$stmt = $conn->prepare($sql);

$stmt->execute([$_POST["marque"], $_POST["annee"], $_POST["numClient"], $matricule]);

header("location:ListeVoiture.php");

} else {

echo "d'echec de la modification";

}
##################################################################################
#######################

##############

del.php

#############

<?php

$dsn = "mysql:host=localhost; dbname=carrepdb";

$user = "root";

$pass = "";

$conn = new PDO($dsn, $user, $pass);

$matricule = $_GET["matricule"];

echo "<h1>$matricule</h1>";

$sql = "DELETE FROM voiture where Matricule = ?";

$stmt = $conn->prepare($sql);

$stmt->execute([$matricule]);

header("location:ListeVoiture.php");

You might also like