1 | <?php |
||
2 | /** |
||
3 | * EGroupware - Wizard for Adressbook CSV export |
||
4 | * |
||
5 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
6 | * @package addressbook |
||
7 | * @link http://www.egroupware.org |
||
8 | * @author Nathan Gray |
||
9 | * @version $Id$ |
||
10 | */ |
||
11 | |||
12 | use EGroupware\Api; |
||
13 | |||
14 | class addressbook_wizard_export_contacts_csv extends importexport_wizard_basic_export_csv |
||
15 | { |
||
16 | public function __construct() { |
||
17 | parent::__construct(); |
||
18 | |||
19 | $this->steps['wizard_step50'] = lang('Choose export options'); |
||
20 | $this->step_templates['wizard_step50'] = 'addressbook.export_explode_fields'; |
||
21 | |||
22 | // Field mapping |
||
23 | $bocontacts = new Api\Contacts(); |
||
24 | $this->export_fields = $bocontacts->contact_fields; |
||
25 | foreach($bocontacts->customfields as $name => $data) { |
||
26 | $this->export_fields['#'.$name] = $data['label']; |
||
27 | } |
||
28 | unset($this->export_fields['jpegphoto']); // can't cvs export that |
||
29 | |||
30 | // Add in last/next appointments |
||
31 | // NB: last_date and next_date are used instead of last_event & next_event |
||
32 | // to avoid automatic conversion - we want to export link title, not date-time |
||
33 | $this->export_fields['last_date'] = lang('Last date'); |
||
34 | $this->export_fields['next_date'] = lang('Next date'); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Overridden to be able to skip the next step |
||
39 | */ |
||
40 | function wizard_step40(&$content, &$sel_options, &$readonlys, &$preserv) { |
||
41 | |||
42 | if ($content['step'] == 'wizard_step40' && array_search('pressed', $content['button']) == 'next') { |
||
43 | $result = parent::wizard_step40($content, $sel_options, $readonlys, $preserv); |
||
44 | $field_list = $this->get_field_list($content); |
||
45 | if(count($field_list)) { |
||
46 | return $result; |
||
47 | } else { |
||
48 | return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],2); |
||
49 | } |
||
50 | } else { |
||
51 | return parent::wizard_step40($content, $sel_options, $readonlys, $preserv); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Choose how to export multi-selects (includes Api\Categories) |
||
57 | */ |
||
58 | function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv) |
||
59 | { |
||
60 | if($this->debug) error_log(get_class($this) . '::wizard_step50->$content '.print_r($content,true)); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
61 | // return from step50 |
||
62 | if ($content['step'] == 'wizard_step50') |
||
63 | { |
||
64 | if($content['explode_multiselects']) { |
||
65 | $explodes = $content['explode_multiselects']; |
||
66 | $content['explode_multiselects'] = array(); |
||
67 | foreach($explodes as $row => $settings) { |
||
68 | if($settings['explode'] != addressbook_export_contacts_csv::NO_EXPLODE) { |
||
69 | $content['explode_multiselects'][$settings['field']] = $settings; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | switch (array_search('pressed', $content['button'])) |
||
74 | { |
||
75 | case 'next': |
||
76 | return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],1); |
||
77 | case 'previous' : |
||
78 | return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],-1); |
||
79 | case 'finish': |
||
80 | return 'wizard_finish'; |
||
81 | default : |
||
82 | return $this->wizard_step50($content,$sel_options,$readonlys,$preserv); |
||
83 | } |
||
84 | } |
||
85 | // init step50 |
||
86 | else |
||
87 | { |
||
88 | $content['msg'] = $this->steps['wizard_step50']; |
||
89 | $content['step'] = 'wizard_step50'; |
||
90 | unset ($preserv['button']); |
||
91 | $field_list = $this->get_field_list($content); |
||
92 | |||
93 | $settings = $content['explode_multiselects'] ? $content['explode_multiselects'] : $content['plugin_options']['explode_multiselects']; |
||
94 | |||
95 | // Skip this step if no fields applicable |
||
96 | if(count($field_list) == 0) { |
||
97 | $content['explode_multiselects'] = array(); |
||
98 | } |
||
99 | |||
100 | $cat_options = array( |
||
101 | addressbook_export_contacts_csv::NO_EXPLODE => lang('All in one field'), |
||
102 | addressbook_export_contacts_csv::MAIN_CATS => lang('Main Api\Categories in their own field'), |
||
103 | addressbook_export_contacts_csv::EACH_CAT => lang('Each category in its own field'), |
||
104 | ); |
||
105 | $multi_options = array( |
||
106 | addressbook_export_contacts_csv::NO_EXPLODE => lang('All in one field'), |
||
107 | addressbook_export_contacts_csv::EXPLODE => lang('Each option in its own field'), |
||
108 | ); |
||
109 | |||
110 | $row = 1; |
||
111 | foreach($field_list as $field => $name) { |
||
112 | $content['explode_multiselects'][$row] = array( |
||
113 | 'field' => $field, |
||
114 | 'name' => $name, |
||
115 | 'explode'=> $settings[$field] |
||
116 | ); |
||
117 | if($field == 'cat_id') { |
||
118 | $sel_options['explode_multiselects'][$row]['explode'] = $cat_options; |
||
119 | } else { |
||
120 | $sel_options['explode_multiselects'][$row]['explode'] = $multi_options; |
||
121 | } |
||
122 | $row++; |
||
123 | } |
||
124 | // Cheat server side validation, which can't handle different options per row |
||
125 | $sel_options['explode'] = $cat_options + $multi_options; |
||
126 | $preserv = $content; |
||
127 | //_debug_array($content['explode_multiselects']); |
||
128 | return $this->step_templates[$content['step']]; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Get a list of multi-select fields |
||
134 | */ |
||
135 | protected function get_field_list($content) { |
||
136 | $field_list = array(); |
||
137 | |||
138 | // Category gets special handling |
||
139 | if(in_array('cat_id', array_keys($content['mapping']))) { |
||
140 | $field_list['cat_id'] = $this->export_fields['cat_id']; |
||
141 | } |
||
142 | |||
143 | // Add any multi-select custom fields |
||
144 | $custom = Api\Storage\Customfields::get('addressbook'); |
||
145 | foreach($custom as $name => $c_field) { |
||
146 | if($c_field['type'] == 'select' && $c_field['rows'] > 1 && in_array('#'.$name, array_keys($content['mapping']))) { |
||
147 | $field_list['#'.$name] = $c_field['label']; |
||
148 | } |
||
149 | } |
||
150 | return $field_list; |
||
151 | } |
||
152 | } |
||
153 |