@@ -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,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']; |
@@ -16,19 +16,19 @@ discard block |
||
16 | 16 | * should get you started on building a CSV plugin for an application fairly quickly. |
17 | 17 | * |
18 | 18 | */ |
19 | -abstract class importexport_basic_import_csv implements importexport_iface_import_plugin { |
|
19 | +abstract class importexport_basic_import_csv implements importexport_iface_import_plugin { |
|
20 | 20 | |
21 | 21 | protected static $plugin_options = array( |
22 | - 'fieldsep', // char |
|
23 | - 'charset', // string |
|
24 | - 'record_owner', // int |
|
25 | - 'update_cats', // string {override|add} overides record |
|
22 | + 'fieldsep', // char |
|
23 | + 'charset', // string |
|
24 | + 'record_owner', // int |
|
25 | + 'update_cats', // string {override|add} overides record |
|
26 | 26 | // with cat(s) from csv OR add the cat from |
27 | 27 | // csv file to exeisting cat(s) of record |
28 | 28 | 'num_header_lines', // int number of header lines |
29 | 29 | 'field_conversion', // array( $csv_col_num => conversion) |
30 | - 'field_mapping', // array( $csv_col_num => adb_filed) |
|
31 | - 'conditions', /* => array containing condition arrays: |
|
30 | + 'field_mapping', // array( $csv_col_num => adb_filed) |
|
31 | + 'conditions', /* => array containing condition arrays: |
|
32 | 32 | 'type' => exists, // exists |
33 | 33 | 'string' => '#kundennummer', |
34 | 34 | 'true' => array( |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * Actions wich could be done to data entries |
47 | 47 | * If your plugin supports different actions, be sure to modify this array |
48 | 48 | */ |
49 | - protected static $actions = array( 'none', 'update', 'insert', 'delete', ); |
|
49 | + protected static $actions = array('none', 'update', 'insert', 'delete',); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Conditions for actions |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @var array |
56 | 56 | */ |
57 | - protected static $conditions = array( 'exists', 'equal', 'less_than'); |
|
57 | + protected static $conditions = array('exists', 'equal', 'less_than'); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * This is the definition that will be used to deal with the CSV file |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param string $_charset |
120 | 120 | * @param definition $_definition |
121 | 121 | */ |
122 | - public function import( $_stream, importexport_definition $_definition ) { |
|
123 | - $import_csv = new importexport_import_csv( $_stream, array( |
|
122 | + public function import($_stream, importexport_definition $_definition) { |
|
123 | + $import_csv = new importexport_import_csv($_stream, array( |
|
124 | 124 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
125 | 125 | 'charset' => $_definition->plugin_options['charset'], |
126 | 126 | )); |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | $this->definition = $_definition; |
129 | 129 | |
130 | 130 | // user, is admin ? |
131 | - $this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin']; |
|
131 | + $this->is_admin = isset($GLOBALS['egw_info']['user']['apps']['admin']) && $GLOBALS['egw_info']['user']['apps']['admin']; |
|
132 | 132 | $this->user = $GLOBALS['egw_info']['user']['account_id']; |
133 | 133 | |
134 | 134 | // dry run? |
135 | - $this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false; |
|
135 | + $this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false; |
|
136 | 136 | |
137 | 137 | // set FieldMapping. |
138 | 138 | $import_csv->mapping = $_definition->plugin_options['field_mapping']; |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | $import_csv->conversion = $_definition->plugin_options['field_conversion']; |
142 | 142 | |
143 | 143 | //check if file has a header lines |
144 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
144 | + if (isset($_definition->plugin_options['num_header_lines']) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
145 | 145 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
146 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
146 | + } elseif (isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
147 | 147 | // First method is preferred |
148 | 148 | $import_csv->skip_records(1); |
149 | 149 | } |
@@ -165,38 +165,38 @@ discard block |
||
165 | 165 | |
166 | 166 | $this->init($_definition); |
167 | 167 | |
168 | - while ( $record = $import_csv->get_record() ) { |
|
168 | + while ($record = $import_csv->get_record()) { |
|
169 | 169 | $success = false; |
170 | 170 | |
171 | 171 | // don't import empty records |
172 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
172 | + if (count(array_unique($record)) < 2) continue; |
|
173 | 173 | |
174 | 174 | |
175 | 175 | $warning = importexport_import_csv::convert($record, $record_class::$types, $app, $this->lookups, $_definition->plugin_options['convert']); |
176 | - if($warning) $this->warnings[$import_csv->get_current_position()] = $warning; |
|
176 | + if ($warning) $this->warnings[$import_csv->get_current_position()] = $warning; |
|
177 | 177 | |
178 | 178 | $egw_record = new $record_class(); |
179 | 179 | $egw_record->set_record($record); |
180 | 180 | $success = $this->import_record($egw_record, $import_csv); |
181 | 181 | |
182 | - if($success) |
|
182 | + if ($success) |
|
183 | 183 | { |
184 | 184 | $this->do_special_fields($egw_record, $import_csv); |
185 | 185 | } |
186 | - if($success) $count++; |
|
186 | + if ($success) $count++; |
|
187 | 187 | |
188 | 188 | // Add some more time |
189 | - if($success && $import_csv->get_current_position() > 0 && $import_csv->get_current_position() % 100 == 0) |
|
189 | + if ($success && $import_csv->get_current_position() > 0 && $import_csv->get_current_position() % 100 == 0) |
|
190 | 190 | { |
191 | 191 | set_time_limit(10); |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Keep a few records for preview, but process the whole file |
195 | - if($this->dry_run && $import_csv->get_current_position() < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) |
|
195 | + if ($this->dry_run && $import_csv->get_current_position() < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) |
|
196 | 196 | { |
197 | 197 | $this->preview_records[] = $egw_record; |
198 | 198 | } |
199 | - if(count($this->warnings) > self::MAX_MESSAGES || count($this->errors) > self::MAX_MESSAGES) |
|
199 | + if (count($this->warnings) > self::MAX_MESSAGES || count($this->errors) > self::MAX_MESSAGES) |
|
200 | 200 | { |
201 | 201 | $this->errors[] = 'Too many errors, aborted'; |
202 | 202 | break; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | /** |
209 | 209 | * Stub to hook into import initialization - set lookups, etc. |
210 | 210 | */ |
211 | - protected function init(importexport_definition &$definition) |
|
211 | + protected function init(importexport_definition&$definition) |
|
212 | 212 | { |
213 | 213 | } |
214 | 214 | |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return boolean success |
224 | 224 | */ |
225 | - protected function import_record(importexport_iface_egw_record &$record, &$import_csv) |
|
225 | + protected function import_record(importexport_iface_egw_record&$record, &$import_csv) |
|
226 | 226 | { |
227 | - if ( $this->definition->plugin_options['conditions'] ) { |
|
228 | - foreach ( $this->definition->plugin_options['conditions'] as $condition ) { |
|
227 | + if ($this->definition->plugin_options['conditions']) { |
|
228 | + foreach ($this->definition->plugin_options['conditions'] as $condition) { |
|
229 | 229 | $result = false; |
230 | - switch ( $condition['type'] ) { |
|
230 | + switch ($condition['type']) { |
|
231 | 231 | // exists |
232 | 232 | case 'exists' : |
233 | 233 | // Check for that record |
@@ -243,23 +243,23 @@ discard block |
||
243 | 243 | die('condition / action not supported!!!'); |
244 | 244 | break; |
245 | 245 | } |
246 | - if($result) |
|
246 | + if ($result) |
|
247 | 247 | { |
248 | 248 | // Apply true action to any matching records found |
249 | 249 | $action = $condition['true']; |
250 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
250 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
251 | 251 | } |
252 | 252 | else |
253 | 253 | { |
254 | 254 | // Apply false action if no matching records found |
255 | 255 | $action = $condition['false']; |
256 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
256 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
257 | 257 | } |
258 | 258 | if ($action['stop']) break; |
259 | 259 | } |
260 | 260 | } else { |
261 | 261 | // unconditional insert |
262 | - $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
|
262 | + $success = $this->action('insert', $record, $import_csv->get_current_position()); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | return $success; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return boolean |
276 | 276 | */ |
277 | - protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$matches = array()) |
|
277 | + protected function exists(importexport_iface_egw_record&$record, Array &$condition, &$matches = array()) |
|
278 | 278 | { |
279 | 279 | } |
280 | 280 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return boolean |
288 | 288 | */ |
289 | - protected function equal(importexport_iface_egw_record &$record, Array &$condition) |
|
289 | + protected function equal(importexport_iface_egw_record&$record, Array &$condition) |
|
290 | 290 | { |
291 | 291 | $field = $condition['string']; |
292 | 292 | return $record->$field == $condition['op_2']; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * |
302 | 302 | * @return boolean |
303 | 303 | */ |
304 | - protected function less_than(importexport_iface_egw_record &$record, Array &$condition) |
|
304 | + protected function less_than(importexport_iface_egw_record&$record, Array &$condition) |
|
305 | 305 | { |
306 | 306 | $field = $condition['string']; |
307 | 307 | return $record->$field < $condition['op_2']; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @param int $record_num Which record number is being dealt with. Used for error messages. |
321 | 321 | * @return bool success or not |
322 | 322 | */ |
323 | - protected abstract function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 ); |
|
323 | + protected abstract function action($_action, importexport_iface_egw_record&$record, $record_num = 0); |
|
324 | 324 | |
325 | 325 | /** |
326 | 326 | * Handle special fields |
@@ -330,51 +330,51 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @param importexport_iface_egw_record $record |
332 | 332 | */ |
333 | - protected function do_special_fields(importexport_iface_egw_record &$record, &$import_csv) |
|
333 | + protected function do_special_fields(importexport_iface_egw_record&$record, &$import_csv) |
|
334 | 334 | { |
335 | 335 | $id = $record->get_identifier(); |
336 | 336 | |
337 | 337 | // Warn if there's no ID unless it's a dry_run because there probably won't be an ID then |
338 | - if(!$this->dry_run && !$id) |
|
338 | + if (!$this->dry_run && !$id) |
|
339 | 339 | { |
340 | 340 | $this->warnings[$import_csv->get_current_position()] .= "Unable to link, no identifier for record"; |
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - foreach(self::$special_fields as $field => $desc) { |
|
345 | - if(!$record->$field) continue; |
|
346 | - if(strpos($field, 'link') === 0) { |
|
347 | - list($app, $app_id) = explode(':', $record->$field,2); |
|
344 | + foreach (self::$special_fields as $field => $desc) { |
|
345 | + if (!$record->$field) continue; |
|
346 | + if (strpos($field, 'link') === 0) { |
|
347 | + list($app, $app_id) = explode(':', $record->$field, 2); |
|
348 | 348 | |
349 | - list($link, $type) = explode('_',$field); |
|
349 | + list($link, $type) = explode('_', $field); |
|
350 | 350 | |
351 | 351 | // Searching, take first result |
352 | - if($type == 'custom') |
|
352 | + if ($type == 'custom') |
|
353 | 353 | { |
354 | 354 | $app_id = $this->link_by_cf($record, $app, $app_id, $import_csv->get_current_position()); |
355 | 355 | } |
356 | - else if($type == 'search') |
|
356 | + else if ($type == 'search') |
|
357 | 357 | { |
358 | 358 | $result = egw_link::query($app, $app_id); |
359 | 359 | do |
360 | 360 | { |
361 | 361 | $app_id = key($result); |
362 | 362 | shift($result); |
363 | - } while($result && !$app_id); |
|
363 | + } while ($result && !$app_id); |
|
364 | 364 | } |
365 | 365 | } else if (in_array($field, array_keys($GLOBALS['egw_info']['apps']))) { |
366 | 366 | $app = $field; |
367 | 367 | $app_id = $record->$field; |
368 | 368 | |
369 | 369 | // Searching, take first result |
370 | - if(!is_numeric($app_id)) |
|
370 | + if (!is_numeric($app_id)) |
|
371 | 371 | { |
372 | 372 | $result = egw_link::query($app, $app_id); |
373 | 373 | do |
374 | 374 | { |
375 | 375 | $app_id = key($result); |
376 | 376 | shift($result); |
377 | - } while($result && !$app_id); |
|
377 | + } while ($result && !$app_id); |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | else if ($field == 'contact') |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | } |
386 | 386 | if (!$this->dry_run && $app && $app_id && ($app != $this->definition->application || $app_id != $id)) |
387 | 387 | { |
388 | - $link_id = egw_link::link($this->definition->application,$id,$app,$app_id); |
|
388 | + $link_id = egw_link::link($this->definition->application, $id, $app, $app_id); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | } |
@@ -402,13 +402,13 @@ discard block |
||
402 | 402 | * @param importexport_definition $definition |
403 | 403 | * @return String HTML for preview |
404 | 404 | */ |
405 | - public function preview( $stream, importexport_definition $definition ) |
|
405 | + public function preview($stream, importexport_definition $definition) |
|
406 | 406 | { |
407 | 407 | $this->import($stream, $definition); |
408 | 408 | rewind($stream); |
409 | 409 | |
410 | 410 | // Set up result |
411 | - $rows = array('h1'=>array(),'f1'=>array(),'.h1'=>'class=th'); |
|
411 | + $rows = array('h1'=>array(), 'f1'=>array(), '.h1'=>'class=th'); |
|
412 | 412 | |
413 | 413 | // Load labels for app |
414 | 414 | $record_class = get_class($this->preview_records[0]); |
@@ -417,27 +417,27 @@ discard block |
||
417 | 417 | $labels = array_combine($definition->plugin_options['field_mapping'], $definition->plugin_options['field_mapping']); |
418 | 418 | |
419 | 419 | $plugin = get_called_class(); |
420 | - $wizard_name = $definition->application . '_wizard_' . str_replace($definition->application . '_', '', $plugin); |
|
420 | + $wizard_name = $definition->application.'_wizard_'.str_replace($definition->application.'_', '', $plugin); |
|
421 | 421 | try { |
422 | 422 | $wizard = new $wizard_name; |
423 | 423 | $fields = $wizard->get_import_fields(); |
424 | - foreach($labels as $field => &$label) |
|
424 | + foreach ($labels as $field => &$label) |
|
425 | 425 | { |
426 | - if($fields[$field]) $label = $fields[$field]; |
|
426 | + if ($fields[$field]) $label = $fields[$field]; |
|
427 | 427 | } |
428 | 428 | } catch (Exception $e) { |
429 | 429 | translation::add_app($definition->application); |
430 | - foreach($labels as $field => &$label) { |
|
430 | + foreach ($labels as $field => &$label) { |
|
431 | 431 | $label = lang($label); |
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | 435 | // Set up HTML |
436 | 436 | $rows['h1'] = $labels; |
437 | - foreach($this->preview_records as $i => $row_data) |
|
437 | + foreach ($this->preview_records as $i => $row_data) |
|
438 | 438 | { |
439 | 439 | // Convert to human-friendly |
440 | - importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups); |
|
440 | + importexport_export_csv::convert($row_data, $record_class::$types, $definition->application, $this->lookups); |
|
441 | 441 | $this->row_preview($row_data); |
442 | 442 | $rows[] = $row_data->get_record_array(); |
443 | 443 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @param egw_record $row_entry |
453 | 453 | */ |
454 | - protected function row_preview(importexport_iface_egw_record &$row_entry) |
|
454 | + protected function row_preview(importexport_iface_egw_record&$row_entry) |
|
455 | 455 | { |
456 | 456 | } |
457 | 457 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | * @param string $org_name |
467 | 467 | * @return int|boolean Contact ID of first match, or false if none found |
468 | 468 | */ |
469 | - public static function addr_id( $n_family,$n_given=null,$org_name=null, &$record=null) { |
|
469 | + public static function addr_id($n_family, $n_given = null, $org_name = null, &$record = null) { |
|
470 | 470 | |
471 | 471 | // find in Addressbook, at least n_family AND (n_given OR org_name) have to match |
472 | 472 | static $contacts; |
@@ -476,18 +476,18 @@ discard block |
||
476 | 476 | list($n_family, $n_given, $org_name) = explode(',', $n_family); |
477 | 477 | } |
478 | 478 | $n_family = trim($n_family); |
479 | - if(!is_null($n_given)) $n_given = trim($n_given); |
|
479 | + if (!is_null($n_given)) $n_given = trim($n_given); |
|
480 | 480 | if (!is_object($contacts)) |
481 | 481 | { |
482 | - $contacts =& CreateObject('phpgwapi.contacts'); |
|
482 | + $contacts = & CreateObject('phpgwapi.contacts'); |
|
483 | 483 | } |
484 | 484 | if (!is_null($org_name)) // org_name given? |
485 | 485 | { |
486 | 486 | $org_name = trim($org_name); |
487 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); |
|
487 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_family=$n_family,n_given=$n_given,org_name=$org_name"); |
|
488 | 488 | if (!count($addrs)) |
489 | 489 | { |
490 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name",'','n_family,org_name'); |
|
490 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_family=$n_family,org_name=$org_name", '', 'n_family,org_name'); |
|
491 | 491 | } |
492 | 492 | } |
493 | 493 | if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) // first name given and no result so far |
@@ -496,11 +496,11 @@ discard block |
||
496 | 496 | } |
497 | 497 | if (is_null($n_given) && is_null($org_name)) // just one name given, check against fn (= full name) |
498 | 498 | { |
499 | - $addrs = $contacts->read( 0,0,array('id'),'',"n_fn=$n_family",'','n_fn' ); |
|
499 | + $addrs = $contacts->read(0, 0, array('id'), '', "n_fn=$n_family", '', 'n_fn'); |
|
500 | 500 | } |
501 | 501 | if (count($addrs)) |
502 | 502 | { |
503 | - if(!$record || !$record->get_identifier()) |
|
503 | + if (!$record || !$record->get_identifier()) |
|
504 | 504 | { |
505 | 505 | return $addrs[0]['id']; |
506 | 506 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | { |
511 | 511 | $id = key($addrs); |
512 | 512 | array_shift($addrs); |
513 | - } while($addrs && !$id && $id == $record->get_identifier()); |
|
513 | + } while ($addrs && !$id && $id == $record->get_identifier()); |
|
514 | 514 | return $id; |
515 | 515 | } |
516 | 516 | } |
@@ -525,22 +525,22 @@ discard block |
||
525 | 525 | * @param string $app Target application name |
526 | 526 | * @param string $value CSV value in the form of custom_field_name:value |
527 | 527 | */ |
528 | - protected function link_by_cf(importexport_iface_egw_record &$record, $app, $value,$record_num) |
|
528 | + protected function link_by_cf(importexport_iface_egw_record&$record, $app, $value, $record_num) |
|
529 | 529 | { |
530 | 530 | $app_id = false; |
531 | 531 | |
532 | - list($custom_field, $value) = explode(':',$value); |
|
532 | + list($custom_field, $value) = explode(':', $value); |
|
533 | 533 | // Find matching entry |
534 | - if($app && $custom_field && $value) |
|
534 | + if ($app && $custom_field && $value) |
|
535 | 535 | { |
536 | 536 | $cfs = config::get_customfields($app); |
537 | 537 | // Error if no custom fields, probably something wrong in definition |
538 | - if(!$cfs[$custom_field]) |
|
538 | + if (!$cfs[$custom_field]) |
|
539 | 539 | { |
540 | 540 | // Check for users specifing label instead of name |
541 | - foreach($cfs as $name => $settings) |
|
541 | + foreach ($cfs as $name => $settings) |
|
542 | 542 | { |
543 | - if(strtolower($settings['label']) == strtolower($custom_field)) |
|
543 | + if (strtolower($settings['label']) == strtolower($custom_field)) |
|
544 | 544 | { |
545 | 545 | $custom_field = $name; |
546 | 546 | break; |
@@ -549,30 +549,30 @@ discard block |
||
549 | 549 | } |
550 | 550 | |
551 | 551 | // Couldn't find field, give an error - something's wrong |
552 | - if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)]) { |
|
552 | + if (!$cfs[$custom_field] && !$cfs[substr($custom_field, 1)]) { |
|
553 | 553 | $this->errors[$record_num] .= lang('No custom field "%1" for %2.', |
554 | 554 | $custom_field, lang($app)); |
555 | 555 | return false; |
556 | 556 | } |
557 | - if($custom_field[0] != '#') $custom_field = '#' . $custom_field; |
|
557 | + if ($custom_field[0] != '#') $custom_field = '#'.$custom_field; |
|
558 | 558 | error_log("Searching for $custom_field = $value"); |
559 | 559 | // Search |
560 | - if(egw_link::get_registry($app, 'query')) |
|
560 | + if (egw_link::get_registry($app, 'query')) |
|
561 | 561 | { |
562 | - $options = array('filter' => array("$custom_field = " . $GLOBALS['egw']->db->quote($value))); |
|
562 | + $options = array('filter' => array("$custom_field = ".$GLOBALS['egw']->db->quote($value))); |
|
563 | 563 | $result = egw_link::query($app, '', $options); |
564 | 564 | |
565 | 565 | // Only one allowed |
566 | - if($record->get_identifier()) |
|
566 | + if ($record->get_identifier()) |
|
567 | 567 | { |
568 | - while(key($result) == $record->get_identifier()) |
|
568 | + while (key($result) == $record->get_identifier()) |
|
569 | 569 | { |
570 | 570 | array_shift($result); |
571 | 571 | } |
572 | 572 | } |
573 | - if(count($result) != 1) |
|
573 | + if (count($result) != 1) |
|
574 | 574 | { |
575 | - $this->warnings[$record_num] .= ($this->warnings[$record_num] ? "\n" : '') . |
|
575 | + $this->warnings[$record_num] .= ($this->warnings[$record_num] ? "\n" : ''). |
|
576 | 576 | lang('Unable to link to %3 by custom field "%1": "%4". %2 matches.', |
577 | 577 | $custom_field, count($result), lang($app), $options['filter'][0] |
578 | 578 | ); |
@@ -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; |
@@ -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 |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @param string $_identifier |
65 | 65 | */ |
66 | - public function __construct( $_identifier='' ) { |
|
67 | - $this->so_sql = new so_sql(self::_appname ,self::_defintion_talbe); |
|
66 | + public function __construct($_identifier = '') { |
|
67 | + $this->so_sql = new so_sql(self::_appname, self::_defintion_talbe); |
|
68 | 68 | $this->user = $GLOBALS['egw_info']['user']['user_id']; |
69 | 69 | $this->is_admin = $GLOBALS['egw_info']['user']['apps']['admin'] || $GLOBALS['egw_setup'] ? true : false; |
70 | 70 | // compability to string identifiers |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | |
73 | 73 | if ((int)$_identifier != 0) { |
74 | 74 | $this->definition = $this->so_sql->read(array('definition_id' => $_identifier)); |
75 | - if ( empty( $this->definition ) ) { |
|
75 | + if (empty($this->definition)) { |
|
76 | 76 | throw new Exception('Error: No such definition with identifier :"'.$_identifier.'"!'); |
77 | 77 | } |
78 | - if ( !( importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) { |
|
78 | + if (!(importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) { |
|
79 | 79 | throw new Exception('Error: User "'.$this->user.'" is not permitted to get definition with identifier "'.$_identifier.'"!'); |
80 | 80 | } |
81 | 81 | try |
82 | 82 | { |
83 | - $options_data = importexport_arrayxml::xml2array( $this->definition['plugin_options'] ); |
|
83 | + $options_data = importexport_arrayxml::xml2array($this->definition['plugin_options']); |
|
84 | 84 | $this->definition['plugin_options'] = $options_data['root']; |
85 | - if($this->definition['filter']) $filter = importexport_arrayxml::xml2array( $this->definition['filter'] ); |
|
85 | + if ($this->definition['filter']) $filter = importexport_arrayxml::xml2array($this->definition['filter']); |
|
86 | 86 | $this->definition['filter'] = $filter['root']; |
87 | 87 | } |
88 | 88 | catch (Exception $e) |
@@ -98,22 +98,22 @@ discard block |
||
98 | 98 | * @param string $_name |
99 | 99 | * @return int |
100 | 100 | */ |
101 | - private function name2identifier( $_name ) { |
|
102 | - $identifiers = $this->so_sql->search(array('name' => $_name),true); |
|
101 | + private function name2identifier($_name) { |
|
102 | + $identifiers = $this->so_sql->search(array('name' => $_name), true); |
|
103 | 103 | if (isset($identifiers[1])) { |
104 | - throw new Exception('Error: Definition: "'.$_name. '" is not unique! Can\'t convert to identifier'); |
|
104 | + throw new Exception('Error: Definition: "'.$_name.'" is not unique! Can\'t convert to identifier'); |
|
105 | 105 | } |
106 | - if ( empty( $identifiers[0] ) ) { |
|
106 | + if (empty($identifiers[0])) { |
|
107 | 107 | // not a good idea, till we don't have different exceptions so far |
108 | 108 | // throw new Exception('Error: No such definition :"'.$_name.'"!'); |
109 | - $identifiers = array( array( 'definition_id' => 0 ) ); |
|
109 | + $identifiers = array(array('definition_id' => 0)); |
|
110 | 110 | } |
111 | 111 | return $identifiers[0]['definition_id']; |
112 | 112 | } |
113 | 113 | |
114 | 114 | public function __get($_attribute_name) { |
115 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
116 | - throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
|
115 | + if (!array_key_exists($_attribute_name, $this->attributes)) { |
|
116 | + throw new Exception('Error: "'.$_attribute_name.'" is not an attribute defintion'); |
|
117 | 117 | } |
118 | 118 | switch ($_attribute_name) { |
119 | 119 | case 'allowed_users' : |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
130 | - public function __set($_attribute_name,$_data) { |
|
131 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
132 | - throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
|
130 | + public function __set($_attribute_name, $_data) { |
|
131 | + if (!array_key_exists($_attribute_name, $this->attributes)) { |
|
132 | + throw new Exception('Error: "'.$_attribute_name.'" is not an attribute defintion'); |
|
133 | 133 | } |
134 | 134 | switch ($_attribute_name) { |
135 | 135 | case 'allowed_users' : |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return array |
151 | 151 | */ |
152 | 152 | private function get_allowed_users() { |
153 | - return explode(',',substr($this->definition['allowed_users'],1,-1)); |
|
153 | + return explode(',', substr($this->definition['allowed_users'], 1, -1)); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @param array $_allowed_users |
160 | 160 | */ |
161 | - private function set_allowed_users( $_allowed_users ) { |
|
162 | - $this->definition['allowed_users'] = ','.implode(',',(array)$_allowed_users) .','; |
|
161 | + private function set_allowed_users($_allowed_users) { |
|
162 | + $this->definition['allowed_users'] = ','.implode(',', (array)$_allowed_users).','; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return void |
230 | 230 | */ |
231 | - public function set_record( array $_record ) { |
|
232 | - $this->definition = array_intersect_key( $_record, $this->attributes ); |
|
231 | + public function set_record(array $_record) { |
|
232 | + $this->definition = array_intersect_key($_record, $this->attributes); |
|
233 | 233 | |
234 | 234 | // anything which is not an attribute is perhaps a plugin_option. |
235 | 235 | // If not, it gets whiped out on save time. |
236 | - foreach ( $_record as $attribute => $value) { |
|
237 | - if ( !array_key_exists( $attribute, $this->attributes ) ) { |
|
236 | + foreach ($_record as $attribute => $value) { |
|
237 | + if (!array_key_exists($attribute, $this->attributes)) { |
|
238 | 238 | $this->definition['plugin_options'][$attribute] = $value; |
239 | 239 | } |
240 | 240 | } |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | $this->plugin = $_record['plugin']; |
243 | 243 | |
244 | 244 | // convert plugin_options into internal representation |
245 | - $this->set_allowed_users( $this->definition['allowed_users'] ); |
|
246 | - $this->set_options( $this->definition['plugin_options'] ? $this->definition['plugin_options'] : array()); |
|
247 | - $this->set_filter( $this->definition['filter'] ? $this->definition['filter'] : array()); |
|
245 | + $this->set_allowed_users($this->definition['allowed_users']); |
|
246 | + $this->set_options($this->definition['plugin_options'] ? $this->definition['plugin_options'] : array()); |
|
247 | + $this->set_filter($this->definition['filter'] ? $this->definition['filter'] : array()); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @return string Full URL of an icon, or appname/icon_name |
265 | 265 | */ |
266 | 266 | public function get_icon() { |
267 | - return self::_appname . '/navbar'; |
|
267 | + return self::_appname.'/navbar'; |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -272,16 +272,16 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return string identifier |
274 | 274 | */ |
275 | - public function save ( $_dst_identifier ) { |
|
276 | - if ( strlen($this->definition['name']) < 3 ) { |
|
275 | + public function save($_dst_identifier) { |
|
276 | + if (strlen($this->definition['name']) < 3) { |
|
277 | 277 | throw new Exception('Error: Can\'t save definition, no valid name given!'); |
278 | 278 | } |
279 | 279 | |
280 | 280 | $this->so_sql->data = $this->definition; |
281 | - $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml( $this->definition['plugin_options'] ); |
|
282 | - $this->so_sql->data['filter'] = importexport_arrayxml::array2xml( $this->definition['filter'] ); |
|
281 | + $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml($this->definition['plugin_options']); |
|
282 | + $this->so_sql->data['filter'] = importexport_arrayxml::array2xml($this->definition['filter']); |
|
283 | 283 | $this->so_sql->data['modified'] = time(); |
284 | - if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) { |
|
284 | + if ($this->so_sql->save(array('definition_id' => $_dst_identifier))) { |
|
285 | 285 | throw new Exception('Error: so_sql was not able to save definition: '.$this->get_identifier()); |
286 | 286 | } |
287 | 287 | |
@@ -294,13 +294,13 @@ discard block |
||
294 | 294 | * @param string $_dst_identifier |
295 | 295 | * @return string dst_identifier |
296 | 296 | */ |
297 | - public function copy ( $_dst_identifier ) { |
|
297 | + public function copy($_dst_identifier) { |
|
298 | 298 | $dst_object = clone $this; |
299 | 299 | try { |
300 | 300 | $dst_object->set_owner($this->user); |
301 | 301 | $dst_identifier = $dst_object->save($_dst_identifier); |
302 | 302 | } |
303 | - catch(exception $Exception) { |
|
303 | + catch (exception $Exception) { |
|
304 | 304 | unset($dst_object); |
305 | 305 | throw $Exception; |
306 | 306 | } |
@@ -315,16 +315,16 @@ discard block |
||
315 | 315 | * @param string $_dst_identifier |
316 | 316 | * @return string dst_identifier |
317 | 317 | */ |
318 | - public function move ( $_dst_identifier ) { |
|
318 | + public function move($_dst_identifier) { |
|
319 | 319 | if ($this->user != $this->get_owner() && !$this->is_admin) { |
320 | - throw('Error: User '. $this->user. 'does not have permissions to move definition '.$this->get_identifier()); |
|
320 | + throw('Error: User '.$this->user.'does not have permissions to move definition '.$this->get_identifier()); |
|
321 | 321 | } |
322 | 322 | $old_object = clone $this; |
323 | 323 | try { |
324 | 324 | $dst_identifier = $this->save($_dst_identifier); |
325 | 325 | $old_object->delete(); |
326 | 326 | } |
327 | - catch(exception $Exception) { |
|
327 | + catch (exception $Exception) { |
|
328 | 328 | unset($old_object); |
329 | 329 | throw $Exception; |
330 | 330 | } |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | * @return void |
338 | 338 | * |
339 | 339 | */ |
340 | - public function delete () { |
|
341 | - if($this->user != $this->get_owner() && !$this->is_admin) { |
|
342 | - throw('Error: User '. $this->user. 'does not have permissions to delete definition '.$this->get_identifier()); |
|
340 | + public function delete() { |
|
341 | + if ($this->user != $this->get_owner() && !$this->is_admin) { |
|
342 | + throw('Error: User '.$this->user.'does not have permissions to delete definition '.$this->get_identifier()); |
|
343 | 343 | } |
344 | - if(!$this->so_sql->delete()) { |
|
344 | + if (!$this->so_sql->delete()) { |
|
345 | 345 | throw('Error: so_sql was not able to delete definition: '.$this->get_identifier()); |
346 | 346 | } |
347 | 347 | } |
@@ -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); |
@@ -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']); |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | */ |
30 | 30 | private $definitions; |
31 | 31 | |
32 | - public function __construct($_query=false, $ignore_acl = false) |
|
32 | + public function __construct($_query = false, $ignore_acl = false) |
|
33 | 33 | { |
34 | - $this->so_sql = new so_sql(self::_appname, self::_defintion_table ); |
|
34 | + $this->so_sql = new so_sql(self::_appname, self::_defintion_table); |
|
35 | 35 | if ($_query) { |
36 | 36 | $definitions = $this->so_sql->search($_query, false); |
37 | 37 | foreach ((array)$definitions as $definition) { |
38 | - if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
38 | + if (self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | } |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | public function get_rows(&$query, &$rows, &$readonlys) |
44 | 44 | { |
45 | 45 | // Filter only definitions user is allowed to use |
46 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
46 | + if (!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
47 | 47 | $this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
48 | 48 | $this_membership[] = $GLOBALS['egw_info']['user']['account_id']; |
49 | 49 | $sql .= ' ('; |
50 | 50 | $read = array(); |
51 | - foreach($this_membership as $id) |
|
51 | + foreach ($this_membership as $id) |
|
52 | 52 | { |
53 | 53 | $read[] = 'allowed_users '. |
54 | 54 | $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '. |
55 | - $GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%'); |
|
55 | + $GLOBALS['egw']->db->quote('%,'.str_replace('_', '\\_', $id).',%'); |
|
56 | 56 | } |
57 | 57 | $sql .= implode(' OR ', $read); |
58 | 58 | $sql .= ') OR owner = '.$GLOBALS['egw_info']['user']['account_id']; |
@@ -60,37 +60,37 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | // Handle allowed filter |
63 | - if($query['col_filter']['allowed_users']) |
|
63 | + if ($query['col_filter']['allowed_users']) |
|
64 | 64 | { |
65 | 65 | $allowed = array(); |
66 | - foreach((array)$query['col_filter']['allowed_users'] as $id) |
|
66 | + foreach ((array)$query['col_filter']['allowed_users'] as $id) |
|
67 | 67 | { |
68 | 68 | $allowed[] = 'allowed_users '. |
69 | 69 | $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '. |
70 | - $GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%'); |
|
70 | + $GLOBALS['egw']->db->quote('%,'.str_replace('_', '\\_', $id).',%'); |
|
71 | 71 | } |
72 | - if($allowed) |
|
72 | + if ($allowed) |
|
73 | 73 | { |
74 | 74 | unset($query['col_filter']['allowed_users']); |
75 | - $query['col_filter'][] = '('.implode(' OR ', $allowed) . ')'; |
|
75 | + $query['col_filter'][] = '('.implode(' OR ', $allowed).')'; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | 79 | $total = $this->so_sql->get_rows($query, $rows, $readonlys); |
80 | 80 | $ro_count = 0; |
81 | - foreach($rows as &$row) { |
|
81 | + foreach ($rows as &$row) { |
|
82 | 82 | // Strip off leading + trailing , |
83 | - $row['allowed_users'] = substr($row['allowed_users'],1,-1); |
|
83 | + $row['allowed_users'] = substr($row['allowed_users'], 1, -1); |
|
84 | 84 | |
85 | 85 | $readonlys["edit[{$row['definition_id']}]"] = $readonlys["delete[{$row['definition_id']}]"] = |
86 | 86 | ($row['owner'] != $GLOBALS['egw_info']['user']['account_id']) && |
87 | 87 | !$GLOBALS['egw_info']['user']['apps']['admin']; |
88 | - if($readonlys["edit[{$row['definition_id']}]"]) |
|
88 | + if ($readonlys["edit[{$row['definition_id']}]"]) |
|
89 | 89 | { |
90 | 90 | $row['class'] .= 'rowNoEdit rowNoDelete'; |
91 | 91 | $ro_count++; |
92 | 92 | } |
93 | - $row['class'] .= ' ' . $row['type']; |
|
93 | + $row['class'] .= ' '.$row['type']; |
|
94 | 94 | } |
95 | 95 | $readonlys['delete_selected'] = $ro_count == count($rows); |
96 | 96 | return $total; |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | return $this->definitions; |
106 | 106 | } |
107 | 107 | public function read($definition_id) { |
108 | - if(is_numeric($definition_id)) { |
|
108 | + if (is_numeric($definition_id)) { |
|
109 | 109 | $this->so_sql->read($definition_id); |
110 | 110 | $definition = new importexport_definition($this->so_sql->data['name']); |
111 | 111 | } else { |
112 | - $definition = new importexport_definition( $definition_id['name'] ); |
|
112 | + $definition = new importexport_definition($definition_id['name']); |
|
113 | 113 | } |
114 | 114 | return $definition->get_record_array(); |
115 | 115 | } |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | foreach ($keys as $index => $key) { |
123 | 123 | // Check for ownership |
124 | 124 | $definition = $this->read($key); |
125 | - if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
125 | + if ($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
126 | 126 | // clear private cache |
127 | - unset($this->definitions[array_search($key,$this->definitions)]); |
|
127 | + unset($this->definitions[array_search($key, $this->definitions)]); |
|
128 | 128 | } else { |
129 | 129 | unset($keys[$index]); |
130 | 130 | } |
131 | 131 | } |
132 | - if(count($keys) > 0) { |
|
132 | + if (count($keys) > 0) { |
|
133 | 133 | $this->so_sql->delete(array('definition_id' => $keys)); |
134 | 134 | } |
135 | 135 | } |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | * @return bool |
153 | 153 | */ |
154 | 154 | static public function is_permitted($_definition) { |
155 | - $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']); |
|
155 | + $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',', $_definition['allowed_users']); |
|
156 | 156 | $this_user_id = $GLOBALS['egw_info']['user']['account_id']; |
157 | 157 | $this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true); |
158 | 158 | $this_membership[] = $this_user_id; |
159 | 159 | $this_membership[] = 'all'; |
160 | - $alluser = array_intersect($allowed_user,$this_membership); |
|
160 | + $alluser = array_intersect($allowed_user, $this_membership); |
|
161 | 161 | return ($this_user_id == $_definition['owner'] || count($alluser) > 0); |
162 | 162 | } |
163 | 163 | |
@@ -176,13 +176,13 @@ discard block |
||
176 | 176 | |
177 | 177 | $export_data['definitions'] = array(); |
178 | 178 | foreach ($keys as $definition_id) { |
179 | - $definition = new importexport_definition( $definition_id ); |
|
179 | + $definition = new importexport_definition($definition_id); |
|
180 | 180 | $export_data['definitions'][$definition->name] = $definition->get_record_array(); |
181 | 181 | $export_data['definitions'][$definition->name]['allowed_users'] = |
182 | 182 | importexport_helper_functions::account_id2name( |
183 | 183 | $export_data['definitions'][$definition->name]['allowed_users'] |
184 | 184 | ); |
185 | - if($export_date['definitions'][$definition->name]['owner']) { |
|
185 | + if ($export_date['definitions'][$definition->name]['owner']) { |
|
186 | 186 | $export_data['definitions'][$definition->name]['owner'] = |
187 | 187 | importexport_helper_functions::account_id2name( |
188 | 188 | $export_data['definitions'][$definition->name]['owner'] |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | unset($export_data['definitions'][$definition->name]['definition_id']); |
194 | 194 | unset($export_data['definitions'][$definition->name]['description']); |
195 | 195 | unset($export_data['definitions'][$definition->name]['user_timezone_read']); |
196 | - if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
196 | + if (is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
197 | 197 | unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']); |
198 | 198 | } |
199 | 199 | unset($definition); |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | * @throws Exeption |
212 | 212 | * @return void |
213 | 213 | */ |
214 | - public static function import( $_import_file ) |
|
214 | + public static function import($_import_file) |
|
215 | 215 | { |
216 | - if ( !is_file( $_import_file ) ) { |
|
217 | - throw new Exception("'$_import_file' does not exist or is not readable" ); |
|
216 | + if (!is_file($_import_file)) { |
|
217 | + throw new Exception("'$_import_file' does not exist or is not readable"); |
|
218 | 218 | } |
219 | 219 | |
220 | - $data = importexport_arrayxml::xml2array( file_get_contents( $_import_file ) ); |
|
220 | + $data = importexport_arrayxml::xml2array(file_get_contents($_import_file)); |
|
221 | 221 | |
222 | 222 | $metainfo = $data['importExportDefinitions']['metainfo']; |
223 | 223 | $definitions = $data['importExportDefinitions']['definitions']; |
224 | - unset ( $data ); |
|
224 | + unset ($data); |
|
225 | 225 | |
226 | 226 | // convert charset into internal used charset |
227 | 227 | $definitions = translation::convert( |
@@ -231,26 +231,26 @@ discard block |
||
231 | 231 | ); |
232 | 232 | |
233 | 233 | // Avoid warning if no definitions found |
234 | - if(!is_array($definitions)) return lang('None found'); |
|
234 | + if (!is_array($definitions)) return lang('None found'); |
|
235 | 235 | |
236 | 236 | // save definition(s) into internal table |
237 | - foreach ( $definitions as $name => $definition_data ) |
|
237 | + foreach ($definitions as $name => $definition_data) |
|
238 | 238 | { |
239 | 239 | // convert allowed_user |
240 | - $definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] ); |
|
241 | - if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
240 | + $definition_data['allowed_users'] = importexport_helper_functions::account_name2id($definition_data['allowed_users']); |
|
241 | + if ($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
242 | 242 | |
243 | - $definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] ); |
|
243 | + $definition_data['owner'] = importexport_helper_functions::account_name2id($definition_data['owner']); |
|
244 | 244 | |
245 | - $definition = new importexport_definition( $definition_data['name'] ); |
|
245 | + $definition = new importexport_definition($definition_data['name']); |
|
246 | 246 | |
247 | 247 | // Only update if the imported is newer |
248 | - if(strtotime($definition->modified) < strtotime($definition_data['modified']) || $definition->modified == 0) |
|
248 | + if (strtotime($definition->modified) < strtotime($definition_data['modified']) || $definition->modified == 0) |
|
249 | 249 | { |
250 | 250 | $definition_id = $definition->get_identifier() ? $definition->get_identifier() : NULL; |
251 | 251 | |
252 | - $definition->set_record( $definition_data ); |
|
253 | - $definition->save( $definition_id ); |
|
252 | + $definition->set_record($definition_data); |
|
253 | + $definition->save($definition_id); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | return $definitions; |
@@ -273,28 +273,28 @@ discard block |
||
273 | 273 | public static function export_from_import(importexport_definition $import) |
274 | 274 | { |
275 | 275 | // Only operates on import definitions |
276 | - if($import->type != 'import') throw new egw_exception_wrong_parameter('Only import definitions'); |
|
276 | + if ($import->type != 'import') throw new egw_exception_wrong_parameter('Only import definitions'); |
|
277 | 277 | |
278 | 278 | // Find export plugin |
279 | - $plugin = str_replace('import', 'export',$import->plugin); |
|
279 | + $plugin = str_replace('import', 'export', $import->plugin); |
|
280 | 280 | $plugin_list = importexport_helper_functions::get_plugins($import->application, 'export'); |
281 | - foreach($plugin_list as $appname => $type) |
|
281 | + foreach ($plugin_list as $appname => $type) |
|
282 | 282 | { |
283 | 283 | $plugins = $type['export']; |
284 | - foreach($plugins as $name => $label) |
|
284 | + foreach ($plugins as $name => $label) |
|
285 | 285 | { |
286 | - if($plugin == $name) break; |
|
286 | + if ($plugin == $name) break; |
|
287 | 287 | } |
288 | - if($plugin !== $name) $plugin = $name; |
|
288 | + if ($plugin !== $name) $plugin = $name; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | $export = new importexport_definition(); |
292 | 292 | |
293 | 293 | // Common settings |
294 | - $export->name = str_replace('import', 'export',$import->name); |
|
295 | - if($export->name == $import->name) $export->name = $export->name . '-export'; |
|
294 | + $export->name = str_replace('import', 'export', $import->name); |
|
295 | + if ($export->name == $import->name) $export->name = $export->name.'-export'; |
|
296 | 296 | $test = new importexport_definition($export->name); |
297 | - if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
297 | + if ($test->name) $export->name = $export->name.'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
298 | 298 | |
299 | 299 | $export->application = $import->application; |
300 | 300 | $export->plugin = $plugin; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | ); |
311 | 311 | |
312 | 312 | // Mapping |
313 | - foreach($i_options['field_mapping'] as $col_num => $field) |
|
313 | + foreach ($i_options['field_mapping'] as $col_num => $field) |
|
314 | 314 | { |
315 | 315 | // Try to use heading from import file, if possible |
316 | 316 | $e_options['mapping'][$field] = $i_options['csv_fields'][$col_num] ? $i_options['csv_fields'][$col_num] : $field; |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @todo make this class an egw_record_pool! |
16 | 16 | */ |
17 | -class importexport_definitions_bo { |
|
17 | +class importexport_definitions_bo |
|
18 | +{ |
|
18 | 19 | |
19 | 20 | const _appname = 'importexport'; |
20 | 21 | const _defintion_table = 'egw_importexport_definitions'; |
@@ -32,10 +33,15 @@ discard block |
||
32 | 33 | public function __construct($_query=false, $ignore_acl = false) |
33 | 34 | { |
34 | 35 | $this->so_sql = new so_sql(self::_appname, self::_defintion_table ); |
35 | - if ($_query) { |
|
36 | + if ($_query) |
|
37 | + { |
|
36 | 38 | $definitions = $this->so_sql->search($_query, false); |
37 | - foreach ((array)$definitions as $definition) { |
|
38 | - if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
39 | + foreach ((array)$definitions as $definition) |
|
40 | + { |
|
41 | + if(self::is_permitted($definition) || $ignore_acl) |
|
42 | + { |
|
43 | + $this->definitions[] = $definition['definition_id']; |
|
44 | + } |
|
39 | 45 | } |
40 | 46 | } |
41 | 47 | } |
@@ -43,7 +49,8 @@ discard block |
||
43 | 49 | public function get_rows(&$query, &$rows, &$readonlys) |
44 | 50 | { |
45 | 51 | // Filter only definitions user is allowed to use |
46 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
52 | + if(!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
53 | + { |
|
47 | 54 | $this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
48 | 55 | $this_membership[] = $GLOBALS['egw_info']['user']['account_id']; |
49 | 56 | $sql .= ' ('; |
@@ -78,7 +85,8 @@ discard block |
||
78 | 85 | |
79 | 86 | $total = $this->so_sql->get_rows($query, $rows, $readonlys); |
80 | 87 | $ro_count = 0; |
81 | - foreach($rows as &$row) { |
|
88 | + foreach($rows as &$row) |
|
89 | + { |
|
82 | 90 | // Strip off leading + trailing , |
83 | 91 | $row['allowed_users'] = substr($row['allowed_users'],1,-1); |
84 | 92 | |
@@ -101,14 +109,19 @@ discard block |
||
101 | 109 | * |
102 | 110 | * @return array |
103 | 111 | */ |
104 | - public function get_definitions() { |
|
112 | + public function get_definitions() |
|
113 | + { |
|
105 | 114 | return $this->definitions; |
106 | 115 | } |
107 | - public function read($definition_id) { |
|
108 | - if(is_numeric($definition_id)) { |
|
116 | + public function read($definition_id) |
|
117 | + { |
|
118 | + if(is_numeric($definition_id)) |
|
119 | + { |
|
109 | 120 | $this->so_sql->read($definition_id); |
110 | 121 | $definition = new importexport_definition($this->so_sql->data['name']); |
111 | - } else { |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
112 | 125 | $definition = new importexport_definition( $definition_id['name'] ); |
113 | 126 | } |
114 | 127 | return $definition->get_record_array(); |
@@ -118,18 +131,24 @@ discard block |
||
118 | 131 | * |
119 | 132 | * @param array $keys |
120 | 133 | */ |
121 | - public function delete($keys) { |
|
122 | - foreach ($keys as $index => $key) { |
|
134 | + public function delete($keys) |
|
135 | + { |
|
136 | + foreach ($keys as $index => $key) |
|
137 | + { |
|
123 | 138 | // Check for ownership |
124 | 139 | $definition = $this->read($key); |
125 | - if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
140 | + if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) |
|
141 | + { |
|
126 | 142 | // clear private cache |
127 | 143 | unset($this->definitions[array_search($key,$this->definitions)]); |
128 | - } else { |
|
144 | + } |
|
145 | + else |
|
146 | + { |
|
129 | 147 | unset($keys[$index]); |
130 | 148 | } |
131 | 149 | } |
132 | - if(count($keys) > 0) { |
|
150 | + if(count($keys) > 0) |
|
151 | + { |
|
133 | 152 | $this->so_sql->delete(array('definition_id' => $keys)); |
134 | 153 | } |
135 | 154 | } |
@@ -139,7 +158,8 @@ discard block |
||
139 | 158 | * |
140 | 159 | * @param definition $definition |
141 | 160 | */ |
142 | - public function save(Array $data) { |
|
161 | + public function save(Array $data) |
|
162 | + { |
|
143 | 163 | $definition = new importexport_definition(); |
144 | 164 | $definition->set_record($data); |
145 | 165 | $definition->save($data['definition_id']); |
@@ -151,7 +171,8 @@ discard block |
||
151 | 171 | * @param array $_definition |
152 | 172 | * @return bool |
153 | 173 | */ |
154 | - static public function is_permitted($_definition) { |
|
174 | + static public function is_permitted($_definition) |
|
175 | + { |
|
155 | 176 | $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']); |
156 | 177 | $this_user_id = $GLOBALS['egw_info']['user']['account_id']; |
157 | 178 | $this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true); |
@@ -175,25 +196,30 @@ discard block |
||
175 | 196 | )); |
176 | 197 | |
177 | 198 | $export_data['definitions'] = array(); |
178 | - foreach ($keys as $definition_id) { |
|
199 | + foreach ($keys as $definition_id) |
|
200 | + { |
|
179 | 201 | $definition = new importexport_definition( $definition_id ); |
180 | 202 | $export_data['definitions'][$definition->name] = $definition->get_record_array(); |
181 | 203 | $export_data['definitions'][$definition->name]['allowed_users'] = |
182 | 204 | importexport_helper_functions::account_id2name( |
183 | 205 | $export_data['definitions'][$definition->name]['allowed_users'] |
184 | 206 | ); |
185 | - if($export_date['definitions'][$definition->name]['owner']) { |
|
207 | + if($export_date['definitions'][$definition->name]['owner']) |
|
208 | + { |
|
186 | 209 | $export_data['definitions'][$definition->name]['owner'] = |
187 | 210 | importexport_helper_functions::account_id2name( |
188 | 211 | $export_data['definitions'][$definition->name]['owner'] |
189 | 212 | ); |
190 | - } else { |
|
213 | + } |
|
214 | + else |
|
215 | + { |
|
191 | 216 | unset($export_data['definitions'][$definition->name]['owner']); |
192 | 217 | } |
193 | 218 | unset($export_data['definitions'][$definition->name]['definition_id']); |
194 | 219 | unset($export_data['definitions'][$definition->name]['description']); |
195 | 220 | unset($export_data['definitions'][$definition->name]['user_timezone_read']); |
196 | - if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
221 | + if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) |
|
222 | + { |
|
197 | 223 | unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']); |
198 | 224 | } |
199 | 225 | unset($definition); |
@@ -213,7 +239,8 @@ discard block |
||
213 | 239 | */ |
214 | 240 | public static function import( $_import_file ) |
215 | 241 | { |
216 | - if ( !is_file( $_import_file ) ) { |
|
242 | + if ( !is_file( $_import_file ) ) |
|
243 | + { |
|
217 | 244 | throw new Exception("'$_import_file' does not exist or is not readable" ); |
218 | 245 | } |
219 | 246 | |
@@ -231,14 +258,20 @@ discard block |
||
231 | 258 | ); |
232 | 259 | |
233 | 260 | // Avoid warning if no definitions found |
234 | - if(!is_array($definitions)) return lang('None found'); |
|
261 | + if(!is_array($definitions)) |
|
262 | + { |
|
263 | + return lang('None found'); |
|
264 | + } |
|
235 | 265 | |
236 | 266 | // save definition(s) into internal table |
237 | 267 | foreach ( $definitions as $name => $definition_data ) |
238 | 268 | { |
239 | 269 | // convert allowed_user |
240 | 270 | $definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] ); |
241 | - if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
271 | + if($definition_data['all_users'] && !$definition_data['allowed_users']) |
|
272 | + { |
|
273 | + $definition_data['allowed_users'] = 'all'; |
|
274 | + } |
|
242 | 275 | |
243 | 276 | $definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] ); |
244 | 277 | |
@@ -273,7 +306,10 @@ discard block |
||
273 | 306 | public static function export_from_import(importexport_definition $import) |
274 | 307 | { |
275 | 308 | // Only operates on import definitions |
276 | - if($import->type != 'import') throw new egw_exception_wrong_parameter('Only import definitions'); |
|
309 | + if($import->type != 'import') |
|
310 | + { |
|
311 | + throw new egw_exception_wrong_parameter('Only import definitions'); |
|
312 | + } |
|
277 | 313 | |
278 | 314 | // Find export plugin |
279 | 315 | $plugin = str_replace('import', 'export',$import->plugin); |
@@ -283,18 +319,30 @@ discard block |
||
283 | 319 | $plugins = $type['export']; |
284 | 320 | foreach($plugins as $name => $label) |
285 | 321 | { |
286 | - if($plugin == $name) break; |
|
322 | + if($plugin == $name) |
|
323 | + { |
|
324 | + break; |
|
325 | + } |
|
326 | + } |
|
327 | + if($plugin !== $name) |
|
328 | + { |
|
329 | + $plugin = $name; |
|
287 | 330 | } |
288 | - if($plugin !== $name) $plugin = $name; |
|
289 | 331 | } |
290 | 332 | |
291 | 333 | $export = new importexport_definition(); |
292 | 334 | |
293 | 335 | // Common settings |
294 | 336 | $export->name = str_replace('import', 'export',$import->name); |
295 | - if($export->name == $import->name) $export->name = $export->name . '-export'; |
|
337 | + if($export->name == $import->name) |
|
338 | + { |
|
339 | + $export->name = $export->name . '-export'; |
|
340 | + } |
|
296 | 341 | $test = new importexport_definition($export->name); |
297 | - if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
342 | + if($test->name) |
|
343 | + { |
|
344 | + $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
345 | + } |
|
298 | 346 | |
299 | 347 | $export->application = $import->application; |
300 | 348 | $export->plugin = $plugin; |
@@ -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) { |
@@ -94,22 +94,22 @@ discard block |
||
94 | 94 | * @param array _options options for specific backends |
95 | 95 | * @return bool |
96 | 96 | */ |
97 | - public function __construct( $_stream, array $_options ) { |
|
97 | + public function __construct($_stream, array $_options) { |
|
98 | 98 | if (!is_object($GLOBALS['egw']->translation)) { |
99 | 99 | $GLOBALS['egw']->translation = new translation(); |
100 | 100 | } |
101 | 101 | $this->translation = &$GLOBALS['egw']->translation; |
102 | 102 | $this->handle = $_stream; |
103 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
103 | + if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
104 | 104 | $this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8'; |
105 | - if ( !empty( $_options ) ) { |
|
106 | - $this->csv_options = array_merge( $this->csv_options, $_options ); |
|
105 | + if (!empty($_options)) { |
|
106 | + $this->csv_options = array_merge($this->csv_options, $_options); |
|
107 | 107 | } |
108 | 108 | //error_log(__METHOD__.__LINE__.array2string($_options['appname'])); |
109 | - if(!bo_merge::is_export_limit_excepted()) { |
|
109 | + if (!bo_merge::is_export_limit_excepted()) { |
|
110 | 110 | $this->export_limit = bo_merge::getExportLimit($_options['appname']); |
111 | 111 | //error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit); |
112 | - if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled'); |
|
112 | + if ($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled'); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -118,15 +118,15 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param array $_mapping egw_field_name => csv_field_name |
120 | 120 | */ |
121 | - public function set_mapping( array &$_mapping) { |
|
121 | + public function set_mapping(array &$_mapping) { |
|
122 | 122 | if ($this->num_of_records > 0) { |
123 | 123 | throw new Exception('Error: Field mapping can\'t be set during ongoing export!'); |
124 | 124 | } |
125 | - if($_mapping['all_custom_fields']) { |
|
125 | + if ($_mapping['all_custom_fields']) { |
|
126 | 126 | // Field value is the appname, so we can pull the fields |
127 | 127 | $custom = config::get_customfields($_mapping['all_custom_fields']); |
128 | 128 | unset($_mapping['all_custom_fields']); |
129 | - foreach($custom as $field => $info) { |
|
129 | + foreach ($custom as $field => $info) { |
|
130 | 130 | $_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field; |
131 | 131 | } |
132 | 132 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param array $_conversion |
141 | 141 | */ |
142 | - public function set_conversion( array $_conversion) { |
|
142 | + public function set_conversion(array $_conversion) { |
|
143 | 143 | $this->conversion = $_conversion; |
144 | 144 | } |
145 | 145 | |
@@ -149,59 +149,59 @@ discard block |
||
149 | 149 | * @param importexport_iface_egw_record record |
150 | 150 | * @return bool |
151 | 151 | */ |
152 | - public function export_record( importexport_iface_egw_record $_record ) { |
|
152 | + public function export_record(importexport_iface_egw_record $_record) { |
|
153 | 153 | $this->record = $_record; |
154 | 154 | $this->record_array = $_record->get_record_array(); |
155 | 155 | |
156 | 156 | // begin with fieldnames ? |
157 | - if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) { |
|
158 | - if($this->csv_options['begin_with_fieldnames'] == 'label') { |
|
157 | + if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames']) { |
|
158 | + if ($this->csv_options['begin_with_fieldnames'] == 'label') { |
|
159 | 159 | // Load translations for app |
160 | 160 | list($appname, $part2) = explode('_', get_class($_record)); |
161 | - if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name |
|
161 | + if (!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name |
|
162 | 162 | |
163 | 163 | // Get translations from wizard, if possible |
164 | - if(!$this->csv_options['no_header_translation']) |
|
164 | + if (!$this->csv_options['no_header_translation']) |
|
165 | 165 | { |
166 | 166 | $backtrace = debug_backtrace(); |
167 | 167 | $plugin = $backtrace[1]['class']; |
168 | - $wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin); |
|
168 | + $wizard_name = $appname.'_wizard_'.str_replace($appname.'_', '', $plugin); |
|
169 | 169 | try { |
170 | 170 | $wizard = new $wizard_name; |
171 | 171 | $fields = $wizard->get_export_fields(); |
172 | - foreach($this->mapping as $field => &$label) |
|
172 | + foreach ($this->mapping as $field => &$label) |
|
173 | 173 | { |
174 | - if($fields[$field]) |
|
174 | + if ($fields[$field]) |
|
175 | 175 | { |
176 | 176 | $label = $label != $fields[$field] ? $fields[$field] : lang($label); |
177 | 177 | } |
178 | 178 | // Make sure no * |
179 | - if(substr($label,-1) == '*') $label = substr($label,0,-1); |
|
179 | + if (substr($label, -1) == '*') $label = substr($label, 0, -1); |
|
180 | 180 | } |
181 | 181 | } catch (Exception $e) { |
182 | 182 | translation::add_app($appname); |
183 | - foreach($this->mapping as $field => &$label) { |
|
183 | + foreach ($this->mapping as $field => &$label) { |
|
184 | 184 | $label = lang($label); |
185 | 185 | } |
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | - $mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record_array ); |
|
190 | - self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] ); |
|
189 | + $mapping = !empty($this->mapping) ? $this->mapping : array_keys($this->record_array); |
|
190 | + self::fputcsv($this->handle, $mapping, $this->csv_options['delimiter'], $this->csv_options['enclosure']); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Check for limit |
194 | - if($this->export_limit && $this->num_of_records >= $this->export_limit) { |
|
194 | + if ($this->export_limit && $this->num_of_records >= $this->export_limit) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | 198 | // do conversions |
199 | - if ( !empty( $this->conversion )) { |
|
200 | - $this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion ); |
|
199 | + if (!empty($this->conversion)) { |
|
200 | + $this->record_array = importexport_helper_functions::conversion($this->record_array, $this->conversion); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // do fieldmapping |
204 | - if ( !empty( $this->mapping ) ) { |
|
204 | + if (!empty($this->mapping)) { |
|
205 | 205 | $record_data = $this->record_array; |
206 | 206 | $this->record_array = array(); |
207 | 207 | foreach ($this->mapping as $egw_field => $csv_field) { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] ); |
|
212 | + self::fputcsv($this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure']); |
|
213 | 213 | $this->num_of_records++; |
214 | 214 | } |
215 | 215 | |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | * @return Array of fields to be added to list of fields needing conversion |
234 | 234 | */ |
235 | 235 | public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) { |
236 | - if(!$appname) return; |
|
236 | + if (!$appname) return; |
|
237 | 237 | |
238 | 238 | $fields = array(); |
239 | 239 | $custom = config::get_customfields($appname); |
240 | - foreach($custom as $name => $c_field) { |
|
241 | - $name = '#' . $name; |
|
242 | - switch($c_field['type']) { |
|
240 | + foreach ($custom as $name => $c_field) { |
|
241 | + $name = '#'.$name; |
|
242 | + switch ($c_field['type']) { |
|
243 | 243 | case 'date': |
244 | 244 | $fields['date'][] = $name; |
245 | 245 | break; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $fields['select-account'][] = $name; |
251 | 251 | break; |
252 | 252 | case 'ajax_select': |
253 | - if($c_field['values']['get_title']) { |
|
253 | + if ($c_field['values']['get_title']) { |
|
254 | 254 | $methods[$name] = $c_field['values']['get_title']; |
255 | 255 | break; |
256 | 256 | } |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | $selects[$name] = $c_field['values']; |
265 | 265 | break; |
266 | 266 | default: |
267 | - list($type) = explode('-',$c_field['type'],2); |
|
268 | - if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) { |
|
267 | + list($type) = explode('-', $c_field['type'], 2); |
|
268 | + if (in_array($type, array_keys($GLOBALS['egw_info']['apps']))) { |
|
269 | 269 | $fields['links'][] = $name; |
270 | 270 | $links[$name] = $c_field['type']; |
271 | 271 | } |
@@ -284,18 +284,18 @@ discard block |
||
284 | 284 | * @parem fields List of field types => field names to be converted |
285 | 285 | * @param appname Current appname if you want to do custom fields too |
286 | 286 | */ |
287 | - public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
288 | - if($appname) { |
|
289 | - if(!self::$cf_parse_cache[$appname]) { |
|
287 | + public static function convert(importexport_iface_egw_record&$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
288 | + if ($appname) { |
|
289 | + if (!self::$cf_parse_cache[$appname]) { |
|
290 | 290 | $c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods); |
291 | 291 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
292 | 292 | } |
293 | 293 | list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname]; |
294 | 294 | |
295 | 295 | // Add in any fields that are keys to another app |
296 | - foreach((array)$fields['links'] as $link_field => $app) |
|
296 | + foreach ((array)$fields['links'] as $link_field => $app) |
|
297 | 297 | { |
298 | - if(is_numeric($link_field)) continue; |
|
298 | + if (is_numeric($link_field)) continue; |
|
299 | 299 | $links[$link_field] = $app; |
300 | 300 | // Set it as a normal link field |
301 | 301 | $fields['links'][] = $link_field; |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | // Not quite a recursive merge, since only one level |
306 | - foreach($fields as $type => &$list) { |
|
307 | - if($c_fields[$type]) { |
|
306 | + foreach ($fields as $type => &$list) { |
|
307 | + if ($c_fields[$type]) { |
|
308 | 308 | $list = array_merge($c_fields[$type], $list); |
309 | 309 | unset($c_fields[$type]); |
310 | 310 | } |
@@ -312,12 +312,12 @@ discard block |
||
312 | 312 | $fields += $c_fields; |
313 | 313 | $selects += $c_selects; |
314 | 314 | } |
315 | - foreach((array)$fields['select'] as $name) { |
|
316 | - if($record->$name != null && is_array($selects) && $selects[$name]) { |
|
315 | + foreach ((array)$fields['select'] as $name) { |
|
316 | + if ($record->$name != null && is_array($selects) && $selects[$name]) { |
|
317 | 317 | $record->$name = explode(',', $record->$name); |
318 | - if(is_array($record->$name)) { |
|
318 | + if (is_array($record->$name)) { |
|
319 | 319 | $names = array(); |
320 | - foreach($record->$name as $_name) { |
|
320 | + foreach ($record->$name as $_name) { |
|
321 | 321 | $names[] = lang($selects[$name][$_name]); |
322 | 322 | } |
323 | 323 | $record->$name = implode(', ', $names); |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | $record->$name = ''; |
331 | 331 | } |
332 | 332 | } |
333 | - foreach((array)$fields['links'] as $name) { |
|
334 | - if($record->$name) { |
|
335 | - if(is_numeric($record->$name) && !$links[$name]) { |
|
333 | + foreach ((array)$fields['links'] as $name) { |
|
334 | + if ($record->$name) { |
|
335 | + if (is_numeric($record->$name) && !$links[$name]) { |
|
336 | 336 | $link = egw_link::get_link($record->$name); |
337 | 337 | $links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']); |
338 | 338 | $record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']); |
339 | 339 | } |
340 | - if($links[$name]) { |
|
340 | + if ($links[$name]) { |
|
341 | 341 | $record->$name = egw_link::title($links[$name], $record->$name); |
342 | 342 | } |
343 | 343 | } |
@@ -346,12 +346,12 @@ discard block |
||
346 | 346 | $record->$name = ''; |
347 | 347 | } |
348 | 348 | } |
349 | - foreach((array)$fields['select-account'] as $name) { |
|
349 | + foreach ((array)$fields['select-account'] as $name) { |
|
350 | 350 | // Compare against null to deal with empty arrays |
351 | 351 | if ($record->$name !== null) { |
352 | - if(is_array($record->$name)) { |
|
352 | + if (is_array($record->$name)) { |
|
353 | 353 | $names = array(); |
354 | - foreach($record->$name as $_name) { |
|
354 | + foreach ($record->$name as $_name) { |
|
355 | 355 | $names[] = common::grab_owner_name($_name); |
356 | 356 | } |
357 | 357 | $record->$name = implode(', ', $names); |
@@ -364,64 +364,64 @@ discard block |
||
364 | 364 | $record->$name = ''; |
365 | 365 | } |
366 | 366 | } |
367 | - foreach((array)$fields['select-bool'] as $name) { |
|
368 | - if($record->$name !== null) { |
|
367 | + foreach ((array)$fields['select-bool'] as $name) { |
|
368 | + if ($record->$name !== null) { |
|
369 | 369 | $record->$name = $record->$name ? lang('Yes') : lang('No'); |
370 | 370 | } |
371 | 371 | } |
372 | - foreach((array)$fields['date-time'] as $name) { |
|
372 | + foreach ((array)$fields['date-time'] as $name) { |
|
373 | 373 | //if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format |
374 | 374 | if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
375 | - if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. |
|
376 | - ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format |
|
375 | + if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '. |
|
376 | + ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'), $record->$name); // User date format |
|
377 | 377 | if (!$record->$name) $record->$name = ''; |
378 | 378 | } |
379 | - foreach((array)$fields['date'] as $name) { |
|
379 | + foreach ((array)$fields['date'] as $name) { |
|
380 | 380 | //if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format |
381 | 381 | if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
382 | 382 | if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format |
383 | 383 | if (!$record->$name) $record->$name = ''; |
384 | 384 | } |
385 | - foreach((array)$fields['float'] as $name) |
|
385 | + foreach ((array)$fields['float'] as $name) |
|
386 | 386 | { |
387 | - static $dec_separator,$thousands_separator; |
|
387 | + static $dec_separator, $thousands_separator; |
|
388 | 388 | if (is_null($dec_separator)) |
389 | 389 | { |
390 | 390 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
391 | 391 | if (empty($dec_separator)) $dec_separator = '.'; |
392 | 392 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
393 | 393 | } |
394 | - if($record->$name && (string)$record->$name != '') |
|
394 | + if ($record->$name && (string)$record->$name != '') |
|
395 | 395 | { |
396 | - if(!is_numeric($record->$name)) |
|
396 | + if (!is_numeric($record->$name)) |
|
397 | 397 | { |
398 | 398 | $record->$name = floatval(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator).']/', '', $record->$name))); |
399 | 399 | } |
400 | - $record->$name = number_format(str_replace(' ','',$record->$name), 2, |
|
401 | - $dec_separator,$thousands_separator |
|
400 | + $record->$name = number_format(str_replace(' ', '', $record->$name), 2, |
|
401 | + $dec_separator, $thousands_separator |
|
402 | 402 | ); |
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | 406 | // Some custom methods for conversion |
407 | - foreach((array)$methods as $name => $method) { |
|
408 | - if($record->$name) $record->$name = ExecMethod($method, $record->$name); |
|
407 | + foreach ((array)$methods as $name => $method) { |
|
408 | + if ($record->$name) $record->$name = ExecMethod($method, $record->$name); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | static $cat_object; |
412 | - if(is_null($cat_object)) $cat_object = new categories(false,$appname); |
|
413 | - foreach((array)$fields['select-cat'] as $name) { |
|
414 | - if($record->$name) { |
|
412 | + if (is_null($cat_object)) $cat_object = new categories(false, $appname); |
|
413 | + foreach ((array)$fields['select-cat'] as $name) { |
|
414 | + if ($record->$name) { |
|
415 | 415 | $cats = array(); |
416 | 416 | $ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name); |
417 | - foreach($ids as $n => $cat_id) { |
|
417 | + foreach ($ids as $n => $cat_id) { |
|
418 | 418 | |
419 | - if ($cat_id && $cat_object->check_perms(EGW_ACL_READ,$cat_id)) |
|
419 | + if ($cat_id && $cat_object->check_perms(EGW_ACL_READ, $cat_id)) |
|
420 | 420 | { |
421 | 421 | $cats[] = $cat_object->id2name($cat_id); |
422 | 422 | } |
423 | 423 | } |
424 | - $record->$name = implode(', ',$cats); |
|
424 | + $record->$name = implode(', ', $cats); |
|
425 | 425 | } |
426 | 426 | else |
427 | 427 | { |
@@ -448,18 +448,18 @@ discard block |
||
448 | 448 | * @param char $delimiter |
449 | 449 | * @param char $enclosure |
450 | 450 | */ |
451 | - protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){ |
|
451 | + protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) { |
|
452 | 452 | $string = ""; |
453 | 453 | $writeDelimiter = false; |
454 | - foreach($dataArray as $dataElement) { |
|
455 | - if($writeDelimiter) $string .= $delimiter; |
|
456 | - $string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure; |
|
454 | + foreach ($dataArray as $dataElement) { |
|
455 | + if ($writeDelimiter) $string .= $delimiter; |
|
456 | + $string .= $enclosure.str_replace(array("\r\n", '"'), array("\n", '""'), $dataElement).$enclosure; |
|
457 | 457 | $writeDelimiter = true; |
458 | 458 | } |
459 | 459 | $string .= "\n"; |
460 | 460 | |
461 | 461 | // do charset translation |
462 | - $string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset ); |
|
462 | + $string = $this->translation->convert($string, $this->translation->charset(), $this->csv_charset); |
|
463 | 463 | |
464 | 464 | fwrite($filePointer, $string); |
465 | 465 |
@@ -94,22 +94,32 @@ discard block |
||
94 | 94 | * @param array _options options for specific backends |
95 | 95 | * @return bool |
96 | 96 | */ |
97 | - public function __construct( $_stream, array $_options ) { |
|
98 | - if (!is_object($GLOBALS['egw']->translation)) { |
|
97 | + public function __construct( $_stream, array $_options ) |
|
98 | + { |
|
99 | + if (!is_object($GLOBALS['egw']->translation)) |
|
100 | + { |
|
99 | 101 | $GLOBALS['egw']->translation = new translation(); |
100 | 102 | } |
101 | 103 | $this->translation = &$GLOBALS['egw']->translation; |
102 | 104 | $this->handle = $_stream; |
103 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
105 | + if($_options['charset'] == 'user') |
|
106 | + { |
|
107 | + $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
108 | + } |
|
104 | 109 | $this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8'; |
105 | - if ( !empty( $_options ) ) { |
|
110 | + if ( !empty( $_options ) ) |
|
111 | + { |
|
106 | 112 | $this->csv_options = array_merge( $this->csv_options, $_options ); |
107 | 113 | } |
108 | 114 | //error_log(__METHOD__.__LINE__.array2string($_options['appname'])); |
109 | - if(!bo_merge::is_export_limit_excepted()) { |
|
115 | + if(!bo_merge::is_export_limit_excepted()) |
|
116 | + { |
|
110 | 117 | $this->export_limit = bo_merge::getExportLimit($_options['appname']); |
111 | 118 | //error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit); |
112 | - if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled'); |
|
119 | + if($this->export_limit == 'no') |
|
120 | + { |
|
121 | + throw new egw_exception_no_permission_admin('Export disabled'); |
|
122 | + } |
|
113 | 123 | } |
114 | 124 | } |
115 | 125 | |
@@ -118,15 +128,19 @@ discard block |
||
118 | 128 | * |
119 | 129 | * @param array $_mapping egw_field_name => csv_field_name |
120 | 130 | */ |
121 | - public function set_mapping( array &$_mapping) { |
|
122 | - if ($this->num_of_records > 0) { |
|
131 | + public function set_mapping( array &$_mapping) |
|
132 | + { |
|
133 | + if ($this->num_of_records > 0) |
|
134 | + { |
|
123 | 135 | throw new Exception('Error: Field mapping can\'t be set during ongoing export!'); |
124 | 136 | } |
125 | - if($_mapping['all_custom_fields']) { |
|
137 | + if($_mapping['all_custom_fields']) |
|
138 | + { |
|
126 | 139 | // Field value is the appname, so we can pull the fields |
127 | 140 | $custom = config::get_customfields($_mapping['all_custom_fields']); |
128 | 141 | unset($_mapping['all_custom_fields']); |
129 | - foreach($custom as $field => $info) { |
|
142 | + foreach($custom as $field => $info) |
|
143 | + { |
|
130 | 144 | $_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field; |
131 | 145 | } |
132 | 146 | } |
@@ -139,7 +153,8 @@ discard block |
||
139 | 153 | * |
140 | 154 | * @param array $_conversion |
141 | 155 | */ |
142 | - public function set_conversion( array $_conversion) { |
|
156 | + public function set_conversion( array $_conversion) |
|
157 | + { |
|
143 | 158 | $this->conversion = $_conversion; |
144 | 159 | } |
145 | 160 | |
@@ -149,16 +164,23 @@ discard block |
||
149 | 164 | * @param importexport_iface_egw_record record |
150 | 165 | * @return bool |
151 | 166 | */ |
152 | - public function export_record( importexport_iface_egw_record $_record ) { |
|
167 | + public function export_record( importexport_iface_egw_record $_record ) |
|
168 | + { |
|
153 | 169 | $this->record = $_record; |
154 | 170 | $this->record_array = $_record->get_record_array(); |
155 | 171 | |
156 | 172 | // begin with fieldnames ? |
157 | - if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) { |
|
158 | - if($this->csv_options['begin_with_fieldnames'] == 'label') { |
|
173 | + if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) |
|
174 | + { |
|
175 | + if($this->csv_options['begin_with_fieldnames'] == 'label') |
|
176 | + { |
|
159 | 177 | // Load translations for app |
160 | 178 | list($appname, $part2) = explode('_', get_class($_record)); |
161 | - if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name |
|
179 | + if(!$GLOBALS['egw_info']['apps'][$appname]) |
|
180 | + { |
|
181 | + $appname .= $part2; |
|
182 | + } |
|
183 | + // Handle apps with _ in the name |
|
162 | 184 | |
163 | 185 | // Get translations from wizard, if possible |
164 | 186 | if(!$this->csv_options['no_header_translation']) |
@@ -176,11 +198,16 @@ discard block |
||
176 | 198 | $label = $label != $fields[$field] ? $fields[$field] : lang($label); |
177 | 199 | } |
178 | 200 | // Make sure no * |
179 | - if(substr($label,-1) == '*') $label = substr($label,0,-1); |
|
201 | + if(substr($label,-1) == '*') |
|
202 | + { |
|
203 | + $label = substr($label,0,-1); |
|
204 | + } |
|
180 | 205 | } |
181 | - } catch (Exception $e) { |
|
206 | + } |
|
207 | + catch (Exception $e) { |
|
182 | 208 | translation::add_app($appname); |
183 | - foreach($this->mapping as $field => &$label) { |
|
209 | + foreach($this->mapping as $field => &$label) |
|
210 | + { |
|
184 | 211 | $label = lang($label); |
185 | 212 | } |
186 | 213 | } |
@@ -191,20 +218,24 @@ discard block |
||
191 | 218 | } |
192 | 219 | |
193 | 220 | // Check for limit |
194 | - if($this->export_limit && $this->num_of_records >= $this->export_limit) { |
|
221 | + if($this->export_limit && $this->num_of_records >= $this->export_limit) |
|
222 | + { |
|
195 | 223 | return; |
196 | 224 | } |
197 | 225 | |
198 | 226 | // do conversions |
199 | - if ( !empty( $this->conversion )) { |
|
227 | + if ( !empty( $this->conversion )) |
|
228 | + { |
|
200 | 229 | $this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion ); |
201 | 230 | } |
202 | 231 | |
203 | 232 | // do fieldmapping |
204 | - if ( !empty( $this->mapping ) ) { |
|
233 | + if ( !empty( $this->mapping ) ) |
|
234 | + { |
|
205 | 235 | $record_data = $this->record_array; |
206 | 236 | $this->record_array = array(); |
207 | - foreach ($this->mapping as $egw_field => $csv_field) { |
|
237 | + foreach ($this->mapping as $egw_field => $csv_field) |
|
238 | + { |
|
208 | 239 | $this->record_array[$csv_field] = $record_data[$egw_field]; |
209 | 240 | } |
210 | 241 | } |
@@ -218,7 +249,8 @@ discard block |
||
218 | 249 | * |
219 | 250 | * @return int |
220 | 251 | */ |
221 | - public function get_num_of_records() { |
|
252 | + public function get_num_of_records() |
|
253 | + { |
|
222 | 254 | return $this->num_of_records; |
223 | 255 | } |
224 | 256 | |
@@ -232,14 +264,20 @@ discard block |
||
232 | 264 | * |
233 | 265 | * @return Array of fields to be added to list of fields needing conversion |
234 | 266 | */ |
235 | - public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) { |
|
236 | - if(!$appname) return; |
|
267 | + public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) |
|
268 | + { |
|
269 | + if(!$appname) |
|
270 | + { |
|
271 | + return; |
|
272 | + } |
|
237 | 273 | |
238 | 274 | $fields = array(); |
239 | 275 | $custom = config::get_customfields($appname); |
240 | - foreach($custom as $name => $c_field) { |
|
276 | + foreach($custom as $name => $c_field) |
|
277 | + { |
|
241 | 278 | $name = '#' . $name; |
242 | - switch($c_field['type']) { |
|
279 | + switch($c_field['type']) |
|
280 | + { |
|
243 | 281 | case 'date': |
244 | 282 | $fields['date'][] = $name; |
245 | 283 | break; |
@@ -250,7 +288,8 @@ discard block |
||
250 | 288 | $fields['select-account'][] = $name; |
251 | 289 | break; |
252 | 290 | case 'ajax_select': |
253 | - if($c_field['values']['get_title']) { |
|
291 | + if($c_field['values']['get_title']) |
|
292 | + { |
|
254 | 293 | $methods[$name] = $c_field['values']['get_title']; |
255 | 294 | break; |
256 | 295 | } |
@@ -265,7 +304,8 @@ discard block |
||
265 | 304 | break; |
266 | 305 | default: |
267 | 306 | list($type) = explode('-',$c_field['type'],2); |
268 | - if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) { |
|
307 | + if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) |
|
308 | + { |
|
269 | 309 | $fields['links'][] = $name; |
270 | 310 | $links[$name] = $c_field['type']; |
271 | 311 | } |
@@ -284,9 +324,12 @@ discard block |
||
284 | 324 | * @parem fields List of field types => field names to be converted |
285 | 325 | * @param appname Current appname if you want to do custom fields too |
286 | 326 | */ |
287 | - public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) { |
|
288 | - if($appname) { |
|
289 | - if(!self::$cf_parse_cache[$appname]) { |
|
327 | + public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) |
|
328 | + { |
|
329 | + if($appname) |
|
330 | + { |
|
331 | + if(!self::$cf_parse_cache[$appname]) |
|
332 | + { |
|
290 | 333 | $c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods); |
291 | 334 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
292 | 335 | } |
@@ -295,7 +338,10 @@ discard block |
||
295 | 338 | // Add in any fields that are keys to another app |
296 | 339 | foreach((array)$fields['links'] as $link_field => $app) |
297 | 340 | { |
298 | - if(is_numeric($link_field)) continue; |
|
341 | + if(is_numeric($link_field)) |
|
342 | + { |
|
343 | + continue; |
|
344 | + } |
|
299 | 345 | $links[$link_field] = $app; |
300 | 346 | // Set it as a normal link field |
301 | 347 | $fields['links'][] = $link_field; |
@@ -303,8 +349,10 @@ discard block |
||
303 | 349 | } |
304 | 350 | |
305 | 351 | // Not quite a recursive merge, since only one level |
306 | - foreach($fields as $type => &$list) { |
|
307 | - if($c_fields[$type]) { |
|
352 | + foreach($fields as $type => &$list) |
|
353 | + { |
|
354 | + if($c_fields[$type]) |
|
355 | + { |
|
308 | 356 | $list = array_merge($c_fields[$type], $list); |
309 | 357 | unset($c_fields[$type]); |
310 | 358 | } |
@@ -312,16 +360,22 @@ discard block |
||
312 | 360 | $fields += $c_fields; |
313 | 361 | $selects += $c_selects; |
314 | 362 | } |
315 | - foreach((array)$fields['select'] as $name) { |
|
316 | - if($record->$name != null && is_array($selects) && $selects[$name]) { |
|
363 | + foreach((array)$fields['select'] as $name) |
|
364 | + { |
|
365 | + if($record->$name != null && is_array($selects) && $selects[$name]) |
|
366 | + { |
|
317 | 367 | $record->$name = explode(',', $record->$name); |
318 | - if(is_array($record->$name)) { |
|
368 | + if(is_array($record->$name)) |
|
369 | + { |
|
319 | 370 | $names = array(); |
320 | - foreach($record->$name as $_name) { |
|
371 | + foreach($record->$name as $_name) |
|
372 | + { |
|
321 | 373 | $names[] = lang($selects[$name][$_name]); |
322 | 374 | } |
323 | 375 | $record->$name = implode(', ', $names); |
324 | - } else { |
|
376 | + } |
|
377 | + else |
|
378 | + { |
|
325 | 379 | $record->$name = lang($selects[$name][$record->$name]); |
326 | 380 | } |
327 | 381 | } |
@@ -330,14 +384,18 @@ discard block |
||
330 | 384 | $record->$name = ''; |
331 | 385 | } |
332 | 386 | } |
333 | - foreach((array)$fields['links'] as $name) { |
|
334 | - if($record->$name) { |
|
335 | - if(is_numeric($record->$name) && !$links[$name]) { |
|
387 | + foreach((array)$fields['links'] as $name) |
|
388 | + { |
|
389 | + if($record->$name) |
|
390 | + { |
|
391 | + if(is_numeric($record->$name) && !$links[$name]) |
|
392 | + { |
|
336 | 393 | $link = egw_link::get_link($record->$name); |
337 | 394 | $links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']); |
338 | 395 | $record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']); |
339 | 396 | } |
340 | - if($links[$name]) { |
|
397 | + if($links[$name]) |
|
398 | + { |
|
341 | 399 | $record->$name = egw_link::title($links[$name], $record->$name); |
342 | 400 | } |
343 | 401 | } |
@@ -346,16 +404,22 @@ discard block |
||
346 | 404 | $record->$name = ''; |
347 | 405 | } |
348 | 406 | } |
349 | - foreach((array)$fields['select-account'] as $name) { |
|
407 | + foreach((array)$fields['select-account'] as $name) |
|
408 | + { |
|
350 | 409 | // Compare against null to deal with empty arrays |
351 | - if ($record->$name !== null) { |
|
352 | - if(is_array($record->$name)) { |
|
410 | + if ($record->$name !== null) |
|
411 | + { |
|
412 | + if(is_array($record->$name)) |
|
413 | + { |
|
353 | 414 | $names = array(); |
354 | - foreach($record->$name as $_name) { |
|
415 | + foreach($record->$name as $_name) |
|
416 | + { |
|
355 | 417 | $names[] = common::grab_owner_name($_name); |
356 | 418 | } |
357 | 419 | $record->$name = implode(', ', $names); |
358 | - } else { |
|
420 | + } |
|
421 | + else |
|
422 | + { |
|
359 | 423 | $record->$name = common::grab_owner_name($record->$name); |
360 | 424 | } |
361 | 425 | } |
@@ -364,23 +428,49 @@ discard block |
||
364 | 428 | $record->$name = ''; |
365 | 429 | } |
366 | 430 | } |
367 | - foreach((array)$fields['select-bool'] as $name) { |
|
368 | - if($record->$name !== null) { |
|
431 | + foreach((array)$fields['select-bool'] as $name) |
|
432 | + { |
|
433 | + if($record->$name !== null) |
|
434 | + { |
|
369 | 435 | $record->$name = $record->$name ? lang('Yes') : lang('No'); |
370 | 436 | } |
371 | 437 | } |
372 | - foreach((array)$fields['date-time'] as $name) { |
|
438 | + foreach((array)$fields['date-time'] as $name) |
|
439 | + { |
|
373 | 440 | //if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format |
374 | - if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
|
375 | - if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. |
|
376 | - ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format |
|
377 | - if (!$record->$name) $record->$name = ''; |
|
441 | + if ($record->$name && !is_numeric($record->$name)) |
|
442 | + { |
|
443 | + $record->$name = strtotime($record->$name); |
|
444 | + } |
|
445 | + // Custom fields stored as string |
|
446 | + if ($record->$name && is_numeric($record->$name)) |
|
447 | + { |
|
448 | + $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '. |
|
449 | + ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); |
|
450 | + } |
|
451 | + // User date format |
|
452 | + if (!$record->$name) |
|
453 | + { |
|
454 | + $record->$name = ''; |
|
455 | + } |
|
378 | 456 | } |
379 | - foreach((array)$fields['date'] as $name) { |
|
457 | + foreach((array)$fields['date'] as $name) |
|
458 | + { |
|
380 | 459 | //if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format |
381 | - if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string |
|
382 | - if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format |
|
383 | - if (!$record->$name) $record->$name = ''; |
|
460 | + if ($record->$name && !is_numeric($record->$name)) |
|
461 | + { |
|
462 | + $record->$name = strtotime($record->$name); |
|
463 | + } |
|
464 | + // Custom fields stored as string |
|
465 | + if ($record->$name && is_numeric($record->$name)) |
|
466 | + { |
|
467 | + $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); |
|
468 | + } |
|
469 | + // User date format |
|
470 | + if (!$record->$name) |
|
471 | + { |
|
472 | + $record->$name = ''; |
|
473 | + } |
|
384 | 474 | } |
385 | 475 | foreach((array)$fields['float'] as $name) |
386 | 476 | { |
@@ -388,7 +478,10 @@ discard block |
||
388 | 478 | if (is_null($dec_separator)) |
389 | 479 | { |
390 | 480 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
391 | - if (empty($dec_separator)) $dec_separator = '.'; |
|
481 | + if (empty($dec_separator)) |
|
482 | + { |
|
483 | + $dec_separator = '.'; |
|
484 | + } |
|
392 | 485 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
393 | 486 | } |
394 | 487 | if($record->$name && (string)$record->$name != '') |
@@ -404,17 +497,27 @@ discard block |
||
404 | 497 | } |
405 | 498 | |
406 | 499 | // Some custom methods for conversion |
407 | - foreach((array)$methods as $name => $method) { |
|
408 | - if($record->$name) $record->$name = ExecMethod($method, $record->$name); |
|
500 | + foreach((array)$methods as $name => $method) |
|
501 | + { |
|
502 | + if($record->$name) |
|
503 | + { |
|
504 | + $record->$name = ExecMethod($method, $record->$name); |
|
505 | + } |
|
409 | 506 | } |
410 | 507 | |
411 | 508 | static $cat_object; |
412 | - if(is_null($cat_object)) $cat_object = new categories(false,$appname); |
|
413 | - foreach((array)$fields['select-cat'] as $name) { |
|
414 | - if($record->$name) { |
|
509 | + if(is_null($cat_object)) |
|
510 | + { |
|
511 | + $cat_object = new categories(false,$appname); |
|
512 | + } |
|
513 | + foreach((array)$fields['select-cat'] as $name) |
|
514 | + { |
|
515 | + if($record->$name) |
|
516 | + { |
|
415 | 517 | $cats = array(); |
416 | 518 | $ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name); |
417 | - foreach($ids as $n => $cat_id) { |
|
519 | + foreach($ids as $n => $cat_id) |
|
520 | + { |
|
418 | 521 | |
419 | 522 | if ($cat_id && $cat_object->check_perms(EGW_ACL_READ,$cat_id)) |
420 | 523 | { |
@@ -435,7 +538,8 @@ discard block |
||
435 | 538 | * |
436 | 539 | * @return |
437 | 540 | */ |
438 | - public function __destruct() { |
|
541 | + public function __destruct() |
|
542 | + { |
|
439 | 543 | |
440 | 544 | } |
441 | 545 | |
@@ -448,11 +552,16 @@ discard block |
||
448 | 552 | * @param char $delimiter |
449 | 553 | * @param char $enclosure |
450 | 554 | */ |
451 | - protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){ |
|
555 | + protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) |
|
556 | + { |
|
452 | 557 | $string = ""; |
453 | 558 | $writeDelimiter = false; |
454 | - foreach($dataArray as $dataElement) { |
|
455 | - if($writeDelimiter) $string .= $delimiter; |
|
559 | + foreach($dataArray as $dataElement) |
|
560 | + { |
|
561 | + if($writeDelimiter) |
|
562 | + { |
|
563 | + $string .= $delimiter; |
|
564 | + } |
|
456 | 565 | $string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure; |
457 | 566 | $writeDelimiter = true; |
458 | 567 | } |
@@ -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 | /** |
@@ -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) { |
@@ -30,19 +30,19 @@ discard block |
||
30 | 30 | * Relative date ranges for filtering |
31 | 31 | */ |
32 | 32 | public static $relative_dates = array( // Start: year,month,day,week, End: year,month,day,week |
33 | - 'Today' => array(0,0,0,0, 0,0,1,0), |
|
34 | - 'Yesterday' => array(0,0,-1,0, 0,0,0,0), |
|
35 | - 'This week' => array(0,0,0,0, 0,0,0,1), |
|
36 | - 'Last week' => array(0,0,0,-1, 0,0,0,0), |
|
37 | - 'This month' => array(0,0,0,0, 0,1,0,0), |
|
38 | - 'Last month' => array(0,-1,0,0, 0,0,0,0), |
|
39 | - 'Last 3 months' => array(0,-3,0,0, 0,0,0,0), |
|
40 | - 'This quarter'=> array(0,0,0,0, 0,0,0,0), // Just a marker, needs special handling |
|
41 | - 'Last quarter'=> array(0,-4,0,0, 0,-4,0,0), // Just a marker |
|
42 | - 'This year' => array(0,0,0,0, 1,0,0,0), |
|
43 | - 'Last year' => array(-1,0,0,0, 0,0,0,0), |
|
44 | - '2 years ago' => array(-2,0,0,0, -1,0,0,0), |
|
45 | - '3 years ago' => array(-3,0,0,0, -2,0,0,0), |
|
33 | + 'Today' => array(0, 0, 0, 0, 0, 0, 1, 0), |
|
34 | + 'Yesterday' => array(0, 0, -1, 0, 0, 0, 0, 0), |
|
35 | + 'This week' => array(0, 0, 0, 0, 0, 0, 0, 1), |
|
36 | + 'Last week' => array(0, 0, 0, -1, 0, 0, 0, 0), |
|
37 | + 'This month' => array(0, 0, 0, 0, 0, 1, 0, 0), |
|
38 | + 'Last month' => array(0, -1, 0, 0, 0, 0, 0, 0), |
|
39 | + 'Last 3 months' => array(0, -3, 0, 0, 0, 0, 0, 0), |
|
40 | + 'This quarter'=> array(0, 0, 0, 0, 0, 0, 0, 0), // Just a marker, needs special handling |
|
41 | + 'Last quarter'=> array(0, -4, 0, 0, 0, -4, 0, 0), // Just a marker |
|
42 | + 'This year' => array(0, 0, 0, 0, 1, 0, 0, 0), |
|
43 | + 'Last year' => array(-1, 0, 0, 0, 0, 0, 0, 0), |
|
44 | + '2 years ago' => array(-2, 0, 0, 0, -1, 0, 0, 0), |
|
45 | + '3 years ago' => array(-3, 0, 0, 0, -2, 0, 0, 0), |
|
46 | 46 | ); |
47 | 47 | |
48 | 48 | /** |
@@ -77,22 +77,22 @@ discard block |
||
77 | 77 | * @param string $_format format of time string e.g.: d.m.Y H:i |
78 | 78 | * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default |
79 | 79 | */ |
80 | - public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) { |
|
81 | - if ( empty( $_format ) ) return strtotime( $_string ); |
|
82 | - $fparams = explode( ',', chunk_split( $_format, 1, ',' ) ); |
|
80 | + public static function custom_strtotime($_string, $_format = '', $_is_dst = -1) { |
|
81 | + if (empty($_format)) return strtotime($_string); |
|
82 | + $fparams = explode(',', chunk_split($_format, 1, ',')); |
|
83 | 83 | $spos = 0; |
84 | - foreach ( $fparams as $fparam ) { |
|
85 | - |
|
86 | - switch ( $fparam ) { |
|
87 | - case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
88 | - case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
89 | - case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
90 | - case 'Y': (int)$year = substr( $_string, $spos, 4 ); $spos += 4; break; |
|
91 | - case 'H': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
92 | - case 'h': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
93 | - case 'i': (int)$min = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
94 | - case 's': (int)$sec = substr( $_string, $spos, 2 ); $spos += 2; break; |
|
95 | - case 'O': (int)$offset = $year = substr( $_string, $spos, 5 ); $spos += 5; break; |
|
84 | + foreach ($fparams as $fparam) { |
|
85 | + |
|
86 | + switch ($fparam) { |
|
87 | + case 'd': (int)$day = substr($_string, $spos, 2); $spos += 2; break; |
|
88 | + case 'm': (int)$mon = substr($_string, $spos, 2); $spos += 2; break; |
|
89 | + case 'y': (int)$year = substr($_string, $spos, 2); $spos += 2; break; |
|
90 | + case 'Y': (int)$year = substr($_string, $spos, 4); $spos += 4; break; |
|
91 | + case 'H': (int)$hour = substr($_string, $spos, 2); $spos += 2; break; |
|
92 | + case 'h': (int)$hour = substr($_string, $spos, 2); $spos += 2; break; |
|
93 | + case 'i': (int)$min = substr($_string, $spos, 2); $spos += 2; break; |
|
94 | + case 's': (int)$sec = substr($_string, $spos, 2); $spos += 2; break; |
|
95 | + case 'O': (int)$offset = $year = substr($_string, $spos, 5); $spos += 5; break; |
|
96 | 96 | case 'a': (int)$hour = $fparam == 'am' ? $hour : $hour + 12; break; |
97 | 97 | case 'A': (int)$hour = $fparam == 'AM' ? $hour : $hour + 12; break; |
98 | 98 | default: $spos++; // seperator |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | $timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst); |
104 | 104 | |
105 | 105 | // offset given? |
106 | - if ( isset( $offset ) && strlen( $offset == 5 ) ) { |
|
106 | + if (isset($offset) && strlen($offset == 5)) { |
|
107 | 107 | $operator = $offset{0}; |
108 | - $ohour = 60 * 60 * (int)substr( $offset, 1, 2 ); |
|
109 | - $omin = 60 * (int)substr( $offset, 3, 2 ); |
|
110 | - if ( $operator == '+' ) $timestamp += $ohour + $omin; |
|
108 | + $ohour = 60 * 60 * (int)substr($offset, 1, 2); |
|
109 | + $omin = 60 * (int)substr($offset, 3, 2); |
|
110 | + if ($operator == '+') $timestamp += $ohour + $omin; |
|
111 | 111 | else $timestamp -= $ohour + $omin; |
112 | 112 | } |
113 | 113 | return $timestamp; |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | * @param mixed $_account_lid comma seperated list or array with lids |
119 | 119 | * @return mixed comma seperated list or array with ids |
120 | 120 | */ |
121 | - public static function account_name2id( &$_account_lids ) { |
|
122 | - $account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids ); |
|
121 | + public static function account_name2id(&$_account_lids) { |
|
122 | + $account_lids = is_array($_account_lids) ? $_account_lids : explode(',', $_account_lids); |
|
123 | 123 | $skip = false; |
124 | - foreach ( $account_lids as $key => $account_lid ) { |
|
125 | - if($skip) { |
|
124 | + foreach ($account_lids as $key => $account_lid) { |
|
125 | + if ($skip) { |
|
126 | 126 | unset($account_lids[$key]); |
127 | 127 | $skip = false; |
128 | 128 | continue; |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | $account_lid = trim($account_lid); |
131 | 131 | |
132 | 132 | // Handle any IDs that slip in |
133 | - if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { |
|
133 | + if (is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { |
|
134 | 134 | unset($account_lids[$key]); |
135 | 135 | $account_ids[] = (int)$account_lid; |
136 | 136 | continue; |
137 | 137 | } |
138 | 138 | // Check for [username] |
139 | - if(strpos($account_lid,'[') !== false) |
|
139 | + if (strpos($account_lid, '[') !== false) |
|
140 | 140 | { |
141 | - if(preg_match('/\[(.+)\]/',$account_lid,$matches)) |
|
141 | + if (preg_match('/\[(.+)\]/', $account_lid, $matches)) |
|
142 | 142 | { |
143 | 143 | $account_id = $GLOBALS['egw']->accounts->name2id($matches[1]); |
144 | 144 | unset($account_lids[$key]); |
@@ -149,46 +149,46 @@ discard block |
||
149 | 149 | |
150 | 150 | // Handle users listed as Lastname, Firstname instead of login ID |
151 | 151 | // Do this first, in case their first name matches a username |
152 | - if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) { |
|
152 | + if ($account_lids[$key + 1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lids[$key + 1]).' '.$account_lid, 'account_fullname')) { |
|
153 | 153 | $account_ids[] = $account_id; |
154 | 154 | unset($account_lids[$key]); |
155 | 155 | $skip = true; // Skip the next one, it's the first name |
156 | - continue ; |
|
156 | + continue; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | // Deal with groups listed as <name> Group, remove the Group |
160 | - if(substr(trim($account_lid),-strlen(lang('Group'))) == lang('Group')) |
|
160 | + if (substr(trim($account_lid), -strlen(lang('Group'))) == lang('Group')) |
|
161 | 161 | { |
162 | 162 | $account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group')))); |
163 | 163 | } |
164 | 164 | |
165 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) { |
|
165 | + if ($account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) { |
|
166 | 166 | $account_ids[] = $account_id; |
167 | 167 | unset($account_lids[$key]); |
168 | 168 | continue; |
169 | 169 | } |
170 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) { |
|
170 | + if ($account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lid), 'account_fullname')) { |
|
171 | 171 | $account_ids[] = $account_id; |
172 | 172 | unset($account_lids[$key]); |
173 | 173 | continue; |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Handle groups listed as Group, <name> |
177 | - if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) { |
|
177 | + if ($account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) { |
|
178 | 178 | $account_ids[] = $account_id; |
179 | - unset($account_lids[$key-1]); |
|
179 | + unset($account_lids[$key - 1]); |
|
180 | 180 | unset($account_lids[$key]); |
181 | 181 | continue; |
182 | 182 | } |
183 | 183 | // Group, <name> - remove the Group part |
184 | - if($account_lid == lang('Group')) |
|
184 | + if ($account_lid == lang('Group')) |
|
185 | 185 | { |
186 | 186 | unset($account_lids[$key]); |
187 | 187 | continue; |
188 | 188 | } |
189 | 189 | } |
190 | - $_account_lids = (is_array($_account_lids) ? $account_lids : implode(',',array_unique($account_lids))); |
|
191 | - return is_array( $_account_lids ) ? array_unique($account_ids) : implode( ',', array_unique((array)$account_ids )); |
|
190 | + $_account_lids = (is_array($_account_lids) ? $account_lids : implode(',', array_unique($account_lids))); |
|
191 | + return is_array($_account_lids) ? array_unique($account_ids) : implode(',', array_unique((array)$account_ids)); |
|
192 | 192 | |
193 | 193 | } // end of member function account_lid2id |
194 | 194 | |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | * @param mixed $_account_ids comma seperated list or array with ids |
199 | 199 | * @return mixed comma seperated list or array with lids |
200 | 200 | */ |
201 | - public static function account_id2name( $_account_id ) { |
|
202 | - $account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id ); |
|
203 | - foreach ( $account_ids as $account_id ) { |
|
204 | - if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) { |
|
201 | + public static function account_id2name($_account_id) { |
|
202 | + $account_ids = is_array($_account_id) ? $_account_id : explode(',', $_account_id); |
|
203 | + foreach ($account_ids as $account_id) { |
|
204 | + if ($account_lid = $GLOBALS['egw']->accounts->id2name($account_id)) { |
|
205 | 205 | $account_lids[] = $account_lid; |
206 | 206 | } |
207 | 207 | } |
208 | - return is_array( $_account_id ) ? $account_lids : implode( ',', (array)$account_lids ); |
|
208 | + return is_array($_account_id) ? $account_lids : implode(',', (array)$account_lids); |
|
209 | 209 | } // end of member function account_id2lid |
210 | 210 | |
211 | 211 | /** |
@@ -214,12 +214,12 @@ discard block |
||
214 | 214 | * @param mixed _cat_ids comma seperated list or array |
215 | 215 | * @return mixed comma seperated list or array with cat_names |
216 | 216 | */ |
217 | - public static function cat_id2name( $_cat_ids ) { |
|
218 | - $cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids ); |
|
219 | - foreach ( $cat_ids as $cat_id ) { |
|
220 | - $cat_names[] = categories::id2name( (int)$cat_id ); |
|
217 | + public static function cat_id2name($_cat_ids) { |
|
218 | + $cat_ids = is_array($_cat_ids) ? $_cat_ids : explode(',', $_cat_ids); |
|
219 | + foreach ($cat_ids as $cat_id) { |
|
220 | + $cat_names[] = categories::id2name((int)$cat_id); |
|
221 | 221 | } |
222 | - return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names); |
|
222 | + return is_array($_cat_ids) ? $cat_names : implode(',', (array)$cat_names); |
|
223 | 223 | } // end of member function category_id2name |
224 | 224 | |
225 | 225 | /** |
@@ -230,24 +230,24 @@ discard block |
||
230 | 230 | * @param int $parent Optional parent ID to use for new categories |
231 | 231 | * @return mixed comma seperated list or array with cat_ids |
232 | 232 | */ |
233 | - public static function cat_name2id( $_cat_names, $parent = 0 ) { |
|
234 | - $cats = new categories(); // uses current user and app (egw_info[flags][currentapp]) |
|
233 | + public static function cat_name2id($_cat_names, $parent = 0) { |
|
234 | + $cats = new categories(); // uses current user and app (egw_info[flags][currentapp]) |
|
235 | 235 | |
236 | - $cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names ); |
|
237 | - foreach ( $cat_names as $cat_name ) { |
|
236 | + $cat_names = is_array($_cat_names) ? $_cat_names : explode(',', $_cat_names); |
|
237 | + foreach ($cat_names as $cat_name) { |
|
238 | 238 | $cat_name = trim($cat_name); |
239 | - if ( $cat_name == '' ) continue; |
|
240 | - if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) { |
|
241 | - $cat_id = $cats->add( array( |
|
239 | + if ($cat_name == '') continue; |
|
240 | + if (($cat_id = $cats->name2id($cat_name)) == 0 && !self::$dry_run) { |
|
241 | + $cat_id = $cats->add(array( |
|
242 | 242 | 'name' => $cat_name, |
243 | 243 | 'parent' => $parent, |
244 | 244 | 'access' => 'public', |
245 | - 'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')' |
|
245 | + 'descr' => $cat_name.' ('.lang('Automatically created by importexport').')' |
|
246 | 246 | )); |
247 | 247 | } |
248 | 248 | $cat_ids[] = $cat_id; |
249 | 249 | } |
250 | - return is_array( $_cat_names ) ? $cat_ids : implode( ',', (array)$cat_ids ); |
|
250 | + return is_array($_cat_names) ? $cat_ids : implode(',', (array)$cat_ids); |
|
251 | 251 | |
252 | 252 | } // end of member function category_name2id |
253 | 253 | |
@@ -286,76 +286,76 @@ discard block |
||
286 | 286 | * @param object &$cclass calling class to process the '@ evals' |
287 | 287 | * @return bool |
288 | 288 | */ |
289 | - public static function conversion( &$_record, $_conversion, &$_cclass = null ) { |
|
290 | - if (empty( $_conversion ) ) return $_record; |
|
289 | + public static function conversion(&$_record, $_conversion, &$_cclass = null) { |
|
290 | + if (empty($_conversion)) return $_record; |
|
291 | 291 | |
292 | - self::$cclass =& $_cclass; |
|
292 | + self::$cclass = & $_cclass; |
|
293 | 293 | |
294 | 294 | $PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in conversion |
295 | 295 | $ASep = '|>'; // Assignment-Separator, separats pattern and replacesment |
296 | - $CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value |
|
296 | + $CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value |
|
297 | 297 | $TPre = '|T{'; $TPos = '}'; // |{_record-idx} is trimmed |
298 | - $CntlPre = '|TC{'; // Filter all cntl-chars \x01-\x1f and trim |
|
299 | - $CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF |
|
300 | - $INE = '|INE{'; // Only insert if stuff in ^^ is not empty |
|
298 | + $CntlPre = '|TC{'; // Filter all cntl-chars \x01-\x1f and trim |
|
299 | + $CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF |
|
300 | + $INE = '|INE{'; // Only insert if stuff in ^^ is not empty |
|
301 | 301 | |
302 | - foreach ( $_conversion as $idx => $conversion_string ) { |
|
303 | - if ( empty( $conversion_string ) ) continue; |
|
302 | + foreach ($_conversion as $idx => $conversion_string) { |
|
303 | + if (empty($conversion_string)) continue; |
|
304 | 304 | |
305 | 305 | // fetch patterns ($rvalues) |
306 | 306 | $rvalues = array(); |
307 | - $pat_reps = explode( $PSep, stripslashes( $conversion_string ) ); |
|
308 | - foreach( $pat_reps as $k => $pat_rep ) { |
|
309 | - list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 ); |
|
310 | - if( $replace == '' ) { |
|
307 | + $pat_reps = explode($PSep, stripslashes($conversion_string)); |
|
308 | + foreach ($pat_reps as $k => $pat_rep) { |
|
309 | + list($pattern, $replace) = explode($ASep, $pat_rep, 2); |
|
310 | + if ($replace == '') { |
|
311 | 311 | $replace = $pattern; $pattern = '^.*$'; |
312 | 312 | } |
313 | - $rvalues[$pattern] = $replace; // replace two with only one, added by the form |
|
313 | + $rvalues[$pattern] = $replace; // replace two with only one, added by the form |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | // conversion list may be longer than $_record aka (no_csv) |
317 | - $val = array_key_exists( $idx, $_record ) ? $_record[$idx] : ''; |
|
317 | + $val = array_key_exists($idx, $_record) ? $_record[$idx] : ''; |
|
318 | 318 | |
319 | 319 | $c_functions = array('cat', 'account', 'strtotime', 'list'); |
320 | - if($_cclass) { |
|
320 | + if ($_cclass) { |
|
321 | 321 | // Add in additional methods |
322 | 322 | $reflection = new ReflectionClass(get_class($_cclass)); |
323 | 323 | $methods = $reflection->getMethods(ReflectionMethod::IS_STATIC); |
324 | - foreach($methods as $method) { |
|
324 | + foreach ($methods as $method) { |
|
325 | 325 | $c_functions[] = $method->name; |
326 | 326 | } |
327 | 327 | } |
328 | 328 | $c_functions = implode('|', $c_functions); |
329 | - foreach ( $rvalues as $pattern => $replace ) { |
|
329 | + foreach ($rvalues as $pattern => $replace) { |
|
330 | 330 | // Allow to include record indexes in pattern |
331 | 331 | $reg = '/\|\[([0-9]+)\]/'; |
332 | - while( preg_match( $reg, $pattern, $vars ) ) { |
|
332 | + while (preg_match($reg, $pattern, $vars)) { |
|
333 | 333 | // expand all _record fields |
334 | 334 | $pattern = str_replace( |
335 | - $CPre . $vars[1] . $CPos, |
|
335 | + $CPre.$vars[1].$CPos, |
|
336 | 336 | $_record[array_search($vars[1], array_keys($_record))], |
337 | 337 | $pattern |
338 | 338 | ); |
339 | 339 | } |
340 | - if( preg_match('/'. (string)$pattern.'/', $val) ) { |
|
340 | + if (preg_match('/'.(string)$pattern.'/', $val)) { |
|
341 | 341 | |
342 | - $val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val ); |
|
342 | + $val = preg_replace('/'.(string)$pattern.'/', $replace, (string)$val); |
|
343 | 343 | |
344 | 344 | $reg = '/\|\[([a-zA-Z_0-9]+)\]/'; |
345 | - while( preg_match( $reg, $val, $vars ) ) { |
|
345 | + while (preg_match($reg, $val, $vars)) { |
|
346 | 346 | // expand all _record fields |
347 | 347 | $val = str_replace( |
348 | - $CPre . $vars[1] . $CPos, |
|
348 | + $CPre.$vars[1].$CPos, |
|
349 | 349 | $_record[array_search($vars[1], array_keys($_record))], |
350 | 350 | $val |
351 | 351 | ); |
352 | 352 | } |
353 | - $val = preg_replace_callback( "/($c_functions)\(([^)]*)\)/i", array( self, 'c2_dispatcher') , $val ); |
|
353 | + $val = preg_replace_callback("/($c_functions)\(([^)]*)\)/i", array(self, 'c2_dispatcher'), $val); |
|
354 | 354 | break; |
355 | 355 | } |
356 | 356 | } |
357 | 357 | // clean each field |
358 | - $val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array( self, 'strclean'), $val ); |
|
358 | + $val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array(self, 'strclean'), $val); |
|
359 | 359 | |
360 | 360 | $_record[$idx] = $val; |
361 | 361 | } |
@@ -369,42 +369,42 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @param array $_matches |
371 | 371 | */ |
372 | - private static function c2_dispatcher( $_matches ) { |
|
372 | + private static function c2_dispatcher($_matches) { |
|
373 | 373 | $action = &$_matches[1]; // cat or account ... |
374 | - $data = &$_matches[2]; // datas for action |
|
374 | + $data = &$_matches[2]; // datas for action |
|
375 | 375 | |
376 | - switch ( $action ) { |
|
376 | + switch ($action) { |
|
377 | 377 | case 'strtotime' : |
378 | - list( $string, $format ) = explode( ',', $data ); |
|
379 | - return self::custom_strtotime( trim( $string ), trim( $format ) ); |
|
378 | + list($string, $format) = explode(',', $data); |
|
379 | + return self::custom_strtotime(trim($string), trim($format)); |
|
380 | 380 | case 'list': |
381 | - list( $split, $data, $index) = explode(',',$data); |
|
381 | + list($split, $data, $index) = explode(',', $data); |
|
382 | 382 | $exploded = explode($split, $data); |
383 | 383 | // 1 based indexing for user ease |
384 | 384 | return $exploded[$index - 1]; |
385 | 385 | default : |
386 | - if(self::$cclass && method_exists(self::$cclass, $action)) { |
|
386 | + if (self::$cclass && method_exists(self::$cclass, $action)) { |
|
387 | 387 | $class = get_class(self::$cclass); |
388 | 388 | return call_user_func("$class::$action", $data); |
389 | 389 | } |
390 | - $method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' ); |
|
391 | - if(self::$cclass && method_exists(self::$cclass, $method)) { |
|
390 | + $method = (string)$action.(is_int($data) ? '_id2name' : '_name2id'); |
|
391 | + if (self::$cclass && method_exists(self::$cclass, $method)) { |
|
392 | 392 | $class = get_class(self::$cclass); |
393 | 393 | return call_user_func("$class::$action", $data); |
394 | 394 | } else { |
395 | - return self::$method( $data ); |
|
395 | + return self::$method($data); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - private static function strclean( $_matches ) { |
|
401 | - switch( $_matches[1] ) { |
|
402 | - case '|T{' : return trim( $_matches[2] ); |
|
403 | - case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) ); |
|
404 | - case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) ); |
|
405 | - case '|INE{' : return preg_match( '/\^.+\^/', $_matches[2] ) ? $_matches[2] : ''; |
|
400 | + private static function strclean($_matches) { |
|
401 | + switch ($_matches[1]) { |
|
402 | + case '|T{' : return trim($_matches[2]); |
|
403 | + case '|TC{' : return trim(preg_replace('/[\x01-\x1F]+/', '', $_matches[2])); |
|
404 | + case '|TCnCL{' : return trim(preg_replace('/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2])); |
|
405 | + case '|INE{' : return preg_match('/\^.+\^/', $_matches[2]) ? $_matches[2] : ''; |
|
406 | 406 | default: |
407 | - throw new Exception('Error in conversion string! "'. substr( $_matches[1], 0, -1 ). '" is not valid!'); |
|
407 | + throw new Exception('Error in conversion string! "'.substr($_matches[1], 0, -1).'" is not valid!'); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
@@ -415,23 +415,23 @@ discard block |
||
415 | 415 | * @param string $_appname {<appname> | all} |
416 | 416 | * @return array(<appname> => array( <type> => array(<plugin> => <title>))) |
417 | 417 | */ |
418 | - public static function get_plugins( $_appname = 'all', $_type = 'all' ) { |
|
418 | + public static function get_plugins($_appname = 'all', $_type = 'all') { |
|
419 | 419 | $plugins = egw_cache::getTree( |
420 | 420 | __CLASS__, |
421 | 421 | 'plugins', |
422 | - array('importexport_helper_functions','_get_plugins'), |
|
422 | + array('importexport_helper_functions', '_get_plugins'), |
|
423 | 423 | array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')), |
424 | 424 | self::CACHE_EXPIRATION |
425 | 425 | ); |
426 | 426 | $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; |
427 | - $types = $_type == 'all' ? array('import','export') : (array)$_type; |
|
427 | + $types = $_type == 'all' ? array('import', 'export') : (array)$_type; |
|
428 | 428 | |
429 | 429 | // Testing: comment out egw_cache call, use this |
430 | 430 | //$plugins = self::_get_plugins($appnames, $types); |
431 | - foreach($plugins as $appname => $_types) { |
|
432 | - if(!in_array($appname, $appnames)) unset($plugins[$appname]); |
|
431 | + foreach ($plugins as $appname => $_types) { |
|
432 | + if (!in_array($appname, $appnames)) unset($plugins[$appname]); |
|
433 | 433 | } |
434 | - foreach($plugins as $appname => $types) { |
|
434 | + foreach ($plugins as $appname => $types) { |
|
435 | 435 | $plugins[$appname] = array_intersect_key($plugins[$appname], $types); |
436 | 436 | } |
437 | 437 | return $plugins; |
@@ -440,25 +440,25 @@ discard block |
||
440 | 440 | public static function _get_plugins(Array $appnames, Array $types) { |
441 | 441 | $plugins = array(); |
442 | 442 | foreach ($appnames as $appname) { |
443 | - if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
|
443 | + if (array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
|
444 | 444 | |
445 | - $appdir = EGW_INCLUDE_ROOT. "/$appname/inc"; |
|
446 | - if(!is_dir($appdir)) continue; |
|
445 | + $appdir = EGW_INCLUDE_ROOT."/$appname/inc"; |
|
446 | + if (!is_dir($appdir)) continue; |
|
447 | 447 | $d = dir($appdir); |
448 | 448 | |
449 | 449 | // step through each file in appdir |
450 | 450 | while (false !== ($entry = $d->read())) { |
451 | 451 | // Blacklisted? |
452 | - if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) continue; |
|
452 | + if (is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) continue; |
|
453 | 453 | if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue; |
454 | 454 | $classname = $matches[1]; |
455 | - $file = $appdir. '/'. $entry; |
|
455 | + $file = $appdir.'/'.$entry; |
|
456 | 456 | |
457 | 457 | foreach ($types as $type) { |
458 | - if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue; |
|
458 | + if (!is_file($file) || strpos($entry, $type) === false || strpos($entry, 'wizard') !== false) continue; |
|
459 | 459 | require_once($file); |
460 | 460 | $reflectionClass = new ReflectionClass($classname); |
461 | - if($reflectionClass->IsInstantiable() && |
|
461 | + if ($reflectionClass->IsInstantiable() && |
|
462 | 462 | $reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) { |
463 | 463 | try { |
464 | 464 | $plugin_object = new $classname; |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | $d->close(); |
475 | 475 | |
476 | 476 | $config = config::read('importexport'); |
477 | - if($config['update'] == 'auto') { |
|
477 | + if ($config['update'] == 'auto') { |
|
478 | 478 | self::load_defaults($appname); |
479 | 479 | } |
480 | 480 | } |
@@ -489,37 +489,37 @@ discard block |
||
489 | 489 | * @return array $num => $appname |
490 | 490 | */ |
491 | 491 | public static function get_apps($_type, $ignore_acl = false) { |
492 | - $apps = array_keys(self::get_plugins('all',$_type)); |
|
493 | - if($ignore_acl) return $apps; |
|
492 | + $apps = array_keys(self::get_plugins('all', $_type)); |
|
493 | + if ($ignore_acl) return $apps; |
|
494 | 494 | |
495 | - foreach($apps as $key => $app) { |
|
496 | - if(!self::has_definitions($app, $_type)) unset($apps[$key]); |
|
495 | + foreach ($apps as $key => $app) { |
|
496 | + if (!self::has_definitions($app, $_type)) unset($apps[$key]); |
|
497 | 497 | } |
498 | 498 | return $apps; |
499 | 499 | } |
500 | 500 | |
501 | 501 | public static function load_defaults($appname) { |
502 | 502 | // Check for new definitions to import from $appname/setup/*.xml |
503 | - $appdir = EGW_INCLUDE_ROOT. "/$appname/setup"; |
|
504 | - if(!is_dir($appdir)) return; |
|
503 | + $appdir = EGW_INCLUDE_ROOT."/$appname/setup"; |
|
504 | + if (!is_dir($appdir)) return; |
|
505 | 505 | $d = dir($appdir); |
506 | 506 | |
507 | 507 | // step through each file in app's setup |
508 | 508 | while (false !== ($entry = $d->read())) { |
509 | - $file = $appdir. '/'. $entry; |
|
510 | - list( $filename, $extension) = explode('.',$entry); |
|
511 | - if ( $extension != 'xml' ) continue; |
|
509 | + $file = $appdir.'/'.$entry; |
|
510 | + list($filename, $extension) = explode('.', $entry); |
|
511 | + if ($extension != 'xml') continue; |
|
512 | 512 | try { |
513 | 513 | // import will skip invalid files |
514 | - importexport_definitions_bo::import( $file ); |
|
514 | + importexport_definitions_bo::import($file); |
|
515 | 515 | } catch (Exception $e) { |
516 | - error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage()); |
|
516 | + error_log(__CLASS__.__FUNCTION__." import $appname definitions: ".$e->getMessage()); |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | $d->close(); |
520 | 520 | } |
521 | 521 | |
522 | - public static function guess_filetype( $_file ) { |
|
522 | + public static function guess_filetype($_file) { |
|
523 | 523 | |
524 | 524 | } |
525 | 525 | |
@@ -530,24 +530,24 @@ discard block |
||
530 | 530 | * @param string $_type {import | export | all} |
531 | 531 | * @return boolean |
532 | 532 | */ |
533 | - public static function has_definitions( $_appname = 'all', $_type = 'all' ) { |
|
533 | + public static function has_definitions($_appname = 'all', $_type = 'all') { |
|
534 | 534 | $definitions = egw_cache::getSession( |
535 | 535 | __CLASS__, |
536 | 536 | 'has_definitions', |
537 | - array('importexport_helper_functions','_has_definitions'), |
|
537 | + array('importexport_helper_functions', '_has_definitions'), |
|
538 | 538 | array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')), |
539 | 539 | self::CACHE_EXPIRATION |
540 | 540 | ); |
541 | 541 | $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; |
542 | - $types = $_type == 'all' ? array('import','export') : (array)$_type; |
|
542 | + $types = $_type == 'all' ? array('import', 'export') : (array)$_type; |
|
543 | 543 | |
544 | 544 | // Testing: Comment out cache call above, use this |
545 | 545 | //$definitions = self::_has_definitions($appnames, $types); |
546 | 546 | |
547 | - foreach($definitions as $appname => $_types) { |
|
548 | - if(!in_array($appname, $appnames)) unset($definitions[$appname]); |
|
547 | + foreach ($definitions as $appname => $_types) { |
|
548 | + if (!in_array($appname, $appnames)) unset($definitions[$appname]); |
|
549 | 549 | } |
550 | - foreach($definitions as $appname => $_types) { |
|
550 | + foreach ($definitions as $appname => $_types) { |
|
551 | 551 | $definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types)); |
552 | 552 | } |
553 | 553 | return count($definitions[$appname]) > 0; |
@@ -557,11 +557,11 @@ discard block |
||
557 | 557 | public static function _has_definitions(Array $appnames, Array $types) { |
558 | 558 | $def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types)); |
559 | 559 | $list = array(); |
560 | - foreach((array)$def->get_definitions() as $id) { |
|
560 | + foreach ((array)$def->get_definitions() as $id) { |
|
561 | 561 | // Need to instanciate it to check, but if the user doesn't have permission, it throws an exception |
562 | 562 | try { |
563 | 563 | $definition = new importexport_definition($id); |
564 | - if($def->is_permitted($definition->get_record_array())) { |
|
564 | + if ($def->is_permitted($definition->get_record_array())) { |
|
565 | 565 | $list[$definition->application][$definition->type][] = $id; |
566 | 566 | } |
567 | 567 | } catch (Exception $e) { |
@@ -593,16 +593,16 @@ discard block |
||
593 | 593 | $plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name(); |
594 | 594 | $plugin_name = get_class($plugin); |
595 | 595 | |
596 | - if($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
597 | - if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname); |
|
596 | + if ($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
597 | + if (!class_exists($record_classname)) throw new Exception('Bad class name '.$record_classname); |
|
598 | 598 | |
599 | - if($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
600 | - if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname); |
|
599 | + if ($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
600 | + if (!class_exists($record_classname)) throw new Exception('Bad class name '.$record_classname); |
|
601 | 601 | |
602 | - if(!$wizard_plugin) |
|
602 | + if (!$wizard_plugin) |
|
603 | 603 | { |
604 | - $wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name); |
|
605 | - if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name); |
|
604 | + $wizard_name = $app_name.'_wizard_'.str_replace($app_name.'_', '', $plugin_name); |
|
605 | + if (!class_exists($wizard_name)) throw new Exception('Bad wizard name '.$wizard_name); |
|
606 | 606 | $wizard_plugin = new $wizard_name; |
607 | 607 | } |
608 | 608 | } |
@@ -614,16 +614,16 @@ discard block |
||
614 | 614 | |
615 | 615 | // Get field -> label map and initialize fields using wizard field order |
616 | 616 | $fields = $export_fields = array(); |
617 | - if(method_exists($wizard_plugin, 'get_export_fields')) |
|
617 | + if (method_exists($wizard_plugin, 'get_export_fields')) |
|
618 | 618 | { |
619 | 619 | $fields = $export_fields = $wizard_plugin->get_export_fields(); |
620 | 620 | } |
621 | 621 | |
622 | - foreach($record_classname::$types as $type => $type_fields) |
|
622 | + foreach ($record_classname::$types as $type => $type_fields) |
|
623 | 623 | { |
624 | 624 | // Only these for now, until filter methods for others are figured out |
625 | - if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue; |
|
626 | - foreach($type_fields as $field_name) |
|
625 | + if (!in_array($type, array('select', 'select-cat', 'select-account', 'date', 'date-time'))) continue; |
|
626 | + foreach ($type_fields as $field_name) |
|
627 | 627 | { |
628 | 628 | $fields[$field_name] = array( |
629 | 629 | 'name' => $field_name, |
@@ -634,21 +634,21 @@ discard block |
||
634 | 634 | } |
635 | 635 | // Add custom fields |
636 | 636 | $custom = config::get_customfields($app_name); |
637 | - foreach($custom as $field_name => $settings) |
|
637 | + foreach ($custom as $field_name => $settings) |
|
638 | 638 | { |
639 | 639 | $settings['name'] = '#'.$field_name; |
640 | 640 | $fields['#'.$field_name] = $settings; |
641 | 641 | } |
642 | 642 | |
643 | - foreach($fields as $field_name => &$settings) { |
|
643 | + foreach ($fields as $field_name => &$settings) { |
|
644 | 644 | // Can't really filter on these (or at least no generic, sane way figured out yet) |
645 | - if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea'))) |
|
645 | + if (!is_array($settings) || in_array($settings['type'], array('text', 'button', 'label', 'url', 'url-email', 'url-phone', 'htmlarea'))) |
|
646 | 646 | { |
647 | 647 | unset($fields[$field_name]); |
648 | 648 | continue; |
649 | 649 | } |
650 | - if($settings['type'] == 'radio') $settings['type'] = 'select'; |
|
651 | - switch($settings['type']) |
|
650 | + if ($settings['type'] == 'radio') $settings['type'] = 'select'; |
|
651 | + switch ($settings['type']) |
|
652 | 652 | { |
653 | 653 | case 'checkbox': |
654 | 654 | // This isn't quite right - there's only 2 options and you can select both |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
674 | - if(method_exists($plugin, 'get_filter_fields')) |
|
674 | + if (method_exists($plugin, 'get_filter_fields')) |
|
675 | 675 | { |
676 | 676 | $plugin->get_filter_fields($fields); |
677 | 677 | } |
@@ -687,65 +687,65 @@ discard block |
||
687 | 687 | */ |
688 | 688 | public static function date_rel2abs($value) |
689 | 689 | { |
690 | - if(is_array($value)) |
|
690 | + if (is_array($value)) |
|
691 | 691 | { |
692 | 692 | $abs = array(); |
693 | - foreach($value as $key => $val) |
|
693 | + foreach ($value as $key => $val) |
|
694 | 694 | { |
695 | 695 | $abs[$key] = self::date_rel2abs($val); |
696 | 696 | } |
697 | 697 | return $abs; |
698 | 698 | } |
699 | - if($date = self::$relative_dates[$value]) |
|
699 | + if ($date = self::$relative_dates[$value]) |
|
700 | 700 | { |
701 | - $year = (int) date('Y'); |
|
702 | - $month = (int) date('m'); |
|
703 | - $day = (int) date('d'); |
|
704 | - $today = mktime(0,0,0,date('m'),date('d'),date('Y')); |
|
701 | + $year = (int)date('Y'); |
|
702 | + $month = (int)date('m'); |
|
703 | + $day = (int)date('d'); |
|
704 | + $today = mktime(0, 0, 0, date('m'), date('d'), date('Y')); |
|
705 | 705 | |
706 | - list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $date; |
|
706 | + list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $date; |
|
707 | 707 | |
708 | - if(stripos($value, 'quarter') !== false) |
|
708 | + if (stripos($value, 'quarter') !== false) |
|
709 | 709 | { |
710 | 710 | // Handle quarters |
711 | - $start = mktime(0,0,0,((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1, $year); |
|
712 | - $end = mktime(0,0,0,((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1, $year); |
|
711 | + $start = mktime(0, 0, 0, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1, $year); |
|
712 | + $end = mktime(0, 0, 0, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1, $year); |
|
713 | 713 | } |
714 | 714 | elseif ($syear || $eyear) |
715 | 715 | { |
716 | - $start = mktime(0,0,0,1,1,$syear+$year); |
|
717 | - $end = mktime(0,0,0,1,1,$eyear+$year); |
|
716 | + $start = mktime(0, 0, 0, 1, 1, $syear + $year); |
|
717 | + $end = mktime(0, 0, 0, 1, 1, $eyear + $year); |
|
718 | 718 | } |
719 | 719 | elseif ($smonth || $emonth) |
720 | 720 | { |
721 | - $start = mktime(0,0,0,$smonth+$month,1,$year); |
|
722 | - $end = mktime(0,0,0,$emonth+$month,1,$year); |
|
721 | + $start = mktime(0, 0, 0, $smonth + $month, 1, $year); |
|
722 | + $end = mktime(0, 0, 0, $emonth + $month, 1, $year); |
|
723 | 723 | } |
724 | 724 | elseif ($sday || $eday) |
725 | 725 | { |
726 | - $start = mktime(0,0,0,$month,$sday+$day,$year); |
|
727 | - $end = mktime(0,0,0,$month,$eday+$day,$year); |
|
726 | + $start = mktime(0, 0, 0, $month, $sday + $day, $year); |
|
727 | + $end = mktime(0, 0, 0, $month, $eday + $day, $year); |
|
728 | 728 | } |
729 | 729 | elseif ($sweek || $eweek) |
730 | 730 | { |
731 | - $wday = (int) date('w'); // 0=sun, ..., 6=sat |
|
732 | - switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
731 | + $wday = (int)date('w'); // 0=sun, ..., 6=sat |
|
732 | + switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']) |
|
733 | 733 | { |
734 | 734 | case 'Sunday': |
735 | - $weekstart = $today - $wday * 24*60*60; |
|
735 | + $weekstart = $today - $wday * 24 * 60 * 60; |
|
736 | 736 | break; |
737 | 737 | case 'Saturday': |
738 | - $weekstart = $today - (6-$wday) * 24*60*60; |
|
738 | + $weekstart = $today - (6 - $wday) * 24 * 60 * 60; |
|
739 | 739 | break; |
740 | 740 | case 'Moday': |
741 | 741 | default: |
742 | - $weekstart = $today - ($wday ? $wday-1 : 6) * 24*60*60; |
|
742 | + $weekstart = $today - ($wday ? $wday - 1 : 6) * 24 * 60 * 60; |
|
743 | 743 | break; |
744 | 744 | } |
745 | - $start = $weekstart + $sweek*7*24*60*60; |
|
746 | - $end = $weekstart + $eweek*7*24*60*60; |
|
745 | + $start = $weekstart + $sweek * 7 * 24 * 60 * 60; |
|
746 | + $end = $weekstart + $eweek * 7 * 24 * 60 * 60; |
|
747 | 747 | } |
748 | - $end_param = $end - 24*60*60; |
|
748 | + $end_param = $end - 24 * 60 * 60; |
|
749 | 749 | |
750 | 750 | // Take 1 second off end to provide an inclusive range.for filtering |
751 | 751 | $end -= 1; |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | * class importexport_helper_functions (only static methods) |
15 | 15 | * use importexport_helper_functions::method |
16 | 16 | */ |
17 | -class importexport_helper_functions { |
|
17 | +class importexport_helper_functions |
|
18 | +{ |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Plugins are scanned and cached for all instances using this source path for given time (in seconds) |
@@ -77,13 +78,19 @@ discard block |
||
77 | 78 | * @param string $_format format of time string e.g.: d.m.Y H:i |
78 | 79 | * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default |
79 | 80 | */ |
80 | - public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) { |
|
81 | - if ( empty( $_format ) ) return strtotime( $_string ); |
|
81 | + public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) |
|
82 | + { |
|
83 | + if ( empty( $_format ) ) |
|
84 | + { |
|
85 | + return strtotime( $_string ); |
|
86 | + } |
|
82 | 87 | $fparams = explode( ',', chunk_split( $_format, 1, ',' ) ); |
83 | 88 | $spos = 0; |
84 | - foreach ( $fparams as $fparam ) { |
|
89 | + foreach ( $fparams as $fparam ) |
|
90 | + { |
|
85 | 91 | |
86 | - switch ( $fparam ) { |
|
92 | + switch ( $fparam ) |
|
93 | + { |
|
87 | 94 | case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break; |
88 | 95 | case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break; |
89 | 96 | case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break; |
@@ -103,12 +110,18 @@ discard block |
||
103 | 110 | $timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst); |
104 | 111 | |
105 | 112 | // offset given? |
106 | - if ( isset( $offset ) && strlen( $offset == 5 ) ) { |
|
113 | + if ( isset( $offset ) && strlen( $offset == 5 ) ) |
|
114 | + { |
|
107 | 115 | $operator = $offset{0}; |
108 | 116 | $ohour = 60 * 60 * (int)substr( $offset, 1, 2 ); |
109 | 117 | $omin = 60 * (int)substr( $offset, 3, 2 ); |
110 | - if ( $operator == '+' ) $timestamp += $ohour + $omin; |
|
111 | - else $timestamp -= $ohour + $omin; |
|
118 | + if ( $operator == '+' ) |
|
119 | + { |
|
120 | + $timestamp += $ohour + $omin; |
|
121 | + } |
|
122 | + else { |
|
123 | + $timestamp -= $ohour + $omin; |
|
124 | + } |
|
112 | 125 | } |
113 | 126 | return $timestamp; |
114 | 127 | } |
@@ -118,11 +131,14 @@ discard block |
||
118 | 131 | * @param mixed $_account_lid comma seperated list or array with lids |
119 | 132 | * @return mixed comma seperated list or array with ids |
120 | 133 | */ |
121 | - public static function account_name2id( &$_account_lids ) { |
|
134 | + public static function account_name2id( &$_account_lids ) |
|
135 | + { |
|
122 | 136 | $account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids ); |
123 | 137 | $skip = false; |
124 | - foreach ( $account_lids as $key => $account_lid ) { |
|
125 | - if($skip) { |
|
138 | + foreach ( $account_lids as $key => $account_lid ) |
|
139 | + { |
|
140 | + if($skip) |
|
141 | + { |
|
126 | 142 | unset($account_lids[$key]); |
127 | 143 | $skip = false; |
128 | 144 | continue; |
@@ -130,7 +146,8 @@ discard block |
||
130 | 146 | $account_lid = trim($account_lid); |
131 | 147 | |
132 | 148 | // Handle any IDs that slip in |
133 | - if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) { |
|
149 | + if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) |
|
150 | + { |
|
134 | 151 | unset($account_lids[$key]); |
135 | 152 | $account_ids[] = (int)$account_lid; |
136 | 153 | continue; |
@@ -149,7 +166,8 @@ discard block |
||
149 | 166 | |
150 | 167 | // Handle users listed as Lastname, Firstname instead of login ID |
151 | 168 | // Do this first, in case their first name matches a username |
152 | - if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) { |
|
169 | + if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) |
|
170 | + { |
|
153 | 171 | $account_ids[] = $account_id; |
154 | 172 | unset($account_lids[$key]); |
155 | 173 | $skip = true; // Skip the next one, it's the first name |
@@ -162,19 +180,22 @@ discard block |
||
162 | 180 | $account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group')))); |
163 | 181 | } |
164 | 182 | |
165 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) { |
|
183 | + if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) |
|
184 | + { |
|
166 | 185 | $account_ids[] = $account_id; |
167 | 186 | unset($account_lids[$key]); |
168 | 187 | continue; |
169 | 188 | } |
170 | - if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) { |
|
189 | + if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) |
|
190 | + { |
|
171 | 191 | $account_ids[] = $account_id; |
172 | 192 | unset($account_lids[$key]); |
173 | 193 | continue; |
174 | 194 | } |
175 | 195 | |
176 | 196 | // Handle groups listed as Group, <name> |
177 | - if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) { |
|
197 | + if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) |
|
198 | + { |
|
178 | 199 | $account_ids[] = $account_id; |
179 | 200 | unset($account_lids[$key-1]); |
180 | 201 | unset($account_lids[$key]); |
@@ -198,10 +219,13 @@ discard block |
||
198 | 219 | * @param mixed $_account_ids comma seperated list or array with ids |
199 | 220 | * @return mixed comma seperated list or array with lids |
200 | 221 | */ |
201 | - public static function account_id2name( $_account_id ) { |
|
222 | + public static function account_id2name( $_account_id ) |
|
223 | + { |
|
202 | 224 | $account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id ); |
203 | - foreach ( $account_ids as $account_id ) { |
|
204 | - if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) { |
|
225 | + foreach ( $account_ids as $account_id ) |
|
226 | + { |
|
227 | + if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) |
|
228 | + { |
|
205 | 229 | $account_lids[] = $account_lid; |
206 | 230 | } |
207 | 231 | } |
@@ -214,9 +238,11 @@ discard block |
||
214 | 238 | * @param mixed _cat_ids comma seperated list or array |
215 | 239 | * @return mixed comma seperated list or array with cat_names |
216 | 240 | */ |
217 | - public static function cat_id2name( $_cat_ids ) { |
|
241 | + public static function cat_id2name( $_cat_ids ) |
|
242 | + { |
|
218 | 243 | $cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids ); |
219 | - foreach ( $cat_ids as $cat_id ) { |
|
244 | + foreach ( $cat_ids as $cat_id ) |
|
245 | + { |
|
220 | 246 | $cat_names[] = categories::id2name( (int)$cat_id ); |
221 | 247 | } |
222 | 248 | return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names); |
@@ -230,14 +256,20 @@ discard block |
||
230 | 256 | * @param int $parent Optional parent ID to use for new categories |
231 | 257 | * @return mixed comma seperated list or array with cat_ids |
232 | 258 | */ |
233 | - public static function cat_name2id( $_cat_names, $parent = 0 ) { |
|
259 | + public static function cat_name2id( $_cat_names, $parent = 0 ) |
|
260 | + { |
|
234 | 261 | $cats = new categories(); // uses current user and app (egw_info[flags][currentapp]) |
235 | 262 | |
236 | 263 | $cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names ); |
237 | - foreach ( $cat_names as $cat_name ) { |
|
264 | + foreach ( $cat_names as $cat_name ) |
|
265 | + { |
|
238 | 266 | $cat_name = trim($cat_name); |
239 | - if ( $cat_name == '' ) continue; |
|
240 | - if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) { |
|
267 | + if ( $cat_name == '' ) |
|
268 | + { |
|
269 | + continue; |
|
270 | + } |
|
271 | + if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) |
|
272 | + { |
|
241 | 273 | $cat_id = $cats->add( array( |
242 | 274 | 'name' => $cat_name, |
243 | 275 | 'parent' => $parent, |
@@ -286,8 +318,12 @@ discard block |
||
286 | 318 | * @param object &$cclass calling class to process the '@ evals' |
287 | 319 | * @return bool |
288 | 320 | */ |
289 | - public static function conversion( &$_record, $_conversion, &$_cclass = null ) { |
|
290 | - if (empty( $_conversion ) ) return $_record; |
|
321 | + public static function conversion( &$_record, $_conversion, &$_cclass = null ) |
|
322 | + { |
|
323 | + if (empty( $_conversion ) ) |
|
324 | + { |
|
325 | + return $_record; |
|
326 | + } |
|
291 | 327 | |
292 | 328 | self::$cclass =& $_cclass; |
293 | 329 | |
@@ -299,15 +335,21 @@ discard block |
||
299 | 335 | $CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF |
300 | 336 | $INE = '|INE{'; // Only insert if stuff in ^^ is not empty |
301 | 337 | |
302 | - foreach ( $_conversion as $idx => $conversion_string ) { |
|
303 | - if ( empty( $conversion_string ) ) continue; |
|
338 | + foreach ( $_conversion as $idx => $conversion_string ) |
|
339 | + { |
|
340 | + if ( empty( $conversion_string ) ) |
|
341 | + { |
|
342 | + continue; |
|
343 | + } |
|
304 | 344 | |
305 | 345 | // fetch patterns ($rvalues) |
306 | 346 | $rvalues = array(); |
307 | 347 | $pat_reps = explode( $PSep, stripslashes( $conversion_string ) ); |
308 | - foreach( $pat_reps as $k => $pat_rep ) { |
|
348 | + foreach( $pat_reps as $k => $pat_rep ) |
|
349 | + { |
|
309 | 350 | list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 ); |
310 | - if( $replace == '' ) { |
|
351 | + if( $replace == '' ) |
|
352 | + { |
|
311 | 353 | $replace = $pattern; $pattern = '^.*$'; |
312 | 354 | } |
313 | 355 | $rvalues[$pattern] = $replace; // replace two with only one, added by the form |
@@ -317,19 +359,23 @@ discard block |
||
317 | 359 | $val = array_key_exists( $idx, $_record ) ? $_record[$idx] : ''; |
318 | 360 | |
319 | 361 | $c_functions = array('cat', 'account', 'strtotime', 'list'); |
320 | - if($_cclass) { |
|
362 | + if($_cclass) |
|
363 | + { |
|
321 | 364 | // Add in additional methods |
322 | 365 | $reflection = new ReflectionClass(get_class($_cclass)); |
323 | 366 | $methods = $reflection->getMethods(ReflectionMethod::IS_STATIC); |
324 | - foreach($methods as $method) { |
|
367 | + foreach($methods as $method) |
|
368 | + { |
|
325 | 369 | $c_functions[] = $method->name; |
326 | 370 | } |
327 | 371 | } |
328 | 372 | $c_functions = implode('|', $c_functions); |
329 | - foreach ( $rvalues as $pattern => $replace ) { |
|
373 | + foreach ( $rvalues as $pattern => $replace ) |
|
374 | + { |
|
330 | 375 | // Allow to include record indexes in pattern |
331 | 376 | $reg = '/\|\[([0-9]+)\]/'; |
332 | - while( preg_match( $reg, $pattern, $vars ) ) { |
|
377 | + while( preg_match( $reg, $pattern, $vars ) ) |
|
378 | + { |
|
333 | 379 | // expand all _record fields |
334 | 380 | $pattern = str_replace( |
335 | 381 | $CPre . $vars[1] . $CPos, |
@@ -337,12 +383,14 @@ discard block |
||
337 | 383 | $pattern |
338 | 384 | ); |
339 | 385 | } |
340 | - if( preg_match('/'. (string)$pattern.'/', $val) ) { |
|
386 | + if( preg_match('/'. (string)$pattern.'/', $val) ) |
|
387 | + { |
|
341 | 388 | |
342 | 389 | $val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val ); |
343 | 390 | |
344 | 391 | $reg = '/\|\[([a-zA-Z_0-9]+)\]/'; |
345 | - while( preg_match( $reg, $val, $vars ) ) { |
|
392 | + while( preg_match( $reg, $val, $vars ) ) |
|
393 | + { |
|
346 | 394 | // expand all _record fields |
347 | 395 | $val = str_replace( |
348 | 396 | $CPre . $vars[1] . $CPos, |
@@ -369,11 +417,13 @@ discard block |
||
369 | 417 | * |
370 | 418 | * @param array $_matches |
371 | 419 | */ |
372 | - private static function c2_dispatcher( $_matches ) { |
|
420 | + private static function c2_dispatcher( $_matches ) |
|
421 | + { |
|
373 | 422 | $action = &$_matches[1]; // cat or account ... |
374 | 423 | $data = &$_matches[2]; // datas for action |
375 | 424 | |
376 | - switch ( $action ) { |
|
425 | + switch ( $action ) |
|
426 | + { |
|
377 | 427 | case 'strtotime' : |
378 | 428 | list( $string, $format ) = explode( ',', $data ); |
379 | 429 | return self::custom_strtotime( trim( $string ), trim( $format ) ); |
@@ -383,22 +433,28 @@ discard block |
||
383 | 433 | // 1 based indexing for user ease |
384 | 434 | return $exploded[$index - 1]; |
385 | 435 | default : |
386 | - if(self::$cclass && method_exists(self::$cclass, $action)) { |
|
436 | + if(self::$cclass && method_exists(self::$cclass, $action)) |
|
437 | + { |
|
387 | 438 | $class = get_class(self::$cclass); |
388 | 439 | return call_user_func("$class::$action", $data); |
389 | 440 | } |
390 | 441 | $method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' ); |
391 | - if(self::$cclass && method_exists(self::$cclass, $method)) { |
|
442 | + if(self::$cclass && method_exists(self::$cclass, $method)) |
|
443 | + { |
|
392 | 444 | $class = get_class(self::$cclass); |
393 | 445 | return call_user_func("$class::$action", $data); |
394 | - } else { |
|
446 | + } |
|
447 | + else |
|
448 | + { |
|
395 | 449 | return self::$method( $data ); |
396 | 450 | } |
397 | 451 | } |
398 | 452 | } |
399 | 453 | |
400 | - private static function strclean( $_matches ) { |
|
401 | - switch( $_matches[1] ) { |
|
454 | + private static function strclean( $_matches ) |
|
455 | + { |
|
456 | + switch( $_matches[1] ) |
|
457 | + { |
|
402 | 458 | case '|T{' : return trim( $_matches[2] ); |
403 | 459 | case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) ); |
404 | 460 | case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) ); |
@@ -415,7 +471,8 @@ discard block |
||
415 | 471 | * @param string $_appname {<appname> | all} |
416 | 472 | * @return array(<appname> => array( <type> => array(<plugin> => <title>))) |
417 | 473 | */ |
418 | - public static function get_plugins( $_appname = 'all', $_type = 'all' ) { |
|
474 | + public static function get_plugins( $_appname = 'all', $_type = 'all' ) |
|
475 | + { |
|
419 | 476 | $plugins = egw_cache::getTree( |
420 | 477 | __CLASS__, |
421 | 478 | 'plugins', |
@@ -428,38 +485,63 @@ discard block |
||
428 | 485 | |
429 | 486 | // Testing: comment out egw_cache call, use this |
430 | 487 | //$plugins = self::_get_plugins($appnames, $types); |
431 | - foreach($plugins as $appname => $_types) { |
|
432 | - if(!in_array($appname, $appnames)) unset($plugins[$appname]); |
|
488 | + foreach($plugins as $appname => $_types) |
|
489 | + { |
|
490 | + if(!in_array($appname, $appnames)) |
|
491 | + { |
|
492 | + unset($plugins[$appname]); |
|
493 | + } |
|
433 | 494 | } |
434 | - foreach($plugins as $appname => $types) { |
|
495 | + foreach($plugins as $appname => $types) |
|
496 | + { |
|
435 | 497 | $plugins[$appname] = array_intersect_key($plugins[$appname], $types); |
436 | 498 | } |
437 | 499 | return $plugins; |
438 | 500 | } |
439 | 501 | |
440 | - public static function _get_plugins(Array $appnames, Array $types) { |
|
502 | + public static function _get_plugins(Array $appnames, Array $types) |
|
503 | + { |
|
441 | 504 | $plugins = array(); |
442 | - foreach ($appnames as $appname) { |
|
443 | - if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue; |
|
505 | + foreach ($appnames as $appname) |
|
506 | + { |
|
507 | + if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) |
|
508 | + { |
|
509 | + continue; |
|
510 | + } |
|
444 | 511 | |
445 | 512 | $appdir = EGW_INCLUDE_ROOT. "/$appname/inc"; |
446 | - if(!is_dir($appdir)) continue; |
|
513 | + if(!is_dir($appdir)) |
|
514 | + { |
|
515 | + continue; |
|
516 | + } |
|
447 | 517 | $d = dir($appdir); |
448 | 518 | |
449 | 519 | // step through each file in appdir |
450 | - while (false !== ($entry = $d->read())) { |
|
520 | + while (false !== ($entry = $d->read())) |
|
521 | + { |
|
451 | 522 | // Blacklisted? |
452 | - if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) continue; |
|
453 | - if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue; |
|
523 | + if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname])) |
|
524 | + { |
|
525 | + continue; |
|
526 | + } |
|
527 | + if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) |
|
528 | + { |
|
529 | + continue; |
|
530 | + } |
|
454 | 531 | $classname = $matches[1]; |
455 | 532 | $file = $appdir. '/'. $entry; |
456 | 533 | |
457 | - foreach ($types as $type) { |
|
458 | - if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue; |
|
534 | + foreach ($types as $type) |
|
535 | + { |
|
536 | + if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) |
|
537 | + { |
|
538 | + continue; |
|
539 | + } |
|
459 | 540 | require_once($file); |
460 | 541 | $reflectionClass = new ReflectionClass($classname); |
461 | 542 | if($reflectionClass->IsInstantiable() && |
462 | - $reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) { |
|
543 | + $reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) |
|
544 | + { |
|
463 | 545 | try { |
464 | 546 | $plugin_object = new $classname; |
465 | 547 | } |
@@ -474,7 +556,8 @@ discard block |
||
474 | 556 | $d->close(); |
475 | 557 | |
476 | 558 | $config = config::read('importexport'); |
477 | - if($config['update'] == 'auto') { |
|
559 | + if($config['update'] == 'auto') |
|
560 | + { |
|
478 | 561 | self::load_defaults($appname); |
479 | 562 | } |
480 | 563 | } |
@@ -488,38 +571,56 @@ discard block |
||
488 | 571 | * @param string $_type |
489 | 572 | * @return array $num => $appname |
490 | 573 | */ |
491 | - public static function get_apps($_type, $ignore_acl = false) { |
|
574 | + public static function get_apps($_type, $ignore_acl = false) |
|
575 | + { |
|
492 | 576 | $apps = array_keys(self::get_plugins('all',$_type)); |
493 | - if($ignore_acl) return $apps; |
|
577 | + if($ignore_acl) |
|
578 | + { |
|
579 | + return $apps; |
|
580 | + } |
|
494 | 581 | |
495 | - foreach($apps as $key => $app) { |
|
496 | - if(!self::has_definitions($app, $_type)) unset($apps[$key]); |
|
582 | + foreach($apps as $key => $app) |
|
583 | + { |
|
584 | + if(!self::has_definitions($app, $_type)) |
|
585 | + { |
|
586 | + unset($apps[$key]); |
|
587 | + } |
|
497 | 588 | } |
498 | 589 | return $apps; |
499 | 590 | } |
500 | 591 | |
501 | - public static function load_defaults($appname) { |
|
592 | + public static function load_defaults($appname) |
|
593 | + { |
|
502 | 594 | // Check for new definitions to import from $appname/setup/*.xml |
503 | 595 | $appdir = EGW_INCLUDE_ROOT. "/$appname/setup"; |
504 | - if(!is_dir($appdir)) return; |
|
596 | + if(!is_dir($appdir)) |
|
597 | + { |
|
598 | + return; |
|
599 | + } |
|
505 | 600 | $d = dir($appdir); |
506 | 601 | |
507 | 602 | // step through each file in app's setup |
508 | - while (false !== ($entry = $d->read())) { |
|
603 | + while (false !== ($entry = $d->read())) |
|
604 | + { |
|
509 | 605 | $file = $appdir. '/'. $entry; |
510 | 606 | list( $filename, $extension) = explode('.',$entry); |
511 | - if ( $extension != 'xml' ) continue; |
|
607 | + if ( $extension != 'xml' ) |
|
608 | + { |
|
609 | + continue; |
|
610 | + } |
|
512 | 611 | try { |
513 | 612 | // import will skip invalid files |
514 | 613 | importexport_definitions_bo::import( $file ); |
515 | - } catch (Exception $e) { |
|
614 | + } |
|
615 | + catch (Exception $e) { |
|
516 | 616 | error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage()); |
517 | 617 | } |
518 | 618 | } |
519 | 619 | $d->close(); |
520 | 620 | } |
521 | 621 | |
522 | - public static function guess_filetype( $_file ) { |
|
622 | + public static function guess_filetype( $_file ) |
|
623 | + { |
|
523 | 624 | |
524 | 625 | } |
525 | 626 | |
@@ -530,7 +631,8 @@ discard block |
||
530 | 631 | * @param string $_type {import | export | all} |
531 | 632 | * @return boolean |
532 | 633 | */ |
533 | - public static function has_definitions( $_appname = 'all', $_type = 'all' ) { |
|
634 | + public static function has_definitions( $_appname = 'all', $_type = 'all' ) |
|
635 | + { |
|
534 | 636 | $definitions = egw_cache::getSession( |
535 | 637 | __CLASS__, |
536 | 638 | 'has_definitions', |
@@ -544,27 +646,36 @@ discard block |
||
544 | 646 | // Testing: Comment out cache call above, use this |
545 | 647 | //$definitions = self::_has_definitions($appnames, $types); |
546 | 648 | |
547 | - foreach($definitions as $appname => $_types) { |
|
548 | - if(!in_array($appname, $appnames)) unset($definitions[$appname]); |
|
649 | + foreach($definitions as $appname => $_types) |
|
650 | + { |
|
651 | + if(!in_array($appname, $appnames)) |
|
652 | + { |
|
653 | + unset($definitions[$appname]); |
|
654 | + } |
|
549 | 655 | } |
550 | - foreach($definitions as $appname => $_types) { |
|
656 | + foreach($definitions as $appname => $_types) |
|
657 | + { |
|
551 | 658 | $definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types)); |
552 | 659 | } |
553 | 660 | return count($definitions[$appname]) > 0; |
554 | 661 | } |
555 | 662 | |
556 | 663 | // egw_cache needs this public |
557 | - public static function _has_definitions(Array $appnames, Array $types) { |
|
664 | + public static function _has_definitions(Array $appnames, Array $types) |
|
665 | + { |
|
558 | 666 | $def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types)); |
559 | 667 | $list = array(); |
560 | - foreach((array)$def->get_definitions() as $id) { |
|
668 | + foreach((array)$def->get_definitions() as $id) |
|
669 | + { |
|
561 | 670 | // Need to instanciate it to check, but if the user doesn't have permission, it throws an exception |
562 | 671 | try { |
563 | 672 | $definition = new importexport_definition($id); |
564 | - if($def->is_permitted($definition->get_record_array())) { |
|
673 | + if($def->is_permitted($definition->get_record_array())) |
|
674 | + { |
|
565 | 675 | $list[$definition->application][$definition->type][] = $id; |
566 | 676 | } |
567 | - } catch (Exception $e) { |
|
677 | + } |
|
678 | + catch (Exception $e) { |
|
568 | 679 | // That one doesn't work, keep going |
569 | 680 | } |
570 | 681 | $definition = null; |
@@ -593,16 +704,31 @@ discard block |
||
593 | 704 | $plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name(); |
594 | 705 | $plugin_name = get_class($plugin); |
595 | 706 | |
596 | - if($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
597 | - if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname); |
|
707 | + if($record_classname == null) |
|
708 | + { |
|
709 | + $record_classname = $plugin::get_egw_record_class(); |
|
710 | + } |
|
711 | + if(!class_exists($record_classname)) |
|
712 | + { |
|
713 | + throw new Exception('Bad class name ' . $record_classname); |
|
714 | + } |
|
598 | 715 | |
599 | - if($record_classname == null) $record_classname = $plugin::get_egw_record_class(); |
|
600 | - if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname); |
|
716 | + if($record_classname == null) |
|
717 | + { |
|
718 | + $record_classname = $plugin::get_egw_record_class(); |
|
719 | + } |
|
720 | + if(!class_exists($record_classname)) |
|
721 | + { |
|
722 | + throw new Exception('Bad class name ' . $record_classname); |
|
723 | + } |
|
601 | 724 | |
602 | 725 | if(!$wizard_plugin) |
603 | 726 | { |
604 | 727 | $wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name); |
605 | - if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name); |
|
728 | + if(!class_exists($wizard_name)) |
|
729 | + { |
|
730 | + throw new Exception('Bad wizard name ' . $wizard_name); |
|
731 | + } |
|
606 | 732 | $wizard_plugin = new $wizard_name; |
607 | 733 | } |
608 | 734 | } |
@@ -622,7 +748,10 @@ discard block |
||
622 | 748 | foreach($record_classname::$types as $type => $type_fields) |
623 | 749 | { |
624 | 750 | // Only these for now, until filter methods for others are figured out |
625 | - if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue; |
|
751 | + if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) |
|
752 | + { |
|
753 | + continue; |
|
754 | + } |
|
626 | 755 | foreach($type_fields as $field_name) |
627 | 756 | { |
628 | 757 | $fields[$field_name] = array( |
@@ -640,14 +769,18 @@ discard block |
||
640 | 769 | $fields['#'.$field_name] = $settings; |
641 | 770 | } |
642 | 771 | |
643 | - foreach($fields as $field_name => &$settings) { |
|
772 | + foreach($fields as $field_name => &$settings) |
|
773 | + { |
|
644 | 774 | // Can't really filter on these (or at least no generic, sane way figured out yet) |
645 | 775 | if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea'))) |
646 | 776 | { |
647 | 777 | unset($fields[$field_name]); |
648 | 778 | continue; |
649 | 779 | } |
650 | - if($settings['type'] == 'radio') $settings['type'] = 'select'; |
|
780 | + if($settings['type'] == 'radio') |
|
781 | + { |
|
782 | + $settings['type'] = 'select'; |
|
783 | + } |
|
651 | 784 | switch($settings['type']) |
652 | 785 | { |
653 | 786 | case 'checkbox': |
@@ -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 |
@@ -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. |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * cleanup |
34 | 34 | * |
35 | 35 | * @return |
36 | - */ |
|
36 | + void |
|
37 | 37 | public function __destruct( ); |
38 | 38 | |
39 | 39 | /** |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param array $_options options for specific backends |
28 | 28 | * @return bool |
29 | 29 | */ |
30 | - public function __construct( $_stream, array $_options ); |
|
30 | + public function __construct($_stream, array $_options); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * cleanup |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string _position may be: {first|last|next|previous|somenumber} |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function get_record( $_position = 'next' ); |
|
45 | + public function get_record($_position = 'next'); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Retruns total number of records for the open resource. |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * updates $this->record |
139 | 139 | * |
140 | - * @param mixed $_position |
|
141 | - * @return bool |
|
140 | + * @param string $_position |
|
141 | + * @return null|false |
|
142 | 142 | */ |
143 | 143 | private function get_raw_record( $_position = 'next' ) { |
144 | 144 | switch ($_position) { |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | /** |
245 | 245 | * does conversions according to $this->conversion |
246 | 246 | * |
247 | - * @return bool |
|
247 | + * @return boolean|null |
|
248 | 248 | */ |
249 | 249 | protected function do_conversions() { |
250 | 250 | if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) { |
@@ -22,7 +22,9 @@ discard block |
||
22 | 22 | * @todo Throw away spechial chars and trim() entries ? |
23 | 23 | * @todo Check for XSS like userinput! (see common_functions) |
24 | 24 | */ |
25 | -class importexport_import_csv implements importexport_iface_import_record { //, Iterator { |
|
25 | +class importexport_import_csv implements importexport_iface_import_record |
|
26 | +{ |
|
27 | +//, Iterator { |
|
26 | 28 | |
27 | 29 | const csv_max_linelength = 8000; |
28 | 30 | |
@@ -83,10 +85,14 @@ discard block |
||
83 | 85 | * @param string $_resource resource containing data. May be each valid php-stream |
84 | 86 | * @param array $_options options for the resource array with keys: charset and fieldsep |
85 | 87 | */ |
86 | - public function __construct( $_resource, array $_options ) { |
|
88 | + public function __construct( $_resource, array $_options ) |
|
89 | + { |
|
87 | 90 | $this->resource = $_resource; |
88 | 91 | $this->csv_fieldsep = $_options['fieldsep']; |
89 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
92 | + if($_options['charset'] == 'user') |
|
93 | + { |
|
94 | + $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
95 | + } |
|
90 | 96 | $this->csv_charset = $_options['charset']; |
91 | 97 | return; |
92 | 98 | } // end of member function __construct |
@@ -94,7 +100,8 @@ discard block |
||
94 | 100 | /** |
95 | 101 | * cleanup |
96 | 102 | */ |
97 | - public function __destruct( ) { |
|
103 | + public function __destruct( ) |
|
104 | + { |
|
98 | 105 | } // end of member function __destruct |
99 | 106 | |
100 | 107 | /** |
@@ -103,20 +110,27 @@ discard block |
||
103 | 110 | * @param mixed _position may be: {current|first|last|next|previous|somenumber} |
104 | 111 | * @return mixed array with data / false if no furtor records |
105 | 112 | */ |
106 | - public function get_record( $_position = 'next' ) { |
|
113 | + public function get_record( $_position = 'next' ) |
|
114 | + { |
|
107 | 115 | |
108 | - if ($this->get_raw_record( $_position ) === false) { |
|
116 | + if ($this->get_raw_record( $_position ) === false) |
|
117 | + { |
|
109 | 118 | return false; |
110 | 119 | } |
111 | 120 | |
112 | 121 | // skip empty records |
113 | - if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position ); |
|
122 | + if( count( array_unique( $this->record ) ) < 2 ) |
|
123 | + { |
|
124 | + return $this->get_record( $_position ); |
|
125 | + } |
|
114 | 126 | |
115 | - if ( !empty( $this->conversion ) ) { |
|
127 | + if ( !empty( $this->conversion ) ) |
|
128 | + { |
|
116 | 129 | $this->do_conversions(); |
117 | 130 | } |
118 | 131 | |
119 | - if ( !empty( $this->mapping ) ) { |
|
132 | + if ( !empty( $this->mapping ) ) |
|
133 | + { |
|
120 | 134 | $this->do_fieldmapping(); |
121 | 135 | } |
122 | 136 | |
@@ -128,8 +142,10 @@ discard block |
||
128 | 142 | * |
129 | 143 | * @param int $_numToSkip |
130 | 144 | */ |
131 | - public function skip_records( $_numToSkip ) { |
|
132 | - while ( (int)$_numToSkip-- !== 0 ) { |
|
145 | + public function skip_records( $_numToSkip ) |
|
146 | + { |
|
147 | + while ( (int)$_numToSkip-- !== 0 ) |
|
148 | + { |
|
133 | 149 | fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
134 | 150 | } |
135 | 151 | } |
@@ -140,22 +156,27 @@ discard block |
||
140 | 156 | * @param mixed $_position |
141 | 157 | * @return bool |
142 | 158 | */ |
143 | - private function get_raw_record( $_position = 'next' ) { |
|
144 | - switch ($_position) { |
|
159 | + private function get_raw_record( $_position = 'next' ) |
|
160 | + { |
|
161 | + switch ($_position) |
|
162 | + { |
|
145 | 163 | case 'current' : |
146 | - if ($this->current_position == 0) { |
|
164 | + if ($this->current_position == 0) |
|
165 | + { |
|
147 | 166 | return; |
148 | 167 | } |
149 | 168 | break; |
150 | 169 | case 'first' : |
151 | - if (!$this->current_position == 0) { |
|
170 | + if (!$this->current_position == 0) |
|
171 | + { |
|
152 | 172 | $this->current_position = 0; |
153 | 173 | rewind($this->resource); |
154 | 174 | } |
155 | 175 | |
156 | 176 | case 'next' : |
157 | 177 | $csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
158 | - if (!is_array($csv_data)) { |
|
178 | + if (!is_array($csv_data)) |
|
179 | + { |
|
159 | 180 | return false; |
160 | 181 | } |
161 | 182 | $this->current_position++; |
@@ -163,33 +184,41 @@ discard block |
||
163 | 184 | break; |
164 | 185 | |
165 | 186 | case 'previous' : |
166 | - if ($this->current_position < 2) { |
|
187 | + if ($this->current_position < 2) |
|
188 | + { |
|
167 | 189 | throw new Exception('Error: There is no previous record!'); |
168 | 190 | } |
169 | 191 | $final_position = --$this->current_position; |
170 | 192 | $this->current_position = 0; |
171 | 193 | rewind($this->resource); |
172 | - while ($this->current_position !== $final_position) { |
|
194 | + while ($this->current_position !== $final_position) |
|
195 | + { |
|
173 | 196 | $this->get_raw_record(); |
174 | 197 | } |
175 | 198 | break; |
176 | 199 | |
177 | 200 | case 'last' : |
178 | - while ($this->get_raw_record()) {} |
|
201 | + while ($this->get_raw_record()) |
|
202 | + { |
|
203 | +} |
|
179 | 204 | break; |
180 | 205 | |
181 | 206 | default: //somenumber |
182 | - if (!is_int($_position)) { |
|
207 | + if (!is_int($_position)) |
|
208 | + { |
|
183 | 209 | throw new Exception('Error: $position must be one of {current|first|last|next|previous} or an integer value'); |
184 | 210 | } |
185 | - if ($_position == $this->current_position) { |
|
211 | + if ($_position == $this->current_position) |
|
212 | + { |
|
186 | 213 | break; |
187 | 214 | } |
188 | - elseif ($_position < $this->current_position) { |
|
215 | + elseif ($_position < $this->current_position) |
|
216 | + { |
|
189 | 217 | $this->current_position = 0; |
190 | 218 | rewind($this->resource); |
191 | 219 | } |
192 | - while ($this->current_position !== $_position) { |
|
220 | + while ($this->current_position !== $_position) |
|
221 | + { |
|
193 | 222 | $this->get_raw_record(); |
194 | 223 | } |
195 | 224 | break; |
@@ -202,12 +231,16 @@ discard block |
||
202 | 231 | * |
203 | 232 | * @return int |
204 | 233 | */ |
205 | - public function get_num_of_records( ) { |
|
206 | - if ($this->num_of_records > 0) { |
|
234 | + public function get_num_of_records( ) |
|
235 | + { |
|
236 | + if ($this->num_of_records > 0) |
|
237 | + { |
|
207 | 238 | return $this->num_of_records; |
208 | 239 | } |
209 | 240 | $current_position = $this->current_position; |
210 | - while ($this->get_raw_record()) {} |
|
241 | + while ($this->get_raw_record()) |
|
242 | + { |
|
243 | +} |
|
211 | 244 | $this->num_of_records = $this->current_position; |
212 | 245 | $this->get_record($current_position); |
213 | 246 | return $this->num_of_records; |
@@ -218,7 +251,8 @@ discard block |
||
218 | 251 | * |
219 | 252 | * @return int |
220 | 253 | */ |
221 | - public function get_current_position( ) { |
|
254 | + public function get_current_position( ) |
|
255 | + { |
|
222 | 256 | |
223 | 257 | return $this->current_position; |
224 | 258 | |
@@ -230,12 +264,16 @@ discard block |
||
230 | 264 | * |
231 | 265 | * @return |
232 | 266 | */ |
233 | - protected function do_fieldmapping( ) { |
|
267 | + protected function do_fieldmapping( ) |
|
268 | + { |
|
234 | 269 | $record = $this->record; |
235 | 270 | $this->record = array(); |
236 | 271 | foreach ($this->mapping as $cvs_idx => $new_idx) |
237 | 272 | { |
238 | - if( $new_idx == '' ) continue; |
|
273 | + if( $new_idx == '' ) |
|
274 | + { |
|
275 | + continue; |
|
276 | + } |
|
239 | 277 | $this->record[$new_idx] = $record[$cvs_idx]; |
240 | 278 | } |
241 | 279 | return true; |
@@ -246,8 +284,10 @@ discard block |
||
246 | 284 | * |
247 | 285 | * @return bool |
248 | 286 | */ |
249 | - protected function do_conversions() { |
|
250 | - if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) { |
|
287 | + protected function do_conversions() |
|
288 | + { |
|
289 | + if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) |
|
290 | + { |
|
251 | 291 | $this->record = $record; |
252 | 292 | return; |
253 | 293 | } |
@@ -264,16 +304,19 @@ discard block |
||
264 | 304 | * |
265 | 305 | * @return string warnings, if any |
266 | 306 | */ |
267 | - public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) { |
|
307 | + public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) |
|
308 | + { |
|
268 | 309 | $warnings = array(); |
269 | 310 | |
270 | 311 | // Automatic conversions |
271 | - if($appname) { |
|
312 | + if($appname) |
|
313 | + { |
|
272 | 314 | |
273 | 315 | // Load translations |
274 | 316 | Api\Translation::add_app($appname); |
275 | 317 | |
276 | - if(!self::$cf_parse_cache[$appname]) { |
|
318 | + if(!self::$cf_parse_cache[$appname]) |
|
319 | + { |
|
277 | 320 | $c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods); |
278 | 321 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
279 | 322 | } |
@@ -282,7 +325,10 @@ discard block |
||
282 | 325 | // Add in any fields that are keys to another app |
283 | 326 | foreach((array)$fields['links'] as $link_field => $app) |
284 | 327 | { |
285 | - if(is_numeric($link_field)) continue; |
|
328 | + if(is_numeric($link_field)) |
|
329 | + { |
|
330 | + continue; |
|
331 | + } |
|
286 | 332 | $links[$link_field] = $app; |
287 | 333 | // Set it as a normal link field |
288 | 334 | $fields['links'][] = $link_field; |
@@ -292,7 +338,8 @@ discard block |
||
292 | 338 | // Not quite a recursive merge, since only one level |
293 | 339 | foreach($fields as $type => &$list) |
294 | 340 | { |
295 | - if($c_fields[$type]) { |
|
341 | + if($c_fields[$type]) |
|
342 | + { |
|
296 | 343 | $list = array_merge($c_fields[$type], $list); |
297 | 344 | unset($c_fields[$type]); |
298 | 345 | } |
@@ -300,9 +347,12 @@ discard block |
||
300 | 347 | $fields += $c_fields; |
301 | 348 | $selects += $c_selects; |
302 | 349 | } |
303 | - if($fields) { |
|
304 | - foreach((array)$fields['select'] as $name) { |
|
305 | - if($record[$name] != null && is_array($selects) && $selects[$name]) { |
|
350 | + if($fields) |
|
351 | + { |
|
352 | + foreach((array)$fields['select'] as $name) |
|
353 | + { |
|
354 | + if($record[$name] != null && is_array($selects) && $selects[$name]) |
|
355 | + { |
|
306 | 356 | $key = array_search(strtolower($record[$name]), array_map('strtolower',$selects[$name])); |
307 | 357 | if($key !== false) |
308 | 358 | { |
@@ -311,11 +361,15 @@ discard block |
||
311 | 361 | else |
312 | 362 | { |
313 | 363 | $key = array_search(strtolower($record[$name]), array_map('strtolower',array_map('lang',$selects[$name]))); |
314 | - if($key !== false) $record[$name] = $key; |
|
364 | + if($key !== false) |
|
365 | + { |
|
366 | + $record[$name] = $key; |
|
367 | + } |
|
315 | 368 | } |
316 | 369 | } |
317 | 370 | } |
318 | - foreach((array)$fields['links'] as $name) { |
|
371 | + foreach((array)$fields['links'] as $name) |
|
372 | + { |
|
319 | 373 | if($record[$name] && $links[$name]) |
320 | 374 | { |
321 | 375 | // Primary key to another app, not a link |
@@ -357,15 +411,19 @@ discard block |
||
357 | 411 | lang($links[$name]), $record[$name]). |
358 | 412 | ' - ' . lang('no matches'); |
359 | 413 | continue; |
360 | - } else { |
|
414 | + } |
|
415 | + else |
|
416 | + { |
|
361 | 417 | $record[$name] = key($results); |
362 | 418 | } |
363 | 419 | } |
364 | 420 | } |
365 | 421 | } |
366 | - foreach((array)$fields['select-account'] as $name) { |
|
422 | + foreach((array)$fields['select-account'] as $name) |
|
423 | + { |
|
367 | 424 | // Compare against null to deal with empty arrays |
368 | - if ($record[$name]) { |
|
425 | + if ($record[$name]) |
|
426 | + { |
|
369 | 427 | // Automatically handle text owner without explicit translation |
370 | 428 | $new_owner = importexport_helper_functions::account_name2id($record[$name]); |
371 | 429 | if(count($new_owner) != count(explode(',',$record[$name]))) |
@@ -373,20 +431,26 @@ discard block |
||
373 | 431 | // Unable to parse value into account |
374 | 432 | $warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]); |
375 | 433 | } |
376 | - if($new_owner != '') { |
|
434 | + if($new_owner != '') |
|
435 | + { |
|
377 | 436 | $record[$name] = $new_owner; |
378 | - } else { |
|
437 | + } |
|
438 | + else |
|
439 | + { |
|
379 | 440 | // Clear it to prevent trouble later on |
380 | 441 | $record[$name] = ''; |
381 | 442 | } |
382 | 443 | } |
383 | 444 | } |
384 | - foreach((array)$fields['select-bool'] as $name) { |
|
385 | - if($record[$name] != null && $record[$name] != '') { |
|
445 | + foreach((array)$fields['select-bool'] as $name) |
|
446 | + { |
|
447 | + if($record[$name] != null && $record[$name] != '') |
|
448 | + { |
|
386 | 449 | $record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0); |
387 | 450 | } |
388 | 451 | } |
389 | - foreach((array)$fields['date-time'] as $name) { |
|
452 | + foreach((array)$fields['date-time'] as $name) |
|
453 | + { |
|
390 | 454 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
391 | 455 | { |
392 | 456 | // Need to handle format first |
@@ -412,7 +476,8 @@ discard block |
||
412 | 476 | // Try again, anything goes |
413 | 477 | try { |
414 | 478 | $formatted = new Api\DateTime($record[$name]); |
415 | - } catch (Exception $e) { |
|
479 | + } |
|
480 | + catch (Exception $e) { |
|
416 | 481 | $warnings[] = $name.': ' . $e->getMessage() . "\n" . |
417 | 482 | 'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat; |
418 | 483 | continue; |
@@ -434,7 +499,8 @@ discard block |
||
434 | 499 | } |
435 | 500 | |
436 | 501 | if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) && |
437 | - in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) { |
|
502 | + in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) |
|
503 | + { |
|
438 | 504 | // Custom fields stored in a particular format (from customfields_widget) |
439 | 505 | $record[$name] = date('Y-m-d H:i:s', $record[$name]); |
440 | 506 | } |
@@ -444,7 +510,8 @@ discard block |
||
444 | 510 | $record[$name] = null; |
445 | 511 | } |
446 | 512 | } |
447 | - foreach((array)$fields['date'] as $name) { |
|
513 | + foreach((array)$fields['date'] as $name) |
|
514 | + { |
|
448 | 515 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
449 | 516 | { |
450 | 517 | // Need to handle format first |
@@ -458,7 +525,8 @@ discard block |
||
458 | 525 | } |
459 | 526 | $record[$name] = Api\DateTime::server2user($record[$name],'ts'); |
460 | 527 | if(is_array(self::$cf_parse_cache[$appname][0]['date']) && |
461 | - in_array($name, self::$cf_parse_cache[$appname][0]['date'])) { |
|
528 | + in_array($name, self::$cf_parse_cache[$appname][0]['date'])) |
|
529 | + { |
|
462 | 530 | // Custom fields stored in a particular format (from customfields_widget) |
463 | 531 | $record[$name] = date('Y-m-d', $record[$name]); |
464 | 532 | } |
@@ -470,26 +538,37 @@ discard block |
||
470 | 538 | } |
471 | 539 | foreach((array)$fields['float'] as $name) |
472 | 540 | { |
473 | - if($record[$name] != null && $record[$name] != '') { |
|
541 | + if($record[$name] != null && $record[$name] != '') |
|
542 | + { |
|
474 | 543 | $dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
475 | - if (empty($dec_point)) $dec_point = '.'; |
|
544 | + if (empty($dec_point)) |
|
545 | + { |
|
546 | + $dec_point = '.'; |
|
547 | + } |
|
476 | 548 | $record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name]))); |
477 | 549 | } |
478 | 550 | } |
479 | 551 | |
480 | 552 | // Some custom methods for conversion |
481 | - foreach((array)$methods as $name => $method) { |
|
482 | - if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]); |
|
553 | + foreach((array)$methods as $name => $method) |
|
554 | + { |
|
555 | + if($record[$name]) |
|
556 | + { |
|
557 | + $record[$name] = ExecMethod($method, $record[$name]); |
|
558 | + } |
|
483 | 559 | } |
484 | 560 | |
485 | 561 | // cat_name2id will use currentapp to create new categories |
486 | 562 | $current_app = $GLOBALS['egw_info']['flags']['currentapp']; |
487 | - if($appname) { |
|
563 | + if($appname) |
|
564 | + { |
|
488 | 565 | $GLOBALS['egw_info']['flags']['currentapp'] = $appname; |
489 | 566 | } |
490 | 567 | $categories = new Api\Categories('',$appname); |
491 | - foreach((array)$fields['select-cat'] as $name) { |
|
492 | - if($record[$name]) { |
|
568 | + foreach((array)$fields['select-cat'] as $name) |
|
569 | + { |
|
570 | + if($record[$name]) |
|
571 | + { |
|
493 | 572 | // Only parse name if it needs it |
494 | 573 | if($format == 1) |
495 | 574 | { |
@@ -503,7 +582,10 @@ discard block |
||
503 | 582 | $cat_id = importexport_helper_functions::cat_name2id($record[$name]); |
504 | 583 | } |
505 | 584 | // Don't clear it if it wasn't found |
506 | - if($cat_id) $record[$name] = $cat_id; |
|
585 | + if($cat_id) |
|
586 | + { |
|
587 | + $record[$name] = $cat_id; |
|
588 | + } |
|
507 | 589 | } |
508 | 590 | } |
509 | 591 | } |
@@ -264,7 +264,7 @@ |
||
264 | 264 | * |
265 | 265 | * @return string warnings, if any |
266 | 266 | */ |
267 | - public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) { |
|
267 | + public static function convert(array &$record, array $fields = array(), $appname = null, array $selects = array(), $format=0) { |
|
268 | 268 | $warnings = array(); |
269 | 269 | |
270 | 270 | // Automatic conversions |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * @param string $_resource resource containing data. May be each valid php-stream |
81 | 81 | * @param array $_options options for the resource array with keys: charset and fieldsep |
82 | 82 | */ |
83 | - public function __construct( $_resource, array $_options ) { |
|
83 | + public function __construct($_resource, array $_options) { |
|
84 | 84 | $this->resource = $_resource; |
85 | 85 | $this->csv_fieldsep = $_options['fieldsep']; |
86 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
86 | + if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
87 | 87 | $this->csv_charset = $_options['charset']; |
88 | 88 | return; |
89 | 89 | } // end of member function __construct |
@@ -100,20 +100,20 @@ discard block |
||
100 | 100 | * @param mixed _position may be: {current|first|last|next|previous|somenumber} |
101 | 101 | * @return mixed array with data / false if no furtor records |
102 | 102 | */ |
103 | - public function get_record( $_position = 'next' ) { |
|
103 | + public function get_record($_position = 'next') { |
|
104 | 104 | |
105 | - if ($this->get_raw_record( $_position ) === false) { |
|
105 | + if ($this->get_raw_record($_position) === false) { |
|
106 | 106 | return false; |
107 | 107 | } |
108 | 108 | |
109 | 109 | // skip empty records |
110 | - if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position ); |
|
110 | + if (count(array_unique($this->record)) < 2) return $this->get_record($_position); |
|
111 | 111 | |
112 | - if ( !empty( $this->conversion ) ) { |
|
112 | + if (!empty($this->conversion)) { |
|
113 | 113 | $this->do_conversions(); |
114 | 114 | } |
115 | 115 | |
116 | - if ( !empty( $this->mapping ) ) { |
|
116 | + if (!empty($this->mapping)) { |
|
117 | 117 | $this->do_fieldmapping(); |
118 | 118 | } |
119 | 119 | |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param int $_numToSkip |
127 | 127 | */ |
128 | - public function skip_records( $_numToSkip ) { |
|
129 | - while ( (int)$_numToSkip-- !== 0 ) { |
|
130 | - fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
128 | + public function skip_records($_numToSkip) { |
|
129 | + while ((int)$_numToSkip-- !== 0) { |
|
130 | + fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param mixed $_position |
138 | 138 | * @return bool |
139 | 139 | */ |
140 | - private function get_raw_record( $_position = 'next' ) { |
|
140 | + private function get_raw_record($_position = 'next') { |
|
141 | 141 | switch ($_position) { |
142 | 142 | case 'current' : |
143 | 143 | if ($this->current_position == 0) { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | case 'next' : |
154 | - $csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
154 | + $csv_data = fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
155 | 155 | if (!is_array($csv_data)) { |
156 | 156 | return false; |
157 | 157 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $this->record = array(); |
233 | 233 | foreach ($this->mapping as $cvs_idx => $new_idx) |
234 | 234 | { |
235 | - if( $new_idx == '' ) continue; |
|
235 | + if ($new_idx == '') continue; |
|
236 | 236 | $this->record[$new_idx] = $record[$cvs_idx]; |
237 | 237 | } |
238 | 238 | return true; |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return bool |
245 | 245 | */ |
246 | 246 | protected function do_conversions() { |
247 | - if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) { |
|
247 | + if ($record = importexport_helper_functions::conversion($this->record, $this->conversion, $this->conversion_class)) { |
|
248 | 248 | $this->record = $record; |
249 | 249 | return; |
250 | 250 | } |
@@ -261,25 +261,25 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return string warnings, if any |
263 | 263 | */ |
264 | - public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) { |
|
264 | + public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format = 0) { |
|
265 | 265 | $warnings = array(); |
266 | 266 | |
267 | 267 | // Automatic conversions |
268 | - if($appname) { |
|
268 | + if ($appname) { |
|
269 | 269 | |
270 | 270 | // Load translations |
271 | 271 | translation::add_app($appname); |
272 | 272 | |
273 | - if(!self::$cf_parse_cache[$appname]) { |
|
273 | + if (!self::$cf_parse_cache[$appname]) { |
|
274 | 274 | $c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods); |
275 | 275 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
276 | 276 | } |
277 | 277 | list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname]; |
278 | 278 | |
279 | 279 | // Add in any fields that are keys to another app |
280 | - foreach((array)$fields['links'] as $link_field => $app) |
|
280 | + foreach ((array)$fields['links'] as $link_field => $app) |
|
281 | 281 | { |
282 | - if(is_numeric($link_field)) continue; |
|
282 | + if (is_numeric($link_field)) continue; |
|
283 | 283 | $links[$link_field] = $app; |
284 | 284 | // Set it as a normal link field |
285 | 285 | $fields['links'][] = $link_field; |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Not quite a recursive merge, since only one level |
290 | - foreach($fields as $type => &$list) |
|
290 | + foreach ($fields as $type => &$list) |
|
291 | 291 | { |
292 | - if($c_fields[$type]) { |
|
292 | + if ($c_fields[$type]) { |
|
293 | 293 | $list = array_merge($c_fields[$type], $list); |
294 | 294 | unset($c_fields[$type]); |
295 | 295 | } |
@@ -297,36 +297,36 @@ discard block |
||
297 | 297 | $fields += $c_fields; |
298 | 298 | $selects += $c_selects; |
299 | 299 | } |
300 | - if($fields) { |
|
301 | - foreach((array)$fields['select'] as $name) { |
|
302 | - if($record[$name] != null && is_array($selects) && $selects[$name]) { |
|
303 | - $key = array_search(strtolower($record[$name]), array_map('strtolower',$selects[$name])); |
|
304 | - if($key !== false) |
|
300 | + if ($fields) { |
|
301 | + foreach ((array)$fields['select'] as $name) { |
|
302 | + if ($record[$name] != null && is_array($selects) && $selects[$name]) { |
|
303 | + $key = array_search(strtolower($record[$name]), array_map('strtolower', $selects[$name])); |
|
304 | + if ($key !== false) |
|
305 | 305 | { |
306 | 306 | $record[$name] = $key; |
307 | 307 | } |
308 | 308 | else |
309 | 309 | { |
310 | - $key = array_search(strtolower($record[$name]), array_map('strtolower',array_map('lang',$selects[$name]))); |
|
311 | - if($key !== false) $record[$name] = $key; |
|
310 | + $key = array_search(strtolower($record[$name]), array_map('strtolower', array_map('lang', $selects[$name]))); |
|
311 | + if ($key !== false) $record[$name] = $key; |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | - foreach((array)$fields['links'] as $name) { |
|
316 | - if($record[$name] && $links[$name]) |
|
315 | + foreach ((array)$fields['links'] as $name) { |
|
316 | + if ($record[$name] && $links[$name]) |
|
317 | 317 | { |
318 | 318 | // Primary key to another app, not a link |
319 | 319 | // Text - search for a matching record |
320 | - if(!is_numeric($record[$name])) |
|
320 | + if (!is_numeric($record[$name])) |
|
321 | 321 | { |
322 | 322 | $results = egw_link::query($links[$name], $record[$name]); |
323 | - if(count($results) >= 1) |
|
323 | + if (count($results) >= 1) |
|
324 | 324 | { |
325 | 325 | // More than 1 result. Check for exact match |
326 | 326 | $exact_count = 0; |
327 | - foreach($results as $id => $title) |
|
327 | + foreach ($results as $id => $title) |
|
328 | 328 | { |
329 | - if($title == $record[$name]) |
|
329 | + if ($title == $record[$name]) |
|
330 | 330 | { |
331 | 331 | $exact_count++; |
332 | 332 | $app_id = $id; |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | unset($results[$id]); |
336 | 336 | } |
337 | 337 | // Too many exact matches, or none good enough |
338 | - if($exact_count > 1 || count($results) == 0) |
|
338 | + if ($exact_count > 1 || count($results) == 0) |
|
339 | 339 | { |
340 | 340 | $warnings[] = lang('Unable to link to %1 "%2"', |
341 | 341 | lang($links[$name]), $record[$name]). |
342 | - ' - ' .lang('too many matches'); |
|
342 | + ' - '.lang('too many matches'); |
|
343 | 343 | continue; |
344 | 344 | } |
345 | 345 | elseif ($exact_count == 1) |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | { |
353 | 353 | $warnings[] = lang('Unable to link to %1 "%2"', |
354 | 354 | lang($links[$name]), $record[$name]). |
355 | - ' - ' . lang('no matches'); |
|
355 | + ' - '.lang('no matches'); |
|
356 | 356 | continue; |
357 | 357 | } else { |
358 | 358 | $record[$name] = key($results); |
@@ -360,17 +360,17 @@ discard block |
||
360 | 360 | } |
361 | 361 | } |
362 | 362 | } |
363 | - foreach((array)$fields['select-account'] as $name) { |
|
363 | + foreach ((array)$fields['select-account'] as $name) { |
|
364 | 364 | // Compare against null to deal with empty arrays |
365 | 365 | if ($record[$name]) { |
366 | 366 | // Automatically handle text owner without explicit translation |
367 | 367 | $new_owner = importexport_helper_functions::account_name2id($record[$name]); |
368 | - if(count($new_owner) != count(explode(',',$record[$name]))) |
|
368 | + if (count($new_owner) != count(explode(',', $record[$name]))) |
|
369 | 369 | { |
370 | 370 | // Unable to parse value into account |
371 | - $warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]); |
|
371 | + $warnings[] = $name.': '.lang('%1 is not a known user or group', $record[$name]); |
|
372 | 372 | } |
373 | - if($new_owner != '') { |
|
373 | + if ($new_owner != '') { |
|
374 | 374 | $record[$name] = $new_owner; |
375 | 375 | } else { |
376 | 376 | // Clear it to prevent trouble later on |
@@ -378,24 +378,24 @@ discard block |
||
378 | 378 | } |
379 | 379 | } |
380 | 380 | } |
381 | - foreach((array)$fields['select-bool'] as $name) { |
|
382 | - if($record[$name] != null && $record[$name] != '') { |
|
381 | + foreach ((array)$fields['select-bool'] as $name) { |
|
382 | + if ($record[$name] != null && $record[$name] != '') { |
|
383 | 383 | $record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0); |
384 | 384 | } |
385 | 385 | } |
386 | - foreach((array)$fields['date-time'] as $name) { |
|
386 | + foreach ((array)$fields['date-time'] as $name) { |
|
387 | 387 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
388 | 388 | { |
389 | 389 | // Need to handle format first |
390 | - if($format == 1) |
|
390 | + if ($format == 1) |
|
391 | 391 | { |
392 | 392 | $formatted = egw_time::createFromFormat( |
393 | - '!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat, |
|
393 | + '!'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat, |
|
394 | 394 | $record[$name], |
395 | 395 | egw_time::$user_timezone |
396 | 396 | ); |
397 | 397 | |
398 | - if(!$formatted && $errors = egw_time::getLastErrors()) |
|
398 | + if (!$formatted && $errors = egw_time::getLastErrors()) |
|
399 | 399 | { |
400 | 400 | // Try again, without time |
401 | 401 | $formatted = egw_time::createFromFormat( |
@@ -404,70 +404,70 @@ discard block |
||
404 | 404 | egw_time::$user_timezone |
405 | 405 | ); |
406 | 406 | |
407 | - if(!$formatted && $errors = egw_time::getLastErrors()) |
|
407 | + if (!$formatted && $errors = egw_time::getLastErrors()) |
|
408 | 408 | { |
409 | 409 | // Try again, anything goes |
410 | 410 | try { |
411 | 411 | $formatted = new egw_time($record[$name]); |
412 | 412 | } catch (Exception $e) { |
413 | - $warnings[] = $name.': ' . $e->getMessage() . "\n" . |
|
414 | - 'Format: '.'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat; |
|
413 | + $warnings[] = $name.': '.$e->getMessage()."\n". |
|
414 | + 'Format: '.'!'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat; |
|
415 | 415 | continue; |
416 | 416 | } |
417 | 417 | $errors = egw_time::getLastErrors(); |
418 | - foreach($errors['errors'] as $char => $msg) |
|
418 | + foreach ($errors['errors'] as $char => $msg) |
|
419 | 419 | { |
420 | 420 | $warnings[] = "$name: [$char] $msg\n". |
421 | - 'Format: '.'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat; |
|
421 | + 'Format: '.'!'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat; |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
425 | - if($formatted) |
|
425 | + if ($formatted) |
|
426 | 426 | { |
427 | 427 | $record[$name] = $formatted->getTimestamp(); |
428 | 428 | // Timestamp is apparently in server time, but apps will do the same conversion |
429 | - $record[$name] = egw_time::server2user($record[$name],'ts'); |
|
429 | + $record[$name] = egw_time::server2user($record[$name], 'ts'); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) && |
|
433 | + if (is_array(self::$cf_parse_cache[$appname][0]['date-time']) && |
|
434 | 434 | in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) { |
435 | 435 | // Custom fields stored in a particular format (from customfields_widget) |
436 | 436 | $record[$name] = date('Y-m-d H:i:s', $record[$name]); |
437 | 437 | } |
438 | 438 | } |
439 | - if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
439 | + if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
440 | 440 | { |
441 | 441 | $record[$name] = null; |
442 | 442 | } |
443 | 443 | } |
444 | - foreach((array)$fields['date'] as $name) { |
|
444 | + foreach ((array)$fields['date'] as $name) { |
|
445 | 445 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
446 | 446 | { |
447 | 447 | // Need to handle format first |
448 | - if($format == 1) |
|
448 | + if ($format == 1) |
|
449 | 449 | { |
450 | 450 | $formatted = egw_time::createFromFormat('!'.egw_time::$user_dateformat, $record[$name]); |
451 | - if($formatted && $errors = egw_time::getLastErrors() && $errors['error_count'] == 0) |
|
451 | + if ($formatted && $errors = egw_time::getLastErrors() && $errors['error_count'] == 0) |
|
452 | 452 | { |
453 | 453 | $record[$name] = $formatted->getTimestamp(); |
454 | 454 | } |
455 | 455 | } |
456 | - $record[$name] = egw_time::server2user($record[$name],'ts'); |
|
457 | - if(is_array(self::$cf_parse_cache[$appname][0]['date']) && |
|
456 | + $record[$name] = egw_time::server2user($record[$name], 'ts'); |
|
457 | + if (is_array(self::$cf_parse_cache[$appname][0]['date']) && |
|
458 | 458 | in_array($name, self::$cf_parse_cache[$appname][0]['date'])) { |
459 | 459 | // Custom fields stored in a particular format (from customfields_widget) |
460 | 460 | $record[$name] = date('Y-m-d', $record[$name]); |
461 | 461 | } |
462 | 462 | } |
463 | - if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
463 | + if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
464 | 464 | { |
465 | 465 | $record[$name] = null; |
466 | 466 | } |
467 | 467 | } |
468 | - foreach((array)$fields['float'] as $name) |
|
468 | + foreach ((array)$fields['float'] as $name) |
|
469 | 469 | { |
470 | - if($record[$name] != null && $record[$name] != '') { |
|
470 | + if ($record[$name] != null && $record[$name] != '') { |
|
471 | 471 | $dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
472 | 472 | if (empty($dec_point)) $dec_point = '.'; |
473 | 473 | $record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name]))); |
@@ -475,23 +475,23 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | // Some custom methods for conversion |
478 | - foreach((array)$methods as $name => $method) { |
|
479 | - if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]); |
|
478 | + foreach ((array)$methods as $name => $method) { |
|
479 | + if ($record[$name]) $record[$name] = ExecMethod($method, $record[$name]); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | // cat_name2id will use currentapp to create new categories |
483 | 483 | $current_app = $GLOBALS['egw_info']['flags']['currentapp']; |
484 | - if($appname) { |
|
484 | + if ($appname) { |
|
485 | 485 | $GLOBALS['egw_info']['flags']['currentapp'] = $appname; |
486 | 486 | } |
487 | - $categories = new categories('',$appname); |
|
488 | - foreach((array)$fields['select-cat'] as $name) { |
|
489 | - if($record[$name]) { |
|
487 | + $categories = new categories('', $appname); |
|
488 | + foreach ((array)$fields['select-cat'] as $name) { |
|
489 | + if ($record[$name]) { |
|
490 | 490 | // Only parse name if it needs it |
491 | - if($format == 1) |
|
491 | + if ($format == 1) |
|
492 | 492 | { |
493 | - $existing_cat = $categories->exists('all',$record[$name]); |
|
494 | - if($existing_cat) |
|
493 | + $existing_cat = $categories->exists('all', $record[$name]); |
|
494 | + if ($existing_cat) |
|
495 | 495 | { |
496 | 496 | $cat_id = $existing_cat; |
497 | 497 | } |
@@ -500,14 +500,14 @@ discard block |
||
500 | 500 | $cat_id = importexport_helper_functions::cat_name2id($record[$name]); |
501 | 501 | } |
502 | 502 | // Don't clear it if it wasn't found |
503 | - if($cat_id) $record[$name] = $cat_id; |
|
503 | + if ($cat_id) $record[$name] = $cat_id; |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | } |
507 | 507 | $GLOBALS['egw_info']['flags']['currentapp'] = $current_app; |
508 | 508 | } |
509 | 509 | |
510 | - return implode("\n",$warnings); |
|
510 | + return implode("\n", $warnings); |
|
511 | 511 | } |
512 | 512 | } // end of import_csv |
513 | 513 | ?> |