Linux-Fan

SIS Computerraum Dev Sample

Feb 7th, 2012
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <head><title>Test für Raumübersicht</title></head>
  3.     <body>
  4.         <h1>Grafische Raumansicht: Test</h1>
  5.         <p><em>Hinweis: Testversion, nicht praktisch zu nutzen.</em></p>
  6. <?php
  7. define("MA_SELF", "sis_raumansicht.php");
  8.  
  9. /*
  10.  * DB Structure
  11.  *
  12.  * table: pc_rooms
  13.  *
  14.  * ID | name | width | height
  15.  *
  16.  * table: pcPositions
  17.  *
  18.  * ID | name | room (int) | int posX | int posY
  19.  *
  20.  */
  21. // Auf gehts franzi...
  22. mysql_connect("localhost", "root", "");
  23. if(!mysql_select_db("sis_tests") || isset($_GET["manual_setup"])) {
  24.     // Setup
  25.     $e = 0;
  26.     $e += mysql_query("CREATE DATABASE sis_tests");
  27.     $e += mysql_select_db("sis_tests");
  28.     $e += mysql_query(
  29.         "CREATE TABLE pc_rooms (".
  30.         "  id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,".
  31.         "  name VARCHAR (32) NOT NULL,".
  32.         "  width INT NOT NULL,".
  33.         "  height INT NOT NULL".
  34.         ")"
  35.     );
  36.     $e += mysql_query(
  37.         "CREATE TABLE IF NOT EXISTS pc_positions (".
  38.         "  id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,".
  39.         "  name VARCHAR (32) NOT NULL,".
  40.         "  room INT NOT NULL,".
  41.         "  posX INT NOT NULL,".
  42.         "  posY INT NOT NULL".
  43.         ")"
  44.     );
  45.     if($e < 2) {
  46.         echo "<p>".mysql_error()."</p>";
  47.     } else {
  48.         echo "<p>Setup ausgeführt. Bitte neuladen.</p>";
  49.     }
  50.     return;
  51. }
  52.  
  53. if(isset($_GET["a"])) {
  54.     $a = $_GET["a"];
  55.     if($a == "create_room") {
  56.         $width = 2; $height = 2;
  57.         if($_POST["size"] != "") {
  58.             $pos = strpos($_POST["size"], "x");
  59.             if($pos === false) {
  60.                 $pos = strpos($_POST["size"], "*");
  61.                 if($pos === false) {
  62.                     echo "<p>Syntaxfehler.</p>";
  63.                     return;
  64.                 }
  65.             }
  66.             $width = substr($_POST["size"], 0, $pos);
  67.             $height = substr($_POST["size"], $pos + 1);
  68.         }
  69.         if(mysql_query("INSERT INTO pc_rooms (name, width, height) VALUES ('".mysql_real_escape_string($_POST["name"])."', ".(int)$width.", ".(int)$height.")")) {
  70.             echo "<p>done. Nicht neuladen.</p>";
  71.         } else {
  72.             echo "<p>".mysql_error()."</p>";
  73.         }
  74.     } else if($a == "view_room") {
  75.         $size = mysql_fetch_assoc(mysql_query("SELECT width, height FROM pc_rooms WHERE id = ".(int)$_GET["d1"]));
  76.         $gitter = array($size["height"]); // YX notation
  77.         for($i = 0; $i < $size["height"]; $i++) {
  78.             $gitter[$i] = array($size["width"]);
  79.             for($j = 0; $j < $size["width"]; $j++) {
  80.                 $gitter[$i][$j] = false;
  81.             }
  82.         }
  83.        
  84.         $link = mysql_query("SELECT id, name, posX, posY FROM pc_positions WHERE room = ".(int)$_GET["d1"]);
  85.         if($link) {
  86.             while(($data = mysql_fetch_assoc($link)) !== false) {
  87.                 $gitter[$data["posY"]][$data["posY"]] = array($data["id"], $data["name"]);
  88.             }
  89.         } else {
  90.             echo "<p>".mysql_error()."</p>";
  91.             return;
  92.         }
  93.  
  94.         echo "<table border=\"1\">";
  95.         foreach($gitter as $y) {
  96.             echo "<tr>";
  97.             foreach($y as $x) {
  98.                 echo "<td>";
  99.                 if($x === false) {
  100.                     echo "<a href=\"".MA_SELF."?a=change&amp;d1=".(int)$_GET["d1"]."&amp;\">#</a>"; // TODO d1 to helper variable... hier parameter x und y koordinate angeben damit das script auch weiß, welcher slot bearbeitet wird.
  101.                 } else {
  102.                     echo $x["name"];
  103.                 }
  104.                 echo "</td>";
  105.             }
  106.             echo "</tr>";
  107.         }  
  108.         echo "</table>";
  109.         echo "<form method=\"post\" action=\"".MA_SELF."?a=enlarge\">";
  110.         echo "<input type=\"hidden\" name=\"id\" id=\"id\" value=\"".(int)$_GET["d1"]."\" />";
  111.         echo "X-Vergrößern: <input type=\"text\" name=\"x\" id=\"x\" value=\"0\" />";
  112.         echo "Y-Vergrößern: <input type=\"text\" name=\"y\" id=\"y\" value=\"0\" />";
  113.         echo "<input type=\"submit\" value=\"Anwenden\" />";
  114.         echo "</form>";
  115.     } else if($a == "enlarge") {
  116.         $cSize = mysql_fetch_assoc(mysql_query("SELECT width, height FROM pc_rooms WHERE id = ".(int)$_POST["id"]));
  117.         if(mysql_query("UPDATE pc_rooms SET width = ".($cSize["width"] + (int)$_POST["x"]).", height = ".($cSize["height"] + (int)$_POST["y"]." WHERE id = ".(int)$_POST["id"]))) {
  118.             echo "<p>Nicht neuladen.</p>"; // TODO AUTO-UPDATE PAGE of course
  119.         } else {
  120.             echo "<p>".mysql_error()."</p>";
  121.         }
  122.     } else if($a == "change") {
  123.         echo "TODO IMPLEMENT";
  124.     } else {
  125.         echo "N/A";
  126.     }
  127. } else {
  128.     $link = mysql_query("SELECT id, name FROM pc_rooms");
  129.     if($link) {
  130.         echo "<p>Alle Räume:</p><ul>";
  131.         while(($data = mysql_fetch_assoc($link)) !== false) {
  132.             echo "<li><a href=\"".MA_SELF."?a=view_room&d1=".$data["id"]."\">".$data["name"]."</a></li>";
  133.         }
  134.         echo "</ul>";
  135.         echo "<form method=\"post\" action=\"".MA_SELF."?a=create_room\">";
  136.         echo "<div>";
  137.         echo "Name: <input type=\"text\" name=\"name\" id=\"name\" /><br />";
  138.         echo "~A x[m]*y[m]: <input type=\"text\" name=\"size\" id=\"size\" /><br />";
  139.         echo "<input type=\"submit\" value=\"Hinzufügen\" />";
  140.         echo "</div>";
  141.         echo "</form>";
  142.     } else {
  143.         echo "<p>".mysql_error()."</p>";
  144.         return;
  145.     }
  146. }
  147. mysql_close();
  148. ?>
  149.     </body>
  150. </html>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×