Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.64 KB | None | 0 0
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
  3. <html>
  4. <head>
  5. <style type="text/css">
  6. table.pretty {
  7. margin-left: auto;
  8. margin-right: auto;
  9. background: whitesmoke;
  10. border-collapse: collapse;
  11. }
  12. table.pretty th, table.pretty td {
  13. border: 1px silver solid;
  14. padding: 0.2em;
  15. }
  16. table.pretty th {
  17. background: gainsboro;
  18. text-align: left;
  19. }
  20.  
  21. table.pretty caption { border:1px solid #5C443A;
  22. color:#5C443A;
  23. font-weight:bold;
  24. letter-spacing:15px;
  25. padding:6px 4px 8px 0px;
  26. text-align:center;
  27. text-transform:uppercase;
  28. }
  29. </style>
  30. </head>
  31. <body bgcolor="#FFFFAA" text="#000000">
  32.  
  33.  
  34. <?php
  35. error_reporting(0);
  36. $step='U';
  37. if (isset($_POST["step"]) ) $step= $_POST["step"];
  38.  
  39. switch ($step)
  40. {
  41. // form auth
  42. case "U":
  43. echo "<form method=\"post\" action=\"ems.php\">";
  44. echo "<small><font face=\"Verdana,Arial\">\n";
  45. echo "<div> <table class=\"pretty\">";
  46. echo"<caption>Simple Application EMS</caption>";
  47. echo "<TR> <Th> DataBase ID</Th> <td><input type=\"text\" name=\"db\" /> </td> </TR>";
  48. echo "<TR> <Th> User ID</Th> <td><input type=\"text\" name=\"user\" /></td> </TR>";
  49. echo "<TR> <Th> Password</Th> <td> <input type=\"password\" name=\"passwd\" /> </td> </TR>";
  50. echo "<TR><TD></TD> <TD><button>Valider</button> </TD></TR>";
  51. echo "</table> </div>";
  52. echo" <input type=\"hidden\" value=\"F\" name=\"step\"> ";
  53. echo "</form>";
  54. break;
  55. // auth + form general
  56. case "F":
  57.  
  58. if (isset($_POST["user"])) $user= $_POST["user"];
  59. else {
  60. exit("Unsupprted Operation ...");
  61. }
  62. $db=$user;
  63. if (isset($_POST["db"]) ) $db= $_POST["db"];
  64. if (isset($_POST["passwd"]) ) $passwd= $_POST["passwd"];
  65.  
  66.  
  67.  
  68. // attempt a connection
  69. $dbh = pg_pconnect("host=aquabdd dbname=$db user=$user password=$passwd");
  70. if (!$dbh) {
  71. die("<H1>Echec connection : Bzzzt </H1>");
  72. } else{
  73. session_start();
  74. $_SESSION['passwd'] = $passwd;
  75. $_SESSION['user'] = $user;
  76. $_SESSION['db'] = $db;
  77. }
  78.  
  79. break;
  80. // form general
  81. case "C" :
  82. session_start();
  83. if (isset($_SESSION["passwd"]))
  84. $passwd=$_SESSION['passwd'];
  85. else {
  86. exit("Unsupprted Operation ...");
  87. }
  88.  
  89. $user= $_SESSION["user"];
  90. $db= $_SESSION["db"];
  91.  
  92. // attempt a connection
  93. $dbh = pg_pconnect("host=aquabdd dbname=$db user=$user password=$passwd");
  94. if (!$dbh) {
  95. die("Error in connection ");
  96. }
  97.  
  98. if (isset($_POST["query"])) $query= $_POST["query"];
  99. else {
  100. exit("Unsupprted Operation ...");
  101. }
  102. switch ($query)
  103. {
  104.  
  105. case "insert":
  106. if ( (isset($_POST["Nom"])) && (!(empty($_POST["Nom"]))))
  107. $Nom= $_POST["Nom"];
  108. else $Nom=NULL;
  109. if ( (isset($_POST["Prenom"])) && (!(empty($_POST["Prenom"]))))
  110. $Prenom= $_POST["Prenom"];
  111. else $Matiere=NULL;
  112. if ( (isset($_POST["Matiere"])) && (!(empty($_POST["Matiere"]))))
  113. $Matiere= $_POST["Matiere"];
  114. else $Matiere=NULL;
  115. if ( (isset($_POST["Salle"])) && (!(empty($_POST["Salle"]))))
  116. $Salle= $_POST["Salle"];
  117. else $Salle=NULL;
  118.  
  119. $sql = "select ems_ins('$Nom','$Prenom','$Matiere','$Salle')";
  120. $res = pg_query($dbh, $sql);
  121. if (!$res) {
  122. die("Error in SQL query: " . pg_last_error());
  123. }
  124. break;
  125. case "delete":
  126. if ( (isset($_POST["rad"])) && (!(empty($_POST["rad"])))) {
  127. $rad= $_POST["rad"];
  128. $sql = "select ems_del('$rad')";
  129. $res = pg_query($dbh, $sql);
  130. if (!$res) {
  131. die("Error in SQL query: " . pg_last_error());
  132. }
  133. }
  134. break;
  135. case "update":
  136. if ( (isset($_POST["rad"])) && (!(empty($_POST["rad"])))) {
  137. $rad= $_POST["rad"];
  138. $sql = "select * from ems where ctid='$rad'";
  139. $res = pg_query($dbh, $sql);
  140. if (!$res) {
  141. die("Error in SQL query: " . pg_last_error());
  142. }
  143. $rowc = pg_fetch_array($res);
  144. // echo "$rowc[0]*$rowc[1]*$rowc[2]*$rowc[3]*$rad\n";
  145. if ( (isset($_POST["Nom"])) && (!(empty($_POST["Nom"]))))
  146. $Nom= $_POST["Nom"];
  147. else $Nom=$rowc[0];
  148. if ( (isset($_POST["Prenom"])) && (!(empty($_POST["Prenom"]))))
  149. $Prenom= $_POST["Prenom"];
  150. else $Prenom=$rowc[1];
  151. if ( (isset($_POST["Matiere"])) && (!(empty($_POST["Matiere"]))))
  152. $Matiere= $_POST["Matiere"];
  153. else $Matiere=$rowc[2];
  154. if ( (isset($_POST["Salle"])) && (!(empty($_POST["Salle"]))))
  155. $Salle= $_POST["Salle"];
  156. else $Salle=$rowc[3];
  157. $sql = "select ems_upd('$Nom','$Prenom','$Matiere','$Salle','$rad')";
  158. $res = pg_query($dbh, $sql);
  159. if (!$res) {
  160. die("Error in SQL query: " . pg_last_error());
  161. }
  162. }
  163. break;
  164. default:
  165. echo "unsupported operation";
  166. break;
  167. }
  168.  
  169. break;
  170. default:
  171. echo "unsupported operation";
  172. break;
  173. }
  174. // general form
  175. if (($step=='F') || ($step=='C')) {
  176. $sql = "SELECT nom,prenom,matiere,salle,ctid FROM ems";
  177. $res = pg_query($dbh, $sql);
  178. if (!$res) {
  179. die("Error in SQL query: " . pg_last_error());
  180. }
  181. echo "<form method=\"post\" action=\"ems.php\">";
  182. echo "<small><font face=\"Verdana,Arial\">\n";
  183. echo "<div> <table class=\"pretty\">";
  184. echo"<caption>Simple Application EMS</caption>";
  185. echo "<TR> <Th>OLD <img src=\"Arr_down.png\"/> </Th> <th> Nom</th> <th> Prenom";
  186. echo "</TH> <TH>Matiere</TH><TH> Salle</TH> </TR>";
  187. while ( $rowc = pg_fetch_array($res) ) {
  188. echo "<TR> <TD>";
  189. echo "<input type=\"radio\" name=\"rad\" value=\"". $rowc[4] . "\" title=\"tid=$rowc[4]\" />\n";
  190. echo "</TD> <TD>";
  191. echo $rowc[0];
  192. echo "</TD> <TD>";
  193. echo $rowc[1];
  194. echo "</TD> <TD>";
  195. echo $rowc[2];
  196. echo "</TD> <TD>";
  197. echo $rowc[3];
  198. echo "</TD> </TR>";
  199.  
  200.  
  201. echo "</font></small>\n";
  202.  
  203. }
  204. echo "<TR> </TR>";
  205. echo "<TR><Th>NEW <img src=\"Arr_right.png\"/> </Th><TD><input type=\"text\" name=\"Nom\" size=10 /> </TD>\n";
  206. echo "<TD><input type=\"text\" name=\"Prenom\" size=10 /> </TD>\n";
  207. echo "<TD><input type=\"text\" name=\"Matiere\" size=10 /> </TD>\n";
  208. echo "<TD><input type=\"text\" name=\"Salle\" size=5/> </TD></TR>\n";
  209. echo" <input type=\"hidden\" value=\"C\" name=\"step\"> \n ";
  210. echo "<TR> </TR>";
  211. echo "<TR><TD></TD>";
  212.  
  213. echo "<TD><button NAME=\"query\" TYPE=\"submit\" value=\"insert\" title=\"Entrer le tuple a inserer dans la ligne NEW et Cliquer\">insert</button> </TD>";
  214. echo "<TD><button NAME=\"query\" TYPE=\"submit\" value=\"delete\" title=\"Selectionner le tuple a supprimer dans la colonne OLD et Cliquer\">delete</button> </TD>";
  215. echo "<TD><button NAME=\"query\" TYPE=\"submit\" value=\"update\" title=\"Selectionner le tuple a modifier dans la colonne OLD et Entrer dans la ligne NEW les nouvelles valeurs des champs a modifier puis Cliquer\">update</button> </TD>";
  216. echo "<TD><button TYPE=RESET title=\"Annuler la selection ou saisie\">reset</button> </TD></TR>";
  217.  
  218. echo "</table> </div>";
  219. echo "</form>";
  220. pg_free_result($res);
  221.  
  222. echo "<p align=\"center\"><font face=\"Verdana, Arial\"><small>\n";
  223. echo "<small>Connection info -> User ID : $user -- Database ID: $db\n";
  224. echo "</small></small></font></p>\n";
  225. pg_close($dbh); ////////////////////////////////////////////////////
  226. }
  227. ?>
  228.  
  229.  
  230. <p align="center"><font face="Verdana, Arial"><small>
  231. <small> Auteur <a title='Cliquer ici pour envoyer un e-mail' href='mailto:abir@iutv.univ-paris13.fr'>Hocine ABIR</a>
  232. </small></small></font></p>
  233.  
  234.  
  235. </body>
  236. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement