forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_handler.php
131 lines (116 loc) · 3.66 KB
/
import_handler.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
<?php
/**
* Description:
* Loads appropriate import file parser and processes the data returned.
* Currently supported:
* Palmdesktop (dba file)
* iCal (ics file)
* vCal (vcs file)
* Git Log (text file output from 'git log' command)
*
*
* Notes:
* User defined import routines may be used, see example
* in the SWITCH statement below.
*
* Input parameters:
* FileName: File name specified by user on import.php user's calendar to
* import data into, unless single user = Y or Admin,
* caluser will equal logged in user.
* exc_private: Exclude private records from Palmdesktop import.
* overwrite: Overwrite previous import.
*
* Security:
* TBD
*/
require_once 'includes/init.php';
require_once 'includes/xcal.php';
$error = $sqlLog = '';
print_header();
$overwrite = getValue ( 'overwrite' );
$doOverwrite = ( empty ( $overwrite ) || $overwrite != 'Y' ) ? false : true;
$numDeleted = 0;
if ( ! empty ( $_FILES['FileName'] ) )
$file = $_FILES['FileName'];
if ( empty ( $file ) )
echo translate ( 'No file' ) . '!<br>';
// Handle user
$calUser = getValue ( 'calUser' );
if ( ! empty ( $calUser ) ) {
if ( $single_user == 'N' && ! $is_admin )
$calUser = $login;
} else
$calUser = $login;
$exc_private = getValue( 'exc_private' );
$importcat = getValue( 'importcat' );
$ImportType = getValue( 'ImportType' );
$overwrite = getValue( 'overwrite' );
if ( $importcat == '__import' ) {
$importcat = '';
}
if ( $file['size'] > 0 ) {
switch ( $ImportType ) {
// ADD New modules here:
/*
case 'MODULE':
require_once "import_module.php";
$data = parse_module ( $_FILES['FileName']['tmp_name'] );
break;
*/
case 'PALMDESKTOP':
require_once 'import_palmdesktop.php';
if ( delete_palm_events ( $login ) != 1 )
$errormsg = translate ( 'Error deleting palm events from webcalendar.' );
$data = parse_palmdesktop ( $file['tmp_name'], $exc_private );
$type = 'palm';
break;
case 'VCAL':
$data = parse_vcal ( $file['tmp_name'] );
$type = 'vcal';
break;
case 'ICAL':
$data = parse_ical ( $file['tmp_name'] );
$type = 'ical';
break;
case 'OUTLOOKCSV':
require_once 'import_outlookcsv.php';
$data = parse_outlookcsv ( $file['tmp_name'] );
$type = 'outlookcsv';
break;
// Output from command: 'git log'
case 'GITLOG':
require_once "import_gitlog.php";
$data = parse_gitlog ( $_FILES['FileName']['tmp_name'] );
$type = 'gitlog';
break;
}
$count_con = $count_suc = $error_num = 0;
if ( ! empty ( $data ) && empty ( $errormsg ) ) {
import_data ( $data, $doOverwrite, $type );
echo '
<p>' . translate ( 'Import Results' ) . '</p><br><br>
' . translate ( 'Events successfully imported' ) . ': ' . $count_suc
. '<br>
' . translate ( 'Events from prior import marked as deleted' ) . ': '
. $numDeleted . '<br>
' . ( empty ( $ALLOW_CONFLICTS )
? translate ( 'Conflicting events' ) . ': ' . $count_con . '<br>
' : '' ) . translate ( 'Errors' ) . ': ' . $error_num . '<br><br>';
} elseif ( ! empty ( $errormsg ) )
echo '
<br><br>
<b>' . translate ( 'Error' ) . ':</b> ' . $errormsg . '<br>';
else
echo '
<br><br>
<b>' . translate ( 'Error' ) . ':</b> '
. translate( 'There was an error parsing the import file or no events were returned.' ) . "<br>" . translate("Error") . ": " . htmlentities($errormsg)
. '<br>';
} else
echo '
<br><br>
<b>' . translate ( 'Error' ) . ':</b> '
. translate( 'The import file contained no data.' ) . '<br>';
// echo "<hr>$sqlLog\n";
echo print_trailer();
?>