Total Complexity | 20 |
Total Lines | 244 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class HistoryController extends BaseController |
||
15 | { |
||
16 | public $controller_name = 'HistoryController'; |
||
17 | |||
18 | /** |
||
19 | * Default method to render the controller according to the action parameter. |
||
20 | */ |
||
21 | public function render() |
||
22 | { |
||
23 | $lang = $this->lang; |
||
24 | $action = $this->action; |
||
25 | |||
26 | $data = $this->misc->getDatabaseAccessor(); |
||
27 | |||
28 | $this->scripts = '<script type="text/javascript">window.inPopUp=true;</script>'; |
||
29 | |||
30 | switch ($action) { |
||
31 | case 'confdelhistory': |
||
32 | $this->doDelHistory($_REQUEST['queryid'], true); |
||
33 | |||
34 | break; |
||
35 | case 'delhistory': |
||
36 | if (isset($_POST['yes'])) { |
||
37 | $this->doDelHistory($_REQUEST['queryid'], false); |
||
38 | } |
||
39 | |||
40 | $this->doDefault(); |
||
41 | |||
42 | break; |
||
43 | case 'confclearhistory': |
||
44 | $this->doClearHistory(true); |
||
45 | |||
46 | break; |
||
47 | case 'clearhistory': |
||
48 | if (isset($_POST['yes'])) { |
||
49 | $this->doClearHistory(false); |
||
50 | } |
||
51 | |||
52 | $this->doDefault(); |
||
53 | |||
54 | break; |
||
55 | case 'download': |
||
56 | return $this->doDownloadHistory(); |
||
57 | default: |
||
58 | $this->doDefault(); |
||
59 | } |
||
60 | |||
61 | // Set the name of the window |
||
62 | $this->setWindowName('history'); |
||
63 | |||
64 | return $this->printFooter(); |
||
65 | } |
||
66 | |||
67 | public function doDefault() |
||
1 ignored issue
–
show
|
|||
68 | { |
||
69 | $lang = $this->lang; |
||
70 | $data = $this->misc->getDatabaseAccessor(); |
||
71 | |||
72 | $onchange = "onchange=\"location.href='" . \SUBFOLDER . "/src/views/history.php?server=' + encodeURI(server.options[server.selectedIndex].value) + '&database=' + encodeURI(database.options[database.selectedIndex].value) + '&'\""; |
||
73 | |||
74 | $this->printHeader($lang['strhistory'], $this->scripts, true, 'header.twig'); |
||
75 | |||
76 | // Bring to the front always |
||
77 | echo "<body onload=\"window.focus();\">\n"; |
||
78 | |||
79 | echo '<form action="' . \SUBFOLDER . "/src/views/history.php\" method=\"post\">\n"; |
||
80 | $this->misc->printConnection($onchange); |
||
81 | echo '</form><br />'; |
||
82 | |||
83 | if (!isset($_REQUEST['database'])) { |
||
84 | echo "<p>{$lang['strnodatabaseselected']}</p>\n"; |
||
85 | |||
86 | return; |
||
87 | } |
||
88 | |||
89 | if (isset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']])) { |
||
90 | $history = new \PHPPgAdmin\ArrayRecordSet($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']]); |
||
91 | |||
92 | //Kint::dump($history); |
||
93 | $columns = [ |
||
94 | 'query' => [ |
||
95 | 'title' => $lang['strsql'], |
||
96 | 'field' => Decorator::field('query'), |
||
97 | ], |
||
98 | 'paginate' => [ |
||
99 | 'title' => $lang['strpaginate'], |
||
100 | 'field' => Decorator::field('paginate'), |
||
101 | 'type' => 'yesno', |
||
102 | ], |
||
103 | 'actions' => [ |
||
104 | 'title' => $lang['stractions'], |
||
105 | ], |
||
106 | ]; |
||
107 | |||
108 | $actions = [ |
||
109 | 'run' => [ |
||
110 | 'content' => $lang['strexecute'], |
||
111 | 'attr' => [ |
||
112 | 'href' => [ |
||
113 | 'url' => 'sql.php', |
||
114 | 'urlvars' => [ |
||
115 | 'subject' => 'history', |
||
116 | 'nohistory' => 't', |
||
117 | 'queryid' => Decorator::field('queryid'), |
||
118 | 'paginate' => Decorator::field('paginate'), |
||
119 | ], |
||
120 | ], |
||
121 | 'target' => 'detail', |
||
122 | ], |
||
123 | ], |
||
124 | 'remove' => [ |
||
125 | 'content' => $lang['strdelete'], |
||
126 | 'attr' => [ |
||
127 | 'href' => [ |
||
128 | 'url' => 'history.php', |
||
129 | 'urlvars' => [ |
||
130 | 'action' => 'confdelhistory', |
||
131 | 'queryid' => Decorator::field('queryid'), |
||
132 | ], |
||
133 | ], |
||
134 | ], |
||
135 | ], |
||
136 | ]; |
||
137 | |||
138 | echo $this->printTable($history, $columns, $actions, 'history-history', $lang['strnohistory']); |
||
139 | } else { |
||
140 | echo "<p>{$lang['strnohistory']}</p>\n"; |
||
141 | } |
||
142 | |||
143 | $navlinks = [ |
||
144 | 'refresh' => [ |
||
145 | 'attr' => [ |
||
146 | 'href' => [ |
||
147 | 'url' => 'history.php', |
||
148 | 'urlvars' => [ |
||
149 | 'action' => 'history', |
||
150 | 'server' => $_REQUEST['server'], |
||
151 | 'database' => $_REQUEST['database'], |
||
152 | ], |
||
153 | ], |
||
154 | ], |
||
155 | 'content' => $lang['strrefresh'], |
||
156 | ], |
||
157 | ]; |
||
158 | |||
159 | if (isset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']]) |
||
160 | && count($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']])) { |
||
1 ignored issue
–
show
|
|||
161 | $navlinks['download'] = [ |
||
162 | 'attr' => [ |
||
163 | 'href' => [ |
||
164 | 'url' => 'history.php', |
||
165 | 'urlvars' => [ |
||
166 | 'action' => 'download', |
||
167 | 'server' => $_REQUEST['server'], |
||
168 | 'database' => $_REQUEST['database'], |
||
169 | ], |
||
170 | ], |
||
171 | ], |
||
172 | 'content' => $lang['strdownload'], |
||
173 | ]; |
||
174 | $navlinks['clear'] = [ |
||
175 | 'attr' => [ |
||
176 | 'href' => [ |
||
177 | 'url' => 'history.php', |
||
178 | 'urlvars' => [ |
||
179 | 'action' => 'confclearhistory', |
||
180 | 'server' => $_REQUEST['server'], |
||
181 | 'database' => $_REQUEST['database'], |
||
182 | ], |
||
183 | ], |
||
184 | ], |
||
185 | 'content' => $lang['strclearhistory'], |
||
186 | ]; |
||
187 | } |
||
188 | |||
189 | $this->printNavLinks($navlinks, 'history-history', get_defined_vars()); |
||
190 | } |
||
191 | |||
192 | public function doDelHistory($qid, $confirm) |
||
1 ignored issue
–
show
|
|||
193 | { |
||
194 | $lang = $this->lang; |
||
195 | $data = $this->misc->getDatabaseAccessor(); |
||
196 | |||
197 | if ($confirm) { |
||
198 | $this->printHeader($lang['strhistory'], $this->scripts); |
||
199 | |||
200 | // Bring to the front always |
||
201 | echo "<body onload=\"window.focus();\">\n"; |
||
202 | |||
203 | echo "<h3>{$lang['strdelhistory']}</h3>\n"; |
||
204 | echo "<p>{$lang['strconfdelhistory']}</p>\n"; |
||
205 | |||
206 | echo '<pre>', htmlentities($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']][$qid]['query'], ENT_QUOTES, 'UTF-8'), '</pre>'; |
||
207 | echo '<form action="' . \SUBFOLDER . "/src/views/history.php\" method=\"post\">\n"; |
||
208 | echo "<input type=\"hidden\" name=\"action\" value=\"delhistory\" />\n"; |
||
209 | echo "<input type=\"hidden\" name=\"queryid\" value=\"${qid}\" />\n"; |
||
210 | echo $this->misc->form; |
||
211 | echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n"; |
||
212 | echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n"; |
||
213 | echo "</form>\n"; |
||
214 | } else { |
||
215 | unset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']][$qid]); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | public function doClearHistory($confirm) |
||
241 | } |
||
242 | } |
||
243 | |||
244 | public function doDownloadHistory() |
||
258 | } |
||
259 | } |
||
261 |