GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. Language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


CRUD.php

    
<?php
/*
   @package Crud
   @version 1.0

Plugin URL: http://davin.50webs.com/research/2014/CRUD.html
   Description: This a plugin for querying http://en.wikipedia.org/wiki/CRUD from an arbitrary database.
   Author: Davin Pearson
   Author URL: <http://davin.50webs.com>

NOTE: You will need to set the values of (in the crud method)

(1) $correct_password_assoc_array inside crud method,
   (2) $page_id == 4 inside crud method,
   (3) $db_hostname, $db_username and $db_password and
   (4) $db_fields array array.

LIMITATION OF WARRANTY:

This file is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
   by the Free Software Foundation; either version 3, or (at your
   option) any later version.

This file is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

You should have received a copy of the GNU General Public License
   along with this software, see the file COPYING.  If not, see:

<http://www.gnu.org/licenses/gpl-3.0.txt>

*/

require_once (dirname(__FILE__) . "/CRUD-functions.php");

//echo h1("Zeroth part of crud function");

// NOTE: the first row in the following table must be the id! (primary key)
$db_fields = array(
                   //    0 English name       1 PHP name         2 TYPE     3 MYSQL CREATE FUNCTION    4  5
                   array("ID",                "id",              "int",     "INT NOT NULL PRIMARY KEY","",""), // 0
                   array("Name",              "name",            "text",    "VARCHAR(255) NOT NULL",   "",""), // 1
                   array("URL Yellow",        "url_yellow",      "url",     "VARCHAR(255) NOT NULL",   "",""), // 2
                   array("Phone#",            "phone",           "tel",     "VARCHAR(255) NOT NULL",   "",""), // 3
                   array("URL Address",       "url_address",     "url",     "VARCHAR(255) NOT NULL",   "",""), // 4
                   array("Email Address",     "email",           "email",   "VARCHAR(255) NOT NULL",   "",""), // 5
                   array("Address",           "address",         "text",    "VARCHAR(255) NOT NULL",   "",""), // 6
                   array("Categories",        "categories",      "text",    "VARCHAR(255) NOT NULL",   "",""), // 7
                   array("Time fixed",        "time_fixed",      "time",    "TIME NOT NULL",           "","")  // 8
                   );

$db_hostname = "localhost";
$db_database = "wordpress";
$db_username = "root";
$db_password = "acadta64";
//$db_database = "davinpea_wp";
//$db_username = "davinpea_wp";
//$db_password = "roger-the-dodger";

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 = "";

//echo h1("Foo!");

add_action('the_content', 'crud');
//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 = 12;
   //echo h1("First part of crud function");
   // -----------------------------------------------------------------
   if ($page_id == 10)
   {
      srand(((int)((double)microtime()*1000003)));
      //$s = "abc";
      //assert(my_is_string($s[1]));
      //assert(my_is_string($s[1][2]));
      //assert(my_is_string($s[1][2][3]));
      //echo h1("Second part of crud function");
      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[]  = "";
         }
         // ------------------------------------------------------------------------------------------
      }
      //assert (array_length($db_fields) == array_length($db_search_fields));
      //assert (array_length($db_fields) == array_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";
      ////////////////////////////////////////////////////////////////
      ///
      /// NOTE: initialises database connection
      ///
      //echo h1("Third part of crud function");
      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 . "%";
         }
      }
      //echo h1("Fourth part of crud function");
      //echo h1("array_length(db_fields)=" . array_length($db_fields));
      for ($i = 0; $i <  array_length($db_fields); $i++)
      {
         //echo h1("db_fields[$i][TYPE]=" . $db_fields[$i][TYPE]);
         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"];
            //echo h1("db_fields[$i][SEARCH_FIELDS][0]="      . $db_fields[$i][SEARCH_FIELDS][0]);
            //echo h1("db_fields[$i][SEARCH_FIELDS][1]="      . $db_fields[$i][SEARCH_FIELDS][1]);
            //echo h1("REQUEST[search_Date_Time_Joined_min]=" . $_REQUEST["search_Date_Time_Joined_min"]);
            //echo h1("REQUEST[search_Date_Time_Joined_max]=" . $_REQUEST["search_Date_Time_Joined_max"]);
         }
         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"];
            // else
            // {
            //    $db_fields[$i][SEARCH_FIELDS][1] = "";
            // }
            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"];
            }
            // else
            // {
            //    $db_fields[$i][SEARCH_FIELDS][0] = "";
            // }
            if (isset($_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"]))
            {
               $db_fields[$i][SEARCH_FIELDS][1] = $_REQUEST["search_" . $db_fields[$i][PHP_NAME] . "_max"];
            }
            // echo h1("db_fields[i][SEARCH_FIELDS][1]=" . $db_fields[$i][SEARCH_FIELDS][1]);
            // else
            // {
            //    $db_fields[$i][SEARCH_FIELDS][1] = "";
            // }
         }
         else
         {
            //assert(false);
            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]];
            }
            // else
            // {
            //    $db_fields[$i][SEARCH_FIELDS] = "";
            // }
           assert(my_is_string($db_fields[$i][SEARCH_FIELDS]));
           //echo h1("db_fields[$i][SEARCH_FIELDS]=" . $db_fields[$i][SEARCH_FIELDS]);
         }
      }
      //echo h1("Fifth part of crud function");
      //      for ($i = 0; $i <  array_length($db_fields); $i++)
      //      {
      //         echo h1("db_fields[$i][TYPE]=" . $db_fields[$i][TYPE]);
      //         if ($db_fields[$i][TYPE] == "datetime")
      //         {
      //            echo h1("db_fields[$i][SEARCH_FIELDS][0]=" . $db_fields[$i][SEARCH_FIELDS][0]);
      //            echo h1("db_fields[$i][SEARCH_FIELDS][1]=" . $db_fields[$i][SEARCH_FIELDS][1]);
      //         }
      //         elseif ($db_fields[$i][TYPE] == "date")
      //         {
      //            echo h1("db_fields[$i][SEARCH_FIELDS][0]=" . $db_fields[$i][SEARCH_FIELDS][0]);
      //            echo h1("db_fields[$i][SEARCH_FIELDS][1]=" . $db_fields[$i][SEARCH_FIELDS][1]);
      //         }
      //         else
      //         {
      //            assert($db_fields[$i][TYPE] != "date");
      //            assert($db_fields[$i][TYPE] != "datetime");
      //            assert(my_is_string($db_fields[$i][SEARCH_FIELDS]));
      //            echo h1("db_fields[$i][SEARCH_FIELDS]=" . $db_fields[$i][SEARCH_FIELDS]);
      //         }
      //      }
      //$search_id          = $_REQUEST['search_id'];
      //$search_name        = $_REQUEST['search_name'];
      //$search_url_yellow  = $_REQUEST['search_url-yellow'];
      //$search_Phone       = $_REQUEST['search_Phone'];
      //$search_url_address = $_REQUEST['search_url-address'];
      //$search_email       = $_REQUEST['search_Email'];
      //$search_address     = $_REQUEST['search_address'];
      //$search_Categories  = $_REQUEST['search_Categories'];
      $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]);
            //echo h1(strlen($db_fields[$i][SEARCH_FIELDS][0]));
            //echo h1(strlen($db_fields[$i][SEARCH_FIELDS][1]));
         }
         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] . "' ";
               //echo h1("(" . $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";
               //echo h1($db_fields[$i][PHP_NAME] . " <= '" . $db_fields[$i][SEARCH_FIELDS][1] . "')\n");
               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(false);
               //echo h1("Farticus");
               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";
               //echo h1("where_clause=$where_clause");
               //assert(false);
            }
         }
      }
      //echo h1("where_clause=$where_clause");
      if ($first)
      {
         $where_clause = "";
         //assert(false);
      }
      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;
      }
      ////////////////////////////////////////////////////////////////
      ///
      /// NOTE: used for calculating the $nrows variable
      ///
      $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();
      ////////////////////////////////////////////////////////////////
      ///
      /// NOTE: used as an anchor for vertical scrolling
      ///
      echo "<a id=\"start-here\"></a>\n";
      echo "<div class=\"heading\">\n";
      echo "   action=$action";
      echo "</div>\n";
      ////////////////////////////////////////////////////////////////
      ///
      /// NOTE: Major branch based on $action variable
      ///
      switch ($action)
      {
      case "browser":
         {
            //$table = readCSV(ABSPATH . "../form/fields.csv");
            //$fields = array();
            //$len = array_length($table[0]);
            //for ($i = 0; $i < $len; $i++)
            //{
            //   $fields[$i] = trim($table[0][$i]);
            //}
            ////////////////////////////////////////////////////////////////
            ///
            /// NOTE: used for calculating $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;

////////////////////////////////////////////////////////////////
            ///
            /// NOTE: used for Add Client and Log Out
            ///
            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=\"middle\">\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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url_yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_Phone\" value=\"$search_Phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url_address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_Email\" value=\"$search_Email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_Categories\" value=\"$search_Categories\">\n";
               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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_Phone\" value=\"$search_Phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_Email\" value=\"$search_Email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               echo             "         <button type=\"submit\">Log Out</button>\n";
               echo             "      </form>\n";
               echo             "   </div>\n";
               //echo             "</div>\n";
               echo             "<br><br><br>\n";

//echo             "<div class=\"middle\">\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           "   <button type=\"submit\">Put SQL file</button>\n";
               echo             "</form>\n";
               echo             "</div>\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=\"middle\">\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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url_yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url_address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               echo             "         <button type=\"submit\">Log In</button>\n";
               echo             "      </form>\n";
               echo             "   </div>\n";
               //echo           "</div>\n";
               echo             "<br><br><br>\n";
               echo             "<br><br><br>\n";
            }
            //echo                "<div class=\"middle\">\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              "   <button type=\"submit\">Get SQL file</button>\n";
            echo                "</form>\n";
            echo                "</div>\n";
            //echo              "</div>\n";
            ////////////////////////////////////////////////////////////////
            ///
            /// NOTE: Used for the main query for generating the table of clients matching the search criteria
            ///
            $query = "SELECT * FROM clients_table\n";
            if ($like)
            {
               //$query .= "WHERE (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));
            //echo h1("ncols=$ncols");
            //echo h1("array_length(db_fields)=" . array_length($db_fields));
            ////////////////////////////////////////////////////////////////
            ///
            /// NOTE: Used for rendering the table of clients matching the search criteria
            ///
            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++)
            {  //                  ---xxx
               echo             "      <tr>\n";
               echo             "         <td class=\"gray\">&nbsp;row&nbsp;<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_id&search_name=$search_name&search_url-yellow=$search_url_yellow&search_phone=$search_phone&search_url-address=$search_url_address&search_email=$search_email&search_address=$search_address&search_categories=$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_id&search_name=$search_name&search_url-yellow=$search_url_yellow&search_phone=$search_phone&search_url-address=$search_url_address&search_email=$search_email&search_address=$search_address&search_categories=$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";
                     }
                     //if (($password == $correct_password) and ($correct_password != ""))
                     //{
                     echo       "         <td valign=\"bottom\">$crow</td>\n";
                     //}
                     //else
                     //{
                     //   echo      "         <td valign=\"bottom\">$crow</td>\n";
                     //}
                     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_id&search_name=$search_name&search_url-yellow=$search_url_yellow&search_phone=$search_phone&search_url-address=$search_url_address&search_email=$search_email&search_address=$search_address&search_categories=$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_id&search_name=$search_name&search_url-yellow=$search_url_yellow&search_phone=$search_phone&search_url-address=$search_url_address&search_email=$search_email&search_address=$search_address&search_categories=$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)
                  {  ///         xxx+++
                     echo       "      <tr><td colspan=9><div class=\"red\">No matching records found</div></td></tr>\n";
                  }
               }
            }
            echo                "   </table>\n";
            echo                "</div>\n";
            ////////////////////////////////////////////////////////////////
            ///
            /// NOTE: Used to calculate $left_offset and $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;
               }
            }
            ////////////////////////////////////////////////////////////////
            ///
            /// NOTE: Used for rendering Client Record Scrolling Functions
            ///
            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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               echo             "      <button type=\"submit\">UP<br>&lt;&lt;&lt;&lt;&lt;&lt;</button>\n";
               echo             "    </form>\n";
            }
            else
            {
               echo             "    UP<br>&lt;&lt;&lt;&lt;&lt;&lt;<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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               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:&nbsp;&nbsp;<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;
            //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
            //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
            //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
            //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
            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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               echo             "      <button type=\"submit\">DOWN<br>&gt;&gt;&gt;&gt;&gt;&gt;</button>\n";
               echo             "    </form>\n";
            }
            else
            {
               echo             "    DOWN<br>&gt;&gt;&gt;&gt;&gt;&gt;<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>";
            }
            //echo "<br>\n";
            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";
            ////////////////////////////////////////////////////////////////
            ///
            /// NOTE: Used for rendering Client Record Searching Functions
            ///
            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";
            //                   ---xxx
            if ($like == 1)
            {
               $l = "";
            }
            else
            {
               $l = $like;
            }
            //                   ---xxx
            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";
               }
            }
            //echo "<input type=\"checkbox\" " . (($search_id != "") ? "checked=checked" : "") . " name=\"search_id\" value=\"true\"><label>Search ID</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_name != "") ? "checked=checked" : "") . " name=\"search_name\" value=\"true\"><label>Search name</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_url_yellow != "") ? "checked=checked" : "") . " name=\"search_url-yellow\" value=\"true\"><label>Search url_yellow</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_phone != "") ? "checked=checked" : "") . " search_phone\" value=\"true\"><label>Search phone number</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_url_address != "") ? "checked=checked" : "") . " name=\"search_url-address\" value=\"true\"><label>Search URL Address</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_email != "") ? "checked=checked" : "") . " name=\"search_email\" value=\"true\"><label>Search email address</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_address != "") ? "checked=checked" : "") . " name=\"search_address\" value=\"true\"><label>Search address</label>\n";
            //echo "<input type=\"checkbox\" " . (($search_categories != "") ? "checked=checked" : "") . " name=\"search_categories\" value=\"true\"><label>Search categories</label>\n";
            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";
            //                   ---xxx
            $hidden_search_fields = calculate_hidden_fields();
            echo $hidden_search_fields;
            //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
            //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
            //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
            //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
            //                   ---xxx
            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);
            }
            //echo "<a href=\"sql/table.sql\">Click here to view the SQL code for setting up the clients database</a>";
            //echo h1("page_id=$page_id\n");
            echo calculate_click_here_to_continue();
            break;
         }
      case "put-sql-file":
         {
            //echo h1("BEG Putted SQL file");
            $name = "";
            if (isset($_FILES['file-smeg']['tmp_name']))
            {
               $name = $_FILES['file-smeg']['tmp_name'];
               //echo h1ok("doneme");
            }
            else
            {
               echo h1error("File name cannot be empty");
               echo calculate_click_here_to_continue();
               exit();
               //$name = "sql/table.sql";
               //echo h1error("notdoneme");
            }
            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();
            //echo array_print($array);
            //echo h1("END Putted SQL file");
            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);)
            {
               // if ($db_fields[$i][TYPE] == "date")
               // {
               //    $db_fields[$i][VALUE_FIELDS][0] = $x[$i];
               //    //$db_fields[$i][VALUE_FIELDS][1] = $x[$i+1];
               //    $i += 1;
               // }
               // elseif ($db_fields[$i][TYPE] == "time")
               // {
               //    $db_fields[$i][VALUE_FIELDS][0] = $x[$i];
               //    //$db_fields[$i][VALUE_FIELDS][1] = $x[$i+1];
               //    $i += 1;
               // }
               // elseif ($db_fields[$i][TYPE] == "datetime")
               // {
               //    $db_fields[$i][VALUE_FIELDS][0] = $x[$i];
               //    //$db_fields[$i][VALUE_FIELDS][1] = $x[$i+1];
               //    $i += 1;
               // }
               // else
               {
                  $db_fields[$i][VALUE_FIELDS] = $x[$i];
                  $i += 1;
               }
            }
            //$name        = $x[1];
            //$url_yellow  = $x[2];
            //$phone       = $x[3];
            //$url_address = $x[4];
            //$email       = $x[5];
            //$address     = $x[6];
            //$categories  = $x[7];
            for ($i = 0; $i<array_length($db_fields); $i++)
            {
               // if ($db_fields[$i][TYPE] == "date")
               // {
               //    echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
               //    //echo h1($db_fields[$i][ENGLISH_NAME] . "_max=" . $db_fields[$i][VALUE_FIELDS][1]);
               // }
               // elseif ($db_fields[$i][TYPE] == "time")
               // {
               //    echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
               //    //echo h1($db_fields[$i][ENGLISH_NAME] . "_max=" . $db_fields[$i][VALUE_FIELDS][1]);
               // }
               // elseif ($db_fields[$i][TYPE] == "datetime")
               // {
               //    echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
               //    //echo h1($db_fields[$i][ENGLISH_NAME] . "_max=" . $db_fields[$i][VALUE_FIELDS][1]);
               // }
               // else
               {
                  //echo h1("BEG Smeg");
                  //$a = $db_fields[$i];
                  //$b = $db_fields[$i];
                  //echo h1("a=$a");
                  //echo h1("b=$b");
                  //assert(my_is_string($db_fields[$i][0]));
                  //assert(my_is_string($db_fields[$i][ENGLISH_NAME]));
                  //assert(ENGLISH_NAME == 0);
                  //assert(my_is_string($db_fields[$i][VALUE_FIELDS]));
                  echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
                  //echo h1("END Smeg");
               }
            }
            //$str = "Really delete customer #" . $db_value_fields[0] . ", name=" . $db_value_fields[1] . "?";
            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;
            //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
            //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
            //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
            //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
            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;
            //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
            //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
            //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
            //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
            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");
               //echo $here_is_the_sql_query . "<br>\n";
            }
            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;
            //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
            //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
            //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
            //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
            //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
            //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
            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";
               }
               // if (($db_fields[$i][TYPE] == "date")
               //     OR ($db_fields[$i][TYPE] == "time")
               //     OR ($db_fields[$i][TYPE] == "datetime"))
               // {
               //    echo "  <label>" . $db_fields[$i][ENGLISH_NAME] . "from: <input type=\"$type\" name=\"" . $name . "_min\" value=\"$x[$i]\"></label><br>\n";
               //    echo "  <label>" . $db_fields[$i][ENGLISH_NAME] . "to:   <input type=\"$type\" name=\"" . $name . "_max\" value=\"" . $x[$i+1] . "\"></label><br>\n";
               //    $i += 2;
               // }
               // else
               {
                  echo "  <label>" . $db_fields[$i][ENGLISH_NAME] . ": <input type=\"$type\" name=\"" . $name . "\" value=\"$x[$i]\"></label><br>\n";
                  $i += 1;
               }
            }
            //echo "<label>URL Yellow:<input type=\"text\" name=\"url_yellow\" value=\"$x[2]\"></label><br>\n";
            //echo "<label>Phone#:<input type=\"tel\" name=\"Phone\" value=\"$x[3]\"></label><br>\n";
            //echo "<label>URL:<input type=\"url\" name=\"url_address\" value=\"$x[4]\"></label><br>\n";
            //echo "<label>Email:<input type=\"email\" name=\"Email\" value=\"$x[5]\"></label><br>\n";
            //echo "<label>Address:<input type=\"text\" name=\"address\" value=\"$x[6]\"></label><br>\n";
            //echo "<label>Categories:<input type=\"text\" name=\"Categories\" value=\"$x[7]\"></label><br>\n";
            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";
               }
               // if ($db_fields[$i][TYPE] == "date")
               // {
               //    $db_fields[$i][VALUE_FIELDS][0] = $_REQUEST[$name . "_min"];
               //    $db_fields[$i][VALUE_FIELDS][1] = $_REQUEST[$name . "_max"];
               // }
               // else
               {
                  $db_fields[$i][VALUE_FIELDS] = $_REQUEST[$name];
               }
            }
            //$id          = $_REQUEST['id'];
            //$name = $_REQUEST['nome'];
            //$db_value_fields[1] = $name;
            //$url_yellow  = $_REQUEST['url_yellow'];
            //$phone       = $_REQUEST['Phone'];
            //$url_address = $_REQUEST['url_address'];
            //$email       = $_REQUEST['Email'];
            //$address     = $_REQUEST['address'];
            //$categories  = $_REQUEST['Categories'];

            assert($db_fields[0][VALUE_FIELDS] != ""); // NOTE: PRIMARY KEY NOT NULL

            $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='$name',\n url_yellow='$url_yellow',\n Phone='$phone',\n url_address='$url_address',\n Email='$email',\n address='$address',\n Categories='$categories'"
               }
            }
            $query .= "\nWHERE " . $db_fields[0][PHP_NAME] . " = " . $db_fields[0][VALUE_FIELDS] . ";\n";
            //$query = "UPDATE 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;
               //exit();
            }
            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;
               //echo "<input type=\"hidden\" name=\"search_id\" value=\"$search_id\">\n";
               //echo "<input type=\"hidden\" name=\"search_name\" value=\"$search_name\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-yellow\" value=\"$search_url_yellow\">\n";
               //echo "<input type=\"hidden\" name=\"search_phone\" value=\"$search_phone\">\n";
               //echo "<input type=\"hidden\" name=\"search_url-address\" value=\"$search_url_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_email\" value=\"$search_email\">\n";
               //echo "<input type=\"hidden\" name=\"search_address\" value=\"$search_address\">\n";
               //echo "<input type=\"hidden\" name=\"search_categories\" value=\"$search_categories\">\n";
               $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")
                  {
                     /*
                       1973/06/17 15:30:00
                     */
                     $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";
                  }
               }
               //echo pre(htmlspecialchars($lines, ENT_QUOTES, 'UTF-8'));
               echo $lines;
               //echo "<label>Name: <input type=\"text\" name=\"nome\" value=\"\"></label><br>\n";
               //echo "<label>URL Yellow:<input type=\"url\" name=\"url_yellow\" value=\"\"></label><br>\n";
               //echo "<label>Phone#:<input type=\"tel\" name=\"Phone\" value=\"\"></label><br>\n";
               //echo "<label>URL:<input type=\"url\" name=\"url_address\" value=\"\"></label><br>\n";
               //echo "<label>Email:<input type=\"email\" name=\"Email\" value=\"\"></label><br>\n";
               //echo "<label>Address:<input type=\"text\" name=\"address\" value=\"\"></label><br>\n";
               //echo "<label>Categories:<input type=\"text\" name=\"Categories\" value=\"\"></label><br>\n";
               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";
               }
               // if ($db_fields[$i][TYPE] == "date")
               // {
               //    $db_fields[$i][VALUE_FIELDS][0] = trim($_REQUEST[$name . "_min"]);
               //    $db_fields[$i][VALUE_FIELDS][1] = trim($_REQUEST[$name . "_max"]);
               //    echo h1($db_fields[$i][ENGLISH_NAME] . " From =" . $db_fields[$i][VALUE_FIELDS][0]);
               //    echo h1($db_fields[$i][ENGLISH_NAME] . " To ="   . $db_fields[$i][VALUE_FIELDS][1]);
               // }
               // elseif ($db_fields[$i][TYPE] == "datetime")
               // {
               //    $db_fields[$i][VALUE_FIELDS][0] = trim($_REQUEST[$name . "_min"]);
               //    $db_fields[$i][VALUE_FIELDS][1] = trim($_REQUEST[$name . "_max"]);
               //    echo h1($db_fields[$i][ENGLISH_NAME] . " From =" . $db_fields[$i][VALUE_FIELDS][0]);
               //    echo h1($db_fields[$i][ENGLISH_NAME] . " To ="   . $db_fields[$i][VALUE_FIELDS][1]);
               // }
               // else
               // {
               $db_fields[$i][VALUE_FIELDS] = trim($_REQUEST[$name]);
               echo h1($db_fields[$i][ENGLISH_NAME] . "=" . $db_fields[$i][VALUE_FIELDS]);
               //}
            }
            //$id          = $_REQUEST['client_id'];
            //$name        = $_REQUEST['nome'];
            //$url_yellow  = $_REQUEST['url_yellow'];
            //$phone       = $_REQUEST['Phone'];
            //$url_address = $_REQUEST['url_address'];
            //$email       = $_REQUEST['Email'];
            //$address     = $_REQUEST['address'];
            //$categories  = $_REQUEST['Categories'];
            //echo h1("client_id=$id");
            //echo h1("name=$name");
            //echo h1("url_yellow=$url_yellow");
            //echo h1("phone=$phone");
            //echo h1("url_address=$url_address");
            //echo h1("email=$email");
            //echo h1("address=$address");
            //echo h1("categories=$categories");

            assert($db_fields[0][VALUE_FIELDS] != "");

//$result = mysqli_query($link,"INSERT INTO clients_table (id,name,url_yellow,Phone,url_address,Email,address,Categories) VALUES\n"
            //. "($client_id,'Davin','http://foo','123-4567','www.foo.com','foo@example.com','Annex Road','Boxes');\n");

            $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 .= "'" . slashes_to_minus_date($db_fields[$i][VALUE_FIELDS][1]) . "'";
               }
               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")
               {
                  //echo h1("value_fields=" . $db_fields[$i][VALUE_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";
            //$query  = "INSERT INTO clients_table (id,name,url_yellow,Phone,url_address,Email,address,Categories) VALUES\n"
            //. "($id,\n'$name',\n'$url_yellow',\n'$phone',\n'$url_address',\n'$email',\n'$address',\n'$categories'\n);\n";
            $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 "DUCKER";
               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;
         }
      }
   }
}

/*
<html>
<head>
<link rel="stylesheet" type="text/css" href="wp-content/themes/twentyeleven/style.css">
</head>
<body>
</body>
</html>
*/

?>
Back
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. Language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Sun Sep 25 16:11:08 NZDT 2016
Best viewed at 800x600 or above resolution.
© Copyright 1999-2016 Davin Pearson.
Please report any broken links to