-
Notifications
You must be signed in to change notification settings - Fork 24
/
import.php
603 lines (497 loc) · 28.6 KB
/
import.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
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<?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_attribute.php");
include_once("./lib/widgets.php");
include_once("./lib/utils.php");
include_once("./lib/item_type.php");
include_once("./lib/item.php");
include_once("./lib/user.php");
include_once("./lib/import.php");
include_once("./lib/importcache.php");
include_once("./lib/parseutils.php");
include_once("./lib/ItemImportHandler.class.php");
include_once("./lib/HTML_Listing.class.php");
function get_column_select_block($fieldname, $lookup_array, $selectedindex) {
$var = "\n<select name=\"$fieldname\">";
$var .= "\n<option value=\"\">-- " . get_opendb_lang_var('none') . " --";
for ($i = 0; $i < count($lookup_array); $i++) {
$var .= "\n<option " . (is_numeric($selectedindex) && $selectedindex == $i ? "SELECTED" : "") . " value=\"$i\">" . $lookup_array[$i];
}
$var .= "\n</select>";
return $var;
}
/**
We are using this instead of the particular input types, so
that users can clearly see what the %value% and %display%
columns are for the lookups, so they can match them in
their import file.
*/
function build_select($name, $lookup_results, $value, $include_none_option = TRUE) {
// If at least one $lookup_r['value'] is different from $lookup_r['display'] set this variable to true.
$display_used = FALSE;
$var = "\n<select name=\"$name\">";
if ($include_none_option)
$var .= "\n<option value=\"\">-- " . get_opendb_lang_var('none') . " --";
while ($lookup_r = db_fetch_assoc($lookup_results)) {
if ($lookup_r['value'] === $lookup_r['display'])
$display = $lookup_r['value'];
else {
$display = $lookup_r['value'] . " - " . $lookup_r['display'];
if (!$display_used)
$display_used = TRUE;
}
$var .= "\n<option value=\"" . $lookup_r['value'] . "\"";
// Only support checked_ind, where we are not displaying a None option. If None option, it should
// be chosen by default.
if (($include_none_option !== TRUE && strlen($value) == 0 && $lookup_r['checked_ind'] == "Y") || (strlen($value) > 0 && strcasecmp($value, $lookup_r['value']) === 0)) {
$var .= " SELECTED";
}
$var .= ">$display";
}
db_free_result($lookup_results);
$var .= "\n</select>";
if ($display_used)
$var .= "<span class=\"selectMask\">(%value% - %display%)</span>";
else
$var .= "<span class=\"selectMask\">(%value%)</span>";
return $var;
}
/**
*/
function get_row_column_mappings_table($s_item_type, $owner_id, $header_row, $field_column_r, $field_default_r, $field_initcap_r) {
$buffer = "\n<table>";
$buffer .= "\n<tr class=\"navbar\"><th></th>" . "<th>" . get_opendb_lang_var('field') . "</th>" . "<th>" . get_opendb_lang_var('default') . "</th>" . "<th> " . get_opendb_lang_var('initcap') . "</th></tr>";
// If the prompt for this field, matches any of the $tokens, then select that token.
if (!is_numeric($field_column_r['s_item_type'])) {
for ($i = 0; $i < count($header_row); $i++) {
if ($header_row[$i] == 's_item_type' || $header_row[$i] == get_opendb_lang_var('s_item_type')) {
$field_column_r['s_item_type'] = $i;
break;
}
}
}
// If your data includes the item_type, then specify the column, so we
// can ignore records that are not of the chosen item_type.
$buffer .= "\n<tr>" . "<th class=\"prompt\" scope=\"row\">" . get_opendb_lang_var('s_item_type') . "</th>" . "<td class=\"data fieldColumn\">" . get_column_select_block("field_column[s_item_type]", $header_row, $field_column_r['s_item_type']) . "</td>"
. "<td class=\"data defaultColumn\"> </td>" . "<td class=\"data initcapColumn\"> </td>" . "</tr>";
// --------- Now the main input fields start....
$results = fetch_item_attribute_type_rs($s_item_type);
if ($results) {
while ($item_attribute_type_r = db_fetch_assoc($results)) {
// purely readonly
if ($item_attribute_type_r['s_field_type'] !== 'ITEM_ID') {
$fieldname = get_field_name($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']);
if ($item_attribute_type_r['s_field_type'] == 'STATUSTYPE') {
$lookup_results = fetch_newitem_status_type_rs();
$default_field = build_select("field_default[$fieldname]", $lookup_results, $field_default_r[$fieldname], FALSE); // do not include 'None' option
$initcap_field = NULL;// No initcap for these types of fields.
} else if ($item_attribute_type_r['input_type'] !== "textarea" && $item_attribute_type_r['input_type'] !== "url") {
// Check if any lookup values for this field.
$lookup_results = fetch_attribute_type_lookup_rs($item_attribute_type_r['s_attribute_type'], 'order_no, value ASC');
if ($lookup_results) {
$default_field = build_select("field_default[$fieldname]", $lookup_results, $field_default_r[$fieldname]);
$initcap_field = NULL;// No initcap for these types of fields.
} else { //use normal input field.
if ($item_attribute_type_r['multi_attribute_ind'] == 'Y') {
$item_attribute_type_r['multi_attribute_ind'] = 'N';
}
$default_field = get_item_input_field("field_default[$fieldname]", $item_attribute_type_r, NULL, //$item_r
$field_default_r[$fieldname], FALSE);
if ($item_attribute_type_r['input_type'] === 'text') {
$initcap_field = get_input_field("field_initcap[$fieldname]", NULL, NULL, "checkbox(true,false,)", "N", ifempty($field_initcap_r[$fieldname], (get_opendb_config_var('import', 'row_import_default_initcap_checked') ? "true" : "false")), FALSE);
} else { //Only for text fields.
$initcap_field = NULL;
}
}
} else {
$field = NULL;
$default_field = NULL;
$initcap_field = NULL;
}
// If the prompt for this field, matches any of the $tokens, then select that token.
if (!is_numeric($field_column_r[$fieldname])) {
for ($i = 0; $i < count($header_row); $i++) {
// A direct export from CSV Export, so lets match the columns for you.
if ($header_row[$i] == $fieldname || $header_row[$i] == $item_attribute_type_r['prompt'] ||
// hack for export which still exports 'Genre' instead of correct specific header, will
// fix but this allows old row based files to still be matched correctly.
($item_attribute_type_r['s_field_type'] == 'CATEGORY' && $header_row[$i] == 'Genre')) {
$field_column_r[$fieldname] = $i;
break;
}
}
}
$buffer .= "\n<tr>" . "<th class=\"prompt\" scope=\"row\">" . $item_attribute_type_r['prompt'] . "</th>" . "<td class=\"data fieldColumn\">" . get_column_select_block("field_column[$fieldname]", $header_row, $field_column_r[$fieldname]) . "</td>"
. "<td class=\"data defaultColumn\">" . $default_field . "</td>" . "<td class=\"data initcapColumn\">" . $initcap_field . "</td>" . "</tr>";
}//if($item_attribute_type_r['s_field_type'] !== 'ITEM_ID')
}//while
db_free_result($results);
}//if($results)
$buffer .= "\n</table>";
return $buffer;
}
function get_import_options_table(&$importPlugin, $HTTP_VARS) {
$buffer = "<ul class=\"importOptions\">";
if ($importPlugin->get_plugin_type() == 'row' && $importPlugin->is_header_row()) {
$buffer .= "<li><input type=\"checkbox\" class=\"checkbox\" name=\"include_header_row\" value=\"Y\"" . (strcmp($HTTP_VARS['include_header_row'], 'Y') === 0 ? ' CHECKED' : '') . ">" . get_opendb_lang_var('include_first_line') . "</li>";
}
$buffer .= "<li><input type=\"checkbox\" class=\"checkbox\" name=\"ignore_duplicate_title\" value=\"Y\"" . (strcmp($HTTP_VARS['ignore_duplicate_title'], 'Y') === 0 ? ' CHECKED' : '') . ">" . get_opendb_lang_var('ignore_duplicate_title') . "</li>";
if (strcasecmp(get_class($importPlugin), 'PreviewImportPlugin') !== 0) {
$buffer .= "<li><input type=\"checkbox\" class=\"checkbox\" name=\"trial_run\" value=\"Y\" CHECKED>" . get_opendb_lang_var('trial_run') . "</li>";
}
$buffer .= "</ul>";
return $buffer;
}
function get_import_choices_table(&$importPlugin, $cfg_include_header_row, $cfg_ignore_duplicate_title, $cfg_is_trial_run, $cfg_override_status_type, $cfg_default_status_type_r) {
$buffer = "<dl class=\"importOptions\">";
if ($importPlugin->get_plugin_type() == 'row' && $importPlugin->is_header_row()) {
$buffer .= "<dt>" . get_opendb_lang_var('include_first_line') . "</dt>" . "<dd>" . ($cfg_include_header_row ? theme_image('tick.gif') : theme_image('cross.gif')) . "</dd>";
}
$buffer .= "<dt>" . get_opendb_lang_var('ignore_duplicate_title') . "</dt>" . "<dd>" . ($cfg_ignore_duplicate_title ? theme_image('tick.gif') : theme_image('cross.gif')) . "</dd>";
if (strcasecmp(get_class($importPlugin), 'PreviewImportPlugin') !== 0) {
$buffer .= "<dt>" . get_opendb_lang_var('trial_run') . "</dt>" . "<dd>" . ($cfg_is_trial_run ? theme_image('tick.gif') : theme_image('cross.gif')) . "</dd>";
}
if ($cfg_override_status_type) {
if (is_not_empty_array($cfg_default_status_type_r)) {
$buffer .= "<dt>" . get_opendb_lang_var('override_status_type') . "</dt>" . "<dd>" . format_display_value('%img%', $cfg_default_status_type_r['img'], 'Y', $cfg_default_status_type_r['description'], "s_status_type") . "</dd>";
}
}
$buffer .= "</dl>";
return $buffer;
}
/*
* This page is displayed, when file is uploaded, and various
* options are available to indicate what the next step should
* be in the upload process. The uploaded page will also be
* loaded when a user chooses to go 'Back' during a trial
* run of the import process.
*/
function get_uploaded_form(&$importPlugin, $header_row, $HTTP_VARS) {
global $PHP_SELF;
$buffer = "\n<form action=\"$PHP_SELF\" method=\"POST\">";
$buffer .= "\n<input type=\"hidden\" name=\"op\" value=\"import\">";
$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=\"ic_sequence_number\" value=\"" . $HTTP_VARS['ic_sequence_number'] . "\">";
$buffer .= get_import_options_table($importPlugin, $HTTP_VARS);
if ($importPlugin->get_plugin_type() == 'row') {
$buffer .= get_row_column_mappings_table($HTTP_VARS['s_item_type'], $HTTP_VARS['owner_id'], $header_row, $HTTP_VARS['field_column'], $HTTP_VARS['field_default'], $HTTP_VARS['field_initcap']);
if (strcasecmp(get_class($importPlugin), 'PreviewImportPlugin') !== 0) {
$buffer .= "\n<input type=\"submit\" class=\"submit\" value=\"" . get_opendb_lang_var('import_items') . "\">";
}
} else if ($importPlugin->get_plugin_type() == 'xml') {
// Include a Status Type LOV and a checkbox to indicate whether the s_status_type should be used for all imports
// ignoring any s_status_type which may be included in the data.
$buffer .= '<table>';
$results = fetch_newitem_status_type_rs();
if ($results && db_num_rows($results) > 1) {
$buffer .= format_field(get_opendb_lang_var('s_status_type'), radio_grid('s_status_type', $results, '%img%', // mask
'VERTICAL', $HTTP_VARS['s_status_type'])); // value
$buffer .= format_field(get_opendb_lang_var('override_status_type'), "<input type=\"checkbox\" class=\"checkbox\" name=\"override_status_type\" value=\"Y\"" . (strcmp($HTTP_VARS['override_status_type'], 'Y') === 0 ? ' CHECKED' : '') . ">");
$buffer .= '</table>';
} else if (db_num_rows($results) > 0) { // handle single status silently
$status_type_r = db_fetch_assoc($results);
$buffer .= "<input type=\"hidden\" name=\"s_status_type\" value=\"" . $status_type_r['s_status_type'] . "\">";
db_free_result($results);
}
if (strcasecmp(get_class($importPlugin), 'PreviewImportPlugin') !== 0) {
$buffer .= "<input type=\"submit\" class=\"submit\" value=\"" . get_opendb_lang_var('import_items') . "\">";
}
}
$buffer .= '</form>';
return $buffer;
}
function get_upload_form($HTTP_VARS) {
global $PHP_SELF;
$buffer .= "\n<form name=\"main\" action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">";
$buffer .= "\n<input type=\"hidden\" name=\"op\" value=\"upload\">";
$buffer .= "\n<table>";
if (is_user_granted_permission(PERM_ADMIN_IMPORT)) {
$buffer .= format_field(get_opendb_lang_var('owner'), custom_select('owner_id', fetch_user_rs(PERM_USER_IMPORT), '%fullname% (%user_id%)', 1, ifempty($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')), 'user_id'));
} else {
$buffer .= "\n<input type=\"hidden\" name=\"owner_id\" value=\"" . $HTTP_VARS['owner_id'] . "\">";
}
$buffer .= format_field(get_opendb_lang_var('item_type'), single_select('s_item_type', fetch_item_type_rs(TRUE), "%value% - %display%", NULL, $HTTP_VARS['s_item_type']));
$buffer .= format_field(get_opendb_lang_var('file'), "<input type=\"file\" class=\"file\" size=\"25\" name=\"uploadfile\">");
$buffer .= "\n</table>";
$buffer .= "\n<input type=\"submit\" class=\"submit\" value=\"" . get_opendb_lang_var('submit') . "\">";
$buffer .= "\n</form>";
return $buffer;
}
if (is_site_enabled()) {
if (is_opendb_valid_session()) {
if (is_user_granted_permission(PERM_USER_IMPORT) || is_user_granted_permission(PERM_ADMIN_IMPORT)) {
if (!is_user_granted_permission(PERM_ADMIN_IMPORT)) {
$HTTP_VARS['owner_id'] = get_opendb_session_var('user_id');
}
if (is_file_upload_enabled()) {
@set_time_limit(600);
if ($HTTP_VARS['op'] == 'upload') {
if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
if ($_FILES['uploadfile']['size'] > 0) {
$importPlugin = &get_import_plugin_from_uploadfile($_FILES['uploadfile'], $error);
if ($importPlugin !== NULL) {
$sequence_number = import_cache_insert($HTTP_VARS['owner_id'], get_class($importPlugin), $_FILES['uploadfile']['tmp_name']);
if ($sequence_number !== FALSE) {
// pass this onto the next call!
$HTTP_VARS['ic_sequence_number'] = $sequence_number;
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('type_import', array('description' => $importPlugin->get_display_name()));
else
$page_title = get_opendb_lang_var('type_import_items_for_name', array('description' => $importPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
echo (_theme_header($page_title));
if ($importPlugin->get_plugin_type() == 'row')
echo ("<h2>" . $page_title . " " . get_item_image($HTTP_VARS['s_item_type']) . "</h2>\n");
else
echo ("<h2>" . $page_title . "</h2>");
$inFile = import_cache_fetch_file($HTTP_VARS['ic_sequence_number']);
if ($inFile) {
$fileHandler = new WrapperFileHandler($inFile);
echo (get_uploaded_form($importPlugin, ($importPlugin->get_plugin_type() == 'row') ? $importPlugin->read_header($fileHandler, $error) : NULL, $HTTP_VARS));
unset($fileHandler);
@fclose($inFile);
echo _theme_footer();
} else {
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($sequence_number!==FALSE)
if (strlen($HTTP_VARS['owner_id']) > 0) {
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('import_my_items');
else
$page_title = get_opendb_lang_var('import_items_for_name', array('fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
} else {
$page_title = get_opendb_lang_var('import_items');
}
echo (_theme_header($page_title));
echo ("<h2>" . $page_title . "</h2>");
echo (format_error_block(get_opendb_lang_var('file_upload_error', 'prompt', strtoupper(get_file_ext($_FILES['uploadfile']['name'])))));
echo (_theme_footer());
}
} else { //if($importPlugin !== NULL)
if (strlen($HTTP_VARS['owner_id']) > 0) {
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('import_my_items');
else
$page_title = get_opendb_lang_var('import_items_for_name', array('fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
} else {
$page_title = get_opendb_lang_var('import_items');
}
echo (_theme_header($page_title));
echo ("<h2>" . $page_title . "</h2>");
echo (format_error_block($error));
echo (_theme_footer());
}
} else { //if($_FILES['uploadfile']['size']>0)
if (strlen($HTTP_VARS['owner_id']) > 0) {
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('import_my_items');
else
$page_title = get_opendb_lang_var('import_items_for_name', array('fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
} else {
$page_title = get_opendb_lang_var('import_items');
}
echo (_theme_header($page_title));
echo ("<h2>" . $page_title . "</h2>");
echo (format_error_block(get_opendb_lang_var('file_upload_empty', 'prompt', strtoupper(get_file_ext($_FILES['uploadfile']['name'])))));
echo (_theme_footer());
}
} else {
$importPlugin = new PreviewImportPlugin();
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('type_import', array('description' => $importPlugin->get_display_name()));
else
$page_title = get_opendb_lang_var('type_import_items_for_name', array('description' => $importPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
echo (_theme_header($page_title));
echo ("<h2>" . $page_title . " " . get_item_image($HTTP_VARS['s_item_type']) . "</h2>\n");
// no upload file provided - so preview mode.
echo (get_uploaded_form($importPlugin, NULL, $HTTP_VARS));
echo _theme_footer();
}
} else if ($HTTP_VARS['op'] == 'uploaded') {
$import_cache_r = fetch_import_cache_r($HTTP_VARS['ic_sequence_number'], $HTTP_VARS['owner_id']);
if (is_not_empty_array($import_cache_r)) {
$importPlugin = &get_import_plugin($import_cache_r['plugin_name']);
if ($importPlugin !== NULL) {
$inFile = import_cache_fetch_file($HTTP_VARS['ic_sequence_number']);
if ($inFile) {
$fileHandler = new WrapperFileHandler($inFile);
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('type_import', array('description' => $importPlugin->get_display_name()));
else
$page_title = get_opendb_lang_var('type_import_items_for_name', array('description' => $importPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
echo (_theme_header($page_title));
if ($importPlugin->get_plugin_type() == 'row')
echo ("<h2>" . $page_title . " " . get_item_image($HTTP_VARS['s_item_type']) . "</h2>\n");
else
echo ("<h2>" . $page_title . "</h2>");
echo (get_uploaded_form($importPlugin, ($importPlugin->get_plugin_type() == 'row') ? $importPlugin->read_header($fileHandler, $error) : NULL, $HTTP_VARS));
unset($fileHandler);
@fclose($inFile);
echo _theme_footer();
} else {
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($importPlugin !== NULL)
echo _theme_header(get_opendb_lang_var('undefined_error'));
echo ("<p class=\"error\">" . get_opendb_lang_var('undefined_error') . " (" . $import_cache_r['plugin_name'] . ")</p>");
echo _theme_footer();
}
} else { //if(is_not_empty_array($import_cache_r))
echo _theme_header(get_opendb_lang_var('import_cache_file_not_found'));
echo ("<p class=\"error\">" . get_opendb_lang_var('import_cache_file_not_found') . "</p>");
echo _theme_footer();
}
} else if ($HTTP_VARS['op'] == 'import') {
$import_cache_r = fetch_import_cache_r($HTTP_VARS['ic_sequence_number'], $HTTP_VARS['owner_id']);
if (is_not_empty_array($import_cache_r)) {
$importPlugin = &get_import_plugin($import_cache_r['plugin_name']);
if ($importPlugin !== NULL) {
$inFile = import_cache_fetch_file($HTTP_VARS['ic_sequence_number']);
if ($inFile) {
$fileHandler = new WrapperFileHandler($inFile);
// we want to display all items - no pagination.
$HTTP_VARS['items_per_page'] = '';
$listingObject = new HTML_Listing($PHP_SELF, $HTTP_VARS);
$listingObject->setNoRowsMessage(get_opendb_lang_var('no_items_found'));
$cfg_include_header_row = (strcmp($HTTP_VARS['include_header_row'], 'Y') === 0 ? TRUE : FALSE);
$cfg_ignore_duplicate_title = (strcmp($HTTP_VARS['ignore_duplicate_title'], 'Y') === 0 ? TRUE : FALSE);
$cfg_is_trial_run = (strcmp($HTTP_VARS['trial_run'], 'Y') === 0 ? TRUE : FALSE);
$cfg_override_status_type = (strcmp($HTTP_VARS['override_status_type'], 'Y') === 0 ? TRUE : FALSE);
// force disable of duplicate titles.
set_opendb_config_ovrd_var('item_input', 'duplicate_title_support', $cfg_ignore_duplicate_title);
set_opendb_config_ovrd_var('listings', 'show_item_image', FALSE);
//set_opendb_config_ovrd_var('item_input', 'confirm_duplicate_insert', TRUE);
if (is_valid_s_status_type($HTTP_VARS['s_status_type']))
$cfg_default_status_type_r = fetch_status_type_r($HTTP_VARS['s_status_type']);
else
$cfg_default_status_type_r = fetch_status_type_r(fetch_default_status_type());
$itemImportHandler = new ItemImportHandler($HTTP_VARS['owner_id'], $cfg_is_trial_run, $cfg_ignore_duplicate_title, $cfg_override_status_type, $cfg_default_status_type_r, $listingObject);
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('type_import', array('description' => $importPlugin->get_display_name()));
else
$page_title = get_opendb_lang_var('type_import_items_for_name', array('description' => $importPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
echo (_theme_header($page_title));
echo ("<h2>" . $page_title . "</h2>\n");
echo (get_import_choices_table($importPlugin, $cfg_include_header_row, $cfg_ignore_duplicate_title, $cfg_is_trial_run, $cfg_override_status_type, $cfg_default_status_type_r));
$listingObject->startListing();
$listingObject->addHeaderColumn('', 'flag', FALSE); // Success or Failure column
$listingObject->addHeaderColumn(get_opendb_lang_var('type'), 's_item_type', FALSE);
$listingObject->addHeaderColumn(get_opendb_lang_var('title'), 'title', FALSE);
//$listingObject->addHeaderColumn(get_opendb_lang_var('owner'));
if ($cfg_override_status_type !== TRUE)
$listingObject->addHeaderColumn(get_opendb_lang_var('s_status_type'), 's_status_type', FALSE);
$listingObject->addHeaderColumn(get_opendb_lang_var('attributes'), 'attributes', FALSE);
if ($importPlugin->get_plugin_type() == 'row') {
$rowHandler = new RowImportPluginHandler($itemImportHandler, $importPlugin, $fileHandler, $HTTP_VARS['field_column'], $HTTP_VARS['field_default'], $HTTP_VARS['field_initcap']);
if (($resultOfImport = $rowHandler->handleImport($cfg_include_header_row, $HTTP_VARS['s_item_type'])) !== TRUE) {
$importError = $xmlHandler->getError();
}
} else if ($importPlugin->get_plugin_type() == 'xml') {
// XML plugins will perform callbacks directly.
$importPlugin->setItemImportHandler($itemImportHandler);
$xmlHandler = new XMLImportPluginHandler($importPlugin, $fileHandler);
if (($resultOfImport = $xmlHandler->handleImport()) !== TRUE) {
$importError = $xmlHandler->getError();
}
}
// Close file.
unset($fileHandler);
@fclose($inFile);
$listingObject->endListing();
if ($resultOfImport !== TRUE) {
$listingObject->setNoRowsMessage($importError);
echo format_error_block($importError);
}
if ($cfg_is_trial_run) {
echo ("<form action=\"$PHP_SELF\" method=\"POST\">");
echo (get_url_fields($HTTP_VARS, array('op'), array('op2')));
echo ("<input type=\"button\" class=\"button\" onclick=\"this.form.op.value='uploaded'; this.form.submit();\" value=\"" . get_opendb_lang_var('back') . "\">");
echo ("<input type=\"button\" class=\"button\" onclick=\"this.form.trial_run.value='N'; this.form.op.value='import'; this.form.submit();\" value=\"" . get_opendb_lang_var('import_items') . "\">");
echo ("</form>");
} else {
if (is_not_empty_array($itemImportHandler->getItemIDList())) {
$footer_links_r[] = array('url' => 'listings.php?item_id_range=' . urlencode(get_item_id_range($itemImportHandler->getItemIDList())), 'text' => get_opendb_lang_var('list_imported_items', 'count', count($itemImportHandler->getItemIDList())));
}
//Get rid of the file now!
import_cache_delete($HTTP_VARS['ic_sequence_number']);
echo format_footer_links($footer_links_r);
}
// don't need it anymore.
unset($listingObject);
echo _theme_footer();
} else {
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($importPlugin !== NULL)
echo _theme_header(get_opendb_lang_var('undefined_error'));
echo ("<p class=\"error\">" . get_opendb_lang_var('undefined_error') . " (" . $import_cache_r['plugin_name'] . ")</p>");
echo _theme_footer();
}
} else { //if(is_not_empty_array($import_cache_r))
echo _theme_header(get_opendb_lang_var('import_cache_file_not_found'));
echo ("<p class=\"error\">" . get_opendb_lang_var('import_cache_file_not_found') . "</p>");
echo _theme_footer();
}
} else {
if (strlen($HTTP_VARS['owner_id']) > 0) {
if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0)
$page_title = get_opendb_lang_var('import_my_items');
else
$page_title = get_opendb_lang_var('import_items_for_name', array('fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id']));
} else {
$page_title = get_opendb_lang_var('import_items');
}
echo (_theme_header($page_title));
echo ("<h2>" . $page_title . "</h2>");
echo (get_upload_form($HTTP_VARS));
echo _theme_footer();
}
} else { // if(is_file_upload_enabled() && import_check_is_installed())
if (is_file_upload_enabled()) {
echo _theme_header(get_opendb_lang_var('import_not_available'));
echo ("<p class=\"error\">" . get_opendb_lang_var('import_not_available') . "</p>");
opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'Import cache table not installed.');
} else {
echo _theme_header(get_opendb_lang_var('file_upload_not_available'));
echo ("<p class=\"error\">" . get_opendb_lang_var('file_upload_not_available') . "</p>");
}
}
} else { //not an administrator or own user.
opendb_not_authorised_page(array(PERM_USER_IMPORT, PERM_ADMIN_IMPORT));
}
} else { //invalid session
// invalid login, so login instead.
redirect_login($PHP_SELF, $HTTP_VARS);
}
} else { //if(is_site_enabled())
opendb_site_disabled();
}
// Cleanup after begin.inc.php
require_once("./include/end.inc.php");
?>