Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <style type="text/css">
- table.pretty {
- margin-left: auto;
- margin-right: auto;
- background: whitesmoke;
- border-collapse: collapse;
- }
- table.pretty th, table.pretty td {
- border: 1px silver solid;
- padding: 0.2em;
- }
- table.pretty th {
- background: gainsboro;
- text-align: left;
- }
- table.pretty caption { border:1px solid #5C443A;
- color:#5C443A;
- font-weight:bold;
- letter-spacing:15px;
- padding:6px 4px 8px 0px;
- text-align:center;
- text-transform:uppercase;
- }
- </style>
- </head>
- <body bgcolor="#FFFFAA" text="#000000">
- <?php
- error_reporting(0);
- $step='U';
- if (isset($_POST["step"]) ) $step= $_POST["step"];
- switch ($step)
- {
- // form auth
- case "U":
- echo "<form method=\"post\" action=\"ems.php\">";
- echo "<small><font face=\"Verdana,Arial\">\n";
- echo "<div> <table class=\"pretty\">";
- echo"<caption>Simple Application EMS</caption>";
- echo "<TR> <Th> DataBase ID</Th> <td><input type=\"text\" name=\"db\" /> </td> </TR>";
- echo "<TR> <Th> User ID</Th> <td><input type=\"text\" name=\"user\" /></td> </TR>";
- echo "<TR> <Th> Password</Th> <td> <input type=\"password\" name=\"passwd\" /> </td> </TR>";
- echo "<TR><TD></TD> <TD><button>Valider</button> </TD></TR>";
- echo "</table> </div>";
- echo" <input type=\"hidden\" value=\"F\" name=\"step\"> ";
- echo "</form>";
- break;
- // auth + form general
- case "F":
- if (isset($_POST["user"])) $user= $_POST["user"];
- else {
- exit("Unsupprted Operation ...");
- }
- $db=$user;
- if (isset($_POST["db"]) ) $db= $_POST["db"];
- if (isset($_POST["passwd"]) ) $passwd= $_POST["passwd"];
- // attempt a connection
- $dbh = pg_pconnect("host=aquabdd dbname=$db user=$user password=$passwd");
- if (!$dbh) {
- die("<H1>Echec connection : Bzzzt </H1>");
- } else{
- session_start();
- $_SESSION['passwd'] = $passwd;
- $_SESSION['user'] = $user;
- $_SESSION['db'] = $db;
- }
- break;
- // form general
- case "C" :
- session_start();
- if (isset($_SESSION["passwd"]))
- $passwd=$_SESSION['passwd'];
- else {
- exit("Unsupprted Operation ...");
- }
- $user= $_SESSION["user"];
- $db= $_SESSION["db"];
- // attempt a connection
- $dbh = pg_pconnect("host=aquabdd dbname=$db user=$user password=$passwd");
- if (!$dbh) {
- die("Error in connection ");
- }
- if (isset($_POST["query"])) $query= $_POST["query"];
- else {
- exit("Unsupprted Operation ...");
- }
- switch ($query)
- {
- case "insert":
- if ( (isset($_POST["Nom"])) && (!(empty($_POST["Nom"]))))
- $Nom= $_POST["Nom"];
- else $Nom=NULL;
- if ( (isset($_POST["Prenom"])) && (!(empty($_POST["Prenom"]))))
- $Prenom= $_POST["Prenom"];
- else $Matiere=NULL;
- if ( (isset($_POST["Matiere"])) && (!(empty($_POST["Matiere"]))))
- $Matiere= $_POST["Matiere"];
- else $Matiere=NULL;
- if ( (isset($_POST["Salle"])) && (!(empty($_POST["Salle"]))))
- $Salle= $_POST["Salle"];
- else $Salle=NULL;
- $sql = "select ems_ins('$Nom','$Prenom','$Matiere','$Salle')";
- $res = pg_query($dbh, $sql);
- if (!$res) {
- die("Error in SQL query: " . pg_last_error());
- }
- break;
- case "delete":
- if ( (isset($_POST["rad"])) && (!(empty($_POST["rad"])))) {
- $rad= $_POST["rad"];
- $sql = "select ems_del('$rad')";
- $res = pg_query($dbh, $sql);
- if (!$res) {
- die("Error in SQL query: " . pg_last_error());
- }
- }
- break;
- case "update":
- if ( (isset($_POST["rad"])) && (!(empty($_POST["rad"])))) {
- $rad= $_POST["rad"];
- $sql = "select * from ems where ctid='$rad'";
- $res = pg_query($dbh, $sql);
- if (!$res) {
- die("Error in SQL query: " . pg_last_error());
- }
- $rowc = pg_fetch_array($res);
- // echo "$rowc[0]*$rowc[1]*$rowc[2]*$rowc[3]*$rad\n";
- if ( (isset($_POST["Nom"])) && (!(empty($_POST["Nom"]))))
- $Nom= $_POST["Nom"];
- else $Nom=$rowc[0];
- if ( (isset($_POST["Prenom"])) && (!(empty($_POST["Prenom"]))))
- $Prenom= $_POST["Prenom"];
- else $Prenom=$rowc[1];
- if ( (isset($_POST["Matiere"])) && (!(empty($_POST["Matiere"]))))
- $Matiere= $_POST["Matiere"];
- else $Matiere=$rowc[2];
- if ( (isset($_POST["Salle"])) && (!(empty($_POST["Salle"]))))
- $Salle= $_POST["Salle"];
- else $Salle=$rowc[3];
- $sql = "select ems_upd('$Nom','$Prenom','$Matiere','$Salle','$rad')";
- $res = pg_query($dbh, $sql);
- if (!$res) {
- die("Error in SQL query: " . pg_last_error());
- }
- }
- break;
- default:
- echo "unsupported operation";
- break;
- }
- break;
- default:
- echo "unsupported operation";
- break;
- }
- // general form
- if (($step=='F') || ($step=='C')) {
- $sql = "SELECT nom,prenom,matiere,salle,ctid FROM ems";
- $res = pg_query($dbh, $sql);
- if (!$res) {
- die("Error in SQL query: " . pg_last_error());
- }
- echo "<form method=\"post\" action=\"ems.php\">";
- echo "<small><font face=\"Verdana,Arial\">\n";
- echo "<div> <table class=\"pretty\">";
- echo"<caption>Simple Application EMS</caption>";
- echo "<TR> <Th>OLD <img src=\"Arr_down.png\"/> </Th> <th> Nom</th> <th> Prenom";
- echo "</TH> <TH>Matiere</TH><TH> Salle</TH> </TR>";
- while ( $rowc = pg_fetch_array($res) ) {
- echo "<TR> <TD>";
- echo "<input type=\"radio\" name=\"rad\" value=\"". $rowc[4] . "\" title=\"tid=$rowc[4]\" />\n";
- echo "</TD> <TD>";
- echo $rowc[0];
- echo "</TD> <TD>";
- echo $rowc[1];
- echo "</TD> <TD>";
- echo $rowc[2];
- echo "</TD> <TD>";
- echo $rowc[3];
- echo "</TD> </TR>";
- echo "</font></small>\n";
- }
- echo "<TR> </TR>";
- echo "<TR><Th>NEW <img src=\"Arr_right.png\"/> </Th><TD><input type=\"text\" name=\"Nom\" size=10 /> </TD>\n";
- echo "<TD><input type=\"text\" name=\"Prenom\" size=10 /> </TD>\n";
- echo "<TD><input type=\"text\" name=\"Matiere\" size=10 /> </TD>\n";
- echo "<TD><input type=\"text\" name=\"Salle\" size=5/> </TD></TR>\n";
- echo" <input type=\"hidden\" value=\"C\" name=\"step\"> \n ";
- echo "<TR> </TR>";
- echo "<TR><TD></TD>";
- echo "<TD><button NAME=\"query\" TYPE=\"submit\" value=\"insert\" title=\"Entrer le tuple a inserer dans la ligne NEW et Cliquer\">insert</button> </TD>";
- echo "<TD><button NAME=\"query\" TYPE=\"submit\" value=\"delete\" title=\"Selectionner le tuple a supprimer dans la colonne OLD et Cliquer\">delete</button> </TD>";
- 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>";
- echo "<TD><button TYPE=RESET title=\"Annuler la selection ou saisie\">reset</button> </TD></TR>";
- echo "</table> </div>";
- echo "</form>";
- pg_free_result($res);
- echo "<p align=\"center\"><font face=\"Verdana, Arial\"><small>\n";
- echo "<small>Connection info -> User ID : $user -- Database ID: $db\n";
- echo "</small></small></font></p>\n";
- pg_close($dbh); ////////////////////////////////////////////////////
- }
- ?>
- <p align="center"><font face="Verdana, Arial"><small>
- <small> Auteur <a title='Cliquer ici pour envoyer un e-mail' href='mailto:abir@iutv.univ-paris13.fr'>Hocine ABIR</a>
- </small></small></font></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement