Browse Source

Contact - Entreprise - Statut

Alexandre MOTTIER 1 year ago
parent
commit
69e13e743d
8 changed files with 300 additions and 0 deletions
  1. 47 0
      ajoutcontact.php
  2. 39 0
      ajoutentreprise.php
  3. 20 0
      class/class.modifcontact.php
  4. 13 0
      class/sqlconnect.php
  5. 40 0
      index.php
  6. 26 0
      infocontact.php
  7. 65 0
      modifcontact.php
  8. 50 0
      modificationstatut.php

+ 47 - 0
ajoutcontact.php

@@ -0,0 +1,47 @@
+<html>
+<head>
+    <title>Ajouter un contact</title>
+</head>
+<body>
+    <h1>Ajouter un contact</h1>
+<?php
+    include 'class/sqlconnect.php';
+
+    if(isset($_POST['submit'])){
+        $prenom = $_POST['Prenom'];
+        $nom = $_POST['Nom'];
+        $poste = $_POST['Poste'];
+        $mobile = $_POST['Mobile'];
+        $entreprise = $_POST['IDEntreprise'];
+
+        $sql = "INSERT INTO Contact (Prenom, Nom, Poste, Mobile, IDEntreprise) VALUES ('$prenom', '$nom', '$poste', '$mobile', '$entreprise')";
+        mysqli_query($conn, $sql);
+    }
+?>
+
+<form method="post" action="">
+    <label for="Prenom">Prénom :</label>
+    <input type="text" name="Prenom" required>
+    <br>
+    <label for="Nom">Nom :</label>
+    <input type="text" name="Nom" required>
+    <br>
+    <label for="Poste">Poste occupé :</label>
+    <input type="text" name="Poste" >
+    <br>
+    <label for="Mobile">Numéro de mobile :</label>
+    <input type="text" name="Mobile" >
+    <br>
+    <label for="Entreprise">Entreprise :</label>
+    <select name="IDEntreprise">
+        <?php
+            $sql = "SELECT ID, NomSociete FROM Entreprise";
+            $result = mysqli_query($conn, $sql);
+            while($row = mysqli_fetch_assoc($result)){
+                echo "<option value='" . $row['ID'] . "'>" . $row['NomSociete'] . "</option>";
+            }
+        ?>
+    </select>
+    <br><br>
+    <input type="submit" name="submit" value="Ajouter">
+</form>

+ 39 - 0
ajoutentreprise.php

@@ -0,0 +1,39 @@
+<html>
+<head>
+    <title>Ajouter une entreprise</title>
+</head>
+<?php
+include("class/sqlconnect.php");
+?>
+<body>
+    <h1>Ajouter une entreprise</h1>
+    <form action="ajoutentreprise.php" method="post">
+        <label for="NomSociete">Nom de la société:</label>
+        <input type="text" id="NomSociete" name="NomSociete" required>
+        <br>
+        <label for="Adresse">Adresse postale de la société:</label>
+        <input type="text" id="Adresse" name="Adresse">
+        <br>
+        <label for="NumeroTel">Numéro de téléphone de la société:</label>
+        <input type="text" id="NumeroTel" name="NumeroTel">
+        <br>
+        <input type="submit" name="submit" value="Ajouter">
+    </form>
+    <?php
+      if(isset($_POST["submit"])) {
+          $NomSociete = $_POST["NomSociete"];
+          $Adresse = $_POST["Adresse"];
+          $NumeroTel = $_POST["NumeroTel"];
+          $StatutEntretien = "2";
+
+          $sql = "INSERT INTO Entreprise (NomSociete, Adresse, NumeroTel, StatutEntretien)
+          VALUES ('$NomSociete', '$Adresse', '$NumeroTel', '$StatutEntretien')";
+          $result = mysqli_query($conn, $sql);
+
+          if($result) {
+              echo "La nouvelle entreprise a été ajoutée avec succès.";
+          } else {
+              echo "Erreur : " . $sql . "<br>" . mysqli_error($conn);
+          }
+        }
+    ?>

+ 20 - 0
class/class.modifcontact.php

@@ -0,0 +1,20 @@
+<?php
+if(isset($_POST['submit'])) {
+$id = $_GET['ID'];
+$prenom = $_POST['prenom'];
+$nom = $_POST['nom'];
+$poste = $_POST['poste'];
+$entreprise = $_POST['entreprise'];
+$mobile = $_POST['mobile'];
+
+$sql = "UPDATE Contact SET Prenom='$prenom', Nom='$nom', Poste='$poste', IDEntreprise='$entreprise', Mobile='$mobile' WHERE ID='$id'";
+
+if ($conn->query($sql) === TRUE) {
+    echo "Le contact a été modifié avec succès";
+    echo $sql;
+    // header("refresh:1; url=infocontact.php?ID=".$id);
+} else {
+    echo "Erreur lors de la modification : " . $conn->error;
+}
+}
+?>

+ 13 - 0
class/sqlconnect.php

@@ -0,0 +1,13 @@
+<?php
+$serveur = "localhost";
+$login = "rechercheemploi";
+$motDePasse = "rechercheemploi";
+$base = "rechercheemploi";
+
+$conn = new mysqli($serveur, $login, $motDePasse, $base);
+
+if ($conn->connect_error) {
+    die("La connexion à la base de données a échoué : " . $conn->connect_error);
+}
+
+?>

+ 40 - 0
index.php

@@ -0,0 +1,40 @@
+<html>
+<head>
+    <title>Liste des entreprises</title>
+</head>
+<body>
+    <h1>Liste des entreprises</h1>
+<?php
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+include("class/sqlconnect.php");
+
+// Récupère les données de la table Entreprise
+$sql = "SELECT Entreprise.ID, Entreprise.NomSociete, Contact.ID, Contact.Prenom, Contact.Nom, Entreprise.Adresse, StatutEntretien.Statut
+FROM Entreprise
+LEFT JOIN Contact ON Entreprise.ID = Contact.IDEntreprise
+LEFT JOIN StatutEntretien ON Entreprise.StatutEntretien = StatutEntretien.ID";
+$result = mysqli_query($conn, $sql);
+if (!$result) {
+    die("Impossible de récupérer les données: " . mysqli_error($conn));
+}
+
+echo "<table style='border:1px solid #000;'>";
+echo "<tr><th style='border:1px solid #000;'>Nom de la société</th><th style='border:1px solid #000;'>Contact</th><th style='border:1px solid #000;'>Adresse</th><th style='border:1px solid #000;'>Statut</th></tr>";
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+    echo "<tr>";
+    echo "<td style='border:1px solid #000;'>" . $row['NomSociete'] . "</td>";
+    echo "<td style='border:1px solid #000;'>" . "<a href='infocontact.php?ID=" . $row['ID'] . "'>" . $row['Prenom'] . ' ' . $row['Nom'] . "</a>" . "</td>";
+    echo "<td style='border:1px solid #000;'>" . $row['Adresse'] . "</td>";
+    echo "<td style='border:1px solid #000;'>" . $row['Statut'] . "</td>";
+    echo '</tr>';
+}
+echo "</table>";
+mysqli_close($conn);
+?>
+<br>
+<button onclick="window.location.href='ajoutentreprise.php'" class="button">Créer une entreprise</button>
+<button onclick="window.location.href='ajoutcontact.php'" class="button">Créer un contact</button>
+<button onclick="window.location.href='modificationstatut.php'" class="button">Modifier le statut pour une entreprise</button>

+ 26 - 0
infocontact.php

@@ -0,0 +1,26 @@
+<html>
+<head>
+    <title>Afficher un contact</title>
+</head>
+<body>
+    <h1>Afficher un contact</h1>
+<?php
+include('class/sqlconnect.php');
+$id = $_GET['ID'];
+
+$sql = "SELECT Contact.Prenom, Contact.Nom, Contact.Poste, Entreprise.NomSociete, Contact.Mobile FROM Contact JOIN Entreprise ON Contact.IDEntreprise = Entreprise.ID WHERE Contact.ID =$id";
+$result = mysqli_query($conn, $sql);
+
+echo "<table style='border:1px solid #000;'>";
+while($row = $result->fetch_assoc()) {
+        echo "<tr><td style='border:1px solid #000;'>Prénom :</td><td style='border:1px solid #000;'>" . $row["Prenom"] . "</td></tr>";
+        echo "<tr><td style='border:1px solid #000;'>Nom :</td><td style='border:1px solid #000;'>" . $row["Nom"] . "</td></tr>";
+        echo "<tr><td style='border:1px solid #000;'>Poste :</td><td style='border:1px solid #000;'>" . $row["Poste"] . "</td></tr>";
+        echo "<tr><td style='border:1px solid #000;'>Entreprise :</td><td style='border:1px solid #000;'>" . $row["NomSociete"] . "</td></tr>";
+        echo "<tr><td style='border:1px solid #000;'>Numéro de mobile :</td><td style='border:1px solid #000;'>" . $row["Mobile"] . "</td></tr>";
+    };
+$conn->close();
+?>
+</table>
+<br><br>
+<button onclick="window.location.href='modifcontact.php?ID=<?php echo $id ?>'" class="button">Modifier le contact</button>

+ 65 - 0
modifcontact.php

@@ -0,0 +1,65 @@
+<html>
+<head>
+    <title>Modifier un contact</title>
+</head>
+<body>
+    <h1>Modifier un contact</h1>
+<?php
+    include('class/sqlconnect.php');
+    $id = $_GET['ID'];
+    $sql = "SELECT * FROM Contact WHERE ID = '$id'";
+    $result = $conn->query($sql);
+    $row = $result->fetch_assoc();
+?>
+
+<form action="modifcontact.php" method="post">
+    <input type="hidden" name="ID" value="<?php echo $id; ?>">
+    <label>Prénom :</label>
+    <input type="text" name="Prenom" value="<?php echo $row['Prenom']; ?>">
+    <br>
+    <label>Nom :</label>
+    <input type="text" name="Nom" value="<?php echo $row['Nom']; ?>">
+    <br>
+    <label>Poste :</label>
+    <input type="text" name="Poste" value="<?php echo $row['Poste']; ?>">
+    <br>
+    <label>Entreprise :</label>
+    <select name="IDEntreprise">
+        <?php
+            $sql = "SELECT * FROM Entreprise";
+            $result = $conn->query($sql);
+            while ($entreprise = $result->fetch_assoc()) {
+                if ($entreprise['ID'] == $row['IDEntreprise']) {
+                    echo "<option value='" . $entreprise['ID'] . "' selected>" . $entreprise['NomSociete'] . "</option>";
+                } else {
+                    echo "<option value='" . $entreprise['ID'] . "'>" . $entreprise['NomSociete'] . "</option>";
+                }
+            }
+        ?>
+    </select>
+    <br>
+    <label>Numéro de mobile :</label>
+    <input type="text" name="Mobile" value="<?php echo $row['Mobile']; ?>">
+    <br>
+    <input type="submit" name="submit" value="Enregistrer les modifications">
+</form>
+
+<?php
+if(isset($_POST['submit'])) {
+$id = $_POST['ID'];
+$prenom = $_POST['Prenom'];
+$nom = $_POST['Nom'];
+$poste = $_POST['Poste'];
+$entreprise = $_POST['IDEntreprise'];
+$mobile = $_POST['Mobile'];
+
+$sql = "UPDATE Contact SET Prenom='$prenom', Nom='$nom', Poste='$poste', IDEntreprise='$entreprise', Mobile='$mobile' WHERE ID='$id'";
+
+if ($conn->query($sql) === TRUE) {
+    echo "Le contact a été modifié avec succès";
+    header("refresh:1; url=infocontact.php?ID=".$id);
+} else {
+    echo "Erreur lors de la modification : " . $conn->error;
+}
+}
+?>

+ 50 - 0
modificationstatut.php

@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Modification statut entretien</title>
+</head>
+<?php
+include("class/sqlconnect.php");
+?>
+<body>
+    <form action="modificationstatut.php" method="post">
+        <label for="entreprise">Entreprise</label>
+        <select name="entreprise" id="entreprise">
+            <?php
+                $sql = "SELECT ID, NomSociete FROM Entreprise";
+                $result = mysqli_query($conn, $sql);
+                while($row = mysqli_fetch_assoc($result)){
+                    echo "<option value='" . $row['ID'] . "'>" . $row['NomSociete'] . "</option>";
+                }
+            ?>
+        </select>
+        <br>
+        <label for="statut">Statut d'entretien</label>
+        <select name="statut" id="statut">
+            <?php
+                $sql = "SELECT ID, Statut FROM StatutEntretien";
+                $result = mysqli_query($conn, $sql);
+                while($row = mysqli_fetch_assoc($result)){
+                    echo "<option value='" . $row['ID'] . "'>" . $row['Statut'] . "</option>";
+                }
+            ?>
+        </select>
+        <br>
+        <input type="submit" name="submit" value="Modifier statut">
+    </form>
+    <?php
+        if(isset($_POST['submit'])){
+            $entreprise = $_POST['entreprise'];
+            $statut = $_POST['statut'];
+
+            $sql = "UPDATE Entreprise SET StatutEntretien = '$statut' WHERE ID = '$entreprise'";
+            $result = mysqli_query($conn, $sql);
+            if($result){
+                echo "Statut d'entretien mis à jour avec succès.";
+            } else {
+                echo "Erreur lors de la mise à jour du statut d'entretien : " . mysqli_error($conn);
+            }
+        }
+    ?>
+</body>
+</html>