@@ -118,8 +118,7 @@ discard block |
||
118 | 118 | /** |
119 | 119 | * imports entries according to given definition object. |
120 | 120 | * @param resource $_stream |
121 | - * @param string $_charset |
|
122 | - * @param definition $_definition |
|
121 | + * @param importexport_definition $_definition |
|
123 | 122 | */ |
124 | 123 | public function import( $_stream, importexport_definition $_definition ) { |
125 | 124 | $import_csv = new importexport_import_csv( $_stream, array( |
@@ -222,7 +221,7 @@ discard block |
||
222 | 221 | * |
223 | 222 | * Updates the count of actions taken |
224 | 223 | * |
225 | - * @return boolean success |
|
224 | + * @return null|boolean success |
|
226 | 225 | */ |
227 | 226 | protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
228 | 227 | { |
@@ -274,7 +273,7 @@ discard block |
||
274 | 273 | * @param condition array = array('string' => field name) |
275 | 274 | * @param matches - On return, will be filled with matching records |
276 | 275 | * |
277 | - * @return boolean |
|
276 | + * @return boolean|null |
|
278 | 277 | */ |
279 | 278 | protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$matches = array()) |
280 | 279 | { |
@@ -451,7 +450,7 @@ discard block |
||
451 | 450 | /** |
452 | 451 | * Allows an extending class to alter a row for preview |
453 | 452 | * |
454 | - * @param egw_record $row_entry |
|
453 | + * @param importexport_iface_egw_record $row_entry |
|
455 | 454 | */ |
456 | 455 | protected function row_preview(importexport_iface_egw_record &$row_entry) |
457 | 456 | { |
@@ -523,7 +522,7 @@ discard block |
||
523 | 522 | * Get the primary key for an entry based on a custom field |
524 | 523 | * Returns key, so regular linking can take over |
525 | 524 | * |
526 | - * @param int $record_number Row number, used for errors |
|
525 | + * @param int $record_num Row number, used for errors |
|
527 | 526 | * @param string $app Target application name |
528 | 527 | * @param string $value CSV value in the form of custom_field_name:value |
529 | 528 | */ |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $record_class = isset(static::$record_class) ? static::$record_class : "{$app}_egw_record"; |
164 | 164 | |
165 | 165 | // Needed for categories to work right |
166 | - $GLOBALS['egw_info']['flags']['currentapp'] = $app; |
|
166 | + $GLOBALS['egw_info']['flags']['currentapp'] = $app; |
|
167 | 167 | |
168 | 168 | $this->init($_definition); |
169 | 169 | |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
218 | - *Import a single record |
|
219 | - * |
|
220 | - * You don't need to worry about mappings or translations, they've been done already. |
|
221 | - * You do need to handle the conditions and the actions taken. |
|
222 | - * |
|
223 | - * Updates the count of actions taken |
|
224 | - * |
|
225 | - * @return boolean success |
|
226 | - */ |
|
218 | + *Import a single record |
|
219 | + * |
|
220 | + * You don't need to worry about mappings or translations, they've been done already. |
|
221 | + * You do need to handle the conditions and the actions taken. |
|
222 | + * |
|
223 | + * Updates the count of actions taken |
|
224 | + * |
|
225 | + * @return boolean success |
|
226 | + */ |
|
227 | 227 | protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
228 | 228 | { |
229 | 229 | if ( $this->definition->plugin_options['conditions'] ) { |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @param stream $stream |
404 | 404 | * @param importexport_definition $definition |
405 | 405 | * @return String HTML for preview |
406 | - */ |
|
406 | + */ |
|
407 | 407 | public function preview( $stream, importexport_definition $definition ) |
408 | 408 | { |
409 | 409 | $this->import($stream, $definition); |
@@ -639,37 +639,37 @@ discard block |
||
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
642 | - * Returns warnings that were encountered during importing |
|
643 | - * Maximum of one warning message per record, but you can append if you need to |
|
644 | - * |
|
645 | - * @return Array ( |
|
646 | - * record_# => warning message |
|
647 | - * ) |
|
648 | - */ |
|
642 | + * Returns warnings that were encountered during importing |
|
643 | + * Maximum of one warning message per record, but you can append if you need to |
|
644 | + * |
|
645 | + * @return Array ( |
|
646 | + * record_# => warning message |
|
647 | + * ) |
|
648 | + */ |
|
649 | 649 | public function get_warnings() { |
650 | 650 | return $this->warnings; |
651 | 651 | } |
652 | 652 | |
653 | 653 | /** |
654 | - * Returns errors that were encountered during importing |
|
655 | - * Maximum of one error message per record, but you can append if you need to |
|
656 | - * |
|
657 | - * @return Array ( |
|
658 | - * record_# => error message |
|
659 | - * ) |
|
660 | - */ |
|
654 | + * Returns errors that were encountered during importing |
|
655 | + * Maximum of one error message per record, but you can append if you need to |
|
656 | + * |
|
657 | + * @return Array ( |
|
658 | + * record_# => error message |
|
659 | + * ) |
|
660 | + */ |
|
661 | 661 | public function get_errors() { |
662 | 662 | return $this->errors; |
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
666 | - * Returns a list of actions taken, and the number of records for that action. |
|
667 | - * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
|
668 | - * |
|
669 | - * @return Array ( |
|
670 | - * action => record count |
|
671 | - * ) |
|
672 | - */ |
|
666 | + * Returns a list of actions taken, and the number of records for that action. |
|
667 | + * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
|
668 | + * |
|
669 | + * @return Array ( |
|
670 | + * action => record count |
|
671 | + * ) |
|
672 | + */ |
|
673 | 673 | public function get_results() { |
674 | 674 | return $this->results; |
675 | 675 | } |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | * should get you started on building a CSV plugin for an application fairly quickly. |
19 | 19 | * |
20 | 20 | */ |
21 | -abstract class importexport_basic_import_csv implements importexport_iface_import_plugin { |
|
21 | +abstract class importexport_basic_import_csv implements importexport_iface_import_plugin { |
|
22 | 22 | |
23 | 23 | protected static $plugin_options = array( |
24 | - 'fieldsep', // char |
|
25 | - 'charset', // string |
|
26 | - 'record_owner', // int |
|
27 | - 'update_cats', // string {override|add} overides record |
|
24 | + 'fieldsep', // char |
|
25 | + 'charset', // string |
|
26 | + 'record_owner', // int |
|
27 | + 'update_cats', // string {override|add} overides record |
|
28 | 28 | // with cat(s) from csv OR add the cat from |
29 | 29 | // csv file to exeisting cat(s) of record |
30 | 30 | 'num_header_lines', // int number of header lines |
31 | 31 | 'field_conversion', // array( $csv_col_num => conversion) |
32 | - 'field_mapping', // array( $csv_col_num => adb_filed) |
|
33 | - 'conditions', /* => array containing condition arrays: |
|
32 | + 'field_mapping', // array( $csv_col_num => adb_filed) |
|
33 | + 'conditions', /* => array containing condition arrays: |
|
34 | 34 | 'type' => exists, // exists |
35 | 35 | 'string' => '#kundennummer', |
36 | 36 | 'true' => array( |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * Actions wich could be done to data entries |
49 | 49 | * If your plugin supports different actions, be sure to modify this array |
50 | 50 | */ |
51 | - protected static $actions = array( 'none', 'update', 'insert', 'delete', ); |
|
51 | + protected static $actions = array('none', 'update', 'insert', 'delete',); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Conditions for actions |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @var array |
58 | 58 | */ |
59 | - protected static $conditions = array( 'exists', 'equal', 'less_than'); |
|
59 | + protected static $conditions = array('exists', 'equal', 'less_than'); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * This is the definition that will be used to deal with the CSV file |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * @param string $_charset |
122 | 122 | * @param definition $_definition |
123 | 123 | */ |
124 | - public function import( $_stream, importexport_definition $_definition ) { |
|
125 | - $import_csv = new importexport_import_csv( $_stream, array( |
|
124 | + public function import($_stream, importexport_definition $_definition) { |
|
125 | + $import_csv = new importexport_import_csv($_stream, array( |
|
126 | 126 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
127 | 127 | 'charset' => $_definition->plugin_options['charset'], |
128 | 128 | )); |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | $this->definition = $_definition; |
131 | 131 | |
132 | 132 | // user, is admin ? |
133 | - $this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin']; |
|
133 | + $this->is_admin = isset($GLOBALS['egw_info']['user']['apps']['admin']) && $GLOBALS['egw_info']['user']['apps']['admin']; |
|
134 | 134 | $this->user = $GLOBALS['egw_info']['user']['account_id']; |
135 | 135 | |
136 | 136 | // dry run? |
137 | - $this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false; |
|
137 | + $this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false; |
|
138 | 138 | |
139 | 139 | // set FieldMapping. |
140 | 140 | $import_csv->mapping = $_definition->plugin_options['field_mapping']; |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | $import_csv->conversion = $_definition->plugin_options['field_conversion']; |
144 | 144 | |
145 | 145 | //check if file has a header lines |
146 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
146 | + if (isset($_definition->plugin_options['num_header_lines']) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
147 | 147 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
148 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
148 | + } elseif (isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
149 | 149 | // First method is preferred |
150 | 150 | $import_csv->skip_records(1); |
151 | 151 | } |
@@ -167,38 +167,38 @@ discard block |
||
167 | 167 | |
168 | 168 | $this->init($_definition); |
169 | 169 | |
170 | - while ( $record = $import_csv->get_record() ) { |
|
170 | + while ($record = $import_csv->get_record()) { |
|
171 | 171 | $success = false; |
172 | 172 | |
173 | 173 | // don't import empty records |
174 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
174 | + if (count(array_unique($record)) < 2) continue; |
|
175 | 175 | |
176 | 176 | |
177 | 177 | $warning = importexport_import_csv::convert($record, $record_class::$types, $app, $this->lookups, $_definition->plugin_options['convert']); |
178 | - if($warning) $this->warnings[$import_csv->get_current_position()] = $warning; |
|
178 | + if ($warning) $this->warnings[$import_csv->get_current_position()] = $warning; |
|
179 | 179 | |
180 | 180 | $egw_record = new $record_class(); |
181 | 181 | $egw_record->set_record($record); |
182 | 182 | $success = $this->import_record($egw_record, $import_csv); |
183 | 183 | |
184 | - if($success) |
|
184 | + if ($success) |
|
185 | 185 | { |
186 | 186 | $this->do_special_fields($egw_record, $import_csv); |
187 | 187 | } |
188 | - if($success) $count++; |
|
188 | + if ($success) $count++; |
|
189 | 189 | |
190 | 190 | // Add some more time |
191 | - if($success && $import_csv->get_current_position() > 0 && $import_csv->get_current_position() % 100 == 0) |
|
191 | + if ($success && $import_csv->get_current_position() > 0 && $import_csv->get_current_position() % 100 == 0) |
|
192 | 192 | { |
193 | 193 | set_time_limit(10); |
194 | 194 | } |
195 | 195 | |
196 | 196 | // Keep a few records for preview, but process the whole file |
197 | - if($this->dry_run && $import_csv->get_current_position() < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) |
|
197 | + if ($this->dry_run && $import_csv->get_current_position() < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) |
|
198 | 198 | { |
199 | 199 | $this->preview_records[] = $egw_record; |
200 | 200 | } |
201 | - if(count($this->warnings) > self::MAX_MESSAGES || count($this->errors) > self::MAX_MESSAGES) |
|
201 | + if (count($this->warnings) > self::MAX_MESSAGES || count($this->errors) > self::MAX_MESSAGES) |
|
202 | 202 | { |
203 | 203 | $this->errors[] = 'Too many errors, aborted'; |
204 | 204 | break; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * Stub to hook into import initialization - set lookups, etc. |
212 | 212 | */ |
213 | - protected function init(importexport_definition &$definition) |
|
213 | + protected function init(importexport_definition&$definition) |
|
214 | 214 | { |
215 | 215 | } |
216 | 216 | |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @return boolean success |
226 | 226 | */ |
227 | - protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
|
227 | + protected function import_record(importexport_iface_egw_record&$record, &$import_csv) |
|
228 | 228 | { |
229 | - if ( $this->definition->plugin_options['conditions'] ) { |
|
230 | - foreach ( $this->definition->plugin_options['conditions'] as $condition ) { |
|
229 | + if ($this->definition->plugin_options['conditions']) { |
|
230 | + foreach ($this->definition->plugin_options['conditions'] as $condition) { |
|
231 | 231 | $result = false; |
232 | - switch ( $condition['type'] ) { |
|
232 | + switch ($condition['type']) { |
|
233 | 233 | // exists |
234 | 234 | case 'exists' : |
235 | 235 | // Check for that record |
@@ -245,23 +245,23 @@ discard block |
||
245 | 245 | die('condition / action not supported!!!'); |
246 | 246 | break; |
247 | 247 | } |
248 | - if($result) |
|
248 | + if ($result) |
|
249 | 249 | { |
250 | 250 | // Apply true action to any matching records found |
251 | 251 | $action = $condition['true']; |
252 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
252 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
253 | 253 | } |
254 | 254 | else |
255 | 255 | { |
256 | 256 | // Apply false action if no matching records found |
257 | 257 | $action = $condition['false']; |
258 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
258 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
259 | 259 | } |
260 | 260 | if ($action['stop']) break; |
261 | 261 | } |
262 | 262 | } else { |
263 | 263 | // unconditional insert |
264 | - $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
|
264 | + $success = $this->action('insert', $record, $import_csv->get_current_position()); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return $success; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return boolean |
278 | 278 | */ |
279 | - protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$matches = array()) |
|
279 | + protected function exists(importexport_iface_egw_record&$record, Array &$condition, &$matches = array()) |
|
280 | 280 | { |
281 | 281 | } |
282 | 282 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | - protected function equal(importexport_iface_egw_record &$record, Array &$condition) |
|
291 | + protected function equal(importexport_iface_egw_record&$record, Array &$condition) |
|
292 | 292 | { |
293 | 293 | $field = $condition['string']; |
294 | 294 | return $record->$field == $condition['op_2']; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return boolean |
305 | 305 | */ |
306 | - protected function less_than(importexport_iface_egw_record &$record, Array &$condition) |
|
306 | + protected function less_than(importexport_iface_egw_record&$record, Array &$condition) |
|
307 | 307 | { |
308 | 308 | $field = $condition['string']; |
309 | 309 | return $record->$field < $condition['op_2']; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @param int $record_num Which record number is being dealt with. Used for error messages. |
323 | 323 | * @return bool success or not |
324 | 324 | */ |
325 | - protected abstract function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 ); |
|
325 | + protected abstract function action($_action, importexport_iface_egw_record&$record, $record_num = 0); |
|
326 | 326 | |
327 | 327 | /** |
328 | 328 | * Handle special fields |
@@ -332,51 +332,51 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @param importexport_iface_egw_record $record |
334 | 334 | */ |
335 | - protected function do_special_fields(importexport_iface_egw_record &$record, &$import_csv) |
|
335 | + protected function do_special_fields(importexport_iface_egw_record&$record, &$import_csv) |
|
336 | 336 | { |
337 | 337 | $id = $record->get_identifier(); |
338 | 338 | |
339 | 339 | // Warn if there's no ID unless it's a dry_run because there probably won't be an ID then |
340 | - if(!$this->dry_run && !$id) |
|
340 | + if (!$this->dry_run && !$id) |
|
341 | 341 | { |
342 | 342 | $this->warnings[$import_csv->get_current_position()] .= "Unable to link, no identifier for record"; |
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - foreach(self::$special_fields as $field => $desc) { |
|
347 | - if(!$record->$field) continue; |
|
348 | - if(strpos($field, 'link') === 0) { |
|
349 | - list($app, $app_id) = explode(':', $record->$field,2); |
|
346 | + foreach (self::$special_fields as $field => $desc) { |
|
347 | + if (!$record->$field) continue; |
|
348 | + if (strpos($field, 'link') === 0) { |
|
349 | + list($app, $app_id) = explode(':', $record->$field, 2); |
|
350 | 350 | |
351 | - list($link, $type) = explode('_',$field); |
|
351 | + list($link, $type) = explode('_', $field); |
|
352 | 352 | |
353 | 353 | // Searching, take first result |
354 | - if($type == 'custom') |
|
354 | + if ($type == 'custom') |
|
355 | 355 | { |
356 | 356 | $app_id = $this->link_by_cf($record, $app, $app_id, $import_csv->get_current_position()); |
357 | 357 | } |
358 | - else if($type == 'search') |
|
358 | + else if ($type == 'search') |
|
359 | 359 | { |
360 | 360 | $result = Link::query($app, $app_id); |
361 | 361 | do |
362 | 362 | { |
363 | 363 | $app_id = key($result); |
364 | 364 | shift($result); |
365 | - } while($result && !$app_id); |
|
365 | + } while ($result && !$app_id); |
|
366 | 366 | } |
367 | 367 | } else if (in_array($field, array_keys($GLOBALS['egw_info']['apps']))) { |
368 | 368 | $app = $field; |
369 | 369 | $app_id = $record->$field; |
370 | 370 | |
371 | 371 | // Searching, take first result |
372 | - if(!is_numeric($app_id)) |
|
372 | + if (!is_numeric($app_id)) |
|
373 | 373 | { |
374 | 374 | $result = Link::query($app, $app_id); |
375 | 375 | do |
376 | 376 | { |
377 | 377 | $app_id = key($result); |
378 | 378 | shift($result); |
379 | - } while($result && !$app_id); |
|
379 | + } while ($result && !$app_id); |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | else if ($field == 'contact') |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | } |
388 | 388 | if (!$this->dry_run && $app && $app_id && ($app != $this->definition->application || $app_id != $id)) |
389 | 389 | { |
390 | - $link_id = Link::link($this->definition->application,$id,$app,$app_id); |
|
390 | + $link_id = Link::link($this->definition->application, $id, $app, $app_id); |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | } |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | * @param importexport_definition $definition |
405 | 405 | * @return String HTML for preview |
406 | 406 | */ |
407 | - public function preview( $stream, importexport_definition $definition ) |
|
407 | + public function preview($stream, importexport_definition $definition) |
|
408 | 408 | { |
409 | 409 | $this->import($stream, $definition); |
410 | 410 | rewind($stream); |
411 | 411 | |
412 | 412 | // Set up result |
413 | - $rows = array('h1'=>array(),'f1'=>array(),'.h1'=>'class=th'); |
|
413 | + $rows = array('h1'=>array(), 'f1'=>array(), '.h1'=>'class=th'); |
|
414 | 414 | |
415 | 415 | // Load labels for app |
416 | 416 | $record_class = get_class($this->preview_records[0]); |
@@ -419,27 +419,27 @@ discard block |
||
419 | 419 | $labels = array_combine($definition->plugin_options['field_mapping'], $definition->plugin_options['field_mapping']); |
420 | 420 | |
421 | 421 | $plugin = get_called_class(); |
422 | - $wizard_name = $definition->application . '_wizard_' . str_replace($definition->application . '_', '', $plugin); |
|
422 | + $wizard_name = $definition->application.'_wizard_'.str_replace($definition->application.'_', '', $plugin); |
|
423 | 423 | try { |
424 | 424 | $wizard = new $wizard_name; |
425 | 425 | $fields = $wizard->get_import_fields(); |
426 | - foreach($labels as $field => &$label) |
|
426 | + foreach ($labels as $field => &$label) |
|
427 | 427 | { |
428 | - if($fields[$field]) $label = $fields[$field]; |
|
428 | + if ($fields[$field]) $label = $fields[$field]; |
|
429 | 429 | } |
430 | 430 | } catch (Exception $e) { |
431 | 431 | Api\Translation::add_app($definition->application); |
432 | - foreach($labels as $field => &$label) { |
|
432 | + foreach ($labels as $field => &$label) { |
|
433 | 433 | $label = lang($label); |
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | 437 | // Set up HTML |
438 | 438 | $rows['h1'] = $labels; |
439 | - foreach($this->preview_records as $i => $row_data) |
|
439 | + foreach ($this->preview_records as $i => $row_data) |
|
440 | 440 | { |
441 | 441 | // Convert to human-friendly |
442 | - importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups); |
|
442 | + importexport_export_csv::convert($row_data, $record_class::$types, $definition->application, $this->lookups); |
|
443 | 443 | $this->row_preview($row_data); |
444 | 444 | $rows[] = $row_data->get_record_array(); |
445 | 445 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * |
454 | 454 | * @param egw_record $row_entry |
455 | 455 | */ |
456 | - protected function row_preview(importexport_iface_egw_record &$row_entry) |
|
456 | + protected function row_preview(importexport_iface_egw_record&$row_entry) |
|
457 | 457 | { |
458 | 458 | } |
459 | 459 | |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @param string $org_name |
469 | 469 | * @return int|boolean Contact ID of first match, or false if none found |
470 | 470 | */ |
471 | - public static function addr_id( $n_family,$n_given=null,$org_name=null, &$record=null) { |
|
471 | + public static function addr_id($n_family, $n_given = null, $org_name = null, &$record = null) { |
|
472 | 472 | |
473 | 473 | // find in Addressbook, at least n_family AND (n_given OR org_name) have to match |
474 | 474 | static $contacts; |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | list($n_family, $n_given, $org_name) = explode(',', $n_family); |
479 | 479 | } |
480 | 480 | $n_family = trim($n_family); |
481 | - if(!is_null($n_given)) $n_given = trim($n_given); |
|
481 | + if (!is_null($n_given)) $n_given = trim($n_given); |
|
482 | 482 | if (!is_object($contacts)) |
483 | 483 | { |
484 | 484 | $contacts = new Api\Contacts(); |
@@ -486,10 +486,10 @@ discard block |
||
486 | 486 | if (!is_null($org_name)) // org_name given? |
487 | 487 | { |
488 | 488 | $org_name = trim($org_name); |
489 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); |
|
489 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_family=$n_family,n_given=$n_given,org_name=$org_name"); |
|
490 | 490 | if (!count($addrs)) |
491 | 491 | { |
492 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name",'','n_family,org_name'); |
|
492 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_family=$n_family,org_name=$org_name", '', 'n_family,org_name'); |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) // first name given and no result so far |
@@ -498,11 +498,11 @@ discard block |
||
498 | 498 | } |
499 | 499 | if (is_null($n_given) && is_null($org_name)) // just one name given, check against fn (= full name) |
500 | 500 | { |
501 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_fn=$n_family",'','n_fn' ); |
|
501 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_fn=$n_family", '', 'n_fn'); |
|
502 | 502 | } |
503 | 503 | if (count($addrs)) |
504 | 504 | { |
505 | - if(!$record || !$record->get_identifier()) |
|
505 | + if (!$record || !$record->get_identifier()) |
|
506 | 506 | { |
507 | 507 | return $addrs[0]['id']; |
508 | 508 | } |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | { |
513 | 513 | $id = key($addrs); |
514 | 514 | array_shift($addrs); |
515 | - } while($addrs && !$id && $id == $record->get_identifier()); |
|
515 | + } while ($addrs && !$id && $id == $record->get_identifier()); |
|
516 | 516 | return $id; |
517 | 517 | } |
518 | 518 | } |
@@ -527,22 +527,22 @@ discard block |
||
527 | 527 | * @param string $app Target application name |
528 | 528 | * @param string $value CSV value in the form of custom_field_name:value |
529 | 529 | */ |
530 | - protected function link_by_cf(importexport_iface_egw_record &$record, $app, $value,$record_num) |
|
530 | + protected function link_by_cf(importexport_iface_egw_record&$record, $app, $value, $record_num) |
|
531 | 531 | { |
532 | 532 | $app_id = false; |
533 | 533 | |
534 | - list($custom_field, $value) = explode(':',$value); |
|
534 | + list($custom_field, $value) = explode(':', $value); |
|
535 | 535 | // Find matching entry |
536 | - if($app && $custom_field && $value) |
|
536 | + if ($app && $custom_field && $value) |
|
537 | 537 | { |
538 | 538 | $cfs = Api\Storage\Customfields::get($app); |
539 | 539 | // Error if no custom fields, probably something wrong in definition |
540 | - if(!$cfs[$custom_field]) |
|
540 | + if (!$cfs[$custom_field]) |
|
541 | 541 | { |
542 | 542 | // Check for users specifing label instead of name |
543 | - foreach($cfs as $name => $settings) |
|
543 | + foreach ($cfs as $name => $settings) |
|
544 | 544 | { |
545 | - if(strtolower($settings['label']) == strtolower($custom_field)) |
|
545 | + if (strtolower($settings['label']) == strtolower($custom_field)) |
|
546 | 546 | { |
547 | 547 | $custom_field = $name; |
548 | 548 | break; |
@@ -551,30 +551,30 @@ discard block |
||
551 | 551 | } |
552 | 552 | |
553 | 553 | // Couldn't find field, give an error - something's wrong |
554 | - if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)]) { |
|
554 | + if (!$cfs[$custom_field] && !$cfs[substr($custom_field, 1)]) { |
|
555 | 555 | $this->errors[$record_num] .= lang('No custom field "%1" for %2.', |
556 | 556 | $custom_field, lang($app)); |
557 | 557 | return false; |
558 | 558 | } |
559 | - if($custom_field[0] != '#') $custom_field = '#' . $custom_field; |
|
559 | + if ($custom_field[0] != '#') $custom_field = '#'.$custom_field; |
|
560 | 560 | error_log("Searching for $custom_field = $value"); |
561 | 561 | // Search |
562 | - if(Link::get_registry($app, 'query')) |
|
562 | + if (Link::get_registry($app, 'query')) |
|
563 | 563 | { |
564 | - $options = array('filter' => array("$custom_field = " . $GLOBALS['egw']->db->quote($value))); |
|
564 | + $options = array('filter' => array("$custom_field = ".$GLOBALS['egw']->db->quote($value))); |
|
565 | 565 | $result = Link::query($app, '', $options); |
566 | 566 | |
567 | 567 | // Only one allowed |
568 | - if($record->get_identifier()) |
|
568 | + if ($record->get_identifier()) |
|
569 | 569 | { |
570 | - while(key($result) == $record->get_identifier()) |
|
570 | + while (key($result) == $record->get_identifier()) |
|
571 | 571 | { |
572 | 572 | array_shift($result); |
573 | 573 | } |
574 | 574 | } |
575 | - if(count($result) != 1) |
|
575 | + if (count($result) != 1) |
|
576 | 576 | { |
577 | - $this->warnings[$record_num] .= ($this->warnings[$record_num] ? "\n" : '') . |
|
577 | + $this->warnings[$record_num] .= ($this->warnings[$record_num] ? "\n" : ''). |
|
578 | 578 | lang('Unable to link to %3 by custom field "%1": "%4". %2 matches.', |
579 | 579 | $custom_field, count($result), lang($app), $options['filter'][0] |
580 | 580 | ); |
@@ -18,7 +18,8 @@ discard block |
||
18 | 18 | * should get you started on building a CSV plugin for an application fairly quickly. |
19 | 19 | * |
20 | 20 | */ |
21 | -abstract class importexport_basic_import_csv implements importexport_iface_import_plugin { |
|
21 | +abstract class importexport_basic_import_csv implements importexport_iface_import_plugin |
|
22 | +{ |
|
22 | 23 | |
23 | 24 | protected static $plugin_options = array( |
24 | 25 | 'fieldsep', // char |
@@ -121,7 +122,8 @@ discard block |
||
121 | 122 | * @param string $_charset |
122 | 123 | * @param definition $_definition |
123 | 124 | */ |
124 | - public function import( $_stream, importexport_definition $_definition ) { |
|
125 | + public function import( $_stream, importexport_definition $_definition ) |
|
126 | + { |
|
125 | 127 | $import_csv = new importexport_import_csv( $_stream, array( |
126 | 128 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
127 | 129 | 'charset' => $_definition->plugin_options['charset'], |
@@ -143,9 +145,12 @@ discard block |
||
143 | 145 | $import_csv->conversion = $_definition->plugin_options['field_conversion']; |
144 | 146 | |
145 | 147 | //check if file has a header lines |
146 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
148 | + if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) |
|
149 | + { |
|
147 | 150 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
148 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
151 | + } |
|
152 | + elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) |
|
153 | + { |
|
149 | 154 | // First method is preferred |
150 | 155 | $import_csv->skip_records(1); |
151 | 156 | } |
@@ -167,15 +172,22 @@ discard block |
||
167 | 172 | |
168 | 173 | $this->init($_definition); |
169 | 174 | |
170 | - while ( $record = $import_csv->get_record() ) { |
|
175 | + while ( $record = $import_csv->get_record() ) |
|
176 | + { |
|
171 | 177 | $success = false; |
172 | 178 | |
173 | 179 | // don't import empty records |
174 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
180 | + if( count( array_unique( $record ) ) < 2 ) |
|
181 | + { |
|
182 | + continue; |
|
183 | + } |
|
175 | 184 | |
176 | 185 | |
177 | 186 | $warning = importexport_import_csv::convert($record, $record_class::$types, $app, $this->lookups, $_definition->plugin_options['convert']); |
178 | - if($warning) $this->warnings[$import_csv->get_current_position()] = $warning; |
|
187 | + if($warning) |
|
188 | + { |
|
189 | + $this->warnings[$import_csv->get_current_position()] = $warning; |
|
190 | + } |
|
179 | 191 | |
180 | 192 | $egw_record = new $record_class(); |
181 | 193 | $egw_record->set_record($record); |
@@ -185,7 +197,10 @@ discard block |
||
185 | 197 | { |
186 | 198 | $this->do_special_fields($egw_record, $import_csv); |
187 | 199 | } |
188 | - if($success) $count++; |
|
200 | + if($success) |
|
201 | + { |
|
202 | + $count++; |
|
203 | + } |
|
189 | 204 | |
190 | 205 | // Add some more time |
191 | 206 | if($success && $import_csv->get_current_position() > 0 && $import_csv->get_current_position() % 100 == 0) |
@@ -226,10 +241,13 @@ discard block |
||
226 | 241 | */ |
227 | 242 | protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
228 | 243 | { |
229 | - if ( $this->definition->plugin_options['conditions'] ) { |
|
230 | - foreach ( $this->definition->plugin_options['conditions'] as $condition ) { |
|
244 | + if ( $this->definition->plugin_options['conditions'] ) |
|
245 | + { |
|
246 | + foreach ( $this->definition->plugin_options['conditions'] as $condition ) |
|
247 | + { |
|
231 | 248 | $result = false; |
232 | - switch ( $condition['type'] ) { |
|
249 | + switch ( $condition['type'] ) |
|
250 | + { |
|
233 | 251 | // exists |
234 | 252 | case 'exists' : |
235 | 253 | // Check for that record |
@@ -257,9 +275,14 @@ discard block |
||
257 | 275 | $action = $condition['false']; |
258 | 276 | $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
259 | 277 | } |
260 | - if ($action['stop']) break; |
|
278 | + if ($action['stop']) |
|
279 | + { |
|
280 | + break; |
|
281 | + } |
|
261 | 282 | } |
262 | - } else { |
|
283 | + } |
|
284 | + else |
|
285 | + { |
|
263 | 286 | // unconditional insert |
264 | 287 | $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
265 | 288 | } |
@@ -343,9 +366,14 @@ discard block |
||
343 | 366 | return; |
344 | 367 | } |
345 | 368 | |
346 | - foreach(self::$special_fields as $field => $desc) { |
|
347 | - if(!$record->$field) continue; |
|
348 | - if(strpos($field, 'link') === 0) { |
|
369 | + foreach(self::$special_fields as $field => $desc) |
|
370 | + { |
|
371 | + if(!$record->$field) |
|
372 | + { |
|
373 | + continue; |
|
374 | + } |
|
375 | + if(strpos($field, 'link') === 0) |
|
376 | + { |
|
349 | 377 | list($app, $app_id) = explode(':', $record->$field,2); |
350 | 378 | |
351 | 379 | list($link, $type) = explode('_',$field); |
@@ -364,7 +392,9 @@ discard block |
||
364 | 392 | shift($result); |
365 | 393 | } while($result && !$app_id); |
366 | 394 | } |
367 | - } else if (in_array($field, array_keys($GLOBALS['egw_info']['apps']))) { |
|
395 | + } |
|
396 | + else if (in_array($field, array_keys($GLOBALS['egw_info']['apps']))) |
|
397 | + { |
|
368 | 398 | $app = $field; |
369 | 399 | $app_id = $record->$field; |
370 | 400 | |
@@ -425,11 +455,16 @@ discard block |
||
425 | 455 | $fields = $wizard->get_import_fields(); |
426 | 456 | foreach($labels as $field => &$label) |
427 | 457 | { |
428 | - if($fields[$field]) $label = $fields[$field]; |
|
458 | + if($fields[$field]) |
|
459 | + { |
|
460 | + $label = $fields[$field]; |
|
461 | + } |
|
429 | 462 | } |
430 | - } catch (Exception $e) { |
|
463 | + } |
|
464 | + catch (Exception $e) { |
|
431 | 465 | Api\Translation::add_app($definition->application); |
432 | - foreach($labels as $field => &$label) { |
|
466 | + foreach($labels as $field => &$label) |
|
467 | + { |
|
433 | 468 | $label = lang($label); |
434 | 469 | } |
435 | 470 | } |
@@ -468,7 +503,8 @@ discard block |
||
468 | 503 | * @param string $org_name |
469 | 504 | * @return int|boolean Contact ID of first match, or false if none found |
470 | 505 | */ |
471 | - public static function addr_id( $n_family,$n_given=null,$org_name=null, &$record=null) { |
|
506 | + public static function addr_id( $n_family,$n_given=null,$org_name=null, &$record=null) |
|
507 | + { |
|
472 | 508 | |
473 | 509 | // find in Addressbook, at least n_family AND (n_given OR org_name) have to match |
474 | 510 | static $contacts; |
@@ -478,28 +514,40 @@ discard block |
||
478 | 514 | list($n_family, $n_given, $org_name) = explode(',', $n_family); |
479 | 515 | } |
480 | 516 | $n_family = trim($n_family); |
481 | - if(!is_null($n_given)) $n_given = trim($n_given); |
|
517 | + if(!is_null($n_given)) |
|
518 | + { |
|
519 | + $n_given = trim($n_given); |
|
520 | + } |
|
482 | 521 | if (!is_object($contacts)) |
483 | 522 | { |
484 | 523 | $contacts = new Api\Contacts(); |
485 | 524 | } |
486 | - if (!is_null($org_name)) // org_name given? |
|
525 | + if (!is_null($org_name)) |
|
526 | + { |
|
527 | + // org_name given? |
|
487 | 528 | { |
488 | 529 | $org_name = trim($org_name); |
530 | + } |
|
489 | 531 | $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); |
490 | 532 | if (!count($addrs)) |
491 | 533 | { |
492 | 534 | $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name",'','n_family,org_name'); |
493 | 535 | } |
494 | 536 | } |
495 | - if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) // first name given and no result so far |
|
537 | + if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) |
|
538 | + { |
|
539 | + // first name given and no result so far |
|
496 | 540 | { |
497 | 541 | $addrs = $contacts->search(array('n_family' => $n_family, 'n_given' => $n_given)); |
498 | 542 | } |
499 | - if (is_null($n_given) && is_null($org_name)) // just one name given, check against fn (= full name) |
|
543 | + } |
|
544 | + if (is_null($n_given) && is_null($org_name)) |
|
545 | + { |
|
546 | + // just one name given, check against fn (= full name) |
|
500 | 547 | { |
501 | 548 | $addrs = $contacts->read( 0,0,array('id'),'',"n_fn=$n_family",'','n_fn' ); |
502 | 549 | } |
550 | + } |
|
503 | 551 | if (count($addrs)) |
504 | 552 | { |
505 | 553 | if(!$record || !$record->get_identifier()) |
@@ -551,13 +599,17 @@ discard block |
||
551 | 599 | } |
552 | 600 | |
553 | 601 | // Couldn't find field, give an error - something's wrong |
554 | - if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)]) { |
|
602 | + if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)]) |
|
603 | + { |
|
555 | 604 | $this->errors[$record_num] .= lang('No custom field "%1" for %2.', |
556 | 605 | $custom_field, lang($app)); |
557 | 606 | return false; |
558 | 607 | } |
559 | - if($custom_field[0] != '#') $custom_field = '#' . $custom_field; |
|
560 | -error_log("Searching for $custom_field = $value"); |
|
608 | + if($custom_field[0] != '#') |
|
609 | + { |
|
610 | + $custom_field = '#' . $custom_field; |
|
611 | + } |
|
612 | + error_log("Searching for $custom_field = $value"); |
|
561 | 613 | // Search |
562 | 614 | if(Link::get_registry($app, 'query')) |
563 | 615 | { |
@@ -591,7 +643,8 @@ discard block |
||
591 | 643 | * |
592 | 644 | * @return string name |
593 | 645 | */ |
594 | - public static function get_name() { |
|
646 | + public static function get_name() |
|
647 | + { |
|
595 | 648 | return lang('Basic CSV import'); |
596 | 649 | } |
597 | 650 | |
@@ -600,7 +653,8 @@ discard block |
||
600 | 653 | * |
601 | 654 | * @return string descriprion |
602 | 655 | */ |
603 | - public static function get_description() { |
|
656 | + public static function get_description() |
|
657 | + { |
|
604 | 658 | return lang("Imports information from a CSV file. This is only a base class, and doesn't do anything on its own."); |
605 | 659 | } |
606 | 660 | |
@@ -609,7 +663,8 @@ discard block |
||
609 | 663 | * |
610 | 664 | * @return string suffix (comma seperated) |
611 | 665 | */ |
612 | - public static function get_filesuffix() { |
|
666 | + public static function get_filesuffix() |
|
667 | + { |
|
613 | 668 | return 'csv'; |
614 | 669 | } |
615 | 670 | |
@@ -625,7 +680,8 @@ discard block |
||
625 | 680 | * preserv => array, |
626 | 681 | * ) |
627 | 682 | */ |
628 | - public function get_options_etpl() { |
|
683 | + public function get_options_etpl() |
|
684 | + { |
|
629 | 685 | // lets do it! |
630 | 686 | } |
631 | 687 | |
@@ -634,7 +690,8 @@ discard block |
||
634 | 690 | * |
635 | 691 | * @return string etemplate name |
636 | 692 | */ |
637 | - public function get_selectors_etpl() { |
|
693 | + public function get_selectors_etpl() |
|
694 | + { |
|
638 | 695 | // lets do it! |
639 | 696 | } |
640 | 697 | |
@@ -646,7 +703,8 @@ discard block |
||
646 | 703 | * record_# => warning message |
647 | 704 | * ) |
648 | 705 | */ |
649 | - public function get_warnings() { |
|
706 | + public function get_warnings() |
|
707 | + { |
|
650 | 708 | return $this->warnings; |
651 | 709 | } |
652 | 710 | |
@@ -658,7 +716,8 @@ discard block |
||
658 | 716 | * record_# => error message |
659 | 717 | * ) |
660 | 718 | */ |
661 | - public function get_errors() { |
|
719 | + public function get_errors() |
|
720 | + { |
|
662 | 721 | return $this->errors; |
663 | 722 | } |
664 | 723 | |
@@ -670,7 +729,8 @@ discard block |
||
670 | 729 | * action => record count |
671 | 730 | * ) |
672 | 731 | */ |
673 | - public function get_results() { |
|
732 | + public function get_results() |
|
733 | + { |
|
674 | 734 | return $this->results; |
675 | 735 | } |
676 | 736 | } // end of iface_export_plugin |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return boolean |
278 | 278 | */ |
279 | - protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$matches = array()) |
|
279 | + protected function exists(importexport_iface_egw_record &$record, array &$condition, &$matches = array()) |
|
280 | 280 | { |
281 | 281 | } |
282 | 282 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | - protected function equal(importexport_iface_egw_record &$record, Array &$condition) |
|
291 | + protected function equal(importexport_iface_egw_record &$record, array &$condition) |
|
292 | 292 | { |
293 | 293 | $field = $condition['string']; |
294 | 294 | return $record->$field == $condition['op_2']; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return boolean |
305 | 305 | */ |
306 | - protected function less_than(importexport_iface_egw_record &$record, Array &$condition) |
|
306 | + protected function less_than(importexport_iface_egw_record &$record, array &$condition) |
|
307 | 307 | { |
308 | 308 | $field = $condition['string']; |
309 | 309 | return $record->$field < $condition['op_2']; |
@@ -176,7 +176,6 @@ |
||
176 | 176 | /** |
177 | 177 | * sets options |
178 | 178 | * |
179 | - * @param array $options |
|
180 | 179 | */ |
181 | 180 | private function set_options(array $_plugin_options) { |
182 | 181 | $this->definition['plugin_options'] = $_plugin_options; |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param string $_identifier |
67 | 67 | */ |
68 | - public function __construct( $_identifier='' ) { |
|
69 | - $this->so_sql = new Api\Storage\Base(self::_appname ,self::_defintion_talbe); |
|
68 | + public function __construct($_identifier = '') { |
|
69 | + $this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_talbe); |
|
70 | 70 | $this->user = $GLOBALS['egw_info']['user']['user_id']; |
71 | 71 | $this->is_admin = $GLOBALS['egw_info']['user']['apps']['admin'] || $GLOBALS['egw_setup'] ? true : false; |
72 | 72 | // compability to string identifiers |
@@ -74,17 +74,17 @@ discard block |
||
74 | 74 | |
75 | 75 | if ((int)$_identifier != 0) { |
76 | 76 | $this->definition = $this->so_sql->read(array('definition_id' => $_identifier)); |
77 | - if ( empty( $this->definition ) ) { |
|
77 | + if (empty($this->definition)) { |
|
78 | 78 | throw new Exception('Error: No such definition with identifier :"'.$_identifier.'"!'); |
79 | 79 | } |
80 | - if ( !( importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) { |
|
80 | + if (!(importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) { |
|
81 | 81 | throw new Exception('Error: User "'.$this->user.'" is not permitted to get definition with identifier "'.$_identifier.'"!'); |
82 | 82 | } |
83 | 83 | try |
84 | 84 | { |
85 | - $options_data = importexport_arrayxml::xml2array( $this->definition['plugin_options'] ); |
|
85 | + $options_data = importexport_arrayxml::xml2array($this->definition['plugin_options']); |
|
86 | 86 | $this->definition['plugin_options'] = $options_data['root']; |
87 | - if($this->definition['filter']) $filter = importexport_arrayxml::xml2array( $this->definition['filter'] ); |
|
87 | + if ($this->definition['filter']) $filter = importexport_arrayxml::xml2array($this->definition['filter']); |
|
88 | 88 | $this->definition['filter'] = $filter['root']; |
89 | 89 | } |
90 | 90 | catch (Exception $e) |
@@ -100,22 +100,22 @@ discard block |
||
100 | 100 | * @param string $_name |
101 | 101 | * @return int |
102 | 102 | */ |
103 | - private function name2identifier( $_name ) { |
|
104 | - $identifiers = $this->so_sql->search(array('name' => $_name),true); |
|
103 | + private function name2identifier($_name) { |
|
104 | + $identifiers = $this->so_sql->search(array('name' => $_name), true); |
|
105 | 105 | if (isset($identifiers[1])) { |
106 | - throw new Exception('Error: Definition: "'.$_name. '" is not unique! Can\'t convert to identifier'); |
|
106 | + throw new Exception('Error: Definition: "'.$_name.'" is not unique! Can\'t convert to identifier'); |
|
107 | 107 | } |
108 | - if ( empty( $identifiers[0] ) ) { |
|
108 | + if (empty($identifiers[0])) { |
|
109 | 109 | // not a good idea, till we don't have different exceptions so far |
110 | 110 | // throw new Exception('Error: No such definition :"'.$_name.'"!'); |
111 | - $identifiers = array( array( 'definition_id' => 0 ) ); |
|
111 | + $identifiers = array(array('definition_id' => 0)); |
|
112 | 112 | } |
113 | 113 | return $identifiers[0]['definition_id']; |
114 | 114 | } |
115 | 115 | |
116 | 116 | public function __get($_attribute_name) { |
117 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
118 | - throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
|
117 | + if (!array_key_exists($_attribute_name, $this->attributes)) { |
|
118 | + throw new Exception('Error: "'.$_attribute_name.'" is not an attribute defintion'); |
|
119 | 119 | } |
120 | 120 | switch ($_attribute_name) { |
121 | 121 | case 'allowed_users' : |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | - public function __set($_attribute_name,$_data) { |
|
133 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
134 | - throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
|
132 | + public function __set($_attribute_name, $_data) { |
|
133 | + if (!array_key_exists($_attribute_name, $this->attributes)) { |
|
134 | + throw new Exception('Error: "'.$_attribute_name.'" is not an attribute defintion'); |
|
135 | 135 | } |
136 | 136 | switch ($_attribute_name) { |
137 | 137 | case 'allowed_users' : |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @return array |
153 | 153 | */ |
154 | 154 | private function get_allowed_users() { |
155 | - return explode(',',substr($this->definition['allowed_users'],1,-1)); |
|
155 | + return explode(',', substr($this->definition['allowed_users'], 1, -1)); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param array $_allowed_users |
162 | 162 | */ |
163 | - private function set_allowed_users( $_allowed_users ) { |
|
164 | - $this->definition['allowed_users'] = ','.implode(',',(array)$_allowed_users) .','; |
|
163 | + private function set_allowed_users($_allowed_users) { |
|
164 | + $this->definition['allowed_users'] = ','.implode(',', (array)$_allowed_users).','; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function set_record( array $_record ) { |
|
234 | - $this->definition = array_intersect_key( $_record, $this->attributes ); |
|
233 | + public function set_record(array $_record) { |
|
234 | + $this->definition = array_intersect_key($_record, $this->attributes); |
|
235 | 235 | |
236 | 236 | // anything which is not an attribute is perhaps a plugin_option. |
237 | 237 | // If not, it gets whiped out on save time. |
238 | - foreach ( $_record as $attribute => $value) { |
|
239 | - if ( !array_key_exists( $attribute, $this->attributes ) ) { |
|
238 | + foreach ($_record as $attribute => $value) { |
|
239 | + if (!array_key_exists($attribute, $this->attributes)) { |
|
240 | 240 | $this->definition['plugin_options'][$attribute] = $value; |
241 | 241 | } |
242 | 242 | } |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | $this->plugin = $_record['plugin']; |
245 | 245 | |
246 | 246 | // convert plugin_options into internal representation |
247 | - $this->set_allowed_users( $this->definition['allowed_users'] ); |
|
248 | - $this->set_options( $this->definition['plugin_options'] ? $this->definition['plugin_options'] : array()); |
|
249 | - $this->set_filter( $this->definition['filter'] ? $this->definition['filter'] : array()); |
|
247 | + $this->set_allowed_users($this->definition['allowed_users']); |
|
248 | + $this->set_options($this->definition['plugin_options'] ? $this->definition['plugin_options'] : array()); |
|
249 | + $this->set_filter($this->definition['filter'] ? $this->definition['filter'] : array()); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @return string Full URL of an icon, or appname/icon_name |
267 | 267 | */ |
268 | 268 | public function get_icon() { |
269 | - return self::_appname . '/navbar'; |
|
269 | + return self::_appname.'/navbar'; |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -274,16 +274,16 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return string identifier |
276 | 276 | */ |
277 | - public function save ( $_dst_identifier ) { |
|
278 | - if ( strlen($this->definition['name']) < 3 ) { |
|
277 | + public function save($_dst_identifier) { |
|
278 | + if (strlen($this->definition['name']) < 3) { |
|
279 | 279 | throw new Exception('Error: Can\'t save definition, no valid name given!'); |
280 | 280 | } |
281 | 281 | |
282 | 282 | $this->so_sql->data = $this->definition; |
283 | - $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml( $this->definition['plugin_options'] ); |
|
284 | - $this->so_sql->data['filter'] = importexport_arrayxml::array2xml( $this->definition['filter'] ); |
|
283 | + $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml($this->definition['plugin_options']); |
|
284 | + $this->so_sql->data['filter'] = importexport_arrayxml::array2xml($this->definition['filter']); |
|
285 | 285 | $this->so_sql->data['modified'] = time(); |
286 | - if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) { |
|
286 | + if ($this->so_sql->save(array('definition_id' => $_dst_identifier))) { |
|
287 | 287 | throw new Exception('Error: Api\Storage\Base was not able to save definition: '.$this->get_identifier()); |
288 | 288 | } |
289 | 289 | |
@@ -296,13 +296,13 @@ discard block |
||
296 | 296 | * @param string $_dst_identifier |
297 | 297 | * @return string dst_identifier |
298 | 298 | */ |
299 | - public function copy ( $_dst_identifier ) { |
|
299 | + public function copy($_dst_identifier) { |
|
300 | 300 | $dst_object = clone $this; |
301 | 301 | try { |
302 | 302 | $dst_object->set_owner($this->user); |
303 | 303 | $dst_identifier = $dst_object->save($_dst_identifier); |
304 | 304 | } |
305 | - catch(exception $Exception) { |
|
305 | + catch (exception $Exception) { |
|
306 | 306 | unset($dst_object); |
307 | 307 | throw $Exception; |
308 | 308 | } |
@@ -317,16 +317,16 @@ discard block |
||
317 | 317 | * @param string $_dst_identifier |
318 | 318 | * @return string dst_identifier |
319 | 319 | */ |
320 | - public function move ( $_dst_identifier ) { |
|
320 | + public function move($_dst_identifier) { |
|
321 | 321 | if ($this->user != $this->get_owner() && !$this->is_admin) { |
322 | - throw('Error: User '. $this->user. 'does not have permissions to move definition '.$this->get_identifier()); |
|
322 | + throw('Error: User '.$this->user.'does not have permissions to move definition '.$this->get_identifier()); |
|
323 | 323 | } |
324 | 324 | $old_object = clone $this; |
325 | 325 | try { |
326 | 326 | $dst_identifier = $this->save($_dst_identifier); |
327 | 327 | $old_object->delete(); |
328 | 328 | } |
329 | - catch(exception $Exception) { |
|
329 | + catch (exception $Exception) { |
|
330 | 330 | unset($old_object); |
331 | 331 | throw $Exception; |
332 | 332 | } |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | * @return void |
340 | 340 | * |
341 | 341 | */ |
342 | - public function delete () { |
|
343 | - if($this->user != $this->get_owner() && !$this->is_admin) { |
|
344 | - throw('Error: User '. $this->user. 'does not have permissions to delete definition '.$this->get_identifier()); |
|
342 | + public function delete() { |
|
343 | + if ($this->user != $this->get_owner() && !$this->is_admin) { |
|
344 | + throw('Error: User '.$this->user.'does not have permissions to delete definition '.$this->get_identifier()); |
|
345 | 345 | } |
346 | - if(!$this->so_sql->delete()) { |
|
346 | + if (!$this->so_sql->delete()) { |
|
347 | 347 | throw('Error: Api\Storage\Base was not able to delete definition: '.$this->get_identifier()); |
348 | 348 | } |
349 | 349 | } |
@@ -20,7 +20,8 @@ discard block |
||
20 | 20 | * are in one assiozative array which is complely managed by {Im|Ex}port plugins |
21 | 21 | * @todo testing |
22 | 22 | */ |
23 | -class importexport_definition implements importexport_iface_egw_record { |
|
23 | +class importexport_definition implements importexport_iface_egw_record |
|
24 | +{ |
|
24 | 25 | |
25 | 26 | const _appname = 'importexport'; |
26 | 27 | const _defintion_talbe = 'egw_importexport_definitions'; |
@@ -65,26 +66,36 @@ discard block |
||
65 | 66 | * |
66 | 67 | * @param string $_identifier |
67 | 68 | */ |
68 | - public function __construct( $_identifier='' ) { |
|
69 | + public function __construct( $_identifier='' ) |
|
70 | + { |
|
69 | 71 | $this->so_sql = new Api\Storage\Base(self::_appname ,self::_defintion_talbe); |
70 | 72 | $this->user = $GLOBALS['egw_info']['user']['user_id']; |
71 | 73 | $this->is_admin = $GLOBALS['egw_info']['user']['apps']['admin'] || $GLOBALS['egw_setup'] ? true : false; |
72 | 74 | // compability to string identifiers |
73 | - if (!is_numeric($_identifier) && strlen($_identifier) > 3) $_identifier = $this->name2identifier($_identifier); |
|
75 | + if (!is_numeric($_identifier) && strlen($_identifier) > 3) |
|
76 | + { |
|
77 | + $_identifier = $this->name2identifier($_identifier); |
|
78 | + } |
|
74 | 79 | |
75 | - if ((int)$_identifier != 0) { |
|
80 | + if ((int)$_identifier != 0) |
|
81 | + { |
|
76 | 82 | $this->definition = $this->so_sql->read(array('definition_id' => $_identifier)); |
77 | - if ( empty( $this->definition ) ) { |
|
83 | + if ( empty( $this->definition ) ) |
|
84 | + { |
|
78 | 85 | throw new Exception('Error: No such definition with identifier :"'.$_identifier.'"!'); |
79 | 86 | } |
80 | - if ( !( importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) { |
|
87 | + if ( !( importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) |
|
88 | + { |
|
81 | 89 | throw new Exception('Error: User "'.$this->user.'" is not permitted to get definition with identifier "'.$_identifier.'"!'); |
82 | 90 | } |
83 | 91 | try |
84 | 92 | { |
85 | 93 | $options_data = importexport_arrayxml::xml2array( $this->definition['plugin_options'] ); |
86 | 94 | $this->definition['plugin_options'] = $options_data['root']; |
87 | - if($this->definition['filter']) $filter = importexport_arrayxml::xml2array( $this->definition['filter'] ); |
|
95 | + if($this->definition['filter']) |
|
96 | + { |
|
97 | + $filter = importexport_arrayxml::xml2array( $this->definition['filter'] ); |
|
98 | + } |
|
88 | 99 | $this->definition['filter'] = $filter['root']; |
89 | 100 | } |
90 | 101 | catch (Exception $e) |
@@ -100,12 +111,15 @@ discard block |
||
100 | 111 | * @param string $_name |
101 | 112 | * @return int |
102 | 113 | */ |
103 | - private function name2identifier( $_name ) { |
|
114 | + private function name2identifier( $_name ) |
|
115 | + { |
|
104 | 116 | $identifiers = $this->so_sql->search(array('name' => $_name),true); |
105 | - if (isset($identifiers[1])) { |
|
117 | + if (isset($identifiers[1])) |
|
118 | + { |
|
106 | 119 | throw new Exception('Error: Definition: "'.$_name. '" is not unique! Can\'t convert to identifier'); |
107 | 120 | } |
108 | - if ( empty( $identifiers[0] ) ) { |
|
121 | + if ( empty( $identifiers[0] ) ) |
|
122 | + { |
|
109 | 123 | // not a good idea, till we don't have different exceptions so far |
110 | 124 | // throw new Exception('Error: No such definition :"'.$_name.'"!'); |
111 | 125 | $identifiers = array( array( 'definition_id' => 0 ) ); |
@@ -113,11 +127,14 @@ discard block |
||
113 | 127 | return $identifiers[0]['definition_id']; |
114 | 128 | } |
115 | 129 | |
116 | - public function __get($_attribute_name) { |
|
117 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
130 | + public function __get($_attribute_name) |
|
131 | + { |
|
132 | + if (!array_key_exists($_attribute_name,$this->attributes)) |
|
133 | + { |
|
118 | 134 | throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
119 | 135 | } |
120 | - switch ($_attribute_name) { |
|
136 | + switch ($_attribute_name) |
|
137 | + { |
|
121 | 138 | case 'allowed_users' : |
122 | 139 | return $this->get_allowed_users(); |
123 | 140 | case 'plugin_options' : |
@@ -129,11 +146,14 @@ discard block |
||
129 | 146 | } |
130 | 147 | } |
131 | 148 | |
132 | - public function __set($_attribute_name,$_data) { |
|
133 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
149 | + public function __set($_attribute_name,$_data) |
|
150 | + { |
|
151 | + if (!array_key_exists($_attribute_name,$this->attributes)) |
|
152 | + { |
|
134 | 153 | throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
135 | 154 | } |
136 | - switch ($_attribute_name) { |
|
155 | + switch ($_attribute_name) |
|
156 | + { |
|
137 | 157 | case 'allowed_users' : |
138 | 158 | return $this->set_allowed_users($_data); |
139 | 159 | case 'plugin_options' : |
@@ -151,7 +171,8 @@ discard block |
||
151 | 171 | * |
152 | 172 | * @return array |
153 | 173 | */ |
154 | - private function get_allowed_users() { |
|
174 | + private function get_allowed_users() |
|
175 | + { |
|
155 | 176 | return explode(',',substr($this->definition['allowed_users'],1,-1)); |
156 | 177 | } |
157 | 178 | |
@@ -160,7 +181,8 @@ discard block |
||
160 | 181 | * |
161 | 182 | * @param array $_allowed_users |
162 | 183 | */ |
163 | - private function set_allowed_users( $_allowed_users ) { |
|
184 | + private function set_allowed_users( $_allowed_users ) |
|
185 | + { |
|
164 | 186 | $this->definition['allowed_users'] = ','.implode(',',(array)$_allowed_users) .','; |
165 | 187 | } |
166 | 188 | |
@@ -169,7 +191,8 @@ discard block |
||
169 | 191 | * |
170 | 192 | * @return array |
171 | 193 | */ |
172 | - private function get_options() { |
|
194 | + private function get_options() |
|
195 | + { |
|
173 | 196 | return $this->definition['plugin_options']; |
174 | 197 | } |
175 | 198 | |
@@ -178,7 +201,8 @@ discard block |
||
178 | 201 | * |
179 | 202 | * @param array $options |
180 | 203 | */ |
181 | - private function set_options(array $_plugin_options) { |
|
204 | + private function set_options(array $_plugin_options) |
|
205 | + { |
|
182 | 206 | $this->definition['plugin_options'] = $_plugin_options; |
183 | 207 | } |
184 | 208 | |
@@ -187,7 +211,8 @@ discard block |
||
187 | 211 | * |
188 | 212 | * @return array |
189 | 213 | */ |
190 | - private function get_filter() { |
|
214 | + private function get_filter() |
|
215 | + { |
|
191 | 216 | return $this->definition['filter']; |
192 | 217 | } |
193 | 218 | |
@@ -196,7 +221,8 @@ discard block |
||
196 | 221 | * |
197 | 222 | * @param filter array of field => settings |
198 | 223 | */ |
199 | - private function set_filter(Array $filter) { |
|
224 | + private function set_filter(Array $filter) |
|
225 | + { |
|
200 | 226 | $this->definition['filter'] = $filter; |
201 | 227 | } |
202 | 228 | |
@@ -208,7 +234,8 @@ discard block |
||
208 | 234 | * |
209 | 235 | * @return array complete record as associative array |
210 | 236 | */ |
211 | - public function get_record_array() { |
|
237 | + public function get_record_array() |
|
238 | + { |
|
212 | 239 | $definition = $this->definition; |
213 | 240 | $definition['allowed_users'] = $this->get_allowed_users(); |
214 | 241 | $definition['plugin_options'] = $this->get_options(); |
@@ -221,7 +248,8 @@ discard block |
||
221 | 248 | * |
222 | 249 | *@return string tiltle |
223 | 250 | */ |
224 | - public function get_title() { |
|
251 | + public function get_title() |
|
252 | + { |
|
225 | 253 | return $this->definition['name']; |
226 | 254 | } |
227 | 255 | |
@@ -230,13 +258,16 @@ discard block |
||
230 | 258 | * |
231 | 259 | * @return void |
232 | 260 | */ |
233 | - public function set_record( array $_record ) { |
|
261 | + public function set_record( array $_record ) |
|
262 | + { |
|
234 | 263 | $this->definition = array_intersect_key( $_record, $this->attributes ); |
235 | 264 | |
236 | 265 | // anything which is not an attribute is perhaps a plugin_option. |
237 | 266 | // If not, it gets whiped out on save time. |
238 | - foreach ( $_record as $attribute => $value) { |
|
239 | - if ( !array_key_exists( $attribute, $this->attributes ) ) { |
|
267 | + foreach ( $_record as $attribute => $value) |
|
268 | + { |
|
269 | + if ( !array_key_exists( $attribute, $this->attributes ) ) |
|
270 | + { |
|
240 | 271 | $this->definition['plugin_options'][$attribute] = $value; |
241 | 272 | } |
242 | 273 | } |
@@ -254,7 +285,8 @@ discard block |
||
254 | 285 | * |
255 | 286 | * @return int identifier of this record |
256 | 287 | */ |
257 | - public function get_identifier() { |
|
288 | + public function get_identifier() |
|
289 | + { |
|
258 | 290 | return $this->definition['definition_id']; |
259 | 291 | } |
260 | 292 | |
@@ -265,7 +297,8 @@ discard block |
||
265 | 297 | * |
266 | 298 | * @return string Full URL of an icon, or appname/icon_name |
267 | 299 | */ |
268 | - public function get_icon() { |
|
300 | + public function get_icon() |
|
301 | + { |
|
269 | 302 | return self::_appname . '/navbar'; |
270 | 303 | } |
271 | 304 | |
@@ -274,8 +307,10 @@ discard block |
||
274 | 307 | * |
275 | 308 | * @return string identifier |
276 | 309 | */ |
277 | - public function save ( $_dst_identifier ) { |
|
278 | - if ( strlen($this->definition['name']) < 3 ) { |
|
310 | + public function save ( $_dst_identifier ) |
|
311 | + { |
|
312 | + if ( strlen($this->definition['name']) < 3 ) |
|
313 | + { |
|
279 | 314 | throw new Exception('Error: Can\'t save definition, no valid name given!'); |
280 | 315 | } |
281 | 316 | |
@@ -283,7 +318,8 @@ discard block |
||
283 | 318 | $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml( $this->definition['plugin_options'] ); |
284 | 319 | $this->so_sql->data['filter'] = importexport_arrayxml::array2xml( $this->definition['filter'] ); |
285 | 320 | $this->so_sql->data['modified'] = time(); |
286 | - if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) { |
|
321 | + if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) |
|
322 | + { |
|
287 | 323 | throw new Exception('Error: Api\Storage\Base was not able to save definition: '.$this->get_identifier()); |
288 | 324 | } |
289 | 325 | |
@@ -296,7 +332,8 @@ discard block |
||
296 | 332 | * @param string $_dst_identifier |
297 | 333 | * @return string dst_identifier |
298 | 334 | */ |
299 | - public function copy ( $_dst_identifier ) { |
|
335 | + public function copy ( $_dst_identifier ) |
|
336 | + { |
|
300 | 337 | $dst_object = clone $this; |
301 | 338 | try { |
302 | 339 | $dst_object->set_owner($this->user); |
@@ -317,8 +354,10 @@ discard block |
||
317 | 354 | * @param string $_dst_identifier |
318 | 355 | * @return string dst_identifier |
319 | 356 | */ |
320 | - public function move ( $_dst_identifier ) { |
|
321 | - if ($this->user != $this->get_owner() && !$this->is_admin) { |
|
357 | + public function move ( $_dst_identifier ) |
|
358 | + { |
|
359 | + if ($this->user != $this->get_owner() && !$this->is_admin) |
|
360 | + { |
|
322 | 361 | throw('Error: User '. $this->user. 'does not have permissions to move definition '.$this->get_identifier()); |
323 | 362 | } |
324 | 363 | $old_object = clone $this; |
@@ -339,11 +378,14 @@ discard block |
||
339 | 378 | * @return void |
340 | 379 | * |
341 | 380 | */ |
342 | - public function delete () { |
|
343 | - if($this->user != $this->get_owner() && !$this->is_admin) { |
|
381 | + public function delete () |
|
382 | + { |
|
383 | + if($this->user != $this->get_owner() && !$this->is_admin) |
|
384 | + { |
|
344 | 385 | throw('Error: User '. $this->user. 'does not have permissions to delete definition '.$this->get_identifier()); |
345 | 386 | } |
346 | - if(!$this->so_sql->delete()) { |
|
387 | + if(!$this->so_sql->delete()) |
|
388 | + { |
|
347 | 389 | throw('Error: Api\Storage\Base was not able to delete definition: '.$this->get_identifier()); |
348 | 390 | } |
349 | 391 | } |
@@ -352,7 +394,8 @@ discard block |
||
352 | 394 | * destructor |
353 | 395 | * |
354 | 396 | */ |
355 | - public function __destruct() { |
|
397 | + public function __destruct() |
|
398 | + { |
|
356 | 399 | unset($this->so_sql); |
357 | 400 | } |
358 | 401 |
@@ -196,7 +196,7 @@ |
||
196 | 196 | * |
197 | 197 | * @param filter array of field => settings |
198 | 198 | */ |
199 | - private function set_filter(Array $filter) { |
|
199 | + private function set_filter(array $filter) { |
|
200 | 200 | $this->definition['filter'] = $filter; |
201 | 201 | } |
202 | 202 |
@@ -139,7 +139,6 @@ discard block |
||
139 | 139 | /** |
140 | 140 | * Save a definition |
141 | 141 | * |
142 | - * @param definition $definition |
|
143 | 142 | */ |
144 | 143 | public function save(Array $data) { |
145 | 144 | $definition = new importexport_definition(); |
@@ -209,7 +208,7 @@ discard block |
||
209 | 208 | /** |
210 | 209 | * imports definitions from file |
211 | 210 | * |
212 | - * @param string $import_file |
|
211 | + * @param string $_import_file |
|
213 | 212 | * @throws Exeption |
214 | 213 | * @return void |
215 | 214 | */ |
@@ -268,7 +267,6 @@ discard block |
||
268 | 267 | * It is not possible to handle some plugin options automatically, because they |
269 | 268 | * just don't have equivalents. (eg: What to do with unknown categories) |
270 | 269 | * |
271 | - * @param importexport_definition $definition Import definition |
|
272 | 270 | * |
273 | 271 | * @return importexport_definition Export definition |
274 | 272 | */ |
@@ -137,10 +137,10 @@ |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | - * Save a definition |
|
141 | - * |
|
142 | - * @param definition $definition |
|
143 | - */ |
|
140 | + * Save a definition |
|
141 | + * |
|
142 | + * @param definition $definition |
|
143 | + */ |
|
144 | 144 | public function save(Array $data) { |
145 | 145 | $definition = new importexport_definition(); |
146 | 146 | $definition->set_record($data); |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | */ |
32 | 32 | private $definitions; |
33 | 33 | |
34 | - public function __construct($_query=false, $ignore_acl = false) |
|
34 | + public function __construct($_query = false, $ignore_acl = false) |
|
35 | 35 | { |
36 | - $this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table ); |
|
36 | + $this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table); |
|
37 | 37 | if ($_query) { |
38 | 38 | $definitions = $this->so_sql->search($_query, false); |
39 | 39 | foreach ((array)$definitions as $definition) { |
40 | - if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
40 | + if (self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | public function get_rows(&$query, &$rows, &$readonlys) |
46 | 46 | { |
47 | 47 | // Filter only definitions user is allowed to use |
48 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
48 | + if (!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
49 | 49 | $this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
50 | 50 | $this_membership[] = $GLOBALS['egw_info']['user']['account_id']; |
51 | 51 | $sql .= ' ('; |
52 | 52 | $read = array(); |
53 | - foreach($this_membership as $id) |
|
53 | + foreach ($this_membership as $id) |
|
54 | 54 | { |
55 | 55 | $read[] = 'allowed_users '. |
56 | 56 | $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '. |
57 | - $GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%'); |
|
57 | + $GLOBALS['egw']->db->quote('%,'.str_replace('_', '\\_', $id).',%'); |
|
58 | 58 | } |
59 | 59 | $sql .= implode(' OR ', $read); |
60 | 60 | $sql .= ') OR owner = '.$GLOBALS['egw_info']['user']['account_id']; |
@@ -62,37 +62,37 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | // Handle allowed filter |
65 | - if($query['col_filter']['allowed_users']) |
|
65 | + if ($query['col_filter']['allowed_users']) |
|
66 | 66 | { |
67 | 67 | $allowed = array(); |
68 | - foreach((array)$query['col_filter']['allowed_users'] as $id) |
|
68 | + foreach ((array)$query['col_filter']['allowed_users'] as $id) |
|
69 | 69 | { |
70 | 70 | $allowed[] = 'allowed_users '. |
71 | 71 | $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '. |
72 | - $GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%'); |
|
72 | + $GLOBALS['egw']->db->quote('%,'.str_replace('_', '\\_', $id).',%'); |
|
73 | 73 | } |
74 | - if($allowed) |
|
74 | + if ($allowed) |
|
75 | 75 | { |
76 | 76 | unset($query['col_filter']['allowed_users']); |
77 | - $query['col_filter'][] = '('.implode(' OR ', $allowed) . ')'; |
|
77 | + $query['col_filter'][] = '('.implode(' OR ', $allowed).')'; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | $total = $this->so_sql->get_rows($query, $rows, $readonlys); |
82 | 82 | $ro_count = 0; |
83 | - foreach($rows as &$row) { |
|
83 | + foreach ($rows as &$row) { |
|
84 | 84 | // Strip off leading + trailing , |
85 | - $row['allowed_users'] = substr($row['allowed_users'],1,-1); |
|
85 | + $row['allowed_users'] = substr($row['allowed_users'], 1, -1); |
|
86 | 86 | |
87 | 87 | $readonlys["edit[{$row['definition_id']}]"] = $readonlys["delete[{$row['definition_id']}]"] = |
88 | 88 | ($row['owner'] != $GLOBALS['egw_info']['user']['account_id']) && |
89 | 89 | !$GLOBALS['egw_info']['user']['apps']['admin']; |
90 | - if($readonlys["edit[{$row['definition_id']}]"]) |
|
90 | + if ($readonlys["edit[{$row['definition_id']}]"]) |
|
91 | 91 | { |
92 | 92 | $row['class'] .= 'rowNoEdit rowNoDelete'; |
93 | 93 | $ro_count++; |
94 | 94 | } |
95 | - $row['class'] .= ' ' . $row['type']; |
|
95 | + $row['class'] .= ' '.$row['type']; |
|
96 | 96 | } |
97 | 97 | $readonlys['delete_selected'] = $ro_count == count($rows); |
98 | 98 | return $total; |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | return $this->definitions; |
108 | 108 | } |
109 | 109 | public function read($definition_id) { |
110 | - if(is_numeric($definition_id)) { |
|
110 | + if (is_numeric($definition_id)) { |
|
111 | 111 | $this->so_sql->read($definition_id); |
112 | 112 | $definition = new importexport_definition($this->so_sql->data['name']); |
113 | 113 | } else { |
114 | - $definition = new importexport_definition( $definition_id['name'] ); |
|
114 | + $definition = new importexport_definition($definition_id['name']); |
|
115 | 115 | } |
116 | 116 | return $definition->get_record_array(); |
117 | 117 | } |
@@ -124,14 +124,14 @@ discard block |
||
124 | 124 | foreach ($keys as $index => $key) { |
125 | 125 | // Check for ownership |
126 | 126 | $definition = $this->read($key); |
127 | - if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
127 | + if ($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
128 | 128 | // clear private cache |
129 | - unset($this->definitions[array_search($key,$this->definitions)]); |
|
129 | + unset($this->definitions[array_search($key, $this->definitions)]); |
|
130 | 130 | } else { |
131 | 131 | unset($keys[$index]); |
132 | 132 | } |
133 | 133 | } |
134 | - if(count($keys) > 0) { |
|
134 | + if (count($keys) > 0) { |
|
135 | 135 | $this->so_sql->delete(array('definition_id' => $keys)); |
136 | 136 | } |
137 | 137 | } |
@@ -154,12 +154,12 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | static public function is_permitted($_definition) { |
157 | - $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']); |
|
157 | + $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',', $_definition['allowed_users']); |
|
158 | 158 | $this_user_id = $GLOBALS['egw_info']['user']['account_id']; |
159 | 159 | $this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true); |
160 | 160 | $this_membership[] = $this_user_id; |
161 | 161 | $this_membership[] = 'all'; |
162 | - $alluser = array_intersect($allowed_user,$this_membership); |
|
162 | + $alluser = array_intersect($allowed_user, $this_membership); |
|
163 | 163 | return ($this_user_id == $_definition['owner'] || count($alluser) > 0); |
164 | 164 | } |
165 | 165 | |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | |
179 | 179 | $export_data['definitions'] = array(); |
180 | 180 | foreach ($keys as $definition_id) { |
181 | - $definition = new importexport_definition( $definition_id ); |
|
181 | + $definition = new importexport_definition($definition_id); |
|
182 | 182 | $export_data['definitions'][$definition->name] = $definition->get_record_array(); |
183 | 183 | $export_data['definitions'][$definition->name]['allowed_users'] = |
184 | 184 | importexport_helper_functions::account_id2name( |
185 | 185 | $export_data['definitions'][$definition->name]['allowed_users'] |
186 | 186 | ); |
187 | - if($export_date['definitions'][$definition->name]['owner']) { |
|
187 | + if ($export_date['definitions'][$definition->name]['owner']) { |
|
188 | 188 | $export_data['definitions'][$definition->name]['owner'] = |
189 | 189 | importexport_helper_functions::account_id2name( |
190 | 190 | $export_data['definitions'][$definition->name]['owner'] |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | unset($export_data['definitions'][$definition->name]['definition_id']); |
196 | 196 | unset($export_data['definitions'][$definition->name]['description']); |
197 | 197 | unset($export_data['definitions'][$definition->name]['user_timezone_read']); |
198 | - if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
198 | + if (is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
199 | 199 | unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']); |
200 | 200 | } |
201 | 201 | unset($definition); |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | * @throws Exeption |
214 | 214 | * @return void |
215 | 215 | */ |
216 | - public static function import( $_import_file ) |
|
216 | + public static function import($_import_file) |
|
217 | 217 | { |
218 | - if ( !is_file( $_import_file ) ) { |
|
219 | - throw new Exception("'$_import_file' does not exist or is not readable" ); |
|
218 | + if (!is_file($_import_file)) { |
|
219 | + throw new Exception("'$_import_file' does not exist or is not readable"); |
|
220 | 220 | } |
221 | 221 | |
222 | - $data = importexport_arrayxml::xml2array( file_get_contents( $_import_file ) ); |
|
222 | + $data = importexport_arrayxml::xml2array(file_get_contents($_import_file)); |
|
223 | 223 | |
224 | 224 | $metainfo = $data['importExportDefinitions']['metainfo']; |
225 | 225 | $definitions = $data['importExportDefinitions']['definitions']; |
226 | - unset ( $data ); |
|
226 | + unset ($data); |
|
227 | 227 | |
228 | 228 | // convert charset into internal used charset |
229 | 229 | $definitions = Api\Translation::convert( |
@@ -233,26 +233,26 @@ discard block |
||
233 | 233 | ); |
234 | 234 | |
235 | 235 | // Avoid warning if no definitions found |
236 | - if(!is_array($definitions)) return lang('None found'); |
|
236 | + if (!is_array($definitions)) return lang('None found'); |
|
237 | 237 | |
238 | 238 | // save definition(s) into internal table |
239 | - foreach ( $definitions as $name => $definition_data ) |
|
239 | + foreach ($definitions as $name => $definition_data) |
|
240 | 240 | { |
241 | 241 | // convert allowed_user |
242 | - $definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] ); |
|
243 | - if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
242 | + $definition_data['allowed_users'] = importexport_helper_functions::account_name2id($definition_data['allowed_users']); |
|
243 | + if ($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
244 | 244 | |
245 | - $definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] ); |
|
245 | + $definition_data['owner'] = importexport_helper_functions::account_name2id($definition_data['owner']); |
|
246 | 246 | |
247 | - $definition = new importexport_definition( $definition_data['name'] ); |
|
247 | + $definition = new importexport_definition($definition_data['name']); |
|
248 | 248 | |
249 | 249 | // Only update if the imported is newer |
250 | - if(strtotime($definition->modified) < strtotime($definition_data['modified']) || $definition->modified == 0) |
|
250 | + if (strtotime($definition->modified) < strtotime($definition_data['modified']) || $definition->modified == 0) |
|
251 | 251 | { |
252 | 252 | $definition_id = $definition->get_identifier() ? $definition->get_identifier() : NULL; |
253 | 253 | |
254 | - $definition->set_record( $definition_data ); |
|
255 | - $definition->save( $definition_id ); |
|
254 | + $definition->set_record($definition_data); |
|
255 | + $definition->save($definition_id); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | return $definitions; |
@@ -275,28 +275,28 @@ discard block |
||
275 | 275 | public static function export_from_import(importexport_definition $import) |
276 | 276 | { |
277 | 277 | // Only operates on import definitions |
278 | - if($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions'); |
|
278 | + if ($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions'); |
|
279 | 279 | |
280 | 280 | // Find export plugin |
281 | - $plugin = str_replace('import', 'export',$import->plugin); |
|
281 | + $plugin = str_replace('import', 'export', $import->plugin); |
|
282 | 282 | $plugin_list = importexport_helper_functions::get_plugins($import->application, 'export'); |
283 | - foreach($plugin_list as $appname => $type) |
|
283 | + foreach ($plugin_list as $appname => $type) |
|
284 | 284 | { |
285 | 285 | $plugins = $type['export']; |
286 | - foreach($plugins as $name => $label) |
|
286 | + foreach ($plugins as $name => $label) |
|
287 | 287 | { |
288 | - if($plugin == $name) break; |
|
288 | + if ($plugin == $name) break; |
|
289 | 289 | } |
290 | - if($plugin !== $name) $plugin = $name; |
|
290 | + if ($plugin !== $name) $plugin = $name; |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | $export = new importexport_definition(); |
294 | 294 | |
295 | 295 | // Common settings |
296 | - $export->name = str_replace('import', 'export',$import->name); |
|
297 | - if($export->name == $import->name) $export->name = $export->name . '-export'; |
|
296 | + $export->name = str_replace('import', 'export', $import->name); |
|
297 | + if ($export->name == $import->name) $export->name = $export->name.'-export'; |
|
298 | 298 | $test = new importexport_definition($export->name); |
299 | - if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
299 | + if ($test->name) $export->name = $export->name.'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
300 | 300 | |
301 | 301 | $export->application = $import->application; |
302 | 302 | $export->plugin = $plugin; |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | ); |
313 | 313 | |
314 | 314 | // Mapping |
315 | - foreach($i_options['field_mapping'] as $col_num => $field) |
|
315 | + foreach ($i_options['field_mapping'] as $col_num => $field) |
|
316 | 316 | { |
317 | 317 | // Try to use heading from import file, if possible |
318 | 318 | $e_options['mapping'][$field] = $i_options['csv_fields'][$col_num] ? $i_options['csv_fields'][$col_num] : $field; |
@@ -16,7 +16,8 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @todo make this class an egw_record_pool! |
18 | 18 | */ |
19 | -class importexport_definitions_bo { |
|
19 | +class importexport_definitions_bo |
|
20 | +{ |
|
20 | 21 | |
21 | 22 | const _appname = 'importexport'; |
22 | 23 | const _defintion_table = 'egw_importexport_definitions'; |
@@ -34,10 +35,15 @@ discard block |
||
34 | 35 | public function __construct($_query=false, $ignore_acl = false) |
35 | 36 | { |
36 | 37 | $this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table ); |
37 | - if ($_query) { |
|
38 | + if ($_query) |
|
39 | + { |
|
38 | 40 | $definitions = $this->so_sql->search($_query, false); |
39 | - foreach ((array)$definitions as $definition) { |
|
40 | - if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
41 | + foreach ((array)$definitions as $definition) |
|
42 | + { |
|
43 | + if(self::is_permitted($definition) || $ignore_acl) |
|
44 | + { |
|
45 | + $this->definitions[] = $definition['definition_id']; |
|
46 | + } |
|
41 | 47 | } |
42 | 48 | } |
43 | 49 | } |
@@ -45,7 +51,8 @@ discard block |
||
45 | 51 | public function get_rows(&$query, &$rows, &$readonlys) |
46 | 52 | { |
47 | 53 | // Filter only definitions user is allowed to use |
48 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
54 | + if(!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
55 | + { |
|
49 | 56 | $this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
50 | 57 | $this_membership[] = $GLOBALS['egw_info']['user']['account_id']; |
51 | 58 | $sql .= ' ('; |
@@ -80,7 +87,8 @@ discard block |
||
80 | 87 | |
81 | 88 | $total = $this->so_sql->get_rows($query, $rows, $readonlys); |
82 | 89 | $ro_count = 0; |
83 | - foreach($rows as &$row) { |
|
90 | + foreach($rows as &$row) |
|
91 | + { |
|
84 | 92 | // Strip off leading + trailing , |
85 | 93 | $row['allowed_users'] = substr($row['allowed_users'],1,-1); |
86 | 94 | |
@@ -103,14 +111,19 @@ discard block |
||
103 | 111 | * |
104 | 112 | * @return array |
105 | 113 | */ |
106 | - public function get_definitions() { |
|
114 | + public function get_definitions() |
|
115 | + { |
|
107 | 116 | return $this->definitions; |
108 | 117 | } |
109 | - public function read($definition_id) { |
|
110 | - if(is_numeric($definition_id)) { |
|
118 | + public function read($definition_id) |
|
119 | + { |
|
120 | + if(is_numeric($definition_id)) |
|
121 | + { |
|
111 | 122 | $this->so_sql->read($definition_id); |
112 | 123 | $definition = new importexport_definition($this->so_sql->data['name']); |
113 | - } else { |
|
124 | + } |
|
125 | + else |
|
126 | + { |
|
114 | 127 | $definition = new importexport_definition( $definition_id['name'] ); |
115 | 128 | } |
116 | 129 | return $definition->get_record_array(); |
@@ -120,18 +133,24 @@ discard block |
||
120 | 133 | * |
121 | 134 | * @param array $keys |
122 | 135 | */ |
123 | - public function delete($keys) { |
|
124 | - foreach ($keys as $index => $key) { |
|
136 | + public function delete($keys) |
|
137 | + { |
|
138 | + foreach ($keys as $index => $key) |
|
139 | + { |
|
125 | 140 | // Check for ownership |
126 | 141 | $definition = $this->read($key); |
127 | - if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
142 | + if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) |
|
143 | + { |
|
128 | 144 | // clear private cache |
129 | 145 | unset($this->definitions[array_search($key,$this->definitions)]); |
130 | - } else { |
|
146 | + } |
|
147 | + else |
|
148 | + { |
|
131 | 149 | unset($keys[$index]); |
132 | 150 | } |
133 | 151 | } |
134 | - if(count($keys) > 0) { |
|
152 | + if(count($keys) > 0) |
|
153 | + { |
|
135 | 154 | $this->so_sql->delete(array('definition_id' => $keys)); |
136 | 155 | } |
137 | 156 | } |
@@ -141,7 +160,8 @@ discard block |
||
141 | 160 | * |
142 | 161 | * @param definition $definition |
143 | 162 | */ |
144 | - public function save(Array $data) { |
|
163 | + public function save(Array $data) |
|
164 | + { |
|
145 | 165 | $definition = new importexport_definition(); |
146 | 166 | $definition->set_record($data); |
147 | 167 | $definition->save($data['definition_id']); |
@@ -153,7 +173,8 @@ discard block |
||
153 | 173 | * @param array $_definition |
154 | 174 | * @return bool |
155 | 175 | */ |
156 | - static public function is_permitted($_definition) { |
|
176 | + static public function is_permitted($_definition) |
|
177 | + { |
|
157 | 178 | $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']); |
158 | 179 | $this_user_id = $GLOBALS['egw_info']['user']['account_id']; |
159 | 180 | $this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true); |
@@ -177,25 +198,30 @@ discard block |
||
177 | 198 | )); |
178 | 199 | |
179 | 200 | $export_data['definitions'] = array(); |
180 | - foreach ($keys as $definition_id) { |
|
201 | + foreach ($keys as $definition_id) |
|
202 | + { |
|
181 | 203 | $definition = new importexport_definition( $definition_id ); |
182 | 204 | $export_data['definitions'][$definition->name] = $definition->get_record_array(); |
183 | 205 | $export_data['definitions'][$definition->name]['allowed_users'] = |
184 | 206 | importexport_helper_functions::account_id2name( |
185 | 207 | $export_data['definitions'][$definition->name]['allowed_users'] |
186 | 208 | ); |
187 | - if($export_date['definitions'][$definition->name]['owner']) { |
|
209 | + if($export_date['definitions'][$definition->name]['owner']) |
|
210 | + { |
|
188 | 211 | $export_data['definitions'][$definition->name]['owner'] = |
189 | 212 | importexport_helper_functions::account_id2name( |
190 | 213 | $export_data['definitions'][$definition->name]['owner'] |
191 | 214 | ); |
192 | - } else { |
|
215 | + } |
|
216 | + else |
|
217 | + { |
|
193 | 218 | unset($export_data['definitions'][$definition->name]['owner']); |
194 | 219 | } |
195 | 220 | unset($export_data['definitions'][$definition->name]['definition_id']); |
196 | 221 | unset($export_data['definitions'][$definition->name]['description']); |
197 | 222 | unset($export_data['definitions'][$definition->name]['user_timezone_read']); |
198 | - if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
223 | + if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) |
|
224 | + { |
|
199 | 225 | unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']); |
200 | 226 | } |
201 | 227 | unset($definition); |
@@ -215,7 +241,8 @@ discard block |
||
215 | 241 | */ |
216 | 242 | public static function import( $_import_file ) |
217 | 243 | { |
218 | - if ( !is_file( $_import_file ) ) { |
|
244 | + if ( !is_file( $_import_file ) ) |
|
245 | + { |
|
219 | 246 | throw new Exception("'$_import_file' does not exist or is not readable" ); |
220 | 247 | } |
221 | 248 | |
@@ -233,14 +260,20 @@ discard block |
||
233 | 260 | ); |
234 | 261 | |
235 | 262 | // Avoid warning if no definitions found |
236 | - if(!is_array($definitions)) return lang('None found'); |
|
263 | + if(!is_array($definitions)) |
|
264 | + { |
|
265 | + return lang('None found'); |
|
266 | + } |
|
237 | 267 | |
238 | 268 | // save definition(s) into internal table |
239 | 269 | foreach ( $definitions as $name => $definition_data ) |
240 | 270 | { |
241 | 271 | // convert allowed_user |
242 | 272 | $definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] ); |
243 | - if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
273 | + if($definition_data['all_users'] && !$definition_data['allowed_users']) |
|
274 | + { |
|
275 | + $definition_data['allowed_users'] = 'all'; |
|
276 | + } |
|
244 | 277 | |
245 | 278 | $definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] ); |
246 | 279 | |
@@ -275,7 +308,10 @@ discard block |
||
275 | 308 | public static function export_from_import(importexport_definition $import) |
276 | 309 | { |
277 | 310 | // Only operates on import definitions |
278 | - if($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions'); |
|
311 | + if($import->type != 'import') |
|
312 | + { |
|
313 | + throw new Api\Exception\WrongParameter('Only import definitions'); |
|
314 | + } |
|
279 | 315 | |
280 | 316 | // Find export plugin |
281 | 317 | $plugin = str_replace('import', 'export',$import->plugin); |
@@ -285,18 +321,30 @@ discard block |
||
285 | 321 | $plugins = $type['export']; |
286 | 322 | foreach($plugins as $name => $label) |
287 | 323 | { |
288 | - if($plugin == $name) break; |
|
324 | + if($plugin == $name) |
|
325 | + { |
|
326 | + break; |
|
327 | + } |
|
328 | + } |
|
329 | + if($plugin !== $name) |
|
330 | + { |
|
331 | + $plugin = $name; |
|
289 | 332 | } |
290 | - if($plugin !== $name) $plugin = $name; |
|
291 | 333 | } |
292 | 334 | |
293 | 335 | $export = new importexport_definition(); |
294 | 336 | |
295 | 337 | // Common settings |
296 | 338 | $export->name = str_replace('import', 'export',$import->name); |
297 | - if($export->name == $import->name) $export->name = $export->name . '-export'; |
|
339 | + if($export->name == $import->name) |
|
340 | + { |
|
341 | + $export->name = $export->name . '-export'; |
|
342 | + } |
|
298 | 343 | $test = new importexport_definition($export->name); |
299 | - if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
344 | + if($test->name) |
|
345 | + { |
|
346 | + $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
347 | + } |
|
300 | 348 | |
301 | 349 | $export->application = $import->application; |
302 | 350 | $export->plugin = $plugin; |
@@ -141,7 +141,7 @@ |
||
141 | 141 | * |
142 | 142 | * @param definition $definition |
143 | 143 | */ |
144 | - public function save(Array $data) { |
|
144 | + public function save(array $data) { |
|
145 | 145 | $definition = new importexport_definition(); |
146 | 146 | $definition->set_record($data); |
147 | 147 | $definition->save($data['definition_id']); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * List defined {im|ex}ports |
84 | 84 | * |
85 | - * @param array $content=null |
|
85 | + * @param array $content |
|
86 | 86 | */ |
87 | 87 | function index($content = null,$msg='') |
88 | 88 | { |
@@ -309,8 +309,9 @@ discard block |
||
309 | 309 | * @param int &$success number of succeded actions |
310 | 310 | * @param int &$failed number of failed actions (not enought permissions) |
311 | 311 | * @param string &$action_msg translated verb for the actions, to be used in a message like %1 entries 'deleted' |
312 | - * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup |
|
313 | - * @return boolean true if all actions succeded, false otherwise |
|
312 | + * @param string $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup |
|
313 | + * @param string $msg |
|
314 | + * @return null|boolean true if all actions succeded, false otherwise |
|
314 | 315 | */ |
315 | 316 | function action($action,$selected,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg) |
316 | 317 | { |
@@ -940,7 +940,7 @@ |
||
940 | 940 | * Determine if the user is allowed to edit the definition |
941 | 941 | * |
942 | 942 | */ |
943 | - protected function can_edit(Array $definition) |
|
943 | + protected function can_edit(array $definition) |
|
944 | 944 | { |
945 | 945 | if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
946 | 946 | { |
@@ -81,14 +81,18 @@ discard block |
||
81 | 81 | { |
82 | 82 | $filter = array('name' => '*'); |
83 | 83 | |
84 | - if($GLOBALS['egw_info']['user']['apps']['admin']) { |
|
84 | + if($GLOBALS['egw_info']['user']['apps']['admin']) |
|
85 | + { |
|
85 | 86 | // Any public definition |
86 | 87 | $filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = ' . $GLOBALS['egw_info']['user']['account_id'] . ')'; |
87 | - } else { |
|
88 | + } |
|
89 | + else |
|
90 | + { |
|
88 | 91 | // Filter private definitions |
89 | 92 | $filter['owner'] = $GLOBALS['egw_info']['user']['account_id']; |
90 | 93 | $config = Api\Config::read('phpgwapi'); |
91 | - if($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) { |
|
94 | + if($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) |
|
95 | + { |
|
92 | 96 | $filter['type'] = 'import'; |
93 | 97 | } |
94 | 98 | } |
@@ -104,7 +108,10 @@ discard block |
||
104 | 108 | elseif(($button = array_search('pressed',$content['nm']['rows'])) !== false) |
105 | 109 | { |
106 | 110 | $selected = $content['nm']['rows']['selected']; |
107 | - if(count($selected) < 1 || !is_array($selected)) exit(); |
|
111 | + if(count($selected) < 1 || !is_array($selected)) |
|
112 | + { |
|
113 | + exit(); |
|
114 | + } |
|
108 | 115 | switch ($button) |
109 | 116 | { |
110 | 117 | case 'delete_selected' : |
@@ -160,7 +167,8 @@ discard block |
||
160 | 167 | } |
161 | 168 | } |
162 | 169 | |
163 | - if(!is_array($content['nm'])) { |
|
170 | + if(!is_array($content['nm'])) |
|
171 | + { |
|
164 | 172 | $content['nm'] = array( |
165 | 173 | 'get_rows' => 'importexport.importexport_definitions_ui.get_rows', |
166 | 174 | 'no_cat' => true, |
@@ -171,7 +179,10 @@ discard block |
||
171 | 179 | 'row_id' => 'definition_id', |
172 | 180 | 'placeholder_actions' => array('add') |
173 | 181 | ); |
174 | - if($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application']; |
|
182 | + if($_GET['application']) |
|
183 | + { |
|
184 | + $content['nm']['col_filter']['application'] = $_GET['application']; |
|
185 | + } |
|
175 | 186 | } |
176 | 187 | if(Api\Cache::getSession('importexport', 'index')) |
177 | 188 | { |
@@ -190,17 +201,22 @@ discard block |
||
190 | 201 | ); |
191 | 202 | foreach ($this->plugins as $appname => $options) |
192 | 203 | { |
193 | - if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
204 | + if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) |
|
205 | + { |
|
194 | 206 | $sel_options['application'][$appname] = lang($appname); |
195 | 207 | } |
196 | 208 | } |
197 | - if($msg) $content['msg'] = $msg; |
|
209 | + if($msg) |
|
210 | + { |
|
211 | + $content['msg'] = $msg; |
|
212 | + } |
|
198 | 213 | |
199 | 214 | $etpl = new Etemplate(self::_appname.'.definition_index'); |
200 | 215 | return $etpl->exec( self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv ); |
201 | 216 | } |
202 | 217 | |
203 | - private function get_actions() { |
|
218 | + private function get_actions() |
|
219 | + { |
|
204 | 220 | $group = 0; |
205 | 221 | $actions = array( |
206 | 222 | 'edit' => array( |
@@ -319,7 +335,8 @@ discard block |
||
319 | 335 | $this->get_rows($query,$rows,$readonlys); |
320 | 336 | |
321 | 337 | $selected = array(); |
322 | - foreach($rows as $row) { |
|
338 | + foreach($rows as $row) |
|
339 | + { |
|
323 | 340 | $selected[] = $row['definition_id']; |
324 | 341 | } |
325 | 342 | if(!is_array($session_name)) |
@@ -334,18 +351,24 @@ discard block |
||
334 | 351 | |
335 | 352 | $bodefinitions = new importexport_definitions_bo(false, true); |
336 | 353 | |
337 | - switch($action) { |
|
354 | + switch($action) |
|
355 | + { |
|
338 | 356 | case 'allowed': |
339 | 357 | // Field is allowed_users, popup doesn't like _ |
340 | 358 | $action = 'allowed_users'; |
341 | 359 | // Fall through |
342 | 360 | case 'owner': |
343 | 361 | $action_msg = lang('changed'. ' ' . $action); |
344 | - foreach($selected as $id) { |
|
362 | + foreach($selected as $id) |
|
363 | + { |
|
345 | 364 | $definition = $bodefinitions->read((int)$id); |
346 | - if($definition['definition_id']) { |
|
365 | + if($definition['definition_id']) |
|
366 | + { |
|
347 | 367 | // Prevent private with no owner |
348 | - if(!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id']; |
|
368 | + if(!$definition['owner'] && !$settings) |
|
369 | + { |
|
370 | + $definition['owner'] = $GLOBALS['egw_info']['user']['account_id']; |
|
371 | + } |
|
349 | 372 | |
350 | 373 | $definition[$action] = $settings; |
351 | 374 | $bodefinitions->save($definition); |
@@ -372,18 +395,22 @@ discard block |
||
372 | 395 | case 'copy': |
373 | 396 | $action_msg = lang('copied'); |
374 | 397 | // Should only be one selected |
375 | - foreach($selected as $id) { |
|
398 | + foreach($selected as $id) |
|
399 | + { |
|
376 | 400 | $definition = $bodefinitions->read((int)$id); |
377 | - if($definition['definition_id']) { |
|
401 | + if($definition['definition_id']) |
|
402 | + { |
|
378 | 403 | unset($definition['definition_id']); |
379 | 404 | $definition['name'] = $settings ? $settings : $definition['name'] . ' copy'; |
380 | 405 | try { |
381 | 406 | $bodefinitions->save($definition); |
382 | - } catch (Exception $e) { |
|
407 | + } |
|
408 | + catch (Exception $e) { |
|
383 | 409 | try { |
384 | 410 | $definition['name'] .= ' ' . $GLOBALS['egw_info']['user']['account_lid']; |
385 | 411 | $bodefinitions->save($definition); |
386 | - } catch (Exception $ex) { |
|
412 | + } |
|
413 | + catch (Exception $ex) { |
|
387 | 414 | $failed++; |
388 | 415 | $msg .= lang('Duplicate name, please choose another.'); |
389 | 416 | continue; |
@@ -396,18 +423,21 @@ discard block |
||
396 | 423 | case 'createexport': |
397 | 424 | $action_msg = lang('created'); |
398 | 425 | // Should only be one selected |
399 | - foreach($selected as $id) { |
|
426 | + foreach($selected as $id) |
|
427 | + { |
|
400 | 428 | $definition = new importexport_definition($id); |
401 | 429 | try { |
402 | 430 | $export = $bodefinitions->export_from_import($definition); |
403 | 431 | $export->save(); |
404 | - } catch (Exception $e) { |
|
432 | + } |
|
433 | + catch (Exception $e) { |
|
405 | 434 | if($export) |
406 | 435 | { |
407 | 436 | try { |
408 | 437 | $export->name = $export->name.' ' . $GLOBALS['egw_info']['user']['account_lid']; |
409 | 438 | $export->save(); |
410 | - } catch (Exception $ex) { |
|
439 | + } |
|
440 | + catch (Exception $ex) { |
|
411 | 441 | $failed++; |
412 | 442 | $msg .= lang('Duplicate name, please choose another.'); |
413 | 443 | continue; |
@@ -425,7 +455,8 @@ discard block |
||
425 | 455 | return !$failed; |
426 | 456 | } |
427 | 457 | |
428 | - public function get_rows(&$query, &$rows, &$readonlys) { |
|
458 | + public function get_rows(&$query, &$rows, &$readonlys) |
|
459 | + { |
|
429 | 460 | $rows = array(); |
430 | 461 | Api\Cache::setSession('importexport', 'index', $query); |
431 | 462 | |
@@ -500,7 +531,10 @@ discard block |
||
500 | 531 | |
501 | 532 | if(is_array($content) &&! $content['edit']) |
502 | 533 | { |
503 | - if(self::_debug) error_log('importexport.wizard->$content '. print_r($content,true)); |
|
534 | + if(self::_debug) |
|
535 | + { |
|
536 | + error_log('importexport.wizard->$content '. print_r($content,true)); |
|
537 | + } |
|
504 | 538 | //foreach($content as $key => $val) error_log(" $key : ".array2string($val)); |
505 | 539 | // fetch plugin object |
506 | 540 | if($content['plugin'] && $content['application']) |
@@ -517,13 +551,18 @@ discard block |
||
517 | 551 | $wizard_plugin = $content['plugin']; |
518 | 552 | } |
519 | 553 | // App translations |
520 | - if($content['application']) Api\Translation::add_app($content['application']); |
|
554 | + if($content['application']) |
|
555 | + { |
|
556 | + Api\Translation::add_app($content['application']); |
|
557 | + } |
|
521 | 558 | |
522 | 559 | $this->plugin = is_object($GLOBALS['egw']->$wizard_plugin) ? $GLOBALS['egw']->$wizard_plugin : new $wizard_plugin; |
523 | 560 | |
524 | 561 | // Global object needs to be the same, or references to plugin don't work |
525 | 562 | if(!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this) |
526 | - $GLOBALS['egw']->importexport_definitions_ui =& $this; |
|
563 | + { |
|
564 | + $GLOBALS['egw']->importexport_definitions_ui =& $this; |
|
565 | + } |
|
527 | 566 | } |
528 | 567 | // deal with buttons even if we are not on ajax |
529 | 568 | if(isset($content['button']) && array_search('pressed',$content['button']) === false && count($content['button']) == 1) |
@@ -653,7 +692,10 @@ discard block |
||
653 | 692 | |
654 | 693 | function wizard_step10(&$content, &$sel_options, &$readonlys, &$preserv) |
655 | 694 | { |
656 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true)); |
|
695 | + if(self::_debug) |
|
696 | + { |
|
697 | + error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true)); |
|
698 | + } |
|
657 | 699 | |
658 | 700 | // return from step10 |
659 | 701 | if ($content['step'] == 'wizard_step10') |
@@ -675,7 +717,8 @@ discard block |
||
675 | 717 | $content['text'] = $this->steps['wizard_step10']; |
676 | 718 | foreach ($this->plugins as $appname => $options) |
677 | 719 | { |
678 | - if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
720 | + if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) |
|
721 | + { |
|
679 | 722 | $sel_options['application'][$appname] = lang($appname); |
680 | 723 | } |
681 | 724 | } |
@@ -691,7 +734,10 @@ discard block |
||
691 | 734 | // get plugin |
692 | 735 | function wizard_step20(&$content, &$sel_options, &$readonlys, &$preserv) |
693 | 736 | { |
694 | - if(self::_debug) error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true)); |
|
737 | + if(self::_debug) |
|
738 | + { |
|
739 | + error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true)); |
|
740 | + } |
|
695 | 741 | |
696 | 742 | // return from step20 |
697 | 743 | if ($content['step'] == 'wizard_step20') |
@@ -700,11 +746,16 @@ discard block |
||
700 | 746 | { |
701 | 747 | case 'next': |
702 | 748 | // There's no real reason the plugin has to come from any of these, as long as it has a $steps variable |
703 | - if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) { |
|
749 | + if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) |
|
750 | + { |
|
704 | 751 | $content['type'] = 'import'; |
705 | - } elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) { |
|
752 | + } |
|
753 | + elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) |
|
754 | + { |
|
706 | 755 | $content['type'] = 'export'; |
707 | - } else { |
|
756 | + } |
|
757 | + else |
|
758 | + { |
|
708 | 759 | throw new Api\Exception('Invalid plugin'); |
709 | 760 | } |
710 | 761 | return $this->get_step($content['step'],1); |
@@ -722,9 +773,14 @@ discard block |
||
722 | 773 | { |
723 | 774 | $content['text'] = $this->steps['wizard_step20']; |
724 | 775 | $config = Api\Config::read('phpgwapi'); |
725 | - foreach ($this->plugins[$content['application']] as $type => $plugins) { |
|
726 | - if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue; |
|
727 | - foreach($plugins as $plugin => $name) { |
|
776 | + foreach ($this->plugins[$content['application']] as $type => $plugins) |
|
777 | + { |
|
778 | + if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') |
|
779 | + { |
|
780 | + continue; |
|
781 | + } |
|
782 | + foreach($plugins as $plugin => $name) |
|
783 | + { |
|
728 | 784 | $sel_options['plugin'][$plugin] = $name; |
729 | 785 | } |
730 | 786 | } |
@@ -740,7 +796,10 @@ discard block |
||
740 | 796 | // name |
741 | 797 | function wizard_step21(&$content, &$sel_options, &$readonlys, &$preserv) |
742 | 798 | { |
743 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true)); |
|
799 | + if(self::_debug) |
|
800 | + { |
|
801 | + error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true)); |
|
802 | + } |
|
744 | 803 | |
745 | 804 | // Check for duplicate name |
746 | 805 | $duplicate = isset($content['duplicate_error']); |
@@ -752,7 +811,8 @@ discard block |
||
752 | 811 | { |
753 | 812 | throw new Exception('Already exists'); |
754 | 813 | } |
755 | - } catch (Exception $e) { |
|
814 | + } |
|
815 | + catch (Exception $e) { |
|
756 | 816 | // throw new Exception('Already exists'); |
757 | 817 | $content['duplicate_error'] = lang('Duplicate name, please choose another.'); |
758 | 818 | |
@@ -763,13 +823,16 @@ discard block |
||
763 | 823 | $content['name'] .'-'. Api\DateTime::to('now', true), |
764 | 824 | //$content['name'] .'-'. rand(0,100), |
765 | 825 | ); |
766 | - foreach($suggestions as $key => $suggestion) { |
|
826 | + foreach($suggestions as $key => $suggestion) |
|
827 | + { |
|
767 | 828 | $sug_definition = new importexport_definition($suggestion); |
768 | - if($sug_definition->definition_id) { |
|
829 | + if($sug_definition->definition_id) |
|
830 | + { |
|
769 | 831 | unset($suggestions[$key]); |
770 | 832 | } |
771 | 833 | } |
772 | - if($suggestions) { |
|
834 | + if($suggestions) |
|
835 | + { |
|
773 | 836 | $content['duplicate_error'] .= ' '. lang('Try')." \n" . implode("\n", $suggestions); |
774 | 837 | } |
775 | 838 | return $this->get_step($content['step'],0); |
@@ -806,7 +869,10 @@ discard block |
||
806 | 869 | // allowed users |
807 | 870 | function wizard_step90(&$content, &$sel_options, &$readonlys, &$preserv) |
808 | 871 | { |
809 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true)); |
|
872 | + if(self::_debug) |
|
873 | + { |
|
874 | + error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true)); |
|
875 | + } |
|
810 | 876 | |
811 | 877 | // return from step90 |
812 | 878 | if ($content['step'] == 'wizard_step90') |
@@ -876,7 +942,10 @@ discard block |
||
876 | 942 | |
877 | 943 | function wizard_finish(&$content) |
878 | 944 | { |
879 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true)); |
|
945 | + if(self::_debug) |
|
946 | + { |
|
947 | + error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true)); |
|
948 | + } |
|
880 | 949 | // Take out some UI leavings |
881 | 950 | unset($content['text']); |
882 | 951 | unset($content['step']); |
@@ -905,7 +974,8 @@ discard block |
||
905 | 974 | if($content['update']) |
906 | 975 | { |
907 | 976 | $applist = importexport_helper_functions::get_apps('all', true); |
908 | - foreach($applist as $appname) { |
|
977 | + foreach($applist as $appname) |
|
978 | + { |
|
909 | 979 | importexport_helper_functions::load_defaults($appname); |
910 | 980 | } |
911 | 981 | return $this->index(); |
@@ -971,7 +1041,9 @@ discard block |
||
971 | 1041 | { |
972 | 1042 | Api\Config::save_value($key, $value, 'importexport'); |
973 | 1043 | } |
974 | - } elseif (isset($content['cancel'])) { |
|
1044 | + } |
|
1045 | + elseif (isset($content['cancel'])) |
|
1046 | + { |
|
975 | 1047 | $GLOBALS['egw']->redirect_link('/admin/index.php'); |
976 | 1048 | } |
977 | 1049 | |
@@ -985,7 +1057,10 @@ discard block |
||
985 | 1057 | unset($sel_options['import_charsets'][strtoupper($charset)]); |
986 | 1058 | } |
987 | 1059 | |
988 | - if(!$data['update']) $data['update'] = 'request'; |
|
1060 | + if(!$data['update']) |
|
1061 | + { |
|
1062 | + $data['update'] = 'request'; |
|
1063 | + } |
|
989 | 1064 | |
990 | 1065 | $GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration') . ' - ' . lang(self::_appname); |
991 | 1066 | $etpl = new etemplate(self::_appname.'.config'); |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | function __construct() |
56 | 56 | { |
57 | 57 | // we cant deal with notice and warnings, as we are on ajax! |
58 | - error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); |
|
58 | + error_reporting(E_ALL&~E_NOTICE&~E_WARNING); |
|
59 | 59 | Api\Translation::add_app(self::_appname); |
60 | 60 | $GLOBALS['egw_info']['flags']['currentapp'] = self::_appname; |
61 | 61 | |
62 | 62 | $this->etpl = new Etemplate(); |
63 | - $this->clock = Api\Html::image(self::_appname,'clock'); |
|
63 | + $this->clock = Api\Html::image(self::_appname, 'clock'); |
|
64 | 64 | $this->steps = array( |
65 | 65 | 'wizard_step10' => lang('Choose an application'), |
66 | 66 | 'wizard_step20' => lang('Choose a plugin'), |
@@ -77,18 +77,18 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param array $content=null |
79 | 79 | */ |
80 | - function index($content = null,$msg='') |
|
80 | + function index($content = null, $msg = '') |
|
81 | 81 | { |
82 | 82 | $filter = array('name' => '*'); |
83 | 83 | |
84 | - if($GLOBALS['egw_info']['user']['apps']['admin']) { |
|
84 | + if ($GLOBALS['egw_info']['user']['apps']['admin']) { |
|
85 | 85 | // Any public definition |
86 | - $filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = ' . $GLOBALS['egw_info']['user']['account_id'] . ')'; |
|
86 | + $filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = '.$GLOBALS['egw_info']['user']['account_id'].')'; |
|
87 | 87 | } else { |
88 | 88 | // Filter private definitions |
89 | 89 | $filter['owner'] = $GLOBALS['egw_info']['user']['account_id']; |
90 | 90 | $config = Api\Config::read('phpgwapi'); |
91 | - if($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) { |
|
91 | + if ($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) { |
|
92 | 92 | $filter['type'] = 'import'; |
93 | 93 | } |
94 | 94 | } |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | if (isset($content['nm']['rows']['delete'])) |
100 | 100 | { |
101 | 101 | $content['nm']['action'] = 'delete'; |
102 | - $content['nm']['selected'] = array_keys($content['nm']['rows']['delete'],'pressed'); |
|
102 | + $content['nm']['selected'] = array_keys($content['nm']['rows']['delete'], 'pressed'); |
|
103 | 103 | } |
104 | - elseif(($button = array_search('pressed',$content['nm']['rows'])) !== false) |
|
104 | + elseif (($button = array_search('pressed', $content['nm']['rows'])) !== false) |
|
105 | 105 | { |
106 | 106 | $selected = $content['nm']['rows']['selected']; |
107 | - if(count($selected) < 1 || !is_array($selected)) exit(); |
|
107 | + if (count($selected) < 1 || !is_array($selected)) exit(); |
|
108 | 108 | switch ($button) |
109 | 109 | { |
110 | 110 | case 'delete_selected' : |
@@ -126,54 +126,54 @@ discard block |
||
126 | 126 | else |
127 | 127 | { |
128 | 128 | // Action has an additional parameter |
129 | - if(in_array($content['nm']['action'], array('owner', 'allowed'))) |
|
129 | + if (in_array($content['nm']['action'], array('owner', 'allowed'))) |
|
130 | 130 | { |
131 | 131 | $action = $content['nm']['action']; |
132 | - if($content['nm']['action'] == 'allowed') |
|
132 | + if ($content['nm']['action'] == 'allowed') |
|
133 | 133 | { |
134 | 134 | $content['allowed'] = $content['allowed_popup']['allowed_private'] == 'true' ? null : ( |
135 | - $content['allowed_popup']['all_users']=='true' ? 'all' : implode(',',$content['allowed_popup']['allowed']) |
|
135 | + $content['allowed_popup']['all_users'] == 'true' ? 'all' : implode(',', $content['allowed_popup']['allowed']) |
|
136 | 136 | ); |
137 | 137 | } |
138 | 138 | else |
139 | 139 | { |
140 | 140 | $content['owner'] = $content['owner_popup']['owner']; |
141 | 141 | } |
142 | - if(is_array($content[$content['nm']['action']])) |
|
142 | + if (is_array($content[$content['nm']['action']])) |
|
143 | 143 | { |
144 | - $content[$content['nm']['action']] = implode(',',$content[$content['nm']['action']]); |
|
144 | + $content[$content['nm']['action']] = implode(',', $content[$content['nm']['action']]); |
|
145 | 145 | } |
146 | - $content['nm']['action'] .= '_' . $content[$action]; |
|
146 | + $content['nm']['action'] .= '_'.$content[$action]; |
|
147 | 147 | unset($content[$action]); |
148 | 148 | unset($content['allowed_popup']); |
149 | 149 | } |
150 | - if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'], |
|
151 | - $success,$failed,$action_msg,'index',$msg)) |
|
150 | + if ($this->action($content['nm']['action'], $content['nm']['selected'], $content['nm']['select_all'], |
|
151 | + $success, $failed, $action_msg, 'index', $msg)) |
|
152 | 152 | { |
153 | - $msg .= lang('%1 definition(s) %2',$success,$action_msg); |
|
153 | + $msg .= lang('%1 definition(s) %2', $success, $action_msg); |
|
154 | 154 | } |
155 | - elseif(empty($msg)) |
|
155 | + elseif (empty($msg)) |
|
156 | 156 | { |
157 | - $msg .= lang('%1 definition(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed); |
|
157 | + $msg .= lang('%1 definition(s) %2, %3 failed because of insufficent rights !!!', $success, $action_msg, $failed); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - if(!is_array($content['nm'])) { |
|
163 | + if (!is_array($content['nm'])) { |
|
164 | 164 | $content['nm'] = array( |
165 | 165 | 'get_rows' => 'importexport.importexport_definitions_ui.get_rows', |
166 | 166 | 'no_cat' => true, |
167 | 167 | 'no_filter' => true, |
168 | 168 | 'no_filter2' => true, |
169 | - 'csv_fields' => false, // Disable CSV export, uses own export |
|
170 | - 'default_cols' => '!actions', // switch legacy actions column and row off by default |
|
169 | + 'csv_fields' => false, // Disable CSV export, uses own export |
|
170 | + 'default_cols' => '!actions', // switch legacy actions column and row off by default |
|
171 | 171 | 'row_id' => 'definition_id', |
172 | 172 | 'placeholder_actions' => array('add') |
173 | 173 | ); |
174 | - if($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application']; |
|
174 | + if ($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application']; |
|
175 | 175 | } |
176 | - if(Api\Cache::getSession('importexport', 'index')) |
|
176 | + if (Api\Cache::getSession('importexport', 'index')) |
|
177 | 177 | { |
178 | 178 | $content['nm'] = array_merge($content['nm'], Api\Cache::getSession('importexport', 'index')); |
179 | 179 | } |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | ); |
191 | 191 | foreach ($this->plugins as $appname => $options) |
192 | 192 | { |
193 | - if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
193 | + if ($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
194 | 194 | $sel_options['application'][$appname] = lang($appname); |
195 | 195 | } |
196 | 196 | } |
197 | - if($msg) $content['msg'] = $msg; |
|
197 | + if ($msg) $content['msg'] = $msg; |
|
198 | 198 | |
199 | 199 | $etpl = new Etemplate(self::_appname.'.definition_index'); |
200 | - return $etpl->exec( self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv ); |
|
200 | + return $etpl->exec(self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | private function get_actions() { |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | ); |
287 | 287 | |
288 | 288 | // Unset admin actions |
289 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
289 | + if (!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
290 | 290 | { |
291 | 291 | unset($actions['schedule']); |
292 | 292 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup |
306 | 306 | * @return boolean true if all actions succeded, false otherwise |
307 | 307 | */ |
308 | - function action($action,$selected,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg) |
|
308 | + function action($action, $selected, $use_all, &$success, &$failed, &$action_msg, $session_name, &$msg) |
|
309 | 309 | { |
310 | 310 | //error_log( __METHOD__."('$action', ".array2string($selected).', '.array2string($use_all).",,, '$session_name')"); |
311 | 311 | if ($use_all) |
@@ -313,16 +313,16 @@ discard block |
||
313 | 313 | // get the whole selection |
314 | 314 | $old_query = $query = is_array($session_name) ? $session_name : Api\Cache::getSession('importexport', $session_name); |
315 | 315 | |
316 | - @set_time_limit(0); // switch off the execution time limit, as it's for big selections to small |
|
317 | - $query['num_rows'] = -1; // all |
|
318 | - $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session |
|
319 | - $this->get_rows($query,$rows,$readonlys); |
|
316 | + @set_time_limit(0); // switch off the execution time limit, as it's for big selections to small |
|
317 | + $query['num_rows'] = -1; // all |
|
318 | + $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session |
|
319 | + $this->get_rows($query, $rows, $readonlys); |
|
320 | 320 | |
321 | 321 | $selected = array(); |
322 | - foreach($rows as $row) { |
|
322 | + foreach ($rows as $row) { |
|
323 | 323 | $selected[] = $row['definition_id']; |
324 | 324 | } |
325 | - if(!is_array($session_name)) |
|
325 | + if (!is_array($session_name)) |
|
326 | 326 | { |
327 | 327 | // Restore old query |
328 | 328 | Api\Cache::setSession('importexport', $session_name, $old_query); |
@@ -334,18 +334,18 @@ discard block |
||
334 | 334 | |
335 | 335 | $bodefinitions = new importexport_definitions_bo(false, true); |
336 | 336 | |
337 | - switch($action) { |
|
337 | + switch ($action) { |
|
338 | 338 | case 'allowed': |
339 | 339 | // Field is allowed_users, popup doesn't like _ |
340 | 340 | $action = 'allowed_users'; |
341 | 341 | // Fall through |
342 | 342 | case 'owner': |
343 | - $action_msg = lang('changed'. ' ' . $action); |
|
344 | - foreach($selected as $id) { |
|
343 | + $action_msg = lang('changed'.' '.$action); |
|
344 | + foreach ($selected as $id) { |
|
345 | 345 | $definition = $bodefinitions->read((int)$id); |
346 | - if($definition['definition_id']) { |
|
346 | + if ($definition['definition_id']) { |
|
347 | 347 | // Prevent private with no owner |
348 | - if(!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id']; |
|
348 | + if (!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id']; |
|
349 | 349 | |
350 | 350 | $definition[$action] = $settings; |
351 | 351 | $bodefinitions->save($definition); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $mime_type = ($GLOBALS['egw']->html->user_agent == 'msie' || $GLOBALS['egw']->html->user_agent == 'opera') ? |
364 | 364 | 'application/octetstream' : 'application/octet-stream'; |
365 | 365 | $name = 'importexport_definition.xml'; |
366 | - header('Content-Type: ' . $mime_type); |
|
366 | + header('Content-Type: '.$mime_type); |
|
367 | 367 | header('Content-Disposition: attachment; filename="'.$name.'"'); |
368 | 368 | echo $bodefinitions->export($selected); |
369 | 369 | exit(); |
@@ -372,16 +372,16 @@ discard block |
||
372 | 372 | case 'copy': |
373 | 373 | $action_msg = lang('copied'); |
374 | 374 | // Should only be one selected |
375 | - foreach($selected as $id) { |
|
375 | + foreach ($selected as $id) { |
|
376 | 376 | $definition = $bodefinitions->read((int)$id); |
377 | - if($definition['definition_id']) { |
|
377 | + if ($definition['definition_id']) { |
|
378 | 378 | unset($definition['definition_id']); |
379 | - $definition['name'] = $settings ? $settings : $definition['name'] . ' copy'; |
|
379 | + $definition['name'] = $settings ? $settings : $definition['name'].' copy'; |
|
380 | 380 | try { |
381 | 381 | $bodefinitions->save($definition); |
382 | 382 | } catch (Exception $e) { |
383 | 383 | try { |
384 | - $definition['name'] .= ' ' . $GLOBALS['egw_info']['user']['account_lid']; |
|
384 | + $definition['name'] .= ' '.$GLOBALS['egw_info']['user']['account_lid']; |
|
385 | 385 | $bodefinitions->save($definition); |
386 | 386 | } catch (Exception $ex) { |
387 | 387 | $failed++; |
@@ -396,16 +396,16 @@ discard block |
||
396 | 396 | case 'createexport': |
397 | 397 | $action_msg = lang('created'); |
398 | 398 | // Should only be one selected |
399 | - foreach($selected as $id) { |
|
399 | + foreach ($selected as $id) { |
|
400 | 400 | $definition = new importexport_definition($id); |
401 | 401 | try { |
402 | 402 | $export = $bodefinitions->export_from_import($definition); |
403 | 403 | $export->save(); |
404 | 404 | } catch (Exception $e) { |
405 | - if($export) |
|
405 | + if ($export) |
|
406 | 406 | { |
407 | 407 | try { |
408 | - $export->name = $export->name.' ' . $GLOBALS['egw_info']['user']['account_lid']; |
|
408 | + $export->name = $export->name.' '.$GLOBALS['egw_info']['user']['account_lid']; |
|
409 | 409 | $export->save(); |
410 | 410 | } catch (Exception $ex) { |
411 | 411 | $failed++; |
@@ -430,10 +430,10 @@ discard block |
||
430 | 430 | Api\Cache::setSession('importexport', 'index', $query); |
431 | 431 | |
432 | 432 | // Special handling for allowed users 'private' |
433 | - if($query['col_filter']['allowed_users'] == 'private') |
|
433 | + if ($query['col_filter']['allowed_users'] == 'private') |
|
434 | 434 | { |
435 | 435 | unset($query['col_filter']['allowed_users']); |
436 | - $query['col_filter'][] = 'allowed_users = ' . $GLOBALS['egw']->db->quote(',,'); |
|
436 | + $query['col_filter'][] = 'allowed_users = '.$GLOBALS['egw']->db->quote(',,'); |
|
437 | 437 | } |
438 | 438 | $bodefinitions = new importexport_definitions_bo($query['col_filter'], true); |
439 | 439 | // We don't care about readonlys for the UI |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | function edit() |
450 | 450 | { |
451 | - if(!$_definition = $_GET['definition']) |
|
451 | + if (!$_definition = $_GET['definition']) |
|
452 | 452 | { |
453 | 453 | $content = array( |
454 | 454 | 'edit' => true, |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | ); |
458 | 458 | |
459 | 459 | // Jump to a step |
460 | - if($_GET['step']) |
|
460 | + if ($_GET['step']) |
|
461 | 461 | { |
462 | 462 | $content['edit'] = false; |
463 | 463 | // Wizard will process previous step, then advance |
464 | - $content['step'] = $this->get_step($_GET['step'],-1); |
|
464 | + $content['step'] = $this->get_step($_GET['step'], -1); |
|
465 | 465 | $content['button']['next'] = 'pressed'; |
466 | 466 | $this->wizard($content); |
467 | 467 | } |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | } |
473 | 473 | return; |
474 | 474 | } |
475 | - if(is_numeric($_GET['definition'])) |
|
475 | + if (is_numeric($_GET['definition'])) |
|
476 | 476 | { |
477 | 477 | $definition = (int)$_GET['definition']; |
478 | 478 | } |
@@ -484,31 +484,31 @@ discard block |
||
484 | 484 | $definition = $bodefinitions->read($definition); |
485 | 485 | $definition['edit'] = true; |
486 | 486 | // Jump to a step |
487 | - if($_GET['step']) |
|
487 | + if ($_GET['step']) |
|
488 | 488 | { |
489 | 489 | $definition['edit'] = false; |
490 | 490 | // Wizard will process previous step, then advance |
491 | - $definition['step'] = $_GET['step'];; |
|
491 | + $definition['step'] = $_GET['step']; ; |
|
492 | 492 | $definition['button'] = array('next' => 'pressed'); |
493 | 493 | } |
494 | 494 | $this->wizard($definition); |
495 | 495 | } |
496 | 496 | |
497 | - function wizard($content = null, $msg='') |
|
497 | + function wizard($content = null, $msg = '') |
|
498 | 498 | { |
499 | 499 | $this->etpl->read('importexport.wizardbox'); |
500 | 500 | |
501 | - if(is_array($content) &&! $content['edit']) |
|
501 | + if (is_array($content) && !$content['edit']) |
|
502 | 502 | { |
503 | - if(self::_debug) error_log('importexport.wizard->$content '. print_r($content,true)); |
|
503 | + if (self::_debug) error_log('importexport.wizard->$content '.print_r($content, true)); |
|
504 | 504 | //foreach($content as $key => $val) error_log(" $key : ".array2string($val)); |
505 | 505 | // fetch plugin object |
506 | - if($content['plugin'] && $content['application']) |
|
506 | + if ($content['plugin'] && $content['application']) |
|
507 | 507 | { |
508 | - $wizard_name = $content['application'] . '_wizard_' . str_replace($content['application'] . '_', '', $content['plugin']); |
|
508 | + $wizard_name = $content['application'].'_wizard_'.str_replace($content['application'].'_', '', $content['plugin']); |
|
509 | 509 | |
510 | 510 | // we need to deal with the wizard object if exists |
511 | - if (file_exists(EGW_SERVER_ROOT . '/'. $content['application']."/inc/class.$wizard_name.inc.php")) |
|
511 | + if (file_exists(EGW_SERVER_ROOT.'/'.$content['application']."/inc/class.$wizard_name.inc.php")) |
|
512 | 512 | { |
513 | 513 | $wizard_plugin = $wizard_name; |
514 | 514 | } |
@@ -517,38 +517,38 @@ discard block |
||
517 | 517 | $wizard_plugin = $content['plugin']; |
518 | 518 | } |
519 | 519 | // App translations |
520 | - if($content['application']) Api\Translation::add_app($content['application']); |
|
520 | + if ($content['application']) Api\Translation::add_app($content['application']); |
|
521 | 521 | |
522 | 522 | $this->plugin = is_object($GLOBALS['egw']->$wizard_plugin) ? $GLOBALS['egw']->$wizard_plugin : new $wizard_plugin; |
523 | 523 | |
524 | 524 | // Global object needs to be the same, or references to plugin don't work |
525 | - if(!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this) |
|
526 | - $GLOBALS['egw']->importexport_definitions_ui =& $this; |
|
525 | + if (!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this) |
|
526 | + $GLOBALS['egw']->importexport_definitions_ui = & $this; |
|
527 | 527 | } |
528 | 528 | // deal with buttons even if we are not on ajax |
529 | - if(isset($content['button']) && array_search('pressed',$content['button']) === false && count($content['button']) == 1) |
|
529 | + if (isset($content['button']) && array_search('pressed', $content['button']) === false && count($content['button']) == 1) |
|
530 | 530 | { |
531 | 531 | $button = array_keys($content['button']); |
532 | 532 | $content['button'] = array($button[0] => 'pressed'); |
533 | 533 | } |
534 | 534 | |
535 | 535 | // post process submitted step |
536 | - if($content['step']) |
|
536 | + if ($content['step']) |
|
537 | 537 | { |
538 | - if(!$this->can_edit($content)) |
|
538 | + if (!$this->can_edit($content)) |
|
539 | 539 | { |
540 | 540 | // Each step changes definition, reload it |
541 | 541 | $bodefinitions = new importexport_definitions_bo(); |
542 | 542 | $definition = $bodefinitions->read($content); |
543 | 543 | $content = $definition + array('step' => $content['step'], 'button' => $content['button']); |
544 | 544 | } |
545 | - if(!key_exists($content['step'],$this->steps)) |
|
545 | + if (!key_exists($content['step'], $this->steps)) |
|
546 | 546 | { |
547 | - $next_step = $this->plugin->{$content['step']}($content,$sel_options,$readonlys,$preserv); |
|
547 | + $next_step = $this->plugin->{$content['step']}($content, $sel_options, $readonlys, $preserv); |
|
548 | 548 | } |
549 | 549 | else |
550 | 550 | { |
551 | - $next_step = $this->{$content['step']}($content,$sel_options,$readonlys,$preserv); |
|
551 | + $next_step = $this->{$content['step']}($content, $sel_options, $readonlys, $preserv); |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | else |
@@ -560,23 +560,23 @@ discard block |
||
560 | 560 | $sel_options = $readonlys = $preserv = array(); |
561 | 561 | |
562 | 562 | // Disable finish button if required fields are missing |
563 | - if(!$content['name'] || !$content['type'] || !$content['plugin']) |
|
563 | + if (!$content['name'] || !$content['type'] || !$content['plugin']) |
|
564 | 564 | { |
565 | 565 | $readonlys['button[finish]'] = true; |
566 | 566 | } |
567 | 567 | do |
568 | 568 | { |
569 | - if(!key_exists($next_step,$this->steps)) |
|
569 | + if (!key_exists($next_step, $this->steps)) |
|
570 | 570 | { |
571 | - $this->wizard_content_template = $this->plugin->$next_step($content,$sel_options,$readonlys,$preserv); |
|
571 | + $this->wizard_content_template = $this->plugin->$next_step($content, $sel_options, $readonlys, $preserv); |
|
572 | 572 | } |
573 | 573 | else |
574 | 574 | { |
575 | - $this->wizard_content_template = $this->$next_step($content,$sel_options,$readonlys,$preserv); |
|
575 | + $this->wizard_content_template = $this->$next_step($content, $sel_options, $readonlys, $preserv); |
|
576 | 576 | } |
577 | - if($this->wizard_content_template == self::SKIP) |
|
577 | + if ($this->wizard_content_template == self::SKIP) |
|
578 | 578 | { |
579 | - if(!key_exists($content['step'],$this->steps)) |
|
579 | + if (!key_exists($content['step'], $this->steps)) |
|
580 | 580 | { |
581 | 581 | $next_step = $this->plugin->{$content['step']}($content); |
582 | 582 | } |
@@ -585,9 +585,9 @@ discard block |
||
585 | 585 | $next_step = $this->{$content['step']}($content); |
586 | 586 | } |
587 | 587 | } |
588 | - } while($this->wizard_content_template == self::SKIP); |
|
588 | + } while ($this->wizard_content_template == self::SKIP); |
|
589 | 589 | |
590 | - if(!$this->can_edit($content)) |
|
590 | + if (!$this->can_edit($content)) |
|
591 | 591 | { |
592 | 592 | $readonlys[$this->wizard_content_template] = true; |
593 | 593 | $preserve = $content; |
@@ -596,21 +596,21 @@ discard block |
||
596 | 596 | |
597 | 597 | unset($content['button']); |
598 | 598 | $content['wizard_content'] = $this->wizard_content_template; |
599 | - $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,2); |
|
599 | + $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard', $content, $sel_options, $readonlys, $preserv, 2); |
|
600 | 600 | } |
601 | 601 | else |
602 | 602 | { |
603 | 603 | // initial content |
604 | 604 | $sel_options = $readonlys = $preserv = array(); |
605 | 605 | $readonlys['button[previous]'] = true; |
606 | - if($content['edit']) |
|
606 | + if ($content['edit']) |
|
607 | 607 | { |
608 | 608 | unset ($content['edit']); |
609 | 609 | } |
610 | 610 | |
611 | 611 | $this->wizard_content_template = $this->wizard_step10($content, $sel_options, $readonlys, $preserv); |
612 | 612 | |
613 | - if(!$this->can_edit($content)) |
|
613 | + if (!$this->can_edit($content)) |
|
614 | 614 | { |
615 | 615 | $readonlys[$this->wizard_content_template] = true; |
616 | 616 | $preserve = $content; |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | } |
619 | 619 | |
620 | 620 | $content['wizard_content'] = $this->wizard_content_template; |
621 | - $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,2); |
|
621 | + $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard', $content, $sel_options, $readonlys, $preserv, 2); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -629,31 +629,31 @@ discard block |
||
629 | 629 | * @param int $step_width |
630 | 630 | * @return string containing function name of next step |
631 | 631 | */ |
632 | - function get_step ($curr_step, $step_width) |
|
632 | + function get_step($curr_step, $step_width) |
|
633 | 633 | { |
634 | 634 | /*if($content['plugin'] && $content['application']&& !is_object($this->plugin)) |
635 | 635 | { |
636 | 636 | $plugin_definition = $this->plugins[$content['application']][$content['plugin']]['definition']; |
637 | 637 | if($plugin_definition) $this->plugin = new $plugin_definition; |
638 | 638 | }*/ |
639 | - if(is_object($this->plugin) && is_array($this->plugin->steps)) |
|
639 | + if (is_object($this->plugin) && is_array($this->plugin->steps)) |
|
640 | 640 | { |
641 | - $steps = array_merge($this->steps,$this->plugin->steps); |
|
642 | - $steps = array_flip($steps); asort($steps); $steps = array_flip($steps); |
|
641 | + $steps = array_merge($this->steps, $this->plugin->steps); |
|
642 | + $steps = array_flip($steps); asort($steps); $steps = array_flip($steps); |
|
643 | 643 | } |
644 | 644 | else |
645 | 645 | { |
646 | 646 | $steps = $this->steps; |
647 | 647 | } |
648 | 648 | $step_keys = array_keys($steps); |
649 | - $nn = array_search($curr_step,$step_keys)+(int)$step_width; |
|
650 | - return (key_exists($nn,$step_keys)) ? $step_keys[$nn] : 'wizard_finish'; |
|
649 | + $nn = array_search($curr_step, $step_keys) + (int)$step_width; |
|
650 | + return (key_exists($nn, $step_keys)) ? $step_keys[$nn] : 'wizard_finish'; |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | |
654 | 654 | function wizard_step10(&$content, &$sel_options, &$readonlys, &$preserv) |
655 | 655 | { |
656 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true)); |
|
656 | + if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content, true)); |
|
657 | 657 | |
658 | 658 | // return from step10 |
659 | 659 | if ($content['step'] == 'wizard_step10') |
@@ -661,11 +661,11 @@ discard block |
||
661 | 661 | switch (array_search('pressed', $content['button'])) |
662 | 662 | { |
663 | 663 | case 'next': |
664 | - return $this->get_step($content['step'],1); |
|
664 | + return $this->get_step($content['step'], 1); |
|
665 | 665 | case 'finish': |
666 | 666 | return 'wizard_finish'; |
667 | 667 | default : |
668 | - return $this->wizard_step10($content,$sel_options,$readonlys,$preserv); |
|
668 | + return $this->wizard_step10($content, $sel_options, $readonlys, $preserv); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | } |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | $content['text'] = $this->steps['wizard_step10']; |
676 | 676 | foreach ($this->plugins as $appname => $options) |
677 | 677 | { |
678 | - if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
678 | + if ($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
679 | 679 | $sel_options['application'][$appname] = lang($appname); |
680 | 680 | } |
681 | 681 | } |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | // get plugin |
692 | 692 | function wizard_step20(&$content, &$sel_options, &$readonlys, &$preserv) |
693 | 693 | { |
694 | - if(self::_debug) error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true)); |
|
694 | + if (self::_debug) error_log('importexport.'.get_class($this).'::wizard_step20->$content '.print_r($content, true)); |
|
695 | 695 | |
696 | 696 | // return from step20 |
697 | 697 | if ($content['step'] == 'wizard_step20') |
@@ -700,21 +700,21 @@ discard block |
||
700 | 700 | { |
701 | 701 | case 'next': |
702 | 702 | // There's no real reason the plugin has to come from any of these, as long as it has a $steps variable |
703 | - if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) { |
|
703 | + if ($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) { |
|
704 | 704 | $content['type'] = 'import'; |
705 | - } elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) { |
|
705 | + } elseif ($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin), 'export') !== false) { |
|
706 | 706 | $content['type'] = 'export'; |
707 | 707 | } else { |
708 | 708 | throw new Api\Exception('Invalid plugin'); |
709 | 709 | } |
710 | - return $this->get_step($content['step'],1); |
|
710 | + return $this->get_step($content['step'], 1); |
|
711 | 711 | case 'previous' : |
712 | 712 | $readonlys['button[previous]'] = true; |
713 | - return $this->get_step($content['step'],-1); |
|
713 | + return $this->get_step($content['step'], -1); |
|
714 | 714 | case 'finish': |
715 | 715 | return 'wizard_finish'; |
716 | 716 | default : |
717 | - return $this->wizard_step20($content,$sel_options,$readonlys,$preserv); |
|
717 | + return $this->wizard_step20($content, $sel_options, $readonlys, $preserv); |
|
718 | 718 | } |
719 | 719 | } |
720 | 720 | // init step20 |
@@ -723,8 +723,8 @@ discard block |
||
723 | 723 | $content['text'] = $this->steps['wizard_step20']; |
724 | 724 | $config = Api\Config::read('phpgwapi'); |
725 | 725 | foreach ($this->plugins[$content['application']] as $type => $plugins) { |
726 | - if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue; |
|
727 | - foreach($plugins as $plugin => $name) { |
|
726 | + if ($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue; |
|
727 | + foreach ($plugins as $plugin => $name) { |
|
728 | 728 | $sel_options['plugin'][$plugin] = $name; |
729 | 729 | } |
730 | 730 | } |
@@ -740,15 +740,15 @@ discard block |
||
740 | 740 | // name |
741 | 741 | function wizard_step21(&$content, &$sel_options, &$readonlys, &$preserv) |
742 | 742 | { |
743 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true)); |
|
743 | + if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content, true)); |
|
744 | 744 | |
745 | 745 | // Check for duplicate name |
746 | 746 | $duplicate = isset($content['duplicate_error']); |
747 | - if($content['name'] && !$duplicate) |
|
747 | + if ($content['name'] && !$duplicate) |
|
748 | 748 | { |
749 | 749 | try { |
750 | 750 | $check_definition = new importexport_definition($content['name']); |
751 | - if($check_definition && $check_definition->definition_id && $check_definition->definition_id != $content['definition_id']) |
|
751 | + if ($check_definition && $check_definition->definition_id && $check_definition->definition_id != $content['definition_id']) |
|
752 | 752 | { |
753 | 753 | throw new Exception('Already exists'); |
754 | 754 | } |
@@ -758,21 +758,21 @@ discard block |
||
758 | 758 | |
759 | 759 | // Try some suggestions |
760 | 760 | $suggestions = array( |
761 | - $content['name'] .'-'. $GLOBALS['egw_info']['user']['account_lid'], |
|
762 | - $content['name'] .'-'. $GLOBALS['egw_info']['user']['account_id'], |
|
763 | - $content['name'] .'-'. Api\DateTime::to('now', true), |
|
761 | + $content['name'].'-'.$GLOBALS['egw_info']['user']['account_lid'], |
|
762 | + $content['name'].'-'.$GLOBALS['egw_info']['user']['account_id'], |
|
763 | + $content['name'].'-'.Api\DateTime::to('now', true), |
|
764 | 764 | //$content['name'] .'-'. rand(0,100), |
765 | 765 | ); |
766 | - foreach($suggestions as $key => $suggestion) { |
|
766 | + foreach ($suggestions as $key => $suggestion) { |
|
767 | 767 | $sug_definition = new importexport_definition($suggestion); |
768 | - if($sug_definition->definition_id) { |
|
768 | + if ($sug_definition->definition_id) { |
|
769 | 769 | unset($suggestions[$key]); |
770 | 770 | } |
771 | 771 | } |
772 | - if($suggestions) { |
|
773 | - $content['duplicate_error'] .= ' '. lang('Try')." \n" . implode("\n", $suggestions); |
|
772 | + if ($suggestions) { |
|
773 | + $content['duplicate_error'] .= ' '.lang('Try')." \n".implode("\n", $suggestions); |
|
774 | 774 | } |
775 | - return $this->get_step($content['step'],0); |
|
775 | + return $this->get_step($content['step'], 0); |
|
776 | 776 | } |
777 | 777 | } |
778 | 778 | |
@@ -782,19 +782,19 @@ discard block |
||
782 | 782 | switch (array_search('pressed', $content['button'])) |
783 | 783 | { |
784 | 784 | case 'next': |
785 | - return $this->get_step($content['step'],1); |
|
785 | + return $this->get_step($content['step'], 1); |
|
786 | 786 | case 'previous' : |
787 | - return $this->get_step($content['step'],-1); |
|
787 | + return $this->get_step($content['step'], -1); |
|
788 | 788 | case 'finish': |
789 | 789 | return 'wizard_finish'; |
790 | 790 | default : |
791 | - return $this->wizard_step21($content,$sel_options,$readonlys,$preserv); |
|
791 | + return $this->wizard_step21($content, $sel_options, $readonlys, $preserv); |
|
792 | 792 | } |
793 | 793 | } |
794 | 794 | // init step21 |
795 | 795 | else |
796 | 796 | { |
797 | - $content['text'] = $this->steps['wizard_step21'] . ($duplicate ? "\n".$content['duplicate_error'] : ''); |
|
797 | + $content['text'] = $this->steps['wizard_step21'].($duplicate ? "\n".$content['duplicate_error'] : ''); |
|
798 | 798 | $content['step'] = 'wizard_step21'; |
799 | 799 | unset($content['duplicate_error']); |
800 | 800 | $preserv = $content; |
@@ -806,17 +806,16 @@ discard block |
||
806 | 806 | // allowed users |
807 | 807 | function wizard_step90(&$content, &$sel_options, &$readonlys, &$preserv) |
808 | 808 | { |
809 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true)); |
|
809 | + if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content, true)); |
|
810 | 810 | |
811 | 811 | // return from step90 |
812 | 812 | if ($content['step'] == 'wizard_step90') |
813 | 813 | { |
814 | - if($this->can_edit($content)) |
|
814 | + if ($this->can_edit($content)) |
|
815 | 815 | { |
816 | - $content['owner'] = $content['just_me'] || !$GLOBALS['egw']->acl->check('share_definitions', Acl::READ,'importexport') ? |
|
817 | - ($content['owner'] ? $content['owner'] : $GLOBALS['egw_info']['user']['account_id']) : |
|
818 | - null; |
|
819 | - $content['allowed_users'] = $content['just_me'] ? '' : ($content['all_users'] ? 'all' : implode(',',$content['allowed_users'])); |
|
816 | + $content['owner'] = $content['just_me'] || !$GLOBALS['egw']->acl->check('share_definitions', Acl::READ, 'importexport') ? |
|
817 | + ($content['owner'] ? $content['owner'] : $GLOBALS['egw_info']['user']['account_id']) : null; |
|
818 | + $content['allowed_users'] = $content['just_me'] ? '' : ($content['all_users'] ? 'all' : implode(',', $content['allowed_users'])); |
|
820 | 819 | unset($content['just_me']); |
821 | 820 | } |
822 | 821 | |
@@ -824,12 +823,12 @@ discard block |
||
824 | 823 | switch (array_search('pressed', $content['button'])) |
825 | 824 | { |
826 | 825 | case 'previous' : |
827 | - return $this->get_step($content['step'],-1); |
|
826 | + return $this->get_step($content['step'], -1); |
|
828 | 827 | case 'next': |
829 | 828 | case 'finish': |
830 | 829 | return 'wizard_finish'; |
831 | 830 | default : |
832 | - return $this->wizard_step90($content,$sel_options,$readonlys,$preserv); |
|
831 | + return $this->wizard_step90($content, $sel_options, $readonlys, $preserv); |
|
833 | 832 | } |
834 | 833 | } |
835 | 834 | // init step90 |
@@ -840,10 +839,10 @@ discard block |
||
840 | 839 | $preserv = $content; |
841 | 840 | |
842 | 841 | // Set owner for non-admins |
843 | - $content['just_me'] = ((!$content['allowed_users'] || !$content['allowed_users'][0] && count($content['allowed_users']) ==1) && $content['owner']); |
|
844 | - $content['all_users'] = is_array($content['allowed_users']) && array_key_exists('0',$content['allowed_users']) && $content['allowed_users'][0] == 'all' || |
|
842 | + $content['just_me'] = ((!$content['allowed_users'] || !$content['allowed_users'][0] && count($content['allowed_users']) == 1) && $content['owner']); |
|
843 | + $content['all_users'] = is_array($content['allowed_users']) && array_key_exists('0', $content['allowed_users']) && $content['allowed_users'][0] == 'all' || |
|
845 | 844 | $content['allowed_users'] == 'all'; |
846 | - if(!$GLOBALS['egw']->acl->check('share_definition', Acl::READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin']) |
|
845 | + if (!$GLOBALS['egw']->acl->check('share_definition', Acl::READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin']) |
|
847 | 846 | { |
848 | 847 | $content['allowed_users'] = array(); |
849 | 848 | $readonlys['allowed_users'] = true; |
@@ -859,11 +858,11 @@ discard block |
||
859 | 858 | ) |
860 | 859 | ); |
861 | 860 | // Hide 'just me' checkbox, users get confused by read-only |
862 | - if($readonlys['just_me'] || !$this->can_edit($content)) |
|
861 | + if ($readonlys['just_me'] || !$this->can_edit($content)) |
|
863 | 862 | { |
864 | 863 | $content['no_just_me'] = true; |
865 | 864 | } |
866 | - if($readonlys['all_users'] || !$this->can_edit($content)) |
|
865 | + if ($readonlys['all_users'] || !$this->can_edit($content)) |
|
867 | 866 | { |
868 | 867 | $content['no_all_users'] = true; |
869 | 868 | } |
@@ -876,7 +875,7 @@ discard block |
||
876 | 875 | |
877 | 876 | function wizard_finish(&$content) |
878 | 877 | { |
879 | - if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true)); |
|
878 | + if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content, true)); |
|
880 | 879 | // Take out some UI leavings |
881 | 880 | unset($content['text']); |
882 | 881 | unset($content['step']); |
@@ -886,26 +885,26 @@ discard block |
||
886 | 885 | $bodefinitions->save($content); |
887 | 886 | // This message is displayed if browser cant close window |
888 | 887 | $content['msg'] = lang('ImportExport wizard finished successfully!'); |
889 | - Framework::refresh_opener('','importexport'); |
|
888 | + Framework::refresh_opener('', 'importexport'); |
|
890 | 889 | Framework::window_close(); |
891 | 890 | return 'importexport.wizard_close'; |
892 | 891 | } |
893 | 892 | |
894 | - function import_definition($content='') |
|
893 | + function import_definition($content = '') |
|
895 | 894 | { |
896 | 895 | $bodefinitions = new importexport_definitions_bo(); |
897 | 896 | if (is_array($content)) |
898 | 897 | { |
899 | - if($content['import_file']['tmp_name']) |
|
898 | + if ($content['import_file']['tmp_name']) |
|
900 | 899 | { |
901 | 900 | $result = $bodefinitions->import($content['import_file']['tmp_name']); |
902 | - $msg = lang('%1 definitions %2', count($result), lang('imported')) ."\n". implode("\n", array_keys($result)); |
|
901 | + $msg = lang('%1 definitions %2', count($result), lang('imported'))."\n".implode("\n", array_keys($result)); |
|
903 | 902 | return $this->index(null, $msg); |
904 | 903 | } |
905 | - if($content['update']) |
|
904 | + if ($content['update']) |
|
906 | 905 | { |
907 | 906 | $applist = importexport_helper_functions::get_apps('all', true); |
908 | - foreach($applist as $appname) { |
|
907 | + foreach ($applist as $appname) { |
|
909 | 908 | importexport_helper_functions::load_defaults($appname); |
910 | 909 | } |
911 | 910 | return $this->index(); |
@@ -915,7 +914,7 @@ discard block |
||
915 | 914 | { |
916 | 915 | $content = array(); |
917 | 916 | $etpl = new etemplate(self::_appname.'.import_definition'); |
918 | - return $etpl->exec(self::_appname.'.importexport_definitions_ui.import_definition',$content,array(),$readonlys,$preserv); |
|
917 | + return $etpl->exec(self::_appname.'.importexport_definitions_ui.import_definition', $content, array(), $readonlys, $preserv); |
|
919 | 918 | } |
920 | 919 | } |
921 | 920 | |
@@ -925,17 +924,17 @@ discard block |
||
925 | 924 | */ |
926 | 925 | protected function can_edit(Array $definition) |
927 | 926 | { |
928 | - if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
927 | + if ($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
929 | 928 | { |
930 | 929 | // Definition belongs to user |
931 | 930 | return true; |
932 | 931 | } |
933 | - elseif($definition['definition_id'] && !$definition['owner'] && $GLOBALS['egw_info']['user']['apps']['admin']) |
|
932 | + elseif ($definition['definition_id'] && !$definition['owner'] && $GLOBALS['egw_info']['user']['apps']['admin']) |
|
934 | 933 | { |
935 | 934 | // Definition is unowned, and user is an admin |
936 | 935 | return true; |
937 | 936 | } |
938 | - elseif(!$definition['definition_id']) |
|
937 | + elseif (!$definition['definition_id']) |
|
939 | 938 | { |
940 | 939 | // Definition is in-progress, not saved yet |
941 | 940 | return true; |
@@ -948,26 +947,26 @@ discard block |
||
948 | 947 | */ |
949 | 948 | public function site_config($content = array()) |
950 | 949 | { |
951 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
950 | + if (!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
952 | 951 | { |
953 | 952 | Egw::redirect_link('/home'); |
954 | 953 | } |
955 | - if($content['save']) |
|
954 | + if ($content['save']) |
|
956 | 955 | { |
957 | 956 | unset($content['save']); |
958 | 957 | |
959 | 958 | // ACL |
960 | - $GLOBALS['egw']->acl->delete_repository(self::_appname, 'definition',false); |
|
961 | - $GLOBALS['egw']->acl->delete_repository(self::_appname, 'share_definition',false); |
|
959 | + $GLOBALS['egw']->acl->delete_repository(self::_appname, 'definition', false); |
|
960 | + $GLOBALS['egw']->acl->delete_repository(self::_appname, 'share_definition', false); |
|
962 | 961 | |
963 | - foreach($content['share_definition'] as $group) |
|
962 | + foreach ($content['share_definition'] as $group) |
|
964 | 963 | { |
965 | - $GLOBALS['egw']->acl->add_repository(self::_appname, 'share_definition', $group,Acl::READ); |
|
964 | + $GLOBALS['egw']->acl->add_repository(self::_appname, 'share_definition', $group, Acl::READ); |
|
966 | 965 | } |
967 | 966 | unset($content['share_definition']); |
968 | 967 | |
969 | 968 | // Other Api\Config |
970 | - foreach($content as $key=>$value) |
|
969 | + foreach ($content as $key=>$value) |
|
971 | 970 | { |
972 | 971 | Api\Config::save_value($key, $value, 'importexport'); |
973 | 972 | } |
@@ -977,18 +976,18 @@ discard block |
||
977 | 976 | |
978 | 977 | $data = Api\Config::read(self::_appname); |
979 | 978 | $data['share_definition'] = $GLOBALS['egw']->acl->get_ids_for_location('share_definition', Acl::READ, self::_appname); |
980 | - $sel_options['import_charsets'] = array_combine(mb_list_encodings(),mb_list_encodings()); |
|
979 | + $sel_options['import_charsets'] = array_combine(mb_list_encodings(), mb_list_encodings()); |
|
981 | 980 | |
982 | 981 | // Remove 'standard' encodings to prevent doubles |
983 | - foreach(Api\Translation::get_installed_charsets() as $charset => $label) |
|
982 | + foreach (Api\Translation::get_installed_charsets() as $charset => $label) |
|
984 | 983 | { |
985 | 984 | unset($sel_options['import_charsets'][strtoupper($charset)]); |
986 | 985 | } |
987 | 986 | |
988 | - if(!$data['update']) $data['update'] = 'request'; |
|
987 | + if (!$data['update']) $data['update'] = 'request'; |
|
989 | 988 | |
990 | - $GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration') . ' - ' . lang(self::_appname); |
|
989 | + $GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration').' - '.lang(self::_appname); |
|
991 | 990 | $etpl = new etemplate(self::_appname.'.config'); |
992 | - $etpl->exec(self::_appname.'.importexport_definitions_ui.site_config',$data,$sel_options,$readonlys,$preserv); |
|
991 | + $etpl->exec(self::_appname.'.importexport_definitions_ui.site_config', $data, $sel_options, $readonlys, $preserv); |
|
993 | 992 | } |
994 | 993 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param stram $_stream resource where records are exported to. |
98 | 98 | * @param array _options options for specific backends |
99 | - * @return bool |
|
99 | + * @return boolean|null |
|
100 | 100 | */ |
101 | 101 | public function __construct( $_stream, array $_options ) { |
102 | 102 | if (!is_object($GLOBALS['egw']->translation)) { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * exports a record into resource of handle |
152 | 152 | * |
153 | 153 | * @param importexport_iface_egw_record record |
154 | - * @return bool |
|
154 | + * @return boolean|null |
|
155 | 155 | */ |
156 | 156 | public function export_record( importexport_iface_egw_record $_record ) { |
157 | 157 | $this->record = $_record; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * |
285 | 285 | * Uses the static variable $types to convert various datatypes. |
286 | 286 | * |
287 | - * @param record Record to be converted |
|
287 | + * @param record importexport_iface_egw_record to be converted |
|
288 | 288 | * @parem fields List of field types => field names to be converted |
289 | 289 | * @param appname Current appname if you want to do custom fields too |
290 | 290 | */ |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * @parem fields List of field types => field names to be converted |
289 | 289 | * @param appname Current appname if you want to do custom fields too |
290 | 290 | */ |
291 | - public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
291 | + public static function convert(importexport_iface_egw_record &$record, array $fields = array(), $appname = null, $selects = array()) { |
|
292 | 292 | if($appname) { |
293 | 293 | if(!self::$cf_parse_cache[$appname]) { |
294 | 294 | $c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods); |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | * @param char $delimiter |
453 | 453 | * @param char $enclosure |
454 | 454 | */ |
455 | - protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){ |
|
455 | + protected function fputcsv($filePointer, array $dataArray, $delimiter, $enclosure){ |
|
456 | 456 | $string = ""; |
457 | 457 | $writeDelimiter = false; |
458 | 458 | foreach($dataArray as $dataElement) { |
@@ -98,22 +98,22 @@ discard block |
||
98 | 98 | * @param array _options options for specific backends |
99 | 99 | * @return bool |
100 | 100 | */ |
101 | - public function __construct( $_stream, array $_options ) { |
|
101 | + public function __construct($_stream, array $_options) { |
|
102 | 102 | if (!is_object($GLOBALS['egw']->translation)) { |
103 | 103 | $GLOBALS['egw']->translation = new Api\Translation(); |
104 | 104 | } |
105 | 105 | $this->translation = &$GLOBALS['egw']->translation; |
106 | 106 | $this->handle = $_stream; |
107 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
107 | + if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
108 | 108 | $this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8'; |
109 | - if ( !empty( $_options ) ) { |
|
110 | - $this->csv_options = array_merge( $this->csv_options, $_options ); |
|
109 | + if (!empty($_options)) { |
|
110 | + $this->csv_options = array_merge($this->csv_options, $_options); |
|
111 | 111 | } |
112 | 112 | //error_log(__METHOD__.__LINE__.array2string($_options['appname'])); |
113 | - if(!Api\Storage\Merge::is_export_limit_excepted()) { |
|
113 | + if (!Api\Storage\Merge::is_export_limit_excepted()) { |
|
114 | 114 | $this->export_limit = Api\Storage\Merge::getExportLimit($_options['appname']); |
115 | 115 | //error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit); |
116 | - if($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled'); |
|
116 | + if ($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled'); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param array $_mapping egw_field_name => csv_field_name |
124 | 124 | */ |
125 | - public function set_mapping( array &$_mapping) { |
|
125 | + public function set_mapping(array &$_mapping) { |
|
126 | 126 | if ($this->num_of_records > 0) { |
127 | 127 | throw new Exception('Error: Field mapping can\'t be set during ongoing export!'); |
128 | 128 | } |
129 | - if($_mapping['all_custom_fields']) { |
|
129 | + if ($_mapping['all_custom_fields']) { |
|
130 | 130 | // Field value is the appname, so we can pull the fields |
131 | 131 | $custom = Api\Storage\Customfields::get($_mapping['all_custom_fields']); |
132 | 132 | unset($_mapping['all_custom_fields']); |
133 | - foreach($custom as $field => $info) { |
|
133 | + foreach ($custom as $field => $info) { |
|
134 | 134 | $_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field; |
135 | 135 | } |
136 | 136 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @param array $_conversion |
145 | 145 | */ |
146 | - public function set_conversion( array $_conversion) { |
|
146 | + public function set_conversion(array $_conversion) { |
|
147 | 147 | $this->conversion = $_conversion; |
148 | 148 | } |
149 | 149 | |
@@ -153,59 +153,59 @@ discard block |
||
153 | 153 | * @param importexport_iface_egw_record record |
154 | 154 | * @return bool |
155 | 155 | */ |
156 | - public function export_record( importexport_iface_egw_record $_record ) { |
|
156 | + public function export_record(importexport_iface_egw_record $_record) { |
|
157 | 157 | $this->record = $_record; |
158 | 158 | $this->record_array = $_record->get_record_array(); |
159 | 159 | |
160 | 160 | // begin with fieldnames ? |
161 | - if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) { |
|
162 | - if($this->csv_options['begin_with_fieldnames'] == 'label') { |
|
161 | + if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames']) { |
|
162 | + if ($this->csv_options['begin_with_fieldnames'] == 'label') { |
|
163 | 163 | // Load translations for app |
164 | 164 | list($appname, $part2) = explode('_', get_class($_record)); |
165 | - if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name |
|
165 | + if (!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name |
|
166 | 166 | |
167 | 167 | // Get translations from wizard, if possible |
168 | - if(!$this->csv_options['no_header_translation']) |
|
168 | + if (!$this->csv_options['no_header_translation']) |
|
169 | 169 | { |
170 | 170 | $backtrace = debug_backtrace(); |
171 | 171 | $plugin = $backtrace[1]['class']; |
172 | - $wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin); |
|
172 | + $wizard_name = $appname.'_wizard_'.str_replace($appname.'_', '', $plugin); |
|
173 | 173 | try { |
174 | 174 | $wizard = new $wizard_name; |
175 | 175 | $fields = $wizard->get_export_fields(); |
176 | - foreach($this->mapping as $field => &$label) |
|
176 | + foreach ($this->mapping as $field => &$label) |
|
177 | 177 | { |
178 | - if($fields[$field]) |
|
178 | + if ($fields[$field]) |
|
179 | 179 | { |
180 | 180 | $label = $label != $fields[$field] ? $fields[$field] : lang($label); |
181 | 181 | } |
182 | 182 | // Make sure no * |
183 | - if(substr($label,-1) == '*') $label = substr($label,0,-1); |
|
183 | + if (substr($label, -1) == '*') $label = substr($label, 0, -1); |
|
184 | 184 | } |
185 | 185 | } catch (Exception $e) { |
186 | 186 | Api\Translation::add_app($appname); |
187 | - foreach($this->mapping as $field => &$label) { |
|
187 | + foreach ($this->mapping as $field => &$label) { |
|
188 | 188 | $label = lang($label); |
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
192 | 192 | } |
193 | - $mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record_array ); |
|
194 | - self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] ); |
|
193 | + $mapping = !empty($this->mapping) ? $this->mapping : array_keys($this->record_array); |
|
194 | + self::fputcsv($this->handle, $mapping, $this->csv_options['delimiter'], $this->csv_options['enclosure']); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | // Check for limit |
198 | - if($this->export_limit && $this->num_of_records >= $this->export_limit) { |
|
198 | + if ($this->export_limit && $this->num_of_records >= $this->export_limit) { |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | |
202 | 202 | // do conversions |
203 | - if ( !empty( $this->conversion )) { |
|
204 | - $this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion ); |
|
203 | + if (!empty($this->conversion)) { |
|
204 | + $this->record_array = importexport_helper_functions::conversion($this->record_array, $this->conversion); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | // do fieldmapping |
208 | - if ( !empty( $this->mapping ) ) { |
|
208 | + if (!empty($this->mapping)) { |
|
209 | 209 | $record_data = $this->record_array; |
210 | 210 | $this->record_array = array(); |
211 | 211 | foreach ($this->mapping as $egw_field => $csv_field) { |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] ); |
|
216 | + self::fputcsv($this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure']); |
|
217 | 217 | $this->num_of_records++; |
218 | 218 | } |
219 | 219 | |
@@ -237,13 +237,13 @@ discard block |
||
237 | 237 | * @return Array of fields to be added to list of fields needing conversion |
238 | 238 | */ |
239 | 239 | public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) { |
240 | - if(!$appname) return; |
|
240 | + if (!$appname) return; |
|
241 | 241 | |
242 | 242 | $fields = array(); |
243 | 243 | $custom = Api\Storage\Customfields::get($appname); |
244 | - foreach($custom as $name => $c_field) { |
|
245 | - $name = '#' . $name; |
|
246 | - switch($c_field['type']) { |
|
244 | + foreach ($custom as $name => $c_field) { |
|
245 | + $name = '#'.$name; |
|
246 | + switch ($c_field['type']) { |
|
247 | 247 | case 'date': |
248 | 248 | $fields['date'][] = $name; |
249 | 249 | break; |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $fields['select-account'][] = $name; |
255 | 255 | break; |
256 | 256 | case 'ajax_select': |
257 | - if($c_field['values']['get_title']) { |
|
257 | + if ($c_field['values']['get_title']) { |
|
258 | 258 | $methods[$name] = $c_field['values']['get_title']; |
259 | 259 | break; |
260 | 260 | } |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | $selects[$name] = $c_field['values']; |
269 | 269 | break; |
270 | 270 | default: |
271 | - list($type) = explode('-',$c_field['type'],2); |
|
272 | - if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) { |
|
271 | + list($type) = explode('-', $c_field['type'], 2); |
|
272 | + if (in_array($type, array_keys($GLOBALS['egw_info']['apps']))) { |
|
273 | 273 | $fields['links'][] = $name; |
274 | 274 | $links[$name] = $c_field['type']; |
275 | 275 | } |
@@ -288,18 +288,18 @@ discard block |
||
288 | 288 | * @parem fields List of field types => field names to be converted |
289 | 289 | * @param appname Current appname if you want to do custom fields too |
290 | 290 | */ |
291 | - public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
292 | - if($appname) { |
|
293 | - if(!self::$cf_parse_cache[$appname]) { |
|
291 | + public static function convert(importexport_iface_egw_record&$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
292 | + if ($appname) { |
|
293 | + if (!self::$cf_parse_cache[$appname]) { |
|
294 | 294 | $c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods); |
295 | 295 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
296 | 296 | } |
297 | 297 | list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname]; |
298 | 298 | |
299 | 299 | // Add in any fields that are keys to another app |
300 | - foreach((array)$fields['links'] as $link_field => $app) |
|
300 | + foreach ((array)$fields['links'] as $link_field => $app) |
|
301 | 301 | { |
302 | - if(is_numeric($link_field)) continue; |
|
302 | + if (is_numeric($link_field)) continue; |
|
303 | 303 | $links[$link_field] = $app; |
304 | 304 | // Set it as a normal link field |
305 | 305 | $fields['links'][] = $link_field; |
@@ -307,8 +307,8 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | // Not quite a recursive merge, since only one level |
310 | - foreach($fields as $type => &$list) { |
|
311 | - if($c_fields[$type]) { |
|
310 | + foreach ($fields as $type => &$list) { |
|
311 | + if ($c_fields[$type]) { |
|
312 | 312 | $list = array_merge($c_fields[$type], $list); |
313 | 313 | unset($c_fields[$type]); |
314 | 314 | } |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | $fields += $c_fields; |
317 | 317 | $selects += $c_selects; |
318 | 318 | } |
319 | - foreach((array)$fields['select'] as $name) { |
|
320 | - if($record->$name != null && is_array($selects) && $selects[$name]) { |
|
319 | + foreach ((array)$fields['select'] as $name) { |
|
320 | + if ($record->$name != null && is_array($selects) && $selects[$name]) { |
|
321 | 321 | $record->$name = explode(',', $record->$name); |
322 | - if(is_array($record->$name)) { |
|
322 | + if (is_array($record->$name)) { |
|
323 | 323 | $names = array(); |
324 | - foreach($record->$name as $_name) { |
|
324 | + foreach ($record->$name as $_name) { |
|
325 | 325 | $names[] = lang($selects[$name][$_name]); |
326 | 326 | } |
327 | 327 | $record->$name = implode(', ', $names); |
@@ -334,18 +334,18 @@ discard block |
||
334 | 334 | $record->$name = ''; |
335 | 335 | } |
336 | 336 | } |
337 | - foreach((array)$fields['links'] as $name) { |
|
338 | - if($record->$name) { |
|
339 | - if(is_numeric($record->$name) && !$links[$name]) { |
|
337 | + foreach ((array)$fields['links'] as $name) { |
|
338 | + if ($record->$name) { |
|
339 | + if (is_numeric($record->$name) && !$links[$name]) { |
|
340 | 340 | $link = Link::get_link($record->$name); |
341 | 341 | $links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']); |
342 | 342 | $record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']); |
343 | 343 | } |
344 | - if($links[$name]) |
|
344 | + if ($links[$name]) |
|
345 | 345 | { |
346 | 346 | $record->$name = Link::title($links[$name], $record->$name); |
347 | 347 | } |
348 | - else if ( is_array($record->$name) && $record->$name['app'] && $record->$name['id']) |
|
348 | + else if (is_array($record->$name) && $record->$name['app'] && $record->$name['id']) |
|
349 | 349 | { |
350 | 350 | $record->$name = Link::title($record->$name['app'], $record->$name['id']); |
351 | 351 | } |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | $record->$name = ''; |
356 | 356 | } |
357 | 357 | } |
358 | - foreach((array)$fields['select-account'] as $name) { |
|
358 | + foreach ((array)$fields['select-account'] as $name) { |
|
359 | 359 | // Compare against null to deal with empty arrays |
360 | 360 | if ($record->$name !== null) { |
361 | - if(is_array($record->$name)) { |
|
361 | + if (is_array($record->$name)) { |
|
362 | 362 | $names = array(); |
363 | - foreach($record->$name as $_name) { |
|
363 | + foreach ($record->$name as $_name) { |
|
364 | 364 | $names[] = Api\Accounts::username($_name); |
365 | 365 | } |
366 | 366 | $record->$name = implode(', ', $names); |
@@ -373,64 +373,64 @@ discard block |
||
373 | 373 | $record->$name = ''; |
374 | 374 | } |
375 | 375 | } |
376 | - foreach((array)$fields['select-bool'] as $name) { |
|
377 | - if($record->$name !== null) { |
|
376 | + foreach ((array)$fields['select-bool'] as $name) { |
|
377 | + if ($record->$name !== null) { |
|
378 | 378 | $record->$name = $record->$name ? lang('Yes') : lang('No'); |
379 | 379 | } |
380 | 380 | } |
381 | - foreach((array)$fields['date-time'] as $name) { |
|
381 | + foreach ((array)$fields['date-time'] as $name) { |
|
382 | 382 | //if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format |
383 | 383 | if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
384 | - if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. |
|
385 | - ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format |
|
384 | + if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '. |
|
385 | + ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'), $record->$name); // User date format |
|
386 | 386 | if (!$record->$name) $record->$name = ''; |
387 | 387 | } |
388 | - foreach((array)$fields['date'] as $name) { |
|
388 | + foreach ((array)$fields['date'] as $name) { |
|
389 | 389 | //if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format |
390 | 390 | if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
391 | 391 | if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format |
392 | 392 | if (!$record->$name) $record->$name = ''; |
393 | 393 | } |
394 | - foreach((array)$fields['float'] as $name) |
|
394 | + foreach ((array)$fields['float'] as $name) |
|
395 | 395 | { |
396 | - static $dec_separator,$thousands_separator; |
|
396 | + static $dec_separator, $thousands_separator; |
|
397 | 397 | if (is_null($dec_separator)) |
398 | 398 | { |
399 | 399 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
400 | 400 | if (empty($dec_separator)) $dec_separator = '.'; |
401 | 401 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
402 | 402 | } |
403 | - if($record->$name && (string)$record->$name != '') |
|
403 | + if ($record->$name && (string)$record->$name != '') |
|
404 | 404 | { |
405 | - if(!is_numeric($record->$name)) |
|
405 | + if (!is_numeric($record->$name)) |
|
406 | 406 | { |
407 | 407 | $record->$name = floatval(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator).']/', '', $record->$name))); |
408 | 408 | } |
409 | - $record->$name = number_format(str_replace(' ','',$record->$name), 2, |
|
410 | - $dec_separator,$thousands_separator |
|
409 | + $record->$name = number_format(str_replace(' ', '', $record->$name), 2, |
|
410 | + $dec_separator, $thousands_separator |
|
411 | 411 | ); |
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | 415 | // Some custom methods for conversion |
416 | - foreach((array)$methods as $name => $method) { |
|
417 | - if($record->$name) $record->$name = ExecMethod($method, $record->$name); |
|
416 | + foreach ((array)$methods as $name => $method) { |
|
417 | + if ($record->$name) $record->$name = ExecMethod($method, $record->$name); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | static $cat_object; |
421 | - if(is_null($cat_object)) $cat_object = new Api\Categories(false,$appname); |
|
422 | - foreach((array)$fields['select-cat'] as $name) { |
|
423 | - if($record->$name) { |
|
421 | + if (is_null($cat_object)) $cat_object = new Api\Categories(false, $appname); |
|
422 | + foreach ((array)$fields['select-cat'] as $name) { |
|
423 | + if ($record->$name) { |
|
424 | 424 | $cats = array(); |
425 | 425 | $ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name); |
426 | - foreach($ids as $n => $cat_id) { |
|
426 | + foreach ($ids as $n => $cat_id) { |
|
427 | 427 | |
428 | - if ($cat_id && $cat_object->check_perms(Acl::READ,$cat_id)) |
|
428 | + if ($cat_id && $cat_object->check_perms(Acl::READ, $cat_id)) |
|
429 | 429 | { |
430 | 430 | $cats[] = $cat_object->id2name($cat_id); |
431 | 431 | } |
432 | 432 | } |
433 | - $record->$name = implode(', ',$cats); |
|
433 | + $record->$name = implode(', ', $cats); |
|
434 | 434 | } |
435 | 435 | else |
436 | 436 | { |
@@ -457,18 +457,18 @@ discard block |
||
457 | 457 | * @param char $delimiter |
458 | 458 | * @param char $enclosure |
459 | 459 | */ |
460 | - protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){ |
|
460 | + protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) { |
|
461 | 461 | $string = ""; |
462 | 462 | $writeDelimiter = false; |
463 | - foreach($dataArray as $dataElement) { |
|
464 | - if($writeDelimiter) $string .= $delimiter; |
|
465 | - $string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure; |
|
463 | + foreach ($dataArray as $dataElement) { |
|
464 | + if ($writeDelimiter) $string .= $delimiter; |
|
465 | + $string .= $enclosure.str_replace(array("\r\n", '"'), array("\n", '""'), $dataElement).$enclosure; |
|
466 | 466 | $writeDelimiter = true; |
467 | 467 | } |
468 | 468 | $string .= "\n"; |
469 | 469 | |
470 | 470 | // do charset translation |
471 | - $string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset ); |
|
471 | + $string = $this->translation->convert($string, $this->translation->charset(), $this->csv_charset); |
|
472 | 472 | |
473 | 473 | fwrite($filePointer, $string); |
474 | 474 |
@@ -98,22 +98,32 @@ discard block |
||
98 | 98 | * @param array _options options for specific backends |
99 | 99 | * @return bool |
100 | 100 | */ |
101 | - public function __construct( $_stream, array $_options ) { |
|
102 | - if (!is_object($GLOBALS['egw']->translation)) { |
|
101 | + public function __construct( $_stream, array $_options ) |
|
102 | + { |
|
103 | + if (!is_object($GLOBALS['egw']->translation)) |
|
104 | + { |
|
103 | 105 | $GLOBALS['egw']->translation = new Api\Translation(); |
104 | 106 | } |
105 | 107 | $this->translation = &$GLOBALS['egw']->translation; |
106 | 108 | $this->handle = $_stream; |
107 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
109 | + if($_options['charset'] == 'user') |
|
110 | + { |
|
111 | + $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
112 | + } |
|
108 | 113 | $this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8'; |
109 | - if ( !empty( $_options ) ) { |
|
114 | + if ( !empty( $_options ) ) |
|
115 | + { |
|
110 | 116 | $this->csv_options = array_merge( $this->csv_options, $_options ); |
111 | 117 | } |
112 | 118 | //error_log(__METHOD__.__LINE__.array2string($_options['appname'])); |
113 | - if(!Api\Storage\Merge::is_export_limit_excepted()) { |
|
119 | + if(!Api\Storage\Merge::is_export_limit_excepted()) |
|
120 | + { |
|
114 | 121 | $this->export_limit = Api\Storage\Merge::getExportLimit($_options['appname']); |
115 | 122 | //error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit); |
116 | - if($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled'); |
|
123 | + if($this->export_limit == 'no') |
|
124 | + { |
|
125 | + throw new Api\Exception\NoPermission\Admin('Export disabled'); |
|
126 | + } |
|
117 | 127 | } |
118 | 128 | } |
119 | 129 | |
@@ -122,15 +132,19 @@ discard block |
||
122 | 132 | * |
123 | 133 | * @param array $_mapping egw_field_name => csv_field_name |
124 | 134 | */ |
125 | - public function set_mapping( array &$_mapping) { |
|
126 | - if ($this->num_of_records > 0) { |
|
135 | + public function set_mapping( array &$_mapping) |
|
136 | + { |
|
137 | + if ($this->num_of_records > 0) |
|
138 | + { |
|
127 | 139 | throw new Exception('Error: Field mapping can\'t be set during ongoing export!'); |
128 | 140 | } |
129 | - if($_mapping['all_custom_fields']) { |
|
141 | + if($_mapping['all_custom_fields']) |
|
142 | + { |
|
130 | 143 | // Field value is the appname, so we can pull the fields |
131 | 144 | $custom = Api\Storage\Customfields::get($_mapping['all_custom_fields']); |
132 | 145 | unset($_mapping['all_custom_fields']); |
133 | - foreach($custom as $field => $info) { |
|
146 | + foreach($custom as $field => $info) |
|
147 | + { |
|
134 | 148 | $_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field; |
135 | 149 | } |
136 | 150 | } |
@@ -143,7 +157,8 @@ discard block |
||
143 | 157 | * |
144 | 158 | * @param array $_conversion |
145 | 159 | */ |
146 | - public function set_conversion( array $_conversion) { |
|
160 | + public function set_conversion( array $_conversion) |
|
161 | + { |
|
147 | 162 | $this->conversion = $_conversion; |
148 | 163 | } |
149 | 164 | |
@@ -153,16 +168,23 @@ discard block |
||
153 | 168 | * @param importexport_iface_egw_record record |
154 | 169 | * @return bool |
155 | 170 | */ |
156 | - public function export_record( importexport_iface_egw_record $_record ) { |
|
171 | + public function export_record( importexport_iface_egw_record $_record ) |
|
172 | + { |
|
157 | 173 | $this->record = $_record; |
158 | 174 | $this->record_array = $_record->get_record_array(); |
159 | 175 | |
160 | 176 | // begin with fieldnames ? |
161 | - if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) { |
|
162 | - if($this->csv_options['begin_with_fieldnames'] == 'label') { |
|
177 | + if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) |
|
178 | + { |
|
179 | + if($this->csv_options['begin_with_fieldnames'] == 'label') |
|
180 | + { |
|
163 | 181 | // Load translations for app |
164 | 182 | list($appname, $part2) = explode('_', get_class($_record)); |
165 | - if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name |
|
183 | + if(!$GLOBALS['egw_info']['apps'][$appname]) |
|
184 | + { |
|
185 | + $appname .= $part2; |
|
186 | + } |
|
187 | + // Handle apps with _ in the name |
|
166 | 188 | |
167 | 189 | // Get translations from wizard, if possible |
168 | 190 | if(!$this->csv_options['no_header_translation']) |
@@ -180,11 +202,16 @@ discard block |
||
180 | 202 | $label = $label != $fields[$field] ? $fields[$field] : lang($label); |
181 | 203 | } |
182 | 204 | // Make sure no * |
183 | - if(substr($label,-1) == '*') $label = substr($label,0,-1); |
|
205 | + if(substr($label,-1) == '*') |
|
206 | + { |
|
207 | + $label = substr($label,0,-1); |
|
208 | + } |
|
184 | 209 | } |
185 | - } catch (Exception $e) { |
|
210 | + } |
|
211 | + catch (Exception $e) { |
|
186 | 212 | Api\Translation::add_app($appname); |
187 | - foreach($this->mapping as $field => &$label) { |
|
213 | + foreach($this->mapping as $field => &$label) |
|
214 | + { |
|
188 | 215 | $label = lang($label); |
189 | 216 | } |
190 | 217 | } |
@@ -195,20 +222,24 @@ discard block |
||
195 | 222 | } |
196 | 223 | |
197 | 224 | // Check for limit |
198 | - if($this->export_limit && $this->num_of_records >= $this->export_limit) { |
|
225 | + if($this->export_limit && $this->num_of_records >= $this->export_limit) |
|
226 | + { |
|
199 | 227 | return; |
200 | 228 | } |
201 | 229 | |
202 | 230 | // do conversions |
203 | - if ( !empty( $this->conversion )) { |
|
231 | + if ( !empty( $this->conversion )) |
|
232 | + { |
|
204 | 233 | $this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion ); |
205 | 234 | } |
206 | 235 | |
207 | 236 | // do fieldmapping |
208 | - if ( !empty( $this->mapping ) ) { |
|
237 | + if ( !empty( $this->mapping ) ) |
|
238 | + { |
|
209 | 239 | $record_data = $this->record_array; |
210 | 240 | $this->record_array = array(); |
211 | - foreach ($this->mapping as $egw_field => $csv_field) { |
|
241 | + foreach ($this->mapping as $egw_field => $csv_field) |
|
242 | + { |
|
212 | 243 | $this->record_array[$csv_field] = $record_data[$egw_field]; |
213 | 244 | } |
214 | 245 | } |
@@ -222,7 +253,8 @@ discard block |
||
222 | 253 | * |
223 | 254 | * @return int |
224 | 255 | */ |
225 | - public function get_num_of_records() { |
|
256 | + public function get_num_of_records() |
|
257 | + { |
|
226 | 258 | return $this->num_of_records; |
227 | 259 | } |
228 | 260 | |
@@ -236,14 +268,20 @@ discard block |
||
236 | 268 | * |
237 | 269 | * @return Array of fields to be added to list of fields needing conversion |
238 | 270 | */ |
239 | - public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) { |
|
240 | - if(!$appname) return; |
|
271 | + public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) |
|
272 | + { |
|
273 | + if(!$appname) |
|
274 | + { |
|
275 | + return; |
|
276 | + } |
|
241 | 277 | |
242 | 278 | $fields = array(); |
243 | 279 | $custom = Api\Storage\Customfields::get($appname); |
244 | - foreach($custom as $name => $c_field) { |
|
280 | + foreach($custom as $name => $c_field) |
|
281 | + { |
|
245 | 282 | $name = '#' . $name; |
246 | - switch($c_field['type']) { |
|
283 | + switch($c_field['type']) |
|
284 | + { |
|
247 | 285 | case 'date': |
248 | 286 | $fields['date'][] = $name; |
249 | 287 | break; |
@@ -254,7 +292,8 @@ discard block |
||
254 | 292 | $fields['select-account'][] = $name; |
255 | 293 | break; |
256 | 294 | case 'ajax_select': |
257 | - if($c_field['values']['get_title']) { |
|
295 | + if($c_field['values']['get_title']) |
|
296 | + { |
|
258 | 297 | $methods[$name] = $c_field['values']['get_title']; |
259 | 298 | break; |
260 | 299 | } |
@@ -269,7 +308,8 @@ discard block |
||
269 | 308 | break; |
270 | 309 | default: |
271 | 310 | list($type) = explode('-',$c_field['type'],2); |
272 | - if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) { |
|
311 | + if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) |
|
312 | + { |
|
273 | 313 | $fields['links'][] = $name; |
274 | 314 | $links[$name] = $c_field['type']; |
275 | 315 | } |
@@ -288,9 +328,12 @@ discard block |
||
288 | 328 | * @parem fields List of field types => field names to be converted |
289 | 329 | * @param appname Current appname if you want to do custom fields too |
290 | 330 | */ |
291 | - public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
292 | - if($appname) { |
|
293 | - if(!self::$cf_parse_cache[$appname]) { |
|
331 | + public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) |
|
332 | + { |
|
333 | + if($appname) |
|
334 | + { |
|
335 | + if(!self::$cf_parse_cache[$appname]) |
|
336 | + { |
|
294 | 337 | $c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods); |
295 | 338 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
296 | 339 | } |
@@ -299,7 +342,10 @@ discard block |
||
299 | 342 | // Add in any fields that are keys to another app |
300 | 343 | foreach((array)$fields['links'] as $link_field => $app) |
301 | 344 | { |
302 | - if(is_numeric($link_field)) continue; |
|
345 | + if(is_numeric($link_field)) |
|
346 | + { |
|
347 | + continue; |
|
348 | + } |
|
303 | 349 | $links[$link_field] = $app; |
304 | 350 | // Set it as a normal link field |
305 | 351 | $fields['links'][] = $link_field; |
@@ -307,8 +353,10 @@ discard block |
||
307 | 353 | } |
308 | 354 | |
309 | 355 | // Not quite a recursive merge, since only one level |
310 | - foreach($fields as $type => &$list) { |
|
311 | - if($c_fields[$type]) { |
|
356 | + foreach($fields as $type => &$list) |
|
357 | + { |
|
358 | + if($c_fields[$type]) |
|
359 | + { |
|
312 | 360 | $list = array_merge($c_fields[$type], $list); |
313 | 361 | unset($c_fields[$type]); |
314 | 362 | } |
@@ -316,16 +364,22 @@ discard block |
||
316 | 364 | $fields += $c_fields; |
317 | 365 | $selects += $c_selects; |
318 | 366 | } |
319 | - foreach((array)$fields['select'] as $name) { |
|
320 | - if($record->$name != null && is_array($selects) && $selects[$name]) { |
|
367 | + foreach((array)$fields['select'] as $name) |
|
368 | + { |
|
369 | + if($record->$name != null && is_array($selects) && $selects[$name]) |
|
370 | + { |
|
321 | 371 | $record->$name = explode(',', $record->$name); |
322 | - if(is_array($record->$name)) { |
|
372 | + if(is_array($record->$name)) |
|
373 | + { |
|
323 | 374 | $names = array(); |
324 | - foreach($record->$name as $_name) { |
|
375 | + foreach($record->$name as $_name) |
|
376 | + { |
|
325 | 377 | $names[] = lang($selects[$name][$_name]); |
326 | 378 | } |
327 | 379 | $record->$name = implode(', ', $names); |
328 | - } else { |
|
380 | + } |
|
381 | + else |
|
382 | + { |
|
329 | 383 | $record->$name = lang($selects[$name][$record->$name]); |
330 | 384 | } |
331 | 385 | } |
@@ -334,9 +388,12 @@ discard block |
||
334 | 388 | $record->$name = ''; |
335 | 389 | } |
336 | 390 | } |
337 | - foreach((array)$fields['links'] as $name) { |
|
338 | - if($record->$name) { |
|
339 | - if(is_numeric($record->$name) && !$links[$name]) { |
|
391 | + foreach((array)$fields['links'] as $name) |
|
392 | + { |
|
393 | + if($record->$name) |
|
394 | + { |
|
395 | + if(is_numeric($record->$name) && !$links[$name]) |
|
396 | + { |
|
340 | 397 | $link = Link::get_link($record->$name); |
341 | 398 | $links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']); |
342 | 399 | $record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']); |
@@ -355,16 +412,22 @@ discard block |
||
355 | 412 | $record->$name = ''; |
356 | 413 | } |
357 | 414 | } |
358 | - foreach((array)$fields['select-account'] as $name) { |
|
415 | + foreach((array)$fields['select-account'] as $name) |
|
416 | + { |
|
359 | 417 | // Compare against null to deal with empty arrays |
360 | - if ($record->$name !== null) { |
|
361 | - if(is_array($record->$name)) { |
|
418 | + if ($record->$name !== null) |
|
419 | + { |
|
420 | + if(is_array($record->$name)) |
|
421 | + { |
|
362 | 422 | $names = array(); |
363 | - foreach($record->$name as $_name) { |
|
423 | + foreach($record->$name as $_name) |
|
424 | + { |
|
364 | 425 | $names[] = Api\Accounts::username($_name); |
365 | 426 | } |
366 | 427 | $record->$name = implode(', ', $names); |
367 | - } else { |
|
428 | + } |
|
429 | + else |
|
430 | + { |
|
368 | 431 | $record->$name = Api\Accounts::username($record->$name); |
369 | 432 | } |
370 | 433 | } |
@@ -373,23 +436,49 @@ discard block |
||
373 | 436 | $record->$name = ''; |
374 | 437 | } |
375 | 438 | } |
376 | - foreach((array)$fields['select-bool'] as $name) { |
|
377 | - if($record->$name !== null) { |
|
439 | + foreach((array)$fields['select-bool'] as $name) |
|
440 | + { |
|
441 | + if($record->$name !== null) |
|
442 | + { |
|
378 | 443 | $record->$name = $record->$name ? lang('Yes') : lang('No'); |
379 | 444 | } |
380 | 445 | } |
381 | - foreach((array)$fields['date-time'] as $name) { |
|
446 | + foreach((array)$fields['date-time'] as $name) |
|
447 | + { |
|
382 | 448 | //if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format |
383 | - if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
|
384 | - if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. |
|
385 | - ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format |
|
386 | - if (!$record->$name) $record->$name = ''; |
|
449 | + if ($record->$name && !is_numeric($record->$name)) |
|
450 | + { |
|
451 | + $record->$name = strtotime($record->$name); |
|
452 | + } |
|
453 | + // Custom fields stored as string |
|
454 | + if ($record->$name && is_numeric($record->$name)) |
|
455 | + { |
|
456 | + $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. |
|
457 | + ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); |
|
458 | + } |
|
459 | + // User date format |
|
460 | + if (!$record->$name) |
|
461 | + { |
|
462 | + $record->$name = ''; |
|
463 | + } |
|
387 | 464 | } |
388 | - foreach((array)$fields['date'] as $name) { |
|
465 | + foreach((array)$fields['date'] as $name) |
|
466 | + { |
|
389 | 467 | //if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format |
390 | - if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
|
391 | - if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format |
|
392 | - if (!$record->$name) $record->$name = ''; |
|
468 | + if ($record->$name && !is_numeric($record->$name)) |
|
469 | + { |
|
470 | + $record->$name = strtotime($record->$name); |
|
471 | + } |
|
472 | + // Custom fields stored as string |
|
473 | + if ($record->$name && is_numeric($record->$name)) |
|
474 | + { |
|
475 | + $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); |
|
476 | + } |
|
477 | + // User date format |
|
478 | + if (!$record->$name) |
|
479 | + { |
|
480 | + $record->$name = ''; |
|
481 | + } |
|
393 | 482 | } |
394 | 483 | foreach((array)$fields['float'] as $name) |
395 | 484 | { |
@@ -397,7 +486,10 @@ discard block |
||
397 | 486 | if (is_null($dec_separator)) |
398 | 487 | { |
399 | 488 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
400 | - if (empty($dec_separator)) $dec_separator = '.'; |
|
489 | + if (empty($dec_separator)) |
|
490 | + { |
|
491 | + $dec_separator = '.'; |
|
492 | + } |
|
401 | 493 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
402 | 494 | } |
403 | 495 | if($record->$name && (string)$record->$name != '') |
@@ -413,17 +505,27 @@ discard block |
||
413 | 505 | } |
414 | 506 | |
415 | 507 | // Some custom methods for conversion |
416 | - foreach((array)$methods as $name => $method) { |
|
417 | - if($record->$name) $record->$name = ExecMethod($method, $record->$name); |
|
508 | + foreach((array)$methods as $name => $method) |
|
509 | + { |
|
510 | + if($record->$name) |
|
511 | + { |
|
512 | + $record->$name = ExecMethod($method, $record->$name); |
|
513 | + } |
|
418 | 514 | } |
419 | 515 | |
420 | 516 | static $cat_object; |
421 | - if(is_null($cat_object)) $cat_object = new Api\Categories(false,$appname); |
|
422 | - foreach((array)$fields['select-cat'] as $name) { |
|
423 | - if($record->$name) { |
|
517 | + if(is_null($cat_object)) |
|
518 | + { |
|
519 | + $cat_object = new Api\Categories(false,$appname); |
|
520 | + } |
|
521 | + foreach((array)$fields['select-cat'] as $name) |
|
522 | + { |
|
523 | + if($record->$name) |
|
524 | + { |
|
424 | 525 | $cats = array(); |
425 | 526 | $ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name); |
426 | - foreach($ids as $n => $cat_id) { |
|
527 | + foreach($ids as $n => $cat_id) |
|
528 | + { |
|
427 | 529 | |
428 | 530 | if ($cat_id && $cat_object->check_perms(Acl::READ,$cat_id)) |
429 | 531 | { |
@@ -444,7 +546,8 @@ discard block |
||
444 | 546 | * |
445 | 547 | * @return |
446 | 548 | */ |
447 | - public function __destruct() { |
|
549 | + public function __destruct() |
|
550 | + { |
|
448 | 551 | |
449 | 552 | } |
450 | 553 | |
@@ -457,11 +560,16 @@ discard block |
||
457 | 560 | * @param char $delimiter |
458 | 561 | * @param char $enclosure |
459 | 562 | */ |
460 | - protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){ |
|
563 | + protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) |
|
564 | + { |
|
461 | 565 | $string = ""; |
462 | 566 | $writeDelimiter = false; |
463 | - foreach($dataArray as $dataElement) { |
|
464 | - if($writeDelimiter) $string .= $delimiter; |
|
567 | + foreach($dataArray as $dataElement) |
|
568 | + { |
|
569 | + if($writeDelimiter) |
|
570 | + { |
|
571 | + $string .= $delimiter; |
|
572 | + } |
|
465 | 573 | $string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure; |
466 | 574 | $writeDelimiter = true; |
467 | 575 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | /** |
124 | 124 | * converts accound_lid to account_id |
125 | 125 | * |
126 | - * @param mixed $_account_lid comma seperated list or array with lids |
|
126 | + * @param mixed $_account_lids comma seperated list or array with lids |
|
127 | 127 | * @return mixed comma seperated list or array with ids |
128 | 128 | */ |
129 | 129 | public static function account_name2id( &$_account_lids ) { |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | /** |
204 | 204 | * converts account_ids to account_lids |
205 | 205 | * |
206 | - * @param mixed $_account_ids comma seperated list or array with ids |
|
206 | + * @param mixed $_account_id comma seperated list or array with ids |
|
207 | 207 | * @return mixed comma seperated list or array with lids |
208 | 208 | */ |
209 | 209 | public static function account_id2name( $_account_id ) { |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | /** |
420 | 420 | * returns a list of importexport plugins |
421 | 421 | * |
422 | - * @param string $_tpye {import | export | all} |
|
422 | + * @param string $_type {import | export | all} |
|
423 | 423 | * @param string $_appname {<appname> | all} |
424 | 424 | * @return array(<appname> => array( <type> => array(<plugin> => <title>))) |
425 | 425 | */ |
@@ -591,6 +591,7 @@ discard block |
||
591 | 591 | * |
592 | 592 | * @param $app_name String name of app |
593 | 593 | * @param $plugin_name Name of the plugin |
594 | + * @param importexport_wizard_basic_export_csv $wizard_plugin |
|
594 | 595 | * |
595 | 596 | * @return Array ([fieldname] => array(widget settings), ...) |
596 | 597 | */ |
@@ -32,25 +32,25 @@ discard block |
||
32 | 32 | * Relative date ranges for filtering |
33 | 33 | */ |
34 | 34 | public static $relative_dates = array( // Start: year,month,day,week, End: year,month,day,week |
35 | - 'Today' => array(0,0,0,0, 0,0,1,0), |
|
36 | - 'Yesterday' => array(0,0,-1,0, 0,0,0,0), |
|
37 | - 'This week' => array(0,0,0,0, 0,0,0,1), |
|
38 | - 'Last week' => array(0,0,0,-1, 0,0,0,0), |
|
39 | - 'This month' => array(0,0,0,0, 0,1,0,0), |
|
40 | - 'Last month' => array(0,-1,0,0, 0,0,0,0), |
|
41 | - 'Last 3 months' => array(0,-3,0,0, 0,0,0,0), |
|
42 | - 'This quarter'=> array(0,0,0,0, 0,0,0,0), // Just a marker, needs special handling |
|
43 | - 'Last quarter'=> array(0,-4,0,0, 0,-4,0,0), // Just a marker |
|
44 | - 'This year' => array(0,0,0,0, 1,0,0,0), |
|
45 | - 'Last year' => array(-1,0,0,0, 0,0,0,0), |
|
46 | - '2 years ago' => array(-2,0,0,0, -1,0,0,0), |
|
47 | - '3 years ago' => array(-3,0,0,0, -2,0,0,0), |
|
48 | - ); |
|
35 | + 'Today' => array(0,0,0,0, 0,0,1,0), |
|
36 | + 'Yesterday' => array(0,0,-1,0, 0,0,0,0), |
|
37 | + 'This week' => array(0,0,0,0, 0,0,0,1), |
|
38 | + 'Last week' => array(0,0,0,-1, 0,0,0,0), |
|
39 | + 'This month' => array(0,0,0,0, 0,1,0,0), |
|
40 | + 'Last month' => array(0,-1,0,0, 0,0,0,0), |
|
41 | + 'Last 3 months' => array(0,-3,0,0, 0,0,0,0), |
|
42 | + 'This quarter'=> array(0,0,0,0, 0,0,0,0), // Just a marker, needs special handling |
|
43 | + 'Last quarter'=> array(0,-4,0,0, 0,-4,0,0), // Just a marker |
|
44 | + 'This year' => array(0,0,0,0, 1,0,0,0), |
|
45 | + 'Last year' => array(-1,0,0,0, 0,0,0,0), |
|
46 | + '2 years ago' => array(-2,0,0,0, -1,0,0,0), |
|
47 | + '3 years ago' => array(-3,0,0,0, -2,0,0,0), |
|
48 | + ); |
|
49 | 49 | |
50 | 50 | /** |
51 | - * Files known to cause problems, and will be skipped in a plugin scan |
|
52 | - * If you put appname => true, the whole app will be skipped. |
|
53 | - */ |
|
51 | + * Files known to cause problems, and will be skipped in a plugin scan |
|
52 | + * If you put appname => true, the whole app will be skipped. |
|
53 | + */ |
|
54 | 54 | protected static $blacklist_files = array( |
55 | 55 | 'api' => true, |
56 | 56 | 'etemplate' => true, |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | ); |
65 | 65 | |
66 | 66 | /** |
67 | - * Class used to provide extra conversion functions |
|
68 | - * |
|
69 | - * Passed in as a param to conversion() |
|
70 | - */ |
|
67 | + * Class used to provide extra conversion functions |
|
68 | + * |
|
69 | + * Passed in as a param to conversion() |
|
70 | + */ |
|
71 | 71 | protected static $cclass = null; |
72 | 72 | |
73 | 73 | /** |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | * Relative date ranges for filtering |
33 | 33 | */ |
34 | 34 | public static $relative_dates = array( // Start: year,month,day,week, End: year,month,day,week |
35 | - 'Today' => array(0,0,0,0, 0,0,1,0), |
|
36 | - 'Yesterday' => array(0,0,-1,0, 0,0,0,0), |
|
37 | - 'This week' => array(0,0,0,0, 0,0,0,1), |
|
38 | - 'Last week' => array(0,0,0,-1, 0,0,0,0), |
|
39 | - 'This month' => array(0,0,0,0, 0,1,0,0), |
|
40 | - 'Last month' => array(0,-1,0,0, 0,0,0,0), |
|
41 | - 'Last 3 months' => array(0,-3,0,0, 0,0,0,0), |
|
42 | - 'This quarter'=> array(0,0,0,0, 0,0,0,0), // Just a marker, needs special handling |
|
43 | - 'Last quarter'=> array(0,-4,0,0, 0,-4,0,0), // Just a marker |
|
44 | - 'This year' => array(0,0,0,0, 1,0,0,0), |
|
45 | - 'Last year' => array(-1,0,0,0, 0,0,0,0), |
|
46 | - '2 years ago' => array(-2,0,0,0, -1,0,0,0), |
|
47 | - '3 years ago' => array(-3,0,0,0, -2,0,0,0), |
|
35 | + 'Today' => array(0, 0, 0, 0, 0, 0, 1, 0), |
|
36 | + 'Yesterday' => array(0, 0, -1, 0, 0, 0, 0, 0), |
|
37 | + 'This week' => array(0, 0, 0, 0, 0, 0, 0, 1), |
|
38 | + 'Last week' => array(0, 0, 0, -1, 0, 0, 0, 0), |
|
39 | + 'This month' => array(0, 0, 0, 0, 0, 1, 0, 0), |
|
40 | + 'Last month' => array(0, -1, 0, 0, 0, 0, 0, 0), |
|
41 | + 'Last 3 months' => array(0, -3, 0, 0, 0, 0, 0, 0), |
|
42 | + 'This quarter'=> array(0, 0, 0, 0, 0, 0, 0, 0), // Just a marker, needs special handling |
|
43 | + 'Last quarter'=> array(0, -4, 0, 0, 0, -4, 0, 0), // Just a marker |
|
44 | + 'This year' => array(0, 0, 0, 0, 1, 0, 0, 0), |
|
45 | + 'Last year' => array(-1, 0, 0, 0, 0, 0, 0, 0), |
|
46 | + '2 years ago' => array(-2, 0, 0, 0, -1, 0, 0, 0), |
|
47 | + '3 years ago' => array(-3, 0, 0, 0, -2, 0, 0, 0), |
|
48 | 48 | ); |
49 | 49 | |
50 | 50 | /** |
@@ -85,22 +85,22 @@ discard block |
||
85 | 85 | * @param string $_format format of time string e.g.: d.m.Y H:i |
86 | 86 | * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default |
87 | 87 | */ |
88 | - public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) { |
|
89 | - if ( empty( $_format ) ) return strtotime( $_string ); |
|
90 | - $fparams = explode( ',', chunk_split( $_format, 1, ',' ) ); |
|
88 | + public static function custom_strtotime($_string, $_format = '', $_is_dst = -1) { |
|
89 | + if (empty($_format)) return strtotime($_string); |
|
90 | + $fparams = explode(',', chunk_split($_format, 1, ',')); |
|
91 | 91 | $spos = 0; |
92 | - foreach ( $fparams as $fparam ) { |
|
93 | - |
|
94 | - switch ( $fparam ) { |
|
95 | - case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
96 | - case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
97 | - case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
98 | - case 'Y': (int)$year = substr( $_string, $spos, 4 ); $spos += 4; break; |
|
99 | - case 'H': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
100 | - case 'h': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
101 | - case 'i': (int)$min = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
102 | - case 's': (int)$sec = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
103 | - case 'O': (int)$offset = $year = substr( $_string, $spos, 5 ); $spos += 5; break; |
|
92 | + foreach ($fparams as $fparam) { |
|
93 | + |
|
94 | + switch ($fparam) { |
|
95 | + case 'd': (int)$day = substr($_string, $spos, 2); $spos += 2; break; |
|
96 | + case 'm': (int)$mon = substr($_string, $spos, 2); $spos += 2; break; |
|
97 | + case 'y': (int)$year = substr($_string, $spos, 2); $spos += 2; break; |
|
98 | + case 'Y': (int)$year = substr($_string, $spos, 4); $spos += 4; break; |
|
99 | + case 'H': (int)$hour = substr($_string, $spos, 2); $spos += 2; break; |
|
100 | + case 'h': (int)$hour = substr($_string, $spos, 2); $spos += 2; break; |
|
101 | + case 'i': (int)$min = substr($_string, $spos, 2); $spos += 2; break; |
|
102 | + case 's': (int)$sec = substr($_string, $spos, 2); $spos += 2; break; |
|
103 | + case 'O': (int)$offset = $year = substr($_string, $spos, 5); $spos += 5; break; |
|
104 | 104 | case 'a': (int)$hour = $fparam == 'am' ? $hour : $hour + 12; break; |
105 | 105 | case 'A': (int)$hour = $fparam == 'AM' ? $hour : $hour + 12; break; |
106 | 106 | default: $spos++; // seperator |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | $timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst); |
112 | 112 | |
113 | 113 | // offset given? |
114 | - if ( isset( $offset ) && strlen( $offset == 5 ) ) { |
|
114 | + if (isset($offset) && strlen($offset == 5)) { |
|
115 | 115 | $operator = $offset{0}; |
116 | - $ohour = 60 * 60 * (int)substr( $offset, 1, 2 ); |
|
117 | - $omin = 60 * (int)substr( $offset, 3, 2 ); |
|
118 | - if ( $operator == '+' ) $timestamp += $ohour + $omin; |
|
116 | + $ohour = 60 * 60 * (int)substr($offset, 1, 2); |
|
117 | + $omin = 60 * (int)substr($offset, 3, 2); |
|
118 | + if ($operator == '+') $timestamp += $ohour + $omin; |
|
119 | 119 | else $timestamp -= $ohour + $omin; |
120 | 120 | } |
121 | 121 | return $timestamp; |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * @param mixed $_account_lid comma seperated list or array with lids |
127 | 127 | * @return mixed comma seperated list or array with ids |
128 | 128 | */ |
129 | - public static function account_name2id( &$_account_lids ) { |
|
130 | - $account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids ); |
|
129 | + public static function account_name2id(&$_account_lids) { |
|
130 | + $account_lids = is_array($_account_lids) ? $_account_lids : explode(',', $_account_lids); |
|
131 | 131 | $skip = false; |
132 | - foreach ( $account_lids as $key => $account_lid ) { |
|
133 | - if($skip) { |
|
132 | + foreach ($account_lids as $key => $account_lid) { |
|
133 | + if ($skip) { |
|
134 | 134 | unset($account_lids[$key]); |
135 | 135 | $skip = false; |
136 | 136 | continue; |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | $account_lid = trim($account_lid); |
139 | 139 | |
140 | 140 | // Handle any IDs that slip in |
141 | - if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { |
|
141 | + if (is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { |
|
142 | 142 | unset($account_lids[$key]); |
143 | 143 | $account_ids[] = (int)$account_lid; |
144 | 144 | continue; |
145 | 145 | } |
146 | 146 | // Check for [username] |
147 | - if(strpos($account_lid,'[') !== false) |
|
147 | + if (strpos($account_lid, '[') !== false) |
|
148 | 148 | { |
149 | - if(preg_match('/\[(.+)\]/',$account_lid,$matches)) |
|
149 | + if (preg_match('/\[(.+)\]/', $account_lid, $matches)) |
|
150 | 150 | { |
151 | 151 | $account_id = $GLOBALS['egw']->accounts->name2id($matches[1]); |
152 | 152 | unset($account_lids[$key]); |
@@ -157,46 +157,46 @@ discard block |
||
157 | 157 | |
158 | 158 | // Handle users listed as Lastname, Firstname instead of login ID |
159 | 159 | // Do this first, in case their first name matches a username |
160 | - if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) { |
|
160 | + if ($account_lids[$key + 1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lids[$key + 1]).' '.$account_lid, 'account_fullname')) { |
|
161 | 161 | $account_ids[] = $account_id; |
162 | 162 | unset($account_lids[$key]); |
163 | 163 | $skip = true; // Skip the next one, it's the first name |
164 | - continue ; |
|
164 | + continue; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Deal with groups listed as <name> Group, remove the Group |
168 | - if(substr(trim($account_lid),-strlen(lang('Group'))) == lang('Group')) |
|
168 | + if (substr(trim($account_lid), -strlen(lang('Group'))) == lang('Group')) |
|
169 | 169 | { |
170 | 170 | $account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group')))); |
171 | 171 | } |
172 | 172 | |
173 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) { |
|
173 | + if ($account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) { |
|
174 | 174 | $account_ids[] = $account_id; |
175 | 175 | unset($account_lids[$key]); |
176 | 176 | continue; |
177 | 177 | } |
178 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) { |
|
178 | + if ($account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lid), 'account_fullname')) { |
|
179 | 179 | $account_ids[] = $account_id; |
180 | 180 | unset($account_lids[$key]); |
181 | 181 | continue; |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Handle groups listed as Group, <name> |
185 | - if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) { |
|
185 | + if ($account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) { |
|
186 | 186 | $account_ids[] = $account_id; |
187 | - unset($account_lids[$key-1]); |
|
187 | + unset($account_lids[$key - 1]); |
|
188 | 188 | unset($account_lids[$key]); |
189 | 189 | continue; |
190 | 190 | } |
191 | 191 | // Group, <name> - remove the Group part |
192 | - if($account_lid == lang('Group')) |
|
192 | + if ($account_lid == lang('Group')) |
|
193 | 193 | { |
194 | 194 | unset($account_lids[$key]); |
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | } |
198 | - $_account_lids = (is_array($_account_lids) ? $account_lids : implode(',',array_unique($account_lids))); |
|
199 | - return is_array( $_account_lids ) ? array_unique($account_ids) : implode( ',', array_unique((array)$account_ids )); |
|
198 | + $_account_lids = (is_array($_account_lids) ? $account_lids : implode(',', array_unique($account_lids))); |
|
199 | + return is_array($_account_lids) ? array_unique($account_ids) : implode(',', array_unique((array)$account_ids)); |
|
200 | 200 | |
201 | 201 | } // end of member function account_lid2id |
202 | 202 | |
@@ -206,14 +206,14 @@ discard block |
||
206 | 206 | * @param mixed $_account_ids comma seperated list or array with ids |
207 | 207 | * @return mixed comma seperated list or array with lids |
208 | 208 | */ |
209 | - public static function account_id2name( $_account_id ) { |
|
210 | - $account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id ); |
|
211 | - foreach ( $account_ids as $account_id ) { |
|
212 | - if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) { |
|
209 | + public static function account_id2name($_account_id) { |
|
210 | + $account_ids = is_array($_account_id) ? $_account_id : explode(',', $_account_id); |
|
211 | + foreach ($account_ids as $account_id) { |
|
212 | + if ($account_lid = $GLOBALS['egw']->accounts->id2name($account_id)) { |
|
213 | 213 | $account_lids[] = $account_lid; |
214 | 214 | } |
215 | 215 | } |
216 | - return is_array( $_account_id ) ? $account_lids : implode( ',', (array)$account_lids ); |
|
216 | + return is_array($_account_id) ? $account_lids : implode(',', (array)$account_lids); |
|
217 | 217 | } // end of member function account_id2lid |
218 | 218 | |
219 | 219 | /** |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | * @param mixed _cat_ids comma seperated list or array |
223 | 223 | * @return mixed comma seperated list or array with cat_names |
224 | 224 | */ |
225 | - public static function cat_id2name( $_cat_ids ) { |
|
226 | - $cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids ); |
|
227 | - foreach ( $cat_ids as $cat_id ) { |
|
228 | - $cat_names[] = Api\Categories::id2name( (int)$cat_id ); |
|
225 | + public static function cat_id2name($_cat_ids) { |
|
226 | + $cat_ids = is_array($_cat_ids) ? $_cat_ids : explode(',', $_cat_ids); |
|
227 | + foreach ($cat_ids as $cat_id) { |
|
228 | + $cat_names[] = Api\Categories::id2name((int)$cat_id); |
|
229 | 229 | } |
230 | - return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names); |
|
230 | + return is_array($_cat_ids) ? $cat_names : implode(',', (array)$cat_names); |
|
231 | 231 | } // end of member function category_id2name |
232 | 232 | |
233 | 233 | /** |
@@ -238,24 +238,24 @@ discard block |
||
238 | 238 | * @param int $parent Optional parent ID to use for new categories |
239 | 239 | * @return mixed comma seperated list or array with cat_ids |
240 | 240 | */ |
241 | - public static function cat_name2id( $_cat_names, $parent = 0 ) { |
|
242 | - $cats = new Api\Categories(); // uses current user and app (egw_info[flags][currentapp]) |
|
241 | + public static function cat_name2id($_cat_names, $parent = 0) { |
|
242 | + $cats = new Api\Categories(); // uses current user and app (egw_info[flags][currentapp]) |
|
243 | 243 | |
244 | - $cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names ); |
|
245 | - foreach ( $cat_names as $cat_name ) { |
|
244 | + $cat_names = is_array($_cat_names) ? $_cat_names : explode(',', $_cat_names); |
|
245 | + foreach ($cat_names as $cat_name) { |
|
246 | 246 | $cat_name = trim($cat_name); |
247 | - if ( $cat_name == '' ) continue; |
|
248 | - if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) { |
|
249 | - $cat_id = $cats->add( array( |
|
247 | + if ($cat_name == '') continue; |
|
248 | + if (($cat_id = $cats->name2id($cat_name)) == 0 && !self::$dry_run) { |
|
249 | + $cat_id = $cats->add(array( |
|
250 | 250 | 'name' => $cat_name, |
251 | 251 | 'parent' => $parent, |
252 | 252 | 'access' => 'public', |
253 | - 'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')' |
|
253 | + 'descr' => $cat_name.' ('.lang('Automatically created by importexport').')' |
|
254 | 254 | )); |
255 | 255 | } |
256 | 256 | $cat_ids[] = $cat_id; |
257 | 257 | } |
258 | - return is_array( $_cat_names ) ? $cat_ids : implode( ',', (array)$cat_ids ); |
|
258 | + return is_array($_cat_names) ? $cat_ids : implode(',', (array)$cat_ids); |
|
259 | 259 | |
260 | 260 | } // end of member function category_name2id |
261 | 261 | |
@@ -294,76 +294,76 @@ discard block |
||
294 | 294 | * @param object &$cclass calling class to process the '@ evals' |
295 | 295 | * @return bool |
296 | 296 | */ |
297 | - public static function conversion( &$_record, $_conversion, &$_cclass = null ) { |
|
298 | - if (empty( $_conversion ) ) return $_record; |
|
297 | + public static function conversion(&$_record, $_conversion, &$_cclass = null) { |
|
298 | + if (empty($_conversion)) return $_record; |
|
299 | 299 | |
300 | - self::$cclass =& $_cclass; |
|
300 | + self::$cclass = & $_cclass; |
|
301 | 301 | |
302 | 302 | $PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in conversion |
303 | 303 | $ASep = '|>'; // Assignment-Separator, separats pattern and replacesment |
304 | - $CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value |
|
304 | + $CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value |
|
305 | 305 | $TPre = '|T{'; $TPos = '}'; // |{_record-idx} is trimmed |
306 | - $CntlPre = '|TC{'; // Filter all cntl-chars \x01-\x1f and trim |
|
307 | - $CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF |
|
308 | - $INE = '|INE{'; // Only insert if stuff in ^^ is not empty |
|
306 | + $CntlPre = '|TC{'; // Filter all cntl-chars \x01-\x1f and trim |
|
307 | + $CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF |
|
308 | + $INE = '|INE{'; // Only insert if stuff in ^^ is not empty |
|
309 | 309 | |
310 | - foreach ( $_conversion as $idx => $conversion_string ) { |
|
311 | - if ( empty( $conversion_string ) ) continue; |
|
310 | + foreach ($_conversion as $idx => $conversion_string) { |
|
311 | + if (empty($conversion_string)) continue; |
|
312 | 312 | |
313 | 313 | // fetch patterns ($rvalues) |
314 | 314 | $rvalues = array(); |
315 | - $pat_reps = explode( $PSep, stripslashes( $conversion_string ) ); |
|
316 | - foreach( $pat_reps as $k => $pat_rep ) { |
|
317 | - list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 ); |
|
318 | - if( $replace == '' ) { |
|
315 | + $pat_reps = explode($PSep, stripslashes($conversion_string)); |
|
316 | + foreach ($pat_reps as $k => $pat_rep) { |
|
317 | + list($pattern, $replace) = explode($ASep, $pat_rep, 2); |
|
318 | + if ($replace == '') { |
|
319 | 319 | $replace = $pattern; $pattern = '^.*$'; |
320 | 320 | } |
321 | - $rvalues[$pattern] = $replace; // replace two with only one, added by the form |
|
321 | + $rvalues[$pattern] = $replace; // replace two with only one, added by the form |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | // conversion list may be longer than $_record aka (no_csv) |
325 | - $val = array_key_exists( $idx, $_record ) ? $_record[$idx] : ''; |
|
325 | + $val = array_key_exists($idx, $_record) ? $_record[$idx] : ''; |
|
326 | 326 | |
327 | 327 | $c_functions = array('cat', 'account', 'strtotime', 'list'); |
328 | - if($_cclass) { |
|
328 | + if ($_cclass) { |
|
329 | 329 | // Add in additional methods |
330 | 330 | $reflection = new ReflectionClass(get_class($_cclass)); |
331 | 331 | $methods = $reflection->getMethods(ReflectionMethod::IS_STATIC); |
332 | - foreach($methods as $method) { |
|
332 | + foreach ($methods as $method) { |
|
333 | 333 | $c_functions[] = $method->name; |
334 | 334 | } |
335 | 335 | } |
336 | 336 | $c_functions = implode('|', $c_functions); |
337 | - foreach ( $rvalues as $pattern => $replace ) { |
|
337 | + foreach ($rvalues as $pattern => $replace) { |
|
338 | 338 | // Allow to include record indexes in pattern |
339 | 339 | $reg = '/\|\[([0-9]+)\]/'; |
340 | - while( preg_match( $reg, $pattern, $vars ) ) { |
|
340 | + while (preg_match($reg, $pattern, $vars)) { |
|
341 | 341 | // expand all _record fields |
342 | 342 | $pattern = str_replace( |
343 | - $CPre . $vars[1] . $CPos, |
|
343 | + $CPre.$vars[1].$CPos, |
|
344 | 344 | $_record[array_search($vars[1], array_keys($_record))], |
345 | 345 | $pattern |
346 | 346 | ); |
347 | 347 | } |
348 | - if( preg_match('/'. (string)$pattern.'/', $val) ) { |
|
348 | + if (preg_match('/'.(string)$pattern.'/', $val)) { |
|
349 | 349 | |
350 | - $val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val ); |
|
350 | + $val = preg_replace('/'.(string)$pattern.'/', $replace, (string)$val); |
|
351 | 351 | |
352 | 352 | $reg = '/\|\[([a-zA-Z_0-9]+)\]/'; |
353 | - while( preg_match( $reg, $val, $vars ) ) { |
|
353 | + while (preg_match($reg, $val, $vars)) { |
|
354 | 354 | // expand all _record fields |
355 | 355 | $val = str_replace( |
356 | - $CPre . $vars[1] . $CPos, |
|
356 | + $CPre.$vars[1].$CPos, |
|
357 | 357 | $_record[array_search($vars[1], array_keys($_record))], |
358 | 358 | $val |
359 | 359 | ); |
360 | 360 | } |
361 | - $val = preg_replace_callback( "/($c_functions)\(([^)]*)\)/i", array( self, 'c2_dispatcher') , $val ); |
|
361 | + $val = preg_replace_callback("/($c_functions)\(([^)]*)\)/i", array(self, 'c2_dispatcher'), $val); |
|
362 | 362 | break; |
363 | 363 | } |
364 | 364 | } |
365 | 365 | // clean each field |
366 | - $val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array( self, 'strclean'), $val ); |
|
366 | + $val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array(self, 'strclean'), $val); |
|
367 | 367 | |
368 | 368 | $_record[$idx] = $val; |
369 | 369 | } |
@@ -377,42 +377,42 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @param array $_matches |
379 | 379 | */ |
380 | - private static function c2_dispatcher( $_matches ) { |
|
380 | + private static function c2_dispatcher($_matches) { |
|
381 | 381 | $action = &$_matches[1]; // cat or account ... |
382 | - $data = &$_matches[2]; // datas for action |
|
382 | + $data = &$_matches[2]; // datas for action |
|
383 | 383 | |
384 | - switch ( $action ) { |
|
384 | + switch ($action) { |
|
385 | 385 | case 'strtotime' : |
386 | - list( $string, $format ) = explode( ',', $data ); |
|
387 | - return self::custom_strtotime( trim( $string ), trim( $format ) ); |
|
386 | + list($string, $format) = explode(',', $data); |
|
387 | + return self::custom_strtotime(trim($string), trim($format)); |
|
388 | 388 | case 'list': |
389 | - list( $split, $data, $index) = explode(',',$data); |
|
389 | + list($split, $data, $index) = explode(',', $data); |
|
390 | 390 | $exploded = explode($split, $data); |
391 | 391 | // 1 based indexing for user ease |
392 | 392 | return $exploded[$index - 1]; |
393 | 393 | default : |
394 | - if(self::$cclass && method_exists(self::$cclass, $action)) { |
|
394 | + if (self::$cclass && method_exists(self::$cclass, $action)) { |
|
395 | 395 | $class = get_class(self::$cclass); |
396 | 396 | return call_user_func("$class::$action", $data); |
397 | 397 | } |
398 | - $method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' ); |
|
399 | - if(self::$cclass && method_exists(self::$cclass, $method)) { |
|
398 | + $method = (string)$action.(is_int($data) ? '_id2name' : '_name2id'); |
|
399 | + if (self::$cclass && method_exists(self::$cclass, $method)) { |
|
400 | 400 | $class = get_class(self::$cclass); |
401 | 401 | return call_user_func("$class::$action", $data); |
402 | 402 | } else { |
403 | - return self::$method( $data ); |
|
403 | + return self::$method($data); |
|
404 | 404 | } |
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | - private static function strclean( $_matches ) { |
|
409 | - switch( $_matches[1] ) { |
|
410 | - case '|T{' : return trim( $_matches[2] ); |
|
411 | - case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) ); |
|
412 | - case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) ); |
|
413 | - case '|INE{' : return preg_match( '/\^.+\^/', $_matches[2] ) ? $_matches[2] : ''; |
|
408 | + private static function strclean($_matches) { |
|
409 | + switch ($_matches[1]) { |
|
410 | + case '|T{' : return trim($_matches[2]); |
|
411 | + case '|TC{' : return trim(preg_replace('/[\x01-\x1F]+/', '', $_matches[2])); |
|
412 | + case '|TCnCL{' : return trim(preg_replace('/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2])); |
|
413 | + case '|INE{' : return preg_match('/\^.+\^/', $_matches[2]) ? $_matches[2] : ''; |
|
414 | 414 | default: |
415 | - throw new Exception('Error in conversion string! "'. substr( $_matches[1], 0, -1 ). '" is not valid!'); |
|
415 | + throw new Exception('Error in conversion string! "'.substr($_matches[1], 0, -1).'" is not valid!'); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
@@ -423,23 +423,23 @@ discard block |
||
423 | 423 | * @param string $_appname {<appname> | all} |
424 | 424 | * @return array(<appname> => array( <type> => array(<plugin> => <title>))) |
425 | 425 | */ |
426 | - public static function get_plugins( $_appname = 'all', $_type = 'all' ) { |
|
426 | + public static function get_plugins($_appname = 'all', $_type = 'all') { |
|
427 | 427 | $plugins = Api\Cache::getTree( |
428 | 428 | __CLASS__, |
429 | 429 | 'plugins', |
430 | - array('importexport_helper_functions','_get_plugins'), |
|
430 | + array('importexport_helper_functions', '_get_plugins'), |
|
431 | 431 | array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')), |
432 | 432 | self::CACHE_EXPIRATION |
433 | 433 | ); |
434 | 434 | $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; |
435 | - $types = $_type == 'all' ? array('import','export') : (array)$_type; |
|
435 | + $types = $_type == 'all' ? array('import', 'export') : (array)$_type; |
|
436 | 436 | |
437 | 437 | // Testing: comment out Api\Cache call, use this |
438 | 438 | //$plugins = self::_get_plugins($appnames, $types); |
439 | - foreach($plugins as $appname => $_types) { |
|
440 | - if(!in_array($appname, $appnames)) unset($plugins[$appname]); |
|
439 | + foreach ($plugins as $appname => $_types) { |
|
440 | + if (!in_array($appname, $appnames)) unset($plugins[$appname]); |
|
441 | 441 | } |
442 | - foreach($plugins as $appname => $types) { |
|
442 | + foreach ($plugins as $appname => $types) { |
|
443 | 443 | $plugins[$appname] = array_intersect_key($plugins[$appname], $types); |
444 | 444 | } |
445 | 445 | return $plugins; |
@@ -448,25 +448,25 @@ discard block |
||
448 | 448 | public static function _get_plugins(Array $appnames, Array $types) { |
449 | 449 | $plugins = array(); |
450 | 450 | foreach ($appnames as $appname) { |
451 | - if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
|
451 | + if (array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
|
452 | 452 | |
453 | - $appdir = EGW_INCLUDE_ROOT. "/$appname/inc"; |
|
454 | - if(!is_dir($appdir)) continue; |
|
453 | + $appdir = EGW_INCLUDE_ROOT."/$appname/inc"; |
|
454 | + if (!is_dir($appdir)) continue; |
|
455 | 455 | $d = dir($appdir); |
456 | 456 | |
457 | 457 | // step through each file in appdir |
458 | 458 | while (false !== ($entry = $d->read())) { |
459 | 459 | // Blacklisted? |
460 | - if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) continue; |
|
460 | + if (is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) continue; |
|
461 | 461 | if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue; |
462 | 462 | $classname = $matches[1]; |
463 | - $file = $appdir. '/'. $entry; |
|
463 | + $file = $appdir.'/'.$entry; |
|
464 | 464 | |
465 | 465 | foreach ($types as $type) { |
466 | - if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue; |
|
466 | + if (!is_file($file) || strpos($entry, $type) === false || strpos($entry, 'wizard') !== false) continue; |
|
467 | 467 | require_once($file); |
468 | 468 | $reflectionClass = new ReflectionClass($classname); |
469 | - if($reflectionClass->IsInstantiable() && |
|
469 | + if ($reflectionClass->IsInstantiable() && |
|
470 | 470 | $reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) { |
471 | 471 | try { |
472 | 472 | $plugin_object = new $classname; |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | $d->close(); |
483 | 483 | |
484 | 484 | $config = Api\Config::read('importexport'); |
485 | - if($config['update'] == 'auto') { |
|
485 | + if ($config['update'] == 'auto') { |
|
486 | 486 | self::load_defaults($appname); |
487 | 487 | } |
488 | 488 | } |
@@ -497,37 +497,37 @@ discard block |
||
497 | 497 | * @return array $num => $appname |
498 | 498 | */ |
499 | 499 | public static function get_apps($_type, $ignore_acl = false) { |
500 | - $apps = array_keys(self::get_plugins('all',$_type)); |
|
501 | - if($ignore_acl) return $apps; |
|
500 | + $apps = array_keys(self::get_plugins('all', $_type)); |
|
501 | + if ($ignore_acl) return $apps; |
|
502 | 502 | |
503 | - foreach($apps as $key => $app) { |
|
504 | - if(!self::has_definitions($app, $_type)) unset($apps[$key]); |
|
503 | + foreach ($apps as $key => $app) { |
|
504 | + if (!self::has_definitions($app, $_type)) unset($apps[$key]); |
|
505 | 505 | } |
506 | 506 | return $apps; |
507 | 507 | } |
508 | 508 | |
509 | 509 | public static function load_defaults($appname) { |
510 | 510 | // Check for new definitions to import from $appname/setup/*.xml |
511 | - $appdir = EGW_INCLUDE_ROOT. "/$appname/setup"; |
|
512 | - if(!is_dir($appdir)) return; |
|
511 | + $appdir = EGW_INCLUDE_ROOT."/$appname/setup"; |
|
512 | + if (!is_dir($appdir)) return; |
|
513 | 513 | $d = dir($appdir); |
514 | 514 | |
515 | 515 | // step through each file in app's setup |
516 | 516 | while (false !== ($entry = $d->read())) { |
517 | - $file = $appdir. '/'. $entry; |
|
518 | - list( $filename, $extension) = explode('.',$entry); |
|
519 | - if ( $extension != 'xml' ) continue; |
|
517 | + $file = $appdir.'/'.$entry; |
|
518 | + list($filename, $extension) = explode('.', $entry); |
|
519 | + if ($extension != 'xml') continue; |
|
520 | 520 | try { |
521 | 521 | // import will skip invalid files |
522 | - importexport_definitions_bo::import( $file ); |
|
522 | + importexport_definitions_bo::import($file); |
|
523 | 523 | } catch (Exception $e) { |
524 | - error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage()); |
|
524 | + error_log(__CLASS__.__FUNCTION__." import $appname definitions: ".$e->getMessage()); |
|
525 | 525 | } |
526 | 526 | } |
527 | 527 | $d->close(); |
528 | 528 | } |
529 | 529 | |
530 | - public static function guess_filetype( $_file ) { |
|
530 | + public static function guess_filetype($_file) { |
|
531 | 531 | |
532 | 532 | } |
533 | 533 | |
@@ -538,24 +538,24 @@ discard block |
||
538 | 538 | * @param string $_type {import | export | all} |
539 | 539 | * @return boolean |
540 | 540 | */ |
541 | - public static function has_definitions( $_appname = 'all', $_type = 'all' ) { |
|
541 | + public static function has_definitions($_appname = 'all', $_type = 'all') { |
|
542 | 542 | $definitions = Api\Cache::getSession( |
543 | 543 | __CLASS__, |
544 | 544 | 'has_definitions', |
545 | - array('importexport_helper_functions','_has_definitions'), |
|
545 | + array('importexport_helper_functions', '_has_definitions'), |
|
546 | 546 | array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')), |
547 | 547 | self::CACHE_EXPIRATION |
548 | 548 | ); |
549 | 549 | $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; |
550 | - $types = $_type == 'all' ? array('import','export') : (array)$_type; |
|
550 | + $types = $_type == 'all' ? array('import', 'export') : (array)$_type; |
|
551 | 551 | |
552 | 552 | // Testing: Comment out cache call above, use this |
553 | 553 | //$definitions = self::_has_definitions($appnames, $types); |
554 | 554 | |
555 | - foreach($definitions as $appname => $_types) { |
|
556 | - if(!in_array($appname, $appnames)) unset($definitions[$appname]); |
|
555 | + foreach ($definitions as $appname => $_types) { |
|
556 | + if (!in_array($appname, $appnames)) unset($definitions[$appname]); |
|
557 | 557 | } |
558 | - foreach($definitions as $appname => $_types) { |
|
558 | + foreach ($definitions as $appname => $_types) { |
|
559 | 559 | $definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types)); |
560 | 560 | } |
561 | 561 | return count($definitions[$appname]) > 0; |
@@ -565,11 +565,11 @@ discard block |
||
565 | 565 | public static function _has_definitions(Array $appnames, Array $types) { |
566 | 566 | $def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types)); |
567 | 567 | $list = array(); |
568 | - foreach((array)$def->get_definitions() as $id) { |
|
568 | + foreach ((array)$def->get_definitions() as $id) { |
|
569 | 569 | // Need to instanciate it to check, but if the user doesn't have permission, it throws an exception |
570 | 570 | try { |
571 | 571 | $definition = new importexport_definition($id); |
572 | - if($def->is_permitted($definition->get_record_array())) { |
|
572 | + if ($def->is_permitted($definition->get_record_array())) { |
|
573 | 573 | $list[$definition->application][$definition->type][] = $id; |
574 | 574 | } |
575 | 575 | } catch (Exception $e) { |
@@ -601,13 +601,13 @@ discard block |
||
601 | 601 | $plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name(); |
602 | 602 | $plugin_name = get_class($plugin); |
603 | 603 | |
604 | - if($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
605 | - if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname); |
|
604 | + if ($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
605 | + if (!class_exists($record_classname)) throw new Exception('Bad class name '.$record_classname); |
|
606 | 606 | |
607 | - if(!$wizard_plugin) |
|
607 | + if (!$wizard_plugin) |
|
608 | 608 | { |
609 | - $wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name); |
|
610 | - if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name); |
|
609 | + $wizard_name = $app_name.'_wizard_'.str_replace($app_name.'_', '', $plugin_name); |
|
610 | + if (!class_exists($wizard_name)) throw new Exception('Bad wizard name '.$wizard_name); |
|
611 | 611 | $wizard_plugin = new $wizard_name; |
612 | 612 | } |
613 | 613 | } |
@@ -619,16 +619,16 @@ discard block |
||
619 | 619 | |
620 | 620 | // Get field -> label map and initialize fields using wizard field order |
621 | 621 | $fields = $export_fields = array(); |
622 | - if(method_exists($wizard_plugin, 'get_export_fields')) |
|
622 | + if (method_exists($wizard_plugin, 'get_export_fields')) |
|
623 | 623 | { |
624 | 624 | $fields = $export_fields = $wizard_plugin->get_export_fields(); |
625 | 625 | } |
626 | 626 | |
627 | - foreach($record_classname::$types as $type => $type_fields) |
|
627 | + foreach ($record_classname::$types as $type => $type_fields) |
|
628 | 628 | { |
629 | 629 | // Only these for now, until filter methods for others are figured out |
630 | - if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue; |
|
631 | - foreach($type_fields as $field_name) |
|
630 | + if (!in_array($type, array('select', 'select-cat', 'select-account', 'date', 'date-time'))) continue; |
|
631 | + foreach ($type_fields as $field_name) |
|
632 | 632 | { |
633 | 633 | $fields[$field_name] = array( |
634 | 634 | 'name' => $field_name, |
@@ -639,21 +639,21 @@ discard block |
||
639 | 639 | } |
640 | 640 | // Add custom fields |
641 | 641 | $custom = Api\Storage\Customfields::get($app_name); |
642 | - foreach($custom as $field_name => $settings) |
|
642 | + foreach ($custom as $field_name => $settings) |
|
643 | 643 | { |
644 | 644 | $settings['name'] = '#'.$field_name; |
645 | 645 | $fields['#'.$field_name] = $settings; |
646 | 646 | } |
647 | 647 | |
648 | - foreach($fields as $field_name => &$settings) { |
|
648 | + foreach ($fields as $field_name => &$settings) { |
|
649 | 649 | // Can't really filter on these (or at least no generic, sane way figured out yet) |
650 | - if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea'))) |
|
650 | + if (!is_array($settings) || in_array($settings['type'], array('text', 'button', 'label', 'url', 'url-email', 'url-phone', 'htmlarea'))) |
|
651 | 651 | { |
652 | 652 | unset($fields[$field_name]); |
653 | 653 | continue; |
654 | 654 | } |
655 | - if($settings['type'] == 'radio') $settings['type'] = 'select'; |
|
656 | - switch($settings['type']) |
|
655 | + if ($settings['type'] == 'radio') $settings['type'] = 'select'; |
|
656 | + switch ($settings['type']) |
|
657 | 657 | { |
658 | 658 | case 'checkbox': |
659 | 659 | // This isn't quite right - there's only 2 options and you can select both |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
679 | - if(method_exists($plugin, 'get_filter_fields')) |
|
679 | + if (method_exists($plugin, 'get_filter_fields')) |
|
680 | 680 | { |
681 | 681 | $plugin->get_filter_fields($fields); |
682 | 682 | } |
@@ -692,65 +692,65 @@ discard block |
||
692 | 692 | */ |
693 | 693 | public static function date_rel2abs($value) |
694 | 694 | { |
695 | - if(is_array($value)) |
|
695 | + if (is_array($value)) |
|
696 | 696 | { |
697 | 697 | $abs = array(); |
698 | - foreach($value as $key => $val) |
|
698 | + foreach ($value as $key => $val) |
|
699 | 699 | { |
700 | 700 | $abs[$key] = self::date_rel2abs($val); |
701 | 701 | } |
702 | 702 | return $abs; |
703 | 703 | } |
704 | - if($date = self::$relative_dates[$value]) |
|
704 | + if ($date = self::$relative_dates[$value]) |
|
705 | 705 | { |
706 | - $year = (int) date('Y'); |
|
707 | - $month = (int) date('m'); |
|
708 | - $day = (int) date('d'); |
|
709 | - $today = mktime(0,0,0,date('m'),date('d'),date('Y')); |
|
706 | + $year = (int)date('Y'); |
|
707 | + $month = (int)date('m'); |
|
708 | + $day = (int)date('d'); |
|
709 | + $today = mktime(0, 0, 0, date('m'), date('d'), date('Y')); |
|
710 | 710 | |
711 | - list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $date; |
|
711 | + list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $date; |
|
712 | 712 | |
713 | - if(stripos($value, 'quarter') !== false) |
|
713 | + if (stripos($value, 'quarter') !== false) |
|
714 | 714 | { |
715 | 715 | // Handle quarters |
716 | - $start = mktime(0,0,0,((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1, $year); |
|
717 | - $end = mktime(0,0,0,((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1, $year); |
|
716 | + $start = mktime(0, 0, 0, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1, $year); |
|
717 | + $end = mktime(0, 0, 0, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1, $year); |
|
718 | 718 | } |
719 | 719 | elseif ($syear || $eyear) |
720 | 720 | { |
721 | - $start = mktime(0,0,0,1,1,$syear+$year); |
|
722 | - $end = mktime(0,0,0,1,1,$eyear+$year); |
|
721 | + $start = mktime(0, 0, 0, 1, 1, $syear + $year); |
|
722 | + $end = mktime(0, 0, 0, 1, 1, $eyear + $year); |
|
723 | 723 | } |
724 | 724 | elseif ($smonth || $emonth) |
725 | 725 | { |
726 | - $start = mktime(0,0,0,$smonth+$month,1,$year); |
|
727 | - $end = mktime(0,0,0,$emonth+$month,1,$year); |
|
726 | + $start = mktime(0, 0, 0, $smonth + $month, 1, $year); |
|
727 | + $end = mktime(0, 0, 0, $emonth + $month, 1, $year); |
|
728 | 728 | } |
729 | 729 | elseif ($sday || $eday) |
730 | 730 | { |
731 | - $start = mktime(0,0,0,$month,$sday+$day,$year); |
|
732 | - $end = mktime(0,0,0,$month,$eday+$day,$year); |
|
731 | + $start = mktime(0, 0, 0, $month, $sday + $day, $year); |
|
732 | + $end = mktime(0, 0, 0, $month, $eday + $day, $year); |
|
733 | 733 | } |
734 | 734 | elseif ($sweek || $eweek) |
735 | 735 | { |
736 | - $wday = (int) date('w'); // 0=sun, ..., 6=sat |
|
737 | - switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
736 | + $wday = (int)date('w'); // 0=sun, ..., 6=sat |
|
737 | + switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
738 | 738 | { |
739 | 739 | case 'Sunday': |
740 | - $weekstart = $today - $wday * 24*60*60; |
|
740 | + $weekstart = $today - $wday * 24 * 60 * 60; |
|
741 | 741 | break; |
742 | 742 | case 'Saturday': |
743 | - $weekstart = $today - (6-$wday) * 24*60*60; |
|
743 | + $weekstart = $today - (6 - $wday) * 24 * 60 * 60; |
|
744 | 744 | break; |
745 | 745 | case 'Moday': |
746 | 746 | default: |
747 | - $weekstart = $today - ($wday ? $wday-1 : 6) * 24*60*60; |
|
747 | + $weekstart = $today - ($wday ? $wday - 1 : 6) * 24 * 60 * 60; |
|
748 | 748 | break; |
749 | 749 | } |
750 | - $start = $weekstart + $sweek*7*24*60*60; |
|
751 | - $end = $weekstart + $eweek*7*24*60*60; |
|
750 | + $start = $weekstart + $sweek * 7 * 24 * 60 * 60; |
|
751 | + $end = $weekstart + $eweek * 7 * 24 * 60 * 60; |
|
752 | 752 | } |
753 | - $end_param = $end - 24*60*60; |
|
753 | + $end_param = $end - 24 * 60 * 60; |
|
754 | 754 | |
755 | 755 | // Take 1 second off end to provide an inclusive range.for filtering |
756 | 756 | $end -= 1; |
@@ -16,7 +16,8 @@ discard block |
||
16 | 16 | * class importexport_helper_functions (only static methods) |
17 | 17 | * use importexport_helper_functions::method |
18 | 18 | */ |
19 | -class importexport_helper_functions { |
|
19 | +class importexport_helper_functions |
|
20 | +{ |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Plugins are scanned and cached for all instances using this source path for given time (in seconds) |
@@ -85,13 +86,19 @@ discard block |
||
85 | 86 | * @param string $_format format of time string e.g.: d.m.Y H:i |
86 | 87 | * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default |
87 | 88 | */ |
88 | - public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) { |
|
89 | - if ( empty( $_format ) ) return strtotime( $_string ); |
|
89 | + public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) |
|
90 | + { |
|
91 | + if ( empty( $_format ) ) |
|
92 | + { |
|
93 | + return strtotime( $_string ); |
|
94 | + } |
|
90 | 95 | $fparams = explode( ',', chunk_split( $_format, 1, ',' ) ); |
91 | 96 | $spos = 0; |
92 | - foreach ( $fparams as $fparam ) { |
|
97 | + foreach ( $fparams as $fparam ) |
|
98 | + { |
|
93 | 99 | |
94 | - switch ( $fparam ) { |
|
100 | + switch ( $fparam ) |
|
101 | + { |
|
95 | 102 | case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break; |
96 | 103 | case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break; |
97 | 104 | case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break; |
@@ -111,12 +118,18 @@ discard block |
||
111 | 118 | $timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst); |
112 | 119 | |
113 | 120 | // offset given? |
114 | - if ( isset( $offset ) && strlen( $offset == 5 ) ) { |
|
121 | + if ( isset( $offset ) && strlen( $offset == 5 ) ) |
|
122 | + { |
|
115 | 123 | $operator = $offset{0}; |
116 | 124 | $ohour = 60 * 60 * (int)substr( $offset, 1, 2 ); |
117 | 125 | $omin = 60 * (int)substr( $offset, 3, 2 ); |
118 | - if ( $operator == '+' ) $timestamp += $ohour + $omin; |
|
119 | - else $timestamp -= $ohour + $omin; |
|
126 | + if ( $operator == '+' ) |
|
127 | + { |
|
128 | + $timestamp += $ohour + $omin; |
|
129 | + } |
|
130 | + else { |
|
131 | + $timestamp -= $ohour + $omin; |
|
132 | + } |
|
120 | 133 | } |
121 | 134 | return $timestamp; |
122 | 135 | } |
@@ -126,11 +139,14 @@ discard block |
||
126 | 139 | * @param mixed $_account_lid comma seperated list or array with lids |
127 | 140 | * @return mixed comma seperated list or array with ids |
128 | 141 | */ |
129 | - public static function account_name2id( &$_account_lids ) { |
|
142 | + public static function account_name2id( &$_account_lids ) |
|
143 | + { |
|
130 | 144 | $account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids ); |
131 | 145 | $skip = false; |
132 | - foreach ( $account_lids as $key => $account_lid ) { |
|
133 | - if($skip) { |
|
146 | + foreach ( $account_lids as $key => $account_lid ) |
|
147 | + { |
|
148 | + if($skip) |
|
149 | + { |
|
134 | 150 | unset($account_lids[$key]); |
135 | 151 | $skip = false; |
136 | 152 | continue; |
@@ -138,7 +154,8 @@ discard block |
||
138 | 154 | $account_lid = trim($account_lid); |
139 | 155 | |
140 | 156 | // Handle any IDs that slip in |
141 | - if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { |
|
157 | + if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) |
|
158 | + { |
|
142 | 159 | unset($account_lids[$key]); |
143 | 160 | $account_ids[] = (int)$account_lid; |
144 | 161 | continue; |
@@ -157,7 +174,8 @@ discard block |
||
157 | 174 | |
158 | 175 | // Handle users listed as Lastname, Firstname instead of login ID |
159 | 176 | // Do this first, in case their first name matches a username |
160 | - if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) { |
|
177 | + if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) |
|
178 | + { |
|
161 | 179 | $account_ids[] = $account_id; |
162 | 180 | unset($account_lids[$key]); |
163 | 181 | $skip = true; // Skip the next one, it's the first name |
@@ -170,19 +188,22 @@ discard block |
||
170 | 188 | $account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group')))); |
171 | 189 | } |
172 | 190 | |
173 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) { |
|
191 | + if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) |
|
192 | + { |
|
174 | 193 | $account_ids[] = $account_id; |
175 | 194 | unset($account_lids[$key]); |
176 | 195 | continue; |
177 | 196 | } |
178 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) { |
|
197 | + if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) |
|
198 | + { |
|
179 | 199 | $account_ids[] = $account_id; |
180 | 200 | unset($account_lids[$key]); |
181 | 201 | continue; |
182 | 202 | } |
183 | 203 | |
184 | 204 | // Handle groups listed as Group, <name> |
185 | - if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) { |
|
205 | + if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) |
|
206 | + { |
|
186 | 207 | $account_ids[] = $account_id; |
187 | 208 | unset($account_lids[$key-1]); |
188 | 209 | unset($account_lids[$key]); |
@@ -206,10 +227,13 @@ discard block |
||
206 | 227 | * @param mixed $_account_ids comma seperated list or array with ids |
207 | 228 | * @return mixed comma seperated list or array with lids |
208 | 229 | */ |
209 | - public static function account_id2name( $_account_id ) { |
|
230 | + public static function account_id2name( $_account_id ) |
|
231 | + { |
|
210 | 232 | $account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id ); |
211 | - foreach ( $account_ids as $account_id ) { |
|
212 | - if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) { |
|
233 | + foreach ( $account_ids as $account_id ) |
|
234 | + { |
|
235 | + if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) |
|
236 | + { |
|
213 | 237 | $account_lids[] = $account_lid; |
214 | 238 | } |
215 | 239 | } |
@@ -222,9 +246,11 @@ discard block |
||
222 | 246 | * @param mixed _cat_ids comma seperated list or array |
223 | 247 | * @return mixed comma seperated list or array with cat_names |
224 | 248 | */ |
225 | - public static function cat_id2name( $_cat_ids ) { |
|
249 | + public static function cat_id2name( $_cat_ids ) |
|
250 | + { |
|
226 | 251 | $cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids ); |
227 | - foreach ( $cat_ids as $cat_id ) { |
|
252 | + foreach ( $cat_ids as $cat_id ) |
|
253 | + { |
|
228 | 254 | $cat_names[] = Api\Categories::id2name( (int)$cat_id ); |
229 | 255 | } |
230 | 256 | return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names); |
@@ -238,14 +264,20 @@ discard block |
||
238 | 264 | * @param int $parent Optional parent ID to use for new categories |
239 | 265 | * @return mixed comma seperated list or array with cat_ids |
240 | 266 | */ |
241 | - public static function cat_name2id( $_cat_names, $parent = 0 ) { |
|
267 | + public static function cat_name2id( $_cat_names, $parent = 0 ) |
|
268 | + { |
|
242 | 269 | $cats = new Api\Categories(); // uses current user and app (egw_info[flags][currentapp]) |
243 | 270 | |
244 | 271 | $cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names ); |
245 | - foreach ( $cat_names as $cat_name ) { |
|
272 | + foreach ( $cat_names as $cat_name ) |
|
273 | + { |
|
246 | 274 | $cat_name = trim($cat_name); |
247 | - if ( $cat_name == '' ) continue; |
|
248 | - if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) { |
|
275 | + if ( $cat_name == '' ) |
|
276 | + { |
|
277 | + continue; |
|
278 | + } |
|
279 | + if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) |
|
280 | + { |
|
249 | 281 | $cat_id = $cats->add( array( |
250 | 282 | 'name' => $cat_name, |
251 | 283 | 'parent' => $parent, |
@@ -294,8 +326,12 @@ discard block |
||
294 | 326 | * @param object &$cclass calling class to process the '@ evals' |
295 | 327 | * @return bool |
296 | 328 | */ |
297 | - public static function conversion( &$_record, $_conversion, &$_cclass = null ) { |
|
298 | - if (empty( $_conversion ) ) return $_record; |
|
329 | + public static function conversion( &$_record, $_conversion, &$_cclass = null ) |
|
330 | + { |
|
331 | + if (empty( $_conversion ) ) |
|
332 | + { |
|
333 | + return $_record; |
|
334 | + } |
|
299 | 335 | |
300 | 336 | self::$cclass =& $_cclass; |
301 | 337 | |
@@ -307,15 +343,21 @@ discard block |
||
307 | 343 | $CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF |
308 | 344 | $INE = '|INE{'; // Only insert if stuff in ^^ is not empty |
309 | 345 | |
310 | - foreach ( $_conversion as $idx => $conversion_string ) { |
|
311 | - if ( empty( $conversion_string ) ) continue; |
|
346 | + foreach ( $_conversion as $idx => $conversion_string ) |
|
347 | + { |
|
348 | + if ( empty( $conversion_string ) ) |
|
349 | + { |
|
350 | + continue; |
|
351 | + } |
|
312 | 352 | |
313 | 353 | // fetch patterns ($rvalues) |
314 | 354 | $rvalues = array(); |
315 | 355 | $pat_reps = explode( $PSep, stripslashes( $conversion_string ) ); |
316 | - foreach( $pat_reps as $k => $pat_rep ) { |
|
356 | + foreach( $pat_reps as $k => $pat_rep ) |
|
357 | + { |
|
317 | 358 | list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 ); |
318 | - if( $replace == '' ) { |
|
359 | + if( $replace == '' ) |
|
360 | + { |
|
319 | 361 | $replace = $pattern; $pattern = '^.*$'; |
320 | 362 | } |
321 | 363 | $rvalues[$pattern] = $replace; // replace two with only one, added by the form |
@@ -325,19 +367,23 @@ discard block |
||
325 | 367 | $val = array_key_exists( $idx, $_record ) ? $_record[$idx] : ''; |
326 | 368 | |
327 | 369 | $c_functions = array('cat', 'account', 'strtotime', 'list'); |
328 | - if($_cclass) { |
|
370 | + if($_cclass) |
|
371 | + { |
|
329 | 372 | // Add in additional methods |
330 | 373 | $reflection = new ReflectionClass(get_class($_cclass)); |
331 | 374 | $methods = $reflection->getMethods(ReflectionMethod::IS_STATIC); |
332 | - foreach($methods as $method) { |
|
375 | + foreach($methods as $method) |
|
376 | + { |
|
333 | 377 | $c_functions[] = $method->name; |
334 | 378 | } |
335 | 379 | } |
336 | 380 | $c_functions = implode('|', $c_functions); |
337 | - foreach ( $rvalues as $pattern => $replace ) { |
|
381 | + foreach ( $rvalues as $pattern => $replace ) |
|
382 | + { |
|
338 | 383 | // Allow to include record indexes in pattern |
339 | 384 | $reg = '/\|\[([0-9]+)\]/'; |
340 | - while( preg_match( $reg, $pattern, $vars ) ) { |
|
385 | + while( preg_match( $reg, $pattern, $vars ) ) |
|
386 | + { |
|
341 | 387 | // expand all _record fields |
342 | 388 | $pattern = str_replace( |
343 | 389 | $CPre . $vars[1] . $CPos, |
@@ -345,12 +391,14 @@ discard block |
||
345 | 391 | $pattern |
346 | 392 | ); |
347 | 393 | } |
348 | - if( preg_match('/'. (string)$pattern.'/', $val) ) { |
|
394 | + if( preg_match('/'. (string)$pattern.'/', $val) ) |
|
395 | + { |
|
349 | 396 | |
350 | 397 | $val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val ); |
351 | 398 | |
352 | 399 | $reg = '/\|\[([a-zA-Z_0-9]+)\]/'; |
353 | - while( preg_match( $reg, $val, $vars ) ) { |
|
400 | + while( preg_match( $reg, $val, $vars ) ) |
|
401 | + { |
|
354 | 402 | // expand all _record fields |
355 | 403 | $val = str_replace( |
356 | 404 | $CPre . $vars[1] . $CPos, |
@@ -377,11 +425,13 @@ discard block |
||
377 | 425 | * |
378 | 426 | * @param array $_matches |
379 | 427 | */ |
380 | - private static function c2_dispatcher( $_matches ) { |
|
428 | + private static function c2_dispatcher( $_matches ) |
|
429 | + { |
|
381 | 430 | $action = &$_matches[1]; // cat or account ... |
382 | 431 | $data = &$_matches[2]; // datas for action |
383 | 432 | |
384 | - switch ( $action ) { |
|
433 | + switch ( $action ) |
|
434 | + { |
|
385 | 435 | case 'strtotime' : |
386 | 436 | list( $string, $format ) = explode( ',', $data ); |
387 | 437 | return self::custom_strtotime( trim( $string ), trim( $format ) ); |
@@ -391,22 +441,28 @@ discard block |
||
391 | 441 | // 1 based indexing for user ease |
392 | 442 | return $exploded[$index - 1]; |
393 | 443 | default : |
394 | - if(self::$cclass && method_exists(self::$cclass, $action)) { |
|
444 | + if(self::$cclass && method_exists(self::$cclass, $action)) |
|
445 | + { |
|
395 | 446 | $class = get_class(self::$cclass); |
396 | 447 | return call_user_func("$class::$action", $data); |
397 | 448 | } |
398 | 449 | $method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' ); |
399 | - if(self::$cclass && method_exists(self::$cclass, $method)) { |
|
450 | + if(self::$cclass && method_exists(self::$cclass, $method)) |
|
451 | + { |
|
400 | 452 | $class = get_class(self::$cclass); |
401 | 453 | return call_user_func("$class::$action", $data); |
402 | - } else { |
|
454 | + } |
|
455 | + else |
|
456 | + { |
|
403 | 457 | return self::$method( $data ); |
404 | 458 | } |
405 | 459 | } |
406 | 460 | } |
407 | 461 | |
408 | - private static function strclean( $_matches ) { |
|
409 | - switch( $_matches[1] ) { |
|
462 | + private static function strclean( $_matches ) |
|
463 | + { |
|
464 | + switch( $_matches[1] ) |
|
465 | + { |
|
410 | 466 | case '|T{' : return trim( $_matches[2] ); |
411 | 467 | case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) ); |
412 | 468 | case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) ); |
@@ -423,7 +479,8 @@ discard block |
||
423 | 479 | * @param string $_appname {<appname> | all} |
424 | 480 | * @return array(<appname> => array( <type> => array(<plugin> => <title>))) |
425 | 481 | */ |
426 | - public static function get_plugins( $_appname = 'all', $_type = 'all' ) { |
|
482 | + public static function get_plugins( $_appname = 'all', $_type = 'all' ) |
|
483 | + { |
|
427 | 484 | $plugins = Api\Cache::getTree( |
428 | 485 | __CLASS__, |
429 | 486 | 'plugins', |
@@ -436,38 +493,63 @@ discard block |
||
436 | 493 | |
437 | 494 | // Testing: comment out Api\Cache call, use this |
438 | 495 | //$plugins = self::_get_plugins($appnames, $types); |
439 | - foreach($plugins as $appname => $_types) { |
|
440 | - if(!in_array($appname, $appnames)) unset($plugins[$appname]); |
|
496 | + foreach($plugins as $appname => $_types) |
|
497 | + { |
|
498 | + if(!in_array($appname, $appnames)) |
|
499 | + { |
|
500 | + unset($plugins[$appname]); |
|
501 | + } |
|
441 | 502 | } |
442 | - foreach($plugins as $appname => $types) { |
|
503 | + foreach($plugins as $appname => $types) |
|
504 | + { |
|
443 | 505 | $plugins[$appname] = array_intersect_key($plugins[$appname], $types); |
444 | 506 | } |
445 | 507 | return $plugins; |
446 | 508 | } |
447 | 509 | |
448 | - public static function _get_plugins(Array $appnames, Array $types) { |
|
510 | + public static function _get_plugins(Array $appnames, Array $types) |
|
511 | + { |
|
449 | 512 | $plugins = array(); |
450 | - foreach ($appnames as $appname) { |
|
451 | - if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
|
513 | + foreach ($appnames as $appname) |
|
514 | + { |
|
515 | + if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) |
|
516 | + { |
|
517 | + continue; |
|
518 | + } |
|
452 | 519 | |
453 | 520 | $appdir = EGW_INCLUDE_ROOT. "/$appname/inc"; |
454 | - if(!is_dir($appdir)) continue; |
|
521 | + if(!is_dir($appdir)) |
|
522 | + { |
|
523 | + continue; |
|
524 | + } |
|
455 | 525 | $d = dir($appdir); |
456 | 526 | |
457 | 527 | // step through each file in appdir |
458 | - while (false !== ($entry = $d->read())) { |
|
528 | + while (false !== ($entry = $d->read())) |
|
529 | + { |
|
459 | 530 | // Blacklisted? |
460 | - if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) continue; |
|
461 | - if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue; |
|
531 | + if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) |
|
532 | + { |
|
533 | + continue; |
|
534 | + } |
|
535 | + if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) |
|
536 | + { |
|
537 | + continue; |
|
538 | + } |
|
462 | 539 | $classname = $matches[1]; |
463 | 540 | $file = $appdir. '/'. $entry; |
464 | 541 | |
465 | - foreach ($types as $type) { |
|
466 | - if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue; |
|
542 | + foreach ($types as $type) |
|
543 | + { |
|
544 | + if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) |
|
545 | + { |
|
546 | + continue; |
|
547 | + } |
|
467 | 548 | require_once($file); |
468 | 549 | $reflectionClass = new ReflectionClass($classname); |
469 | 550 | if($reflectionClass->IsInstantiable() && |
470 | - $reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) { |
|
551 | + $reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) |
|
552 | + { |
|
471 | 553 | try { |
472 | 554 | $plugin_object = new $classname; |
473 | 555 | } |
@@ -482,7 +564,8 @@ discard block |
||
482 | 564 | $d->close(); |
483 | 565 | |
484 | 566 | $config = Api\Config::read('importexport'); |
485 | - if($config['update'] == 'auto') { |
|
567 | + if($config['update'] == 'auto') |
|
568 | + { |
|
486 | 569 | self::load_defaults($appname); |
487 | 570 | } |
488 | 571 | } |
@@ -496,38 +579,56 @@ discard block |
||
496 | 579 | * @param string $_type |
497 | 580 | * @return array $num => $appname |
498 | 581 | */ |
499 | - public static function get_apps($_type, $ignore_acl = false) { |
|
582 | + public static function get_apps($_type, $ignore_acl = false) |
|
583 | + { |
|
500 | 584 | $apps = array_keys(self::get_plugins('all',$_type)); |
501 | - if($ignore_acl) return $apps; |
|
585 | + if($ignore_acl) |
|
586 | + { |
|
587 | + return $apps; |
|
588 | + } |
|
502 | 589 | |
503 | - foreach($apps as $key => $app) { |
|
504 | - if(!self::has_definitions($app, $_type)) unset($apps[$key]); |
|
590 | + foreach($apps as $key => $app) |
|
591 | + { |
|
592 | + if(!self::has_definitions($app, $_type)) |
|
593 | + { |
|
594 | + unset($apps[$key]); |
|
595 | + } |
|
505 | 596 | } |
506 | 597 | return $apps; |
507 | 598 | } |
508 | 599 | |
509 | - public static function load_defaults($appname) { |
|
600 | + public static function load_defaults($appname) |
|
601 | + { |
|
510 | 602 | // Check for new definitions to import from $appname/setup/*.xml |
511 | 603 | $appdir = EGW_INCLUDE_ROOT. "/$appname/setup"; |
512 | - if(!is_dir($appdir)) return; |
|
604 | + if(!is_dir($appdir)) |
|
605 | + { |
|
606 | + return; |
|
607 | + } |
|
513 | 608 | $d = dir($appdir); |
514 | 609 | |
515 | 610 | // step through each file in app's setup |
516 | - while (false !== ($entry = $d->read())) { |
|
611 | + while (false !== ($entry = $d->read())) |
|
612 | + { |
|
517 | 613 | $file = $appdir. '/'. $entry; |
518 | 614 | list( $filename, $extension) = explode('.',$entry); |
519 | - if ( $extension != 'xml' ) continue; |
|
615 | + if ( $extension != 'xml' ) |
|
616 | + { |
|
617 | + continue; |
|
618 | + } |
|
520 | 619 | try { |
521 | 620 | // import will skip invalid files |
522 | 621 | importexport_definitions_bo::import( $file ); |
523 | - } catch (Exception $e) { |
|
622 | + } |
|
623 | + catch (Exception $e) { |
|
524 | 624 | error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage()); |
525 | 625 | } |
526 | 626 | } |
527 | 627 | $d->close(); |
528 | 628 | } |
529 | 629 | |
530 | - public static function guess_filetype( $_file ) { |
|
630 | + public static function guess_filetype( $_file ) |
|
631 | + { |
|
531 | 632 | |
532 | 633 | } |
533 | 634 | |
@@ -538,7 +639,8 @@ discard block |
||
538 | 639 | * @param string $_type {import | export | all} |
539 | 640 | * @return boolean |
540 | 641 | */ |
541 | - public static function has_definitions( $_appname = 'all', $_type = 'all' ) { |
|
642 | + public static function has_definitions( $_appname = 'all', $_type = 'all' ) |
|
643 | + { |
|
542 | 644 | $definitions = Api\Cache::getSession( |
543 | 645 | __CLASS__, |
544 | 646 | 'has_definitions', |
@@ -552,27 +654,36 @@ discard block |
||
552 | 654 | // Testing: Comment out cache call above, use this |
553 | 655 | //$definitions = self::_has_definitions($appnames, $types); |
554 | 656 | |
555 | - foreach($definitions as $appname => $_types) { |
|
556 | - if(!in_array($appname, $appnames)) unset($definitions[$appname]); |
|
657 | + foreach($definitions as $appname => $_types) |
|
658 | + { |
|
659 | + if(!in_array($appname, $appnames)) |
|
660 | + { |
|
661 | + unset($definitions[$appname]); |
|
662 | + } |
|
557 | 663 | } |
558 | - foreach($definitions as $appname => $_types) { |
|
664 | + foreach($definitions as $appname => $_types) |
|
665 | + { |
|
559 | 666 | $definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types)); |
560 | 667 | } |
561 | 668 | return count($definitions[$appname]) > 0; |
562 | 669 | } |
563 | 670 | |
564 | 671 | // Api\Cache needs this public |
565 | - public static function _has_definitions(Array $appnames, Array $types) { |
|
672 | + public static function _has_definitions(Array $appnames, Array $types) |
|
673 | + { |
|
566 | 674 | $def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types)); |
567 | 675 | $list = array(); |
568 | - foreach((array)$def->get_definitions() as $id) { |
|
676 | + foreach((array)$def->get_definitions() as $id) |
|
677 | + { |
|
569 | 678 | // Need to instanciate it to check, but if the user doesn't have permission, it throws an exception |
570 | 679 | try { |
571 | 680 | $definition = new importexport_definition($id); |
572 | - if($def->is_permitted($definition->get_record_array())) { |
|
681 | + if($def->is_permitted($definition->get_record_array())) |
|
682 | + { |
|
573 | 683 | $list[$definition->application][$definition->type][] = $id; |
574 | 684 | } |
575 | - } catch (Exception $e) { |
|
685 | + } |
|
686 | + catch (Exception $e) { |
|
576 | 687 | // That one doesn't work, keep going |
577 | 688 | } |
578 | 689 | $definition = null; |
@@ -601,13 +712,22 @@ discard block |
||
601 | 712 | $plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name(); |
602 | 713 | $plugin_name = get_class($plugin); |
603 | 714 | |
604 | - if($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
605 | - if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname); |
|
715 | + if($record_classname == null) |
|
716 | + { |
|
717 | + $record_classname = $plugin::get_egw_record_class(); |
|
718 | + } |
|
719 | + if(!class_exists($record_classname)) |
|
720 | + { |
|
721 | + throw new Exception('Bad class name ' . $record_classname); |
|
722 | + } |
|
606 | 723 | |
607 | 724 | if(!$wizard_plugin) |
608 | 725 | { |
609 | 726 | $wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name); |
610 | - if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name); |
|
727 | + if(!class_exists($wizard_name)) |
|
728 | + { |
|
729 | + throw new Exception('Bad wizard name ' . $wizard_name); |
|
730 | + } |
|
611 | 731 | $wizard_plugin = new $wizard_name; |
612 | 732 | } |
613 | 733 | } |
@@ -627,7 +747,10 @@ discard block |
||
627 | 747 | foreach($record_classname::$types as $type => $type_fields) |
628 | 748 | { |
629 | 749 | // Only these for now, until filter methods for others are figured out |
630 | - if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue; |
|
750 | + if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) |
|
751 | + { |
|
752 | + continue; |
|
753 | + } |
|
631 | 754 | foreach($type_fields as $field_name) |
632 | 755 | { |
633 | 756 | $fields[$field_name] = array( |
@@ -645,14 +768,18 @@ discard block |
||
645 | 768 | $fields['#'.$field_name] = $settings; |
646 | 769 | } |
647 | 770 | |
648 | - foreach($fields as $field_name => &$settings) { |
|
771 | + foreach($fields as $field_name => &$settings) |
|
772 | + { |
|
649 | 773 | // Can't really filter on these (or at least no generic, sane way figured out yet) |
650 | 774 | if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea'))) |
651 | 775 | { |
652 | 776 | unset($fields[$field_name]); |
653 | 777 | continue; |
654 | 778 | } |
655 | - if($settings['type'] == 'radio') $settings['type'] = 'select'; |
|
779 | + if($settings['type'] == 'radio') |
|
780 | + { |
|
781 | + $settings['type'] = 'select'; |
|
782 | + } |
|
656 | 783 | switch($settings['type']) |
657 | 784 | { |
658 | 785 | case 'checkbox': |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | return $plugins; |
446 | 446 | } |
447 | 447 | |
448 | - public static function _get_plugins(Array $appnames, Array $types) { |
|
448 | + public static function _get_plugins(array $appnames, array $types) { |
|
449 | 449 | $plugins = array(); |
450 | 450 | foreach ($appnames as $appname) { |
451 | 451 | if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | } |
563 | 563 | |
564 | 564 | // Api\Cache needs this public |
565 | - public static function _has_definitions(Array $appnames, Array $types) { |
|
565 | + public static function _has_definitions(array $appnames, array $types) { |
|
566 | 566 | $def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types)); |
567 | 567 | $list = array(); |
568 | 568 | foreach((array)$def->get_definitions() as $id) { |
@@ -35,6 +35,7 @@ discard block |
||
35 | 35 | * reads record from backend if identifier is given. |
36 | 36 | * |
37 | 37 | * @param string $_identifier |
38 | + * @return void |
|
38 | 39 | */ |
39 | 40 | public function __construct( $_identifier='' ); |
40 | 41 | |
@@ -50,6 +51,7 @@ discard block |
||
50 | 51 | * |
51 | 52 | * @param string $_attribute_name |
52 | 53 | * @param data $data |
54 | + * @return void |
|
53 | 55 | */ |
54 | 56 | public function __set($_attribute_name, $data); |
55 | 57 | |
@@ -126,6 +128,7 @@ discard block |
||
126 | 128 | /** |
127 | 129 | * destructor |
128 | 130 | * |
131 | + * @return void |
|
129 | 132 | */ |
130 | 133 | public function __destruct(); |
131 | 134 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param string $_identifier |
38 | 38 | */ |
39 | - public function __construct( $_identifier='' ); |
|
39 | + public function __construct($_identifier = ''); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * magic method to set attributes of record |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return string identifier |
99 | 99 | */ |
100 | - public function save ( $_dst_identifier ); |
|
100 | + public function save($_dst_identifier); |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * copys current record to record identified by $_dst_identifier |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string $_dst_identifier |
106 | 106 | * @return string dst_identifier |
107 | 107 | */ |
108 | - public function copy ( $_dst_identifier ); |
|
108 | + public function copy($_dst_identifier); |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * moves current record to record identified by $_dst_identifier |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @param string $_dst_identifier |
115 | 115 | * @return string dst_identifier |
116 | 116 | */ |
117 | - public function move ( $_dst_identifier ); |
|
117 | + public function move($_dst_identifier); |
|
118 | 118 | |
119 | 119 | /** |
120 | 120 | * delets current record from backend |
121 | 121 | * @return void |
122 | 122 | * |
123 | 123 | */ |
124 | - public function delete (); |
|
124 | + public function delete(); |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * destructor |
@@ -107,7 +107,7 @@ |
||
107 | 107 | * and automatic conversions. In most cases they are named <appname>_egw_record, |
108 | 108 | * but projectmanager is an exception to this. |
109 | 109 | * |
110 | - * @return string; |
|
110 | + * @return string |
|
111 | 111 | */ |
112 | 112 | public static function get_egw_record_class(); |
113 | 113 | } // end of iface_export_plugin |
@@ -34,7 +34,8 @@ |
||
34 | 34 | * |
35 | 35 | * get_selector(); //returns array |
36 | 36 | */ |
37 | -interface importexport_iface_export_plugin { |
|
37 | +interface importexport_iface_export_plugin |
|
38 | +{ |
|
38 | 39 | |
39 | 40 | /** |
40 | 41 | * exports entries according to given definition object. |
@@ -29,8 +29,8 @@ |
||
29 | 29 | /** |
30 | 30 | * imports entries according to given definition object. |
31 | 31 | * |
32 | - * @param stram $_stram |
|
33 | - * @param definition $_definition |
|
32 | + * @param stram $_stream |
|
33 | + * @param importexport_definition $_definition |
|
34 | 34 | * @return int number of successful imports |
35 | 35 | */ |
36 | 36 | public function import( $_stream, importexport_definition $_definition ); |
@@ -88,33 +88,33 @@ |
||
88 | 88 | public function get_selectors_etpl(); |
89 | 89 | |
90 | 90 | /** |
91 | - * Returns errors that were encountered during importing |
|
92 | - * Maximum of one error message per record, but you can concatenate them if you need to |
|
93 | - * |
|
94 | - * @return Array ( |
|
95 | - * record_# => error message |
|
96 | - * ) |
|
97 | - */ |
|
91 | + * Returns errors that were encountered during importing |
|
92 | + * Maximum of one error message per record, but you can concatenate them if you need to |
|
93 | + * |
|
94 | + * @return Array ( |
|
95 | + * record_# => error message |
|
96 | + * ) |
|
97 | + */ |
|
98 | 98 | public function get_errors(); |
99 | 99 | |
100 | 100 | /** |
101 | - * Returns warnings that were encountered during importing |
|
102 | - * Maximum of one warning message per record, but you can concatenate them if you need to |
|
103 | - * |
|
104 | - * @return Array ( |
|
105 | - * record_# => warning message |
|
106 | - * ) |
|
107 | - */ |
|
101 | + * Returns warnings that were encountered during importing |
|
102 | + * Maximum of one warning message per record, but you can concatenate them if you need to |
|
103 | + * |
|
104 | + * @return Array ( |
|
105 | + * record_# => warning message |
|
106 | + * ) |
|
107 | + */ |
|
108 | 108 | public function get_warnings(); |
109 | 109 | |
110 | 110 | /** |
111 | - * Returns a list of actions taken, and the number of records for that action. |
|
112 | - * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
|
113 | - * |
|
114 | - * @return Array ( |
|
115 | - * action => record count |
|
116 | - * ) |
|
117 | - */ |
|
111 | + * Returns a list of actions taken, and the number of records for that action. |
|
112 | + * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin. |
|
113 | + * |
|
114 | + * @return Array ( |
|
115 | + * action => record count |
|
116 | + * ) |
|
117 | + */ |
|
118 | 118 | public function get_results(); |
119 | 119 | |
120 | 120 | } // end of iface_export_plugin |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @param definition $_definition |
34 | 34 | * @return int number of successful imports |
35 | 35 | */ |
36 | - public function import( $_stream, importexport_definition $_definition ); |
|
36 | + public function import($_stream, importexport_definition $_definition); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Reads entries, and presents them back as they will be understood |
@@ -24,7 +24,8 @@ |
||
24 | 24 | * So this interface just garanties the interaction with userinterfaces. It |
25 | 25 | * has nothing to do with datatypes. |
26 | 26 | */ |
27 | -interface importexport_iface_import_plugin { |
|
27 | +interface importexport_iface_import_plugin |
|
28 | +{ |
|
28 | 29 | |
29 | 30 | /** |
30 | 31 | * imports entries according to given definition object. |