1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* eGroupWare |
4
|
|
|
* |
5
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
6
|
|
|
* @package calendar |
7
|
|
|
* @subpackage importexport |
8
|
|
|
* @link http://www.egroupware.org |
9
|
|
|
* @author Nathan Gray |
10
|
|
|
* @copyright Nathan Gray |
11
|
|
|
* @version $Id$ |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* import ical for calendar |
17
|
|
|
*/ |
18
|
|
|
class calendar_import_ical implements importexport_iface_import_plugin { |
19
|
|
|
|
20
|
|
|
private static $plugin_options = array( |
|
|
|
|
21
|
|
|
'fieldsep', // char |
22
|
|
|
'charset', // string |
23
|
|
|
'owner', // int |
24
|
|
|
'update_cats', // string {override|add} overides record |
25
|
|
|
// with cat(s) from csv OR add the cat from |
26
|
|
|
// csv file to exeisting cat(s) of record |
27
|
|
|
'num_header_lines', // int number of header lines |
28
|
|
|
'field_conversion', // array( $csv_col_num => conversion) |
29
|
|
|
'field_mapping', // array( $csv_col_num => adb_filed) |
30
|
|
|
'conditions', /* => array containing condition arrays: |
31
|
|
|
'type' => exists, // exists |
32
|
|
|
'string' => '#kundennummer', |
33
|
|
|
'true' => array( |
34
|
|
|
'action' => update, |
35
|
|
|
'last' => true, |
36
|
|
|
), |
37
|
|
|
'false' => array( |
38
|
|
|
'action' => insert, |
39
|
|
|
'last' => true, |
40
|
|
|
),*/ |
41
|
|
|
|
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* actions wich could be done to data entries |
46
|
|
|
*/ |
47
|
|
|
protected static $actions = array(); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* conditions for actions |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected static $conditions = array(); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var definition |
58
|
|
|
*/ |
59
|
|
|
private $definition; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var bo |
63
|
|
|
*/ |
64
|
|
|
private $bo; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* For figuring out if an entry has changed |
68
|
|
|
*/ |
69
|
|
|
protected $tracking; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var bool |
73
|
|
|
*/ |
74
|
|
|
private $dry_run = false; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var bool is current user admin? |
78
|
|
|
*/ |
79
|
|
|
private $is_admin = false; |
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var int |
83
|
|
|
*/ |
84
|
|
|
private $user = null; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* List of import warnings |
88
|
|
|
*/ |
89
|
|
|
protected $warnings = array(); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* List of import errors |
93
|
|
|
*/ |
94
|
|
|
protected $errors = array(); |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* List of actions, and how many times that action was taken |
98
|
|
|
*/ |
99
|
|
|
protected $results = array(); |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* imports entries according to given definition object. |
103
|
|
|
* @param resource $_stream |
104
|
|
|
* @param string $_charset |
105
|
|
|
* @param definition $_definition |
106
|
|
|
*/ |
107
|
|
|
public function import( $_stream, importexport_definition $_definition ) { |
108
|
|
|
|
109
|
|
|
$this->definition = $_definition; |
110
|
|
|
|
111
|
|
|
// user, is admin ? |
112
|
|
|
$this->user = $GLOBALS['egw_info']['user']['account_id']; |
113
|
|
|
|
114
|
|
|
// dry run? |
115
|
|
|
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false; |
116
|
|
|
|
117
|
|
|
// fetch the addressbook bo |
118
|
|
|
$this->bo= new calendar_boupdate(); |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
// Failures |
122
|
|
|
$this->errors = array(); |
123
|
|
|
|
124
|
|
|
@set_time_limit(0); // try switching execution time limit off |
125
|
|
|
|
126
|
|
|
$calendar_ical = new calendar_ical; |
127
|
|
|
$calendar_ical->setSupportedFields('file', ''); |
128
|
|
|
if($this->dry_run) |
129
|
|
|
{ |
130
|
|
|
// No real dry run for iCal |
131
|
|
|
echo lang("No preview for iCal"); |
132
|
|
|
return; |
133
|
|
|
} |
134
|
|
|
// switch off notifications by default |
135
|
|
|
if (!isset($_definition->plugin_options['no_notification'])) |
136
|
|
|
{ |
137
|
|
|
$_definition->plugin_options['no_notification'] = true; |
138
|
|
|
} |
139
|
|
|
// User wants conflicting events to not be imported |
140
|
|
|
if($_definition->plugin_options['skip_conflicts']) |
141
|
|
|
{ |
142
|
|
|
$calendar_ical->conflict_callback = array($this, 'conflict_warning'); |
143
|
|
|
} |
144
|
|
|
if (!$calendar_ical->importVCal($_stream, -1,null,false,0,'',null,null,null,$_definition->plugin_options['no_notification'])) |
145
|
|
|
{ |
146
|
|
|
$this->errors[] = lang('Error: importing the iCal'); |
147
|
|
|
} |
148
|
|
|
else |
149
|
|
|
{ |
150
|
|
|
$this->results['imported'] += $calendar_ical->events_imported; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $calendar_ical->events_imported; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Add a warning message about conflicting events |
159
|
|
|
* |
160
|
|
|
* @param int $record_num Current record index |
161
|
|
|
* @param Array $conflicts List of found conflicting events |
162
|
|
|
*/ |
163
|
|
|
public function conflict_warning(&$event, &$conflicts) |
164
|
|
|
{ |
165
|
|
|
$warning = EGroupware\Api\DateTime::to($event['start']) . ' ' . $event['title'] . ' ' . lang('Conflicts') . ':'; |
166
|
|
|
foreach($conflicts as $conflict) |
167
|
|
|
{ |
168
|
|
|
$warning .= "<br />\n" . EGroupware\Api\DateTime::to($conflict['start']) . "\t" . $conflict['title']; |
169
|
|
|
} |
170
|
|
|
$this->warnings[] = $warning; |
171
|
|
|
|
172
|
|
|
// iCal will always count as imported, even if it wasn't |
173
|
|
|
$this->results['imported'] -= 1; |
174
|
|
|
|
175
|
|
|
$this->results['skipped']++; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* returns translated name of plugin |
180
|
|
|
* |
181
|
|
|
* @return string name |
182
|
|
|
*/ |
183
|
|
|
public static function get_name() { |
184
|
|
|
return lang('Calendar iCal import'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* returns translated (user) description of plugin |
189
|
|
|
* |
190
|
|
|
* @return string descriprion |
191
|
|
|
*/ |
192
|
|
|
public static function get_description() { |
193
|
|
|
return lang("Imports events into your Calendar from an iCal File."); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* retruns file suffix(s) plugin can handle (e.g. csv) |
198
|
|
|
* |
199
|
|
|
* @return string suffix (comma seperated) |
200
|
|
|
*/ |
201
|
|
|
public static function get_filesuffix() { |
202
|
|
|
return 'ics'; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* return etemplate components for options. |
207
|
|
|
* @abstract We can't deal with etemplate objects here, as an uietemplate |
208
|
|
|
* objects itself are scipt orientated and not "dialog objects" |
209
|
|
|
* |
210
|
|
|
* @return array ( |
211
|
|
|
* name => string, |
212
|
|
|
* content => array, |
213
|
|
|
* sel_options => array, |
214
|
|
|
* preserv => array, |
215
|
|
|
* ) |
216
|
|
|
*/ |
217
|
|
|
public function get_options_etpl() { |
218
|
|
|
// lets do it! |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* returns etemplate name for slectors of this plugin |
223
|
|
|
* |
224
|
|
|
* @return string etemplate name |
225
|
|
|
*/ |
226
|
|
|
public function get_selectors_etpl() { |
227
|
|
|
// lets do it! |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns warnings that were encountered during importing |
232
|
|
|
* Maximum of one warning message per record, but you can append if you need to |
233
|
|
|
* |
234
|
|
|
* @return Array ( |
235
|
|
|
* record_# => warning message |
236
|
|
|
* ) |
237
|
|
|
*/ |
238
|
|
|
public function get_warnings() { |
239
|
|
|
return $this->warnings; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Returns errors that were encountered during importing |
244
|
|
|
* Maximum of one error message per record, but you can append if you need to |
245
|
|
|
* |
246
|
|
|
* @return Array ( |
247
|
|
|
* record_# => error message |
248
|
|
|
* ) |
249
|
|
|
*/ |
250
|
|
|
public function get_errors() { |
251
|
|
|
return $this->errors; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Returns a list of actions taken, and the number of records for that action. |
256
|
|
|
* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
257
|
|
|
* |
258
|
|
|
* @return Array ( |
259
|
|
|
* action => record count |
260
|
|
|
* ) |
261
|
|
|
*/ |
262
|
|
|
public function get_results() { |
263
|
|
|
return $this->results; |
264
|
|
|
} |
265
|
|
|
} // end of iface_export_plugin |
266
|
|
|
?> |
267
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.