<?php
@package@version$correct_password_assoc_array$page_id$db_hostname$db_username$db_password$db_fields
require_once (dirname(__FILE__) . "/CRUD-functions.php");
h1
$db_fields = array(
array("ID", "id", "int", "INT NOT NULL PRIMARY KEY","",""), array("Name", "name", "text", "VARCHAR(255) NOT NULL", "",""), array("URL Yellow", "url_yellow", "url", "VARCHAR(255) NOT NULL", "",""), array("Phone#", "phone", "tel", "VARCHAR(255) NOT NULL", "",""), array("URL Address", "url_address", "url", "VARCHAR(255) NOT NULL", "",""), array("Email Address", "email", "email", "VARCHAR(255) NOT NULL", "",""), array("Address", "address", "text", "VARCHAR(255) NOT NULL", "",""), array("Categories", "categories", "text", "VARCHAR(255) NOT NULL", "",""), array("Time fixed", "time_fixed", "time", "TIME NOT NULL", "","") );
$db_hostname = "localhost";
$db_database = "wordpress";
$db_username = "root";
$db_password = "acadta64";
$db_database$db_username$db_password
define(ENGLISH_NAME,0);
define(PHP_NAME,1);
define(TYPE,2);
define(MYSQL_INIT,3);
define(SEARCH_FIELDS,4);
define(VALUE_FIELDS,5);
define(DATE_LENGTH,10);
define(DATE_TIME_LENGTH,19);
define(TIME_LENGTH,8);
$offset = "";
$limit = "";
$order_by = "";
$like = "";
$username = "";
$password = "";
h1
add_action('the_content', 'crud');
function crud($arg)
{
global $db_fields;
global $page_id,$offset,$limit,$order_by,$like,$username,$password;
global $db_hostname, $db_username, $db_password, $db_database;
echo $arg;
----------------------------------------------------------------- $correct_password_assoc_array = array("admin" => sha1('abc'));
----------------------------------------------------------------- $page_id = "";
if (isset($_REQUEST['page_id']))
{
$page_id = $_REQUEST['page_id'];
}
$page_id h1 ----------------------------------------------------------------- if ($page_id == 10)
{
srand(((int)((double)microtime()*1000003)));
assertmy_is_string assertmy_is_string assertmy_is_string h1 for ($i = 0; $i < array_length($db_fields); $i++)
{
if (($db_fields[$i][TYPE] == "datetime") or ($db_fields[$i][TYPE] == "date") or ($db_fields[$i][TYPE] == "time"))
{
$db_fields[$i][SEARCH_FIELDS] = array("","");
$db_fields[$i][VALUE_FIELDS] = array("","");
assert(array_length($db_fields[$i][SEARCH_FIELDS]) == 2);
assert(array_length($db_fields[$i][VALUE_FIELDS]) == 2);
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
assert(my_is_string($db_fields[$i][VALUE_FIELDS][0]));
assert(my_is_string($db_fields[$i][VALUE_FIELDS][1]));
$db_search_fields $db_value_fields }
------------------------------------------------------------------------------------------ }
assertarray_length$db_fieldsarray_length$db_search_fields assertarray_length$db_fieldsarray_length$db_value_fields $hidden_search_fields = "";
$href_search_fields = "";
$link = mysqli_connect($db_hostname,$db_username,$db_password);
if (!$link)
{
echo h1error('Unable to connect to the database server');
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
echo h1error('Unable to set database connection encoding.');
exit();
}
$create_table_query = "CREATE TABLE clients_table (\n";
for ($i = 0; $i<array_length($db_fields); $i++)
{
if ($i != 0)
{
$create_table_query .= ", ";
}
$create_table_query .= $db_fields[$i][PHP_NAME] . " " . $db_fields[$i][MYSQL_INIT] . "\n";
}
$create_table_query .= ") DEFAULT CHARACTER SET utf8;\n";
$here_is_the_sql_query = "<span class=\"big-black\">Here is the SQL query:</span><br>\n";
h1 if (!mysqli_select_db($link, $db_database))
{
echo h1error("Unable to locate the \"$db_database\" database.");
$result = mysqli_query($link,"create database $db_database;");
if (!$result)
{
echo h1error("Unable to create the \"$db_database\" databse.");
echo $here_is_the_sql_query . "<br>\n";
echo pre("create database $db_database;");
exit();
}
if (!mysqli_select_db($link, $db_database))
{
echo h1error("Unable to locate the \"$db_database\" database.");
}
$result = mysqli_query($link,$create_table_query);
if (!$result)
{
echo h1error("Unable to create the clients_table\n");
exit();
}
else
{
echo h1ok("Successfully created the clients_table\n");
echo $here_is_the_sql_query . "<br>\n";
echo pre($create_table_query);
}
}
if (!mysqli_query($link,"SELECT * FROM clients_table;\n"))
{
if (!mysqli_query($link,$create_table_query))
{
echo h1error("Unable to create the clients_table\n");
echo $here_is_the_sql_query . "<br>\n";
echo pre($create_table_query);
exit();
}
else
{
echo h1ok("Successfully created the clients_table\n");
echo $here_is_the_sql_query . "<br>\n";
echo pre($create_table_query);
}
}
$action = "";
if (isset($_REQUEST['action']))
{
$action = $_REQUEST['action'];
}
$offset = "";
if (isset($_REQUEST['offset']))
{
$offset = $_REQUEST['offset'];
}
$limit = "";
if (isset($_REQUEST['limit']))
{
$limit = $_REQUEST['limit'];
}
$username = "";
if (isset($_REQUEST['username']))
{
$username = $_REQUEST['username'];
}
$encoded = "";
if (isset($_REQUEST['encoded']))
{
$encoded = $_REQUEST['encoded'];
}
$password = "";
if (isset($_REQUEST['password']))
{
$password = $_REQUEST['password'];
}
if (!$encoded)
{
$password = sha1($password);
$encoded = true;
}
if ($username != "")
{
$correct_password = $correct_password_assoc_array[$username];
}
else
{
$correct_password = "";
}
$like = "";
if (isset($_REQUEST['like']))
{
$like = $_REQUEST['like'];
}
$order_by = "";
if (isset($_REQUEST['order-by']))
{
$order_by = $_REQUEST['order-by'];
}
$asc = "";
if (isset($_REQUEST['asc']))
{
$asc = $_REQUEST['asc'];
}
if ($offset == "")
{
$offset = 0;
}
if ($limit == "")
{
$limit = 10;
}
if ($action == "")
{
$action = "browser";
}
$like_2 = $like;
if ($like != "")
{
$like_2 = $like;
if ($like_2[0] != '%')
{
$like_2 = "%" . $like_2;
}
if ($like_2[strlen($like_2) - 1] != '%')
{
$like_2 = $like_2 . "%";
}
}
h1 h1array_lengtharray_length$db_fields for ($i = 0; $i < array_length($db_fields); $i++)
{
h1$db_fields if ($db_fields[$i][TYPE] == "datetime")
{
assert(isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_min"]));
$db_fields[$i][SEARCH_FIELDS][0] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_min"];
assert(isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"]));
$db_fields[$i][SEARCH_FIELDS][1] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"];
h1$db_fields h1$db_fields h1$_REQUEST h1$_REQUEST }
elseif ($db_fields[$i][TYPE] == "date")
{
assert(isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_min"]));
$db_fields[$i][SEARCH_FIELDS][0] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_min"];
assert(isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"]));
$db_fields[$i][SEARCH_FIELDS][1] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"];
$db_fields assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
assert(my_is_string($db_fields[$i][VALUE_FIELDS][0]));
assert(my_is_string($db_fields[$i][VALUE_FIELDS][1]));
}
elseif ($db_fields[$i][TYPE] == "time")
{
if (isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_min"]))
{
$db_fields[$i][SEARCH_FIELDS][0] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_min"];
}
$db_fields if (isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"]))
{
$db_fields[$i][SEARCH_FIELDS][1] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"];
}
h1$db_fields $db_fields }
else
{
assert assert(($db_fields[$i][TYPE] != "datetime") and ($db_fields[$i][TYPE] != "date") and ($db_fields[$i][TYPE] != "time"));
if (isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME]]))
{
$db_fields[$i][SEARCH_FIELDS] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME]];
}
$db_fields assert(my_is_string($db_fields[$i][SEARCH_FIELDS]));
h1$db_fields }
}
h1 array_length$db_fields h1$db_fields $db_fields h1$db_fields h1$db_fields $db_fields h1$db_fields h1$db_fields assert$db_fields assert$db_fields assertmy_is_string$db_fields h1$db_fields $search_id$_REQUEST $search_name$_REQUEST $search_url_yellow$_REQUEST $search_Phone$_REQUEST $search_url_address$_REQUEST $search_email$_REQUEST $search_address$_REQUEST $search_Categories$_REQUEST $where_clause = "WHERE (";
$first = true;
for ($i = 0; $i < array_length($db_fields); $i++)
{
$date_or_time_or_datetime = false;
---------------------------------------------------------- if ($db_fields[$i][TYPE] == "datetime")
{
$date_or_time_or_datetime= true;
$db_fields[$i][SEARCH_FIELDS][0] = slashes_to_minus_datetime($db_fields[$i][SEARCH_FIELDS][0]);
$db_fields[$i][SEARCH_FIELDS][1] = slashes_to_minus_datetime($db_fields[$i][SEARCH_FIELDS][1]);
}
elseif ($db_fields[$i][TYPE] == "date")
{
$date_or_time_or_datetime = true;
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
$db_fields[$i][SEARCH_FIELDS][0] = slashes_to_minus_date($db_fields[$i][SEARCH_FIELDS][0]);
$db_fields[$i][SEARCH_FIELDS][1] = slashes_to_minus_date($db_fields[$i][SEARCH_FIELDS][1]);
h1$db_fields h1$db_fields }
elseif ($db_fields[$i][TYPE] == "time")
{
$date_or_time_or_datetime = true;
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
}
if ($date_or_time_or_datetime)
{
$len0 = strlen($db_fields[$i][SEARCH_FIELDS][0]);
$len1 = strlen($db_fields[$i][SEARCH_FIELDS][1]);
if (($len0 == TIME_LENGTH) and ($len1 == TIME_LENGTH))
{
if (!$first)
{
$where_clause .= " OR ";
}
if ($like == "")
{
$like = "1";
}
$first = false;
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " >= '" . $db_fields[$i][SEARCH_FIELDS][0] . "' ";
h1$db_fields$db_fields $where_clause .= "AND ";
$where_clause .= $db_fields[$i][PHP_NAME] . " <= '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n";
h1$db_fields$db_fields assert(false);
}
elseif ($len0 == TIME_LENGTH)
{
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
if ($like == "")
{
$like = "1";
}
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " = '" . $db_fields[$i][SEARCH_FIELDS][0] . "')\n";
}
elseif ($len1 == TIME_LENGTH)
{
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
if ($like == "")
{
$like = "1";
}
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " = '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n";
}
elseif (($len0 == DATE_LENGTH) and ($len1 == DATE_LENGTH))
{
if (!$first)
{
$where_clause .= " OR ";
}
if ($like == "")
{
$like = "1";
}
$first = false;
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " >= '" . $db_fields[$i][SEARCH_FIELDS][0] . "' ";
$where_clause .= "AND ";
$where_clause .= $db_fields[$i][PHP_NAME] . " <= '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n";
}
elseif ($len0 == DATE_LENGTH)
{
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
if ($like == "")
{
$like = "1";
}
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " = '" . $db_fields[$i][SEARCH_FIELDS][0] . "')\n";
}
elseif ($len1 == DATE_LENGTH)
{
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
if ($like == "")
{
$like = "1";
}
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " = '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n";
}
elseif (($len0 == DATE_TIME_LENGTH) and ($len1 == DATE_TIME_LENGTH))
{
if (!$first)
{
$where_clause .= " OR ";
}
if ($like == "")
{
$like = "1";
}
$first = false;
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " >= '" . $db_fields[$i][SEARCH_FIELDS][0] . "' ";
$where_clause .= "AND ";
$where_clause .= $db_fields[$i][PHP_NAME] . " <= '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n";
}
elseif ($len0 == DATE_TIME_LENGTH)
{
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
if ($like == "")
{
$like = "1";
}
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " = '" . $db_fields[$i][SEARCH_FIELDS][0] . "')\n";
}
elseif ($len1 == DATE_TIME_LENGTH)
{
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
if ($like == "")
{
$like = "1";
}
$where_clause .= "(" . $db_fields[$i][PHP_NAME] . " = '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n";
}
}
elseif ($db_fields[$i][SEARCH_FIELDS] == true)
{
if (($like_2 != "") and ($like_2 != "%1%"))
{
assert h1 assert($db_fields[$i][TYPE] != "date");
assert($db_fields[$i][TYPE] != "time");
assert($db_fields[$i][TYPE] != "datetime");
if (!$first)
{
$where_clause .= " OR ";
}
$first = false;
$where_clause .= $db_fields[$i][PHP_NAME] . " LIKE \"$like_2\"\n";
h1$where_clause assert }
}
}
h1$where_clause if ($first)
{
$where_clause = "";
assert }
else
{
$where_clause .= ")\n";
}
if ($password != $correct_password)
{
$password = "";
}
if ($offset < 0)
{
$offset = 0;
}
if ($limit < 1)
{
$limit = 10;
}
if ($order_by == "")
{
$order_by = $db_fields[0][PHP_NAME];
$asc = true;
}
$nrows $click_here_to_continue = calculate_click_here_to_continue();
$query = "SELECT * FROM clients_table\n";
if ($like)
{
$query .= $where_clause . ";";
}
$result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("SELECT query failed:");
echo $here_is_the_sql_query . "<br>\n";
echo pre($query);
echo $click_here_to_continue;
exit();
}
$nrows = 0;
while ($x = mysqli_fetch_array($result))
{
$nrows++;
}
if ($nrows <= $limit)
{
$offset = 0;
}
$click_here_to_continue = calculate_click_here_to_continue();
echo "<a id=\"start-here\"></a>\n";
echo "<div class=\"heading\">\n";
echo " action=$action";
echo "</div>\n";
$action switch ($action)
{
case "browser":
{
$table $fields $lenarray_length$table $len $fields$table $new_client_id $result = mysqli_query($link,"SELECT MAX(" . $db_fields[0][PHP_NAME] . ") FROM clients_table;");
if (!$result)
{
echo h1error("Query failed.");
echo $click_here_to_continue;
exit();
}
$x = mysqli_fetch_row($result);
$new_client_id = $x[0] + 1;
if (($password == $correct_password) and ($correct_password != ""))
{
echo "You are now in read/write mode.\n";
echo "Logging out removes write access to the Clients Table\n";
echo "<br><br>\n";
echo " <div class=\"left\">\n";
echo " <form action=\"#start-here\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"new-client\">\n";
echo " <input type=\"hidden\" name=\"new_client_id\" value=\"$new_client_id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_Phone $search_url_address $search_Email $search_address $search_Categories echo " <button type=\"submit\">Add New Client</button>\n";
echo " </form>\n";
echo " </div>\n";
echo " <div class=\"right\">\n";
echo " <form action=\"#start-here\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"logout\">\n";
echo " <input type=\"hidden\" name=\"new_client_id\" value=\"$new_client_id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_Phone $search_url_address $search_Email $search_address $search_categories echo " <button type=\"submit\">Log Out</button>\n";
echo " </form>\n";
echo " </div>\n";
echo "<br><br><br>\n";
echo "<div class=\"left\">\n";
echo "<form action=\"#\" method=\"post\" enctype=\"multipart/form-data\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"put-sql-file\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
echo " <input type=\"file\" name=\"file-smeg\" size=\"40\"><br>";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
echo " <input type=\"submit\" name=\"Submit\" value=\"Put SQL file\">";
echo "</form>\n";
echo "</div>\n";
}
else
{
echo "You are in read only mode. To edit the clients_table you need to enter the correct username and password.<br>\n";
echo " <div class=\"left\">\n";
echo " <form action=\"#start-here\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"login\">\n";
echo " <input type=\"hidden\" name=\"new_client_id\" value=\"$new_client_id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"\">\n";
echo " <label for=\"username\">Username:</label>\n";
echo " <input id=\"username\" type=\"username\" name=\"username\" value=\"$username\"><br>\n";
echo " <label for=\"password\">Password:</label>\n";
echo " <input id=\"password\" type=\"password\" name=\"password\" value=\"\"><br>\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">Log In</button>\n";
echo " </form>\n";
echo " </div>\n";
echo "<br><br><br>\n";
echo "<br><br><br>\n";
}
echo "<div class=\"right\">\n";
echo "<form action=\"#\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"get-sql-file\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
echo " <input type=\"submit\" name=\"Submit\" value=\"Get SQL file\">";
echo "</form>\n";
echo "</div>\n";
$query = "SELECT * FROM clients_table\n";
if ($like)
{
$queryWHERE (name LIKE \"$like_2\"\n OR url_address LIKE \"$like_2\"\n OR Email LIKE \"$like_2\")\n"; $query .= $where_clause;
}
$query .= "ORDER BY " . $order_by . ($asc ? " ASC\n" : " DESC\n");
$query .= "LIMIT $offset,$limit;";
echo "<br><br>\n";
echo "<div class=\"heading\">\n";
echo $here_is_the_sql_query;
echo "</div>\n";
echo pre($query);
$result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("Query failed.");
echo $click_here_to_continue;
exit();
}
$ncols = mysqli_num_fields($result);
assert($ncols == array_length($db_fields));
h1$ncols h1array_lengtharray_length$db_fields echo "<div class=\"heading\">Clients Matching Search Criteria</div>\n";
echo "<div class=\"foo\">\n";
echo " <table border=\"0\">\n";
$href_search_fields = "";
for ($i = 0; $i < array_length($db_fields); $i++)
{
if (($db_fields[$i][TYPE] == "date") or
($db_fields[$i][TYPE] == "time") or
($db_fields[$i][TYPE] == "datetime"))
{
$href_search_fields .= "&search_" . $db_fields[$i][PHP_NAME] . "_min=" . $db_fields[$i][SEARCH_FIELDS][0];
$href_search_fields .= "&search_" . $db_fields[$i][PHP_NAME] . "_max=" . $db_fields[$i][SEARCH_FIELDS][1];
}
else
{
$href_search_fields .= "&search_" . $db_fields[$i][PHP_NAME] . "=" . $db_fields[$i][SEARCH_FIELDS];
}
}
for ($k = 0; $k < 2; $k++)
{ --- echo " <tr>\n";
echo " <td class=\"gray\"> row <br><img src=\"updown.png\" width=16 height=16></td>\n";
if (($password == $correct_password) and ($correct_password != ""))
{
echo " <td></td>\n";
echo " <td></td>\n";
}
for ($j = 0; $j < $ncols; $j++)
{
if ($db_fields[$j][PHP_NAME] == $order_by)
{
echo " <td class=\"gray\" valign=\"middle\"><span class=\"green\"><u>" . $db_fields[$j][ENGLISH_NAME] . "</u><br><a href=\"?page_id=$page_id&action=browser&offset=$offset&limit=$limit&order-by=" . $db_fields[$j][PHP_NAME] . "&asc=" . !$asc . "&like=$like&username=$username&encoded=1&password=$password"
. $href_search_fields
$search_id$search_name$search_url_yellow$search_phone$search_url_address$search_email$search_address$search_categories . "#start-here\">"
. "<img src=" . ($asc ? "\"up-selected.png\" alt=\"up\" title=\"View by " . $db_fields[$j][ENGLISH_NAME] . " in descending order\"" : "\"down-selected.png\" alt=\"down\" title=\"View by " . $db_fields[$j][ENGLISH_NAME] . " in ascending order\"")
. " width=\"16\" height=\"16\"></span></a></td>\n";
}
else
{
echo " <td class=\"gray\" valign=\"middle\">" . $db_fields[$j][ENGLISH_NAME] . "<br><a href=\"?page_id=$page_id&action=browser&offset=$offset&limit=$limit&order-by=" . $db_fields[$j][PHP_NAME] . "&asc=1&like=$like&username=$username&encoded=1&password=$password"
. $href_search_fields
$search_id$search_name$search_url_yellow$search_phone$search_url_address$search_email$search_address$search_categories . "#start-here\">"
. "<img src=\"up-unselected.png\" alt=\"up\" title=\"View by " . $db_fields[$j][ENGLISH_NAME] . " in ascending order\" "
. " width=\"16\" height=\"16\"></a></td>\n";
}
}
echo " </tr>\n";
if ($k == 0)
{
$crow = $offset;
$found = false;
while ($x = mysqli_fetch_row($result))
{
$found = true;
if ($crow & 1)
{
$lit = false;
}
else
{
$lit = true;
}
if ($lit)
{
echo " <tr class=\"evens\">\n";
}
else
{
echo " <tr class=\"odds\">\n";
}
$password$correct_password$correct_password echo " <td valign=\"bottom\">$crow</td>\n";
$crow if (($password == $correct_password) and ($correct_password != ""))
{
echo " <td align=\"left\" valign=top>\n";
echo "<a href=\"?page_id=$page_id&action=delete&id=$x[0]&offset=$offset&limit=$limit&order-by=$order_by&asc=$asc&like=$like&username=$username&encoded=1&password=$password"
. $href_search_fields
$search_id$search_name$search_url_yellow$search_phone$search_url_address$search_email$search_address$search_categories . "#start-here\"><img src=delete.png width=\"16\" height=\"16\" title=\"Delete\" alt=\"Delete\"></a>\n";
echo " </td>\n";
echo " <td align=\"left\" valign=top>\n";
echo "<a href=\"?page_id=$page_id&action=edit&id=$x[0]&offset=$offset&limit=$limit&order-by=$order_by&asc=$asc&like=$like&username=$username&encoded=1&password=$password"
. $href_search_fields
$search_id$search_name$search_url_yellow$search_phone$search_url_address$search_email$search_address$search_categories . "#start-here\"><img src=edit.png width=\"16\" height=\"16\" title=\"Edit\" alt=\"Edit\"></a>\n";
echo " </td>\n";
}
for ($i = 0; $i < $ncols; $i++)
{
echo " <td valign=\"top\">\n";
if ($i == 0)
{
echo " <span class=\"id\">";
}
elseif ($db_fields[$i][PHP_NAME] == "name")
{
echo " <span class=\"name\">";
}
elseif ($db_fields[$i][TYPE] == "url")
{
echo " <a href=\"$x[$i]\"><span class=\"blue\">";
}
elseif ($db_fields[$i][TYPE] == "email")
{
echo " <a href=\"mailto:$x[$i]?Subject=Enquiry\"><span class=\"blue\">";
}
else
{
echo " <span class=\"black\">";
}
echo trim($x[$i]);
if ($i == 0)
{
echo " </span>\n";
}
elseif ($db_fields[$i][PHP_NAME] == "name")
{
echo " </span>\n";
}
elseif ($db_fields[$i][TYPE] == "url")
{
echo " </span></a>\n";
}
elseif ($db_fields[$i][TYPE] == "email")
{
echo " </span></a>\n";
}
else
{
echo " </span>\n";
}
echo " </td>\n";
} --- echo " </tr>\n";
$crow++;
}
if (!$found)
{ echo " <tr><td colspan=9><div class=\"red\">No matching records found</div></td></tr>\n";
}
}
}
echo " </table>\n";
echo "</div>\n";
$left_offset$right_offset $left_offset = $offset - $limit;
if ($left_offset < 0)
{
$left_offset = 0;
}
$right_offset = $offset + $limit;
if ($right_offset + $limit > $nrows)
{
$right_offset = $nrows - $limit;
if ($right_offset < 0)
{
$right_offset = 0;
}
}
echo "<br>\n";
echo "<div class=\"heading\">\n";
echo " <a name=\"crscrollingf\"></a>\n";
echo " Client Record Scrolling Functions";
echo "</div>\n";
echo "<div class=\"below-heading\">\n";
echo " <div id=\"columnLeft\">\n";
if ($left_offset != $offset)
{
echo " <form action=\"#crscrollingf\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$left_offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">UP<br><<<<<<</button>\n";
echo " </form>\n";
}
else
{
echo " UP<br><<<<<<<br>\n";
}
echo " <br>\n";
echo " Go To Rows#<br><b>$left_offset ... " . ($left_offset + $limit - 1) . "</b>\n";
echo "</div>\n";
echo "<div id=\"columnMiddle\">\n";
echo " <div class=\"left\">\n";
if ($offset != 0)
{
echo " <form action=\"#crscrollingf\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"0\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">GOTO BEGINNING</button>\n";
echo " </form>\n";
}
else
{
echo " GOTO BEGINNING\n";
}
echo " </div>\n";
echo " <div class=\"right\">\n";
if ($offset < $nrows - $limit)
{
echo " <form action=\"#crscrollingf\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"" . ($nrows - $limit) . "\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">GOTO END</button>\n";
echo " </form>\n";
}
else
{
echo " GOTO END\n";
}
echo " </div>\n";
echo " <form action=\"#crscrollingf\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\"><br>\n";
echo " <label>Offset:<input type=\"number\" name=\"offset\" value=\"$offset\"></label><br>\n";
echo " <label>Limit: <input type=\"number\" name=\"limit\" value=\"$limit\"></label><br>\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">Set Offset and Limit</button>\n";
echo " </form>\n";
echo " </div>\n";
echo " <div id=\"columnRight\">\n";
if ($right_offset != $offset)
{
echo " <form action=\"#crscrollingf\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$right_offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">DOWN<br>>>>>>></button>\n";
echo " </form>\n";
}
else
{
echo " DOWN<br>>>>>>><br>\n";
}
echo " <br>\n";
echo " Go To Rows#<br><b>$right_offset ... " . ($right_offset + $limit - 1) . "</b>\n";
echo " </div>\n";
echo " <br><br><br><br><br><br>\n";
if ($like)
{
echo "<div id=\"big-black\">Total number of matching rows found = $nrows</div>";
}
else
{
echo "<div id=\"big-black\">Total number of rows in table = $nrows</div>";
}
if (($nrows <= $limit) and ($offset == 0))
{
if ($like)
{
echo "<div id=\"big-black\">Entire matching records found. No scrolling is necessary!</div>";
}
else
{
echo "<div id=\"big-black\">Entire clients_table is shown. No scrolling is necessary!</div>";
}
}
echo "</div>\n";
echo "<br>\n";
echo "<div class=\"heading\">\n";
echo " <a name=\"crsearchingf\"></a>\n";
echo " Client Record Searching Functions";
echo "</div>\n";
echo "<div class=\"below-heading\">\n";
echo " <form action=\"#start-here\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"0\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
--- if ($like == 1)
{
$l = "";
}
else
{
$l = $like;
}
--- echo " <input type=\"text\" name=\"like\" size=\"30\" value=\"$l\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
echo " <br>\n";
for ($i = 0; $i < array_length($db_fields); $i++)
{
if ($db_fields[$i][TYPE] == "date")
{
echo " <br>\n";
echo " <input type=\"text\" value=\"" . $db_fields[$i][SEARCH_FIELDS][0] . "\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_min\" size=\"" . DATE_LENGTH . "\" maxlength=\"" . DATE_LENGTH . "\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . " from date (YYYY-MM-DD)</label><br>\n";
echo " <input type=\"text\" value=\"" . $db_fields[$i][SEARCH_FIELDS][1] . "\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_max\" size=\"" . DATE_LENGTH . "\" maxlength=\"" . DATE_LENGTH . "\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . " to date (YYYY-MM-DD)</label>\n";
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
}
elseif ($db_fields[$i][TYPE] == "time")
{
echo " <br>\n";
echo " <input type=\"text\" value=\"" . $db_fields[$i][SEARCH_FIELDS][0] . "\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_min\" size=\"" . TIME_LENGTH . "\" maxlength=\"" . TIME_LENGTH . "\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . " from time (HH:MM:SS)</label><br>\n";
echo " <input type=\"text\" value=\"" . $db_fields[$i][SEARCH_FIELDS][1] . "\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_max\" size=\"" . TIME_LENGTH . "\" maxlength=\"" . TIME_LENGTH . "\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . " to time (HH:MM:SS)</label>\n";
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
}
elseif ($db_fields[$i][TYPE] == "datetime")
{
echo " <br>\n";
echo " <input type=\"text\" value=\"" . $db_fields[$i][SEARCH_FIELDS][0] . "\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_min\" size=\"" . DATE_TIME_LENGTH . "\" maxlength=\"" . DATE_TIME_LENGTH . "\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . " from date time (YYYY-MM-DD HH:MM:SS)</label><br>\n";
echo " <input type=\"text\" value=\"" . $db_fields[$i][SEARCH_FIELDS][1] . "\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_max\" size=\"" . DATE_TIME_LENGTH . "\" maxlength=\"" . DATE_TIME_LENGTH . "\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . " to date time (YYYY-MM-DD HH:MM::SS)</label>\n";
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][0]));
assert(my_is_string($db_fields[$i][SEARCH_FIELDS][1]));
}
else
{
assert(my_is_string($db_fields[$i][SEARCH_FIELDS]));
echo " <input type=\"checkbox\" " . (($db_fields[$i][SEARCH_FIELDS] != "") ? "checked=\"checked\"" : "") . " name=\"search_" . $db_fields[$i][PHP_NAME] . "\" value=\"true\"><label>Search " . $db_fields[$i][ENGLISH_NAME] . "</label>\n";
}
}
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <br>\n";
echo " <button type=\"submit\">Search Clients</button>\n";
echo " </form>\n";
echo " <form action=\"#crsearchingf\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"browser\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"0\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
--- $hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories --- echo " <button type=\"submit\">Erase the Client Search Field</button>\n";
echo " </form>\n";
echo "</div>\n";
break;
}
case "get-sql-file":
{
if (!file_exists("sql"))
{
mkdir("sql");
}
$file_handle = fopen("sql/table.sql","w");
$create_table_query = get_create_table_query();
fputs($file_handle, $create_table_query);
$var = get_insert_table_query();
fputs($file_handle,$var);
fclose($file_handle);
echo h1("Here is the contents of the SQL file:");
{
$str = "";
$file_handle = fopen("sql/table.sql","r");
while (($c = fgetc($file_handle)) != "")
{
$str .= $c;
}
fclose($file_handle);
echo pre($str);
}
h1$page_id echo calculate_click_here_to_continue();
break;
}
case "put-sql-file":
{
h1 $name = "";
if (isset($_FILES['file-smeg']['tmp_name']))
{
$name = $_FILES['file-smeg']['tmp_name'];
h1ok }
else
{
echo h1error("File name cannot be empty");
echo calculate_click_here_to_continue();
exit();
$name h1error }
if ($name == "")
{
echo h1error("File name cannot be empty");
echo calculate_click_here_to_continue();
exit();
}
$file_handle = fopen($name,"r");
$query = "";
while (($line = fgets($file_handle)) != "")
{
$query .= $line;
}
echo h1("Here is the contents of the uploaded file:");
echo pre($query);
$array = my_explode($query);
{
$link = mysqli_connect($db_hostname,$db_username,$db_password);
if (!$link)
{
echo h1error('Unable to connect to the database server');
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
echo h1error('Unable to set database connection encoding.');
exit();
}
}
for ($i=0; $i<array_length($array); $i++)
{
if (trim($array[$i]) != "")
{
$result = mysqli_query($link,$array[$i] . ";");
if (!$result)
{
echo h1error("Query failed: ");
echo pre($array[$i] . ";");
}
else
{
echo h1ok("Query succeeded:");
echo pre($array[$i] . ";");
}
}
}
echo calculate_click_here_to_continue();
$array h1 break;
}
case "delete":
{
if (($password != $correct_password) or ($correct_password == ""))
{
echo h1error("You cannot edit the clients_table without the correct password");
echo $click_here_to_continue;
exit();
}
$id = $_REQUEST[$db_fields[0][PHP_NAME]];
$query = "SELECT * FROM clients_table WHERE " . $db_fields[0][PHP_NAME] . " = $id";
$result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("Failed to SELECT * FROM clients_table");
echo $here_is_the_sql_query . "<br>\n";
echo pre($query);
echo $click_here_to_continue;
exit();
}
$x = mysqli_fetch_array($result);
for ($i = 0; $i<array_length($db_fields);)
{
$db_fields $db_fields $db_fields $db_fields $db_fields $db_fields $db_fields $db_fields $db_fields {
$db_fields[$i][VALUE_FIELDS] = $x[$i];
$i += 1;
}
}
$name $url_yellow $phone $url_address $email $address $categories for ($i = 0; $i<array_length($db_fields); $i++)
{
$db_fields h1$db_fields$db_fields h1$db_fields_max$db_fields $db_fields h1$db_fields$db_fields h1$db_fields_max$db_fields $db_fields h1$db_fields$db_fields h1$db_fields_max$db_fields {
h1 $db_fields $db_fields h1 h1 assertmy_is_string$db_fields assertmy_is_string$db_fields assert assertmy_is_string$db_fields echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
h1 }
}
$str$db_value_fields$db_value_fields echo h1ok("Really delete client id = $id? (Yes/No)");
echo "<div class=\"left\">\n";
echo " <form action=\"#start-here\" method=\"post\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"delete-2\">\n";
echo " <input type=\"hidden\" name=\"id\" value=\"$id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"yorn\" value=\"yes\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">Yes</button>\n";
echo " </form>\n";
echo "</div>\n";
echo "<div class=\"right\">\n";
echo " <form action=\"#start-here\" method=\"post\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"delete-2\">\n";
echo " <input type=\"hidden\" name=\"id\" value=\"$id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"yorn\" value=\"no\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories echo " <button type=\"submit\">No</button>\n";
echo " </form>\n";
echo "</div>\n";
break;
}
case "delete-2":
{
if (($password != $correct_password) or ($correct_password == ""))
{
echo h1error("You cannot edit the clients_table without the correct password");
echo $click_here_to_continue;
exit();
}
$yorn = $_REQUEST['yorn'];
$id = $_REQUEST['id'];
$y = substr($yorn,0,1);
if ($y == 'y' or $y == 'Y')
{
$query = "delete FROM clients_table WHERE id = $id;";
$result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("Failed to delete client # $id");
echo $here_is_the_sql_query . "<br>\n";
echo pre($query);
echo $click_here_to_continue;
exit();
}
else
{
echo h1ok("Successfully deleted client # $id");
echo $here_is_the_sql_query . "<br>\n";
echo pre($query);
}
}
else
{
echo h1("You chose not to delete client number $id");
$here_is_the_sql_query }
echo $click_here_to_continue;
break;
}
case "edit":
{
if (($password != $correct_password) or ($correct_password == ""))
{
echo h1error("You cannot edit the clients_table without the correct password");
echo $click_here_to_continue;
exit();
}
$id = $_REQUEST[$db_fields[0][PHP_NAME]];
$result = mysqli_query($link,"SELECT * FROM clients_table WHERE " . $db_fields[0][PHP_NAME] . "=$id;");
if (!$result)
{
echo h1error("Failed to extract client information.");
echo $click_here_to_continue;
exit();
}
$x = mysqli_fetch_row($result);
echo "<form action=\"#start-here\" method=\"post\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"edit-2\">\n";
echo " <input type=\"hidden\" name=\"" . $db_fields[0][PHP_NAME] . "\" value=\"$id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories for ($i = 1; $i < array_length($db_fields);)
{
if ($db_fields[$i][TYPE] == "int")
{
$type = "text";
}
else
{
$type = $db_fields[$i][TYPE];
}
$name = $db_fields[$i][PHP_NAME];
if ($name == "name")
{
$name = "nome";
}
$db_fields $db_fields $db_fields $db_fields$type$name_min $db_fields$type$name_max {
echo " <label>" . $db_fields[$i][ENGLISH_NAME] . ": <input type=\"$type\" name=\"" . $name . "\" value=\"$x[$i]\"></label><br>\n";
$i += 1;
}
}
echo " <button type=\"submit\">Save Changes</button>\n";
echo "</form>\n";
echo "<br>\n";
echo $click_here_to_continue;
break;
}
case "edit-2":
{
if (($password != $correct_password) and ($correct_password != ""))
{
echo h1error("You cannot edit the clients_table without the correct password");
echo $click_here_to_continue;
exit();
}
for ($i = 0; $i < array_length($db_fields); $i++)
{
$name = $db_fields[$i][PHP_NAME];
if ($name == "name")
{
$name = "nome";
}
$db_fields $db_fields$_REQUEST$name_min $db_fields$_REQUEST$name_max {
$db_fields[$i][VALUE_FIELDS] = $_REQUEST[$name];
}
}
$id$_REQUEST $name$_REQUEST $db_value_fields$name $url_yellow$_REQUEST $phone$_REQUEST $url_address$_REQUEST $email$_REQUEST $address$_REQUEST $categories$_REQUEST
assert($db_fields[0][VALUE_FIELDS] != "");
$query = "UPDATE clients_table\n";
$query .= "SET ";
for ($i = 0; $i < array_length($db_fields); $i++)
{
if ($i != 0)
{
$query .= ", ";
}
if (($db_fields[$i][TYPE] == "date") or ($db_fields[$i][TYPE] == "time") or ($db_fields[$i][TYPE] == "datetime"))
{
$query .= $db_fields[$i][PHP_NAME] . "_min='" . $db_fields[$i][VALUE_FIELDS][0] . "'\n";
$query .= $db_fields[$i][PHP_NAME] . "_max='" . $db_fields[$i][VALUE_FIELDS][1] . "'\n";
}
else
{
$query .= $db_fields[$i][PHP_NAME] . "='" . $db_fields[$i][VALUE_FIELDS] . "'\n";
$name$url_yellow$phone$url_address$email$address$categories }
}
$query .= "\nWHERE " . $db_fields[0][PHP_NAME] . " = " . $db_fields[0][VALUE_FIELDS] . ";\n";
$queryUPDATE clients_table SET name='Davin Pearson', phone='339-1145' WHERE id = $id;"; $result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("Failed to UPDATE the clients_table.");
echo "<div class=\"heading\">" . $here_is_the_sql_query . "</div>\n";
echo pre($query);
echo $click_here_to_continue;
}
else
{
echo h1ok("Successfully UPDATED the clients_table.");
echo "<div class=\"heading\">" . $here_is_the_sql_query . "</div>\n";
echo pre($query);
echo $click_here_to_continue;
}
break;
}
case "new-client":
{
$new_client_id = $_REQUEST['new_client_id'];
if (($password != $correct_password) and ($correct_password != ""))
{
echo h1error("You cannot edit the clients_table without the correct password");
echo $click_here_to_continue;
exit();
}
if ($new_client_id != "")
{
echo h1("new client id=$new_client_id");
echo "<form action=\"#start-here\" method=\"get\">\n";
echo " <input type=\"hidden\" name=\"page_id\" value=\"$page_id\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"new-client-2\">\n";
echo " <input type=\"hidden\" name=\"id\" value=\"$new_client_id\">\n";
echo " <input type=\"hidden\" name=\"offset\" value=\"$offset\">\n";
echo " <input type=\"hidden\" name=\"limit\" value=\"$limit\">\n";
echo " <input type=\"hidden\" name=\"order-by\" value=\"$order_by\">\n";
echo " <input type=\"hidden\" name=\"asc\" value=\"$asc\">\n";
echo " <input type=\"hidden\" name=\"like\" value=\"$like\">\n";
echo " <input type=\"hidden\" name=\"username\" value=\"$username\">\n";
echo " <input type=\"hidden\" name=\"encoded\" value=\"1\">\n";
echo " <input type=\"hidden\" name=\"password\" value=\"$password\">\n";
$hidden_search_fields = calculate_hidden_fields();
echo $hidden_search_fields;
$search_id $search_name $search_url_yellow $search_phone $search_url_address $search_email $search_address $search_categories $lines = "";
for ($i = 1; $i < array_length($db_fields); $i++)
{
if ($db_fields[$i][TYPE] == "int")
{
$type = "text";
}
else
{
$type = $db_fields[$i][TYPE];
}
$name = $db_fields[$i][PHP_NAME];
if ($name == "name")
{
$name = "nome";
}
if ($type == "date")
{
$lines .= "<label>" . $db_fields[$i][ENGLISH_NAME] . " (YYYY-MM-DD):";
$lines .= " <input type=\"text\" name=\"" . $db_fields[$i][PHP_NAME] . "\" value=\"\" maxlength=" . DATE_LENGTH . "><br>\n";
$lines .= "</label><br>\n";
}
elseif ($type == "time")
{
$lines .= "<label>" . $db_fields[$i][ENGLISH_NAME] . " (HH:MM:SS):";
$lines .= " <input type=\"text\" name=\"" . $db_fields[$i][PHP_NAME] . "\" value=\"\" maxlength=" . TIME_LENGTH . "><br>\n";
$lines .= "</label><br>\n";
}
elseif ($type == "datetime")
{
$lines .= "<label>" . $db_fields[$i][ENGLISH_NAME] . " (YYYY-MM-DD HH:MM:SS):";
$lines .= " <input type=\"text\" name=\"" . $db_fields[$i][PHP_NAME] . "\" value=\"\" maxlength=" . DATE_TIME_LENGTH . "><br>\n";
$lines .= "</label><br>\n";
}
else
{
$lines .= "<label>" . $db_fields[$i][ENGLISH_NAME] . ":<input type=\"$type\" name=\"$name\" value=\"" . $db_fields[$i][VALUE_FIELDS] . "\"></label><br>\n";
}
}
pre$lines echo $lines;
echo " <button type=\"submit\">Add Client to Database</button>\n";
echo "</form>\n";
echo "<br>\n";
echo $click_here_to_continue;
}
break;
}
case "new-client-2":
{
if (($password != $correct_password) and ($correct_password != ""))
{
echo h1error("You cannot edit the clients_table without the correct password");
echo $click_here_to_continue;
exit();
}
for ($i = 0; $i < array_length($db_fields); $i++)
{
$name = $db_fields[$i][PHP_NAME];
if ($name == "name")
{
$name = "nome";
}
$db_fields $db_fields$_REQUEST$name_min $db_fields$_REQUEST$name_max h1$db_fields$db_fields h1$db_fields$db_fields $db_fields $db_fields$_REQUEST$name_min $db_fields$_REQUEST$name_max h1$db_fields$db_fields h1$db_fields$db_fields $db_fields[$i][VALUE_FIELDS] = trim($_REQUEST[$name]);
echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
}
$id$_REQUEST $name$_REQUEST $url_yellow$_REQUEST $phone$_REQUEST $url_address$_REQUEST $email$_REQUEST $address$_REQUEST $categories$_REQUEST h1$id h1$name h1$url_yellow h1$phone h1$url_address h1$email h1$address h1$categories
assert($db_fields[0][VALUE_FIELDS] != "");
$resultmysqli_query$linkINSERT INTO clients_table (id,name,url_yellow,Phone,url_address,Email,address,Categories) VALUES\n" $client_id@example
$query = "INSERT INTO clients_table (";
for ($i = 0; $i<array_length($db_fields); $i++)
{
if ($i != 0)
{
$query .= ", ";
}
$query .= $db_fields[$i][PHP_NAME];
}
$query .= ") VALUES\n";
$query .= "(";
for ($i = 0; $i<array_length($db_fields); $i++)
{
if ($i != 0)
{
$query .= ",\n";
}
if ($db_fields[$i][TYPE] == "date")
{
if (strlen($db_fields[$i][VALUE_FIELDS]) != DATE_LENGTH);
{
$db_fields[$i][VALUE_FIELDS] = '0000/00/00';
}
$query .= "'" . slashes_to_minus_date($db_fields[$i][VALUE_FIELDS]) . "'";
$query$db_fields }
if ($db_fields[$i][TYPE] == "time")
{
if (strlen($db_fields[$i][VALUE_FIELDS]) != TIME_LENGTH)
{
$db_fields[$i][VALUE_FIELDS] = '00:00:00';
}
$query .= "'" . $db_fields[$i][VALUE_FIELDS] . "'";
}
elseif ($db_fields[$i][TYPE] == "datetime")
{
h1$db_fields if (strlen($db_fields[$i][VALUE_FIELDS]) != DATE_TIME_LENGTH)
{
$db_fields[$i][VALUE_FIELDS] = '0000/00/00 00:00:00';
}
$query .= "'" . slashes_to_minus_datetime($db_fields[$i][VALUE_FIELDS]) . "'";
}
else
{
$query .= "'" . $db_fields[$i][VALUE_FIELDS] . "'";
}
}
$query .= ");\n";
$queryINSERT INTO clients_table (id,name,url_yellow,Phone,url_address,Email,address,Categories) VALUES\n" $id$name$url_yellow$phone$url_address$email$address$categories $result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("Failed to INSERT INTO clients_table.");
echo "<div class=\"heading\">" . $here_is_the_sql_query . "</div>\n";
echo pre($query);
echo $click_here_to_continue;
exit();
}
else
{
echo h1ok("Successfully inserted into clients_table.");
echo "<div class=\"heading\">" . $here_is_the_sql_query . "</div>\n";
echo pre($query);
echo $click_here_to_continue;
}
break;
}
case "login":
{
if (($password == $correct_password) and ($correct_password != ""))
{
echo h1ok("Correct username and password!");
echo $click_here_to_continue;
}
else
{
echo h1error("Incorrect username and/or password!");
echo $click_here_to_continue;
}
break;
}
case "logout":
{
echo h1ok("Successfully logged out.");
echo $click_here_to_continue;
break;
}
}
}
}
?>