<?php
function mySQLOperator($op) {
/*echo('<option value="equal">' . $literals['GF_EQUAL'] . '</option>
<option value="notequal">' . $literals['GF_NOTEQUAL'] . '</option>
<option value="lessthan">' . $literals['GF_LT'] . '</option>
<option value="lte">' . $literals['GF_LTE'] . '</option>
<option value="greaterthan">' . $literals['GF_GT'] . '</option>
<option value="gte">' . $literals['GF_GTE'] . '</option>
<option value="like">' . $literals['GF_LIKE'] . '</option>
<option value="notlike">' . $literals['GF_NOTLIKE'] . '</option>
<option value="rlike">' . $literals['GF_RLIKE'] . '</option>
<option value="notrlike">' . $literals['GF_NOTRLIKE'] . '</option>
<option value="contains">' . $literals['GF_CONTAINS'] . '</option>
<option value="notcontains">' . $literals['GF_NOTCONTAINS'] . '</option>
<option value="between">' . $literals['GF_BETWEEN'] . '</option>
<option value="notbetween"*/
switch($op) {
case 'equal':
return '=';
case 'notequal':
return '!=';
case 'lessthan':
return '<';
case 'lte':
return '<=';
case 'greaterthan':
return '>';
case 'gte':
return '>=';
case 'like':
return 'LIKE';
case 'notlike':
return 'NOT LIKE';
case 'rlike':
return 'RLIKE';
case 'notrlike':
return 'NOT RLIKE';
case 'contains':
return 'LIKE';
case 'notcontains':
return 'NOT LIKE';
case 'between':
return 'BETWEEN';
case 'notbetween':
return 'NOT BETWEEN';
}
}
include("common_db.php");
include("functions.php");
dbconnect($host, $username, $password); //from common_db.php
$strings = loadStrings($lang, 'ADVRES');
headers();
html();
head($strings['ASR_TITLE']);
menu();
navpane();
?>
<div id="mainpane">
<?php
$db = mysql_real_escape_string($_REQUEST['database']);
$table = mysql_real_escape_string($_REQUEST['table']);
$count = intval($_REQUEST['count']); //number of conditions
//Build an array for the where clause
$where = '';
for($i = 0; $i < $count; $i++) {
$where_clause[$i] = '(';
if($_REQUEST["operator$i"] == 'contains' || $_REQUEST["operator$i"] == 'notcontains')
$_REQUEST["rvalue$i"] = '%' . mysql_real_escape_string($_REQUEST["rvalue$i"]) . '%';
else
$_REQUEST["rvalue$i"] = mysql_real_escape_string($_REQUEST["rvalue$i"]);
if($_REQUEST["lvalue$i"] == 'hypatia___allfields') {
//wonderful. We need to get, of all things, a list
//of all the fields in the table and build this into a nice long query
$where .= listFields('`%s` ' . mySQLOperator($_REQUEST["operator$i"]) . ' "' . str_replace('%', '%%', $_REQUEST["rvalue$i"]) . '" OR ', $db, $table);
//knock off the OR on the end
$where = substr($where, 0, -3);
$where_clause[$i] .= $where;
} else {
$where_clause[$i] .= '`' . $_REQUEST["lvalue$i"] . '` ' . mySQLOperator($_REQUEST["operator$i"]) . " '" . $_REQUEST["rvalue$i"] . "'";
}
$where_clause[$i] .= ')';
}
//Build the query
$query = "SELECT * FROM `$table` WHERE " . implode(" AND ", $where_clause);
//echo $query;
($results = mysql_query($query)) or die(mysql_error()); //TODO: L10N
print_query_results_func($results);
?>
</div>
<?php
endhtml();
?>