-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec-query.php
227 lines (198 loc) · 6.26 KB
/
exec-query.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/*
Copyright (C) 2011 Thijs van Dijk
This file is part of CM-LDB.
CM-LDB is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CM-LDB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CM-LDB. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Execute a query, and display its result.
*/
require_once( "inc/db.inc" );
require_once( "inc/query.inc" );
require_once( 'inc/maillijst.inc' );
require_once( 'inc/openoffice.inc' );
require_once( 'inc/adresstickers.inc' );
$Q = Query::query_from_file();
if ( ! $Q )
{
die( "Query niet gevonden." );
}
function I($n)
{
return str_repeat(' ',4*$n);
}
function QSA( $map )
{
$qs = "";
foreach ( $map as $k => $v )
{
$qs .= "&" . urlencode($k) . "=" . urlencode($v);
}
if ( strlen($qs) > 0 ) { $qs = substr($qs,1); }
if ( strpos($_SERVER["REQUEST_URI"],'?') !== false )
{
return $_SERVER["REQUEST_URI"] . '&' . $qs;
}
else
{
return $_SERVER["REQUEST_URI"] . '?' . $qs;
}
}
$Result = $Q->execute();
function get_a_table()
{
global $Result;
$tn = @$_REQUEST["table"];
$table = @$Result[$tn];
if ( ! $table )
{
throw new Exception( "Er is geen tabel met de naam \"{$tn}\"." );
}
return $table;
}
if ( @$_REQUEST["as"] == "e-mail" )
{
$table = get_a_table();
header( "Content-type: text/plain" );
print( Maillijst::maak_lijst( $table ) );
exit;
}
elseif ( @$_REQUEST["as"] == "ods" )
{
Openoffice::SpreadSheet( $Result, $Q->Title );
exit;
}
elseif ( @$_REQUEST["as"] == "stickers" )
{
$table = get_a_table();
Adresstickers::quick_download( $table, $Q->Title );
exit;
}
header( "Content-type: text/html;charset=UTF-8" );
?><!DOCTYPE html>
<html>
<head>
<title><?=$Q->Title?></title>
<link type="text/css" href="/css/admina.css" rel="stylesheet" />
<style type="text/css">
span.maillijstlink
{
padding: 2px;
}
div.ods
{
margin: 10px 2px 10px 2px;
}
</style>
<script type="text/javascript" src="/js/admina.js"></script>
<script type="text/javascript" src="/js/ZeroClipboard.js"></script>
<script type="text/javascript">
$(function(){
$("#Table-tabs").tabs();
})
</script>
</head>
<body id="layout1280">
<div id="page" class="width">
<div class="ods"><a href="<?=QSA(array('as'=>'ods'))?>">Openen in OpenOffice</a></div>
<div id="Table-tabs">
<ul>
<?php
foreach ( array_keys($Result) as $table )
{
$tid = preg_replace('/[^a-zA-Z0-9]/','',$table);
print( " <li><a href=\"#table-$tid\">$table</a></li>\n" );
}
?>
</ul>
<?php
foreach ( $Result as $table=>$data )
{
$tid = preg_replace('/[^a-zA-Z0-9]/','',$table);
print( I(3)."<div id=\"table-$tid\">\n" );
print( I(4)."<div>\n" );
print( I(5)."<span class=\"total_count\">Totaal: <strong>".count($data)."</strong>.</span>\n" );
if ( isset($data[0]) && (isset($data[0]['email']) || isset($data[0]['Email'])) )
{
print( I(5)."<span class=\"maillijstlink\">" .
"<a id=\"maillijstlink_$tid\" href=\"" .
QSA(array('as'=>'e-mail','table'=>$table)) .
"\">Openen als maillijst</a></span>\n" );
Maillijst::klembordknop( "maillijstlink_$tid", Maillijst::maak_lijst($data),
array('height' => 18, 'width' => 135) );
}
if ( isset($data[0]) && (isset($data[0]['adres']) || isset($data[0]['Adres']))
&& (isset($data[0]['postcode']) || isset($data[0]['Postcode']))
&& (isset($data[0]['plaats']) || isset($data[0]['Plaats']))
) // TODO: Elegantere manier
{
print( I(5)."<a id=\"stickerlink_$tid\" href=\"" . QSA(array('as'=>'stickers','table'=>$table)) .
"\">Adresstickers maken</a></span>\n" );
}
print( I(5)."\n" );
print( I(4)."</div>\n" );
if ( count($data) > 0 )
{
print( I(4)."<table class=\"query-result\">\n" );
print( I(5)."<thead>\n" );
print( I(6)."<tr><th class=\"row-number\" />\n" );
foreach ( array_keys($data[0]) as $col )
{
print( I(7)."<th>{$col}</th>\n" );
}
print( I(6)."</tr>\n" );
print( I(5)."</tbody>\n" );
print( I(5)."<thead>\n" );
foreach ( $data as $i=>$row )
{
print( I(6)."<tr>\n" );
print( I(7)."<td class=\"row-number\">".($i+1)."</td>\n" );
foreach ( $row as $val )
{
print( I(7)."<td>{$val}</td>\n" );
}
print( I(6)."</tr>\n" );
}
print( I(5)."</tbody>\n" );
print( I(4)."</table>\n" );
}
print( I(3)."</div>\n" );
}
?>
</div>
<script type="text/javascript">
$(function(){
function reposition_clips()
{
var ind = $("#Table-tabs").tabs( "option", "selected" );
var id = $($("#Table-tabs > div")[ind]).attr('id').substr("table-".length);
for ( i in ZeroClipboard.clients )
{
var fid = ZeroClipboard.clients[i].domElement.id.
substr("maillijstlink_".length);
if ( id == fid )
{
ZeroClipboard.clients[i].show();
}
else
{
ZeroClipboard.clients[i].hide();
}
}
}
reposition_clips();
$("#Table-tabs").bind( "tabsshow", reposition_clips );
})
</script>
</div>
</body>
</html>