forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_palmdesktop.php
91 lines (83 loc) · 2.61 KB
/
import_palmdesktop.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
<?php
/**
* Parse the datebook file.
*
* @return array the data hash.
*/
function parse_palmdesktop ( $file, $exc_private = 1 ) {
$file = EscapeShellArg ( $file );
$exc_private = EscapeShellArg ( $exc_private );
exec ( 'perl tools/palm_datebook.pl ' . "$file $exc_private", $Entries );
$data = [];
foreach ($Entries as $line_num => $line) {
$data[] = ParseLine ( $line );
}
return $data;
}
/**
* Delete all Palm Events for $login to clear any events deleted in the palm.
*
* @return 1 if successful.
*/
function delete_palm_events ( $login ) {
$res = dbi_execute ( 'SELECT cal_id FROM webcal_import_data
WHERE cal_login = ? AND cal_import_type = ?', [$login, 'palm'] );
if ( $res ) {
while ( $row = dbi_fetch_row ( $res ) ) {
dbi_execute ( 'DELETE FROM webcal_blob WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_entry_log WHERE cal_entry_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_entry_repeats WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_entry_repeats_not WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_import_data WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_reminders WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_site_extras WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_entry_user WHERE cal_id = ?',
[$row[0]] );
dbi_execute ( 'DELETE FROM webcal_entry WHERE cal_id = ?',
[$row[0]] );
}
}
dbi_free_result ( $res );
return 1;
}
function ParseLine ( $line ) {
global $calUser;
list (
$Entry['RecordID'],
$Entry['StartTime'],
$Entry['EndTime'],
$Entry['Summary'],
$Entry['Duration'],
$Entry['Description'],
$Entry['Untimed'],
$Entry['Private'],
$Entry['Category'],
$Entry['AlarmSet'],
$Entry['AlarmAdvanceAmount'],
$Entry['AlarmAdvanceType'],
$Entry['Repeat']['Interval'],
$Entry['Repeat']['Frequency'],
$Entry['Repeat']['EndTime'],
$Exceptions,
$Entry['Repeat']['RepeatDays'],
$WeekNum,
) = explode ( '|', $line );
// Adjust times to users Timezone if not Untimed.
if ( isset ( $Entry['Untimed'] ) && $Entry['Untimed'] == 0 ) {
$Entry['StartTime'] -= date ( 'Z', $Entry['StartTime'] );
$Entry['EndTime'] -= date ( 'Z', $Entry['EndTime'] );
}
if ( $Exceptions )
$Entry['Repeat']['Exceptions'] = explode ( ': ', $Exceptions );
if ( ( $WeekNum == '5' ) && ( $Entry['Repeat']['Interval'] == '3' ) )
$Entry['Repeat']['Interval'] = '6';
return $Entry;
}
?>