Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head><title>Test für Raumübersicht</title></head>
- <body>
- <h1>Grafische Raumansicht: Test</h1>
- <p><em>Hinweis: Testversion, nicht praktisch zu nutzen.</em></p>
- <?php
- define("MA_SELF", "sis_raumansicht.php");
- /*
- * DB Structure
- *
- * table: pc_rooms
- *
- * ID | name | width | height
- *
- * table: pcPositions
- *
- * ID | name | room (int) | int posX | int posY
- *
- */
- // Auf gehts franzi...
- mysql_connect("localhost", "root", "");
- if(!mysql_select_db("sis_tests") || isset($_GET["manual_setup"])) {
- // Setup
- $e = 0;
- $e += mysql_query("CREATE DATABASE sis_tests");
- $e += mysql_select_db("sis_tests");
- $e += mysql_query(
- "CREATE TABLE pc_rooms (".
- " id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,".
- " name VARCHAR (32) NOT NULL,".
- " width INT NOT NULL,".
- " height INT NOT NULL".
- ")"
- );
- $e += mysql_query(
- "CREATE TABLE IF NOT EXISTS pc_positions (".
- " id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,".
- " name VARCHAR (32) NOT NULL,".
- " room INT NOT NULL,".
- " posX INT NOT NULL,".
- " posY INT NOT NULL".
- ")"
- );
- if($e < 2) {
- echo "<p>".mysql_error()."</p>";
- } else {
- echo "<p>Setup ausgeführt. Bitte neuladen.</p>";
- }
- return;
- }
- if(isset($_GET["a"])) {
- $a = $_GET["a"];
- if($a == "create_room") {
- $width = 2; $height = 2;
- if($_POST["size"] != "") {
- $pos = strpos($_POST["size"], "x");
- if($pos === false) {
- $pos = strpos($_POST["size"], "*");
- if($pos === false) {
- echo "<p>Syntaxfehler.</p>";
- return;
- }
- }
- $width = substr($_POST["size"], 0, $pos);
- $height = substr($_POST["size"], $pos + 1);
- }
- if(mysql_query("INSERT INTO pc_rooms (name, width, height) VALUES ('".mysql_real_escape_string($_POST["name"])."', ".(int)$width.", ".(int)$height.")")) {
- echo "<p>done. Nicht neuladen.</p>";
- } else {
- echo "<p>".mysql_error()."</p>";
- }
- } else if($a == "view_room") {
- $size = mysql_fetch_assoc(mysql_query("SELECT width, height FROM pc_rooms WHERE id = ".(int)$_GET["d1"]));
- $gitter = array($size["height"]); // YX notation
- for($i = 0; $i < $size["height"]; $i++) {
- $gitter[$i] = array($size["width"]);
- for($j = 0; $j < $size["width"]; $j++) {
- $gitter[$i][$j] = false;
- }
- }
- $link = mysql_query("SELECT id, name, posX, posY FROM pc_positions WHERE room = ".(int)$_GET["d1"]);
- if($link) {
- while(($data = mysql_fetch_assoc($link)) !== false) {
- $gitter[$data["posY"]][$data["posY"]] = array($data["id"], $data["name"]);
- }
- } else {
- echo "<p>".mysql_error()."</p>";
- return;
- }
- echo "<table border=\"1\">";
- foreach($gitter as $y) {
- echo "<tr>";
- foreach($y as $x) {
- echo "<td>";
- if($x === false) {
- echo "<a href=\"".MA_SELF."?a=change&d1=".(int)$_GET["d1"]."&\">#</a>"; // TODO d1 to helper variable... hier parameter x und y koordinate angeben damit das script auch weiß, welcher slot bearbeitet wird.
- } else {
- echo $x["name"];
- }
- echo "</td>";
- }
- echo "</tr>";
- }
- echo "</table>";
- echo "<form method=\"post\" action=\"".MA_SELF."?a=enlarge\">";
- echo "<input type=\"hidden\" name=\"id\" id=\"id\" value=\"".(int)$_GET["d1"]."\" />";
- echo "X-Vergrößern: <input type=\"text\" name=\"x\" id=\"x\" value=\"0\" />";
- echo "Y-Vergrößern: <input type=\"text\" name=\"y\" id=\"y\" value=\"0\" />";
- echo "<input type=\"submit\" value=\"Anwenden\" />";
- echo "</form>";
- } else if($a == "enlarge") {
- $cSize = mysql_fetch_assoc(mysql_query("SELECT width, height FROM pc_rooms WHERE id = ".(int)$_POST["id"]));
- if(mysql_query("UPDATE pc_rooms SET width = ".($cSize["width"] + (int)$_POST["x"]).", height = ".($cSize["height"] + (int)$_POST["y"]." WHERE id = ".(int)$_POST["id"]))) {
- echo "<p>Nicht neuladen.</p>"; // TODO AUTO-UPDATE PAGE of course
- } else {
- echo "<p>".mysql_error()."</p>";
- }
- } else if($a == "change") {
- echo "TODO IMPLEMENT";
- } else {
- echo "N/A";
- }
- } else {
- $link = mysql_query("SELECT id, name FROM pc_rooms");
- if($link) {
- echo "<p>Alle Räume:</p><ul>";
- while(($data = mysql_fetch_assoc($link)) !== false) {
- echo "<li><a href=\"".MA_SELF."?a=view_room&d1=".$data["id"]."\">".$data["name"]."</a></li>";
- }
- echo "</ul>";
- echo "<form method=\"post\" action=\"".MA_SELF."?a=create_room\">";
- echo "<div>";
- echo "Name: <input type=\"text\" name=\"name\" id=\"name\" /><br />";
- echo "~A x[m]*y[m]: <input type=\"text\" name=\"size\" id=\"size\" /><br />";
- echo "<input type=\"submit\" value=\"Hinzufügen\" />";
- echo "</div>";
- echo "</form>";
- } else {
- echo "<p>".mysql_error()."</p>";
- return;
- }
- }
- mysql_close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement