<?php
@package@version
function array_length($array)
{
if (!is_array($array))
{
if (is_string($array))
{
echo h1("Arg to array_length is a string=$array");
return 0;
assert }
else
{
echo h1("arg to array_length not an array");
assert(false);
}
exit();
}
$len = 0;
if (!empty($array))
{
foreach ($array as $a)
{
$len++;
}
}
return $len;
}
function array_print($array)
{
echo "BEG printing array<br>\n";
$i = 0;
foreach ($array as $a)
{
echo "line=$i: $a . <br>";
$i++;
}
echo "END printing array<br>\n";
}
function mysubstr($string,$from,$to)
{
$result = "";
for ($i = $from; $i < $to; $i++)
{
$result .= $string[$i];
}
return $result;
}
function mystrpos($string,$contains)
{
for ($i = 0; $i < strlen($string); $i++)
{
if ($string[$i] == $contains)
{
h1 return $i;
}
}
h1 return -1;
}
function pre($arg)
{
return "<pre>$arg</pre>\n";
}
function h1($title)
{
return "<h1><span class=bold>$title</span></h1>\n";
}
function h1error($title)
{
return "<span class=\"error\">$title</span><br><br>\n";
}
function h1ok($title)
{
return "<span class=\"ok\">$title</span><br><br>\n";
}
function h1debug($title)
{
return "<span class=\"debug\">$title</span><br><br>\n";
}
function readCSV($csvFile)
{
$file_handle = null;
if (file_exists($csvFile))
{
$file_handle = fopen($csvFile, 'r');
}
if ($file_handle == null)
{
echo "<h1>File not found: $csvFile</h1>\n";
exit();
}
$file_handle while (!feof($file_handle))
{
$line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return $line_of_text;
}
function DD_MM_YYYY_to_YYYY_MM_DD($arg)
{
assert(is_string($arg));
if (substr($arg,2,1) != "/")
{
echo h1("substr($arg,2,1)=" . substr($arg,2,1));
assert }
if (substr($arg,5,1) != "/")
{
echo h1("substr($arg,5,1)=" . substr($arg,5,1));
assert }
$yyyy = substr($arg,6,4);
$mm = substr($arg,3,2);
$dd = substr($arg,0,2);
h1$yyyy h1$mm h1$dd return $yyyy . "-" . $mm . "-" . $dd;
}
function slashes_to_minus_date($arg)
{
h1$arg if ($arg != "")
{
assert(my_is_string($arg));
if (substr($arg,4,1) != "/")
{
echo h1("substr($arg,2,1)=" . substr($arg,4,1));
assert(false);
}
if (substr($arg,7,1) != "/")
{
echo h1("substr($arg,5,1)=" . substr($arg,7,1));
assert(false);
}
$yyyy = substr($arg,6,4);
$mm = substr($arg,3,2);
$dd = substr($arg,0,2);
h1$arg return $yyyy . "-" . $mm . "-" . $dd;
}
h1$arg return "";
}
function slashes_to_minus_datetime($arg)
{
h1$arg $arg if ($arg != "")
{
assert(my_is_string($arg));
if ((substr($arg,4,1) != "/") and (substr($arg,4,1) != "-"))
{
echo h1("substr($arg,4,1)=" . substr($arg,4,1));
assert(false);
}
if ((substr($arg,7,1) != "/") and (substr($arg,7,1) != "-"))
{
echo h1("substr($arg,7,1)=" . substr($arg,7,1));
assert(false);
}
if (substr($arg,10,1) != " ")
{
echo h1("substr($arg,10,1)=" . substr($arg,10,1));
assert(false);
}
if (substr($arg,13,1) != ":")
{
echo h1("substr($arg,13,1)=" . substr($arg,13,1));
assert(false);
}
if (substr($arg,16,1) != ":")
{
echo h1("substr($arg,16,1)=" . substr($arg,16,1));
assert(false);
}
$yyyy = substr($arg, 0,4);
$mm = substr($arg, 5,2);
$dd = substr($arg, 8,2);
$hh = substr($arg,11,2);
$MM = substr($arg,14,2);
$ss = substr($arg,17,2);
h1$arg return $yyyy . "-" . $mm . "-" . $dd . " " . $hh . ":" . $MM . ":" . $ss;
}
h1$arg return "";
}
function my_is_string($candidate)
{
return $candidate == "" or is_string($candidate);
}
pre$hidden_search_fieldspre$href_search_fields
function calculate_hidden_fields()
{
global $db_fields;
$result = "";
for ($i = 0; $i < array_length($db_fields); $i++)
{
if ($db_fields[$i][TYPE] == "date")
{
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_min\" value=\"" . $db_fields[$i][SEARCH_FIELDS][0] . "\">\n";
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_max\" value=\"" . $db_fields[$i][SEARCH_FIELDS][1] . "\">\n";
}
elseif ($db_fields[$i][TYPE] == "time")
{
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_min\" value=\"" . $db_fields[$i][SEARCH_FIELDS][0] . "\">\n";
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_max\" value=\"" . $db_fields[$i][SEARCH_FIELDS][1] . "\">\n";
}
elseif ($db_fields[$i][TYPE] == "datetime")
{
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_min\" value=\"" . $db_fields[$i][SEARCH_FIELDS][0] . "\">\n";
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "_max\" value=\"" . $db_fields[$i][SEARCH_FIELDS][1] . "\">\n";
}
else
{
$result .= " <input type=\"hidden\" name=\"search_" . $db_fields[$i][PHP_NAME] . "\" value=\"" . $db_fields[$i][SEARCH_FIELDS] . "\">\n";
}
}
return $result;
}
function calculate_click_here_to_continue()
{
global $db_fields,$page_id,$offset,$limit,$order_by,$asc,$like,$username,$password;
$c = "<a href=\"?page_id=$page_id&action=browser&offset=$offset&limit=$limit&order-by=$order_by&asc=$asc&like=$like&username=$username&encoded=1&password=$password";
for ($i = 0; $i < array_length($db_fields); $i++)
{
$s = $db_fields[$i][SEARCH_FIELDS];
if (my_is_string($s))
{
$c .= "&search_" . $db_fields[$i][PHP_NAME] . "=" . $s;
$search_id$search_name$search_url_yellow$search_phone$search_url_address$search_email$search_address$search_categories }
else
{
$c .= "&search_" . $db_fields[$i][PHP_NAME] . "_min=" . $db_fields[$i][SEARCH_FIELDS][0];
$c .= "&search_" . $db_fields[$i][PHP_NAME] . "_max=" . $db_fields[$i][SEARCH_FIELDS][1];
}
}
$c .= "&r=" . rand() . "#start-here\">Click here to just return to the client browser</a>";
$c = h1($c);
return $c;
}
function get_create_table_query()
{
global $db_fields, $db_database;
$query = "";
$query$db_database $query .= "USE $db_database;\n\n";
$query .= "DROP TABLE clients_table;\n\n";
$query .= "CREATE TABLE clients_table (\n";
for ($i = 0; $i<array_length($db_fields); $i++)
{
if ($i != 0)
{
$query .= ", ";
}
$query .= $db_fields[$i][PHP_NAME] . " " . $db_fields[$i][MYSQL_INIT] . "\n";
}
$query .= ") DEFAULT CHARACTER SET utf8;\n\n";
return $query;
}
function get_insert_table_query()
{
global $db_hostname, $db_username, $db_password, $db_database;
global $db_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();
}
$here_is_the_sql_query = "<span class=\"big-black\">Here is the SQL query:</span><br>\n";
$query = "USE $db_database;\n\n";
$result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("USE query failed");
echo $here_is_the_sql_query;
echo pre($query);
echo calculate_click_here_to_continue();
exit();
}
$query = "SELECT ";
for ($i=0; $i<array_length($db_fields); $i++)
{
if ($i > 0)
{
$query .= ",";
}
$query .= $db_fields[$i][PHP_NAME];
}
$query .= " FROM clients_table;\n";
$querySELECT id,name,url_yellow,phone,url_address,email,address,categories,time_fixed FROM clients_table;\n";
$result = mysqli_query($link,$query);
if (!$result)
{
echo h1error("SELECT query failed:");
echo $here_is_the_sql_query;
echo pre($query);
echo calculate_click_here_to_continue();
exit();
}
$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 $nrows = 0;
h1 while ($x = mysqli_fetch_array($result))
{
h1$nrows if ($nrows != 0)
{
$query .= ",";
}
$query .= "(";
for ($i = 0; $i<array_length($db_fields); $i++)
{
if ($i != 0)
{
$query .= ",";
}
$query .= "'" . escape_quotes($x[$i]) . "'";
}
$query .= ")\n";
$nrows++;
}
if ($nrows == 0)
{
$query = "";
}
else
{
$query .= ";\n";
}
return $query;
}
function my_explode($str)
{
$len = strlen($str);
$newarray = array();
$newstr = "";
for ($i = 0; $i<$len; $i++)
{
$ch = $str[$i];
if ($ch == '\'')
{
$newstr .= $ch;
$i++;
while (($ch = $str[$i]) != '\'')
{
if ($ch == '\\')
{
$i++;
$ch = $str[$i];
$newstr .= "\\" . $ch;
$i++;
$ch = $str[$ch];
}
else
{
$newstr .= $ch;
$i++;
}
}
assert($ch == '\'');
$newstr .= $ch;
}
elseif ($ch == ';')
{
$newarray[] = $newstr;
$newstr = "";
}
else
{
$newstr .= $ch;
}
}
return $newarray;
}
function escape_quotes($str)
{
assert(my_is_string($str));
$len = strlen($str);
for ($i=0; $i<$len; $i++)
{
$ch = $str[$i];
if ($ch == '\'')
{
$result .= "\\'";
}
else
{
$result .= $ch;
}
}
return $result;
}
?>