forked from pellcorp/opendb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.php
555 lines (474 loc) · 24.6 KB
/
export.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
<?php
/*
Open Media Collectors Database
Copyright (C) 2001,2013 by Jason Pell
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// This must be first - includes config.php
require_once("./include/begin.inc.php");
include_once("./lib/database.php");
include_once("./lib/auth.php");
include_once("./lib/logging.php");
include_once("./lib/item_type.php");
include_once("./lib/item.php");
include_once("./lib/item_attribute.php");
include_once("./lib/user.php");
include_once("./lib/widgets.php");
include_once("./lib/utils.php");
include_once("./lib/export.php");
include_once("./lib/TitleMask.class.php");
/*
* Export Type
*
* @param $item_id - if provided will restrict export to this single item.instance combo
* @param $instance_no
* @param $restrict_status_type_r - an array of status_type's to restrict to.
*/
function export_type_items(&$exportPlugin, $page_title, $s_item_type, $item_id, $instance_no, $owner_id, $restrict_status_type_r = NULL) {
// the $restrict_status_type_r is ignored for a single item
if (is_numeric($item_id) && is_numeric($instance_no)) {
send_header($exportPlugin, $page_title);
$item_r = fetch_item_instance_r($item_id, $instance_no);
if ($item_r['owner_id'] == get_opendb_session_var('user_id') || is_user_granted_permission(PERM_VIEW_ITEM_DISPLAY)) {
send_data(get_export_type_item($exportPlugin, $item_id, $instance_no, $item_r['s_item_type'], $item_r['title'], $owner_id));
}
send_footer($exportPlugin);
return TRUE;
} else {
$itemresults = fetch_export_item_rs($s_item_type, $owner_id, $restrict_status_type_r);
if ($itemresults) {
send_header($exportPlugin, $page_title);
while ($item_r = db_fetch_assoc($itemresults)) {
send_data(get_export_type_item($exportPlugin, $item_r['item_id'], NULL, $item_r['s_item_type'], $item_r['title'], $owner_id, $include_parent_related_item));
}
db_free_result($itemresults);
send_footer($exportPlugin);
return TRUE;
}
}
//else
return FALSE;
}
function get_export_type_item(&$exportPlugin, $item_id, $instance_no, $s_item_type, $title, $owner_id) {
$buffer = '';
$buffer .= $exportPlugin->start_item($item_id, $s_item_type, $title);
// export item (non instance level) attributes.
$buffer .= export_type_item_attributes($exportPlugin, $item_id, NULL, $s_item_type);
// $instance_no will have been provided if a single item.instance is being exported, otherwise
// we are exporting all instances for this particular item.
if (is_numeric($instance_no)) {
$item_instance_r = fetch_item_instance_r($item_id, $instance_no);
if (is_not_empty_array($item_instance_r)) {
$buffer .= $exportPlugin->start_item_instance($item_instance_r['item_id'], $item_instance_r['instance_no'], $item_instance_r['owner_id'], $item_instance_r['borrow_duration'], $item_instance_r['s_status_type'], $item_instance_r['status_comment'], $item_instance_r['update_on']);
$buffer .= export_type_item_attributes($exportPlugin, $item_id, $item_instance_r['instance_no'], $s_item_type);
$buffer .= $exportPlugin->end_item_instance();
}
} else {
$iiresults = fetch_item_instance_rs($item_id, $owner_id);
if ($iiresults) {
while ($item_instance_r = db_fetch_assoc($iiresults)) {
$buffer .= $exportPlugin->start_item_instance($item_instance_r['item_id'], $item_instance_r['instance_no'], $item_instance_r['owner_id'], $item_instance_r['borrow_duration'], $item_instance_r['s_status_type'], $item_instance_r['status_comment'], $item_instance_r['update_on']);
$buffer .= export_type_item_attributes($exportPlugin, $item_id, $item_instance_r['instance_no'], $s_item_type);
$buffer .= $exportPlugin->end_item_instance();
}
db_free_result($iiresults);
}
}
$buffer .= $exportPlugin->end_item();
return $buffer;
}
function export_type_item_attributes($exportPlugin, $item_id, $instance_no, $s_item_type) {
$buffer = '';
$attresults = fetch_item_attribute_type_rs($s_item_type, is_numeric($instance_no) ? 'instance_attribute_ind' : 'item_attribute_ind', FALSE);
if ($attresults) {
while ($item_attribute_type_r = db_fetch_assoc($attresults)) {
// Only attribute specific s_field_type's should be exported as XML.
if (strlen($item_attribute_type_r['s_field_type']) == 0
|| ($item_attribute_type_r['s_field_type'] != 'TITLE' && $item_attribute_type_r['s_field_type'] != 'DURATION' && $item_attribute_type_r['s_field_type'] != 'STATUSTYPE' && $item_attribute_type_r['s_field_type'] != 'STATUSCMNT'
&& $item_attribute_type_r['s_field_type'] != 'ITEM_ID')) {
$item_attribute_val_r = fetch_attribute_val_r($item_id, $instance_no, $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
if (is_not_empty_array($item_attribute_val_r)) {
for ($i = 0; $i < count($item_attribute_val_r); $i++) {
$buffer .= $exportPlugin->item_attribute($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $item_attribute_val_r[$i]);
}
}
}
}
db_free_result($attresults);
}
return $buffer;
}
/**
* Row Export
*/
function export_row_items(&$exportPlugin, $page_title, $include_header, $export_columns, $s_item_type, $owner_id) {
$iiresults = fetch_export_item_instance_rs($s_item_type, $owner_id);
if ($iiresults) {
send_header($exportPlugin, $page_title);
if ($include_header == 'Y') {
if (method_exists($exportPlugin, 'prompt_header')) {
$row = get_header_row('prompt', $export_columns, $s_item_type);
if (is_not_empty_array($row)) {
send_data($exportPlugin->prompt_header($row));
}
} else if (method_exists($exportPlugin, 'data_header')) {
$row = get_header_row('data', $export_columns, $s_item_type);
if (is_not_empty_array($row)) {
send_data($exportPlugin->data_header());
}
}
}
$item_instance_r2 = NULL;
while ($item_instance_r = db_fetch_assoc($iiresults)) {
$row = get_item_row($export_columns, strlen($s_item_type) == 0, $item_instance_r['item_id'], $item_instance_r['instance_no'], $item_instance_r['owner_id'], $item_instance_r['s_item_type'], $item_instance_r['title'], $item_instance_r['borrow_duration'], $item_instance_r['s_status_type'],
$item_instance_r['status_comment']);
if (is_not_empty_array($row)) {
send_data($exportPlugin->item_row($row));
}
$item_instance_r2 = $item_instance_r;
}
db_free_result($iiresults);
if (method_exists($exportPlugin, 'close')) {
send_data($exportPlugin->close());
}
send_footer($exportPlugin);
return TRUE;
} else {
return FALSE;
}
}
function get_item_row($export_columns, $is_all_item_types, $item_id, $instance_no, $owner_id, $s_item_type, $title, $borrow_duration, $s_status_type, $status_comment) {
if (!is_array($export_columns) || $export_columns['item_id'] == 'Y') {
$row[] = $item_id;
}
if (!is_array($export_columns) || $export_columns['instance_no'] == 'Y') {
$row[] = $instance_no;
}
if (!is_array($export_columns) || $export_columns['owner_id'] == 'Y') {
$row[] = $owner_id;
}
if (!is_array($export_columns) || $export_columns['s_item_type'] == 'Y') {
$row[] = $s_item_type;
}
if ($is_all_item_types !== TRUE) {
$results = fetch_item_attribute_type_rs($s_item_type);
if ($results) {
while ($item_attribute_type_r = db_fetch_assoc($results)) {
$fieldname = get_field_name($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
if (!is_array($export_columns) || $export_columns[$fieldname] == 'Y') {
if ($item_attribute_type_r['s_field_type'] != 'ITEM_ID') {
if ($item_attribute_type_r['s_field_type'] == 'TITLE') {
$row[] = $title;
} else if ($item_attribute_type_r['s_field_type'] == 'DURATION') {
$row[] = $borrow_duration;
} else if ($item_attribute_type_r['s_field_type'] == 'STATUSTYPE') {
$row[] = $s_status_type;
} else if ($item_attribute_type_r['s_field_type'] == 'STATUSCMNT') {
$row[] = $status_comment;
} else {
$item_attribute_val_r = fetch_attribute_val_r($item_id, $instance_no, $item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
if (is_not_empty_array($item_attribute_val_r)) {
// the plugins will have to handle a array, and format it appropriately.
$row[] = $item_attribute_val_r;
} else {
$row[] = ''; // nothing.
}
}
}
}
}
db_free_result($results);
}
} else {
if (!is_array($export_columns) || $export_columns['title'] == 'Y') {
$row[] = $title;
}
}
return $row;
}
function get_header_row($header_type, $export_columns, $s_item_type) {
if (!is_array($export_columns) || $export_columns['item_id'] == 'Y') {
if ($header_type == 'data')
$headings[] = 'item_id';
else
$headings[] = get_opendb_lang_var('item_id');
}
if (!is_array($export_columns) || $export_columns['instance_no'] == 'Y') {
if ($header_type == 'data')
$headings[] = 'instance_no';
else
$headings[] = get_opendb_lang_var('instance_no');
}
if (!is_array($export_columns) || $export_columns['owner_id'] == 'Y') {
if ($header_type == 'data')
$headings[] = 'owner_id';
else
$headings[] = get_opendb_lang_var('owner_id');
}
if (!is_array($export_columns) || $export_columns['s_item_type'] == 'Y') {
if ($header_type == 'data')
$headings[] = 's_item_type';
else
$headings[] = get_opendb_lang_var('s_item_type');
}
if (strlen($s_item_type) > 0) {
// Get the item_attribute headings.
$results = fetch_item_attribute_type_rs($s_item_type);
if ($results) {
while ($item_attribute_type_r = db_fetch_assoc($results)) {
// Only legal s_field_type's - ignore ITEM_ID!!!
if (strlen($item_attribute_type_r['s_field_type']) == 0 || $item_attribute_type_r['s_field_type'] == 'CATEGORY' || $item_attribute_type_r['s_field_type'] == 'TITLE' || $item_attribute_type_r['s_field_type'] == 'DURATION' || $item_attribute_type_r['s_field_type'] == 'STATUSTYPE'
|| $item_attribute_type_r['s_field_type'] == 'STATUSCMNT' || $item_attribute_type_r['s_field_type'] == 'IMAGE') {
$fieldname = get_field_name($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
if (!is_array($export_columns) || $export_columns[$fieldname] == 'Y') {
if ($header_type == 'data') {
$headings[] = $fieldname;
} else { //if($header_type == 'prompt')
$headings[] = $item_attribute_type_r['prompt'];
}
}
}
}
db_free_result($results);
}
} else {
if (!is_array($export_columns) || $export_columns['title'] == 'Y') {
if ($header_type == 'data')
$headings[] = 'title';
else
$headings[] = get_opendb_lang_var('title');
}
}
return $headings;
}
function send_data($buffer) {
if (strlen($buffer)) {
echo ($buffer);
// do explicit flush
flush();
}
}
function send_header(&$exportPlugin, $page_title) {
$filename_prefix = 'export';
if (method_exists($exportPlugin, 'get_file_name')) {
$filename = $exportPlugin->get_file_name();
} else if (method_exists($exportPlugin, 'get_file_extension')) {
$filename = $filename_prefix . '.' . $exportPlugin->get_file_extension();
} else {
$filename = $filename_prefix . '.txt';
}
if (method_exists($exportPlugin, 'get_file_content_type')) {
$content_type = $exportPlugin->get_file_content_type();
} else {
$content_type = 'text/plain';
}
if (method_exists($exportPlugin, 'http_header')) {
$exportPlugin->http_header($filename, $content_type);
} else {
header("Cache-control: no-store");
header("Pragma: no-store");
header("Expires: 0");
header("Content-disposition: attachment; filename=$filename");
header("Content-type: $content_type");
}
if (method_exists($exportPlugin, 'file_header')) {
send_data($exportPlugin->file_header($page_title));
}
}
function send_footer(&$exportPlugin) {
if (method_exists($exportPlugin, 'file_footer')) {
send_data($exportPlugin->file_footer());
}
}
function get_row_export_column_form(&$exportPlugin, $HTTP_VARS) {
global $PHP_SELF;
$buffer .= "\n<form method=\"POST\" action=\"$PHP_SELF\">";
$buffer .= "\n<input type=\"hidden\" name=\"op\" value=\"export\">";
$buffer .= "\n<input type=\"hidden\" name=\"owner_id\" value=\"" . $HTTP_VARS['owner_id'] . "\">";
$buffer .= "\n<input type=\"hidden\" name=\"s_item_type\" value=\"" . $HTTP_VARS['s_item_type'] . "\">";
$buffer .= "\n<input type=\"hidden\" name=\"plugin\" value=\"" . $HTTP_VARS['plugin'] . "\">";
$buffer .= "\n<ul class=\"checkboxGridOptionsVertical\">";
$buffer .= "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"export_columns[item_id]\" value=\"Y\">" . get_opendb_lang_var('item_id') . "</li>";
$buffer .= "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"export_columns[instance_no]\" value=\"Y\">" . get_opendb_lang_var('instance_no') . "</li>";
$buffer .= "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"export_columns[owner_id]\" value=\"Y\">" . get_opendb_lang_var('owner_id') . "</li>";
$buffer .= "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"export_columns[item_id]\" value=\"Y\"" . (strlen($HTTP_VARS['owner_id']) == 0 ? ' CHECKED' : '') . ">" . get_opendb_lang_var('item_id') . "</li>";
$buffer .= "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"export_columns[s_item_type]\" value=\"Y\">" . get_opendb_lang_var('s_item_type') . "</li>";
if (strlen($HTTP_VARS['s_item_type']) > 0) {
$results = fetch_item_attribute_type_rs($HTTP_VARS['s_item_type']);
if ($results) {
while ($item_attribute_type_r = db_fetch_assoc($results)) {
// Only legal s_field_type's - ignore ITEM_ID!!!
if (strlen($item_attribute_type_r['s_field_type']) == 0 || $item_attribute_type_r['s_field_type'] == 'CATEGORY' || $item_attribute_type_r['s_field_type'] == 'TITLE' || $item_attribute_type_r['s_field_type'] == 'DURATION' || $item_attribute_type_r['s_field_type'] == 'STATUSTYPE'
|| $item_attribute_type_r['s_field_type'] == 'STATUSCMNT' || $item_attribute_type_r['s_field_type'] == 'IMAGE') {
$buffer .= '<li><input type="checkbox" class="checkbox" name="export_columns[' . get_field_name($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']) . ']" value="Y"';
// work out what columns to have checked by default.
if ($item_attribute_type_r['s_field_type'] == 'TITLE' || $item_attribute_type_r['s_field_type'] == 'IMAGE'
|| (strlen($item_attribute_type_r['s_field_type']) == 0 && strcasecmp(ifempty($item_attribute_type_r['display_type'], $item_attribute_type_r['input_type']), "hidden") !== 0)) {
$buffer .= ' CHECKED';
}
$buffer .= '>' . $item_attribute_type_r['prompt'] . "</li>";
}
}
db_free_result($results);
}
} else {
$buffer .= "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"export_columns[title]\" value=\"Y\">" . get_opendb_lang_var('title') . "</li>";
}
if (method_exists($exportPlugin, 'prompt_header') || method_exists($exportPlugin, 'data_header')) {
$buffer .= "\n<li id=\"include-header\"><input type=\"checkbox\" class=\"checkbox\" name=\"include_header\" value=\"Y\" CHECKED>" . get_opendb_lang_var('include_header') . "</li>";
}
$buffer .= "</ul>";
$buffer .= "\n<ul class=\"actionButtons\">";
$buffer .= "\n<li><input type=\"button\" class=\"button\" value=\"" . get_opendb_lang_var('check_all') . "\" onClick=\"setCheckboxes(this.form, 'export_columns', true);\"></li>" . "\n<li><input type=\"button\" class=\"button\" value=\"" . get_opendb_lang_var('uncheck_all')
. "\" onClick=\"setCheckboxes(this.form, 'export_columns', false);\"></li>" . "\n<li><input type=\"reset\" class=\"reset\" value=\"" . get_opendb_lang_var('reset') . "\"></li>" . "\n<li class=\"submitButton\"><input type=\"submit\" class=\"submit\" value=\""
. get_opendb_lang_var('export_items') . "\"></li>" . "</ul>";
$buffer .= '</form>';
return $buffer;
}
if (is_site_enabled()) {
if (is_opendb_valid_session()) {
if (is_user_granted_permission(PERM_ADMIN_EXPORT) || is_user_granted_permission(PERM_USER_EXPORT)) {
if (!is_numeric($HTTP_VARS['item_id']) && !is_user_granted_permission(PERM_ADMIN_EXPORT)) {
$HTTP_VARS['owner_id'] = get_opendb_session_var('user_id');
}
if ($HTTP_VARS['op'] == 'export') {
$exportPlugin = &get_export_plugin($HTTP_VARS['plugin']);
if ($exportPlugin !== NULL) {
if (strlen($HTTP_VARS['s_item_type']) == 0 || is_valid_item_type_structure($HTTP_VARS['s_item_type'])) {
if ($exportPlugin->get_plugin_type() == 'row') {
// Work out page title.
if (strlen($HTTP_VARS['owner_id']) > 0)
$page_title = get_opendb_lang_var('type_export_for_name_item_type', array('description' => $exportPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id'], 's_item_type' => $HTTP_VARS['s_item_type']));
else if (strlen($HTTP_VARS['s_item_type']) > 0)
$page_title = get_opendb_lang_var('type_export_for_item_type', array('description' => $exportPlugin->get_display_name(), 's_item_type' => $HTTP_VARS['s_item_type']));
else
$page_title = get_opendb_lang_var('type_export', array('description' => $exportPlugin->get_display_name()));
if (is_not_empty_array($HTTP_VARS['export_columns'])) {
@set_time_limit(600);
if (!export_row_items($exportPlugin, $page_title, $HTTP_VARS['include_header'], $HTTP_VARS['export_columns'], $HTTP_VARS['s_item_type'], $HTTP_VARS['owner_id'])) {
echo _theme_header($page_title);
echo ("<h2>" . $page_title . "</h2>");
echo format_error_block(array('error' => get_opendb_lang_var('no_records_found'), 'detail' => ''));
echo _theme_footer();
}
} else {
echo _theme_header($page_title);
echo ("<h2>" . $page_title . "</h2>");
echo ("<h3>" . get_opendb_lang_var('choose_export_fields') . "</h3>");
echo (get_row_export_column_form($exportPlugin, $HTTP_VARS));
echo _theme_footer();
}
} else if ($exportPlugin->get_plugin_type() == 'item') {
$titleMaskCfg = new TitleMask('item_display');
// Work out page title.
if (strlen($HTTP_VARS['owner_id']) > 0 || is_numeric($HTTP_VARS['item_id'])) {
if (strlen($HTTP_VARS['owner_id']) > 0 && strlen($HTTP_VARS['s_item_type']) > 0)
$page_title = get_opendb_lang_var('type_export_for_name_item_type', array('description' => $exportPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id'], 's_item_type' => $HTTP_VARS['s_item_type']));
else if (strlen($HTTP_VARS['s_item_type']) > 0)
$page_title = get_opendb_lang_var('type_export_for_item_type', array('description' => $exportPlugin->get_display_name(), 's_item_type' => $HTTP_VARS['s_item_type']));
else if (is_numeric($HTTP_VARS['item_id']) && is_numeric($HTTP_VARS['instance_no'])) {
$item_r = fetch_item_instance_r($HTTP_VARS['item_id'], $HTTP_VARS['instance_no']);
$page_title = get_opendb_lang_var('type_export_for_item_instance', array('description' => $exportPlugin->get_display_name(), 'item_id' => $HTTP_VARS['item_id'], 'instance_no' => $HTTP_VARS['instance_no'], 'title' => $titleMaskCfg->expand_item_title($item_r)));
} else if (is_numeric($HTTP_VARS['item_id'])) {
// Not really a child item, but we are not interested in the instance, so use this. It still
// returns the right data anyway.
$item_r = fetch_child_item_r($HTTP_VARS['item_id']);
$page_title = get_opendb_lang_var('type_export_for_item', array('description' => $exportPlugin->get_display_name(), 'item_id' => $HTTP_VARS['item_id'], 'title' => $titleMaskCfg->expand_item_title($item_r)));
} else {
$page_title = get_opendb_lang_var('type_export_for_name', array('description' => $exportPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
}
} else { //if(strlen($HTTP_VARS['owner_id'])>0 || is_numeric($HTTP_VARS['item_id']))
$page_title = get_opendb_lang_var('type_export', array('description' => $exportPlugin->get_display_name()));
}
@set_time_limit(600);
if (!export_type_items($exportPlugin, $page_title, $HTTP_VARS['s_item_type'], $HTTP_VARS['item_id'], $HTTP_VARS['instance_no'], $HTTP_VARS['owner_id'], $HTTP_VARS['s_status_type'])) {
echo _theme_header($page_title);
echo ("<h2>" . $page_title . "</h2>");
echo format_error_block(array('error' => get_opendb_lang_var('no_records_found'), 'detail' => ''));
echo _theme_footer();
}
} else { //get_plugin_type() not supported.
echo _theme_header(get_opendb_lang_var('undefined_error'));
echo ("<p class=\"error\">" . get_opendb_lang_var('undefined_error') . "</p>");
echo _theme_footer();
}
} else { //if(strlen($HTTP_VARS['s_item_type'])==0 || is_valid_item_type_structure($HTTP_VARS['s_item_type']))
$page_title = get_opendb_lang_var('type_export', array('description' => $exportPlugin->get_display_name()));
echo _theme_header($page_title);
echo ("<h2>" . $page_title . "</h2>");
echo (format_error_block(array('error' => get_opendb_lang_var('invalid_item_type_structure', 's_item_type', $HTTP_VARS['s_item_type']), 'detail' => '')));
echo _theme_footer();
}
} else { //if($importPlugin !== NULL)
echo _theme_header(get_opendb_lang_var('undefined_error'));
echo ("<p class=\"error\">" . get_opendb_lang_var('undefined_error') . "</p>");
echo _theme_footer();
}
} else {
// A custom title.
if (is_user_granted_permission(PERM_ADMIN_EXPORT) && strlen($HTTP_VARS['owner_id']) == 0)
$page_title = get_opendb_lang_var('export_items');
else if ($HTTP_VARS['owner_id'] == get_opendb_session_var('user_id') || strlen($HTTP_VARS['owner_id']) == 0)
$page_title = get_opendb_lang_var('export_my_items');
echo _theme_header($page_title);
echo ("<h2>" . $page_title . "</h2>");
echo ("<form method=\"GET\" action=\"$PHP_SELF\">");
echo ("\n<input type=\"hidden\" name=\"op\" value=\"export\">");
echo ("<table>");
$field = "\n<select name=\"plugin\">\n";
$plugin_list_r = get_export_plugin_list_r();
if (is_array($plugin_list_r)) {
while (list(, $plugin_r) = @each($plugin_list_r)) {
$field .= '<option value="' . $plugin_r['name'] . '"';
if ($plugin_r['name'] == 'OpenDbExportPlugin') {
$field .= ' SELECTED';
}
$field .= '>' . $plugin_r['description'] . "\n";
}
}
$field .= "</select>";
echo format_field(get_opendb_lang_var('type'), $field);
if (is_user_granted_permission(PERM_ADMIN_EXPORT)) {
echo format_field(get_opendb_lang_var('owner'),
"\n<select name=\"owner_id\">" . "\n<option value=\"\">-------------- " . get_opendb_lang_var('all') . " --------------"
. custom_select('owner_id', fetch_user_rs(PERM_USER_EXPORT), '%fullname% (%user_id%)', 'NA', ifempty($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')), 'user_id') . "\n</select>");
} else {
echo ("<input type=\"hidden\" name=\"owner_id\" value=\"" . $HTTP_VARS['owner_id'] . "\">");
}
echo format_field(get_opendb_lang_var('item_type'),
"<select name=\"s_item_type\">" . "\n<option value=\"\">-------------- " . get_opendb_lang_var('all') . " --------------"
. custom_select('s_item_type', fetch_item_type_rs(), '%s_item_type% - %description%', 'NA', $HTTP_VARS['s_item_type'], 's_item_type') . "\n</select>");
$lookup_results = fetch_status_type_rs(TRUE);
if ($lookup_results && db_num_rows($lookup_results) > 1) {
echo format_field(get_opendb_lang_var('s_status_type'), checkbox_grid('s_status_type', $lookup_results, '%img%', // mask
'VERTICAL', NULL)); // value
}
echo ("</table>");
echo ("<input type=\"submit\" class=\"submit\" value=\"" . get_opendb_lang_var('submit') . "\">");
echo ("</form>");
echo _theme_footer();
}
} else { //no guests or borrowers allowed!
opendb_not_authorised_page(array(PERM_USER_EXPORT, PERM_ADMIN_EXPORT));
}
} else {
// invalid login, so login instead.
redirect_login($PHP_SELF, $HTTP_VARS);
}
}//if(is_site_enabled())
else {
opendb_site_disabled();
}
// Cleanup after begin.inc.php
require_once("./include/end.inc.php");
?>