forked from vrana/adminer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd-button-column-header.php
More file actions
58 lines (48 loc) · 1.9 KB
/
Copy pathadd-button-column-header.php
File metadata and controls
58 lines (48 loc) · 1.9 KB
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
<?php
/** Add a quick link under each header column
* @author Andrea Mariani, https://fasys.it
*/
class AdminerAddButtonColumnHeader extends Adminer\Plugin {
const DISTINCT = "DISTINCT";
private $tableName;
private $buttons;
function __construct($buttons = [self::DISTINCT]) {
$this->buttons = $buttons;
}
function tableName($tableStatus){
$this->tableName = $tableStatus['Name'];
}
function selectColumnsPrint() {
?>
<script<?php echo Adminer\nonce() ?> type="text/javascript">
function domReady(fn) {
document.addEventListener("DOMContentLoaded", fn);
if (document.readyState === "interactive" || document.readyState === "complete" ) {
fn();
}
}
function closest(el, tag) {
while (el && el.nodeName !== tag) {
el = el.parentElement;
}
return el;
}
domReady(() => {
document.querySelectorAll("table#table thead th .column").forEach(el => {
const fieldname = closest(el, 'TH').innerText;
<?php
foreach($this->buttons as $button) {
switch($button){
case self::DISTINCT:
echo "el.insertAdjacentHTML(\"beforeend\", \"<div class='AdminerAddButtonColumnHeader'><a href='?username=". $_GET['username'] ."&db=" . $_GET['db'] ."&sql=SELECT `\"+ fieldname +\"`, COUNT(`\"+ fieldname +\"`) AS total FROM `". $this->tableName ."` GROUP BY `\" + fieldname +\"`;'>Distinct</a></div>\");";
break;
//TODO: waiting for other ideas...
}
}
?>
});
});
</script>
<?php
}
}