|
1
|
|
|
<?php |
|
2
|
|
|
/************************************************************************** |
|
3
|
|
|
********** English Wikipedia Account Request Interface ********** |
|
4
|
|
|
*************************************************************************** |
|
5
|
|
|
** Wikipedia Account Request Graphic Design by Charles Melbye, ** |
|
6
|
|
|
** which is licensed under a Creative Commons ** |
|
7
|
|
|
** Attribution-Noncommercial-Share Alike 3.0 United States License. ** |
|
8
|
|
|
** ** |
|
9
|
|
|
** All other code are released under the Public Domain ** |
|
10
|
|
|
** by the ACC Development Team. ** |
|
11
|
|
|
** ** |
|
12
|
|
|
** See CREDITS for the list of developers. ** |
|
13
|
|
|
***************************************************************************/ |
|
14
|
|
|
|
|
15
|
|
|
class QueryBrowser |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var boolean |
|
19
|
|
|
*/ |
|
20
|
|
|
public $numberedList = false; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
public $numberedListTitle = "#"; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var boolean|callable |
|
29
|
|
|
*/ |
|
30
|
|
|
public $tableCallbackFunction = false; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var boolean|string[] |
|
34
|
|
|
*/ |
|
35
|
|
|
public $overrideTableTitles = false; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var int |
|
39
|
|
|
*/ |
|
40
|
|
|
public $rowFetchMode = PDO::FETCH_ASSOC; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $query |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function executeQueryToTable($query) |
|
47
|
|
|
{ |
|
48
|
|
|
$out = ""; |
|
49
|
|
|
|
|
50
|
|
|
$results = $this->executeQueryToArray($query); |
|
51
|
|
|
|
|
52
|
|
|
$out .= '<table class="table table-striped table-hover table-condensed"><tr>'; |
|
53
|
|
|
|
|
54
|
|
|
if ($this->numberedList == true) { |
|
|
|
|
|
|
55
|
|
|
$out .= "<th>" . $this->numberedListTitle . "</th>"; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ($this->overrideTableTitles != false) { |
|
59
|
|
|
foreach ($this->overrideTableTitles as $value) { |
|
60
|
|
|
$out .= "<th>" . $value . "</th>"; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
else { |
|
64
|
|
|
if (count($results) > 0) { |
|
65
|
|
|
foreach ($results[0] as $k => $v) { |
|
66
|
|
|
$out .= "<th>" . $k . "</th>"; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
$out .= "</tr>"; |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$currentreq = 0; |
|
74
|
|
|
foreach ($results as $row) { |
|
75
|
|
|
$currentreq++; |
|
76
|
|
|
if (function_exists($this->tableCallbackFunction)) { |
|
|
|
|
|
|
77
|
|
|
$out .= call_user_func($this->tableCallbackFunction, $row, $currentreq); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
else { |
|
80
|
|
|
$out .= '<tr>'; |
|
81
|
|
|
|
|
82
|
|
|
if ($this->numberedList == true) { |
|
|
|
|
|
|
83
|
|
|
$out .= "<th>" . $currentreq . "</th>"; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
foreach ($row as $cell) { |
|
88
|
|
|
|
|
89
|
|
|
$out .= "<td>" . $cell . "</td>"; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$out .= "</tr>"; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$out .= "</table>"; |
|
99
|
|
|
|
|
100
|
|
|
return $out; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function executeQueryToArray($query) |
|
104
|
|
|
{ |
|
105
|
|
|
$database = gGetDb(); |
|
106
|
|
|
|
|
107
|
|
|
$statement = $database->prepare($query); |
|
108
|
|
|
|
|
109
|
|
|
$statement->execute(); |
|
110
|
|
|
|
|
111
|
|
|
return $statement->fetchAll($this->rowFetchMode); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.