1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* List reports in a database
|
5
|
*
|
6
|
* $Id: reports.php,v 1.22 2005/10/18 03:45:16 chriskl Exp $
|
7
|
*/
|
8
|
|
9
|
// Include application functions
|
10
|
include_once('./libraries/lib.inc.php');
|
11
|
|
12
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
13
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
14
|
|
15
|
/**
|
16
|
* Displays a screen where they can edit a report
|
17
|
*/
|
18
|
function doEdit($msg = '') {
|
19
|
global $data, $reportsdb, $misc;
|
20
|
global $PHP_SELF, $lang;
|
21
|
|
22
|
// If it's a first, load then get the data from the database
|
23
|
$report = $reportsdb->getReport($_REQUEST['report_id']);
|
24
|
if ($_REQUEST['action'] == 'edit') {
|
25
|
$_POST['report_name'] = $report->f['report_name'];
|
26
|
$_POST['db_name'] = $report->f['db_name'];
|
27
|
$_POST['descr'] = $report->f['descr'];
|
28
|
$_POST['report_sql'] = $report->f['report_sql'];
|
29
|
}
|
30
|
|
31
|
// Get a list of available databases
|
32
|
$databases = $data->getDatabases();
|
33
|
|
34
|
$_REQUEST['report'] = $report->f['report_name'];
|
35
|
$misc->printTrail('report');
|
36
|
$misc->printTitle($lang['stredit']);
|
37
|
$misc->printMsg($msg);
|
38
|
|
39
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
40
|
echo $misc->form;
|
41
|
echo "<table width=\"100%\">\n";
|
42
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
|
43
|
echo "<td class=\"data1\"><input name=\"report_name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
44
|
htmlspecialchars($_POST['report_name']), "\" /></td></tr>\n";
|
45
|
echo "<tr><th class=\"data left required\">{$lang['strdatabase']}</th>\n";
|
46
|
echo "<td class=\"data1\"><select name=\"db_name\">\n";
|
47
|
while (!$databases->EOF) {
|
48
|
$dbname = $databases->f['datname'];
|
49
|
echo "<option value=\"", htmlspecialchars($dbname), "\"",
|
50
|
($dbname == $_POST['db_name']) ? ' selected="selected"' : '', ">",
|
51
|
htmlspecialchars($dbname), "</option>\n";
|
52
|
$databases->moveNext();
|
53
|
}
|
54
|
echo "</select></td></tr>\n";
|
55
|
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
|
56
|
echo "<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"5\" cols=\"50\" name=\"descr\" wrap=\"virtual\">",
|
57
|
htmlspecialchars($_POST['descr']), "</textarea></td></tr>\n";
|
58
|
echo "<tr><th class=\"data left required\">{$lang['strsql']}</th>\n";
|
59
|
echo "<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"15\" cols=\"50\" name=\"report_sql\" wrap=\"virtual\">",
|
60
|
htmlspecialchars($_POST['report_sql']), "</textarea></td></tr>\n";
|
61
|
echo "</table>\n";
|
62
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
|
63
|
echo "<input type=\"submit\" value=\"{$lang['strsave']}\" />\n";
|
64
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
65
|
echo "<input type=\"hidden\" name=\"report_id\" value=\"{$report->f['report_id']}\" />\n";
|
66
|
echo "</form>\n";
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Saves changes to a report
|
71
|
*/
|
72
|
function doSaveEdit() {
|
73
|
global $reportsdb, $lang;
|
74
|
|
75
|
if (!isset($_POST['report_name'])) $_POST['report_name'] = '';
|
76
|
if (!isset($_POST['db_name'])) $_POST['db_name'] = '';
|
77
|
if (!isset($_POST['descr'])) $_POST['descr'] = '';
|
78
|
if (!isset($_POST['report_sql'])) $_POST['report_sql'] = '';
|
79
|
|
80
|
// Check that they've given a name and a definition
|
81
|
if ($_POST['report_name'] == '') doEdit($lang['strreportneedsname']);
|
82
|
elseif ($_POST['report_sql'] == '') doEdit($lang['strreportneedsdef']);
|
83
|
else {
|
84
|
$status = $reportsdb->alterReport($_POST['report_id'], $_POST['report_name'], $_POST['db_name'],
|
85
|
$_POST['descr'], $_POST['report_sql']);
|
86
|
if ($status == 0)
|
87
|
doDefault($lang['strreportcreated']);
|
88
|
else
|
89
|
doEdit($lang['strreportcreatedbad']);
|
90
|
}
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Display read-only properties of a report
|
95
|
*/
|
96
|
function doProperties($msg = '') {
|
97
|
global $data, $reportsdb, $misc;
|
98
|
global $PHP_SELF, $lang;
|
99
|
|
100
|
$report = $reportsdb->getReport($_REQUEST['report_id']);
|
101
|
|
102
|
$_REQUEST['report'] = $report->f['report_name'];
|
103
|
$misc->printTrail('report');
|
104
|
$misc->printTitle($lang['strproperties']);
|
105
|
$misc->printMsg($msg);
|
106
|
|
107
|
if ($report->recordCount() == 1) {
|
108
|
echo "<table>\n";
|
109
|
echo "<tr><th class=\"data left\">{$lang['strname']}</th>\n";
|
110
|
echo "<td class=\"data1\">", $misc->printVal($report->f['report_name']), "</td></tr>\n";
|
111
|
echo "<tr><th class=\"data left\">{$lang['strdatabase']}</th>\n";
|
112
|
echo "<td class=\"data1\">", $misc->printVal($report->f['db_name']), "</td></tr>\n";
|
113
|
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
|
114
|
echo "<td class=\"data1\">", $misc->printVal($report->f['descr']), "</td></tr>\n";
|
115
|
echo "<tr><th class=\"data left\">{$lang['strsql']}</th>\n";
|
116
|
echo "<td class=\"data1\">", $misc->printVal($report->f['report_sql']), "</td></tr>\n";
|
117
|
echo "</table>\n";
|
118
|
}
|
119
|
else echo "<p>{$lang['strinvalidparam']}</p>\n";
|
120
|
|
121
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?{$misc->href}\">{$lang['strshowallreports']}</a> |\n";
|
122
|
echo "<a class=\"navlink\" href=\"$PHP_SELF?action=edit&{$misc->href}&report_id={$report->f['report_id']}\">{$lang['stredit']}</a></p>\n";
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Displays a screen where they can enter a new report
|
127
|
*/
|
128
|
function doCreate($msg = '') {
|
129
|
global $data, $reportsdb, $misc;
|
130
|
global $PHP_SELF, $lang;
|
131
|
|
132
|
if (!isset($_REQUEST['report_name'])) $_REQUEST['report_name'] = '';
|
133
|
if (!isset($_REQUEST['db_name'])) $_REQUEST['db_name'] = (isset($_REQUEST['database']) ? $_REQUEST['database'] : '');
|
134
|
if (!isset($_REQUEST['descr'])) $_REQUEST['descr'] = '';
|
135
|
if (!isset($_REQUEST['report_sql'])) $_REQUEST['report_sql'] = '';
|
136
|
|
137
|
$databases = $data->getDatabases();
|
138
|
|
139
|
$misc->printTrail('server');
|
140
|
$misc->printTitle($lang['strcreatereport']);
|
141
|
$misc->printMsg($msg);
|
142
|
|
143
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
144
|
echo $misc->form;
|
145
|
echo "<table width=\"100%\">\n";
|
146
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
|
147
|
echo "<td class=\"data1\"><input name=\"report_name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
148
|
htmlspecialchars($_REQUEST['report_name']), "\" /></td></tr>\n";
|
149
|
echo "<tr><th class=\"data left required\">{$lang['strdatabase']}</th>\n";
|
150
|
echo "<td class=\"data1\"><select name=\"db_name\">\n";
|
151
|
while (!$databases->EOF) {
|
152
|
$dbname = $databases->f['datname'];
|
153
|
echo "<option value=\"", htmlspecialchars($dbname), "\"",
|
154
|
($dbname == $_REQUEST['db_name']) ? ' selected="selected"' : '', ">",
|
155
|
htmlspecialchars($dbname), "</option>\n";
|
156
|
$databases->moveNext();
|
157
|
}
|
158
|
echo "</select></td></tr>\n";
|
159
|
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
|
160
|
echo "<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"5\" cols=\"50\" name=\"descr\" wrap=\"virtual\">",
|
161
|
htmlspecialchars($_REQUEST['descr']), "</textarea></td></tr>\n";
|
162
|
echo "<tr><th class=\"data left required\">{$lang['strsql']}</th>\n";
|
163
|
echo "<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"15\" cols=\"50\" name=\"report_sql\" wrap=\"virtual\">",
|
164
|
htmlspecialchars($_REQUEST['report_sql']), "</textarea></td></tr>\n";
|
165
|
echo "</table>\n";
|
166
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
|
167
|
echo "<input type=\"submit\" value=\"{$lang['strsave']}\" />\n";
|
168
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
169
|
echo "</form>\n";
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* Actually creates the new report in the database
|
174
|
*/
|
175
|
function doSaveCreate() {
|
176
|
global $reportsdb, $lang;
|
177
|
|
178
|
if (!isset($_POST['report_name'])) $_POST['report_name'] = '';
|
179
|
if (!isset($_POST['db_name'])) $_POST['db_name'] = '';
|
180
|
if (!isset($_POST['descr'])) $_POST['descr'] = '';
|
181
|
if (!isset($_POST['report_sql'])) $_POST['report_sql'] = '';
|
182
|
|
183
|
// Check that they've given a name and a definition
|
184
|
if ($_POST['report_name'] == '') doCreate($lang['strreportneedsname']);
|
185
|
elseif ($_POST['report_sql'] == '') doCreate($lang['strreportneedsdef']);
|
186
|
else {
|
187
|
$status = $reportsdb->createReport($_POST['report_name'], $_POST['db_name'],
|
188
|
$_POST['descr'], $_POST['report_sql']);
|
189
|
if ($status == 0)
|
190
|
doDefault($lang['strreportcreated']);
|
191
|
else
|
192
|
doCreate($lang['strreportcreatedbad']);
|
193
|
}
|
194
|
}
|
195
|
|
196
|
/**
|
197
|
* Show confirmation of drop and perform actual drop
|
198
|
*/
|
199
|
function doDrop($confirm) {
|
200
|
global $reportsdb, $misc;
|
201
|
global $lang;
|
202
|
global $PHP_SELF;
|
203
|
|
204
|
if ($confirm) {
|
205
|
// Fetch report from the database
|
206
|
$report = $reportsdb->getReport($_REQUEST['report_id']);
|
207
|
|
208
|
$_REQUEST['report'] = $report->f['report_name'];
|
209
|
$misc->printTrail('report');
|
210
|
$misc->printTitle($lang['strdrop']);
|
211
|
|
212
|
echo "<p>", sprintf($lang['strconfdropreport'], $misc->printVal($report->f['report_name'])), "</p>\n";
|
213
|
|
214
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
215
|
echo $misc->form;
|
216
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
|
217
|
echo "<input type=\"hidden\" name=\"report_id\" value=\"", htmlspecialchars($_REQUEST['report_id']), "\" />\n";
|
218
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
|
219
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
220
|
echo "</form>\n";
|
221
|
}
|
222
|
else {
|
223
|
$status = $reportsdb->dropReport($_POST['report_id']);
|
224
|
if ($status == 0)
|
225
|
doDefault($lang['strreportdropped']);
|
226
|
else
|
227
|
doDefault($lang['strreportdroppedbad']);
|
228
|
}
|
229
|
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* Show default list of reports in the database
|
234
|
*/
|
235
|
function doDefault($msg = '') {
|
236
|
global $data, $misc, $reportsdb;
|
237
|
global $PHP_SELF, $lang;
|
238
|
|
239
|
$misc->printTrail('server');
|
240
|
$misc->printTabs('server','reports');
|
241
|
$misc->printMsg($msg);
|
242
|
|
243
|
$reports = $reportsdb->getReports();
|
244
|
|
245
|
$columns = array(
|
246
|
'report' => array(
|
247
|
'title' => $lang['strreport'],
|
248
|
'field' => 'report_name',
|
249
|
),
|
250
|
'database' => array(
|
251
|
'title' => $lang['strdatabase'],
|
252
|
'field' => 'db_name',
|
253
|
),
|
254
|
'created' => array(
|
255
|
'title' => $lang['strcreated'],
|
256
|
'field' => 'date_created',
|
257
|
),
|
258
|
'actions' => array(
|
259
|
'title' => $lang['stractions'],
|
260
|
),
|
261
|
'comment' => array(
|
262
|
'title' => $lang['strcomment'],
|
263
|
'field' => 'descr',
|
264
|
),
|
265
|
);
|
266
|
|
267
|
$return_url = urlencode("{$PHP_SELF}?{$misc->href}");
|
268
|
|
269
|
$actions = array(
|
270
|
'properties' => array(
|
271
|
'title' => $lang['strproperties'],
|
272
|
'url' => "{$PHP_SELF}?action=properties&{$misc->href}&",
|
273
|
'vars' => array('report_id' => 'report_id'),
|
274
|
),
|
275
|
'run' => array(
|
276
|
'title' => $lang['strrun'],
|
277
|
'url' => "display.php?subject=report&{$misc->href}&return_url={$return_url}&return_desc=".urlencode($lang['strback'])."&",
|
278
|
'vars' => array('report' => 'report_name', 'database' => 'db_name', 'query' => 'report_sql'),
|
279
|
),
|
280
|
'edit' => array(
|
281
|
'title' => $lang['stredit'],
|
282
|
'url' => "{$PHP_SELF}?action=edit&{$misc->href}&",
|
283
|
'vars' => array('report_id' => 'report_id'),
|
284
|
),
|
285
|
'drop' => array(
|
286
|
'title' => $lang['strdrop'],
|
287
|
'url' => "{$PHP_SELF}?action=confirm_drop&{$misc->href}&",
|
288
|
'vars' => array('report_id' => 'report_id'),
|
289
|
),
|
290
|
);
|
291
|
|
292
|
$misc->printTable($reports, $columns, $actions, $lang['strnoreports']);
|
293
|
|
294
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=create&{$misc->href}\">{$lang['strcreatereport']}</a></p>\n";
|
295
|
}
|
296
|
|
297
|
$misc->printHeader($lang['strreports']);
|
298
|
$misc->printBody();
|
299
|
|
300
|
// Create a database accessor for the reports database
|
301
|
include_once('./classes/Reports.php');
|
302
|
$reportsdb = new Reports($status);
|
303
|
if ($status != 0) {
|
304
|
$misc->printTrail('server');
|
305
|
$misc->printTabs('server','reports');
|
306
|
$misc->printMsg($lang['strnoreportsdb']);
|
307
|
}
|
308
|
else {
|
309
|
switch ($action) {
|
310
|
case 'save_edit':
|
311
|
if (isset($_POST['cancel'])) doDefault();
|
312
|
else doSaveEdit();
|
313
|
break;
|
314
|
case 'edit':
|
315
|
doEdit();
|
316
|
break;
|
317
|
case 'properties':
|
318
|
doProperties();
|
319
|
break;
|
320
|
case 'save_create':
|
321
|
if (isset($_POST['cancel'])) doDefault();
|
322
|
else doSaveCreate();
|
323
|
break;
|
324
|
case 'create':
|
325
|
doCreate();
|
326
|
break;
|
327
|
case 'drop':
|
328
|
if (isset($_POST['drop'])) doDrop(false);
|
329
|
else doDefault();
|
330
|
break;
|
331
|
case 'confirm_drop':
|
332
|
doDrop(true);
|
333
|
break;
|
334
|
default:
|
335
|
doDefault();
|
336
|
break;
|
337
|
}
|
338
|
}
|
339
|
|
340
|
$misc->printFooter();
|
341
|
|
342
|
?>
|