1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * eGroupWare - Contacts Center * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by: * |
---|
6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
7 | * - Jonas Goes <jqhcb@users.sourceforge.net> * |
---|
8 | * sponsored by Thyamad - http://www.thyamad.com * |
---|
9 | * ------------------------------------------------------------------------- * |
---|
10 | * This program is free software; you can redistribute it and/or modify it * |
---|
11 | * under the terms of the GNU General Public License as published by the * |
---|
12 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
13 | * option) any later version. * |
---|
14 | \***************************************************************************/ |
---|
15 | |
---|
16 | |
---|
17 | class ui_data |
---|
18 | { |
---|
19 | var $public_functions = array( |
---|
20 | 'data_manager' => true, |
---|
21 | 'advanced_searh_fields' => true |
---|
22 | ); |
---|
23 | |
---|
24 | var $bo; |
---|
25 | var $so_group; |
---|
26 | var $typeContact; |
---|
27 | var $preferences; |
---|
28 | |
---|
29 | var $page_info = array( |
---|
30 | 'n_cards' => 20, |
---|
31 | 'n_pages' => false, |
---|
32 | 'actual_letter' => 'A', |
---|
33 | 'actual_page' => 1, |
---|
34 | 'actual_entries' => false, |
---|
35 | 'changed' => false, |
---|
36 | 'catalogs' => false, |
---|
37 | 'actual_catalog' => false |
---|
38 | ); |
---|
39 | |
---|
40 | /*! |
---|
41 | |
---|
42 | @function ui_data |
---|
43 | @abstract The constructor. Sets the initial parameters and loads |
---|
44 | the data saved in the session |
---|
45 | @author Raphael Derosso Pereira |
---|
46 | |
---|
47 | */ |
---|
48 | function ui_data() |
---|
49 | { |
---|
50 | $temp = $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter'); |
---|
51 | $temp2 = $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter'); |
---|
52 | |
---|
53 | $this->bo = CreateObject('contactcenter.bo_contactcenter'); |
---|
54 | |
---|
55 | if ($temp) |
---|
56 | { |
---|
57 | $this->page_info = $temp; |
---|
58 | } |
---|
59 | |
---|
60 | if ($temp2) |
---|
61 | { |
---|
62 | $this->all_entries = $temp2; |
---|
63 | } |
---|
64 | |
---|
65 | if (!$this->page_info['actual_catalog']) |
---|
66 | { |
---|
67 | $catalogs = $this->bo->get_catalog_tree(); |
---|
68 | $this->page_info['actual_catalog'] = $catalogs[0]; |
---|
69 | } |
---|
70 | |
---|
71 | $this->page_info['actual_catalog'] = $this->bo->set_catalog($this->page_info['actual_catalog']); |
---|
72 | |
---|
73 | |
---|
74 | if($this->page_info['actual_catalog']['class'] == 'bo_group_manager') |
---|
75 | $this -> typeContact = 'groups'; |
---|
76 | /**rev 104**/ |
---|
77 | else if($this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager') |
---|
78 | $this -> typeContact = 'shared_groups'; |
---|
79 | else if($this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager') |
---|
80 | $this -> typeContact = 'shared_contacts'; |
---|
81 | /******/ |
---|
82 | else |
---|
83 | $this -> typeContact = 'contacts'; |
---|
84 | $this->preferences = $_SESSION['phpgw_info']['user']['preferences']['contactcenter']; |
---|
85 | } |
---|
86 | |
---|
87 | /*! |
---|
88 | |
---|
89 | @function index |
---|
90 | @abstract Builds the Main Page |
---|
91 | @author Raphael Derosso Pereira |
---|
92 | @author Jonas Goes |
---|
93 | |
---|
94 | */ |
---|
95 | function index() |
---|
96 | { |
---|
97 | if(!@is_object($GLOBALS['phpgw']->js)) |
---|
98 | { |
---|
99 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
100 | } |
---|
101 | |
---|
102 | $GLOBALS['phpgw']->js->validate_file('venus','table'); |
---|
103 | $GLOBALS['phpgw']->js->validate_file('venus','shapes'); |
---|
104 | $GLOBALS['phpgw']->js->validate_file('venus','jsStructUtil'); |
---|
105 | $GLOBALS['phpgw']->js->validate_file('venus','cssUtil'); |
---|
106 | |
---|
107 | // $GLOBALS['phpgw']->js->set_onload('setTimeout(\'updateCards()\',1000)'); |
---|
108 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
109 | |
---|
110 | $GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl')); |
---|
111 | $GLOBALS['phpgw']->template->set_var('cc_root_dir', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/'); |
---|
112 | $GLOBALS['phpgw']->template->set_var('cc_msg_not_informed', lang('Not informed')); |
---|
113 | /* Quick Add */ |
---|
114 | $GLOBALS['phpgw']->template->set_var('cc_qa_alias',lang('Alias').':'); |
---|
115 | $GLOBALS['phpgw']->template->set_var('cc_qa_given_names',lang('Given Names').':'); |
---|
116 | $GLOBALS['phpgw']->template->set_var('cc_qa_family_names',lang('Family Names').':'); |
---|
117 | $GLOBALS['phpgw']->template->set_var('cc_qa_phone',lang('Phone').':'); |
---|
118 | $GLOBALS['phpgw']->template->set_var('cc_qa_email',lang('Email').':'); |
---|
119 | $GLOBALS['phpgw']->template->set_var('cc_qa_save',lang('Save')); |
---|
120 | $GLOBALS['phpgw']->template->set_var('cc_qa_clear',lang('Clear')); |
---|
121 | $GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close')); |
---|
122 | /* End Quick Add */ |
---|
123 | |
---|
124 | /* Advanced Search */ |
---|
125 | |
---|
126 | $GLOBALS['phpgw']->template->set_var('cc_corporate',lang('Corporate')); |
---|
127 | $GLOBALS['phpgw']->template->set_var('cc_cs_title',lang('Advanced Search')); |
---|
128 | $GLOBALS['phpgw']->template->set_var('cc_catalogues',lang('Catalogues')); |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | /* End of Advanced Search*/ |
---|
133 | |
---|
134 | $cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css'; |
---|
135 | $cc_card_image_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/card.png'; |
---|
136 | $GLOBALS['phpgw']->template->set_var('cc_css',$cc_css_file); |
---|
137 | $GLOBALS['phpgw']->template->set_var('cc_dtree_css', $cc_dtree_file); |
---|
138 | $GLOBALS['phpgw']->template->set_var('cc_card_image',$cc_card_image_file); |
---|
139 | |
---|
140 | $GLOBALS['phpgw']->template->set_var('cc_personal',lang('Personal')); |
---|
141 | |
---|
142 | /***rev 104***/ |
---|
143 | //$GLOBALS['phpgw']->template->set_var('cc_full_add',lang('Full Add')); |
---|
144 | $GLOBALS['phpgw']->template->set_var('cc_full_add_button',lang('Full Add')); |
---|
145 | /******/ |
---|
146 | $GLOBALS['phpgw']->template->set_var('cc_full_add_button_sh',lang('Full Add Shared')); |
---|
147 | $GLOBALS['phpgw']->template->set_var('cc_reset',lang('Reset')); |
---|
148 | |
---|
149 | $GLOBALS['phpgw']->template->set_var('cc_personal_data',lang('Personal Data')); |
---|
150 | $GLOBALS['phpgw']->template->set_var('cc_addresses',lang('Addresses')); |
---|
151 | $GLOBALS['phpgw']->template->set_var('cc_connections',lang('Connections')); |
---|
152 | $GLOBALS['phpgw']->template->set_var('cc_relations',lang('Relations')); |
---|
153 | |
---|
154 | $GLOBALS['phpgw']->template->set_var('cc_quick_add',lang('Quick Add')); |
---|
155 | $GLOBALS['phpgw']->template->set_var('cc_catalogs',lang('Catalogues')); |
---|
156 | $GLOBALS['phpgw']->template->set_var('cc_group_add',lang('Group Add')); |
---|
157 | |
---|
158 | /* Panel */ |
---|
159 | $GLOBALS['phpgw']->template->set_var('cc_panel_new',lang('New').'...'); |
---|
160 | $GLOBALS['phpgw']->template->set_var('cc_panel_search',lang('Search').'...'); |
---|
161 | $GLOBALS['phpgw']->template->set_var('cc_panel_table',lang('Table View')); |
---|
162 | $GLOBALS['phpgw']->template->set_var('cc_panel_cards',lang('Cards View')); |
---|
163 | $GLOBALS['phpgw']->template->set_var('cc_btn_import_export', lang('Import/Export')); |
---|
164 | $GLOBALS['phpgw']->template->set_var('cc_btn_new', lang("New...")); |
---|
165 | |
---|
166 | $GLOBALS['phpgw']->template->set_var('cc_panel_search_found',lang('Showing found entries')); |
---|
167 | $GLOBALS['phpgw']->template->set_var('cc_panel_first_page',lang('First Page')); |
---|
168 | $GLOBALS['phpgw']->template->set_var('cc_panel_previous_page',lang('Previous Page')); |
---|
169 | $GLOBALS['phpgw']->template->set_var('cc_panel_next_page',lang('Next Page')); |
---|
170 | $GLOBALS['phpgw']->template->set_var('cc_panel_last_page',lang('Last Page')); |
---|
171 | $GLOBALS['phpgw']->template->set_var('cc_all',lang('all')); |
---|
172 | /* End Panel */ |
---|
173 | |
---|
174 | /* Messages */ |
---|
175 | /**rev 104**/ |
---|
176 | $GLOBALS['phpgw']->template->set_var('cc_msg_not_allowed',lang('Not Allowed')); |
---|
177 | $GLOBALS['phpgw']->template->set_var('cc_msg_unavailable',lang('Unavailable function')); |
---|
178 | /*****/ |
---|
179 | |
---|
180 | |
---|
181 | $GLOBALS['phpgw']->template->set_var('cc_msg_name_mandatory',lang('Name is mandatory')); |
---|
182 | $GLOBALS['phpgw']->template->set_var('cc_msg_err_invalid_serch',lang('The query should not have the characters {%,?}')); |
---|
183 | $GLOBALS['phpgw']->template->set_var('cc_msg_tel_or_mail_required',lang('Tel or email is required')); |
---|
184 | |
---|
185 | $GLOBALS['phpgw']->template->set_var('cc_msg_no_cards',lang('No Cards')); |
---|
186 | $GLOBALS['phpgw']->template->set_var('cc_msg_err_no_room',lang('No Room for Cards! Increase your browser area.')); |
---|
187 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_new',lang('New from same Company')); |
---|
188 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_edit',lang('Edit Contact')); |
---|
189 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove',lang('Remove Contact')); |
---|
190 | $GLOBALS['phpgw']->template->set_var('cc_send_mail',lang('Send Mail')); |
---|
191 | $GLOBALS['phpgw']->template->set_var('cc_msg_group_edit',lang('Edit Group')); |
---|
192 | $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove',lang('Remove Group')); |
---|
193 | $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove_confirm',lang('Confirm Removal of this Group?')); |
---|
194 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove_confirm',lang('Confirm Removal of this Contact?')); |
---|
195 | $GLOBALS['phpgw']->template->set_var('cc_participants',lang('Participants')); |
---|
196 | $GLOBALS['phpgw']->template->set_var('cc_empty',lang('Empty')); |
---|
197 | /* End Messages */ |
---|
198 | |
---|
199 | $GLOBALS['phpgw']->template->set_var('cc_results',lang('Results')); |
---|
200 | $GLOBALS['phpgw']->template->set_var('cc_is_my',lang('Is My')); |
---|
201 | $GLOBALS['phpgw']->template->set_var('cc_ie_personal',lang('Import/Export pesonal contacts')); |
---|
202 | $GLOBALS['phpgw']->template->set_var('cc_btn_search',lang('Search')); |
---|
203 | $GLOBALS['phpgw']->template->set_var('cc_add_relation',lang('Add Relation')); |
---|
204 | $GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations')); |
---|
205 | $GLOBALS['phpgw']->template->set_var('cc_msg_group',lang('Group')); |
---|
206 | $GLOBALS['phpgw']->template->set_var('cc_msg_contact_full',lang('Contact [Full]')); |
---|
207 | $GLOBALS['phpgw']->template->set_var('cc_msg_contact_sh',lang('Contact [Shared]')); |
---|
208 | $GLOBALS['phpgw']->template->set_var('cc_msg_contact_qa',lang('Contact [Quick Add]')); |
---|
209 | $GLOBALS['phpgw']->template->set_var('cc_contact_title',lang('Contact Center').' - '.lang('Contacts')); |
---|
210 | $GLOBALS['phpgw']->template->set_var('cc_window_views_title',lang('Contact Center').' - '.lang('Views')); |
---|
211 | $GLOBALS['phpgw']->template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images'); |
---|
212 | |
---|
213 | $GLOBALS['phpgw']->template->set_var('cc_msg_import_contacts', lang('Import Contacts')); |
---|
214 | $GLOBALS['phpgw']->template->set_var('cc_msg_export_contacts', lang('Export Contacts')); |
---|
215 | $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_info_csv', lang('The Expresso supports the contacts importation in the CSV file format.')); |
---|
216 | $GLOBALS['phpgw']->template->set_var('cc_msg_choose_file_type', lang('Select the file type')); |
---|
217 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express', lang('Outlook Express')); |
---|
218 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook2k', lang('Outlook 2000')); |
---|
219 | $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)')); |
---|
220 | $GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:')); |
---|
221 | $GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close')); |
---|
222 | $GLOBALS['phpgw']->template->set_var('cc_msg_close', lang('Close')); |
---|
223 | $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts')); |
---|
224 | $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.')); |
---|
225 | $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...')); |
---|
226 | $GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.')); |
---|
227 | $GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new')); |
---|
228 | $GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed')); |
---|
229 | $GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent')); |
---|
230 | $GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info')); |
---|
231 | $GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean')); |
---|
232 | $GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts')); |
---|
233 | $GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts')); |
---|
234 | $GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic')); |
---|
235 | $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.')); |
---|
236 | $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email')); |
---|
237 | $GLOBALS['phpgw']->template->set_var('cc_msg_main', lang('Main')); |
---|
238 | $GLOBALS['phpgw']->template->set_var('cc_msg_alternative', lang('Alternative')); |
---|
239 | $GLOBALS['phpgw']->template->set_var('cc_msg_select_email', lang('Select E-Mail')); |
---|
240 | $GLOBALS['phpgw']->template->set_var('cc_msg_new_phone', lang('New Telephone')); |
---|
241 | $GLOBALS['phpgw']->template->set_var('cc_msg_home', lang('Home Phone')); |
---|
242 | $GLOBALS['phpgw']->template->set_var('cc_msg_cellphone', lang('Cellphone')); |
---|
243 | $GLOBALS['phpgw']->template->set_var('cc_msg_corporative_cellphone', lang('Corporative Cellphone')); |
---|
244 | $GLOBALS['phpgw']->template->set_var('cc_msg_corporative_fax', lang('Corporative Fax')); |
---|
245 | $GLOBALS['phpgw']->template->set_var('cc_msg_corporative_pager', lang('Corporative Pager')); |
---|
246 | $GLOBALS['phpgw']->template->set_var('cc_msg_work', lang('Work')); |
---|
247 | $GLOBALS['phpgw']->template->set_var('cc_msg_fax', lang('Fax')); |
---|
248 | $GLOBALS['phpgw']->template->set_var('cc_msg_pager', lang('Pager')); |
---|
249 | $GLOBALS['phpgw']->template->set_var('cc_msg_choose_phone', lang('Select the telephone')); |
---|
250 | $GLOBALS['phpgw']->template->set_var('cc_msg_warn_firefox', lang('Warning: Too old version of Firefox')); |
---|
251 | $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half1', lang('For this application work correctly</u>')); |
---|
252 | $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half2', lang('it\'s necessary to update your Firefox Browser for a new version (version > 1.5) Install now clicking in the link bellow, or if you want to update it later')); |
---|
253 | $GLOBALS['phpgw']->template->set_var('cc_msg_click_close', lang('click Close')); |
---|
254 | $GLOBALS['phpgw']->template->set_var('cc_msg_install_now', lang('Install Now')); |
---|
255 | $GLOBALS['phpgw']->template->set_var('cc_msg_install_new_firefox', lang('Install a new Firefox version')); |
---|
256 | $GLOBALS['phpgw']->template->set_var('cc_msg_moz_thunderbird', lang('Export as Mozilla Thunderbird CSV.')); |
---|
257 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_pt', lang('Export as Outlook Express (Portuguese) CSV.')); |
---|
258 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_en', lang('Export as Outlook Express (English) CSV.')); |
---|
259 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_pt', lang('Export as Outlook 2000 (Portuguese) CSV.')); |
---|
260 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_en', lang('Export as Outlook 2000 (English) CSV.')); |
---|
261 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2003', lang('Export as Outlook 2003 CSV.')); |
---|
262 | $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default_csv', lang('Export as Expresso (Default) CSV.')); |
---|
263 | $GLOBALS['phpgw']->template->set_var('cc_msg_copy_to_catalog', lang('Copy to personal catalog.')); |
---|
264 | $GLOBALS['phpgw']->template->set_var('cc_msg_add_contact_to_group', lang('You did not add any contact for this group.')); |
---|
265 | $GLOBALS['phpgw']->template->set_var('cc_msg_fill_field_name', lang('Fill the field Full Name')); |
---|
266 | $GLOBALS['phpgw']->template->set_var('cc_msg_show_extra_detail', lang("Show extra contact's details.")); |
---|
267 | |
---|
268 | $select_groups = ''; |
---|
269 | |
---|
270 | $this->so_group = CreateObject('contactcenter.so_group'); |
---|
271 | |
---|
272 | $array_groups = $this->so_group->selectGroupsOwnerCanImportContacts($GLOBALS['phpgw_info']['user']['account_id']); |
---|
273 | |
---|
274 | $select_groups = "<select id='id_group'>";//<option value=0>Selecione um grupo...</option></select>"; |
---|
275 | $select_groups .= "<option value=0 selected>Nenhum...</option>"; |
---|
276 | foreach ($array_groups as $group){ |
---|
277 | $select_groups .= "<option value='".$group['id_group']."'>".$group['title']."</option>"; |
---|
278 | } |
---|
279 | $select_groups .= "</select>"; |
---|
280 | |
---|
281 | $GLOBALS['phpgw']->template->set_var('cc_select_groups',$select_groups); |
---|
282 | |
---|
283 | if($GLOBALS['phpgw_info']['server']['personal_contact_type']=='True'){ |
---|
284 | $GLOBALS['phpgw']->template->set_var('cc_contact_type', 'advanced'); |
---|
285 | }else{ |
---|
286 | $GLOBALS['phpgw']->template->set_var('cc_contact_type', 'default'); |
---|
287 | } |
---|
288 | |
---|
289 | /* |
---|
290 | * Monta Contactcenter Busca Avancada |
---|
291 | */ |
---|
292 | $c = CreateObject('phpgwapi.config','contactcenter'); |
---|
293 | $c->read_repository(); |
---|
294 | $current_config = $c->config_data; |
---|
295 | |
---|
296 | $arraySearch = array(); |
---|
297 | foreach ($current_config as $index => $value) |
---|
298 | { |
---|
299 | |
---|
300 | if(substr($index, 0, 24) == 'cc_attribute_searchable_') |
---|
301 | { |
---|
302 | if($value == 'true') |
---|
303 | { |
---|
304 | $v = substr($index, 24, strlen($index)); |
---|
305 | $arraySearch[] = $v; |
---|
306 | } |
---|
307 | } |
---|
308 | } |
---|
309 | $advanceSearchArray = array(); |
---|
310 | foreach ($arraySearch as $value) |
---|
311 | { |
---|
312 | foreach ($current_config as $index => $value2) |
---|
313 | { |
---|
314 | if($value == substr($index, 22, strlen($index)) && substr($index, 0, 22) == 'cc_attribute_ldapname_') |
---|
315 | { |
---|
316 | foreach ($current_config as $index2 => $value3) |
---|
317 | { |
---|
318 | if($value == substr($index2, 18, strlen($index2)) && substr($index2, 0, 18) == 'cc_attribute_name_') |
---|
319 | $advanceSearchArray[$value2] = $value3; |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | $advanceSearch = array(); |
---|
327 | foreach ($advanceSearchArray as $index => $value) |
---|
328 | $advanceSearch[] ='"'.$index.'":"'.$value.'"'; |
---|
329 | |
---|
330 | $advancedFields = "{".implode(',',$advanceSearch)."}"; |
---|
331 | |
---|
332 | |
---|
333 | $GLOBALS['phpgw']->template->set_var('cc_config_advanced_search', $advancedFields); |
---|
334 | |
---|
335 | |
---|
336 | |
---|
337 | $GLOBALS['phpgw']->template->parse('out','index'); |
---|
338 | |
---|
339 | $api = CreateObject('contactcenter.ui_api'); |
---|
340 | $main = $api->get_full_add(); |
---|
341 | $main .= $api->get_search_obj(); |
---|
342 | $main .= $api->get_quick_add_plugin(); |
---|
343 | $main .= $api->get_add_group(); |
---|
344 | $main .= $api->get_contact_details(); |
---|
345 | $main .= $GLOBALS['phpgw']->template->get_var('out'); |
---|
346 | |
---|
347 | echo $main; |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | /*! |
---|
352 | |
---|
353 | @function data_manager |
---|
354 | @abstract Calls the right method and passes to it the right |
---|
355 | parameters |
---|
356 | @author Raphael Derosso Pereira |
---|
357 | |
---|
358 | */ |
---|
359 | function data_manager() |
---|
360 | { |
---|
361 | $GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl')); |
---|
362 | $GLOBALS['phpgw']->template->set_var('cc_msg_not_informed', lang('Not informed')); |
---|
363 | |
---|
364 | switch($_GET['method']) |
---|
365 | { |
---|
366 | /* Cards Methods */ |
---|
367 | case 'set_n_cards': |
---|
368 | return $this->set_n_cards((int)$_GET['ncards']); |
---|
369 | |
---|
370 | case 'get_cards_data': |
---|
371 | |
---|
372 | $ids = false; |
---|
373 | // To support ldap catalogs using accentuation |
---|
374 | if ($_POST['letter'] == 'search' && isset($_POST['data'])) |
---|
375 | { |
---|
376 | $ids = utf8_decode($this->search($_POST['data'])); |
---|
377 | } |
---|
378 | |
---|
379 | if(isset($_SESSION['ids'])) |
---|
380 | $ids = $_SESSION['ids']; |
---|
381 | |
---|
382 | return $this->get_cards_data($_POST['letter'], $_POST['page'], $ids); |
---|
383 | |
---|
384 | case 'get_cards_data_get': |
---|
385 | return $this->get_cards_data($_GET['letter'], $_GET['page'], unserialize(str_replace('\\"','"',$_GET['ids']))); |
---|
386 | |
---|
387 | |
---|
388 | case 'get_photo': |
---|
389 | return $this->get_photo($_GET['id']); |
---|
390 | |
---|
391 | case 'get_init_values': |
---|
392 | echo serialize(array("visible_all_ldap" => $this->get_visible_all_ldap(), "preferences" => $this->preferences)); |
---|
393 | return; |
---|
394 | |
---|
395 | /* Catalog Methods */ |
---|
396 | case 'set_catalog': |
---|
397 | return $this->set_catalog($_GET['catalog']); |
---|
398 | |
---|
399 | case 'get_catalog_tree': |
---|
400 | echo serialize($this->get_catalog_tree($_GET['level'])); |
---|
401 | return; |
---|
402 | |
---|
403 | case 'get_actual_catalog': |
---|
404 | echo serialize($this->get_actual_catalog()); |
---|
405 | return; |
---|
406 | |
---|
407 | case 'get_catalog_participants_list': |
---|
408 | echo serialize($this->get_catalog_participants_list($_POST['id'])); |
---|
409 | return; |
---|
410 | /**rev 104**/ |
---|
411 | case 'get_catalog_participants_group': |
---|
412 | echo serialize($this->get_catalog_participants_group($_POST['id'])); |
---|
413 | return; |
---|
414 | /***/ |
---|
415 | case 'get_catalog_add_contact': |
---|
416 | // To support ldap catalogs with accentuation |
---|
417 | echo serialize($this->get_catalog_add_contact($_POST['id'])); |
---|
418 | return; |
---|
419 | |
---|
420 | /* Full Add Methods */ |
---|
421 | case 'get_full_data': |
---|
422 | //return $this->get_full_data($_GET['id']); |
---|
423 | /**rev 104**/ |
---|
424 | return $this->get_full_data($_GET['id'],$_GET['catalog']); |
---|
425 | /****/ |
---|
426 | |
---|
427 | case 'get_group': |
---|
428 | return $this->get_group_data($_GET['id'],isset($_GET['shared_from'])?$_GET['shared_from']:null); |
---|
429 | |
---|
430 | case 'get_contact_full_add_const': |
---|
431 | return $this->get_contact_full_add_const(); |
---|
432 | |
---|
433 | case 'post_full_add': |
---|
434 | return $this->post_full_add(); |
---|
435 | |
---|
436 | case 'post_full_add_shared' : |
---|
437 | return $this->post_full_add_shared(); |
---|
438 | |
---|
439 | case 'post_photo': |
---|
440 | return $this->post_photo((int) $_GET['id'] ? (int) $_GET['id'] : '_new_'); |
---|
441 | |
---|
442 | case 'get_states': |
---|
443 | return $this->get_states($_GET['country']); |
---|
444 | |
---|
445 | case 'get_cities': |
---|
446 | return $this->get_cities($_GET['country'], $_GET['state'] ? $_GET['state'] : null); |
---|
447 | |
---|
448 | |
---|
449 | /* Other Methods */ |
---|
450 | case 'quick_add': |
---|
451 | return $this->quick_add($_POST['add']); |
---|
452 | |
---|
453 | case 'add_group': |
---|
454 | return $this->add_group($_POST['add']); |
---|
455 | |
---|
456 | case 'remove_entry': |
---|
457 | return $this->remove_entry((int)$_GET['remove']); |
---|
458 | |
---|
459 | case 'remove_all_entries': |
---|
460 | return $this->remove_all_entries(); |
---|
461 | |
---|
462 | case 'remove_group': |
---|
463 | |
---|
464 | return $this->remove_group((int)$_GET['remove']); |
---|
465 | |
---|
466 | case 'search': |
---|
467 | $ids = false; |
---|
468 | $ids = $this->search($_GET['data']); |
---|
469 | $data = unserialize($_GET['data']); |
---|
470 | $dontPaginate = false; |
---|
471 | if (isset($data['ccAddGroup'])){ |
---|
472 | $dontPaginate = true; |
---|
473 | } |
---|
474 | return $this->get_cards_data('search', '1', $ids, $dontPaginate); |
---|
475 | |
---|
476 | case 'email_win': |
---|
477 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
478 | $api = CreateObject('contactcenter.ui_api'); |
---|
479 | $win = $api->get_email_win(); |
---|
480 | $win .= $api->get_quick_add_plugin(); |
---|
481 | $win .= '<input id="QAbutton" type="button" value="QuickAdd" />' |
---|
482 | .'<br><input type="button" value="EmailWin" onclick="ccEmailWin.open()" />' |
---|
483 | .'<script type="text/javascript">' |
---|
484 | .' ccQuickAdd.associateAsButton(Element("QAbutton"));' |
---|
485 | .'</script>'; |
---|
486 | echo $win; |
---|
487 | return; |
---|
488 | |
---|
489 | /* Information Gathering */ |
---|
490 | case 'get_multiple_entries': |
---|
491 | echo serialize($this->get_multiple_entries(str_replace('\\"','"',$_POST['data']))); |
---|
492 | return; |
---|
493 | |
---|
494 | case 'get_all_entries': |
---|
495 | echo serialize($this->get_all_entries(str_replace('\\"','"',$_POST['data']))); |
---|
496 | return; |
---|
497 | |
---|
498 | case 'import_contacts': |
---|
499 | return $this->import_contacts($_GET['typeImport'],$_GET['id_group']); |
---|
500 | |
---|
501 | case 'export_contacts': |
---|
502 | return $this->export_contacts($_POST['typeExport']); |
---|
503 | |
---|
504 | case 'get_qtds_compartilhado': |
---|
505 | return $this->get_qtds_compartilhado(); |
---|
506 | case 'get_list_owners_perms_add': |
---|
507 | echo $this->get_list_owners_perms_add(); |
---|
508 | return; |
---|
509 | case 'get_contact_details': |
---|
510 | return $this->get_contact_details($_GET['id']); |
---|
511 | } |
---|
512 | } |
---|
513 | |
---|
514 | /*! |
---|
515 | |
---|
516 | @function set_n_cards |
---|
517 | @abstract Informs the class the number of cards the page can show |
---|
518 | @author Raphael Derosso Pereira |
---|
519 | |
---|
520 | @param integer $n_cards The number of cards |
---|
521 | |
---|
522 | */ |
---|
523 | function set_n_cards($n_cards) |
---|
524 | { |
---|
525 | if (is_int($n_cards)) |
---|
526 | { |
---|
527 | $this->page_info['n_cards'] = $n_cards; |
---|
528 | echo 1; |
---|
529 | } |
---|
530 | |
---|
531 | $this->save_session(); |
---|
532 | } |
---|
533 | |
---|
534 | /*! |
---|
535 | |
---|
536 | @function set_catalog |
---|
537 | @abstract Sets the current catalog selected by the user |
---|
538 | @author Raphael Derosso Pereira |
---|
539 | |
---|
540 | @param string $id_catalog The sequence of IDs to reach the catalog |
---|
541 | separated by commas |
---|
542 | |
---|
543 | */ |
---|
544 | function set_catalog($id_catalog, $echo=true) |
---|
545 | { |
---|
546 | $id_catalog = str_replace('\\"', '"', $id_catalog); |
---|
547 | $temp = $this->bo->set_catalog($id_catalog); |
---|
548 | |
---|
549 | if(!$this->bo->catalog->src_info) { |
---|
550 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
551 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
552 | } |
---|
553 | |
---|
554 | $resetCC_actual_letter = 0; |
---|
555 | if($this->bo->catalog->src_info['visible'] == "false") |
---|
556 | { |
---|
557 | $resetCC_actual_letter = 1; |
---|
558 | } |
---|
559 | |
---|
560 | if ($temp) |
---|
561 | { |
---|
562 | unset($this->page_info['actual_letter']); |
---|
563 | $this->page_info['changed'] = true; |
---|
564 | $this->page_info['actual_entries'] = false; |
---|
565 | $this->page_info['actual_catalog'] = $temp; |
---|
566 | $this->save_session(); |
---|
567 | |
---|
568 | $catalog_info = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); |
---|
569 | |
---|
570 | if ($catalog_info['class'] === 'bo_global_ldap_catalog' || |
---|
571 | $catalog_info['class'] === 'bo_catalog_group_catalog') |
---|
572 | { |
---|
573 | $perms = 1; |
---|
574 | } |
---|
575 | else |
---|
576 | { |
---|
577 | $perms = 15; |
---|
578 | } |
---|
579 | |
---|
580 | if ($echo) |
---|
581 | { |
---|
582 | echo serialize(array( |
---|
583 | 'status' => 'ok', |
---|
584 | 'catalog' => $catalog_info['class'], |
---|
585 | 'external' => $catalog_info['external']?true:false, |
---|
586 | 'resetCC_actual_letter' => $resetCC_actual_letter, |
---|
587 | 'perms' => $perms |
---|
588 | )); |
---|
589 | } |
---|
590 | else |
---|
591 | { |
---|
592 | return serialize(array( |
---|
593 | 'status' => 'ok', |
---|
594 | 'catalog' => $catalog_info['class'], |
---|
595 | 'external' => $catalog_info['external']?true:false, |
---|
596 | 'resetCC_actual_letter' => $resetCC_actual_letter, |
---|
597 | 'perms' => $perms |
---|
598 | )); |
---|
599 | } |
---|
600 | |
---|
601 | return; |
---|
602 | } |
---|
603 | |
---|
604 | echo serialize(array( |
---|
605 | 'status' => 'ok', |
---|
606 | 'resetCC_actual_letter' => $resetCC_actual_letter, |
---|
607 | 'perms' => 0 |
---|
608 | )); |
---|
609 | } |
---|
610 | |
---|
611 | |
---|
612 | /*! |
---|
613 | |
---|
614 | @function get_catalog_tree |
---|
615 | @abstract Returns the JS serialized array to used as the tree |
---|
616 | level |
---|
617 | @author Raphael Derosso Pereira |
---|
618 | @author Mário César Kolling (error messages and timeout) |
---|
619 | |
---|
620 | @param (string) $level The level to be taken |
---|
621 | |
---|
622 | */ |
---|
623 | function get_catalog_tree($level) |
---|
624 | { |
---|
625 | if ($level === '0') |
---|
626 | { |
---|
627 | $folderImageDir = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/dftree/images/'; |
---|
628 | |
---|
629 | $parent = '0'; |
---|
630 | |
---|
631 | if (!($tree = $this->bo->get_catalog_tree($level))) |
---|
632 | { |
---|
633 | return array( |
---|
634 | 'msg' => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'), |
---|
635 | 'status' => 'fatal' |
---|
636 | ); |
---|
637 | } |
---|
638 | } |
---|
639 | else |
---|
640 | { |
---|
641 | $last_dot = strrpos($level,'.'); |
---|
642 | $parent = substr($level, 0, $last_dot); |
---|
643 | $child = substr($level, $last_dot+1, strlen($level)); |
---|
644 | if (!($tree[$child] = $this->bo->get_catalog_tree($level))) |
---|
645 | { |
---|
646 | return array( |
---|
647 | 'msg' => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'), |
---|
648 | 'status' => 'fatal' |
---|
649 | ); |
---|
650 | } |
---|
651 | // Deals with timeout and returns the generated message to the browser |
---|
652 | else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg'])) |
---|
653 | { |
---|
654 | $tmp = array( |
---|
655 | 'msg' => $tree[$child]['msg'], |
---|
656 | 'status' => 'fatal' |
---|
657 | ); |
---|
658 | unset($tree[$child]); |
---|
659 | return $tmp; |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png'); |
---|
664 | $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png')); |
---|
665 | |
---|
666 | // Deals with error messages from the server and returns them to the browser |
---|
667 | if ($tree['msg']) |
---|
668 | { |
---|
669 | $msg = $tree['msg']; |
---|
670 | unset($tree['msg']); |
---|
671 | } |
---|
672 | |
---|
673 | $tree_js = $this->convert_tree($tree, $folderImageDir, $parent); |
---|
674 | |
---|
675 | // Return status = ok, or else return generated message to the browser |
---|
676 | if (!$msg) |
---|
677 | { |
---|
678 | return array( |
---|
679 | 'data' => $tree_js, |
---|
680 | 'msg' => lang('Catalog Tree Successfully taken!'), |
---|
681 | 'status' => 'ok' |
---|
682 | ); |
---|
683 | } |
---|
684 | else |
---|
685 | { |
---|
686 | return array( |
---|
687 | 'data' => $tree_js, |
---|
688 | 'msg' => $msg, |
---|
689 | 'status' => 'error' |
---|
690 | ); |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | /*! |
---|
695 | |
---|
696 | @function get_actual_catalog |
---|
697 | @abstract Returns the actual selected Catalog |
---|
698 | @author Raphael Derosso Pereira |
---|
699 | |
---|
700 | */ |
---|
701 | function get_actual_catalog() |
---|
702 | { |
---|
703 | $level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0'); |
---|
704 | |
---|
705 | if ($level) |
---|
706 | { |
---|
707 | return array( |
---|
708 | 'status' => 'ok', |
---|
709 | 'data' => $level |
---|
710 | ); |
---|
711 | } |
---|
712 | |
---|
713 | return array( |
---|
714 | 'status' => 'fatal', |
---|
715 | 'msg' => lang('Couldn\'t get the actual catalog.'), |
---|
716 | ); |
---|
717 | } |
---|
718 | |
---|
719 | function get_qtds_compartilhado() { |
---|
720 | $so_contact = CreateObject('contactcenter.so_contact', $GLOBALS['phpgw_info']['user']['account_id']); |
---|
721 | $relacionados = $so_contact->get_relations(); |
---|
722 | |
---|
723 | $perms_relacao = array(); |
---|
724 | |
---|
725 | foreach($relacionados as $uid_relacionado => $tipo_relacionamento) { |
---|
726 | $aclTemp = CreateObject("phpgwapi.acl",$uid_relacionado); |
---|
727 | $aclTemp->read(); |
---|
728 | $perms_relacao[$uid_relacionado] = $aclTemp->get_specific_rights($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter'); //Preciso verificar as permissões que o contato relacionado deu para o atual |
---|
729 | } |
---|
730 | |
---|
731 | $validos = array(); |
---|
732 | $count = 0; |
---|
733 | foreach($perms_relacao as $uid_relacionado => $val){ |
---|
734 | if ($perms_relacao[$uid_relacionado]&2) |
---|
735 | { |
---|
736 | $validos[$uid_relacionado] = $perms_relacao[$uid_relacionado]; |
---|
737 | $count++; |
---|
738 | } |
---|
739 | } |
---|
740 | echo serialize(array(0=>$count)); |
---|
741 | } |
---|
742 | |
---|
743 | /*! |
---|
744 | |
---|
745 | @function get_cards_data |
---|
746 | @abstract Returns the information that is placed on the cards |
---|
747 | @author Raphael Derosso Pereira |
---|
748 | |
---|
749 | @param string $letter The first letter to be searched |
---|
750 | @param (int) $page The page to be taken |
---|
751 | @param (str) $ids The ids to be taken in case of search |
---|
752 | |
---|
753 | TODO: This function is not well done. It must be rewritten |
---|
754 | using the new array 'msg','status','data' schema. |
---|
755 | */ |
---|
756 | function get_cards_data($letter, $page, $ids, $dontPaginate = false) |
---|
757 | { |
---|
758 | if( $ids ) |
---|
759 | $_SESSION['ids'] = $ids; |
---|
760 | |
---|
761 | // It's an external catalog? |
---|
762 | $external = $this->bo->is_external($this->page_info['actual_catalog']); |
---|
763 | //echo $page."\n"; |
---|
764 | if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or |
---|
765 | ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or |
---|
766 | $this->page_info['changed'])) |
---|
767 | { |
---|
768 | unset($ids); |
---|
769 | $this->page_info['changed'] = false; |
---|
770 | |
---|
771 | switch ($this->page_info['actual_catalog']['class']) |
---|
772 | { |
---|
773 | /**rev 104**/ |
---|
774 | case 'bo_shared_people_manager': |
---|
775 | /****/ |
---|
776 | case 'bo_people_catalog': |
---|
777 | $field_name = 'id_contact'; |
---|
778 | |
---|
779 | if ($letter !== 'number') |
---|
780 | { |
---|
781 | $find_restric[0] = array( |
---|
782 | 0 => array( |
---|
783 | 'field' => 'contact.names_ordered', |
---|
784 | 'type' => 'iLIKE', |
---|
785 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
786 | /**rev 104**/ |
---|
787 | /* ), |
---|
788 | 1 => array( |
---|
789 | 'field' => 'contact.id_owner', |
---|
790 | 'type' => '=', |
---|
791 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
792 | */ |
---|
793 | ) |
---|
794 | ); |
---|
795 | |
---|
796 | //Tratamento de permissão de escrita no compartilhamento de catalogo |
---|
797 | $so_contact = CreateObject('contactcenter.so_contact', $GLOBALS['phpgw_info']['user']['account_id']); |
---|
798 | $relacionados = $so_contact->get_relations(); |
---|
799 | |
---|
800 | $perms_relacao = array(); |
---|
801 | |
---|
802 | foreach($relacionados as $uid_relacionado => $tipo_relacionamento) { |
---|
803 | $aclTemp = CreateObject("phpgwapi.acl",$uid_relacionado); |
---|
804 | $aclTemp->read(); |
---|
805 | $perms_relacao[$uid_relacionado] = $aclTemp->get_specific_rights($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter'); //Preciso verificar as permissões que o contato relacionado deu para o atual |
---|
806 | } |
---|
807 | |
---|
808 | $validos = array(); |
---|
809 | $count = 0; |
---|
810 | foreach($perms_relacao as $uid_relacionado => $val){ |
---|
811 | if ($perms_relacao[$uid_relacionado]&2) |
---|
812 | { |
---|
813 | $validos[$uid_relacionado] = $perms_relacao[$uid_relacionado]; |
---|
814 | $count++; |
---|
815 | } |
---|
816 | } |
---|
817 | $prop_names = array(); |
---|
818 | if($validos) { |
---|
819 | $filtro = "(|"; |
---|
820 | foreach($validos as $i => $prop) { |
---|
821 | $filtro .= "(uidNumber=".$i.")"; |
---|
822 | } |
---|
823 | $filtro .= ")"; |
---|
824 | |
---|
825 | if(!$this->bo->catalog->src_info) { |
---|
826 | $ldaps = CreateObject('contactcenter.bo_ldap_manager'); |
---|
827 | $this->bo->catalog->src_info = $ldaps->srcs[1]; |
---|
828 | } |
---|
829 | $s = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false); |
---|
830 | $n=$this->bo->catalog->src_info['dn']; |
---|
831 | $apenasThese = array("cn","uidnumber","uid"); |
---|
832 | $r = ldap_search($s,$n, $filtro,$apenasThese); |
---|
833 | $infos = ldap_get_entries($s, $r); |
---|
834 | ldap_close($s); |
---|
835 | for($z = 0; $z < $infos['count']; $z++) { |
---|
836 | $prop_names[$infos[$z]['uidnumber'][0]] = array("cn" => $infos[$z]['cn'][0], "uid" => $infos[$z]['uid'][0]); |
---|
837 | } |
---|
838 | } |
---|
839 | //-------------------------------------------------------------------------------- |
---|
840 | if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog') |
---|
841 | { |
---|
842 | $find_restric[0][1] = array( |
---|
843 | 'field' => 'contact.id_owner', |
---|
844 | 'type' => '=', |
---|
845 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
846 | ); |
---|
847 | } |
---|
848 | /****/ |
---|
849 | |
---|
850 | } |
---|
851 | else |
---|
852 | { |
---|
853 | $find_restric[0] = array( |
---|
854 | 0 => array( |
---|
855 | 'type' => 'branch', |
---|
856 | 'value' => 'OR', |
---|
857 | 'sub_branch' => array( |
---|
858 | 0 => array( |
---|
859 | 'field' => 'contact.names_ordered', |
---|
860 | 'type' => 'LIKE', |
---|
861 | 'value' => '0%' |
---|
862 | ), |
---|
863 | 1 => array( |
---|
864 | 'field' => 'contact.names_ordered', |
---|
865 | 'type' => 'LIKE', |
---|
866 | 'value' => '1%' |
---|
867 | ), |
---|
868 | 2 => array( |
---|
869 | 'field' => 'contact.names_ordered', |
---|
870 | 'type' => 'LIKE', |
---|
871 | 'value' => '2%' |
---|
872 | ), |
---|
873 | 3 => array( |
---|
874 | 'field' => 'contact.names_ordered', |
---|
875 | 'type' => 'LIKE', |
---|
876 | 'value' => '3%' |
---|
877 | ), |
---|
878 | 4 => array( |
---|
879 | 'field' => 'contact.names_ordered', |
---|
880 | 'type' => 'LIKE', |
---|
881 | 'value' => '4%' |
---|
882 | ), |
---|
883 | 5 => array( |
---|
884 | 'field' => 'contact.names_ordered', |
---|
885 | 'type' => 'LIKE', |
---|
886 | 'value' => '5%' |
---|
887 | ), |
---|
888 | 6 => array( |
---|
889 | 'field' => 'contact.names_ordered', |
---|
890 | 'type' => 'LIKE', |
---|
891 | 'value' => '6%' |
---|
892 | ), |
---|
893 | 7 => array( |
---|
894 | 'field' => 'contact.names_ordered', |
---|
895 | 'type' => 'LIKE', |
---|
896 | 'value' => '7%' |
---|
897 | ), |
---|
898 | 8 => array( |
---|
899 | 'field' => 'contact.names_ordered', |
---|
900 | 'type' => 'LIKE', |
---|
901 | 'value' => '8%' |
---|
902 | ), |
---|
903 | 9 => array( |
---|
904 | 'field' => 'contact.names_ordered', |
---|
905 | 'type' => 'LIKE', |
---|
906 | 'value' => '9%' |
---|
907 | ), |
---|
908 | ), |
---|
909 | /**rev 104**/ |
---|
910 | /* ), |
---|
911 | 1 => array( |
---|
912 | 'field' => 'contact.id_owner', |
---|
913 | 'type' => '=', |
---|
914 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
915 | ), |
---|
916 | */ |
---|
917 | ) |
---|
918 | ); |
---|
919 | } |
---|
920 | |
---|
921 | if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){ |
---|
922 | $find_restric[0][1] = array( |
---|
923 | 'field' => 'contact.id_owner', |
---|
924 | 'type' => '=', |
---|
925 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
926 | ); |
---|
927 | } |
---|
928 | /*****/ |
---|
929 | |
---|
930 | $find_field[0] = array('contact.id_contact','contact.names_ordered'); |
---|
931 | |
---|
932 | $find_other[0] = array( |
---|
933 | /**rev 104**/ |
---|
934 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
935 | //'limit' => $this->page_info['n_cards'], |
---|
936 | /*****/ |
---|
937 | 'order' => 'contact.names_ordered' |
---|
938 | ); |
---|
939 | |
---|
940 | break; |
---|
941 | |
---|
942 | case 'bo_catalog_group_catalog': |
---|
943 | case 'bo_global_ldap_catalog': |
---|
944 | |
---|
945 | $field_name = 'id_contact'; |
---|
946 | |
---|
947 | if ($letter !== 'number') |
---|
948 | { |
---|
949 | $find_restric[0] = array( |
---|
950 | 0 => array( |
---|
951 | 'field' => 'contact.names_ordered', |
---|
952 | 'type' => 'iLIKE', |
---|
953 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
954 | ), |
---|
955 | /* |
---|
956 | * Restrict the returned contacts in a "first letter" search |
---|
957 | /**rev 104 |
---|
958 | * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, |
---|
959 | * phpgwAccountVisible != -1 |
---|
960 | */ |
---|
961 | 1 => array( |
---|
962 | 'field' => 'contact.object_class', |
---|
963 | 'type' => '=', |
---|
964 | 'value' => 'phpgwAccount' |
---|
965 | /**rev 104**/ |
---|
966 | //),/* |
---|
967 | ), |
---|
968 | /****/ |
---|
969 | 2 => array( |
---|
970 | 'field' => 'contact.account_status', |
---|
971 | 'type' => 'iLIKE', |
---|
972 | 'value' => '%' |
---|
973 | /**rev 104**/ |
---|
974 | //),*/ |
---|
975 | //2 => array( |
---|
976 | ), |
---|
977 | 3 => array( |
---|
978 | /*****/ |
---|
979 | 'field' => 'contact.account_visible', |
---|
980 | 'type' => '!=', |
---|
981 | 'value' => '-1' |
---|
982 | /**rev 104**/ |
---|
983 | /* ), |
---|
984 | 3 => array( |
---|
985 | 'field' => 'contact.object_class', |
---|
986 | 'type' => '=', |
---|
987 | 'value' => 'inetOrgPerson' |
---|
988 | ), |
---|
989 | */ |
---|
990 | ) |
---|
991 | /*****/ |
---|
992 | |
---|
993 | ); |
---|
994 | // If not external catalog get only phpgwAccountType = u ou l |
---|
995 | if (!$external) |
---|
996 | { |
---|
997 | $find_restric[0][5] = array( |
---|
998 | 'type' => 'branch', |
---|
999 | 'value' => 'OR', |
---|
1000 | 'sub_branch' => array( |
---|
1001 | 0 => array( |
---|
1002 | 'field' => 'contact.account_type', |
---|
1003 | 'type' => '=', |
---|
1004 | 'value' => 'u' |
---|
1005 | ), |
---|
1006 | 1 => array( |
---|
1007 | 'field' => 'contact.account_type', |
---|
1008 | 'type' => '=', |
---|
1009 | 'value' => 'i' |
---|
1010 | /**rev 104**/ |
---|
1011 | ), |
---|
1012 | 2 => array( |
---|
1013 | 'field' => 'contact.account_type', |
---|
1014 | 'type' => '=', |
---|
1015 | /****/ |
---|
1016 | 'value' => 'l' |
---|
1017 | /**rev 104**/ |
---|
1018 | ), |
---|
1019 | 3 => array( |
---|
1020 | 'field' => 'contact.account_type', |
---|
1021 | 'type' => '=', |
---|
1022 | 'value' => 'g' |
---|
1023 | /***/ |
---|
1024 | ), |
---|
1025 | 4 => array( |
---|
1026 | 'field' => 'contact.account_type', |
---|
1027 | 'type' => '=', |
---|
1028 | 'value' => 's' |
---|
1029 | ) |
---|
1030 | ) |
---|
1031 | ); |
---|
1032 | } |
---|
1033 | } |
---|
1034 | else |
---|
1035 | { |
---|
1036 | $find_restric[0] = array( |
---|
1037 | /* |
---|
1038 | * Restrict the returned contacts in a "first number" search |
---|
1039 | /**rev 104 |
---|
1040 | * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, |
---|
1041 | * phpgwAccountVisible != -1 |
---|
1042 | */ |
---|
1043 | 0 => array( |
---|
1044 | 'field' => 'contact.object_class', |
---|
1045 | 'type' => '=', |
---|
1046 | 'value' => 'phpgwAccount' |
---|
1047 | /**rev 104**/ |
---|
1048 | //),/* |
---|
1049 | ), |
---|
1050 | /****/ |
---|
1051 | 1 => array( |
---|
1052 | 'field' => 'contact.account_status', |
---|
1053 | 'type' => 'iLIKE', |
---|
1054 | 'value' => '%' |
---|
1055 | /**rev 104**/ |
---|
1056 | //),*/ |
---|
1057 | //1 => array( |
---|
1058 | ), |
---|
1059 | 2 => array( |
---|
1060 | /*****/ |
---|
1061 | 'field' => 'contact.account_visible', |
---|
1062 | 'type' => '!=', |
---|
1063 | 'value' => '-1' |
---|
1064 | ), |
---|
1065 | /**rev 104**/ |
---|
1066 | /* 2 => array( |
---|
1067 | 'field' => 'contact.object_class', |
---|
1068 | 'type' => '=', |
---|
1069 | 'value' => 'inetOrgPerson' |
---|
1070 | ), |
---|
1071 | */ |
---|
1072 | /****/ |
---|
1073 | 3 => array( |
---|
1074 | 'type' => 'branch', |
---|
1075 | 'value' => 'OR', |
---|
1076 | 'sub_branch' => array( |
---|
1077 | 0 => array( |
---|
1078 | 'field' => 'contact.names_ordered', |
---|
1079 | 'type' => 'LIKE', |
---|
1080 | 'value' => '0%' |
---|
1081 | ), |
---|
1082 | 1 => array( |
---|
1083 | 'field' => 'contact.names_ordered', |
---|
1084 | 'type' => 'LIKE', |
---|
1085 | 'value' => '1%' |
---|
1086 | ), |
---|
1087 | 2 => array( |
---|
1088 | 'field' => 'contact.names_ordered', |
---|
1089 | 'type' => 'LIKE', |
---|
1090 | 'value' => '2%' |
---|
1091 | ), |
---|
1092 | 3 => array( |
---|
1093 | 'field' => 'contact.names_ordered', |
---|
1094 | 'type' => 'LIKE', |
---|
1095 | 'value' => '3%' |
---|
1096 | ), |
---|
1097 | 4 => array( |
---|
1098 | 'field' => 'contact.names_ordered', |
---|
1099 | 'type' => 'LIKE', |
---|
1100 | 'value' => '4%' |
---|
1101 | ), |
---|
1102 | 5 => array( |
---|
1103 | 'field' => 'contact.names_ordered', |
---|
1104 | 'type' => 'LIKE', |
---|
1105 | 'value' => '5%' |
---|
1106 | ), |
---|
1107 | 6 => array( |
---|
1108 | 'field' => 'contact.names_ordered', |
---|
1109 | 'type' => 'LIKE', |
---|
1110 | 'value' => '6%' |
---|
1111 | ), |
---|
1112 | 7 => array( |
---|
1113 | 'field' => 'contact.names_ordered', |
---|
1114 | 'type' => 'LIKE', |
---|
1115 | 'value' => '7%' |
---|
1116 | ), |
---|
1117 | 8 => array( |
---|
1118 | 'field' => 'contact.names_ordered', |
---|
1119 | 'type' => 'LIKE', |
---|
1120 | 'value' => '8%' |
---|
1121 | ), |
---|
1122 | 9 => array( |
---|
1123 | 'field' => 'contact.names_ordered', |
---|
1124 | 'type' => 'LIKE', |
---|
1125 | 'value' => '9%' |
---|
1126 | ), |
---|
1127 | ), |
---|
1128 | ), |
---|
1129 | ); |
---|
1130 | // If not external catalog get only phpgwAccountType = u ou l |
---|
1131 | if (!$external) |
---|
1132 | { |
---|
1133 | $find_restric[0][5] = array( |
---|
1134 | 'type' => 'branch', |
---|
1135 | 'value' => 'OR', |
---|
1136 | 'sub_branch' => array( |
---|
1137 | 0 => array( |
---|
1138 | 'field' => 'contact.account_type', |
---|
1139 | 'type' => '=', |
---|
1140 | 'value' => 'u' |
---|
1141 | ), |
---|
1142 | 1 => array( |
---|
1143 | 'field' => 'contact.account_type', |
---|
1144 | 'type' => '=', |
---|
1145 | /**rev 104**/ |
---|
1146 | //'value' => 'g' |
---|
1147 | //); |
---|
1148 | //1 => array( |
---|
1149 | 'value' => 'i' |
---|
1150 | ), |
---|
1151 | 2 => array( |
---|
1152 | /****/ |
---|
1153 | 'field' => 'contact.account_type', |
---|
1154 | 'type' => '=', |
---|
1155 | 'value' => 'l' |
---|
1156 | /**rev 104**/ |
---|
1157 | ), |
---|
1158 | 3 => array( |
---|
1159 | 'field' => 'contact.account_type', |
---|
1160 | 'type' => '=', |
---|
1161 | 'value' => 'g' |
---|
1162 | ), |
---|
1163 | /****/ |
---|
1164 | 4 => array( |
---|
1165 | 'field' => 'contact.account_type', |
---|
1166 | 'type' => '=', |
---|
1167 | 'value' => 's' |
---|
1168 | ) |
---|
1169 | ) |
---|
1170 | ); |
---|
1171 | } |
---|
1172 | } |
---|
1173 | |
---|
1174 | if (!$external) |
---|
1175 | { |
---|
1176 | // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible |
---|
1177 | // for non-external catalogs, used to restrict the attributes used in filters |
---|
1178 | $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type', |
---|
1179 | 'contact.object_class','contact.account_visible'); |
---|
1180 | } |
---|
1181 | else |
---|
1182 | { |
---|
1183 | // Get only this attributes: dn, cn for external catalogs, |
---|
1184 | // used to restrict the attributes used in filters |
---|
1185 | $find_field[0] = array('contact.id_contact','contact.names_ordered'); |
---|
1186 | } |
---|
1187 | |
---|
1188 | $find_other[0] = array( |
---|
1189 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
1190 | //'limit' => $this->page_info['n_cards'], |
---|
1191 | 'order' => 'contact.names_ordered' |
---|
1192 | ); |
---|
1193 | |
---|
1194 | break; |
---|
1195 | |
---|
1196 | case 'bo_company_manager': |
---|
1197 | $field_name = 'id_company'; |
---|
1198 | |
---|
1199 | $find_field[0] = array('company.id_company','company.company_name'); |
---|
1200 | |
---|
1201 | $find_other[0] = array( |
---|
1202 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
1203 | //'limit' => $this->page_info['n_cards'], |
---|
1204 | 'order' => 'company.company_name' |
---|
1205 | ); |
---|
1206 | |
---|
1207 | $find_restric[0] = array( |
---|
1208 | 0 => array( |
---|
1209 | 'field' => 'company.company_name', |
---|
1210 | 'type' => 'iLIKE', |
---|
1211 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
1212 | ) |
---|
1213 | ); |
---|
1214 | |
---|
1215 | break; |
---|
1216 | |
---|
1217 | case 'bo_group_manager': |
---|
1218 | /**rev 104**/ |
---|
1219 | case 'bo_shared_group_manager': |
---|
1220 | /****/ |
---|
1221 | |
---|
1222 | $field_name = 'id_group'; |
---|
1223 | |
---|
1224 | if ($letter !== 'number') { |
---|
1225 | |
---|
1226 | $find_restric[0] = array( |
---|
1227 | 0 => array( |
---|
1228 | 'field' => 'group.title', |
---|
1229 | 'type' => 'iLIKE', |
---|
1230 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
1231 | ) |
---|
1232 | ); |
---|
1233 | } |
---|
1234 | else { |
---|
1235 | |
---|
1236 | $find_restric[0] = array( |
---|
1237 | 0 => array( |
---|
1238 | 'field' => 'group.title', |
---|
1239 | 'type' => 'LIKE', |
---|
1240 | 'value' => '0%' |
---|
1241 | ) |
---|
1242 | ); |
---|
1243 | } |
---|
1244 | /**rev 104**/ |
---|
1245 | if($this->page_info['actual_catalog']['class'] == 'bo_group_manager'){ |
---|
1246 | /****/ |
---|
1247 | array_push($find_restric[0], array( |
---|
1248 | 'field' => 'group.owner', |
---|
1249 | 'type' => '=', |
---|
1250 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
1251 | ) |
---|
1252 | ); |
---|
1253 | } |
---|
1254 | |
---|
1255 | $find_field[0] = array('group.id_group','group.title','group.short_name'); |
---|
1256 | $find_other[0] = array( |
---|
1257 | 'order' => 'group.title' |
---|
1258 | ); |
---|
1259 | break; |
---|
1260 | |
---|
1261 | /*case 'bo_catalog_group_catalog': |
---|
1262 | $this->page_info['actual_entries'] = false; |
---|
1263 | |
---|
1264 | $this->page_info['actual_letter'] = $letter; |
---|
1265 | $this->page_info['actual_page'] = 0; |
---|
1266 | |
---|
1267 | $this->save_session(); |
---|
1268 | $final[0] = 0; |
---|
1269 | $final[1] = $this->typeContact; |
---|
1270 | echo serialize($final); |
---|
1271 | return;*/ |
---|
1272 | |
---|
1273 | } |
---|
1274 | |
---|
1275 | if(!$this->bo->catalog->src_info) { |
---|
1276 | $ldaps = CreateObject('contactcenter.bo_ldap_manager'); |
---|
1277 | $this->bo->catalog->src_info = $ldaps->srcs[1]; |
---|
1278 | } |
---|
1279 | $recursive = $this->bo->catalog->src_info['recursive']; |
---|
1280 | |
---|
1281 | $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0],false,($recursive == "true") ? true : ''); |
---|
1282 | $n_entries = count($result); |
---|
1283 | |
---|
1284 | if ($n_entries) |
---|
1285 | { |
---|
1286 | //echo 'N_entries: '.$n_entries.'<br>'; |
---|
1287 | $this->page_info['n_pages'] = $dontPaginate ? 1 : ceil($n_entries/$this->page_info['n_cards']); |
---|
1288 | } |
---|
1289 | else |
---|
1290 | { |
---|
1291 | $this->page_info['n_pages'] = 0; |
---|
1292 | } |
---|
1293 | |
---|
1294 | if (!$result) |
---|
1295 | { |
---|
1296 | $this->page_info['actual_entries'] = false; |
---|
1297 | |
---|
1298 | $this->page_info['actual_letter'] = $letter; |
---|
1299 | $this->page_info['actual_page'] = 0; |
---|
1300 | |
---|
1301 | $this->save_session(); |
---|
1302 | $final[0] = 0; |
---|
1303 | $final[1] = $this->typeContact; |
---|
1304 | echo serialize($final); |
---|
1305 | return; |
---|
1306 | } |
---|
1307 | else |
---|
1308 | { |
---|
1309 | unset($this->page_info['actual_entries']); |
---|
1310 | if(is_array($result)) { |
---|
1311 | foreach ($result as $id => $value) |
---|
1312 | { |
---|
1313 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
1314 | $this->page_info['actual_entries'][] = $value[$field_name]; |
---|
1315 | else |
---|
1316 | $this->page_info['actual_entries'][] = array(0=>$value[$field_name],1=>$value['perms'],2=>$value['owner']); |
---|
1317 | } |
---|
1318 | } |
---|
1319 | } |
---|
1320 | } |
---|
1321 | else if ($letter === 'search') |
---|
1322 | { |
---|
1323 | //if (!$ids and $this->page_info['actual_letter'] !== 'search') |
---|
1324 | if (!$ids) |
---|
1325 | { |
---|
1326 | /**rev 104**/ |
---|
1327 | //error_log('!$ids e $this->page_info[\'actual_letter\'] != search'); |
---|
1328 | /*****/ |
---|
1329 | $this->page_info['actual_entries'] = false; |
---|
1330 | |
---|
1331 | $this->page_info['actual_letter'] = $letter; |
---|
1332 | $this->page_info['actual_page'] = 0; |
---|
1333 | |
---|
1334 | $this->save_session(); |
---|
1335 | $final[0] = 0; |
---|
1336 | $final[1] = $this -> typeContact; |
---|
1337 | echo serialize($final); |
---|
1338 | return; |
---|
1339 | } |
---|
1340 | else if ($ids['error']) |
---|
1341 | { |
---|
1342 | $this->page_info['actual_entries'] = false; |
---|
1343 | $this->page_info['actual_letter'] = $letter; |
---|
1344 | $this->page_info['actual_page'] = 0; |
---|
1345 | |
---|
1346 | $this->save_session(); |
---|
1347 | $final[0] = 0; |
---|
1348 | $final[1] = $this -> typeContact; |
---|
1349 | $final['error'] = $ids['error']; |
---|
1350 | echo serialize($final); |
---|
1351 | return; |
---|
1352 | } |
---|
1353 | else if ($ids) |
---|
1354 | { |
---|
1355 | $this->page_info['actual_letter'] = $letter; |
---|
1356 | $this->page_info['actual_entries'] = $ids; |
---|
1357 | $this->page_info['n_pages'] = $dontPaginate ? 1 : ceil(count($this->page_info['actual_entries'])/$this->page_info['n_cards']); |
---|
1358 | } |
---|
1359 | } |
---|
1360 | else |
---|
1361 | { |
---|
1362 | unset($ids); |
---|
1363 | } |
---|
1364 | |
---|
1365 | if ($this->page_info['actual_entries']) |
---|
1366 | { |
---|
1367 | if ($page >= $this->page_info['n_pages']) |
---|
1368 | { |
---|
1369 | $page = $this->page_info['n_pages']; |
---|
1370 | } |
---|
1371 | |
---|
1372 | $final = array( |
---|
1373 | 0 => (int)$this->page_info['n_pages'], |
---|
1374 | 1 => (int)$page, |
---|
1375 | 2 => array( |
---|
1376 | 0 => 'cc_company', |
---|
1377 | 1 => 'cc_name', |
---|
1378 | 2 => 'cc_title', |
---|
1379 | 3 => 'cc_phone', |
---|
1380 | 4 => 'cc_mail', |
---|
1381 | 5 => 'cc_alias', |
---|
1382 | 6 => 'cc_id', |
---|
1383 | 7 => 'cc_forwarding_address', |
---|
1384 | 8 => 'cc_empNumber', |
---|
1385 | 9 => 'cc_department', |
---|
1386 | 10 => 'cc_mobile' |
---|
1387 | ) |
---|
1388 | ); |
---|
1389 | |
---|
1390 | //verifica se esta habilitado a opcao de exibir os detalhes extras |
---|
1391 | $objconfig = CreateObject('phpgwapi.config', 'contactcenter'); |
---|
1392 | $config = $objconfig->read_repository(); |
---|
1393 | |
---|
1394 | //echo 'Page: '.$page.'<br>'; |
---|
1395 | $n_entries = count($this->page_info['actual_entries']); |
---|
1396 | $n_cards = $dontPaginate? $n_entries : $this->page_info['n_cards']; |
---|
1397 | $id_i = (($page-1)*$n_cards); |
---|
1398 | $id_f = $id_i + $n_cards; |
---|
1399 | |
---|
1400 | //echo 'ID_I: '.$id_i.'<br>'; |
---|
1401 | //echo 'ID_F: '.$id_f.'<br>'; |
---|
1402 | ///---------------- Correção Temporária PHP5 -----------------------/// |
---|
1403 | $ids = array(); |
---|
1404 | /**rev 104**/ |
---|
1405 | $perms = array(); |
---|
1406 | $owners = array(); |
---|
1407 | /****/ |
---|
1408 | $array_temp = array(); |
---|
1409 | |
---|
1410 | foreach($this->page_info['actual_entries'] as $key=>$tmp){ |
---|
1411 | $array_temp[] = $tmp; |
---|
1412 | } |
---|
1413 | |
---|
1414 | for($i = $id_i; $i < $id_f and $i < $n_entries; $i++) |
---|
1415 | { |
---|
1416 | /**rev 104**/ |
---|
1417 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
1418 | { |
---|
1419 | /****/ |
---|
1420 | $ids[] = $array_temp[$i]; |
---|
1421 | /**rev 104**/ |
---|
1422 | }else { |
---|
1423 | $ids[] = $array_temp[$i][0]; |
---|
1424 | $perms[] = $array_temp[$i][1]; |
---|
1425 | $owners[] = $array_temp[$i][2]; |
---|
1426 | /****/ |
---|
1427 | } |
---|
1428 | } |
---|
1429 | |
---|
1430 | /**rev 104**/ |
---|
1431 | // Carrega o nome completo dos donos dos objetos (contatos e grupos); |
---|
1432 | $owner_names = array(); |
---|
1433 | |
---|
1434 | if($owners) { |
---|
1435 | $filter = "(|"; |
---|
1436 | foreach($owners as $i => $owner) { |
---|
1437 | $filter .= "(uidNumber=".$owner.")"; |
---|
1438 | } |
---|
1439 | $filter .= ")"; |
---|
1440 | |
---|
1441 | if(!$this->bo->catalog->src_info) { |
---|
1442 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
1443 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
1444 | } |
---|
1445 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false); |
---|
1446 | $dn=$this->bo->catalog->src_info['dn']; |
---|
1447 | $justThese = array("cn","uidnumber","uid"); |
---|
1448 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
1449 | $info = ldap_get_entries($ds, $sr); |
---|
1450 | ldap_close($ds); |
---|
1451 | for($z = 0; $z < $info['count']; $z++) { |
---|
1452 | $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]); |
---|
1453 | } |
---|
1454 | |
---|
1455 | //SAMPLE : dc=teste, dc=diretorio, dc=empresa |
---|
1456 | if(!count($owner_names)){ |
---|
1457 | $dns = explode(',', $dn); |
---|
1458 | for($i = count($dns); $i > 0; $i--){ |
---|
1459 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false); |
---|
1460 | //verifica se veio a base como parametro, remoção de erros gerados por paramentro null |
---|
1461 | //if(isset($dns[$i])){ |
---|
1462 | $sr = ldap_search($ds,$dns[$i], $filter,$justThese); |
---|
1463 | $info = ldap_get_entries($ds, $sr); |
---|
1464 | ldap_close($ds); |
---|
1465 | for($z = 0; $z < $info['count']; $z++) { |
---|
1466 | $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]); |
---|
1467 | } |
---|
1468 | if(count($owner_names)){ |
---|
1469 | $i = 0; |
---|
1470 | } |
---|
1471 | // } |
---|
1472 | } |
---|
1473 | } |
---|
1474 | } |
---|
1475 | |
---|
1476 | /*****/ |
---|
1477 | |
---|
1478 | |
---|
1479 | /// Original |
---|
1480 | //for($i = $id_i; $i < $id_f and $i < $n_entries; $i++) |
---|
1481 | //{ |
---|
1482 | // $ids[] = $this->page_info['actual_entries'][$i]; |
---|
1483 | //} |
---|
1484 | /// |
---|
1485 | |
---|
1486 | $fields = $this->bo->catalog->get_fields(false); |
---|
1487 | /**rev 104**/ |
---|
1488 | //if( $this->typeContact == 'groups') { |
---|
1489 | if( $this->typeContact == 'groups' || $this->typeContact == 'shared_groups') { |
---|
1490 | /****/ |
---|
1491 | $final = array( |
---|
1492 | 0 => (int)$this->page_info['n_pages'], |
---|
1493 | 1 => (int)$page, |
---|
1494 | 2 => array( |
---|
1495 | 0 => 'cc_title', |
---|
1496 | 1 => 'cc_short_name', |
---|
1497 | 2 => 'cc_id', |
---|
1498 | 3 => 'cc_contacts' |
---|
1499 | ) |
---|
1500 | ); |
---|
1501 | |
---|
1502 | $groups = $this->bo->catalog->get_multiple_entries($ids,$fields); |
---|
1503 | |
---|
1504 | $i = 0; |
---|
1505 | // contatos do grupo |
---|
1506 | $boGroups = CreateObject('contactcenter.bo_group'); |
---|
1507 | $contacts = array(); |
---|
1508 | foreach($groups as $group) { |
---|
1509 | |
---|
1510 | $final[3][$i][0] = $group['title'] ? $group['title'] : 'none'; |
---|
1511 | $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none'; |
---|
1512 | $final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none'; |
---|
1513 | $contacts = $boGroups -> get_contacts_by_group($group['id_group']); |
---|
1514 | $final[3][$i][3] = $contacts; |
---|
1515 | $final[3][$i][4] = $perms[$i]; |
---|
1516 | if($this->typeContact == 'shared_groups'){ |
---|
1517 | $final[3][$i][5] = lang('Shared').": ".$owner_names[$owners[$i]]['cn']; |
---|
1518 | $final[3][$i][6] = $owner_names[$owners[$i]]['uid']; |
---|
1519 | $final[3][$i][7] = $owners[$i]; //uidNumber |
---|
1520 | } |
---|
1521 | $i++; |
---|
1522 | } |
---|
1523 | |
---|
1524 | $this->page_info['actual_letter'] = $letter; |
---|
1525 | $this->page_info['actual_page'] = $page; |
---|
1526 | |
---|
1527 | |
---|
1528 | $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; |
---|
1529 | |
---|
1530 | $final[5] = '<span class="link" onclick="'.$lnk_compose; |
---|
1531 | /**rev 104**/ |
---|
1532 | //$final[10] = 'groups'; |
---|
1533 | $final[10] = $this->typeContact; |
---|
1534 | /******/ |
---|
1535 | $this->save_session(); |
---|
1536 | echo serialize($final); |
---|
1537 | return; |
---|
1538 | } |
---|
1539 | /**rev 104**/ |
---|
1540 | $final[10] = $this -> typeContact; |
---|
1541 | /*****/ |
---|
1542 | |
---|
1543 | $fields['photo'] = true; |
---|
1544 | $fields['names_ordered'] = true; |
---|
1545 | $fields['alias'] = true; |
---|
1546 | $fields['account_type'] = true; |
---|
1547 | $fields['companies'] = 'default'; |
---|
1548 | $fields['connections'] = 'default'; |
---|
1549 | |
---|
1550 | /**rev 104**/ |
---|
1551 | // ?aqui alterar a chamada desse método para receber o base dn? |
---|
1552 | //$contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields); |
---|
1553 | |
---|
1554 | // ?aqui alterar a chamada desse método para receber o base dn? |
---|
1555 | if($external) |
---|
1556 | { |
---|
1557 | $contacts = $this->bo->catalog->get_multiple_entries($ids,$fields,false,true); |
---|
1558 | } else{ |
---|
1559 | $contacts = $this->bo->catalog->get_multiple_entries($ids,$fields); |
---|
1560 | } |
---|
1561 | /*******/ |
---|
1562 | if (!is_array($contacts) or !count($contacts)) |
---|
1563 | { |
---|
1564 | $final[0] = 0; |
---|
1565 | $final[1] = $this -> typeContact; |
---|
1566 | echo serialize($final); |
---|
1567 | return; |
---|
1568 | } |
---|
1569 | |
---|
1570 | $i = 0; |
---|
1571 | if (!is_array($this->preferences)) |
---|
1572 | { |
---|
1573 | $this->preferences['personCardEmail'] = 1; |
---|
1574 | $this->preferences['personCardPhone'] = 2; |
---|
1575 | } |
---|
1576 | foreach($contacts as $index => $contact) |
---|
1577 | { |
---|
1578 | /* |
---|
1579 | * TODO: Os timeouts de conexão foram retirados, ver se será necessário retornar essa funcionalidade, e, |
---|
1580 | * neste caso, terminar a implementação das mensagens de retorno. |
---|
1581 | */ |
---|
1582 | if ($index !== 'error'){ |
---|
1583 | $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none'; |
---|
1584 | |
---|
1585 | /**rev 104**/ |
---|
1586 | //$final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none'; |
---|
1587 | |
---|
1588 | if($this->page_info['actual_catalog']['class']!='bo_global_ldap_catalog'){ |
---|
1589 | $final[3][$i][1] = $contact['names_ordered'] ? urldecode(is_array($contact['names_ordered']) ? $contact['names_ordered'][0] : $contact['names_ordered']) : 'none'; |
---|
1590 | } |
---|
1591 | else { |
---|
1592 | $contact['names_ordered'][0] = urldecode($contact['names_ordered'][0]); |
---|
1593 | $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none'; |
---|
1594 | } |
---|
1595 | |
---|
1596 | /********/ |
---|
1597 | |
---|
1598 | $final[3][$i][2] = $contact['companies']['company1']['title']? $contact['companies']['company1']['title']:'none'; |
---|
1599 | |
---|
1600 | //Para exibir a matricula do empregado |
---|
1601 | $final[3][$i][8] = $contact['companies']['company1']['empNumber']?$contact['companies']['company1']['empNumber']:'none'; |
---|
1602 | //Para exibir o setor/lotacao do empregado |
---|
1603 | $final[3][$i][9] = $contact['companies']['company1']['department']?$contact['companies']['company1']['department']:'none'; |
---|
1604 | //Para exibir o celular empresarial do empregado |
---|
1605 | $final[3][$i][10] = $contact['companies']['company1']['celPhone']?$contact['companies']['company1']['celPhone']:'none'; |
---|
1606 | |
---|
1607 | //Para exibir o celular empresarial do empregado |
---|
1608 | if ($this->preferences['voip_enabled'] && !$external && $final[3][$i][10] != 'none') |
---|
1609 | $final[3][$i][10] = "<a title=\"".lang("Call Mobile")."\" href=\"#\" onclick=\"connectVoip('".$final[3][$i][10]."', 'mob')\">".$final[3][$i][10]."</a>"; |
---|
1610 | |
---|
1611 | if ($contact['connections']) |
---|
1612 | { |
---|
1613 | $default_email_found = false; |
---|
1614 | $default_phone_found = false; |
---|
1615 | foreach($contact['connections'] as $conn_info) |
---|
1616 | { |
---|
1617 | if ($conn_info['id_type'] == $this->preferences['personCardEmail'] and !$default_email_found) |
---|
1618 | { |
---|
1619 | if ($conn_info['connection_is_default']) |
---|
1620 | { |
---|
1621 | $default_email_found = true; |
---|
1622 | } |
---|
1623 | $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; |
---|
1624 | $final[3][$i][13] = $conn_info['id_connection']; |
---|
1625 | } |
---|
1626 | else if ($conn_info['id_type'] == $this->preferences['personCardPhone'] and !$default_phone_found) |
---|
1627 | { |
---|
1628 | if ($conn_info['connection_is_default']) |
---|
1629 | { |
---|
1630 | $default_phone_found = true; |
---|
1631 | } |
---|
1632 | if($final[3][$i][4] == 'none' or !$final[3][$i][4]){ |
---|
1633 | $final[3][$i][4] = lang('Not informed'); |
---|
1634 | $final[3][$i][13] = $conn_info['id_connection']; |
---|
1635 | } |
---|
1636 | /**rev 104**/ |
---|
1637 | //if ($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] && !$external){ |
---|
1638 | // $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'ramal')\">".$conn_info['connection_value']."</a>"; |
---|
1639 | |
---|
1640 | if (!($this->preferences['telephone_number'] == $conn_info['connection_value']) && $this->preferences['contactcenter']['voip_enabled'] && $conn_info['connection_value'] && preg_match('/^\([0-9]{2}\)[0-9]{4}\-[0-9]{4}$/',$conn_info['connection_value'])==1 && !$external){ |
---|
1641 | $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>"; |
---|
1642 | |
---|
1643 | /*****/ |
---|
1644 | } |
---|
1645 | $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; |
---|
1646 | } |
---|
1647 | if($final[3][$i][4] == 'none' or !$final[3][$i][4]){ |
---|
1648 | $final[3][$i][4] = lang('Not informed'); |
---|
1649 | $final[3][$i][13] = $conn_info['id_connection']; |
---|
1650 | |
---|
1651 | } |
---|
1652 | } |
---|
1653 | } |
---|
1654 | |
---|
1655 | if (!$final[3][$i][3]) |
---|
1656 | { |
---|
1657 | $final[3][$i][3] = 'none'; |
---|
1658 | } |
---|
1659 | |
---|
1660 | if($final[3][$i][4] == 'none' or !$final[3][$i][4]){ |
---|
1661 | $final[3][$i][4] = lang('Not informed'); |
---|
1662 | $final[3][$i][13] = $conn_info['id_connection']; |
---|
1663 | |
---|
1664 | } |
---|
1665 | |
---|
1666 | $final[3][$i][5] = $contact['alias']? urldecode( $contact['alias'] ):'none'; |
---|
1667 | $final[3][$i][6] = utf8_decode($ids[$i]); |
---|
1668 | |
---|
1669 | /**rev 104**/ |
---|
1670 | /* // If contact is a public list, then load the forwarding addresses. |
---|
1671 | if($contact['account_type'][0] == 'l') |
---|
1672 | $final[3][$i][7] = array(); |
---|
1673 | */ |
---|
1674 | |
---|
1675 | //If contact is a public list or a group, then load the forwarding addresses. |
---|
1676 | if($contact['account_type'][0] == 'l' || $contact['account_type'][0] == 'g') |
---|
1677 | $final[3][$i][7] = ($contact['account_type'][0] == 'l' ? 'list' : 'group'); |
---|
1678 | |
---|
1679 | if($this->page_info['actual_catalog']['class']=='bo_shared_people_manager') { |
---|
1680 | $final[3][$i][11] = $perms[$i]; |
---|
1681 | $final[3][$i][12] = lang('Shared').": ".$owner_names[$owners[$i]]['cn']; |
---|
1682 | } |
---|
1683 | |
---|
1684 | $final[4][$i] = $contact['photo'] ? 1 : 0; |
---|
1685 | |
---|
1686 | |
---|
1687 | |
---|
1688 | $i++; |
---|
1689 | } |
---|
1690 | else |
---|
1691 | { |
---|
1692 | // coloca mensagem de erro no vetor que retorna para o browser |
---|
1693 | } |
---|
1694 | } |
---|
1695 | $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; |
---|
1696 | $final[5] = '<span class="link" onclick="'.$lnk_compose; |
---|
1697 | $final[6] = $prop_names; |
---|
1698 | $final[7] = $validos; |
---|
1699 | $final[8] = $this->page_info['actual_catalog']['class']; |
---|
1700 | $final[9] = $count; |
---|
1701 | $final[11] = $this->bo->catalog_level; |
---|
1702 | $final[12] = isset($config['cc_allow_details'])? $config['cc_allow_details'] : false; |
---|
1703 | $final[13] = '<span class="" '; |
---|
1704 | $this->page_info['actual_letter'] = $letter; |
---|
1705 | $this->page_info['actual_page'] = $page; |
---|
1706 | |
---|
1707 | $this->save_session(); |
---|
1708 | echo serialize($final); |
---|
1709 | return; |
---|
1710 | } |
---|
1711 | |
---|
1712 | $this->page_info['actual_letter'] = $letter; |
---|
1713 | $this->page_info['actual_page'] = $page; |
---|
1714 | |
---|
1715 | $this->save_session(); |
---|
1716 | |
---|
1717 | $final[0] = 0; |
---|
1718 | $final[1] = $this -> typeContact; |
---|
1719 | echo serialize($final); |
---|
1720 | } |
---|
1721 | |
---|
1722 | |
---|
1723 | function get_list_owners_perms_add(){ |
---|
1724 | $acl = CreateObject('phpgwapi.acl'); |
---|
1725 | $find_result = $acl->get_rights_and_owners($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter'); |
---|
1726 | if($find_result){ |
---|
1727 | $owner_names = array(); |
---|
1728 | $filter = "(|"; |
---|
1729 | foreach($find_result as $owner) { |
---|
1730 | if(($owner['acl_rights'] & PHPGW_ACL_ADD) == PHPGW_ACL_ADD){ |
---|
1731 | $filter .= "(uidNumber=".$owner['acl_account'].")"; |
---|
1732 | } |
---|
1733 | } |
---|
1734 | if(!$this->bo->catalog->src_info) { |
---|
1735 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
1736 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
1737 | } |
---|
1738 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false); |
---|
1739 | $filter .= ")"; |
---|
1740 | $dn=$this->bo->catalog->src_info['dn']; |
---|
1741 | $justThese = array("cn","uidnumber","uid"); |
---|
1742 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
1743 | $info = ldap_get_entries($ds, $sr); |
---|
1744 | for($z = 0; $z < $info['count']; $z++) { |
---|
1745 | $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]); |
---|
1746 | } |
---|
1747 | ldap_close($ds); |
---|
1748 | if(!count($owner_names)){ |
---|
1749 | $dns = explode(',', $dn); |
---|
1750 | for($i = count($dns); $i > 0; $i--){ |
---|
1751 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false); |
---|
1752 | $sr = ldap_search($ds,$dns[$i], $filter,$justThese); |
---|
1753 | $info = ldap_get_entries($ds, $sr); |
---|
1754 | ldap_close($ds); |
---|
1755 | for($z = 0; $z < $info['count']; $z++) { |
---|
1756 | $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]); |
---|
1757 | } |
---|
1758 | if(count($owner_names)){ |
---|
1759 | $i = 0; |
---|
1760 | } |
---|
1761 | } |
---|
1762 | } |
---|
1763 | } |
---|
1764 | echo serialize ($owner_names); |
---|
1765 | } |
---|
1766 | |
---|
1767 | function get_visible_all_ldap() |
---|
1768 | { |
---|
1769 | $bo = CreateObject('contactcenter.bo_ldap_manager'); |
---|
1770 | $ldap_query = $bo->srcs; |
---|
1771 | return $ldap_query[1]['visible']; |
---|
1772 | } |
---|
1773 | |
---|
1774 | |
---|
1775 | /*! |
---|
1776 | |
---|
1777 | @function get_group_data |
---|
1778 | @abstract Returns all the information of a given Group |
---|
1779 | @author Nilton Emilio Buhrer Neto |
---|
1780 | |
---|
1781 | @param (integer) $id The id to get information |
---|
1782 | |
---|
1783 | */ |
---|
1784 | function get_group_data($id,$shared_from=null) |
---|
1785 | { |
---|
1786 | $this->bo->catalog = CreateObject('contactcenter.bo_group_manager'); |
---|
1787 | $fields = $this->bo->catalog->get_fields(true); |
---|
1788 | $data = $this->bo->catalog->get_single_entry($id,$fields); |
---|
1789 | |
---|
1790 | if($id) { |
---|
1791 | // get All Contacts by group. |
---|
1792 | $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id); |
---|
1793 | } |
---|
1794 | |
---|
1795 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
1796 | |
---|
1797 | $all_contacts = $boGroup->get_all_contacts(false,$shared_from); |
---|
1798 | |
---|
1799 | $contact_options = ""; |
---|
1800 | if(count($all_contacts)) { |
---|
1801 | foreach($all_contacts as $idx => $contact) { |
---|
1802 | $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']; |
---|
1803 | if (isset($contact['connection_value'])) |
---|
1804 | $contact_options .= " (".$contact['connection_value'].")</OPTION>"; |
---|
1805 | else |
---|
1806 | $contact_options .= " (". $contact['phone'].")</OPTION>"; |
---|
1807 | } |
---|
1808 | } |
---|
1809 | $data['contact_list'] = $contact_options; |
---|
1810 | $data['result'] = 'ok'; |
---|
1811 | echo serialize($data); |
---|
1812 | } |
---|
1813 | |
---|
1814 | /*! |
---|
1815 | |
---|
1816 | @function get_full_data |
---|
1817 | @abstract Returns all the information of a given Entry |
---|
1818 | @author Raphael Derosso Pereira |
---|
1819 | |
---|
1820 | @param (integer) $id The id to get information |
---|
1821 | |
---|
1822 | */ |
---|
1823 | /**rev 104**/ |
---|
1824 | //function get_full_data($id) |
---|
1825 | function get_full_data($id,$catalog='bo_people_catalog') |
---|
1826 | { |
---|
1827 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
1828 | /**rev 104**/ |
---|
1829 | //$this->bo->catalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
1830 | $this->bo->catalog = CreateObject('contactcenter.'.$catalog); |
---|
1831 | /****/ |
---|
1832 | $fields = $this->bo->catalog->get_fields(true); |
---|
1833 | $fields['photo'] = false; |
---|
1834 | $entry = $this->bo->catalog->get_single_entry($id,$fields); |
---|
1835 | |
---|
1836 | if (is_bool($entry['given_names'])) |
---|
1837 | { |
---|
1838 | $data['result'] = 'false'; |
---|
1839 | echo serialize($data); |
---|
1840 | return; |
---|
1841 | } |
---|
1842 | |
---|
1843 | $date = explode('-', $entry['birthdate']); |
---|
1844 | $j = 0; |
---|
1845 | for ($i = 0; $i < 5; $i+=2) |
---|
1846 | { |
---|
1847 | switch($dateformat{$i}) |
---|
1848 | { |
---|
1849 | case 'Y': |
---|
1850 | $birthdate[$j] = $date[0]; |
---|
1851 | break; |
---|
1852 | |
---|
1853 | case 'm': |
---|
1854 | case 'M': |
---|
1855 | $birthdate[$j] = $date[1]; |
---|
1856 | break; |
---|
1857 | |
---|
1858 | case 'd': |
---|
1859 | $birthdate[$j] = $date[2]; |
---|
1860 | } |
---|
1861 | $j++; |
---|
1862 | } |
---|
1863 | $datecount = 0; |
---|
1864 | |
---|
1865 | $data['result'] = 'ok'; |
---|
1866 | $data['cc_full_add_contact_id'] = $id; |
---|
1867 | |
---|
1868 | /* Personal Data */ |
---|
1869 | $data['personal']['cc_pd_photo'] = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id; |
---|
1870 | $data['personal']['cc_pd_alias'] = $entry['alias']; |
---|
1871 | $data['personal']['cc_pd_given_names'] = $entry['given_names']; |
---|
1872 | $data['personal']['cc_pd_family_names'] = $entry['family_names']; |
---|
1873 | $data['personal']['cc_pd_full_name'] = $entry['names_ordered']; |
---|
1874 | $data['personal']['cc_pd_suffix'] = $entry['id_suffix']; |
---|
1875 | $data['personal']['cc_pd_birthdate_0'] = $birthdate[0]; |
---|
1876 | $data['personal']['cc_pd_birthdate_1'] = $birthdate[1]; |
---|
1877 | $data['personal']['cc_pd_birthdate_2'] = $birthdate[2]; |
---|
1878 | //$data['personal']['cc_pd_sex'] = $entry['sex'] === 'M' ? 1 : ($entry['sex'] === 'F' ? 2 : 0); |
---|
1879 | $data['personal']['cc_pd_prefix'] = $entry['id_prefix']; |
---|
1880 | $data['personal']['cc_pd_gpg_finger_print'] = $entry['pgp_key']; |
---|
1881 | $data['personal']['cc_pd_notes'] = $entry['notes']; |
---|
1882 | |
---|
1883 | /* Addresses */ |
---|
1884 | if (is_array($entry['addresses'])) |
---|
1885 | { |
---|
1886 | $data['addresses'] = $entry['addresses']; |
---|
1887 | } |
---|
1888 | |
---|
1889 | /* Connections */ |
---|
1890 | if (is_array($entry['connections'])) |
---|
1891 | { |
---|
1892 | $data['connections'] = array(); |
---|
1893 | foreach ($entry['connections'] as $connection) |
---|
1894 | { |
---|
1895 | $type = $connection['id_type']; |
---|
1896 | $i = count($data['connections'][$type]); |
---|
1897 | $data['connections'][$type][$i]['id'] = $connection['id_connection']; |
---|
1898 | $data['connections'][$type][$i]['name'] = $connection['connection_name']; |
---|
1899 | $data['connections'][$type][$i]['value'] = $connection['connection_value']; |
---|
1900 | $data['connections'][$type][$i]['is_default'] = $connection['connection_is_default']; |
---|
1901 | } |
---|
1902 | } |
---|
1903 | // print_r($data); |
---|
1904 | //OBSERVAR cc_department |
---|
1905 | /*Corporative*/ |
---|
1906 | if($GLOBALS['phpgw_info']['server']['personal_contact_type']=='True'){ |
---|
1907 | $data['personal']['cc_job_title'] = $entry['job_title']; |
---|
1908 | $data['personal']['cc_department'] = $entry['department']; |
---|
1909 | $data['personal']['cc_name_corporate'] = $entry['corporate_name']; |
---|
1910 | $data['personal']['cc_web_page'] = $entry['web_page']; |
---|
1911 | } |
---|
1912 | |
---|
1913 | |
---|
1914 | |
---|
1915 | /* Relations */ |
---|
1916 | /* Groups */ |
---|
1917 | /* |
---|
1918 | * Criado uma estrutura no data que conterá os grupos do |
---|
1919 | * contato. O formato é: |
---|
1920 | * data['groups'] = array( |
---|
1921 | * 'id_group' => array( |
---|
1922 | * 'id_group', 'title', 'short_name' |
---|
1923 | * ) |
---|
1924 | * ); |
---|
1925 | */ |
---|
1926 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
1927 | $groups = $boGroup->get_contact_groups($id); |
---|
1928 | |
---|
1929 | $i = 0; |
---|
1930 | $data['groups'] = array(); |
---|
1931 | if(is_array($groups)) |
---|
1932 | foreach($groups as $group) |
---|
1933 | { |
---|
1934 | $idGroup = $group['id_group']; |
---|
1935 | $data['groups'][$idGroup] = array( |
---|
1936 | 'title' => $group['title'], |
---|
1937 | 'id_group' => $idGroup, |
---|
1938 | 'short_name' => $group['short_name'] |
---|
1939 | ); |
---|
1940 | $i++; |
---|
1941 | } |
---|
1942 | |
---|
1943 | echo serialize($data); |
---|
1944 | } |
---|
1945 | |
---|
1946 | /*! |
---|
1947 | |
---|
1948 | @function get_contact_full_add_const |
---|
1949 | @abstract Returns all the constant fields in Contact Full Add Window to the JS |
---|
1950 | @author Raphael Derosso Pereira |
---|
1951 | */ |
---|
1952 | function get_contact_full_add_const() |
---|
1953 | { |
---|
1954 | $data = array(); |
---|
1955 | $boPeopleCatalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
1956 | $predata[] = $boPeopleCatalog -> get_all_prefixes(); |
---|
1957 | $predata[] = $boPeopleCatalog -> get_all_suffixes(); |
---|
1958 | $predata[] = $boPeopleCatalog -> get_all_addresses_types(); |
---|
1959 | $predata[] = $boPeopleCatalog -> get_all_countries(); |
---|
1960 | $predata[] = $boPeopleCatalog -> get_all_connections_types(); |
---|
1961 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
1962 | //$predata[] = $boGroup->get_groups_by_user(); |
---|
1963 | //$predata[] = $this->bo->catalog->get_all_relations_types(); |
---|
1964 | |
---|
1965 | if ($this->typeContact == 'shared_contacts') { |
---|
1966 | $so_contact = CreateObject('contactcenter.so_contact', $GLOBALS['phpgw_info']['user']['account_id']); |
---|
1967 | $relacionados = $so_contact->get_relations(); |
---|
1968 | |
---|
1969 | foreach($relacionados as $uid_relacionado => $tipo_relacionamento) { |
---|
1970 | $predata[] = $boGroup->get_groups_by_user($uid_relacionado); |
---|
1971 | } |
---|
1972 | } else { |
---|
1973 | $predata[] = $boGroup->get_groups_by_user(); |
---|
1974 | } |
---|
1975 | |
---|
1976 | |
---|
1977 | $i = 0; |
---|
1978 | foreach($predata as $data_) |
---|
1979 | { |
---|
1980 | if ($data_) |
---|
1981 | { |
---|
1982 | $data[$i] = $data_; |
---|
1983 | } |
---|
1984 | |
---|
1985 | $i++; |
---|
1986 | } |
---|
1987 | |
---|
1988 | if (count($data)) |
---|
1989 | { |
---|
1990 | echo serialize($data); |
---|
1991 | return; |
---|
1992 | } |
---|
1993 | |
---|
1994 | echo 0; |
---|
1995 | } |
---|
1996 | |
---|
1997 | /*! |
---|
1998 | |
---|
1999 | @function quick_add |
---|
2000 | @abstract Adds a new Contact using the Quick Add interface |
---|
2001 | @author Raphael Derosso Pereira |
---|
2002 | |
---|
2003 | @param string $sdata Serialized data |
---|
2004 | */ |
---|
2005 | function quick_add($sdata, $echo=true) |
---|
2006 | { |
---|
2007 | |
---|
2008 | $sdata = str_replace('\\"', '"', $sdata); |
---|
2009 | $new_array = unserialize($sdata); |
---|
2010 | $tdata = array(); |
---|
2011 | |
---|
2012 | foreach($new_array as $tmp) |
---|
2013 | $tdata[] = $tmp; |
---|
2014 | |
---|
2015 | if (!$tdata) |
---|
2016 | { |
---|
2017 | if ($echo) |
---|
2018 | { |
---|
2019 | echo serialize(array( |
---|
2020 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
2021 | 'status' => 'abort' |
---|
2022 | )); |
---|
2023 | |
---|
2024 | return; |
---|
2025 | } |
---|
2026 | else |
---|
2027 | { |
---|
2028 | return serialize(array( |
---|
2029 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
2030 | 'status' => 'abort' |
---|
2031 | )); |
---|
2032 | } |
---|
2033 | } |
---|
2034 | $data['alias'] = addslashes($tdata[0]); |
---|
2035 | $data['given_names'] = addslashes($tdata[1]); |
---|
2036 | $data['family_names'] = addslashes($tdata[2]); |
---|
2037 | $data['connections']['default_phone']['connection_name'] = lang('Main'); |
---|
2038 | $data['connections']['default_phone']['connection_value'] = $tdata[3]; |
---|
2039 | $data['connections']['default_email']['connection_name'] = lang('Main'); |
---|
2040 | $data['connections']['default_email']['connection_value'] = $tdata[4]; |
---|
2041 | $data['is_quick_add'] = true; |
---|
2042 | $boPeople = CreateObject('contactcenter.bo_people_catalog'); |
---|
2043 | |
---|
2044 | $result = $boPeople->quick_add($data); |
---|
2045 | if ($result) |
---|
2046 | { |
---|
2047 | $this->page_info['changed'] = true; |
---|
2048 | |
---|
2049 | if ($echo) |
---|
2050 | { |
---|
2051 | echo serialize(array( |
---|
2052 | 'msg' => lang('Entry added with success!'), |
---|
2053 | 'status' => 'ok' |
---|
2054 | )); |
---|
2055 | } |
---|
2056 | else |
---|
2057 | { |
---|
2058 | return serialize(array( |
---|
2059 | 'msg' => lang('Entry added with success!'), |
---|
2060 | 'status' => 'ok', |
---|
2061 | 'conn' => $boPeople->get_connections($result) |
---|
2062 | )); |
---|
2063 | } |
---|
2064 | } |
---|
2065 | else |
---|
2066 | { |
---|
2067 | if ($echo) |
---|
2068 | { |
---|
2069 | echo serialize(array( |
---|
2070 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
2071 | 'status' => 'error' |
---|
2072 | )); |
---|
2073 | } |
---|
2074 | else |
---|
2075 | { |
---|
2076 | echo serialize(array( |
---|
2077 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
2078 | 'status' => 'error' |
---|
2079 | )); |
---|
2080 | } |
---|
2081 | } |
---|
2082 | |
---|
2083 | $this->save_session(); |
---|
2084 | |
---|
2085 | } |
---|
2086 | |
---|
2087 | /*! |
---|
2088 | |
---|
2089 | @function add_group |
---|
2090 | @abstract Adds a new Group using the Add Group interface |
---|
2091 | @author Nilton Emilio Buhrer Neto |
---|
2092 | |
---|
2093 | @param string $sdata Serialized data |
---|
2094 | */ |
---|
2095 | function add_group($sdata) |
---|
2096 | { |
---|
2097 | $sdata = str_replace('\\"', '"', $sdata); |
---|
2098 | $tdata = unserialize($sdata); |
---|
2099 | $new_tdata = array(); |
---|
2100 | |
---|
2101 | if (!$tdata) |
---|
2102 | { |
---|
2103 | echo serialize(array( |
---|
2104 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
2105 | 'status' => 'abort' |
---|
2106 | )); |
---|
2107 | |
---|
2108 | return; |
---|
2109 | } |
---|
2110 | |
---|
2111 | foreach($tdata as $tmp) |
---|
2112 | $new_tdata[] = $tmp; |
---|
2113 | |
---|
2114 | $data['title'] = $new_tdata[0]; |
---|
2115 | $data['contact_in_list'] = $new_tdata[1]; |
---|
2116 | $data['id_group'] = $new_tdata[2]; |
---|
2117 | $acumulatedErrors = ''; |
---|
2118 | |
---|
2119 | $actualCatalog = $this->get_actual_catalog(); |
---|
2120 | for ($i = 0; $i < count($data['contact_in_list']); $i++) |
---|
2121 | { |
---|
2122 | if (preg_match('/ldap:.*:.*/', $data['contact_in_list'][$i])) // from ldap |
---|
2123 | { |
---|
2124 | list(, $level, $dn) = explode(':', $data['contact_in_list'][$i]); |
---|
2125 | |
---|
2126 | // pesquisa os dados, insere no catálogo e modifica |
---|
2127 | // a entrada em $data['contact_in_list'][$i] |
---|
2128 | $set_catalog = $this->set_catalog($level, false); |
---|
2129 | $contact_data = unserialize($this->get_catalog_add_contact(utf8_encode($dn), false)); |
---|
2130 | $tmp_contact[] = $contact_data[0][0]; |
---|
2131 | $tmp_contact[] = $contact_data[1][0]; |
---|
2132 | $tmp_contact[] = $contact_data[2][0]; |
---|
2133 | $tmp_contact[] = $contact_data[3][0]; |
---|
2134 | $tmp_contact[] = $contact_data[4][0]; |
---|
2135 | |
---|
2136 | // Determinar o id_connection |
---|
2137 | $id_contact = unserialize($this->quick_add(serialize($tmp_contact), false)); |
---|
2138 | |
---|
2139 | switch ($id_contact['status']) |
---|
2140 | { |
---|
2141 | case 'ok' : |
---|
2142 | foreach ($id_contact['conn'] as $connection) |
---|
2143 | { |
---|
2144 | if ($connection['id_type'] == 1) |
---|
2145 | { |
---|
2146 | $data['contact_in_list'][$i] = $connection['id_connection']; |
---|
2147 | } |
---|
2148 | } |
---|
2149 | break; |
---|
2150 | |
---|
2151 | case 'alreadyExists': // if e-mail exists get their id_connection from people_catalog |
---|
2152 | $data['contact_in_list'][$i] = $id_contact['id_connection']; |
---|
2153 | |
---|
2154 | default: |
---|
2155 | $acumulatedErrors += $id_contact['msg']."\n"; |
---|
2156 | } |
---|
2157 | unset($tmp_contact); |
---|
2158 | |
---|
2159 | } |
---|
2160 | } |
---|
2161 | $set_catalog = $this->set_catalog($actualCatalog['data'], false); // retorna ao catálogo original. |
---|
2162 | $boGroup = CreateObject('contactcenter.bo_group_manager'); |
---|
2163 | $id = $boGroup -> add_group($data); |
---|
2164 | |
---|
2165 | if ($id) |
---|
2166 | { |
---|
2167 | $this->page_info['changed'] = true; |
---|
2168 | |
---|
2169 | echo serialize(array( |
---|
2170 | 'msg' => lang('Entry added with success!'), |
---|
2171 | 'status' => 'ok' |
---|
2172 | )); |
---|
2173 | } |
---|
2174 | else |
---|
2175 | { |
---|
2176 | echo serialize(array( |
---|
2177 | 'msg' => lang("Problems on adding your Group. Be sure that a group with this name do not exists"). |
---|
2178 | "\n".$acumulatedErrors, |
---|
2179 | 'status' => 'error' |
---|
2180 | )); |
---|
2181 | } |
---|
2182 | |
---|
2183 | $this->save_session(); |
---|
2184 | } |
---|
2185 | |
---|
2186 | /*! |
---|
2187 | |
---|
2188 | @function remove_group |
---|
2189 | @abstract Removes a group if the user has the right to do it |
---|
2190 | @author Nilton Emilio Buhrer Neto |
---|
2191 | @param (integer) $id The id to be removed |
---|
2192 | |
---|
2193 | */ |
---|
2194 | function remove_group($id) |
---|
2195 | { |
---|
2196 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
2197 | $data = array ('id_group' => $id); |
---|
2198 | if($soGroup -> delete($data)) { |
---|
2199 | echo serialize(array( |
---|
2200 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
2201 | 'status' => 'ok' |
---|
2202 | )); |
---|
2203 | } |
---|
2204 | else { |
---|
2205 | echo serialize(array( |
---|
2206 | 'msg' => lang("Could\'nt remove group with id: %1", $id), |
---|
2207 | 'status' => 'error' |
---|
2208 | )); |
---|
2209 | } |
---|
2210 | |
---|
2211 | $this->save_session(); |
---|
2212 | } |
---|
2213 | |
---|
2214 | |
---|
2215 | function remove_all_entries (){ |
---|
2216 | |
---|
2217 | $error = false; |
---|
2218 | $this->all_entries = $this->bo->catalog->get_all_entries_ids(); |
---|
2219 | |
---|
2220 | foreach($this->all_entries as $index => $id) { |
---|
2221 | $result = $this->bo->catalog->remove_single_entry($id); |
---|
2222 | if(!$result) { |
---|
2223 | $error = true; |
---|
2224 | break; |
---|
2225 | } |
---|
2226 | } |
---|
2227 | |
---|
2228 | if(!$error) { |
---|
2229 | echo serialize(array( |
---|
2230 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
2231 | 'status' => 'ok' |
---|
2232 | )); |
---|
2233 | } |
---|
2234 | else { |
---|
2235 | echo serialize(array( |
---|
2236 | 'msg' => lang('Couldn\'t remove this entry. Inform the Site Admin!'), |
---|
2237 | 'status' => 'fail' |
---|
2238 | )); |
---|
2239 | } |
---|
2240 | |
---|
2241 | $this->save_session(); |
---|
2242 | } |
---|
2243 | |
---|
2244 | /*! |
---|
2245 | |
---|
2246 | @function remove_entry |
---|
2247 | @abstract Removes an entry if the user has the right to do it |
---|
2248 | @author Raphael Derosso Pereira |
---|
2249 | |
---|
2250 | @param (integer) $id The id to be removed |
---|
2251 | |
---|
2252 | */ |
---|
2253 | function remove_entry ($id) |
---|
2254 | { |
---|
2255 | if (!is_int($id)) |
---|
2256 | { |
---|
2257 | echo lang('Couldn\'t remove entry! Problem passing data to the server. Please inform admin!'); |
---|
2258 | return; |
---|
2259 | } |
---|
2260 | |
---|
2261 | $this->page_info['changed'] = true; |
---|
2262 | $result = $this->bo->catalog->remove_single_entry($id); |
---|
2263 | |
---|
2264 | if ($result) |
---|
2265 | { |
---|
2266 | if ($pos = array_search($id, $this->page_info['actual_entries'])) |
---|
2267 | { |
---|
2268 | unset($this->page_info['actual_entries'][$pos]); |
---|
2269 | } |
---|
2270 | |
---|
2271 | $temp = false; |
---|
2272 | reset($this->page_info['actual_entries']); |
---|
2273 | foreach($this->page_info['actual_entries'] as $t) |
---|
2274 | { |
---|
2275 | $temp[] = $t; |
---|
2276 | } |
---|
2277 | |
---|
2278 | $this->page_info['actual_entries'] = $temp; |
---|
2279 | |
---|
2280 | echo serialize(array( |
---|
2281 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
2282 | 'status' => 'ok' |
---|
2283 | )); |
---|
2284 | } |
---|
2285 | else |
---|
2286 | { |
---|
2287 | echo serialize(array( |
---|
2288 | 'msg' => lang('Couldn\'t remove this entry. Inform the Site Admin!'), |
---|
2289 | 'status' => 'fail' |
---|
2290 | )); |
---|
2291 | } |
---|
2292 | |
---|
2293 | $this->save_session(); |
---|
2294 | } |
---|
2295 | |
---|
2296 | |
---|
2297 | /*! |
---|
2298 | |
---|
2299 | @function post_full_add |
---|
2300 | @abstract Saves all the information altered/entered in the Full Add |
---|
2301 | window |
---|
2302 | @author Raphael Derosso Pereira |
---|
2303 | |
---|
2304 | */ |
---|
2305 | function post_full_add() |
---|
2306 | { |
---|
2307 | $data = $_POST['data']; |
---|
2308 | // Exceptions!!! utf8 special chars. |
---|
2309 | $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data); |
---|
2310 | $data = unserialize(str_replace('\\"', '"', $data)); |
---|
2311 | $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
2312 | |
---|
2313 | if (!is_array($data)) |
---|
2314 | { |
---|
2315 | echo serialize(array( |
---|
2316 | 'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'. |
---|
2317 | 'Please go to eGroupWare Bug Reporting page and report this bug.<br>'. |
---|
2318 | 'Sorry for the inconvenient!<br><br>'. |
---|
2319 | '<b><i>ContactCenter Developer Team</i></b></p>'), |
---|
2320 | 'status' => 'fatal' |
---|
2321 | )); |
---|
2322 | return; |
---|
2323 | } |
---|
2324 | // print_r($data); |
---|
2325 | // echo '<br><br>'; |
---|
2326 | |
---|
2327 | $replacer = $data['commercialAnd']; |
---|
2328 | unset($data['commercialAnd']); |
---|
2329 | if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"')) |
---|
2330 | { |
---|
2331 | echo serialize(array( |
---|
2332 | 'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'), |
---|
2333 | 'status' => 'fatal' |
---|
2334 | )); |
---|
2335 | |
---|
2336 | return; |
---|
2337 | } |
---|
2338 | |
---|
2339 | if ($data['id_contact']) |
---|
2340 | { |
---|
2341 | $id = $data['id_contact']; |
---|
2342 | $id_photo = $id; |
---|
2343 | unset($data['id_contact']); |
---|
2344 | } |
---|
2345 | else |
---|
2346 | { |
---|
2347 | $id_photo = '_new_'; |
---|
2348 | } |
---|
2349 | |
---|
2350 | /* |
---|
2351 | * Process Photo, if available |
---|
2352 | */ |
---|
2353 | $sleep_count = 0; |
---|
2354 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
2355 | while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y') |
---|
2356 | { |
---|
2357 | sleep(1); |
---|
2358 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
2359 | $sleep_count++; |
---|
2360 | |
---|
2361 | if ($sleep_count > 35) |
---|
2362 | { |
---|
2363 | // TODO |
---|
2364 | return; |
---|
2365 | } |
---|
2366 | } |
---|
2367 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n')); |
---|
2368 | |
---|
2369 | if (isset($this->page_info['photos'][$id_photo])) |
---|
2370 | { |
---|
2371 | if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false) |
---|
2372 | { |
---|
2373 | echo serialize(array( |
---|
2374 | 'msg' => $this->page_info['photos'][$id_photo]['msg'], |
---|
2375 | 'status' => $this->page_info['photos'][$id_photo]['status'] |
---|
2376 | )); |
---|
2377 | |
---|
2378 | return; |
---|
2379 | } |
---|
2380 | |
---|
2381 | $data['photo'] = $this->page_info['photos'][$id_photo]['content']; |
---|
2382 | unset($this->page_info['photos'][$id_photo]); |
---|
2383 | $this->save_session(); |
---|
2384 | } |
---|
2385 | |
---|
2386 | /* |
---|
2387 | * Arrange Date so it gets inserted correctly |
---|
2388 | */ |
---|
2389 | |
---|
2390 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
2391 | |
---|
2392 | $j = 0; |
---|
2393 | for ($i = 0; $i < 5; $i+=2) |
---|
2394 | { |
---|
2395 | switch($dateformat{$i}) |
---|
2396 | { |
---|
2397 | case 'Y': |
---|
2398 | $date[$j]['size'] = 4; |
---|
2399 | $date[$j]['digit'] = 'Y'; |
---|
2400 | break; |
---|
2401 | |
---|
2402 | case 'm': |
---|
2403 | case 'M': |
---|
2404 | $date[$j]['size'] = 2; |
---|
2405 | $date[$j]['digit'] = 'M'; |
---|
2406 | break; |
---|
2407 | |
---|
2408 | case 'd': |
---|
2409 | $date[$j]['size'] = 2; |
---|
2410 | $date[$j]['digit'] = 'D'; |
---|
2411 | } |
---|
2412 | $j++; |
---|
2413 | } |
---|
2414 | $datecount = 0; |
---|
2415 | |
---|
2416 | /* Verify Data and performs insertion/update */ |
---|
2417 | foreach($data as $field => $value) |
---|
2418 | { |
---|
2419 | $dataConn = $data['connections']; |
---|
2420 | $aa = count($dataConn); |
---|
2421 | |
---|
2422 | for($i = 0; $i < $aa; $i++ ) |
---|
2423 | { |
---|
2424 | if($dataConn['connection'.$i]['connection_is_default'] == "TRUE") |
---|
2425 | { |
---|
2426 | $email = $dataConn['connection'.$i]['connection_value']; |
---|
2427 | } |
---|
2428 | } |
---|
2429 | |
---|
2430 | switch($field) |
---|
2431 | { |
---|
2432 | case 'names_ordered': |
---|
2433 | $data[$field] = addslashes(rawurldecode($value)); |
---|
2434 | case 'corporate_name': |
---|
2435 | case 'job_title': |
---|
2436 | case 'department': |
---|
2437 | case 'web_page': |
---|
2438 | case 'alias': |
---|
2439 | case 'given_names': |
---|
2440 | case 'family_names': |
---|
2441 | case 'pgp_key': |
---|
2442 | case 'notes': |
---|
2443 | $data[$field] = addslashes(rawurldecode($data[$field])); |
---|
2444 | break; |
---|
2445 | |
---|
2446 | case 'id_status': |
---|
2447 | case 'id_prefix': |
---|
2448 | case 'id_suffix': |
---|
2449 | if ($data[$field] == 0) |
---|
2450 | { |
---|
2451 | unset($data[$field]); |
---|
2452 | } |
---|
2453 | break; |
---|
2454 | |
---|
2455 | case 'birthdate_0': |
---|
2456 | case 'birthdate_1': |
---|
2457 | case 'birthdate_2': |
---|
2458 | case 'birthdate': |
---|
2459 | |
---|
2460 | if($field == 'birthdate'){ |
---|
2461 | $array_birth = explode("/",$data[$field]); |
---|
2462 | $date['value'][2] = $array_birth[2]; |
---|
2463 | $date['value'][1] = $array_birth[1]; |
---|
2464 | $date['value'][0] = $array_birth[0]; |
---|
2465 | }else{ |
---|
2466 | switch($date[$datecount]['digit']) |
---|
2467 | { |
---|
2468 | case 'Y': |
---|
2469 | $date['value'][2] = (int) $data[$field]; |
---|
2470 | break; |
---|
2471 | |
---|
2472 | case 'M': |
---|
2473 | $date['value'][0] = (int) $data[$field]; |
---|
2474 | break; |
---|
2475 | |
---|
2476 | case 'D': |
---|
2477 | $date['value'][1] = (int) $data[$field]; |
---|
2478 | break; |
---|
2479 | } |
---|
2480 | unset($data[$field]); |
---|
2481 | } |
---|
2482 | |
---|
2483 | $datecount++; |
---|
2484 | |
---|
2485 | if ($datecount != 3) |
---|
2486 | { |
---|
2487 | break; |
---|
2488 | } |
---|
2489 | |
---|
2490 | if($date['value'][0] =='' && $date['value'][1] =='' && $date['value'][2] ==''){ |
---|
2491 | $data['birthdate'] = null; |
---|
2492 | break; |
---|
2493 | } |
---|
2494 | if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2])) |
---|
2495 | { |
---|
2496 | echo serialize(array( |
---|
2497 | 'msg' => lang('Invalid Date'), |
---|
2498 | 'status' => 'invalid_data' |
---|
2499 | )); |
---|
2500 | return; |
---|
2501 | } |
---|
2502 | if( $date['value'][2] != "" && $date['value'][0] != "" && $date['value'][1] != ""){ |
---|
2503 | $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1]; |
---|
2504 | } |
---|
2505 | break; |
---|
2506 | |
---|
2507 | case 'sex': |
---|
2508 | if ($data[$field] !== 'M' and $data[$field] !== 'F') |
---|
2509 | { |
---|
2510 | echo serialize(array( |
---|
2511 | 'msg' => lang('Invalid Sex'), |
---|
2512 | 'status' => 'invalid_data' |
---|
2513 | )); |
---|
2514 | return; |
---|
2515 | } |
---|
2516 | break; |
---|
2517 | |
---|
2518 | |
---|
2519 | case 'addresses': |
---|
2520 | /* Insert new cities/states */ |
---|
2521 | if (isset($value['new_states'])) |
---|
2522 | { |
---|
2523 | foreach($value['new_states'] as $type => $state_info) |
---|
2524 | { |
---|
2525 | $index = 'address'.$type; |
---|
2526 | |
---|
2527 | $id_state = $this->bo->catalog->add_state($state_info); |
---|
2528 | $data['addresses'][$index]['id_state'] = $id_state; |
---|
2529 | |
---|
2530 | if ($value['new_cities'][$type]) |
---|
2531 | { |
---|
2532 | $data[$field]['new_cities'][$type]['id_state'] = $id_state; |
---|
2533 | } |
---|
2534 | } |
---|
2535 | |
---|
2536 | unset($data['addresses']['new_states']); |
---|
2537 | } |
---|
2538 | |
---|
2539 | if (isset($value['new_cities'])) |
---|
2540 | { |
---|
2541 | foreach($value['new_cities'] as $type => $city_info) |
---|
2542 | { |
---|
2543 | $index = 'address'.$type; |
---|
2544 | |
---|
2545 | $id_city = $this->bo->catalog->add_city($city_info); |
---|
2546 | $data['addresses'][$index]['id_city'] = $id_city; |
---|
2547 | } |
---|
2548 | |
---|
2549 | unset($data['addresses']['new_cities']); |
---|
2550 | } |
---|
2551 | |
---|
2552 | break; |
---|
2553 | |
---|
2554 | case 'birthdate': |
---|
2555 | case 'connections': |
---|
2556 | case 'photo': |
---|
2557 | /* Does nothing... */ |
---|
2558 | break; |
---|
2559 | case 'groups': |
---|
2560 | $groups = $data['groups']; |
---|
2561 | unset($data['groups']); |
---|
2562 | break; |
---|
2563 | default: |
---|
2564 | echo serialize(array( |
---|
2565 | 'msg' => lang('Invalid field: ').$field, |
---|
2566 | 'status' => 'invalid_data' |
---|
2567 | )); |
---|
2568 | return; |
---|
2569 | } |
---|
2570 | } |
---|
2571 | |
---|
2572 | if (!is_null($id) and $id !== '') |
---|
2573 | { |
---|
2574 | $id = $this->bo->catalog->update_single_info($id, $data); |
---|
2575 | $result = array( |
---|
2576 | 'msg' => lang('Updated Successfully!'), |
---|
2577 | 'status' => 'ok' |
---|
2578 | ); |
---|
2579 | } |
---|
2580 | else |
---|
2581 | { |
---|
2582 | $id = $this->bo->catalog->add_single_entry($data); |
---|
2583 | $result = array( |
---|
2584 | 'msg' => lang('Entry Added Successfully!'), |
---|
2585 | 'status' => 'ok' |
---|
2586 | ); |
---|
2587 | } |
---|
2588 | |
---|
2589 | if (!($id)) |
---|
2590 | { |
---|
2591 | $result = array( |
---|
2592 | 'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'. |
---|
2593 | 'Report the problem to the Administrator.'), |
---|
2594 | 'status' => 'fail' |
---|
2595 | ); |
---|
2596 | } |
---|
2597 | else |
---|
2598 | { |
---|
2599 | if (isset($old_connections)) |
---|
2600 | $this->bo->catalog->update_contact_groups($id, $groups, $old_connections); |
---|
2601 | else |
---|
2602 | $this->bo->catalog->update_contact_groups($id, $groups); |
---|
2603 | } |
---|
2604 | |
---|
2605 | echo serialize($result); |
---|
2606 | } |
---|
2607 | |
---|
2608 | |
---|
2609 | function post_full_add_shared() |
---|
2610 | { |
---|
2611 | $data = $_POST['data']; |
---|
2612 | // Exceptions!!! utf8 special chars. |
---|
2613 | $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data); |
---|
2614 | $data = unserialize(str_replace('\\"', '"', $data)); |
---|
2615 | $this -> bo -> catalog = CreateObject('contactcenter.bo_shared_people_manager'); |
---|
2616 | |
---|
2617 | if (!is_array($data)) |
---|
2618 | { |
---|
2619 | echo serialize(array( |
---|
2620 | 'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'. |
---|
2621 | 'Please go to eGroupWare Bug Reporting page and report this bug.<br>'. |
---|
2622 | 'Sorry for the inconvenient!<br><br>'. |
---|
2623 | '<b><i>ContactCenter Developer Team</i></b></p>'), |
---|
2624 | 'status' => 'fatal' |
---|
2625 | )); |
---|
2626 | return; |
---|
2627 | } |
---|
2628 | // print_r($data); |
---|
2629 | // echo '<br><br>'; |
---|
2630 | |
---|
2631 | $replacer = $data['commercialAnd']; |
---|
2632 | unset($data['commercialAnd']); |
---|
2633 | if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"')) |
---|
2634 | { |
---|
2635 | echo serialize(array( |
---|
2636 | 'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'), |
---|
2637 | 'status' => 'fatal' |
---|
2638 | )); |
---|
2639 | |
---|
2640 | return; |
---|
2641 | } |
---|
2642 | |
---|
2643 | if ($data['id_contact']) |
---|
2644 | { |
---|
2645 | $id = $data['id_contact']; |
---|
2646 | $id_photo = $id; |
---|
2647 | unset($data['id_contact']); |
---|
2648 | } |
---|
2649 | else |
---|
2650 | { |
---|
2651 | $id_photo = '_new_'; |
---|
2652 | } |
---|
2653 | |
---|
2654 | if ($data['owner']) |
---|
2655 | { |
---|
2656 | $owner = $data['owner']; |
---|
2657 | unset($data['owner']); |
---|
2658 | } |
---|
2659 | /* |
---|
2660 | * Process Photo, if available |
---|
2661 | */ |
---|
2662 | $sleep_count = 0; |
---|
2663 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
2664 | while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y') |
---|
2665 | { |
---|
2666 | sleep(1); |
---|
2667 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
2668 | $sleep_count++; |
---|
2669 | |
---|
2670 | if ($sleep_count > 35) |
---|
2671 | { |
---|
2672 | // TODO |
---|
2673 | return; |
---|
2674 | } |
---|
2675 | } |
---|
2676 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n')); |
---|
2677 | |
---|
2678 | if (isset($this->page_info['photos'][$id_photo])) |
---|
2679 | { |
---|
2680 | if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false) |
---|
2681 | { |
---|
2682 | echo serialize(array( |
---|
2683 | 'msg' => $this->page_info['photos'][$id_photo]['msg'], |
---|
2684 | 'status' => $this->page_info['photos'][$id_photo]['status'] |
---|
2685 | )); |
---|
2686 | |
---|
2687 | return; |
---|
2688 | } |
---|
2689 | |
---|
2690 | $data['photo'] = $this->page_info['photos'][$id_photo]['content']; |
---|
2691 | unset($this->page_info['photos'][$id_photo]); |
---|
2692 | $this->save_session(); |
---|
2693 | } |
---|
2694 | |
---|
2695 | /* |
---|
2696 | * Arrange Date so it gets inserted correctly |
---|
2697 | */ |
---|
2698 | |
---|
2699 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
2700 | |
---|
2701 | $j = 0; |
---|
2702 | for ($i = 0; $i < 5; $i+=2) |
---|
2703 | { |
---|
2704 | switch($dateformat{$i}) |
---|
2705 | { |
---|
2706 | case 'Y': |
---|
2707 | $date[$j]['size'] = 4; |
---|
2708 | $date[$j]['digit'] = 'Y'; |
---|
2709 | break; |
---|
2710 | |
---|
2711 | case 'm': |
---|
2712 | case 'M': |
---|
2713 | $date[$j]['size'] = 2; |
---|
2714 | $date[$j]['digit'] = 'M'; |
---|
2715 | break; |
---|
2716 | |
---|
2717 | case 'd': |
---|
2718 | $date[$j]['size'] = 2; |
---|
2719 | $date[$j]['digit'] = 'D'; |
---|
2720 | } |
---|
2721 | $j++; |
---|
2722 | } |
---|
2723 | $datecount = 0; |
---|
2724 | |
---|
2725 | /* Verify Data and performs insertion/update */ |
---|
2726 | foreach($data as $field => &$value) |
---|
2727 | { |
---|
2728 | |
---|
2729 | $dataConn = $data['connections']; |
---|
2730 | $aa = count($dataConn); |
---|
2731 | |
---|
2732 | for($i = 0; $i < $aa; $i++ ) |
---|
2733 | { |
---|
2734 | if($dataConn['connection'.$i]['connection_is_default'] == "TRUE") |
---|
2735 | { |
---|
2736 | $email = $dataConn['connection'.$i]['connection_value']; |
---|
2737 | } |
---|
2738 | } |
---|
2739 | |
---|
2740 | if ($value == '' or is_null($value)) |
---|
2741 | { |
---|
2742 | unset($data[$field]); |
---|
2743 | continue; |
---|
2744 | } |
---|
2745 | |
---|
2746 | switch($field) |
---|
2747 | { |
---|
2748 | case 'corporate_name': |
---|
2749 | case 'job_title': |
---|
2750 | case 'department': |
---|
2751 | case 'web_page': |
---|
2752 | case 'alias': |
---|
2753 | case 'given_names': |
---|
2754 | case 'family_names': |
---|
2755 | case 'groups': |
---|
2756 | $groups = $data['groups']; |
---|
2757 | unset($data['groups']); |
---|
2758 | break; |
---|
2759 | case 'names_ordered': |
---|
2760 | case 'pgp_key': |
---|
2761 | case 'notes': |
---|
2762 | case 'photo': |
---|
2763 | $data[$field] = urldecode( $value ); |
---|
2764 | break; |
---|
2765 | |
---|
2766 | case 'id_status': |
---|
2767 | case 'id_prefix': |
---|
2768 | case 'id_suffix': |
---|
2769 | if ($data[$field] == 0) |
---|
2770 | { |
---|
2771 | unset($data[$field]); |
---|
2772 | } |
---|
2773 | break; |
---|
2774 | |
---|
2775 | case 'birthdate_0': |
---|
2776 | case 'birthdate_1': |
---|
2777 | case 'birthdate_2': |
---|
2778 | |
---|
2779 | switch($date[$datecount]['digit']) |
---|
2780 | { |
---|
2781 | case 'Y': |
---|
2782 | $date['value'][2] = (int) $data[$field]; |
---|
2783 | break; |
---|
2784 | |
---|
2785 | case 'M': |
---|
2786 | $date['value'][0] = (int) $data[$field]; |
---|
2787 | break; |
---|
2788 | |
---|
2789 | case 'D': |
---|
2790 | $date['value'][1] = (int) $data[$field]; |
---|
2791 | break; |
---|
2792 | } |
---|
2793 | unset($data[$field]); |
---|
2794 | $datecount++; |
---|
2795 | |
---|
2796 | if ($datecount != 3) |
---|
2797 | { |
---|
2798 | break; |
---|
2799 | } |
---|
2800 | |
---|
2801 | if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2])) |
---|
2802 | { |
---|
2803 | echo serialize(array( |
---|
2804 | 'msg' => lang('Invalid Date'), |
---|
2805 | 'status' => 'invalid_data' |
---|
2806 | )); |
---|
2807 | return; |
---|
2808 | } |
---|
2809 | |
---|
2810 | $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1]; |
---|
2811 | break; |
---|
2812 | |
---|
2813 | case 'sex': |
---|
2814 | if ($data[$field] !== 'M' and $data[$field] !== 'F') |
---|
2815 | { |
---|
2816 | echo serialize(array( |
---|
2817 | 'msg' => lang('Invalid Sex'), |
---|
2818 | 'status' => 'invalid_data' |
---|
2819 | )); |
---|
2820 | return; |
---|
2821 | } |
---|
2822 | break; |
---|
2823 | |
---|
2824 | |
---|
2825 | case 'addresses': |
---|
2826 | /* Insert new cities/states */ |
---|
2827 | if (isset($value['new_states'])) |
---|
2828 | { |
---|
2829 | foreach($value['new_states'] as $type => $state_info) |
---|
2830 | { |
---|
2831 | $index = 'address'.$type; |
---|
2832 | |
---|
2833 | $id_state = $this->bo->catalog->add_state($state_info); |
---|
2834 | $data['addresses'][$index]['id_state'] = $id_state; |
---|
2835 | |
---|
2836 | if ($value['new_cities'][$type]) |
---|
2837 | { |
---|
2838 | $value['new_cities'][$type]['id_state'] = $id_state; |
---|
2839 | } |
---|
2840 | } |
---|
2841 | |
---|
2842 | unset($data['addresses']['new_states']); |
---|
2843 | } |
---|
2844 | |
---|
2845 | if (isset($value['new_cities'])) |
---|
2846 | { |
---|
2847 | foreach($value['new_cities'] as $type => $city_info) |
---|
2848 | { |
---|
2849 | $index = 'address'.$type; |
---|
2850 | |
---|
2851 | $id_city = $this->bo->catalog->add_city($city_info); |
---|
2852 | $data['addresses'][$index]['id_city'] = $id_city; |
---|
2853 | } |
---|
2854 | |
---|
2855 | unset($data['addresses']['new_cities']); |
---|
2856 | } |
---|
2857 | |
---|
2858 | break; |
---|
2859 | |
---|
2860 | case 'connections': |
---|
2861 | /* Does nothing... */ |
---|
2862 | $aaaa = 1111; |
---|
2863 | break; |
---|
2864 | |
---|
2865 | default: |
---|
2866 | echo serialize(array( |
---|
2867 | 'msg' => lang('Invalid field: ').$field, |
---|
2868 | 'status' => 'invalid_data' |
---|
2869 | )); |
---|
2870 | return; |
---|
2871 | } |
---|
2872 | } |
---|
2873 | |
---|
2874 | //$code = '$id = $this->bo->catalog->'; |
---|
2875 | |
---|
2876 | if (!is_null($id) and $id !== '') |
---|
2877 | { |
---|
2878 | //$code .= $code.'update_single_info($id, $data);'; |
---|
2879 | $id = $this->bo->catalog->update_single_info($id, $data); |
---|
2880 | if(!$id){ |
---|
2881 | $result = array( |
---|
2882 | 'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'. |
---|
2883 | 'Report the problem to the Administrator.'), |
---|
2884 | 'status' => 'fail' |
---|
2885 | ); |
---|
2886 | } |
---|
2887 | else{ |
---|
2888 | $result = array( |
---|
2889 | 'msg' => lang('Updated Successfully!'), |
---|
2890 | 'status' => 'ok' |
---|
2891 | ); |
---|
2892 | } |
---|
2893 | } |
---|
2894 | else |
---|
2895 | { |
---|
2896 | //$code .= 'add_single_entry($data,'.$owner.');'; |
---|
2897 | $id = $this->bo->catalog->add_single_entry($data,$owner); |
---|
2898 | if(!$id){ |
---|
2899 | $result = array( |
---|
2900 | 'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'. |
---|
2901 | 'Report the problem to the Administrator.'), |
---|
2902 | 'status' => 'fail' |
---|
2903 | ); |
---|
2904 | } |
---|
2905 | else{ |
---|
2906 | $result = array( |
---|
2907 | 'msg' => lang('Entry Added Successfully!'), |
---|
2908 | 'status' => 'ok' |
---|
2909 | ); |
---|
2910 | } |
---|
2911 | } |
---|
2912 | echo serialize($result); |
---|
2913 | } |
---|
2914 | /*! |
---|
2915 | |
---|
2916 | @function post_photo |
---|
2917 | @abstract Wrapper to post a photo without reload a page. |
---|
2918 | @author Raphael Derosso Pereira |
---|
2919 | |
---|
2920 | */ |
---|
2921 | function post_photo($id) |
---|
2922 | { |
---|
2923 | //print_r($_FILES); |
---|
2924 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y')); |
---|
2925 | |
---|
2926 | if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo'])) |
---|
2927 | { |
---|
2928 | $this->page_info['photos'][$id]['status'] = 'no_upload'; |
---|
2929 | $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.'); |
---|
2930 | |
---|
2931 | $this->save_session(); |
---|
2932 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2933 | return; |
---|
2934 | } |
---|
2935 | |
---|
2936 | if (!function_exists('imagecreate')) |
---|
2937 | { |
---|
2938 | $this->page_info['photos'][$id]['status'] = 'no_GD_lib'; |
---|
2939 | $this->page_info['photos'][$id]['msg'] = lang('Cannot manipulate Image. No Image added. Please, if you want to use images, ask the Administrator to install GD library.'); |
---|
2940 | |
---|
2941 | $this->save_session(); |
---|
2942 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2943 | return; |
---|
2944 | } |
---|
2945 | |
---|
2946 | // TODO: Get Max Size from preferences! |
---|
2947 | if ($_FILES['cc_pd_photo']['size'] > 1000000) |
---|
2948 | { |
---|
2949 | $this->page_info['photos'][$id]['status'] = 'too_large'; |
---|
2950 | $this->page_info['photos'][$id]['msg'] = lang('Image too large! ContactCenter limits the image size to 1 Mb'); |
---|
2951 | |
---|
2952 | $this->save_session(); |
---|
2953 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2954 | return; |
---|
2955 | } |
---|
2956 | |
---|
2957 | if ($_FILES['cc_pd_photo']['error']) |
---|
2958 | { |
---|
2959 | $this->page_info['photos'][$id]['status'] = 'error'; |
---|
2960 | $this->page_info['photos'][$id]['msg'] = lang('Some Error occured while processed the Image. Contact the Administrator. The error code was: ').$_FILES['cc_pd_photo']['error']; |
---|
2961 | |
---|
2962 | $this->save_session(); |
---|
2963 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2964 | return; |
---|
2965 | } |
---|
2966 | |
---|
2967 | switch($_FILES['cc_pd_photo']['type']) |
---|
2968 | { |
---|
2969 | case 'image/jpeg': |
---|
2970 | case 'image/pjpeg': |
---|
2971 | $src_img = imagecreatefromjpeg($_FILES['cc_pd_photo']['tmp_name']); |
---|
2972 | if ($src_img == '') |
---|
2973 | { |
---|
2974 | $bogus = true; |
---|
2975 | } |
---|
2976 | break; |
---|
2977 | |
---|
2978 | case 'image/png': |
---|
2979 | case 'image/x-png': |
---|
2980 | $src_img = imagecreatefrompng($_FILES['cc_pd_photo']['tmp_name']); |
---|
2981 | if ($src_img == '') |
---|
2982 | { |
---|
2983 | $bogus = true; |
---|
2984 | } |
---|
2985 | break; |
---|
2986 | |
---|
2987 | case 'image/gif': |
---|
2988 | $src_img = imagecreatefromgif($_FILES['cc_pd_photo']['tmp_name']); |
---|
2989 | if ($src_img == '') |
---|
2990 | { |
---|
2991 | $bogus = true; |
---|
2992 | } |
---|
2993 | break; |
---|
2994 | |
---|
2995 | default: |
---|
2996 | |
---|
2997 | $this->page_info['photos'][$id]['status'] = 'invalid_image'; |
---|
2998 | $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.'); |
---|
2999 | |
---|
3000 | $this->save_session(); |
---|
3001 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
3002 | return; |
---|
3003 | } |
---|
3004 | |
---|
3005 | if ($bogus) |
---|
3006 | { |
---|
3007 | $this->page_info['photos'][$id]['status'] = 'invalid_file'; |
---|
3008 | $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); |
---|
3009 | |
---|
3010 | $this->save_session(); |
---|
3011 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
3012 | return; |
---|
3013 | } |
---|
3014 | |
---|
3015 | $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']); |
---|
3016 | $dst_img = imagecreatetruecolor(60, 80); |
---|
3017 | |
---|
3018 | if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1])) |
---|
3019 | { |
---|
3020 | $this->page_info['photos'][$id]['status'] = 'invalid_file'; |
---|
3021 | $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); |
---|
3022 | |
---|
3023 | $this->save_session(); |
---|
3024 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
3025 | return; |
---|
3026 | } |
---|
3027 | |
---|
3028 | ob_start(); |
---|
3029 | imagepng($dst_img); |
---|
3030 | $this->page_info['photos'][$id]['content'] = ob_get_contents(); |
---|
3031 | ob_end_clean(); |
---|
3032 | |
---|
3033 | $this->page_info['photos'][$id]['status'] = 'changed'; |
---|
3034 | $this->page_info['photos'][$id]['msg'] = lang('Photo Successfully Updated!'); |
---|
3035 | |
---|
3036 | $this->save_session(); |
---|
3037 | |
---|
3038 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
3039 | |
---|
3040 | imagedestroy($src_img); |
---|
3041 | imagedestroy($dst_img); |
---|
3042 | echo 'ok'; |
---|
3043 | return; |
---|
3044 | } |
---|
3045 | |
---|
3046 | |
---|
3047 | /*! |
---|
3048 | |
---|
3049 | @function get_photo |
---|
3050 | @abstract Returns the photo to the browser |
---|
3051 | @author Raphael Derosso Pereira |
---|
3052 | |
---|
3053 | */ |
---|
3054 | function get_photo($id) |
---|
3055 | { |
---|
3056 | $fields = $this->bo->catalog->get_fields(false); |
---|
3057 | $fields['photo'] = true; |
---|
3058 | |
---|
3059 | $contact = $this->bo->catalog->get_single_entry($id, $fields); |
---|
3060 | |
---|
3061 | if (!$contact['photo']) |
---|
3062 | { |
---|
3063 | header('Content-type: image/png'); |
---|
3064 | echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png'); |
---|
3065 | return; |
---|
3066 | } |
---|
3067 | |
---|
3068 | header('Content-type: image/jpeg'); |
---|
3069 | $photo = imagecreatefromstring ($contact['photo']); |
---|
3070 | $width = imagesx($photo); |
---|
3071 | $height = imagesy($photo); |
---|
3072 | $twidth = 70; |
---|
3073 | $theight = 90; |
---|
3074 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
3075 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
3076 | imagejpeg($small_photo,"",100); |
---|
3077 | return; |
---|
3078 | } |
---|
3079 | |
---|
3080 | /*! |
---|
3081 | |
---|
3082 | @function get_states |
---|
3083 | @abstract Echos a serialized array containing all the states for the given country |
---|
3084 | @author Raphael Derosso Pereira |
---|
3085 | |
---|
3086 | @params $id_country The ID of the Country that contains the requested states |
---|
3087 | |
---|
3088 | */ |
---|
3089 | function get_states($id_country) |
---|
3090 | { |
---|
3091 | $states = $this->bo->catalog->get_all_states($id_country); |
---|
3092 | |
---|
3093 | if (!$states) |
---|
3094 | { |
---|
3095 | $result = array( |
---|
3096 | 'msg' => lang('No States found for this Country.'), |
---|
3097 | 'status' => 'empty' |
---|
3098 | ); |
---|
3099 | |
---|
3100 | echo serialize($result); |
---|
3101 | return; |
---|
3102 | } |
---|
3103 | |
---|
3104 | $result = array( |
---|
3105 | 'msg' => lang('States Successfully retrieved!'), |
---|
3106 | 'status' => 'ok' |
---|
3107 | ); |
---|
3108 | |
---|
3109 | foreach ($states as $state_info) |
---|
3110 | { |
---|
3111 | $result['data'][$state_info['id_state']] = $state_info['name']; |
---|
3112 | |
---|
3113 | if ($state_info['symbol']) |
---|
3114 | { |
---|
3115 | $result['data'][$state_info['id_state']] .= ', '.$state_info['symbol']; |
---|
3116 | } |
---|
3117 | } |
---|
3118 | |
---|
3119 | echo serialize($result); |
---|
3120 | } |
---|
3121 | |
---|
3122 | /*! |
---|
3123 | |
---|
3124 | @function get_cities |
---|
3125 | @abstract Echos a serialized array containing all the cities of a given state |
---|
3126 | @author Raphael Derosso Pereira |
---|
3127 | |
---|
3128 | @param $id_country The ID of the Country that has the specified Cities (in case the |
---|
3129 | Country doesn't have any States) |
---|
3130 | @param $id_state The ID of the State that has the Cities requested |
---|
3131 | |
---|
3132 | */ |
---|
3133 | function get_cities($id_country, $id_state=false) |
---|
3134 | { |
---|
3135 | $cities = $this->bo->catalog->get_all_cities($id_country, $id_state); |
---|
3136 | |
---|
3137 | if (!$cities) |
---|
3138 | { |
---|
3139 | $result = array( |
---|
3140 | 'msg' => lang('No Cities found for this State.'), |
---|
3141 | 'status' => 'empty' |
---|
3142 | ); |
---|
3143 | |
---|
3144 | echo serialize($result); |
---|
3145 | return; |
---|
3146 | } |
---|
3147 | |
---|
3148 | $result = array( |
---|
3149 | 'msg' => lang('Cities Successfully retrieved!'), |
---|
3150 | 'status' => 'ok' |
---|
3151 | ); |
---|
3152 | |
---|
3153 | foreach ($cities as $city_info) |
---|
3154 | { |
---|
3155 | $result['data'][$city_info['id_city']] = $city_info['name']; |
---|
3156 | } |
---|
3157 | |
---|
3158 | echo serialize($result); |
---|
3159 | } |
---|
3160 | |
---|
3161 | //Traduz o campo na busca completa por entradas no catálogo do usuário. |
---|
3162 | function aux_full_search ($field,$isldap) { |
---|
3163 | $retorno = ''; |
---|
3164 | if($isldap) { |
---|
3165 | switch($field) { |
---|
3166 | case 'mail': |
---|
3167 | $retorno = 'contact.connection.mail'; |
---|
3168 | break; |
---|
3169 | case 'phone': |
---|
3170 | $retorno = 'contact.connection.phone'; |
---|
3171 | break; |
---|
3172 | } |
---|
3173 | } |
---|
3174 | else { |
---|
3175 | switch($field) { |
---|
3176 | case 'corporate': |
---|
3177 | $retorno = 'contact.corporate_name'; |
---|
3178 | break; |
---|
3179 | case 'mail': |
---|
3180 | case 'phone': |
---|
3181 | $retorno = 'contact.contact_connection.connection.connection_value'; |
---|
3182 | break; |
---|
3183 | } |
---|
3184 | } |
---|
3185 | return $retorno; |
---|
3186 | } |
---|
3187 | |
---|
3188 | /*! |
---|
3189 | |
---|
3190 | @function search |
---|
3191 | @abstract Echos a serialized array containing the IDs |
---|
3192 | of the entries that matches the search argument |
---|
3193 | @author Raphael Derosso Pereira |
---|
3194 | @author Mário César Kolling (external catalogs) |
---|
3195 | |
---|
3196 | @param string $str_data A serialized array with two informations: |
---|
3197 | $data = array( |
---|
3198 | 'search_for' => (string), |
---|
3199 | 'recursive' => (boolean), |
---|
3200 | ); |
---|
3201 | |
---|
3202 | */ |
---|
3203 | // SERPRO |
---|
3204 | function search($str_data) |
---|
3205 | { |
---|
3206 | $data = unserialize($str_data); |
---|
3207 | // It's an external catalog? |
---|
3208 | $external = $this->bo->is_external($this->page_info['actual_catalog']); |
---|
3209 | $full_search = isset($data['full_search'])?$data['full_search']:false; |
---|
3210 | |
---|
3211 | if (!is_array($data) || (!$data['search_for'] && !$full_search) || !is_array($data['fields'])) |
---|
3212 | { |
---|
3213 | // echo serialize(array( |
---|
3214 | // 'msg' => lang('Invalid parameters'), |
---|
3215 | // 'status' => 'abort' |
---|
3216 | // )); |
---|
3217 | |
---|
3218 | // return array('error' => lang('Invalid parameters')); |
---|
3219 | $rules = array( |
---|
3220 | 0 => array( |
---|
3221 | 'field' => $data['fields']['search'], |
---|
3222 | 'type' => 'LIKE', |
---|
3223 | 'value' => '%' |
---|
3224 | ) |
---|
3225 | ); |
---|
3226 | } |
---|
3227 | |
---|
3228 | |
---|
3229 | /* |
---|
3230 | * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly |
---|
3231 | */ |
---|
3232 | // Support search parameters with accentuation |
---|
3233 | if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && |
---|
3234 | /**rev 104**/ |
---|
3235 | //$this->page_info['actual_catalog']['class'] != 'bo_group_manager') |
---|
3236 | $this->page_info['actual_catalog']['class'] != 'bo_group_manager' && |
---|
3237 | $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && |
---|
3238 | $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
3239 | /****/ |
---|
3240 | { |
---|
3241 | |
---|
3242 | $data['search_for'] = $data['search_for']; |
---|
3243 | } |
---|
3244 | |
---|
3245 | $rules = array(); |
---|
3246 | |
---|
3247 | if ($data['search_for'] === '*') |
---|
3248 | { |
---|
3249 | $rules = array( |
---|
3250 | 0 => array( |
---|
3251 | 'field' => $data['fields']['search'], |
---|
3252 | 'type' => 'LIKE', |
---|
3253 | 'value' => '%' |
---|
3254 | ) |
---|
3255 | ); |
---|
3256 | } |
---|
3257 | else |
---|
3258 | { |
---|
3259 | $names = explode(' ', $data['search_for']); |
---|
3260 | |
---|
3261 | if (!is_array($names)) |
---|
3262 | { |
---|
3263 | if(!$full_search) { |
---|
3264 | echo serialize(array( |
---|
3265 | 'msg' => lang('Invalid Search Parameter'), |
---|
3266 | 'status' => 'abort' |
---|
3267 | )); |
---|
3268 | exit; |
---|
3269 | } |
---|
3270 | else |
---|
3271 | $names = array(); |
---|
3272 | |
---|
3273 | } |
---|
3274 | |
---|
3275 | if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && |
---|
3276 | /**rev 104**/ |
---|
3277 | //$this->page_info['actual_catalog']['class'] != 'bo_group_manager') |
---|
3278 | $this->page_info['actual_catalog']['class'] != 'bo_group_manager' && |
---|
3279 | $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && |
---|
3280 | $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager' ) |
---|
3281 | /*****/ |
---|
3282 | { |
---|
3283 | /* |
---|
3284 | * Restrict the returned contacts search to objectClass = phpgwAccount, |
---|
3285 | * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1 |
---|
3286 | */ |
---|
3287 | |
---|
3288 | $rules = array( |
---|
3289 | 0 => array( |
---|
3290 | 'field' => 'contact.object_class', |
---|
3291 | 'type' => '=', |
---|
3292 | 'value' => 'phpgwAccount' |
---|
3293 | ), |
---|
3294 | 1 => array( |
---|
3295 | 'field' => 'contact.account_status', |
---|
3296 | 'type' => 'iLIKE', |
---|
3297 | 'value' => '%' |
---|
3298 | ), |
---|
3299 | /**rev 104**/ |
---|
3300 | /// |
---|
3301 | //1 => array( |
---|
3302 | 2 => array( |
---|
3303 | /*****/ |
---|
3304 | 'field' => 'contact.account_visible', |
---|
3305 | 'type' => '!=', |
---|
3306 | 'value' => '-1' |
---|
3307 | /**rev 104**/ |
---|
3308 | /* ), |
---|
3309 | 2 => array( |
---|
3310 | 'field' => 'contact.object_class', |
---|
3311 | 'type' => '=', |
---|
3312 | 'value' => 'inetOrgPerson' |
---|
3313 | /****/ |
---|
3314 | ), |
---|
3315 | ); |
---|
3316 | |
---|
3317 | if($full_search) { |
---|
3318 | foreach($full_search as $field => $value) { |
---|
3319 | if(trim($value)!='') |
---|
3320 | array_push($rules,array( |
---|
3321 | 'field' => $this->aux_full_search($field,true), |
---|
3322 | 'type' => 'LIKE', |
---|
3323 | 'value' => '*'.$value.'*' |
---|
3324 | )); |
---|
3325 | } |
---|
3326 | } |
---|
3327 | |
---|
3328 | } |
---|
3329 | else if(!$external && $full_search) { |
---|
3330 | |
---|
3331 | foreach($full_search as $field => $value) { |
---|
3332 | if(trim($value)!='') |
---|
3333 | array_push($rules,array( |
---|
3334 | 'field' => $this->aux_full_search($field,false), |
---|
3335 | 'type' => 'iLIKE', |
---|
3336 | 'value' => '%'.$value.'%' |
---|
3337 | )); |
---|
3338 | } |
---|
3339 | |
---|
3340 | } |
---|
3341 | |
---|
3342 | foreach ($names as $name) |
---|
3343 | { |
---|
3344 | if ($name != '') |
---|
3345 | { |
---|
3346 | array_push($rules, array( |
---|
3347 | 'field' => $data['fields']['search'], |
---|
3348 | //'type' => 'iLIKE', |
---|
3349 | //'value' => '%'.$name.'%' |
---|
3350 | 'type' => 'LIKE and ~=', |
---|
3351 | 'value' => $name |
---|
3352 | )); |
---|
3353 | } |
---|
3354 | } |
---|
3355 | } |
---|
3356 | |
---|
3357 | if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' || |
---|
3358 | /**rev 104**/ |
---|
3359 | //$this->page_info['actual_catalog']['class'] == 'bo_group_manager') |
---|
3360 | $this->page_info['actual_catalog']['class'] == 'bo_group_manager' || |
---|
3361 | $this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager' || |
---|
3362 | $this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager') |
---|
3363 | |
---|
3364 | |
---|
3365 | /***/ |
---|
3366 | { |
---|
3367 | // Get only this attributes: dn, cn for external catalogs, |
---|
3368 | // used to restrict the attributes used in filters |
---|
3369 | $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC', 'customFilter' => $data['custom_filter'], 'CN' => $data['CN'], 'exact' => $data['exact']), $data['search_for'] != null); } |
---|
3370 | else |
---|
3371 | { |
---|
3372 | // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible |
---|
3373 | // for non-external catalogs, used to restrict the attributes used in filters |
---|
3374 | $ids = $this->bo->find(array( |
---|
3375 | $data['fields']['id'], |
---|
3376 | $data['fields']['search'], |
---|
3377 | 'contact.object_class', |
---|
3378 | //'contact.account_status', |
---|
3379 | 'contact.account_visible', |
---|
3380 | 'contact.connection.mail', |
---|
3381 | 'contact.connection.phone' |
---|
3382 | ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC', 'customFilter' => $data['custom_filter'], 'CN' => $data['CN'], 'exact' => $data['exact']), $data['search_for_area'], $data['search_for'] != null ); } |
---|
3383 | |
---|
3384 | if (!is_array($ids) || !count($ids)) |
---|
3385 | { |
---|
3386 | $this->last_search_ids = null; |
---|
3387 | $this->save_session(); |
---|
3388 | return null; |
---|
3389 | } |
---|
3390 | |
---|
3391 | $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1); |
---|
3392 | |
---|
3393 | $ids_f = array(); |
---|
3394 | |
---|
3395 | foreach ($ids as $e_info) |
---|
3396 | { |
---|
3397 | /**rev 104**/ |
---|
3398 | //$ids_f[] = $e_info[$id_field]; |
---|
3399 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
3400 | { |
---|
3401 | $ids_f[] = $e_info[$id_field]; |
---|
3402 | } else{ |
---|
3403 | $ids_f[] = array(0=>$e_info[$id_field],1=>$e_info['perms'],2=>$e_info['owner']); |
---|
3404 | } |
---|
3405 | /****/ |
---|
3406 | } |
---|
3407 | |
---|
3408 | return $ids_f; |
---|
3409 | } |
---|
3410 | |
---|
3411 | // CELEPAR |
---|
3412 | /* |
---|
3413 | function search($str_data) |
---|
3414 | { |
---|
3415 | $data = unserialize($str_data); |
---|
3416 | |
---|
3417 | if (!is_array($data) || !$data['search_for'] || !is_array($data['fields'])) |
---|
3418 | { |
---|
3419 | echo serialize(array( |
---|
3420 | 'msg' => lang('Invalid parameters'), |
---|
3421 | 'status' => 'abort' |
---|
3422 | )); |
---|
3423 | |
---|
3424 | return; |
---|
3425 | } |
---|
3426 | |
---|
3427 | $rules = array(); |
---|
3428 | |
---|
3429 | if ($data['search_for'] === '*') |
---|
3430 | { |
---|
3431 | $rules = array( |
---|
3432 | 0 => array( |
---|
3433 | 'field' => $data['fields']['search'], |
---|
3434 | 'type' => 'LIKE', |
---|
3435 | 'value' => '%' |
---|
3436 | ) |
---|
3437 | ); |
---|
3438 | } |
---|
3439 | else |
---|
3440 | { |
---|
3441 | $names = explode(' ', $data['search_for']); |
---|
3442 | |
---|
3443 | if (!is_array($names)) |
---|
3444 | { |
---|
3445 | echo serialize(array( |
---|
3446 | 'msg' => lang('Invalid Search Parameter'), |
---|
3447 | 'status' => 'abort' |
---|
3448 | )); |
---|
3449 | |
---|
3450 | return; |
---|
3451 | } |
---|
3452 | |
---|
3453 | foreach ($names as $name) |
---|
3454 | { |
---|
3455 | if ($name != '') |
---|
3456 | { |
---|
3457 | array_push($rules, array( |
---|
3458 | 'field' => $data['fields']['search'], |
---|
3459 | 'type' => 'iLIKE', |
---|
3460 | 'value' => '%'.$name.'%' |
---|
3461 | )); |
---|
3462 | } |
---|
3463 | } |
---|
3464 | } |
---|
3465 | |
---|
3466 | |
---|
3467 | |
---|
3468 | //$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); |
---|
3469 | |
---|
3470 | //if ($catalog['class'] === 'bo_people_catalog') |
---|
3471 | //{ |
---|
3472 | // array_push($rules, array( |
---|
3473 | // 'field' => 'contact.id_owner', |
---|
3474 | // 'type' => '=', |
---|
3475 | // 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
3476 | // )); |
---|
3477 | //} |
---|
3478 | |
---|
3479 | |
---|
3480 | $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
3481 | |
---|
3482 | if (!is_array($ids) || !count($ids)) |
---|
3483 | { |
---|
3484 | echo serialize(array( |
---|
3485 | 'msg' => lang('No Entries Found!'), |
---|
3486 | 'status' => 'empty' |
---|
3487 | )); |
---|
3488 | |
---|
3489 | return; |
---|
3490 | } |
---|
3491 | $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1); |
---|
3492 | |
---|
3493 | $ids_f = array(); |
---|
3494 | foreach ($ids as $e_info) |
---|
3495 | { |
---|
3496 | $ids_f[] = $e_info[$id_field]; |
---|
3497 | } |
---|
3498 | |
---|
3499 | echo serialize(array( |
---|
3500 | 'data' => $ids_f, |
---|
3501 | 'msg' => lang('Found %1 Entries', count($ids)), |
---|
3502 | 'status' => 'ok' |
---|
3503 | )); |
---|
3504 | |
---|
3505 | return; |
---|
3506 | }*/ |
---|
3507 | /*! |
---|
3508 | |
---|
3509 | @function get_multiple_entries |
---|
3510 | @abstract Returns an array containing the specifiend data in the default |
---|
3511 | CC UI format |
---|
3512 | @author Raphael Derosso Pereira |
---|
3513 | |
---|
3514 | @param array str_data A serialized array containing the ID's of the entries |
---|
3515 | to be taken, the fields to be taken and the rules to be used on the |
---|
3516 | retrieval: |
---|
3517 | $data = array( |
---|
3518 | 'ids' => array(...), |
---|
3519 | 'fields' => array(...), |
---|
3520 | 'rules' => array(...) |
---|
3521 | ); |
---|
3522 | |
---|
3523 | */ |
---|
3524 | function get_multiple_entries($str_data) |
---|
3525 | { |
---|
3526 | $data = unserialize($str_data); |
---|
3527 | |
---|
3528 | if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids'])) |
---|
3529 | { |
---|
3530 | return array( |
---|
3531 | 'msg' => lang('Invalid Parameters'), |
---|
3532 | 'status' => 'abort' |
---|
3533 | ); |
---|
3534 | } |
---|
3535 | |
---|
3536 | $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']); |
---|
3537 | |
---|
3538 | if (!is_array($entries) or !count($entries)) |
---|
3539 | { |
---|
3540 | return array( |
---|
3541 | 'msg' => lang('No Entries Found!'), |
---|
3542 | 'status' => 'empty' |
---|
3543 | ); |
---|
3544 | } |
---|
3545 | |
---|
3546 | return array( |
---|
3547 | 'msg' => lang('Found %1 Entries!', count($entries)), |
---|
3548 | 'status' => 'ok', |
---|
3549 | 'data' => $entries |
---|
3550 | ); |
---|
3551 | } |
---|
3552 | |
---|
3553 | /* |
---|
3554 | |
---|
3555 | @function get_all_entries |
---|
3556 | @abstract Returns the specified fields for all catalog's entries |
---|
3557 | in the default CC UI format |
---|
3558 | @author Raphael Derosso Pereira |
---|
3559 | |
---|
3560 | @params array str_data A serialized array containing the fields to |
---|
3561 | be grabbed, the maximum number of entries to be returned and a |
---|
3562 | boolean specifying if the calls refers to a new grab or to an |
---|
3563 | unfinished one. |
---|
3564 | |
---|
3565 | */ |
---|
3566 | function get_all_entries($str_data) |
---|
3567 | { |
---|
3568 | $data = unserialize($str_data); |
---|
3569 | |
---|
3570 | if (!is_array($data) or |
---|
3571 | !count($data) or |
---|
3572 | !count($data['fields']) or |
---|
3573 | !$data['maxlength'] or |
---|
3574 | (!$data['new'] and !$data['offset'])) |
---|
3575 | { |
---|
3576 | return array( |
---|
3577 | 'msg' => lang('Invalid Parameters'), |
---|
3578 | 'status' => 'abort' |
---|
3579 | ); |
---|
3580 | } |
---|
3581 | |
---|
3582 | if ($data['new']) |
---|
3583 | { |
---|
3584 | $this->all_entries = $this->bo->catalog->get_all_entries_ids(); |
---|
3585 | |
---|
3586 | $this->save_session(); |
---|
3587 | |
---|
3588 | if (!is_array($this->all_entries) or !count($this->all_entries)) |
---|
3589 | { |
---|
3590 | return array( |
---|
3591 | 'msg' => lang('No Entries Found!'), |
---|
3592 | 'status' => 'empty' |
---|
3593 | ); |
---|
3594 | } |
---|
3595 | |
---|
3596 | $data['offset'] = 0; |
---|
3597 | } |
---|
3598 | |
---|
3599 | if ($data['maxlength'] != -1) |
---|
3600 | { |
---|
3601 | $result = $this->bo->catalog->get_multiple_entries(array_slice($this->all_entries, $data['offset'], $data['maxlength']), $data['fields']); |
---|
3602 | } |
---|
3603 | else |
---|
3604 | { |
---|
3605 | $result = $this->bo->catalog->get_multiple_entries($this->all_entries, $data['fields']); |
---|
3606 | } |
---|
3607 | |
---|
3608 | $jsCode = array(); |
---|
3609 | $count = 0; |
---|
3610 | foreach ($result as $each) |
---|
3611 | { |
---|
3612 | if (!is_array($each)) |
---|
3613 | { |
---|
3614 | continue; |
---|
3615 | } |
---|
3616 | |
---|
3617 | if($this-> typeContact == 'groups') { |
---|
3618 | |
---|
3619 | foreach ($each as $field => $value) { |
---|
3620 | |
---|
3621 | if ($field === 'title') { |
---|
3622 | $optionName = '\\"'.$value.'\\"'; |
---|
3623 | |
---|
3624 | } |
---|
3625 | else if ($field === 'short_name') { |
---|
3626 | |
---|
3627 | $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");'; |
---|
3628 | $count++; |
---|
3629 | } |
---|
3630 | } |
---|
3631 | } |
---|
3632 | |
---|
3633 | else { |
---|
3634 | foreach ($each as $field => $value) { |
---|
3635 | if ($field === 'names_ordered') { |
---|
3636 | if(is_array($value)) |
---|
3637 | $value = $value[0]; |
---|
3638 | $name = '\\"'.$value.'\\"'; |
---|
3639 | } |
---|
3640 | else if ($field === 'connections') { |
---|
3641 | |
---|
3642 | foreach ($value as $connection) { |
---|
3643 | if ($connection['id_type'] == $this->preferences['personCardEmail']) { |
---|
3644 | $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$name.' <'.$connection['connection_value'].'>", "'.$count.'");'; |
---|
3645 | $count++; |
---|
3646 | } |
---|
3647 | } |
---|
3648 | } |
---|
3649 | } |
---|
3650 | } |
---|
3651 | } |
---|
3652 | |
---|
3653 | $jsCodeFinal = implode("\n", $jsCode); |
---|
3654 | |
---|
3655 | $nEntries = count($result); |
---|
3656 | |
---|
3657 | if (!$nEntries) |
---|
3658 | { |
---|
3659 | return array( |
---|
3660 | 'msg' => lang('Error while getting user information...'), |
---|
3661 | 'status' => 'abort' |
---|
3662 | ); |
---|
3663 | } |
---|
3664 | |
---|
3665 | return array( |
---|
3666 | 'msg' => lang('Found %1 Entries!', $nEntries), |
---|
3667 | 'status' => 'ok', |
---|
3668 | 'typeContact' => $this -> typeContact, |
---|
3669 | 'final' => $nEntries + $data['offset'] < count($this->all_entries) ? false : true, |
---|
3670 | 'offset' => $data['offset'] + $nEntries, |
---|
3671 | 'data' => $jsCodeFinal |
---|
3672 | ); |
---|
3673 | } |
---|
3674 | |
---|
3675 | /*********************************************************************\ |
---|
3676 | * Auxiliar Methods * |
---|
3677 | \*********************************************************************/ |
---|
3678 | |
---|
3679 | /*! |
---|
3680 | |
---|
3681 | @function save_session |
---|
3682 | @abstract Saves the data on the session |
---|
3683 | @author Raphael Derosso Pereira |
---|
3684 | |
---|
3685 | */ |
---|
3686 | function save_session() |
---|
3687 | { |
---|
3688 | $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info); |
---|
3689 | $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries); |
---|
3690 | } |
---|
3691 | |
---|
3692 | /*! |
---|
3693 | |
---|
3694 | @function convert_tree |
---|
3695 | @abstract Converts the tree array in the BO format to a JS tree array compatible |
---|
3696 | with the one available in eGW |
---|
3697 | @author Raphael Derosso Pereira |
---|
3698 | |
---|
3699 | @param (array) $tree The tree in the BO format |
---|
3700 | @param (string) $name The tree name |
---|
3701 | @param (string) $iconDir The dir where the icons are |
---|
3702 | @param (string) $parent The parent |
---|
3703 | */ |
---|
3704 | |
---|
3705 | function convert_tree($tree, &$iconDir, $parent='0') |
---|
3706 | { |
---|
3707 | // echo "Entrou<br>\tPai: $parent <br>"; |
---|
3708 | $rtree = array(); |
---|
3709 | |
---|
3710 | if ($parent === '0') |
---|
3711 | { |
---|
3712 | // echo 'Root!<br>'; |
---|
3713 | $rtree['0'] = array( |
---|
3714 | 'type' => 'catalog_group', |
---|
3715 | 'id' => '0', |
---|
3716 | 'pid' => 'none', |
---|
3717 | 'caption' => lang('Catalogues'), |
---|
3718 | 'class' => 'bo_catalog_group_catalog', |
---|
3719 | 'class_args' => array('_ROOT_', '$this', '$this->get_branch_by_level($this->catalog_level[0])') |
---|
3720 | ); |
---|
3721 | } |
---|
3722 | |
---|
3723 | foreach($tree as $id => $value) |
---|
3724 | { |
---|
3725 | // echo 'ID: '.$id.'<br>'; |
---|
3726 | $rtree[$parent.'.'.$id] = array( |
---|
3727 | 'type' => $value['type'], |
---|
3728 | 'id' => $parent.'.'.$id, |
---|
3729 | 'pid' => $parent, |
---|
3730 | 'caption' => $value['name'] |
---|
3731 | ); |
---|
3732 | |
---|
3733 | switch($value['type']) |
---|
3734 | { |
---|
3735 | case 'catalog_group': |
---|
3736 | case 'mixed_catalog_group': |
---|
3737 | $rtree = $rtree + $this->convert_tree($value['sub_branch'],$iconDir,$parent.'.'.$id); |
---|
3738 | break; |
---|
3739 | } |
---|
3740 | } |
---|
3741 | |
---|
3742 | if (count($rtree)) |
---|
3743 | { |
---|
3744 | return $rtree; |
---|
3745 | } |
---|
3746 | } |
---|
3747 | |
---|
3748 | function get_catalog_add_contact($id, $echo=true){ |
---|
3749 | |
---|
3750 | $array_participants = array(); |
---|
3751 | if(!$this->bo->catalog->src_info) { |
---|
3752 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
3753 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
3754 | } |
---|
3755 | |
---|
3756 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
3757 | $dn=$this->bo->catalog->src_info['dn']; |
---|
3758 | $justThese = array("givenname","givenname","sn","telephonenumber","mail"); |
---|
3759 | $sr = ldap_read($ds,$id, "objectClass=*",$justThese); |
---|
3760 | $info = ldap_get_entries($ds, $sr); |
---|
3761 | for($z = 0; $z < 5; $z++) { |
---|
3762 | $participant = $info[0][$justThese[$z]]; |
---|
3763 | $participant[0] = utf8_decode($participant[0]); |
---|
3764 | array_push($array_participants, $participant); |
---|
3765 | } |
---|
3766 | |
---|
3767 | ldap_close($ds); |
---|
3768 | if ($echo) |
---|
3769 | { |
---|
3770 | echo serialize($array_participants); |
---|
3771 | } |
---|
3772 | else |
---|
3773 | { |
---|
3774 | return serialize($array_participants); |
---|
3775 | } |
---|
3776 | } |
---|
3777 | |
---|
3778 | function get_catalog_participants_group($id) |
---|
3779 | { |
---|
3780 | if(!$this->bo->catalog->src_info) { |
---|
3781 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
3782 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
3783 | } |
---|
3784 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
3785 | $justThese = array("description","memberuid"); |
---|
3786 | $sr = ldap_read($ds,$id, "objectClass=*",$justThese); |
---|
3787 | $info = ldap_get_entries($ds, $sr); |
---|
3788 | $member_uids = $info[0]['memberuid']; |
---|
3789 | $contact['names_ordered'] = $info[0]['description']; |
---|
3790 | $filter = ""; |
---|
3791 | for($z = 0; $z < count($member_uids); $z++) { |
---|
3792 | if($member_uids[$z]) |
---|
3793 | $filter.="(uid=".$member_uids[$z].")"; |
---|
3794 | } |
---|
3795 | $array_participants = array(); |
---|
3796 | if($filter) { |
---|
3797 | $filter = "(|".$filter.")"; |
---|
3798 | $valarray = explode(',',$id); |
---|
3799 | array_shift($valarray); |
---|
3800 | $dn = implode(',',$valarray); |
---|
3801 | $justThese = array("cn","mail"); |
---|
3802 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
3803 | $info = ldap_get_entries($ds, $sr); |
---|
3804 | for($z = 0; $z < $info['count']; $z++) { |
---|
3805 | $participant = '<font color=\'DARKBLUE\'> "'.$info[$z]['cn'][0].'" <'.$info[$z]['mail'][0].'></font><br>'; |
---|
3806 | $array_emails[$info[$z]['mail'][0]] = null; |
---|
3807 | array_push($array_participants, $participant); |
---|
3808 | } |
---|
3809 | ldap_close($ds); |
---|
3810 | } |
---|
3811 | sort($array_participants); |
---|
3812 | $innerHTML = ''; |
---|
3813 | foreach($array_participants as $index => $participant){ |
---|
3814 | $innerHTML .= $participant; |
---|
3815 | } |
---|
3816 | $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); |
---|
3817 | echo serialize($return); |
---|
3818 | } |
---|
3819 | |
---|
3820 | function get_catalog_participants_list($id) |
---|
3821 | { |
---|
3822 | |
---|
3823 | $fields = $this->bo->catalog->get_fields(false); |
---|
3824 | $fields['names_ordered'] = true; |
---|
3825 | $fields['mail_forwarding_address'] = true; |
---|
3826 | $contact = $this->bo->catalog->get_single_entry($id,$fields); |
---|
3827 | |
---|
3828 | $array_participants = array(); |
---|
3829 | $array_emails = array(); |
---|
3830 | |
---|
3831 | $filter = null; |
---|
3832 | for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) { |
---|
3833 | if(strstr($contact['mail_forwarding_address'][$z],'@')) { |
---|
3834 | $filter.="(mail=".$contact['mail_forwarding_address'][$z].")"; |
---|
3835 | $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>"; |
---|
3836 | } |
---|
3837 | else |
---|
3838 | $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>"; |
---|
3839 | } |
---|
3840 | |
---|
3841 | if($filter) { |
---|
3842 | $filter = "(|".$filter.")"; |
---|
3843 | if(!$this->bo->catalog->src_info) { |
---|
3844 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
3845 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
3846 | } |
---|
3847 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
3848 | $dn=$this->bo->catalog->src_info['dn']; |
---|
3849 | $justThese = array("cn","mail"); |
---|
3850 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
3851 | $info = ldap_get_entries($ds, $sr); |
---|
3852 | for($z = 0; $z < $info['count']; $z++) { |
---|
3853 | $participant = '<font color=\'DARKBLUE\'> "'.$info[$z]['cn'][0].'" <'.$info[$z]['mail'][0].'></font><br>'; |
---|
3854 | $array_emails[$info[$z]['mail'][0]] = null; |
---|
3855 | array_push($array_participants, $participant); |
---|
3856 | } |
---|
3857 | |
---|
3858 | foreach($array_emails as $index => $email) |
---|
3859 | if($email) |
---|
3860 | array_push($array_participants, " ".$email."<br>"); |
---|
3861 | |
---|
3862 | ldap_close($ds); |
---|
3863 | } |
---|
3864 | sort($array_participants); |
---|
3865 | $innerHTML = ''; |
---|
3866 | foreach($array_participants as $index => $participant){ |
---|
3867 | $innerHTML .= $participant; |
---|
3868 | } |
---|
3869 | $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); |
---|
3870 | echo serialize($return); |
---|
3871 | } |
---|
3872 | |
---|
3873 | function export_contacts($typeExport){ |
---|
3874 | |
---|
3875 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
3876 | $contacts = $boGroup->get_all_contacts(); |
---|
3877 | $streamBuffer = ''; |
---|
3878 | $stramArray = Array(); |
---|
3879 | |
---|
3880 | if(!count($contacts)) |
---|
3881 | echo null; |
---|
3882 | |
---|
3883 | switch($typeExport) { |
---|
3884 | |
---|
3885 | case 'outlook_en': |
---|
3886 | $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;". |
---|
3887 | "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n"; |
---|
3888 | foreach($contacts as $index => $object){ |
---|
3889 | $streamBuffer.= "\"".$object[ 'names_ordered'] . "\";" |
---|
3890 | . "\"".$object[ 'main-mail' ] . "\";" |
---|
3891 | . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\";" |
---|
3892 | . "\"".$object[ 'mobile' ] . "\";" |
---|
3893 | . "\"".$object[ 'business-pager' ] . "\";" |
---|
3894 | . "\"".$object[ 'corporate_name' ] . "\";" |
---|
3895 | . "\"".$object[ 'job_title' ] . "\";" |
---|
3896 | . "\"".$object[ 'home-phone' ] . "\";" |
---|
3897 | . "\"".$object[ 'home-fax' ] . "\";" |
---|
3898 | . "\"".$object[ 'business-phone' ] . "\";" |
---|
3899 | . "\"".$object[ 'business-fax' ] . "\"\r\n"; |
---|
3900 | } |
---|
3901 | break; |
---|
3902 | |
---|
3903 | case 'outlook_pt-BR': |
---|
3904 | $streamBuffer = "Nome;Apelido;End. de email;Endereço residencial;" |
---|
3905 | ."Cidade do endereço residencial;CEP do endereço residencial;Estado;País/região do endereço residencial;" |
---|
3906 | ."Telefone residencial;Fax residencial;Telefone celular;Página pessoal da Web;Rua do endereço comercial;" |
---|
3907 | ."Cidade do endereço comercial;CEP do endereço comercial;Estado do endereço comercial;" |
---|
3908 | ."País/região do endereço comercial;Página comercial da Web;Telefone comercial;Fax comercial;Pager;Empresa;" |
---|
3909 | ."Cargo;Departamento;End. comercial;Observações\r\n"; |
---|
3910 | |
---|
3911 | foreach($contacts as $index => $object){ |
---|
3912 | $streamBuffer.= "\"".$object[ 'names_ordered'] . "\";" |
---|
3913 | . "\"".$object[ 'alias' ] . "\";" |
---|
3914 | . "\"".$object[ 'main-mail' ] . "\";" |
---|
3915 | . "\"".$object[ 'home-address' ] . "\";" |
---|
3916 | . "\"".$object[ 'home-city_name' ] . "\";" |
---|
3917 | . "\"".$object[ 'home-postal_code' ] . "\";" |
---|
3918 | . "\"".$object[ 'home-state_name' ] . "\";" |
---|
3919 | . "\"".$object[ 'home-id_country' ] . "\";" |
---|
3920 | . "\"".$object[ 'home-phone' ] . "\";" |
---|
3921 | . "\"".$object[ 'home-fax' ] . "\";" |
---|
3922 | . "\"".$object[ 'mobile' ] . "\";" |
---|
3923 | . "\"".$object[ 'web_page' ] . "\";" |
---|
3924 | . "\"".$object[ 'business-address' ] . "\";" |
---|
3925 | . "\"".$object[ 'business-city_name' ] . "\";" |
---|
3926 | . "\"".$object[ 'business-postal_code' ] . "\";" |
---|
3927 | . "\"".$object[ 'business-state_name' ] . "\";" |
---|
3928 | . "\"".$object[ 'business-id_country' ] . "\";" |
---|
3929 | . "\"".$object[ 'web_page' ] . "\";" |
---|
3930 | . "\"".$object[ 'business-phone' ] . "\";" |
---|
3931 | . "\"".$object[ 'business-fax' ] . "\";" |
---|
3932 | . "\"".$object[ 'business-pager' ] . "\";" |
---|
3933 | . "\"".$object[ 'corporate_name' ] . "\";" |
---|
3934 | . "\"".$object[ 'job_title' ] . "\";" |
---|
3935 | . "\"".$object[ 'department' ] . "\";" |
---|
3936 | ."\"\";" |
---|
3937 | . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"\r\n"; |
---|
3938 | } |
---|
3939 | |
---|
3940 | break; |
---|
3941 | |
---|
3942 | case 'outlook2000_pt-BR': |
---|
3943 | $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",". |
---|
3944 | "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",". |
---|
3945 | "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",". |
---|
3946 | "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",". |
---|
3947 | "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",". |
---|
3948 | "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",". |
---|
3949 | "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",". |
---|
3950 | "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",". |
---|
3951 | "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",". |
---|
3952 | "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",". |
---|
3953 | "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",". |
---|
3954 | "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",". |
---|
3955 | "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",". |
---|
3956 | "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",". |
---|
3957 | "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",". |
---|
3958 | "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",". |
---|
3959 | "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",". |
---|
3960 | "\"Sexo\"\r\n"; |
---|
3961 | |
---|
3962 | |
---|
3963 | |
---|
3964 | foreach($contacts as $index => $object){ |
---|
3965 | $streamBuffer .= "\"".$object[ 'alias' ] . "\"," |
---|
3966 | . "\"".$object[ 'names_ordered' ] . "\"," |
---|
3967 | .",,," |
---|
3968 | . "\"".$object[ 'corporate_name' ] . "\"," |
---|
3969 | . "\"".$object[ 'department' ] . "\"," |
---|
3970 | . "\"".$object[ 'job_title' ] . "\"," |
---|
3971 | . "\"".$object[ 'business-address' ] . "\"," |
---|
3972 | . "\"".$object[ 'business-address-2' ] . "\"," |
---|
3973 | ."," |
---|
3974 | . "\"".$object[ 'business-city_name' ] . "\"," |
---|
3975 | . "\"".$object[ 'business-state' ] . "\"," |
---|
3976 | . "\"".$object[ 'business-postal_code' ] . "\"," |
---|
3977 | . "\"".$object[ 'business-id_country' ] . "\"," |
---|
3978 | . "\"".$object[ 'home-address' ] . "\"," |
---|
3979 | . "\"".$object[ 'home-address-2' ] . "\"," |
---|
3980 | ."," |
---|
3981 | . "\"".$object[ 'home-city_name' ] . "\"," |
---|
3982 | . "\"".$object[ 'home-state_name' ] . "\"," |
---|
3983 | . "\"".$object[ 'home-postal_code' ] . "\"," |
---|
3984 | . "\"".$object[ 'home-id_country' ] . "\"," |
---|
3985 | .",,,,,,,," |
---|
3986 | . "\"".$object[ 'business-fax' ] . "\"," |
---|
3987 | . "\"".$object[ 'business-phone' ] . "\"," |
---|
3988 | . "\"".$object[ 'business-mobile' ] . "\"," |
---|
3989 | .",,," |
---|
3990 | . "\"".$object[ 'home-fax' ] . "\"," |
---|
3991 | . "\"".$object[ 'home-phone' ] . "\"," |
---|
3992 | .",," |
---|
3993 | . "\"".$object[ 'mobile' ] . "\"," |
---|
3994 | .",," |
---|
3995 | . "\"".$object[ 'home-pager' ] . "\"," |
---|
3996 | . "\"".$object[ 'business-phone' ] . "\"," |
---|
3997 | .",,," |
---|
3998 | . "\"".$object[ 'birthdate' ] . "\"," |
---|
3999 | . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"," |
---|
4000 | .",,,,,," |
---|
4001 | . "\"".$object[ 'main-mail' ] . "\"," |
---|
4002 | ."," |
---|
4003 | . "\"".$object[ 'alternative-mail' ] . "\"," |
---|
4004 | .",,,,,,,,,,,,,," |
---|
4005 | . "\"".$object[ 'web_page' ] . "\"," |
---|
4006 | .",,,,,,,,,,,," |
---|
4007 | . "\"".$object[ 'sex' ] . "\"\r\n"; |
---|
4008 | } |
---|
4009 | break; |
---|
4010 | |
---|
4011 | case 'outlook2000_en': |
---|
4012 | $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,". |
---|
4013 | "Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,". |
---|
4014 | "Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,". |
---|
4015 | "Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,". |
---|
4016 | "Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,". |
---|
4017 | "Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,". |
---|
4018 | "Account,Anniversary,Assistant's Name,Billing Information,Birthday,Categories,Children,Directory Server,E-mail Address,". |
---|
4019 | "E-mail Type,E-mail Display Name,E-mail 2 Address,E-mail 2 Type,E-mail 2 Display Name,E-mail 3 Address,E-mail 3 Type,E-mail 3 Display Name,". |
---|
4020 | "Gender,Government ID Number,Hobby,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,". |
---|
4021 | "Office Location,Organizational ID Number,PO Box,Priority,Private,Profession,Referred By,Sensitivity,Spouse,User 1,User 2,User 3,User 4,Web Page\r\n"; |
---|
4022 | |
---|
4023 | foreach($contacts as $index => $object) |
---|
4024 | { |
---|
4025 | if( array_key_exists("phone", $object) ) |
---|
4026 | $phone = $object['phone']; |
---|
4027 | else |
---|
4028 | $phone = $object['business-phone']; |
---|
4029 | |
---|
4030 | $streamBuffer.= "\"".$object[ 'alias' ] . "\"," |
---|
4031 | . "\"".$object[ 'names_ordered'] . "\"," |
---|
4032 | .",,," |
---|
4033 | . "\"".$object[ 'corporate_name' ] . "\"," |
---|
4034 | . "\"".$object[ 'department' ] . "\"," |
---|
4035 | . "\"".$object[ 'job_title' ] . "\"," |
---|
4036 | . "\"".$object[ 'business-address' ] . "\"," |
---|
4037 | . "\"".$object[ 'business-address-2' ] . "\"," |
---|
4038 | ."," |
---|
4039 | . "\"".$object[ 'business-city_name' ] . "\"," |
---|
4040 | . "\"".$object[ 'business-state' ] . "\"," |
---|
4041 | . "\"".$object[ 'business-postal_code' ] . "\"," |
---|
4042 | . "\"".$object[ 'business-id_country' ] . "\"," |
---|
4043 | . "\"".$object[ 'home-address' ] . "\"," |
---|
4044 | . "\"".$object[ 'home-address-2' ] . "\"," |
---|
4045 | ."," |
---|
4046 | . "\"".$object[ 'home-city_name' ] . "\"," |
---|
4047 | . "\"".$object[ 'home-state_name' ] . "\"," |
---|
4048 | . "\"".$object[ 'home-postal_code' ] . "\"," |
---|
4049 | . "\"".$object[ 'home-id_country' ] . "\"," |
---|
4050 | .",,,,,,,," |
---|
4051 | . "\"".$object[ 'business-fax' ] . "\"," |
---|
4052 | . "\"".$phone . "\"," |
---|
4053 | . "\"".$object[ 'business-mobile' ] . "\"," |
---|
4054 | .",,," |
---|
4055 | . "\"".$object[ 'home-fax' ] . "\"," |
---|
4056 | . "\"".$object[ 'home-phone' ] . "\"," |
---|
4057 | .",," |
---|
4058 | . "\"".$object[ 'mobile' ] . "\"," |
---|
4059 | .",," |
---|
4060 | . "\"".$object[ 'business-pager' ] . "\"," |
---|
4061 | . "\"".$object[ 'home-pager' ] . "\"," |
---|
4062 | .",,,,,,,," |
---|
4063 | . "\"".$object[ 'birthdate' ] . "\"," |
---|
4064 | .",,," |
---|
4065 | . "\"".$object[ 'main-mail' ] . "\"," |
---|
4066 | .",," |
---|
4067 | . "\"".$object[ 'alternative-mail' ] . "\"," |
---|
4068 | .",,,,,,,,,,,,,,," |
---|
4069 | . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"," |
---|
4070 | .",,,,,,,,,,,,," |
---|
4071 | . "\"".$object[ 'web_page' ] . "\"\r\n"; |
---|
4072 | |
---|
4073 | } |
---|
4074 | break; |
---|
4075 | |
---|
4076 | case 'thunderbird': |
---|
4077 | $streamBuffer = "First Name,Last Name,Display Name,Nickname,Primary Email,Secondary Email," |
---|
4078 | ."Screen Name,Work Phone,Home Phone,Fax Number,Pager Number,Mobile Number,Home Address," |
---|
4079 | ."Home Address 2,Home City,Home State,Home ZipCode,Home Country,Work Address,Work Address 2," |
---|
4080 | ."Work City,Work State,Work ZipCode,Work Country,Job Title,Department,Organization,Web Page 1," |
---|
4081 | ."Web Page 2,Birth Year,Birth Month,Birth Day,Custom 1,Custom 2,Custom 3,Custom 4,Notes,\r\n"; |
---|
4082 | |
---|
4083 | foreach($contacts as $index => $object){ |
---|
4084 | $array_birth = explode("-",$object[ 'birthdate' ]); |
---|
4085 | |
---|
4086 | $stramArray[0] = "\"".$object[ 'names_ordered'] . "\""; |
---|
4087 | $stramArray[1] = ""; |
---|
4088 | $stramArray[2] = "\"".$object[ 'names_ordered'] . "\""; |
---|
4089 | $stramArray[3] = "\"".$object[ 'alias' ] . "\""; |
---|
4090 | $stramArray[4] = "\"".$object[ 'main-mail' ] . "\""; |
---|
4091 | $stramArray[5] = "\"".$object[ 'alternative-mail' ] . "\""; |
---|
4092 | $stramArray[6] = ""; |
---|
4093 | $stramArray[7] = "\"".$object[ 'business-phone' ] . "\""; |
---|
4094 | $stramArray[8] = "\"".$object[ 'home-phone' ] . "\""; |
---|
4095 | $stramArray[9] = "\"".$object[ 'business-fax' ] . "\""; |
---|
4096 | $stramArray[10] = "\"".$object[ 'business-pager' ] . "\""; |
---|
4097 | $stramArray[11] = "\"".$object[ 'mobile' ] . "\""; |
---|
4098 | $stramArray[12] = "\"".$object[ 'home-address' ] . "\""; |
---|
4099 | $stramArray[13] = "\"".$object[ 'home-address-2' ] . "\""; |
---|
4100 | $stramArray[14] = "\"".$object[ 'home-city_name' ] . "\""; |
---|
4101 | $stramArray[15] = "\"".$object[ 'home-state_name' ] . "\""; |
---|
4102 | $stramArray[16] = "\"".$object[ 'home-postal_code' ] . "\""; |
---|
4103 | $stramArray[17] = "\"".$object[ 'home-id_country' ] . "\""; |
---|
4104 | $stramArray[18] = "\"".$object[ 'business-address' ] . "\""; |
---|
4105 | $stramArray[19] = "\"".$object[ 'business-address-2' ] . "\""; |
---|
4106 | $stramArray[20] = "\"".$object[ 'business-city_name' ] . "\""; |
---|
4107 | $stramArray[21] = "\"".$object[ 'business-state_name' ] . "\""; |
---|
4108 | $stramArray[22] = "\"".$object[ 'business-postal_code' ] . "\""; |
---|
4109 | $stramArray[23] = "\"".$object[ 'business-id_country' ] . "\""; |
---|
4110 | $stramArray[24] = "\"".$object[ 'job_title' ] . "\""; |
---|
4111 | $stramArray[25] = "\"".$object[ 'department' ] . "\""; |
---|
4112 | $stramArray[26] = "\"".$object[ 'corporate_name' ] . "\""; |
---|
4113 | $stramArray[27] = ""; |
---|
4114 | $stramArray[28] = ""; |
---|
4115 | $stramArray[29] = "\"".$array_birth[0] . "\""; |
---|
4116 | $stramArray[30] = "\"".$array_birth[1] . "\""; |
---|
4117 | $stramArray[31] = "\"".$array_birth[2] . "\""; |
---|
4118 | $stramArray[32] = ""; |
---|
4119 | $stramArray[33] = ""; |
---|
4120 | $stramArray[34] = ""; |
---|
4121 | $stramArray[35] = ""; |
---|
4122 | $stramArray[36] = ""; |
---|
4123 | $stramArray[37] = "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"\r\n"; |
---|
4124 | |
---|
4125 | if($object[ 'phone' ]){ |
---|
4126 | if(!$object[ 'home-phone' ]) |
---|
4127 | $stramArray[8] = "\"".$object[ 'phone' ]. "\""; |
---|
4128 | else if(!$object[ 'mobile' ]) |
---|
4129 | $stramArray[11] = "\"".$object[ 'phone' ]. "\""; |
---|
4130 | else if(!$object[ 'business-phone' ]) |
---|
4131 | $stramArray[7] = "\"".$object[ 'phone' ]. "\""; |
---|
4132 | } |
---|
4133 | |
---|
4134 | $streamBuffer .= implode("," , $stramArray); |
---|
4135 | } |
---|
4136 | break; |
---|
4137 | |
---|
4138 | case 'expresso': |
---|
4139 | $streamBuffer = 'Nome,Apelido,E-mail Principal,E-mail Alternativo,Celular,' |
---|
4140 | . 'Telefone Comercial,Endereço Comercial,Complemento End. Comercial,CEP Comercial,Cidade End. Comercial,Estado End. Comercial,País End. Comercial,' |
---|
4141 | . 'Telefone Residencial,Endereço Residencial,Complemento End. Residencial,CEP Residencial,Cidade End. Residencial,Estado End. Residencial,País End. Residencial,' |
---|
4142 | . 'Aniversário,Sexo,Assinatura GPG,Notas,Página Web,Empresa,Cargo,Departamento,Fax Comercial,Pager Comercial,Celular Comercial,Fax,Pager,Endereço Comercial 2,Endereço Residencial 2' |
---|
4143 | . "\r\n"; |
---|
4144 | |
---|
4145 | foreach($contacts as $index => $object){ |
---|
4146 | $stramArray[0] = "\"".$object[ 'names_ordered'] . "\""; |
---|
4147 | $stramArray[1] = "\"".$object[ 'alias' ] . "\""; |
---|
4148 | $stramArray[2] = "\"".$object[ 'main-mail' ] . "\""; |
---|
4149 | $stramArray[3] = "\"".$object[ 'alternative-mail' ] . "\""; |
---|
4150 | $stramArray[4] = "\"".$object[ 'mobile' ] . "\""; |
---|
4151 | $stramArray[5] = "\"".$object[ 'business-phone' ] . "\""; |
---|
4152 | $stramArray[6] = "\"".$object[ 'business-address' ] . "\""; |
---|
4153 | $stramArray[7] = "\"".$object[ 'business-complement' ] . "\""; |
---|
4154 | $stramArray[8] = "\"".$object[ 'business-postal_code' ] . "\""; |
---|
4155 | $stramArray[9] = "\"".$object[ 'business-city_name' ] . "\""; |
---|
4156 | $stramArray[10] = "\"".$object[ 'business-state_name' ] . "\""; |
---|
4157 | $stramArray[11] = "\"".$object[ 'business-id_country' ] . "\""; |
---|
4158 | $stramArray[12] = "\"".$object[ 'home-phone' ] . "\""; |
---|
4159 | $stramArray[13] = "\"".$object[ 'home-address' ] . "\""; |
---|
4160 | $stramArray[14] = "\"".$object[ 'home-complement' ] . "\""; |
---|
4161 | $stramArray[15] = "\"".$object[ 'home-postal_code' ] . "\""; |
---|
4162 | $stramArray[16] = "\"".$object[ 'home-city_name' ] . "\""; |
---|
4163 | $stramArray[17] = "\"".$object[ 'home-state_name' ] . "\""; |
---|
4164 | $stramArray[18] = "\"".$object[ 'home-id_country' ] . "\""; |
---|
4165 | $stramArray[19] = "\"".$object[ 'birthdate' ] . "\""; |
---|
4166 | $stramArray[20] = "\"".$object[ 'sex' ] . "\""; |
---|
4167 | $stramArray[21] = "\"".$object[ 'pgp_key' ] . "\""; |
---|
4168 | $stramArray[22] = "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\""; |
---|
4169 | $stramArray[23] = "\"".$object[ 'web_page' ] . "\""; |
---|
4170 | $stramArray[24] = "\"".$object[ 'corporate_name' ] . "\""; |
---|
4171 | $stramArray[25] = "\"".$object[ 'job_title' ] . "\""; |
---|
4172 | $stramArray[26] = "\"".$object[ 'department' ] . "\""; |
---|
4173 | $stramArray[27] = "\"".$object[ 'business-fax' ] . "\""; |
---|
4174 | $stramArray[28] = "\"".$object[ 'business-pager' ] . "\""; |
---|
4175 | $stramArray[29] = "\"".$object[ 'business-mobile' ] . "\""; |
---|
4176 | $stramArray[30] = "\"".$object[ 'home-fax' ] . "\""; |
---|
4177 | $stramArray[31] = "\"".$object[ 'home-pager' ] . "\""; |
---|
4178 | $stramArray[32] = "\"".$object[ 'business-address-2' ] . "\""; |
---|
4179 | $stramArray[33] = "\"".$object[ 'home-address-2' ] . "\"\r\n"; |
---|
4180 | |
---|
4181 | if($object[ 'phone' ]){ |
---|
4182 | if(!$object[ 'home-phone' ]) |
---|
4183 | $stramArray[12] = "\"".$object[ 'phone' ]. "\""; |
---|
4184 | else if(!$object[ 'mobile' ]) |
---|
4185 | $stramArray[4] = "\"".$object[ 'phone' ]. "\""; |
---|
4186 | else if(!$object[ 'business-phone' ]) |
---|
4187 | $stramArray[5] = "\"".$object[ 'phone' ]. "\""; |
---|
4188 | } |
---|
4189 | |
---|
4190 | $streamBuffer .= implode("," , $stramArray); |
---|
4191 | } |
---|
4192 | break; |
---|
4193 | |
---|
4194 | case 'outlook2003': |
---|
4195 | $streamBuffer = "\"Tratamento\",\"Primeiro nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",". |
---|
4196 | "\"Empresa\",\"Departamento\",\"Cargo\",\"Business Street\",\"Rua do endereço comercial 2\",". |
---|
4197 | "\"Rua do endereço comercial 3\",\"Business City\",\"Business State\",". |
---|
4198 | "\"Business Postal Code\",\"Business Country\",\"Endereço residencial\",\"Endereço residencial 2\",". |
---|
4199 | "\"Endereço residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",". |
---|
4200 | "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",". |
---|
4201 | "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",". |
---|
4202 | "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",". |
---|
4203 | "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",". |
---|
4204 | "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Anotações\",\"Birthday\",\"Caixa postal de outro endereço\",\"Caixa postal do endereço comercial\",". |
---|
4205 | "\"Caixa postal do endereço residencial\",\"Categorias\",\"Código da empresa\",\"Código do governo\",\"Conta\",\"Datas especiais\",\"Disponibilidade da internet\",\"E-mail Address\",". |
---|
4206 | "\"Tipo de email\",\"Nome para exibição do email\",\"Endereço de email 2\",". |
---|
4207 | "\"Tipo de email 2\",\"Nome para exibição do email 2\",". |
---|
4208 | "\"Endereço de email 3\",\"Tipo de email 3\",\"Nome para exibição de email 3\",". |
---|
4209 | "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",". |
---|
4210 | "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",". |
---|
4211 | "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",". |
---|
4212 | "\"Sexo\",\"Spouse\"\r\n"; |
---|
4213 | foreach($contacts as $index => $object){ |
---|
4214 | $stramArray[0] = "\"".$object[ 'alias' ] . "\""; |
---|
4215 | $stramArray[1] = "\"".$object[ 'names_ordered'] . "\""; |
---|
4216 | $stramArray[2] = ""; |
---|
4217 | $stramArray[3] = ""; |
---|
4218 | $stramArray[4] = ""; |
---|
4219 | $stramArray[5] = "\"".$object[ 'corporate_name' ] . "\""; |
---|
4220 | $stramArray[6] = "\"".$object[ 'department' ] . "\""; |
---|
4221 | $stramArray[7] = "\"".$object[ 'job_title' ] . "\""; |
---|
4222 | $stramArray[8] = "\"".$object[ 'business-address' ] . "\""; |
---|
4223 | $stramArray[9] = "\"".$object[ 'business-address-2' ] . "\""; |
---|
4224 | $stramArray[10] = ""; |
---|
4225 | $stramArray[11] = "\"".$object[ 'business-city_name' ] . "\""; |
---|
4226 | $stramArray[12] = "\"".$object[ 'business-state_name' ] . "\""; |
---|
4227 | $stramArray[13] = "\"".$object[ 'business-postal_code' ] . "\""; |
---|
4228 | $stramArray[14] = "\"".$object[ 'business-id_country' ] . "\""; |
---|
4229 | $stramArray[15] = "\"".$object[ 'home-address' ] . "\""; |
---|
4230 | $stramArray[16] = "\"".$object[ 'business-address-2' ] . "\""; |
---|
4231 | $stramArray[17] = ""; |
---|
4232 | $stramArray[18] = "\"".$object[ 'home-city_name' ] . "\""; |
---|
4233 | $stramArray[19] = "\"".$object[ 'home-state_name' ] . "\""; |
---|
4234 | $stramArray[20] = "\"".$object[ 'home-postal_code' ] . "\""; |
---|
4235 | $stramArray[21] = "\"".$object[ 'home-id_country' ] . "\""; |
---|
4236 | $stramArray[22] = ""; |
---|
4237 | $stramArray[23] = ""; |
---|
4238 | $stramArray[24] = ""; |
---|
4239 | $stramArray[25] = "\"".$object[ 'home-city_name' ] . "\""; |
---|
4240 | $stramArray[26] = "\"".$object[ 'home-state_name' ] . "\""; |
---|
4241 | $stramArray[27] = "\"".$object[ 'home-postal_code' ] . "\""; |
---|
4242 | $stramArray[28] = "\"".$object[ 'home-id_country' ] . "\""; |
---|
4243 | $stramArray[29] = ""; |
---|
4244 | $stramArray[30] = "\"".$object[ 'business-fax' ] . "\""; |
---|
4245 | $stramArray[31] = "\"".$object[ 'business-phone' ] . "\""; |
---|
4246 | $stramArray[32] = "\"".$object[ 'mobile' ] . "\""; |
---|
4247 | $stramArray[33] = ""; |
---|
4248 | $stramArray[34] = ""; |
---|
4249 | $stramArray[35] = ""; |
---|
4250 | $stramArray[36] = "\"".$object[ 'home-fax' ] . "\""; |
---|
4251 | $stramArray[37] = "\"".$object[ 'home-phone' ] . "\""; |
---|
4252 | $stramArray[38] = ""; |
---|
4253 | $stramArray[39] = ""; |
---|
4254 | $stramArray[40] = "\"".$object[ 'mobile' ] . "\""; |
---|
4255 | $stramArray[41] = ""; |
---|
4256 | $stramArray[42] = ""; |
---|
4257 | $stramArray[43] = "\"".$object[ 'home-pager' ] . "\""; |
---|
4258 | $stramArray[44] = "\"".$object[ 'phone' ] . "\""; |
---|
4259 | $stramArray[45] = ""; |
---|
4260 | $stramArray[46] = ""; |
---|
4261 | $stramArray[47] = ""; |
---|
4262 | $stramArray[48] = "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\""; |
---|
4263 | $stramArray[49] = "\"".$object[ 'birthdate' ] . "\""; |
---|
4264 | $stramArray[50] = ""; |
---|
4265 | $stramArray[51] = ""; |
---|
4266 | $stramArray[52] = ""; |
---|
4267 | $stramArray[53] = ""; |
---|
4268 | $stramArray[54] = ""; |
---|
4269 | $stramArray[55] = ""; |
---|
4270 | $stramArray[56] = ""; |
---|
4271 | $stramArray[57] = ""; |
---|
4272 | $stramArray[58] = ""; |
---|
4273 | $stramArray[59] = "\"".$object[ 'main-mail' ] . "\""; |
---|
4274 | $stramArray[60] = ""; |
---|
4275 | $stramArray[61] = ""; |
---|
4276 | $stramArray[62] = "\"".$object[ 'alternative-mail' ] . "\""; |
---|
4277 | $stramArray[63] = ""; |
---|
4278 | $stramArray[64] = ""; |
---|
4279 | $stramArray[65] = ""; |
---|
4280 | $stramArray[66] = ""; |
---|
4281 | $stramArray[67] = ""; |
---|
4282 | $stramArray[68] = ""; |
---|
4283 | $stramArray[69] = ""; |
---|
4284 | $stramArray[70] = ""; |
---|
4285 | $stramArray[71] = ""; |
---|
4286 | $stramArray[72] = ""; |
---|
4287 | $stramArray[73] = ""; |
---|
4288 | $stramArray[74] = ""; |
---|
4289 | $stramArray[75] = ""; |
---|
4290 | $stramArray[76] = ""; |
---|
4291 | $stramArray[77] = "\"".$object[ 'web_page' ] . "\""; |
---|
4292 | $stramArray[78] = ""; |
---|
4293 | $stramArray[79] = ""; |
---|
4294 | $stramArray[80] = ""; |
---|
4295 | $stramArray[81] = ""; |
---|
4296 | $stramArray[82] = ""; |
---|
4297 | $stramArray[83] = ""; |
---|
4298 | $stramArray[84] = ""; |
---|
4299 | $stramArray[85] = ""; |
---|
4300 | $stramArray[86] = ""; |
---|
4301 | $stramArray[87] = ""; |
---|
4302 | $stramArray[88] = ""; |
---|
4303 | $stramArray[89] = ""; |
---|
4304 | $stramArray[90] = "\"".$object[ 'sex' ] . "\""; |
---|
4305 | $stramArray[91] = "\r\n"; |
---|
4306 | |
---|
4307 | $streamBuffer .= implode("," , $stramArray); |
---|
4308 | } |
---|
4309 | break; |
---|
4310 | |
---|
4311 | } |
---|
4312 | |
---|
4313 | $file = "contacts_".md5(microtime()).".swp"; |
---|
4314 | $tempDir = $GLOBALS['phpgw_info']['server']['temp_dir']; |
---|
4315 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
4316 | if(!$f) |
---|
4317 | echo null; |
---|
4318 | |
---|
4319 | fputs($f,$streamBuffer); |
---|
4320 | fclose($f); |
---|
4321 | |
---|
4322 | echo $tempDir.'/'.$file; |
---|
4323 | } |
---|
4324 | |
---|
4325 | // Get the csv field and put into array, from php.net |
---|
4326 | function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') { |
---|
4327 | $text = trim($input_text); |
---|
4328 | if(is_string($delimiter) && is_string($text_qualifier)) { |
---|
4329 | $re_d = '\x' . dechex(ord($delimiter)); //format for regexp |
---|
4330 | $re_tq = '\x' . dechex(ord($text_qualifier)); //format for regexp |
---|
4331 | |
---|
4332 | $fields = array(); |
---|
4333 | $field_num = 0; |
---|
4334 | while(strlen($text) > 0) { |
---|
4335 | if($text{0} == $text_qualifier) { |
---|
4336 | preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches); |
---|
4337 | |
---|
4338 | $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]); |
---|
4339 | $text = trim($matches[2]); |
---|
4340 | |
---|
4341 | $fields[$field_num++] = $value; |
---|
4342 | } else { |
---|
4343 | preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches); |
---|
4344 | |
---|
4345 | $value = $matches[1]; |
---|
4346 | $text = trim($matches[2]); |
---|
4347 | |
---|
4348 | $fields[$field_num++] = $value; |
---|
4349 | } |
---|
4350 | } |
---|
4351 | return $fields; |
---|
4352 | } else |
---|
4353 | return false; |
---|
4354 | } |
---|
4355 | |
---|
4356 | //funcao alterada para importar outros campos alem de nome, telefone e email, de arquivo csv (Outlook 2000) |
---|
4357 | //em 08/04/2009 - Rommel Cysne (rommel.cysne@serpro.gov.br); |
---|
4358 | //Foi adicionada uma funcao (escapesheelcmd()) nas variaveis para que caracteres especiais sejam ignorados |
---|
4359 | //durante a importacao dos contatos; o processo estava travando por causa de caracteres em campos como nome, |
---|
4360 | //sobrenome, notas e e-mail; |
---|
4361 | //em 19/06/2009 - Rommel Cysne (rommel.cysne@serpro.gov.br); |
---|
4362 | function import_contacts($typeImport, $id_group=false) |
---|
4363 | { |
---|
4364 | $this->so_group = CreateObject('contactcenter.so_group'); |
---|
4365 | if($file = $_SESSION['contactcenter']['importCSV']) |
---|
4366 | { |
---|
4367 | unset($_SESSION['contactcenter']['importCSV']); |
---|
4368 | $len = filesize($file); |
---|
4369 | $count = 0; |
---|
4370 | $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0); |
---|
4371 | $handle = @fopen($file, "r") or die(serialize($return['error'] = true)); |
---|
4372 | |
---|
4373 | $input_header = fgets($handle); |
---|
4374 | if ($typeImport == 'outlook') |
---|
4375 | $delim = ';'; |
---|
4376 | else if ($typeImport == 'auto' || $typeImport== 'thunderbird') |
---|
4377 | $delim = strstr($input_header,',') ? ',' : ';'; |
---|
4378 | else |
---|
4379 | $delim = ','; |
---|
4380 | $csv_header = $this->parse_line($input_header,$delim); |
---|
4381 | $firstContact = fgets($handle); |
---|
4382 | preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv |
---|
4383 | rewind($handle); |
---|
4384 | |
---|
4385 | $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true)); |
---|
4386 | if(count($header) < 2 || count($header) > 100) { |
---|
4387 | $return['error'] = true; |
---|
4388 | $return['sizeheader'] = count($header); |
---|
4389 | echo serialize($return); |
---|
4390 | return; |
---|
4391 | } |
---|
4392 | |
---|
4393 | if ($matches[0][strlen($matches[0])-1] == ';') |
---|
4394 | $delim = ';'; |
---|
4395 | |
---|
4396 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
4397 | $boPeople = CreateObject('contactcenter.bo_people_catalog'); |
---|
4398 | switch($typeImport){ |
---|
4399 | case 'outlook2000': |
---|
4400 | $name_pos=1; |
---|
4401 | $name2_pos=2; |
---|
4402 | $name3_pos=3; |
---|
4403 | $corporate_street_pos=8; |
---|
4404 | $cep_pos=13; |
---|
4405 | $corporate_street_2_pos=22; |
---|
4406 | $fax_pos=30; |
---|
4407 | $phone_pos=31; |
---|
4408 | $home_phone_pos=37; |
---|
4409 | $personal_cell_pos=40; |
---|
4410 | $pager_pos=43; |
---|
4411 | $birth_pos=48; |
---|
4412 | $notes_pos=49; |
---|
4413 | $email_pos=56; |
---|
4414 | $aditionalEmail_pos=59; |
---|
4415 | |
---|
4416 | break; |
---|
4417 | case 'outlook': |
---|
4418 | $name_pos=0; |
---|
4419 | $email_pos=2; |
---|
4420 | $phone_pos=8; |
---|
4421 | $home_phone_pos=9; |
---|
4422 | $personal_cell_pos=10; |
---|
4423 | $corporate_street_pos=12; |
---|
4424 | $cep_pos=14; |
---|
4425 | $corporate_phone_pos=18; |
---|
4426 | $fax_pos=19; |
---|
4427 | $pager_pos=20; |
---|
4428 | $notes_pos=25; |
---|
4429 | break; |
---|
4430 | case 'thunderbird': |
---|
4431 | $name_pos=2; |
---|
4432 | $alias_pos=3; |
---|
4433 | //MAILS |
---|
4434 | $email_pos=4; |
---|
4435 | $aditionalEmail_pos=5; |
---|
4436 | |
---|
4437 | //PHONES |
---|
4438 | $corporate_phone_pos=7; |
---|
4439 | $main_phone_pos=8; |
---|
4440 | $home_phone_pos=8; |
---|
4441 | $fax_pos=9; |
---|
4442 | $pager_pos=10; |
---|
4443 | $personal_cell_pos=11; |
---|
4444 | |
---|
4445 | //ADRESS |
---|
4446 | $street_pos=12; |
---|
4447 | $street_2_pos = 13; |
---|
4448 | $city_pos=14; |
---|
4449 | $state_pos=15; |
---|
4450 | $cep_pos=16; |
---|
4451 | $country_pos=17; |
---|
4452 | |
---|
4453 | //CORPORATE ADRESS |
---|
4454 | $corporate_street_pos=18; |
---|
4455 | $corporate_city_pos=20; |
---|
4456 | $corporate_state_pos=21; |
---|
4457 | $corporate_cep_pos=22; |
---|
4458 | $corporate_country_pos=23; |
---|
4459 | |
---|
4460 | //CORPORATE DETAILS |
---|
4461 | $job_title_pos=24; |
---|
4462 | $department_pos=25; |
---|
4463 | $corporate_name_pos=26; |
---|
4464 | |
---|
4465 | $notes_pos=36; |
---|
4466 | break; |
---|
4467 | case 'outlook2003': |
---|
4468 | $alias_pos=0; |
---|
4469 | $name_pos=1; |
---|
4470 | //CORPORATE DETAILS |
---|
4471 | $corporate_name_pos=5; |
---|
4472 | $department_pos=6; |
---|
4473 | $job_title_pos=7; |
---|
4474 | //CORPORATE ADRESS |
---|
4475 | $corporate_comp_pos=7; |
---|
4476 | $corporate_street_pos=8; |
---|
4477 | $street_2_pos = 9; |
---|
4478 | $corporate_city_pos=11; |
---|
4479 | $corporate_state_pos=12; |
---|
4480 | $corporate_cep_pos=13; |
---|
4481 | $corporate_country_pos=14; |
---|
4482 | //HOME ADRESS |
---|
4483 | $street_pos=13; |
---|
4484 | $comp_pos=14; |
---|
4485 | $cep_pos=15; |
---|
4486 | $city_pos=16; |
---|
4487 | $state_pos=17; |
---|
4488 | $country_pos=18; |
---|
4489 | //PHONE's |
---|
4490 | $corporate_phone_pos=31; |
---|
4491 | $fax_pos=36; |
---|
4492 | $home_phone_pos=37; |
---|
4493 | $pager_pos=43; |
---|
4494 | $main_phone_pos=44; |
---|
4495 | //OTHER's |
---|
4496 | $notes_pos=48; |
---|
4497 | $birth_pos=49; |
---|
4498 | //EMAIL's |
---|
4499 | $email_pos=59; |
---|
4500 | $aditionalEmail_pos=62; |
---|
4501 | break; |
---|
4502 | case 'expresso': |
---|
4503 | $name_pos=0; |
---|
4504 | $alias_pos=1; |
---|
4505 | $email_pos=2; |
---|
4506 | $aditionalEmail_pos=3; |
---|
4507 | $personal_cell_pos=4; |
---|
4508 | $corporate_phone_pos=5; |
---|
4509 | $corporate_street_pos=6; |
---|
4510 | $corporate_comp_pos=7; |
---|
4511 | $corporate_cep_pos=8; |
---|
4512 | $corporate_city_pos=9; |
---|
4513 | $corporate_state_pos=10; |
---|
4514 | $corporate_country_pos=11; |
---|
4515 | $home_phone_pos=12; |
---|
4516 | $street_pos=13; |
---|
4517 | $comp_pos=14; |
---|
4518 | $cep_pos=15; |
---|
4519 | $city_pos=16; |
---|
4520 | $state_pos=17; |
---|
4521 | $country_pos=18; |
---|
4522 | $birth_pos=19; |
---|
4523 | $sex_pos = 20; |
---|
4524 | $pgp_key_pos = 21; |
---|
4525 | $notes_pos=22; |
---|
4526 | $web_page_pos=23; |
---|
4527 | $corporate_name_pos=24; |
---|
4528 | $job_title_pos=25; |
---|
4529 | $department_pos=26; |
---|
4530 | $corporate_fax_pos=27; |
---|
4531 | $corporate_pager_pos=28; |
---|
4532 | $corporate_cell_pos=29; |
---|
4533 | $fax_pos=30; |
---|
4534 | $pager_pos=31; |
---|
4535 | $corporate_street_2_pos = 32; |
---|
4536 | $street_2_pos = 33; |
---|
4537 | break; |
---|
4538 | default: |
---|
4539 | foreach($csv_header as $index => $fieldName) |
---|
4540 | { |
---|
4541 | switch($fieldName){ |
---|
4542 | case 'Name': |
---|
4543 | case 'Nome': |
---|
4544 | case 'First Name': |
---|
4545 | $name_pos = $index; |
---|
4546 | break; |
---|
4547 | case 'Second name': |
---|
4548 | case 'Segundo nome': |
---|
4549 | $name2_pos = $index; |
---|
4550 | break; |
---|
4551 | case 'Sobrenome': |
---|
4552 | case 'Surname': |
---|
4553 | $name3_pos = $index; |
---|
4554 | break; |
---|
4555 | case 'Business Street': |
---|
4556 | case 'Rua do endereço comercial': |
---|
4557 | $corporate_street_pos = $index; |
---|
4558 | break; |
---|
4559 | case 'Rua do endereço comercial 2': |
---|
4560 | case 'Outro endereço': |
---|
4561 | $corporate_street_2_pos = $index; |
---|
4562 | break; |
---|
4563 | case 'Business Postal Code': |
---|
4564 | case 'CEP do endereço comercial': |
---|
4565 | $cep_pos = $index; |
---|
4566 | break; |
---|
4567 | case 'Business Fax': |
---|
4568 | case 'Fax comercial': |
---|
4569 | case 'Fax': |
---|
4570 | $fax_pos = $index; |
---|
4571 | break; |
---|
4572 | case 'Home Phone': |
---|
4573 | case 'Telefone residencial': |
---|
4574 | $home_phone_pos = $index; |
---|
4575 | break; |
---|
4576 | case 'Mobile phone': |
---|
4577 | case 'Telefone celular': |
---|
4578 | $personal_cell_pos = $index; |
---|
4579 | break; |
---|
4580 | case 'Pager': |
---|
4581 | $pager_pos = $index; |
---|
4582 | break; |
---|
4583 | case 'Phone': |
---|
4584 | case 'Business Phone': |
---|
4585 | case 'Telefone': |
---|
4586 | case 'Telefone principal': |
---|
4587 | case 'Telefone comercial': |
---|
4588 | case 'Telefone Comercial': |
---|
4589 | $phone_pos = $index; |
---|
4590 | break; |
---|
4591 | case 'Aniversário': |
---|
4592 | case 'Birthdate': |
---|
4593 | $birth_pos = $index; |
---|
4594 | case 'Anotações': |
---|
4595 | case 'Notes': |
---|
4596 | $notes_pos = $index; |
---|
4597 | case 'E-mail': |
---|
4598 | case 'Email': |
---|
4599 | case 'E-mail Address': |
---|
4600 | case 'Endereço de correio eletrônico': |
---|
4601 | case 'End. de email': |
---|
4602 | $email_pos = $index; |
---|
4603 | break; |
---|
4604 | case 'Endereço de correio eletrônico 2': |
---|
4605 | $aditionalEmail_pos = $index; |
---|
4606 | break; |
---|
4607 | } |
---|
4608 | } |
---|
4609 | break; |
---|
4610 | } |
---|
4611 | |
---|
4612 | |
---|
4613 | |
---|
4614 | while (($data = fgetcsv($handle, $len, $delim))) |
---|
4615 | { |
---|
4616 | foreach ($header as $key=>$heading) |
---|
4617 | $row[$heading]=(isset($data[$key])) ? $data[$key] : ''; |
---|
4618 | |
---|
4619 | $sdata = array(); |
---|
4620 | $full_name = addslashes(trim($row[$header[$name_pos]])); |
---|
4621 | $email = addslashes(trim($row[$header[$email_pos]])); |
---|
4622 | $phone = addslashes(trim($row[$header[$main_phone_pos]])); |
---|
4623 | $name2 = addslashes(trim($row[$header[$name2_pos]])); |
---|
4624 | $name3 = addslashes(trim($row[$header[$name3_pos]])); |
---|
4625 | $birth = addslashes(trim($row[$header[$birth_pos]])); |
---|
4626 | $notes = addslashes(trim($row[$header[$notes_pos]])); |
---|
4627 | $altEmail = addslashes(trim($row[$header[$altEmail_pos]])); |
---|
4628 | $sdata['alias'] = addslashes(trim($row[$header[$alias_pos]])); |
---|
4629 | $sdata['corporate_name'] = addslashes(trim($row[$header[$corporate_name_pos]])); |
---|
4630 | $sdata['job_title'] = addslashes(trim($row[$header[$job_title_pos]])); |
---|
4631 | $sdata['department'] = addslashes(trim($row[$header[$department_pos]])); |
---|
4632 | $sdata['web_page'] = addslashes(trim($row[$header[$web_page_pos]])); |
---|
4633 | $sdata['sex'] = addslashes(trim($row[$header[$sex_pos]])); |
---|
4634 | $sdata['pgp_key'] = addslashes(trim($row[$header[$pgp_key_pos]])); |
---|
4635 | |
---|
4636 | $array_name = explode(' ', str_replace('"','',(str_replace('\'','',$full_name)))); |
---|
4637 | $sdata['given_names'] = addslashes($array_name[0]); |
---|
4638 | $array_name[0] = null; |
---|
4639 | $sdata['family_names'] = trim(implode(' ',$array_name)); |
---|
4640 | if($sdata['family_names'] == '') |
---|
4641 | { |
---|
4642 | $sdata['family_names'] = addslashes($name2) . " " . addslashes($name3); |
---|
4643 | } |
---|
4644 | |
---|
4645 | $sdata['connections']['default_email']['connection_name'] = lang('Main'); |
---|
4646 | $sdata['connections']['default_email']['connection_value'] = addslashes($email); |
---|
4647 | $sdata['connections']['aditional_email']['connection_name'] = "Alternativo"; |
---|
4648 | $sdata['connections']['aditional_email']['connection_value'] = trim($row[$header[$aditionalEmail_pos]]); |
---|
4649 | |
---|
4650 | $sdata['connections']['default_phone']['connection_name'] = lang('Main'); |
---|
4651 | $sdata['connections']['default_phone']['connection_value'] = $phone; |
---|
4652 | |
---|
4653 | if( trim($row[$header[$home_phone_pos]]) != "" ) |
---|
4654 | { |
---|
4655 | $sdata['connections']['aditional_phone']['home_phone']['connection_name'] = 'Casa'; |
---|
4656 | $sdata['connections']['aditional_phone']['home_phone']['connection_value'] = trim($row[$header[$home_phone_pos]]); |
---|
4657 | } |
---|
4658 | |
---|
4659 | if( trim($row[$header[$personal_cell_pos]]) != "" ) |
---|
4660 | { |
---|
4661 | $sdata['connections']['aditional_phone']['cellphone']['connection_name'] = 'Celular'; |
---|
4662 | $sdata['connections']['aditional_phone']['cellphone']['connection_value'] = trim($row[$header[$personal_cell_pos]]); |
---|
4663 | } |
---|
4664 | |
---|
4665 | if( trim($row[$header[$corporate_phone_pos]]) != "") |
---|
4666 | { |
---|
4667 | $sdata['connections']['aditional_phone']['corporate_phone']['connection_name'] = 'Trabalho'; |
---|
4668 | $sdata['connections']['aditional_phone']['corporate_phone']['connection_value'] = trim($row[$header[$corporate_phone_pos]]); |
---|
4669 | } |
---|
4670 | |
---|
4671 | if( trim($row[$header[$fax_pos]]) != "" ) |
---|
4672 | { |
---|
4673 | $sdata['connections']['aditional_phone']['fax']['connection_name'] = 'Fax'; |
---|
4674 | $sdata['connections']['aditional_phone']['fax']['connection_value'] = trim($row[$header[$fax_pos]]); |
---|
4675 | } |
---|
4676 | |
---|
4677 | if ($GLOBALS['phpgw_info']['server']['personal_contact_type'] == 'True') |
---|
4678 | { |
---|
4679 | if( trim($row[$header[$pager_pos]]) != "" ) |
---|
4680 | { |
---|
4681 | $sdata['connections']['aditional_phone']['pager']['connection_name'] = 'Pager'; |
---|
4682 | $sdata['connections']['aditional_phone']['pager']['connection_value'] = trim($row[$header[$pager_pos]]); |
---|
4683 | } |
---|
4684 | |
---|
4685 | if( trim($row[$header[$corporate_fax_pos]]) != "" ) |
---|
4686 | { |
---|
4687 | $sdata['connections']['aditional_phone']['corporate_fax']['connection_name'] = 'Fax Corporativo'; |
---|
4688 | $sdata['connections']['aditional_phone']['corporate_fax']['connection_value'] = trim($row[$header[$corporate_fax_pos]]); |
---|
4689 | } |
---|
4690 | |
---|
4691 | if( trim($row[$header[$corporate_cell_pos]]) != "" ) |
---|
4692 | { |
---|
4693 | $sdata['connections']['aditional_phone']['corporate_cell']['connection_name'] = 'Celular Corporativo'; |
---|
4694 | $sdata['connections']['aditional_phone']['corporate_cell']['connection_value'] = trim($row[$header[$corporate_cell_pos]]); |
---|
4695 | } |
---|
4696 | |
---|
4697 | if( trim($row[$header[$corporate_pager_pos]]) != "" ) |
---|
4698 | { |
---|
4699 | $sdata['connections']['aditional_phone']['corporate_pager']['connection_name'] = 'Pager Corporativo'; |
---|
4700 | $sdata['connections']['aditional_phone']['corporate_pager']['connection_value'] = trim($row[$header[$corporate_pager_pos]]); |
---|
4701 | } |
---|
4702 | } |
---|
4703 | |
---|
4704 | $sdata['addresses']['address_corporative']['address1'] = trim($row[$header[$corporate_street_pos]]); |
---|
4705 | $sdata['addresses']['address_corporative']['address2'] = trim($row[$header[$corporate_street_2_pos]]); |
---|
4706 | $sdata['addresses']['address_corporative']['complement'] = trim($row[$header[$corporate_comp_pos]]); |
---|
4707 | $sdata['addresses']['address_corporative']['postal_code'] = trim($row[$header[$corporate_cep_pos]]); |
---|
4708 | $sdata['addresses']['address_corporative']['id_country'] = "BR"; |
---|
4709 | $sdata['addresses']['address_corporative']['id_state'] = trim($row[$header[$corporate_state_pos]]); |
---|
4710 | $sdata['addresses']['address_corporative']['id_city'] = trim($row[$header[$corporate_city_pos]]); |
---|
4711 | |
---|
4712 | |
---|
4713 | $sdata['addresses']['address_personal']['address1'] = trim($row[$header[$street_pos]]); |
---|
4714 | $sdata['addresses']['address_personal']['address2'] = trim($row[$header[$street_2_pos]]); |
---|
4715 | $sdata['addresses']['address_personal']['complement'] = trim($row[$header[$comp_pos]]); |
---|
4716 | $sdata['addresses']['address_personal']['postal_code'] = trim($row[$header[$cep_pos]]); |
---|
4717 | $sdata['addresses']['address_personal']['id_country'] = "BR"; |
---|
4718 | $sdata['addresses']['address_personal']['id_state'] = trim($row[$header[$state_pos]]); |
---|
4719 | $sdata['addresses']['address_personal']['id_city'] = trim($row[$header[$city_pos]]); |
---|
4720 | |
---|
4721 | if(trim($birth)) |
---|
4722 | { |
---|
4723 | $array_birth = explode("/",trim($birth)); |
---|
4724 | $sdata['birthdate'] = date('Y-m-d', mktime(0,0,0,$array_birth[1],$array_birth[0],$array_birth[2])); |
---|
4725 | } |
---|
4726 | |
---|
4727 | $sdata['notes'] = addslashes($notes); |
---|
4728 | //$sdata['is_quick_add'] = true; |
---|
4729 | $sdata['connections']['default_phone']['connection_value'] = $phone; |
---|
4730 | if(!$phone){ |
---|
4731 | |
---|
4732 | } |
---|
4733 | // verifica se email já existe! |
---|
4734 | $email = addslashes($email); |
---|
4735 | $contact = false; |
---|
4736 | $contact = $boGroup->verify_contact($email, $full_name, $phone); |
---|
4737 | if(!$sdata['given_names'] && $email) |
---|
4738 | { |
---|
4739 | $a_email = explode("@",$email); |
---|
4740 | $sdata['given_names'] = addslashes($a_email[0]); |
---|
4741 | } |
---|
4742 | |
---|
4743 | $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new']; |
---|
4744 | |
---|
4745 | if($contact[0] != null) |
---|
4746 | { |
---|
4747 | $return['_existing']++; |
---|
4748 | } |
---|
4749 | else if((!preg_match('/^[a-zA-Z0-9][_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*$/i', $email)) && $email) { |
---|
4750 | $return['_failure']++; |
---|
4751 | $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>"; |
---|
4752 | } |
---|
4753 | else if (!$sdata['given_names'] || !$boPeople ->quick_add($sdata)){ |
---|
4754 | $return['_failure']++; |
---|
4755 | $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>"; |
---|
4756 | } |
---|
4757 | else{ |
---|
4758 | if($id_group != 0){ |
---|
4759 | $this->so_group->add_user_by_name($id_group,$full_name); |
---|
4760 | } |
---|
4761 | $return['_new']++; |
---|
4762 | } |
---|
4763 | } |
---|
4764 | fclose($handle); |
---|
4765 | unlink($file); |
---|
4766 | } |
---|
4767 | else |
---|
4768 | $return['error'] = true; |
---|
4769 | |
---|
4770 | echo serialize($return); |
---|
4771 | } |
---|
4772 | |
---|
4773 | function get_contact_details($id) |
---|
4774 | { |
---|
4775 | $data = array(); |
---|
4776 | |
---|
4777 | if(!$this->bo->catalog->src_info) { |
---|
4778 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
4779 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
4780 | } |
---|
4781 | //$id = urlencode($id); |
---|
4782 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
4783 | $dn=$this->bo->catalog->src_info['dn']; |
---|
4784 | |
---|
4785 | //buscar os atributos do ldap |
---|
4786 | $configobj = CreateObject('phpgwapi.config', 'contactcenter'); |
---|
4787 | $prefs = $configobj->read_repository(); |
---|
4788 | $attr_names = array(); |
---|
4789 | $attr_types = array(); |
---|
4790 | $justThese = array(); |
---|
4791 | foreach ($prefs as $pref_key => $pref_value) |
---|
4792 | { |
---|
4793 | if (stripos($pref_key, "cc_attribute_name_") !== false) |
---|
4794 | { |
---|
4795 | $num = substr($pref_key, strlen("cc_attribute_name_")); |
---|
4796 | $attr_names[] = $prefs["cc_attribute_name_$num"]; |
---|
4797 | $attr_types[] = $prefs["cc_attribute_type_$num"]; |
---|
4798 | $justThese[] = strtolower($prefs["cc_attribute_ldapname_$num"]); |
---|
4799 | } |
---|
4800 | } |
---|
4801 | |
---|
4802 | |
---|
4803 | |
---|
4804 | $sr = ldap_read($ds,utf8_encode($id), "objectClass=*",$justThese); |
---|
4805 | $info = ldap_get_entries($ds, $sr); |
---|
4806 | if ($info) |
---|
4807 | { |
---|
4808 | for ($i = 0; $i < count($justThese); $i++) |
---|
4809 | { |
---|
4810 | $attr = array(); |
---|
4811 | $attr['name'] = $attr_names[$i]; |
---|
4812 | if ($attr_types[$i] == 'multivalues') |
---|
4813 | { |
---|
4814 | $attr['type'] = 'multivalues'; |
---|
4815 | $attr['value'] = array(); |
---|
4816 | for ($j = 0; $j < $info[0][$justThese[$i]]['count']; $j++) |
---|
4817 | $attr['value'][] = utf8_decode($info[0][$justThese[$i]][$j]); |
---|
4818 | } |
---|
4819 | else |
---|
4820 | { |
---|
4821 | $attr['type'] = 'text'; |
---|
4822 | $attr['value'] = utf8_decode($info[0][$justThese[$i]][0]); |
---|
4823 | } |
---|
4824 | $data[] = $attr; |
---|
4825 | } |
---|
4826 | } |
---|
4827 | else |
---|
4828 | $data = 'error'; |
---|
4829 | ldap_close($ds); |
---|
4830 | |
---|
4831 | echo serialize($data); |
---|
4832 | } |
---|
4833 | |
---|
4834 | } |
---|
4835 | |
---|
4836 | ?> |
---|