Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AcinsertController.php « controllers « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9aa2d6cb34c44572d658a945b6f69b595c483c65 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php

/**
 * PHPPgAdmin 6.1.2
 */

namespace PHPPgAdmin\Controller;

/**
 * AcinsertController controller class.
 */
class AcinsertController extends BaseController
{
    /**
     * Default method to render the controller according to the action parameter.
     */
    public function render(): void
    {
        $data = $this->misc->getDatabaseAccessor();

        if (isset($_POST['offset'])) {
            $offset = " OFFSET {$_POST['offset']}";
        } else {
            $_POST['offset'] = 0;
            $offset = ' OFFSET 0';
        }

        $fkeynames = [];

        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, true)) {
                    echo '<img src="' . $this->view->icon('ForeignKey') . '" alt="[referenced key]" />';
                }

                echo \htmlentities($h, \ENT_QUOTES, 'UTF-8'), '</th>';
            }
            echo '</tr>' . \PHP_EOL;
            $i = 0;

            while ((!$res->EOF) && (11 > $i)) {
                $j = 0;
                echo '<tr class="acline">';

                foreach ($res->fields as $n => $v) {
                    $finfo = $res->fetchField($j++);

                    if (\in_array($n, $fkeynames, true)) {
                        echo "<td><a href=\"javascript:void(0)\" class=\"fkval\" name=\"{$keyspos[$n]}\">",
                        $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']),
                            '</a></td>';
                    } else {
                        echo '<td><a href="javascript:void(0)">',
                        $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']),
                            '</a></td>';
                    }
                }
                echo '</tr>' . \PHP_EOL;
                ++$i;
                $res->moveNext();
            }
            echo '</table>' . \PHP_EOL;

            $js = '<script type="text/javascript">' . \PHP_EOL;

            if ($_POST['offset']) {
                echo '<a href="javascript:void(0)" id="fkprev">&lt;&lt; Prev</a>';
                $js .= "fkl_hasprev=true;\n";
            } else {
                $js .= "fkl_hasprev=false;\n";
            }

            if (12 === $res->recordCount()) {
                $js .= "fkl_hasnext=true;\n";
                echo '&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" id="fknext">Next &gt;&gt;</a>';
            } else {
                $js .= "fkl_hasnext=false;\n";
            }

            echo $js . '</script>';
        } else {
            \printf("<p>{$this->lang['strnofkref']}</p>", "\"{$_POST['f_schema']}\".\"{$_POST['f_table']}\".\"{$fkeynames[$_POST['fattpos']]}\"");

            if ($_POST['offset']) {
                echo '<a href="javascript:void(0)" class="fkprev">Prev &lt;&lt;</a>';
            }
        }
    }
}