function generateUpdateQuery() { $username = $_SESSION['sess_user']; $columnNames = getColumnNames("Players"); $updatedFields = array(); $updatedFieldColumns = array(); for ($i = 0; $i < count($columnNames); $i++) { if (isset($_POST[$columnNames[$i]])) { $value = trim($_POST[$columnNames[$i]]); if ($value != "") { array_push($updatedFields, $_POST[$columnNames[$i]]); array_push($updatedFieldColumns, $columnNames[$i]); } } } //Update.. $query = "UPDATE players SET "; for ($i = 0; $i < count($updatedFields); $i++) { $query .= "{$updatedFieldColumns[$i]} = " . "'" . $updatedFields[$i] . "'"; if ($i + 1 < count($updatedFields)) { $query .= ", "; } } $query .= " WHERE Email = '{$username}'"; //echo $query; return $query; }
function createNpc() { $trait_table = "npc_traits"; $table = "npc"; $columns = getColumnNames($table); if (empty($_POST["sex"])) { $_POST["sex"] = getGender(); } if (empty($_POST["weight"])) { $_POST["weight"] = getWeight(); } if (empty($_POST["feet"]) || empty($_POST["inches"])) { $_POST["height"] = getHeight(); } else { $_POST["height"] = $_POST["feet"] * 12 + $_POST["inches"]; } if (empty($_POST["age"])) { $_POST["age"] = getAge(); } if (empty($_POST["first_name"])) { $_POST["first_name"] = getName(); } // will add the remaining traits not already added foreach ($columns as $column) { if (empty($_POST[$column])) { $_POST[$column] = getTrait($trait_table, $column); } } }
function createDataFromPost($table) { $columns = getColumnNames($table); $data = []; foreach ($columns as $column) { $data[$column] = $_POST[$column]; } return $data; }
function getFields($db, $table) { $fieldsOrigen = getColumnNames($db, $table, 'main'); $fieldsDestino = getColumnNames($db, $table, 'destino'); if (isset($fieldsOrigen) && isset($fieldsDestino)) { $valRet = array_intersect($fieldsOrigen, $fieldsDestino); return implode(",", $valRet); } return ''; }
function createDungeon() { $trait_table = "dungeon_traits"; $table = "dungeon"; $columns = getColumnNames($table); foreach ($columns as $column) { if (empty($_POST[$column])) { $_POST[$column] = getTrait($trait_table, $column); } } }
function createDataFromPost($table) { $columns = getColumnNames($table); $restrictedColumns = ['approved', 'date_created']; if (empty($_POST['owner_id'])) { array_push($restrictedColumns, "owner_id"); } $data = []; foreach ($columns as $column) { if (!in_array($column, $restrictedColumns)) { $data[$column] = $_POST[$column]; } } return $data; }
function createSettelment() { $trait_table = "settlement_traits"; $table = "settlement"; $columns = getColumnNames($table); if (empty($_POST['size'])) { $i = rand(0, 2); if ($i == 0) { $size = "S"; } else { if ($i == 1) { $size = "M"; } else { $s = "L"; } } $_POST['size'] = $size; } if (empty($_POST['population'])) { $size = $_POST['size']; if ($size == "S") { $pop = purebell(20, 75, 5); } else { if ($size == "M") { $pop = purebell(76, 300, 10); } else { $pop = purebell(300, 1500, 100); } } $_POST['population'] = $pop; } // Pick a mayor if (empty($_POST['ruler_id'])) { createNpc(); $table = "npc"; $_POST['ruler_id'] = insertFromPostWithIdReturn($table); } foreach ($columns as $column) { if (empty($_POST[$column])) { $_POST[$column] = getTrait($trait_table, $column); } } }
function createVillain() { $trait_table = "villain_trait"; $table = "villain"; $columns = getColumnNames($table); if (empty($_POST['npc_id'])) { createNpc(); $c_table = "npc"; $_POST['npc_id'] = insertFromPostWithIdReturn($c_table); } foreach ($columns as $column) { if (empty($_POST[$column])) { $c = split("_", $column); if (count($c) == 2) { $type = $c[0]; $trait = getFullTrait($trait_table, $type); $_POST[$type . "_type"] = $trait['kind']; $_POST[$type . "_description"] = $trait['description']; } else { $_POST[$column] = getTrait($trait_table, $column); } } } }
<link rel="shortcut icon" href="http://grm.execon.pl/devel/images/favicons/favicon.ico"> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <?php require 'logic.php'; require 'tables_dict.php'; if (isset($_POST['sequence_step'])) { $sequence_step = $_POST['sequence_step']; } else { $sequence_step = 1; } $current_table = $tables_dict[$sequence_step]; $table_col_count = getColumnCount($current_table); $names = getColumnNames($current_table); $last_id = getNextId($current_table, $names[0]); $stored_id_map = array(); if (isset($_POST['iterator'])) { rebuildStoredIdMap(); } echo "\n\t\t\t<form action=\"connector.php\" method=\"post\">\n\t\t\t\t<table>"; for ($i = 0; $i < $table_col_count; $i++) { if ($i == 0) { $column_name = getColumnName($current_table, $i); $label = strval($column_name); $current_field = $i + 1; $stored_id_map[$column_name] = $last_id; echo "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>{$label}</td>\n\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t<input type=\"text\" name=\"field_" . $i . "\" value=\"" . $last_id . "\" />\n\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"current_field\" value=\"" . $current_field . "\" />\n\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"current_table\" value=\"" . $current_table . "\" />\n\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"sequence_step\" value=\"" . $sequence_step . "\" />\n\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>"; } else { $column_name = getColumnName($current_table, $i);
function getAllColumnNames($tables) { $output = array(); foreach ($tables as $table) { $columNames = getColumnNames($table); foreach ($columNames as $name) { array_push($output, $name); } $output = array_unique($output); } return $output; }
function displayMessage() { $conn = connectToDatabase(); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $table = $_POST['table']; $id = $_POST['id']; // Send the update query, check to see if the update was successful. $columnNames = getColumnNames($table); $columns = array(); // Array that holds the column names of the values to be inserted. $values = array(); // Array that holds the values to be inserted. for ($i = 1; $i < count($columnNames); $i++) { if (isset($_POST[$columnNames[$i]])) { $value = trim($_POST[$columnNames[$i]]); if ($value != "") { array_push($columns, $columnNames[$i]); array_push($values, $value); } } } $query = "UPDATE {$table} SET "; if (count($columns) == count($values)) { for ($i = 0; $i < count($values); $i++) { $query .= "{$columns[$i]} = " . "'" . $values[$i] . "'"; if ($i + 1 < count($columns)) { $query .= ", "; } } } $query .= " WHERE " . $_POST['id_column'] . " = " . $_POST['id']; //echo $query; if (mysqli_query($conn, $query) == TRUE and count($values) > 0) { $result = retrieveRow($table, $id); echo "<p>The " . $_POST['table'] . " has been updated to</p>"; echo "<table class='updated'>"; if (count($columnNames) > 0 and $result->num_rows > 0) { while ($row = $result->fetch_assoc()) { if (count($row) == count($columnNames)) { for ($i = 0; $i < count($row); $i++) { echo "<tr>"; echo "<td><b>" . $columnNames[$i] . "</b></td>"; echo "<td>" . $row[$columnNames[$i]] . "</td>"; echo "</tr>"; } } } } else { echo "0 results"; } echo "</table>"; echo "<form action='runAudit.php' method='post'>\n <input type='hidden' name='bowlingAudit' value='" . $_POST['table'] . "'>\n <input type='submit' value='Back to table'>\n </form>"; } else { if (count($values) < 1) { $error = "<br>No fields have been updated."; echo $error; echo "<br><br><form action='runAudit.php' method='post'>\n <input type='hidden' name='bowlingAudit' value='" . $_POST['table'] . "'>\n <input type='submit' value='Back to table'>\n </form>"; } else { $error = "Unable to update.\n\nError: " . $conn->error; //echo $error; $error = json_encode($error); echo "\n <script type='text/javascript'>\n alert({$error});\n history.go(-1);\n </script>"; } } $conn->close(); }
function displayMessage() { $conn = connectToDatabase(); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $table = $_POST['table']; // Send the update query, check to see if the update was successful. $columnNames = getColumnNames($table); //INSERT INTO bowling.Ball (Color, Weight, Size) VALUES ('Black', 7, 2); $query = "INSERT INTO bowling.{$table} ("; $columns = array(); // Array that holds column names of the values to be inserted $values = array(); // Array that holds values to be inserted for ($i = 1; $i < count($columnNames); $i++) { if ($columnNames[$i] == "Date_Added" || $columnNames[$i] == "Last_Date_Modified" || $columnNames[$i] == "Date_Joined" || $columnNames[$i] == "Date_Deleted") { continue; } else { if ($_POST[$columnNames[$i]] == "") { continue; } else { array_push($columns, $columnNames[$i]); array_push($values, $_POST[$columnNames[$i]]); } } } for ($i = 0; $i < count($columns); $i++) { $query .= "{$columns[$i]}"; if ($i + 1 < count($columns)) { $query .= ", "; } } $query .= ") VALUES ("; for ($i = 0; $i < count($values); $i++) { $query .= "'" . $values[$i] . "'"; if ($i + 1 < count($values)) { $query .= ", "; } } $query .= ");"; //echo $query; if (mysqli_query($conn, $query) == TRUE) { $id = $conn->insert_id; $result = retrieveRow($table, $id, $columnNames[0]); echo "<p>A new " . $_POST['table'] . " has been added with the following values </p>"; echo "<table>"; if (count($columnNames) > 0 and $result->num_rows > 0) { while ($row = $result->fetch_assoc()) { if (count($row) == count($columnNames)) { for ($i = 0; $i < count($row); $i++) { echo "<tr>"; echo "<td><b>" . $columnNames[$i] . "</b></td>"; echo "<td>" . $row[$columnNames[$i]] . "</td>"; echo "</tr>"; } } } } else { echo "0 results"; } echo "</table>"; echo "<form action='runAudit.php' method='post'>\n <input type='hidden' name='bowlingAudit' value='" . $_POST['table'] . "'>\n <input type='submit' value='Back to table'>\n </form>"; } else { $error = "<br>Unable to update. Error: " . $conn->error; echo $error . "<br><br>"; echo "<form action='runAudit.php' method='post'>\n <input type='hidden' name='bowlingAudit' value='" . $_POST['table'] . "'>\n <input type='submit' value='Back to table'>\n </form>"; } $conn->close(); }
function columnsToString($table) { $columns = getColumnNames($table); $string = "("; foreach ($columns as $column) { $string .= $column . ", "; } return substr($string, 0, strlen($string) - 2) . ")"; }