forked from phppgadmin/phppgadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax-ac-insert.php
92 lines (76 loc) · 2.43 KB
/
ajax-ac-insert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
include_once('./libraries/lib.inc.php');
if(isset($_POST['offset']))
$offset = " OFFSET {$_POST['offset']}";
else {
$_POST['offset'] = 0;
$offset = " OFFSET 0";
}
$keynames = array();
foreach ($_POST['fkeynames'] as $k => $v) {
$fkeynames[$k] = html_entity_decode($v, ENT_QUOTES);
}
$keyspos = array_combine($fkeynames, $_POST['keys']);
$f_schema = html_entity_decode($_POST['f_schema'], ENT_QUOTES);
$data->fieldClean($f_schema);
$f_table = html_entity_decode($_POST['f_table'], ENT_QUOTES);
$data->fieldClean($f_table);
$f_attname = $fkeynames[$_POST['fattpos'][0]];
$data->fieldClean($f_attname);
$q = "SELECT *
FROM \"{$f_schema}\".\"{$f_table}\"
WHERE \"{$f_attname}\"::text LIKE '{$_POST['fvalue']}%'
ORDER BY \"{$f_attname}\" LIMIT 12 {$offset};";
$res = $data->selectSet($q);
if (!$res->EOF) {
echo "<table class=\"ac_values\">";
echo '<tr>';
foreach (array_keys($res->fields) as $h) {
echo '<th>';
if (in_array($h, $fkeynames))
echo '<img src="'. $misc->icon('ForeignKey') .'" alt="[referenced key]" />';
echo htmlentities($h, ENT_QUOTES, 'UTF-8'), '</th>';
}
echo "</tr>\n";
$i=0;
while ((!$res->EOF) && ($i < 11)) {
$j=0;
echo "<tr class=\"acline\">";
foreach ($res->fields as $n => $v) {
$finfo = $res->fetchField($j++);
if (in_array($n, $fkeynames))
echo "<td><a href=\"javascript:void(0)\" class=\"fkval\" name=\"{$keyspos[$n]}\">",
$misc->printVal($v, $finfo->type, array('clip' => 'collapsed')),
"</a></td>";
else
echo "<td><a href=\"javascript:void(0)\">",
$misc->printVal($v, $finfo->type, array('clip' => 'collapsed')),
"</a></td>";
}
echo "</tr>\n";
$i++;
$res->moveNext();
}
echo "</table>\n";
$page_tests='';
$js = "<script type=\"text/javascript\">\n";
if ($_POST['offset']) {
echo "<a href=\"javascript:void(0)\" id=\"fkprev\"><< Prev</a>";
$js.= "fkl_hasprev=true;\n";
}
else
$js.= "fkl_hasprev=false;\n";
if ($res->recordCount() == 12) {
$js.= "fkl_hasnext=true;\n";
echo " <a href=\"javascript:void(0)\" id=\"fknext\">Next >></a>";
}
else
$js.= "fkl_hasnext=false;\n";
echo $js ."</script>";
}
else {
printf("<p>{$lang['strnofkref']}</p>", "\"{$_POST['f_schema']}\".\"{$_POST['f_table']}\".\"{$fkeynames[$_POST['fattpos']]}\"");
if ($_POST['offset'])
echo "<a href=\"javascript:void(0)\" class=\"fkprev\">Prev <<</a>";
}
?>