Passed
Pull Request — develop (#92)
by Felipe
04:47
created

src/controllers/AcinsertController.php (1 issue)

1
<?php
2
0 ignored issues
show
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
/**
10
 * Base controller class.
11
 */
12
class AcinsertController extends BaseController
13
{
14
    public $controller_name = 'AcinsertController';
15
16
    /**
17
     * Default method to render the controller according to the action parameter.
18
     */
19
    public function render()
20
    {
21
        $conf = $this->conf;
22
23
        $lang   = $this->lang;
24
        $data   = $this->misc->getDatabaseAccessor();
25
        $action = $this->action;
26
27
        if (isset($_POST['offset'])) {
28
            $offset = " OFFSET {$_POST['offset']}";
29
        } else {
30
            $_POST['offset'] = 0;
31
            $offset          = ' OFFSET 0';
32
        }
33
34
        $keynames = [];
35
        foreach ($_POST['fkeynames'] as $k => $v) {
36
            $fkeynames[$k] = html_entity_decode($v, ENT_QUOTES);
37
        }
38
39
        $keyspos = array_combine($fkeynames, $_POST['keys']);
40
41
        $f_schema = html_entity_decode($_POST['f_schema'], ENT_QUOTES);
42
        $data->fieldClean($f_schema);
43
        $f_table = html_entity_decode($_POST['f_table'], ENT_QUOTES);
44
        $data->fieldClean($f_table);
45
        $f_attname = $fkeynames[$_POST['fattpos'][0]];
46
        $data->fieldClean($f_attname);
47
48
        $q = "SELECT *
49
		FROM \"{$f_schema}\".\"{$f_table}\"
50
		WHERE \"{$f_attname}\"::text LIKE '{$_POST['fvalue']}%'
51
		ORDER BY \"{$f_attname}\" LIMIT 12 {$offset};";
52
53
        $res = $data->selectSet($q);
54
55
        if (!$res->EOF) {
56
            echo '<table class="ac_values">';
57
            echo '<tr>';
58
            foreach (array_keys($res->fields) as $h) {
59
                echo '<th>';
60
61
                if (in_array($h, $fkeynames, true)) {
62
                    echo '<img src="'.$this->misc->icon('ForeignKey').'" alt="[referenced key]" />';
63
                }
64
65
                echo htmlentities($h, ENT_QUOTES, 'UTF-8'), '</th>';
66
            }
67
            echo "</tr>\n";
68
            $i = 0;
69
            while ((!$res->EOF) && ($i < 11)) {
70
                $j = 0;
71
                echo '<tr class="acline">';
72
                foreach ($res->fields as $n => $v) {
73
                    $finfo = $res->fetchField($j++);
74
                    if (in_array($n, $fkeynames, true)) {
75
                        echo "<td><a href=\"javascript:void(0)\" class=\"fkval\" name=\"{$keyspos[$n]}\">",
76
                        $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']),
77
                            '</a></td>';
78
                    } else {
79
                        echo '<td><a href="javascript:void(0)">',
80
                        $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']),
81
                            '</a></td>';
82
                    }
83
                }
84
                echo "</tr>\n";
85
                ++$i;
86
                $res->moveNext();
87
            }
88
            echo "</table>\n";
89
90
            $page_tests = '';
91
92
            $js = "<script type=\"text/javascript\">\n";
93
94
            if ($_POST['offset']) {
95
                echo '<a href="javascript:void(0)" id="fkprev">&lt;&lt; Prev</a>';
96
                $js .= "fkl_hasprev=true;\n";
97
            } else {
98
                $js .= "fkl_hasprev=false;\n";
99
            }
100
101
            if (12 == $res->recordCount()) {
102
                $js .= "fkl_hasnext=true;\n";
103
                echo '&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" id="fknext">Next &gt;&gt;</a>';
104
            } else {
105
                $js .= "fkl_hasnext=false;\n";
106
            }
107
108
            echo $js.'</script>';
109
        } else {
110
            printf("<p>{$lang['strnofkref']}</p>", "\"{$_POST['f_schema']}\".\"{$_POST['f_table']}\".\"{$fkeynames[$_POST['fattpos']]}\"");
111
112
            if ($_POST['offset']) {
113
                echo '<a href="javascript:void(0)" class="fkprev">Prev &lt;&lt;</a>';
114
            }
115
        }
116
    }
117
}
118