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