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