modifentreprise.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <html>
  2. <head>
  3. <title>Modifier une entreprise</title>
  4. <link href="custom.css" rel="stylesheet">
  5. <meta name="viewport" content="width=device-width">
  6. <?php
  7. session_start();
  8. if (!isset($_SESSION['loggedin'])) {
  9. header("Location: login.php");
  10. exit;
  11. }
  12. ?>
  13. </head>
  14. <body>
  15. <fieldset>
  16. <legend><font size="6">Modifier une entreprise</font></legend>
  17. <?php
  18. include('class/sqlconnect.php');
  19. $id = $_GET['ID'];
  20. $sql = "SELECT * FROM Entreprise WHERE ID = '$id'";
  21. $result = $conn->query($sql);
  22. $row = $result->fetch_assoc();
  23. $entreprise_id = $row['StatutEntretien'];
  24. ?>
  25. <font size="5">Société <?php echo $row['NomSociete'] ?></font>
  26. </fieldset><br>
  27. <a href="index.php">Revenir à l'accueil</a><br><br>
  28. <form action="modifentreprise.php" method="post">
  29. <table>
  30. <tr>
  31. <td>
  32. <input type="hidden" name="ID" value="<?php echo $id; ?>">
  33. <label>Nom de la société :</label>
  34. </td>
  35. <td>
  36. <input type="text" name="NomSociete" value="<?php echo $row['NomSociete']; ?>">
  37. </td>
  38. </tr>
  39. <tr>
  40. <td>
  41. <label>Adresse :</label>
  42. </td>
  43. <td>
  44. <input type="text" name="Adresse" value="<?php echo $row['Adresse']; ?>">
  45. </td>
  46. </tr>
  47. <tr>
  48. <td>
  49. <label>Numéro de téléphone (format 0102030405):</label>
  50. </td>
  51. <td>
  52. <input type="text" name="NumeroTel" pattern="0[0-9]{9}" value="<?php echo $row['NumeroTel']; ?>">
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>
  57. <label>Statut :</label>
  58. </td>
  59. <td>
  60. <select name="statut" id="statut">
  61. <?php
  62. include('class/sqlconnect.php');
  63. $sql = "SELECT StatutEntretien.ID, StatutEntretien.Statut FROM StatutEntretien";
  64. $result = mysqli_query($conn, $sql);
  65. while($row = mysqli_fetch_assoc($result)){
  66. if ($row['ID'] == $entreprise_id) {
  67. echo "<option value='" . $row['ID'] . "' selected>" . $row['Statut'] . "</option>";
  68. } else {
  69. echo "<option value='" . $row['ID'] . "'>" . $row['Statut'] . "</option>";
  70. }
  71. }
  72. ?>
  73. </select>
  74. </table>
  75. <br>
  76. <input type="submit" name="submit" value="Enregistrer les modifications">
  77. </form>
  78. <?php
  79. if(isset($_POST['submit'])) {
  80. $id = $_POST['ID'];
  81. $nomsociete = $_POST['NomSociete'];
  82. $adresse = $_POST['Adresse'];
  83. $adresse = htmlentities($adresse);
  84. $adresse = str_replace("'", "\'", $adresse);
  85. $numerotel = $_POST['NumeroTel'];
  86. $statut = $_POST['statut'];
  87. $sql = "UPDATE Entreprise SET NomSociete='$nomsociete', Adresse='$adresse', NumeroTel='$numerotel', StatutEntretien='$statut' WHERE ID='$id'";
  88. if ($conn->query($sql) === TRUE) {
  89. echo "La société a été modifiée avec succès";
  90. header("Location: index.php");
  91. } else {
  92. echo "Erreur lors de la modification : " . $conn->error;
  93. }
  94. }
  95. ?>