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 $typeContact; |
---|
25 | |
---|
26 | var $page_info = array( |
---|
27 | 'n_cards' => 20, |
---|
28 | 'n_pages' => false, |
---|
29 | 'actual_letter' => 'A', |
---|
30 | 'actual_page' => 1, |
---|
31 | 'actual_entries' => false, |
---|
32 | 'changed' => false, |
---|
33 | 'catalogs' => false, |
---|
34 | 'actual_catalog' => false |
---|
35 | ); |
---|
36 | |
---|
37 | /*! |
---|
38 | |
---|
39 | @function ui_data |
---|
40 | @abstract The constructor. Sets the initial parameters and loads |
---|
41 | the data saved in the session |
---|
42 | @author Raphael Derosso Pereira |
---|
43 | |
---|
44 | */ |
---|
45 | function ui_data() |
---|
46 | { |
---|
47 | $temp = $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter'); |
---|
48 | $temp2 = $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter'); |
---|
49 | |
---|
50 | $this->bo = CreateObject('contactcenter.bo_contactcenter'); |
---|
51 | |
---|
52 | if ($temp) |
---|
53 | { |
---|
54 | $this->page_info = $temp; |
---|
55 | } |
---|
56 | |
---|
57 | if ($temp2) |
---|
58 | { |
---|
59 | $this->all_entries = $temp2; |
---|
60 | } |
---|
61 | |
---|
62 | if (!$this->page_info['actual_catalog']) |
---|
63 | { |
---|
64 | $catalogs = $this->bo->get_catalog_tree(); |
---|
65 | $this->page_info['actual_catalog'] = $catalogs[0]; |
---|
66 | } |
---|
67 | |
---|
68 | $this->page_info['actual_catalog'] =& $this->bo->set_catalog($this->page_info['actual_catalog']); |
---|
69 | |
---|
70 | if($this->page_info['actual_catalog']['class'] == 'bo_group_manager') |
---|
71 | $this -> typeContact = 'groups'; |
---|
72 | else if($this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager') |
---|
73 | $this -> typeContact = 'shared_groups'; |
---|
74 | else if($this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager') |
---|
75 | $this -> typeContact = 'shared_contacts'; |
---|
76 | else |
---|
77 | $this -> typeContact = 'contacts'; |
---|
78 | } |
---|
79 | |
---|
80 | /*! |
---|
81 | |
---|
82 | @function index |
---|
83 | @abstract Builds the Main Page |
---|
84 | @author Raphael Derosso Pereira |
---|
85 | @author Jonas Goes |
---|
86 | |
---|
87 | */ |
---|
88 | function index() |
---|
89 | { |
---|
90 | if(!@is_object($GLOBALS['phpgw']->js)) |
---|
91 | { |
---|
92 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
93 | } |
---|
94 | $GLOBALS['phpgw']->js->validate_file('venus','table'); |
---|
95 | $GLOBALS['phpgw']->js->validate_file('venus','shapes'); |
---|
96 | $GLOBALS['phpgw']->js->validate_file('venus','jsStructUtil'); |
---|
97 | $GLOBALS['phpgw']->js->validate_file('venus','cssUtil'); |
---|
98 | |
---|
99 | // $GLOBALS['phpgw']->js->set_onload('setTimeout(\'updateCards()\',1000)'); |
---|
100 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
101 | |
---|
102 | $GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl')); |
---|
103 | $GLOBALS['phpgw']->template->set_var('cc_root_dir', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/'); |
---|
104 | |
---|
105 | /* Quick Add */ |
---|
106 | $GLOBALS['phpgw']->template->set_var('cc_qa_alias',lang('Alias').':'); |
---|
107 | $GLOBALS['phpgw']->template->set_var('cc_qa_given_names',lang('Given Names').':'); |
---|
108 | $GLOBALS['phpgw']->template->set_var('cc_qa_family_names',lang('Family Names').':'); |
---|
109 | $GLOBALS['phpgw']->template->set_var('cc_qa_phone',lang('Phone').':'); |
---|
110 | $GLOBALS['phpgw']->template->set_var('cc_qa_email',lang('Email').':'); |
---|
111 | $GLOBALS['phpgw']->template->set_var('cc_qa_save',lang('Save')); |
---|
112 | $GLOBALS['phpgw']->template->set_var('cc_qa_clear',lang('Clear')); |
---|
113 | $GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close')); |
---|
114 | /* End Quick Add */ |
---|
115 | |
---|
116 | $cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css'; |
---|
117 | $cc_card_image_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/card.png'; |
---|
118 | $GLOBALS['phpgw']->template->set_var('cc_css',$cc_css_file); |
---|
119 | $GLOBALS['phpgw']->template->set_var('cc_dtree_css', $cc_dtree_file); |
---|
120 | $GLOBALS['phpgw']->template->set_var('cc_card_image',$cc_card_image_file); |
---|
121 | |
---|
122 | $GLOBALS['phpgw']->template->set_var('cc_personal',lang('Personal')); |
---|
123 | |
---|
124 | $GLOBALS['phpgw']->template->set_var('cc_full_add_button',lang('Full Add')); |
---|
125 | $GLOBALS['phpgw']->template->set_var('cc_reset',lang('Reset')); |
---|
126 | |
---|
127 | $GLOBALS['phpgw']->template->set_var('cc_personal_data',lang('Personal Data')); |
---|
128 | $GLOBALS['phpgw']->template->set_var('cc_addresses',lang('Addresses')); |
---|
129 | $GLOBALS['phpgw']->template->set_var('cc_connections',lang('Connections')); |
---|
130 | $GLOBALS['phpgw']->template->set_var('cc_relations',lang('Relations')); |
---|
131 | |
---|
132 | $GLOBALS['phpgw']->template->set_var('cc_quick_add',lang('Quick Add')); |
---|
133 | $GLOBALS['phpgw']->template->set_var('cc_catalogs',lang('Catalogues')); |
---|
134 | $GLOBALS['phpgw']->template->set_var('cc_group_add',lang('Group Add')); |
---|
135 | |
---|
136 | /* Panel */ |
---|
137 | $GLOBALS['phpgw']->template->set_var('cc_panel_new',lang('New').'...'); |
---|
138 | $GLOBALS['phpgw']->template->set_var('cc_panel_search',lang('Search').'...'); |
---|
139 | $GLOBALS['phpgw']->template->set_var('cc_panel_table',lang('Table View')); |
---|
140 | $GLOBALS['phpgw']->template->set_var('cc_panel_cards',lang('Cards View')); |
---|
141 | $GLOBALS['phpgw']->template->set_var('cc_btn_import_export', lang('Import/Export')); |
---|
142 | $GLOBALS['phpgw']->template->set_var('cc_btn_new', lang("New...")); |
---|
143 | |
---|
144 | $GLOBALS['phpgw']->template->set_var('cc_panel_search_found',lang('Showing found entries')); |
---|
145 | $GLOBALS['phpgw']->template->set_var('cc_panel_first_page',lang('First Page')); |
---|
146 | $GLOBALS['phpgw']->template->set_var('cc_panel_previous_page',lang('Previous Page')); |
---|
147 | $GLOBALS['phpgw']->template->set_var('cc_panel_next_page',lang('Next Page')); |
---|
148 | $GLOBALS['phpgw']->template->set_var('cc_panel_last_page',lang('Last Page')); |
---|
149 | $GLOBALS['phpgw']->template->set_var('cc_all',lang('all')); |
---|
150 | /* End Panel */ |
---|
151 | |
---|
152 | /* Messages */ |
---|
153 | $GLOBALS['phpgw']->template->set_var('cc_msg_not_allowed',lang('Not Allowed')); |
---|
154 | $GLOBALS['phpgw']->template->set_var('cc_msg_unavailable',lang('Unavailable function')); |
---|
155 | $GLOBALS['phpgw']->template->set_var('cc_msg_no_cards',lang('No Cards')); |
---|
156 | $GLOBALS['phpgw']->template->set_var('cc_msg_err_no_room',lang('No Room for Cards! Increase your browser area.')); |
---|
157 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_new',lang('New from same Company')); |
---|
158 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_edit',lang('Edit Contact')); |
---|
159 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove',lang('Remove Contact')); |
---|
160 | $GLOBALS['phpgw']->template->set_var('cc_send_mail',lang('Send Mail')); |
---|
161 | $GLOBALS['phpgw']->template->set_var('cc_msg_group_edit',lang('Edit Group')); |
---|
162 | $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove',lang('Remove Group')); |
---|
163 | $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove_confirm',lang('Confirm Removal of this Group?')); |
---|
164 | $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove_confirm',lang('Confirm Removal of this Contact?')); |
---|
165 | $GLOBALS['phpgw']->template->set_var('cc_participants',lang('Participants')); |
---|
166 | $GLOBALS['phpgw']->template->set_var('cc_empty',lang('Empty')); |
---|
167 | /* End Messages */ |
---|
168 | |
---|
169 | $GLOBALS['phpgw']->template->set_var('cc_results',lang('Results')); |
---|
170 | $GLOBALS['phpgw']->template->set_var('cc_is_my',lang('Is My')); |
---|
171 | $GLOBALS['phpgw']->template->set_var('cc_ie_personal',lang('Import/Export pesonal contacts')); |
---|
172 | $GLOBALS['phpgw']->template->set_var('cc_btn_search',lang('Search')); |
---|
173 | $GLOBALS['phpgw']->template->set_var('cc_add_relation',lang('Add Relation')); |
---|
174 | $GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations')); |
---|
175 | $GLOBALS['phpgw']->template->set_var('cc_msg_group',lang('Group')); |
---|
176 | $GLOBALS['phpgw']->template->set_var('cc_msg_contact_full',lang('Contact [Full]')); |
---|
177 | $GLOBALS['phpgw']->template->set_var('cc_msg_contact_qa',lang('Contact [Quick Add]')); |
---|
178 | $GLOBALS['phpgw']->template->set_var('cc_contact_title',lang('Contact Center').' - '.lang('Contacts')); |
---|
179 | $GLOBALS['phpgw']->template->set_var('cc_window_views_title',lang('Contact Center').' - '.lang('Views')); |
---|
180 | $GLOBALS['phpgw']->template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images'); |
---|
181 | |
---|
182 | $GLOBALS['phpgw']->template->set_var('cc_msg_import_contacts', lang('Import Contacts')); |
---|
183 | $GLOBALS['phpgw']->template->set_var('cc_msg_export_contacts', lang('Export Contacts')); |
---|
184 | $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_info_csv', lang('The Expresso supports the contacts importation in the CSV file format.')); |
---|
185 | $GLOBALS['phpgw']->template->set_var('cc_msg_choose_file_type', lang('Select the file type')); |
---|
186 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express', lang('Outlook Express')); |
---|
187 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook2k', lang('Outlook 2000')); |
---|
188 | $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)')); |
---|
189 | $GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:')); |
---|
190 | $GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close')); |
---|
191 | $GLOBALS['phpgw']->template->set_var('cc_msg_close', lang('Close')); |
---|
192 | $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts')); |
---|
193 | $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.')); |
---|
194 | $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...')); |
---|
195 | $GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.')); |
---|
196 | $GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new')); |
---|
197 | $GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed')); |
---|
198 | $GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent')); |
---|
199 | $GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info')); |
---|
200 | $GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean')); |
---|
201 | $GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts')); |
---|
202 | $GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts')); |
---|
203 | $GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic')); |
---|
204 | $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.')); |
---|
205 | $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email')); |
---|
206 | $GLOBALS['phpgw']->template->set_var('cc_msg_main', lang('Main')); |
---|
207 | $GLOBALS['phpgw']->template->set_var('cc_msg_alternative', lang('Alternative')); |
---|
208 | $GLOBALS['phpgw']->template->set_var('cc_msg_select_email', lang('Select E-Mail')); |
---|
209 | $GLOBALS['phpgw']->template->set_var('cc_msg_new_phone', lang('New Telephone')); |
---|
210 | $GLOBALS['phpgw']->template->set_var('cc_msg_home', lang('Home')); |
---|
211 | $GLOBALS['phpgw']->template->set_var('cc_msg_cellphone', lang('Cellphone')); |
---|
212 | $GLOBALS['phpgw']->template->set_var('cc_msg_work', lang('Work')); |
---|
213 | $GLOBALS['phpgw']->template->set_var('cc_msg_fax', lang('Fax')); |
---|
214 | $GLOBALS['phpgw']->template->set_var('cc_msg_pager', lang('Pager')); |
---|
215 | $GLOBALS['phpgw']->template->set_var('cc_msg_choose_phone', lang('Select the telephone')); |
---|
216 | $GLOBALS['phpgw']->template->set_var('cc_msg_warn_firefox', lang('Warning: Too old version of Firefox')); |
---|
217 | $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half1', lang('For this application work correctly</u>')); |
---|
218 | $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')); |
---|
219 | $GLOBALS['phpgw']->template->set_var('cc_msg_click_close', lang('click Close')); |
---|
220 | $GLOBALS['phpgw']->template->set_var('cc_msg_install_now', lang('Install Now')); |
---|
221 | $GLOBALS['phpgw']->template->set_var('cc_msg_install_new_firefox', lang('Install a new Firefox version')); |
---|
222 | $GLOBALS['phpgw']->template->set_var('cc_msg_moz_thunderbird', lang('Export as Mozilla Thunderbird CSV.')); |
---|
223 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_pt', lang('Export as Outlook Express (Portuguese) CSV.')); |
---|
224 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_en', lang('Export as Outlook Express (English) CSV.')); |
---|
225 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_pt', lang('Export as Outlook 2000 (Portuguese) CSV.')); |
---|
226 | $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_en', lang('Export as Outlook 2000 (English) CSV.')); |
---|
227 | $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default_csv', lang('Export as Expresso (Default) CSV.')); |
---|
228 | $GLOBALS['phpgw']->template->set_var('cc_msg_copy_to_catalog', lang('Copy to personal catalog.')); |
---|
229 | $GLOBALS['phpgw']->template->set_var('cc_msg_add_contact_to_group', lang('You did not add any contact for this group.')); |
---|
230 | $GLOBALS['phpgw']->template->set_var('cc_msg_fill_field_name', lang('Fill the field Full Name')); |
---|
231 | |
---|
232 | $GLOBALS['phpgw']->template->parse('out','index'); |
---|
233 | |
---|
234 | $api = CreateObject('contactcenter.ui_api'); |
---|
235 | $main = $api->get_full_add(); |
---|
236 | $main .= $api->get_search_obj(); |
---|
237 | $main .= $api->get_quick_add_plugin(); |
---|
238 | $main .= $api->get_add_group(); |
---|
239 | $main .= $GLOBALS['phpgw']->template->get_var('out'); |
---|
240 | |
---|
241 | echo $main; |
---|
242 | } |
---|
243 | |
---|
244 | |
---|
245 | /*! |
---|
246 | |
---|
247 | @function data_manager |
---|
248 | @abstract Calls the right method and passes to it the right |
---|
249 | parameters |
---|
250 | @author Raphael Derosso Pereira |
---|
251 | |
---|
252 | */ |
---|
253 | function data_manager() |
---|
254 | { |
---|
255 | switch($_GET['method']) |
---|
256 | { |
---|
257 | /* Cards Methods */ |
---|
258 | case 'set_n_cards': |
---|
259 | return $this->set_n_cards((int)$_GET['ncards']); |
---|
260 | |
---|
261 | case 'get_cards_data': |
---|
262 | $ids = false; |
---|
263 | // To support ldap catalogs using accentuation |
---|
264 | if ($_POST['letter'] == 'search' && isset($_POST['data'])) |
---|
265 | { |
---|
266 | $ids = utf8_decode($this->search($_POST['data'])); |
---|
267 | } |
---|
268 | |
---|
269 | if(isset($_SESSION['ids'])) |
---|
270 | $ids = $_SESSION['ids']; |
---|
271 | |
---|
272 | return $this->get_cards_data($_POST['letter'], $_POST['page'], $ids); |
---|
273 | case 'get_cards_data_get': |
---|
274 | return $this->get_cards_data($_GET['letter'], $_GET['page'], unserialize(str_replace('\\"','"',$_GET['ids']))); |
---|
275 | |
---|
276 | |
---|
277 | case 'get_photo': |
---|
278 | return $this->get_photo($_GET['id']); |
---|
279 | |
---|
280 | case 'get_visible_all_ldap': |
---|
281 | echo $this->get_visible_all_ldap(); |
---|
282 | return; |
---|
283 | |
---|
284 | /* Catalog Methods */ |
---|
285 | case 'set_catalog': |
---|
286 | return $this->set_catalog($_GET['catalog']); |
---|
287 | |
---|
288 | case 'get_catalog_tree': |
---|
289 | echo serialize($this->get_catalog_tree($_GET['level'])); |
---|
290 | return; |
---|
291 | |
---|
292 | case 'get_actual_catalog': |
---|
293 | echo serialize($this->get_actual_catalog()); |
---|
294 | return; |
---|
295 | |
---|
296 | case 'get_catalog_participants_list': |
---|
297 | echo serialize($this->get_catalog_participants_list($_POST['id'])); |
---|
298 | return; |
---|
299 | |
---|
300 | case 'get_catalog_participants_group': |
---|
301 | echo serialize($this->get_catalog_participants_group($_POST['id'])); |
---|
302 | return; |
---|
303 | |
---|
304 | case 'get_catalog_add_contact': |
---|
305 | // To support ldap catalogs with accentuation |
---|
306 | echo serialize($this->get_catalog_add_contact(utf8_decode($_POST['id']))); |
---|
307 | return; |
---|
308 | |
---|
309 | /* Full Add Methods */ |
---|
310 | case 'get_full_data': |
---|
311 | return $this->get_full_data($_GET['id'],$_GET['catalog']); |
---|
312 | |
---|
313 | case 'get_group': |
---|
314 | return $this->get_group_data($_GET['id']); |
---|
315 | |
---|
316 | case 'get_contact_full_add_const': |
---|
317 | return $this->get_contact_full_add_const(); |
---|
318 | |
---|
319 | case 'post_full_add': |
---|
320 | return $this->post_full_add(); |
---|
321 | |
---|
322 | case 'post_photo': |
---|
323 | return $this->post_photo((int) $_GET['id'] ? (int) $_GET['id'] : '_new_'); |
---|
324 | |
---|
325 | case 'get_states': |
---|
326 | return $this->get_states($_GET['country']); |
---|
327 | |
---|
328 | case 'get_cities': |
---|
329 | return $this->get_cities($_GET['country'], $_GET['state'] ? $_GET['state'] : null); |
---|
330 | |
---|
331 | |
---|
332 | /* Other Methods */ |
---|
333 | case 'quick_add': |
---|
334 | return $this->quick_add($_POST['add']); |
---|
335 | |
---|
336 | case 'add_group': |
---|
337 | return $this->add_group($_POST['add']); |
---|
338 | |
---|
339 | case 'remove_entry': |
---|
340 | return $this->remove_entry((int)$_GET['remove']); |
---|
341 | |
---|
342 | case 'remove_all_entries': |
---|
343 | return $this->remove_all_entries(); |
---|
344 | |
---|
345 | case 'remove_group': |
---|
346 | |
---|
347 | return $this->remove_group((int)$_GET['remove']); |
---|
348 | |
---|
349 | case 'search': |
---|
350 | $ids = false; |
---|
351 | $ids = $this->search($_GET['data']); |
---|
352 | return $this->get_cards_data('search', '1', $ids); |
---|
353 | |
---|
354 | case 'email_win': |
---|
355 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
356 | $api = CreateObject('contactcenter.ui_api'); |
---|
357 | $win = $api->get_email_win(); |
---|
358 | $win .= $api->get_quick_add_plugin(); |
---|
359 | $win .= '<input id="QAbutton" type="button" value="QuickAdd" />' |
---|
360 | .'<br><input type="button" value="EmailWin" onclick="ccEmailWin.open()" />' |
---|
361 | .'<script type="text/javascript">' |
---|
362 | .' ccQuickAdd.associateAsButton(Element("QAbutton"));' |
---|
363 | .'</script>'; |
---|
364 | echo $win; |
---|
365 | return; |
---|
366 | |
---|
367 | /* Information Gathering */ |
---|
368 | case 'get_multiple_entries': |
---|
369 | echo serialize($this->get_multiple_entries(str_replace('\\"','"',$_POST['data']))); |
---|
370 | return; |
---|
371 | |
---|
372 | case 'get_all_entries': |
---|
373 | echo serialize($this->get_all_entries(str_replace('\\"','"',$_POST['data']))); |
---|
374 | return; |
---|
375 | |
---|
376 | case 'import_contacts': |
---|
377 | return $this->import_contacts($_GET['typeImport']); |
---|
378 | |
---|
379 | case 'export_contacts': |
---|
380 | return $this->export_contacts($_POST['typeExport']); |
---|
381 | |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | /*! |
---|
386 | |
---|
387 | @function set_n_cards |
---|
388 | @abstract Informs the class the number of cards the page can show |
---|
389 | @author Raphael Derosso Pereira |
---|
390 | |
---|
391 | @param integer $n_cards The number of cards |
---|
392 | |
---|
393 | */ |
---|
394 | function set_n_cards($n_cards) |
---|
395 | { |
---|
396 | if (is_int($n_cards)) |
---|
397 | { |
---|
398 | $this->page_info['n_cards'] = $n_cards; |
---|
399 | echo 1; |
---|
400 | } |
---|
401 | |
---|
402 | $this->save_session(); |
---|
403 | } |
---|
404 | |
---|
405 | /*! |
---|
406 | |
---|
407 | @function set_catalog |
---|
408 | @abstract Sets the current catalog selected by the user |
---|
409 | @author Raphael Derosso Pereira |
---|
410 | |
---|
411 | @param string $id_catalog The sequence of IDs to reach the catalog |
---|
412 | separated by commas |
---|
413 | |
---|
414 | */ |
---|
415 | function set_catalog($id_catalog) |
---|
416 | { |
---|
417 | $id_catalog = str_replace('\\"', '"', $id_catalog); |
---|
418 | $temp =& $this->bo->set_catalog($id_catalog); |
---|
419 | |
---|
420 | if ($temp) |
---|
421 | { |
---|
422 | $this->page_info['changed'] = true; |
---|
423 | $this->page_info['actual_entries'] = false; |
---|
424 | $this->page_info['actual_catalog'] =& $temp; |
---|
425 | $this->save_session(); |
---|
426 | |
---|
427 | $catalog_info = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); |
---|
428 | |
---|
429 | if ($catalog_info['class'] === 'bo_global_ldap_catalog' || |
---|
430 | $catalog_info['class'] === 'bo_catalog_group_catalog') |
---|
431 | { |
---|
432 | $perms = 1; |
---|
433 | } |
---|
434 | else |
---|
435 | { |
---|
436 | $perms = 15; |
---|
437 | } |
---|
438 | |
---|
439 | echo serialize(array( |
---|
440 | 'status' => 'ok', |
---|
441 | 'perms' => $perms |
---|
442 | )); |
---|
443 | |
---|
444 | return; |
---|
445 | } |
---|
446 | |
---|
447 | echo serialize(array( |
---|
448 | 'status' => 'ok', |
---|
449 | 'perms' => 0 |
---|
450 | )); |
---|
451 | } |
---|
452 | |
---|
453 | |
---|
454 | /*! |
---|
455 | |
---|
456 | @function get_catalog_tree |
---|
457 | @abstract Returns the JS serialized array to used as the tree |
---|
458 | level |
---|
459 | @author Raphael Derosso Pereira |
---|
460 | @author Mário César Kolling (error messages and timeout) |
---|
461 | |
---|
462 | @param (string) $level The level to be taken |
---|
463 | |
---|
464 | */ |
---|
465 | function get_catalog_tree($level) |
---|
466 | { |
---|
467 | if ($level === '0') |
---|
468 | { |
---|
469 | $folderImageDir = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/dftree/images/'; |
---|
470 | |
---|
471 | $parent = '0'; |
---|
472 | |
---|
473 | if (!($tree = $this->bo->get_catalog_tree($level))) |
---|
474 | { |
---|
475 | return array( |
---|
476 | 'msg' => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'), |
---|
477 | 'status' => 'fatal' |
---|
478 | ); |
---|
479 | } |
---|
480 | } |
---|
481 | else |
---|
482 | { |
---|
483 | $last_dot = strrpos($level,'.'); |
---|
484 | $parent = substr($level, 0, $last_dot); |
---|
485 | $child = substr($level, $last_dot+1, strlen($level)); |
---|
486 | |
---|
487 | if (!($tree[$child] = $this->bo->get_catalog_tree($level))) |
---|
488 | { |
---|
489 | return array( |
---|
490 | 'msg' => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'), |
---|
491 | 'status' => 'fatal' |
---|
492 | ); |
---|
493 | } |
---|
494 | // Deals with timeout and returns the generated message to the browser |
---|
495 | else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg'])) |
---|
496 | { |
---|
497 | $tmp = array( |
---|
498 | 'msg' => $tree[$child]['msg'], |
---|
499 | 'status' => 'fatal' |
---|
500 | ); |
---|
501 | unset($tree[$child]); |
---|
502 | return $tmp; |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|
506 | $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png'); |
---|
507 | $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png')); |
---|
508 | |
---|
509 | // Deals with error messages from the server and returns them to the browser |
---|
510 | if ($tree['msg']) |
---|
511 | { |
---|
512 | $msg = $tree['msg']; |
---|
513 | unset($tree['msg']); |
---|
514 | } |
---|
515 | |
---|
516 | $tree_js = $this->convert_tree($tree, $folderImageDir, $parent); |
---|
517 | |
---|
518 | // Return status = ok, or else return generated message to the browser |
---|
519 | if (!$msg) |
---|
520 | { |
---|
521 | return array( |
---|
522 | 'data' => $tree_js, |
---|
523 | 'msg' => lang('Catalog Tree Successfully taken!'), |
---|
524 | 'status' => 'ok' |
---|
525 | ); |
---|
526 | } |
---|
527 | else |
---|
528 | { |
---|
529 | return array( |
---|
530 | 'data' => $tree_js, |
---|
531 | 'msg' => $msg, |
---|
532 | 'status' => 'error' |
---|
533 | ); |
---|
534 | } |
---|
535 | } |
---|
536 | |
---|
537 | /*! |
---|
538 | |
---|
539 | @function get_actual_catalog |
---|
540 | @abstract Returns the actual selected Catalog |
---|
541 | @author Raphael Derosso Pereira |
---|
542 | |
---|
543 | */ |
---|
544 | function get_actual_catalog() |
---|
545 | { |
---|
546 | $level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0'); |
---|
547 | |
---|
548 | if ($level) |
---|
549 | { |
---|
550 | return array( |
---|
551 | 'status' => 'ok', |
---|
552 | 'data' => $level |
---|
553 | ); |
---|
554 | } |
---|
555 | |
---|
556 | return array( |
---|
557 | 'status' => 'fatal', |
---|
558 | 'msg' => lang('Couldn\'t get the actual catalog.'), |
---|
559 | ); |
---|
560 | } |
---|
561 | |
---|
562 | /*! |
---|
563 | |
---|
564 | @function get_cards_data |
---|
565 | @abstract Returns the information that is placed on the cards |
---|
566 | @author Raphael Derosso Pereira |
---|
567 | |
---|
568 | @param string $letter The first letter to be searched |
---|
569 | @param (int) $page The page to be taken |
---|
570 | @param (str) $ids The ids to be taken in case of search |
---|
571 | |
---|
572 | TODO: This function is not well done. It must be rewritten |
---|
573 | using the new array 'msg','status','data' schema. |
---|
574 | */ |
---|
575 | function get_cards_data($letter, $page, $ids) |
---|
576 | { |
---|
577 | if( $ids ) |
---|
578 | $_SESSION['ids'] = $ids; |
---|
579 | |
---|
580 | // It's an external catalog? |
---|
581 | $external = $this->bo->is_external($this->page_info['actual_catalog']); |
---|
582 | //echo $page."\n"; |
---|
583 | if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or |
---|
584 | ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or |
---|
585 | $this->page_info['changed'])) |
---|
586 | { |
---|
587 | unset($ids); |
---|
588 | $this->page_info['changed'] = false; |
---|
589 | |
---|
590 | switch ($this->page_info['actual_catalog']['class']) |
---|
591 | { |
---|
592 | case 'bo_shared_people_manager': |
---|
593 | case 'bo_people_catalog': |
---|
594 | $field_name = 'id_contact'; |
---|
595 | |
---|
596 | if ($letter !== 'number') |
---|
597 | { |
---|
598 | $find_restric[0] = array( |
---|
599 | 0 => array( |
---|
600 | 'field' => 'contact.names_ordered', |
---|
601 | 'type' => 'iLIKE', |
---|
602 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
603 | ) |
---|
604 | ); |
---|
605 | if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){ |
---|
606 | $find_restric[0][1] = array( |
---|
607 | 'field' => 'contact.id_owner', |
---|
608 | 'type' => '=', |
---|
609 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
610 | ); |
---|
611 | } |
---|
612 | } |
---|
613 | else |
---|
614 | { |
---|
615 | $find_restric[0] = array( |
---|
616 | 0 => array( |
---|
617 | 'type' => 'branch', |
---|
618 | 'value' => 'OR', |
---|
619 | 'sub_branch' => array( |
---|
620 | 0 => array( |
---|
621 | 'field' => 'contact.names_ordered', |
---|
622 | 'type' => 'LIKE', |
---|
623 | 'value' => '0%' |
---|
624 | ), |
---|
625 | 1 => array( |
---|
626 | 'field' => 'contact.names_ordered', |
---|
627 | 'type' => 'LIKE', |
---|
628 | 'value' => '1%' |
---|
629 | ), |
---|
630 | 2 => array( |
---|
631 | 'field' => 'contact.names_ordered', |
---|
632 | 'type' => 'LIKE', |
---|
633 | 'value' => '2%' |
---|
634 | ), |
---|
635 | 3 => array( |
---|
636 | 'field' => 'contact.names_ordered', |
---|
637 | 'type' => 'LIKE', |
---|
638 | 'value' => '3%' |
---|
639 | ), |
---|
640 | 4 => array( |
---|
641 | 'field' => 'contact.names_ordered', |
---|
642 | 'type' => 'LIKE', |
---|
643 | 'value' => '4%' |
---|
644 | ), |
---|
645 | 5 => array( |
---|
646 | 'field' => 'contact.names_ordered', |
---|
647 | 'type' => 'LIKE', |
---|
648 | 'value' => '5%' |
---|
649 | ), |
---|
650 | 6 => array( |
---|
651 | 'field' => 'contact.names_ordered', |
---|
652 | 'type' => 'LIKE', |
---|
653 | 'value' => '6%' |
---|
654 | ), |
---|
655 | 7 => array( |
---|
656 | 'field' => 'contact.names_ordered', |
---|
657 | 'type' => 'LIKE', |
---|
658 | 'value' => '7%' |
---|
659 | ), |
---|
660 | 8 => array( |
---|
661 | 'field' => 'contact.names_ordered', |
---|
662 | 'type' => 'LIKE', |
---|
663 | 'value' => '8%' |
---|
664 | ), |
---|
665 | 9 => array( |
---|
666 | 'field' => 'contact.names_ordered', |
---|
667 | 'type' => 'LIKE', |
---|
668 | 'value' => '9%' |
---|
669 | ), |
---|
670 | ), |
---|
671 | ) |
---|
672 | ); |
---|
673 | } |
---|
674 | |
---|
675 | if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){ |
---|
676 | $find_restric[0][1] = array( |
---|
677 | 'field' => 'contact.id_owner', |
---|
678 | 'type' => '=', |
---|
679 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
680 | ); |
---|
681 | } |
---|
682 | |
---|
683 | |
---|
684 | $find_field[0] = array('contact.id_contact','contact.names_ordered'); |
---|
685 | |
---|
686 | $find_other[0] = array( |
---|
687 | 'order' => 'contact.names_ordered' |
---|
688 | ); |
---|
689 | |
---|
690 | break; |
---|
691 | |
---|
692 | case 'bo_global_ldap_catalog': |
---|
693 | |
---|
694 | $field_name = 'id_contact'; |
---|
695 | |
---|
696 | if ($letter !== 'number') |
---|
697 | { |
---|
698 | $find_restric[0] = array( |
---|
699 | 0 => array( |
---|
700 | 'field' => 'contact.names_ordered', |
---|
701 | 'type' => 'iLIKE', |
---|
702 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
703 | ), |
---|
704 | /* |
---|
705 | * Restrict the returned contacts in a "first letter" search |
---|
706 | * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, |
---|
707 | * phpgwAccountVisible != -1 |
---|
708 | */ |
---|
709 | 1 => array( |
---|
710 | 'field' => 'contact.object_class', |
---|
711 | 'type' => '=', |
---|
712 | 'value' => 'phpgwAccount' |
---|
713 | ), |
---|
714 | 2 => array( |
---|
715 | 'field' => 'contact.account_status', |
---|
716 | 'type' => 'iLIKE', |
---|
717 | 'value' => '%' |
---|
718 | ), |
---|
719 | 3 => array( |
---|
720 | 'field' => 'contact.account_visible', |
---|
721 | 'type' => '!=', |
---|
722 | 'value' => '-1' |
---|
723 | ) |
---|
724 | ); |
---|
725 | // If not external catalog get only phpgwAccountType = u ou l |
---|
726 | if (!$external) |
---|
727 | { |
---|
728 | $find_restric[0][5] = array( |
---|
729 | 'type' => 'branch', |
---|
730 | 'value' => 'OR', |
---|
731 | 'sub_branch' => array( |
---|
732 | 0 => array( |
---|
733 | 'field' => 'contact.account_type', |
---|
734 | 'type' => '=', |
---|
735 | 'value' => 'u' |
---|
736 | ), |
---|
737 | 1 => array( |
---|
738 | 'field' => 'contact.account_type', |
---|
739 | 'type' => '=', |
---|
740 | 'value' => 'i' |
---|
741 | ), |
---|
742 | 2 => array( |
---|
743 | 'field' => 'contact.account_type', |
---|
744 | 'type' => '=', |
---|
745 | 'value' => 'l' |
---|
746 | ), |
---|
747 | 3 => array( |
---|
748 | 'field' => 'contact.account_type', |
---|
749 | 'type' => '=', |
---|
750 | 'value' => 'g' |
---|
751 | ) |
---|
752 | ) |
---|
753 | ); |
---|
754 | } |
---|
755 | } |
---|
756 | else |
---|
757 | { |
---|
758 | $find_restric[0] = array( |
---|
759 | /* |
---|
760 | * Restrict the returned contacts in a "first number" search |
---|
761 | * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, |
---|
762 | * phpgwAccountVisible != -1 |
---|
763 | */ |
---|
764 | 0 => array( |
---|
765 | 'field' => 'contact.object_class', |
---|
766 | 'type' => '=', |
---|
767 | 'value' => 'phpgwAccount' |
---|
768 | ), |
---|
769 | 1 => array( |
---|
770 | 'field' => 'contact.account_status', |
---|
771 | 'type' => 'iLIKE', |
---|
772 | 'value' => '%' |
---|
773 | ), |
---|
774 | 2 => array( |
---|
775 | 'field' => 'contact.account_visible', |
---|
776 | 'type' => '!=', |
---|
777 | 'value' => '-1' |
---|
778 | ), |
---|
779 | 3 => array( |
---|
780 | 'type' => 'branch', |
---|
781 | 'value' => 'OR', |
---|
782 | 'sub_branch' => array( |
---|
783 | 0 => array( |
---|
784 | 'field' => 'contact.names_ordered', |
---|
785 | 'type' => 'LIKE', |
---|
786 | 'value' => '0%' |
---|
787 | ), |
---|
788 | 1 => array( |
---|
789 | 'field' => 'contact.names_ordered', |
---|
790 | 'type' => 'LIKE', |
---|
791 | 'value' => '1%' |
---|
792 | ), |
---|
793 | 2 => array( |
---|
794 | 'field' => 'contact.names_ordered', |
---|
795 | 'type' => 'LIKE', |
---|
796 | 'value' => '2%' |
---|
797 | ), |
---|
798 | 3 => array( |
---|
799 | 'field' => 'contact.names_ordered', |
---|
800 | 'type' => 'LIKE', |
---|
801 | 'value' => '3%' |
---|
802 | ), |
---|
803 | 4 => array( |
---|
804 | 'field' => 'contact.names_ordered', |
---|
805 | 'type' => 'LIKE', |
---|
806 | 'value' => '4%' |
---|
807 | ), |
---|
808 | 5 => array( |
---|
809 | 'field' => 'contact.names_ordered', |
---|
810 | 'type' => 'LIKE', |
---|
811 | 'value' => '5%' |
---|
812 | ), |
---|
813 | 6 => array( |
---|
814 | 'field' => 'contact.names_ordered', |
---|
815 | 'type' => 'LIKE', |
---|
816 | 'value' => '6%' |
---|
817 | ), |
---|
818 | 7 => array( |
---|
819 | 'field' => 'contact.names_ordered', |
---|
820 | 'type' => 'LIKE', |
---|
821 | 'value' => '7%' |
---|
822 | ), |
---|
823 | 8 => array( |
---|
824 | 'field' => 'contact.names_ordered', |
---|
825 | 'type' => 'LIKE', |
---|
826 | 'value' => '8%' |
---|
827 | ), |
---|
828 | 9 => array( |
---|
829 | 'field' => 'contact.names_ordered', |
---|
830 | 'type' => 'LIKE', |
---|
831 | 'value' => '9%' |
---|
832 | ), |
---|
833 | ), |
---|
834 | ), |
---|
835 | ); |
---|
836 | // If not external catalog get only phpgwAccountType = u ou l |
---|
837 | if (!$external) |
---|
838 | { |
---|
839 | $find_restric[0][5] = array( |
---|
840 | 'type' => 'branch', |
---|
841 | 'value' => 'OR', |
---|
842 | 'sub_branch' => array( |
---|
843 | 0 => array( |
---|
844 | 'field' => 'contact.account_type', |
---|
845 | 'type' => '=', |
---|
846 | 'value' => 'u' |
---|
847 | ), |
---|
848 | 1 => array( |
---|
849 | 'field' => 'contact.account_type', |
---|
850 | 'type' => '=', |
---|
851 | 'value' => 'i' |
---|
852 | ), |
---|
853 | 2 => array( |
---|
854 | 'field' => 'contact.account_type', |
---|
855 | 'type' => '=', |
---|
856 | 'value' => 'l' |
---|
857 | ), |
---|
858 | 3 => array( |
---|
859 | 'field' => 'contact.account_type', |
---|
860 | 'type' => '=', |
---|
861 | 'value' => 'g' |
---|
862 | ) |
---|
863 | |
---|
864 | ) |
---|
865 | ); |
---|
866 | } |
---|
867 | } |
---|
868 | |
---|
869 | if (!$external) |
---|
870 | { |
---|
871 | // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible |
---|
872 | // for non-external catalogs, used to restrict the attributes used in filters |
---|
873 | $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type', |
---|
874 | 'contact.object_class',/*'contact.account_status',*/'contact.account_visible'); |
---|
875 | } |
---|
876 | else |
---|
877 | { |
---|
878 | // Get only this attributes: dn, cn for external catalogs, |
---|
879 | // used to restrict the attributes used in filters |
---|
880 | $find_field[0] = array('contact.id_contact','contact.names_ordered'); |
---|
881 | } |
---|
882 | |
---|
883 | $find_other[0] = array( |
---|
884 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
885 | //'limit' => $this->page_info['n_cards'], |
---|
886 | 'order' => 'contact.names_ordered' |
---|
887 | ); |
---|
888 | |
---|
889 | break; |
---|
890 | |
---|
891 | case 'bo_company_manager': |
---|
892 | $field_name = 'id_company'; |
---|
893 | |
---|
894 | $find_field[0] = array('company.id_company','company.company_name'); |
---|
895 | |
---|
896 | $find_other[0] = array( |
---|
897 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
898 | //'limit' => $this->page_info['n_cards'], |
---|
899 | 'order' => 'company.company_name' |
---|
900 | ); |
---|
901 | |
---|
902 | $find_restric[0] = array( |
---|
903 | 0 => array( |
---|
904 | 'field' => 'company.company_name', |
---|
905 | 'type' => 'iLIKE', |
---|
906 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
907 | ) |
---|
908 | ); |
---|
909 | |
---|
910 | break; |
---|
911 | |
---|
912 | case 'bo_group_manager': |
---|
913 | case 'bo_shared_group_manager': |
---|
914 | |
---|
915 | $field_name = 'id_group'; |
---|
916 | |
---|
917 | if ($letter !== 'number') { |
---|
918 | |
---|
919 | $find_restric[0] = array( |
---|
920 | 0 => array( |
---|
921 | 'field' => 'group.title', |
---|
922 | 'type' => 'iLIKE', |
---|
923 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
924 | ) |
---|
925 | ); |
---|
926 | } |
---|
927 | else { |
---|
928 | |
---|
929 | $find_restric[0] = array( |
---|
930 | 0 => array( |
---|
931 | 'field' => 'group.title', |
---|
932 | 'type' => 'LIKE', |
---|
933 | 'value' => '0%' |
---|
934 | ) |
---|
935 | ); |
---|
936 | } |
---|
937 | |
---|
938 | if($this->page_info['actual_catalog']['class'] == 'bo_group_manager'){ |
---|
939 | array_push($find_restric[0], array( |
---|
940 | 'field' => 'group.owner', |
---|
941 | 'type' => '=', |
---|
942 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
943 | ) |
---|
944 | ); |
---|
945 | } |
---|
946 | |
---|
947 | $find_field[0] = array('group.id_group','group.title','group.short_name'); |
---|
948 | $find_other[0] = array( |
---|
949 | 'order' => 'group.title' |
---|
950 | ); |
---|
951 | break; |
---|
952 | |
---|
953 | case 'bo_catalog_group_catalog': |
---|
954 | $this->page_info['actual_entries'] = false; |
---|
955 | |
---|
956 | $this->page_info['actual_letter'] = $letter; |
---|
957 | $this->page_info['actual_page'] = 0; |
---|
958 | |
---|
959 | $this->save_session(); |
---|
960 | $final[0] = 0; |
---|
961 | $final[1] = $this->typeContact; |
---|
962 | echo serialize($final); |
---|
963 | return; |
---|
964 | |
---|
965 | } |
---|
966 | |
---|
967 | $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0]); |
---|
968 | |
---|
969 | $n_entries = count($result); |
---|
970 | |
---|
971 | if ($n_entries) |
---|
972 | { |
---|
973 | //echo 'N_entries: '.$n_entries.'<br>'; |
---|
974 | $this->page_info['n_pages'] = ceil($n_entries/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1)); |
---|
975 | } |
---|
976 | else |
---|
977 | { |
---|
978 | $this->page_info['n_pages'] = 0; |
---|
979 | } |
---|
980 | |
---|
981 | if (!$result) |
---|
982 | { |
---|
983 | |
---|
984 | $this->page_info['actual_entries'] = false; |
---|
985 | |
---|
986 | $this->page_info['actual_letter'] = $letter; |
---|
987 | $this->page_info['actual_page'] = 0; |
---|
988 | |
---|
989 | $this->save_session(); |
---|
990 | $final[0] = 0; |
---|
991 | $final[1] = $this->typeContact; |
---|
992 | echo serialize($final); |
---|
993 | return; |
---|
994 | } |
---|
995 | else |
---|
996 | { |
---|
997 | unset($this->page_info['actual_entries']); |
---|
998 | foreach ($result as $id => $value) |
---|
999 | { |
---|
1000 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
1001 | $this->page_info['actual_entries'][] = $value[$field_name]; |
---|
1002 | else |
---|
1003 | $this->page_info['actual_entries'][] = array(0=>$value[$field_name],1=>$value['perms'],2=>$value['owner']); |
---|
1004 | } |
---|
1005 | //print_r($this->page_info['actual_entries']); |
---|
1006 | } |
---|
1007 | } |
---|
1008 | else if ($letter === 'search') |
---|
1009 | { |
---|
1010 | //if (!$ids and $this->page_info['actual_letter'] !== 'search') |
---|
1011 | if (!$ids) |
---|
1012 | { |
---|
1013 | //error_log('!$ids e $this->page_info[\'actual_letter\'] != search'); |
---|
1014 | $this->page_info['actual_entries'] = false; |
---|
1015 | |
---|
1016 | $this->page_info['actual_letter'] = $letter; |
---|
1017 | $this->page_info['actual_page'] = 0; |
---|
1018 | |
---|
1019 | $this->save_session(); |
---|
1020 | $final[0] = 0; |
---|
1021 | $final[1] = $this -> typeContact; |
---|
1022 | echo serialize($final); |
---|
1023 | return; |
---|
1024 | } |
---|
1025 | else if ($ids['error']) |
---|
1026 | { |
---|
1027 | $this->page_info['actual_entries'] = false; |
---|
1028 | $this->page_info['actual_letter'] = $letter; |
---|
1029 | $this->page_info['actual_page'] = 0; |
---|
1030 | |
---|
1031 | $this->save_session(); |
---|
1032 | $final[0] = 0; |
---|
1033 | $final[1] = $this -> typeContact; |
---|
1034 | $final['error'] = $ids['error']; |
---|
1035 | echo serialize($final); |
---|
1036 | return; |
---|
1037 | } |
---|
1038 | else if ($ids) |
---|
1039 | { |
---|
1040 | $this->page_info['actual_letter'] = $letter; |
---|
1041 | $this->page_info['actual_entries'] = $ids; |
---|
1042 | $this->page_info['n_pages'] = ceil(count($ids)/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1)); |
---|
1043 | } |
---|
1044 | } |
---|
1045 | else |
---|
1046 | { |
---|
1047 | unset($ids); |
---|
1048 | } |
---|
1049 | |
---|
1050 | if ($this->page_info['actual_entries']) |
---|
1051 | { |
---|
1052 | if ($page >= $this->page_info['n_pages']) |
---|
1053 | { |
---|
1054 | $page = $this->page_info['n_pages']; |
---|
1055 | } |
---|
1056 | |
---|
1057 | $final = array( |
---|
1058 | 0 => (int)$this->page_info['n_pages'], |
---|
1059 | 1 => (int)$page, |
---|
1060 | 2 => array( |
---|
1061 | 0 => 'cc_company', |
---|
1062 | 1 => 'cc_name', |
---|
1063 | 2 => 'cc_title', |
---|
1064 | 3 => 'cc_phone', |
---|
1065 | 4 => 'cc_mail', |
---|
1066 | 5 => 'cc_alias', |
---|
1067 | 6 => 'cc_id', |
---|
1068 | 7 => 'cc_forwarding_address' |
---|
1069 | ) |
---|
1070 | ); |
---|
1071 | |
---|
1072 | //echo 'Page: '.$page.'<br>'; |
---|
1073 | $id_i = (($page-1)*$this->page_info['n_cards']); |
---|
1074 | $id_f = $id_i + $this->page_info['n_cards']; |
---|
1075 | $n_entries = count($this->page_info['actual_entries']); |
---|
1076 | |
---|
1077 | //echo 'ID_I: '.$id_i.'<br>'; |
---|
1078 | //echo 'ID_F: '.$id_f.'<br>'; |
---|
1079 | |
---|
1080 | $ids = array(); |
---|
1081 | $perms = array(); |
---|
1082 | $owners = array(); |
---|
1083 | $array_temp = array(); |
---|
1084 | |
---|
1085 | foreach($this->page_info['actual_entries'] as $key=>$tmp){ |
---|
1086 | $array_temp[] = $tmp; |
---|
1087 | } |
---|
1088 | |
---|
1089 | for($i = $id_i; $i < $id_f and $i < $n_entries; $i++) |
---|
1090 | { |
---|
1091 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
1092 | $ids[] = $array_temp[$i]; |
---|
1093 | else { |
---|
1094 | $ids[] = $array_temp[$i][0]; |
---|
1095 | $perms[] = $array_temp[$i][1]; |
---|
1096 | $owners[] = $array_temp[$i][2]; |
---|
1097 | } |
---|
1098 | //$perms[] = $array_temp[$i]; |
---|
1099 | } |
---|
1100 | |
---|
1101 | |
---|
1102 | // Carrega o nome completo dos donos dos objetos (contatos e grupos); |
---|
1103 | $owner_names = array(); |
---|
1104 | |
---|
1105 | if($owners) { |
---|
1106 | $filter = "(|"; |
---|
1107 | foreach($owners as $i => $owner) { |
---|
1108 | $filter .= "(uidNumber=".$owner.")"; |
---|
1109 | } |
---|
1110 | $filter .= ")"; |
---|
1111 | |
---|
1112 | if(!$this->bo->catalog->src_info) { |
---|
1113 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
1114 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
1115 | } |
---|
1116 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false); |
---|
1117 | $dn=$this->bo->catalog->src_info['dn']; |
---|
1118 | $justThese = array("cn","uidnumber","uid"); |
---|
1119 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
1120 | $info = ldap_get_entries($ds, $sr); |
---|
1121 | ldap_close($ds); |
---|
1122 | for($z = 0; $z < $info['count']; $z++) { |
---|
1123 | $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]); |
---|
1124 | } |
---|
1125 | } |
---|
1126 | /// Original |
---|
1127 | //for($i = $id_i; $i < $id_f and $i < $n_entries; $i++) |
---|
1128 | //{ |
---|
1129 | // $ids[] = $this->page_info['actual_entries'][$i]; |
---|
1130 | //} |
---|
1131 | /// |
---|
1132 | |
---|
1133 | $fields = $this->bo->catalog->get_fields(false); |
---|
1134 | if( $this->typeContact == 'groups' || $this->typeContact == 'shared_groups') { |
---|
1135 | $final = array( |
---|
1136 | 0 => (int)$this->page_info['n_pages'], |
---|
1137 | 1 => (int)$page, |
---|
1138 | 2 => array( |
---|
1139 | 0 => 'cc_title', |
---|
1140 | 1 => 'cc_short_name', |
---|
1141 | 2 => 'cc_id', |
---|
1142 | 3 => 'cc_contacts' |
---|
1143 | ) |
---|
1144 | ); |
---|
1145 | $groups =& $this->bo->catalog->get_multiple_entries($ids,$fields); |
---|
1146 | |
---|
1147 | $i = 0; |
---|
1148 | // contatos do grupo |
---|
1149 | $boGroups = CreateObject('contactcenter.bo_group'); |
---|
1150 | $contacts = array(); |
---|
1151 | |
---|
1152 | foreach($groups as $group) { |
---|
1153 | $final[3][$i][0] = $group['title'] ? $group['title'] : 'none'; |
---|
1154 | $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none'; |
---|
1155 | $final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none'; |
---|
1156 | $contacts = $boGroups -> get_contacts_by_group($group['id_group']); |
---|
1157 | $final[3][$i][3] = $contacts; |
---|
1158 | $final[3][$i][4] = $perms[$i]; |
---|
1159 | if($this->typeContact == 'shared_groups'){ |
---|
1160 | $final[3][$i][5] = lang('Shared').": ".$owner_names[$owners[$i]]['cn']; |
---|
1161 | $final[3][$i][6] = $owner_names[$owners[$i]]['uid']; |
---|
1162 | } |
---|
1163 | $i++; |
---|
1164 | } |
---|
1165 | |
---|
1166 | $this->page_info['actual_letter'] = $letter; |
---|
1167 | $this->page_info['actual_page'] = $page; |
---|
1168 | |
---|
1169 | |
---|
1170 | $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; |
---|
1171 | |
---|
1172 | $final[5] = '<span class="link" onclick="'.$lnk_compose; |
---|
1173 | $final[10] = $this->typeContact; |
---|
1174 | $this->save_session(); |
---|
1175 | echo serialize($final); |
---|
1176 | return; |
---|
1177 | } |
---|
1178 | $final[10] = $this -> typeContact; |
---|
1179 | |
---|
1180 | $fields['photo'] = true; |
---|
1181 | $fields['names_ordered'] = true; |
---|
1182 | $fields['alias'] = true; |
---|
1183 | $fields['account_type'] = true; |
---|
1184 | $fields['companies'] = 'default'; |
---|
1185 | $fields['connections'] = 'default'; |
---|
1186 | // ?aqui alterar a chamada desse método para receber o base dn? |
---|
1187 | $contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields); |
---|
1188 | |
---|
1189 | |
---|
1190 | if (!is_array($contacts) or !count($contacts)) |
---|
1191 | { |
---|
1192 | $final[0] = 0; |
---|
1193 | $final[1] = $this -> typeContact; |
---|
1194 | echo serialize($final); |
---|
1195 | return; |
---|
1196 | } |
---|
1197 | |
---|
1198 | $i = 0; |
---|
1199 | foreach($contacts as $index => $contact) |
---|
1200 | { |
---|
1201 | /* |
---|
1202 | * TODO: Os timeouts de conexão foram retirados, ver se será necessário retornar essa funcionalidade, e, |
---|
1203 | * neste caso, terminar a implementação das mensagens de retorno. |
---|
1204 | */ |
---|
1205 | if ($index !== 'error'){ |
---|
1206 | $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none'; |
---|
1207 | $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none'; |
---|
1208 | $final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none'; |
---|
1209 | |
---|
1210 | /* Select the correct Email and Telephone to be shown */ |
---|
1211 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
1212 | |
---|
1213 | if (!is_array($preferences)) |
---|
1214 | { |
---|
1215 | $preferences['personCardEmail'] = 1; |
---|
1216 | $preferences['personCardPhone'] = 2; |
---|
1217 | } |
---|
1218 | if ($contact['connections']) |
---|
1219 | { |
---|
1220 | $default_email_found = false; |
---|
1221 | $default_phone_found = false; |
---|
1222 | foreach($contact['connections'] as $conn_info) |
---|
1223 | { |
---|
1224 | if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found) |
---|
1225 | { |
---|
1226 | if ($conn_info['connection_is_default']) |
---|
1227 | { |
---|
1228 | $default_email_found = true; |
---|
1229 | } |
---|
1230 | $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; |
---|
1231 | } |
---|
1232 | else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found) |
---|
1233 | { |
---|
1234 | if ($conn_info['connection_is_default']) |
---|
1235 | { |
---|
1236 | $default_phone_found = true; |
---|
1237 | } |
---|
1238 | 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){ |
---|
1239 | $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>"; |
---|
1240 | } |
---|
1241 | $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; |
---|
1242 | } |
---|
1243 | } |
---|
1244 | } |
---|
1245 | |
---|
1246 | if (!$final[3][$i][3]) |
---|
1247 | { |
---|
1248 | $final[3][$i][3] = 'none'; |
---|
1249 | } |
---|
1250 | |
---|
1251 | if (!$final[3][$i][4]) |
---|
1252 | { |
---|
1253 | $final[3][$i][4] = 'none'; |
---|
1254 | } |
---|
1255 | |
---|
1256 | $final[3][$i][5] = $contact['alias']?$contact['alias']:'none'; |
---|
1257 | $final[3][$i][6] = $ids[$i]; |
---|
1258 | |
---|
1259 | // If contact is a public list or a group, then load the forwarding addresses. |
---|
1260 | if($contact['account_type'][0] == 'l' || $contact['account_type'][0] == 'g') |
---|
1261 | $final[3][$i][7] = ($contact['account_type'][0] == 'l' ? 'list' : 'group'); |
---|
1262 | |
---|
1263 | if($this->page_info['actual_catalog']['class']=='bo_shared_people_manager') { |
---|
1264 | $final[3][$i][8] = $perms[$i]; |
---|
1265 | $final[3][$i][9] = lang('Shared').": ".$owner_names[$owners[$i]]['cn']; |
---|
1266 | } |
---|
1267 | |
---|
1268 | $final[4][$i] = $contact['photo'] ? 1 : 0; |
---|
1269 | $i++; |
---|
1270 | } |
---|
1271 | else |
---|
1272 | { |
---|
1273 | // coloca mensagem de erro no vetor que retorna para o browser |
---|
1274 | } |
---|
1275 | } |
---|
1276 | $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; |
---|
1277 | $final[5] = '<span class="link" onclick="'.$lnk_compose; |
---|
1278 | |
---|
1279 | |
---|
1280 | $this->page_info['actual_letter'] = $letter; |
---|
1281 | $this->page_info['actual_page'] = $page; |
---|
1282 | |
---|
1283 | $this->save_session(); |
---|
1284 | echo serialize($final); |
---|
1285 | return; |
---|
1286 | } |
---|
1287 | |
---|
1288 | $this->page_info['actual_letter'] = $letter; |
---|
1289 | $this->page_info['actual_page'] = $page; |
---|
1290 | |
---|
1291 | $this->save_session(); |
---|
1292 | |
---|
1293 | $final[0] = 0; |
---|
1294 | $final[1] = $this -> typeContact; |
---|
1295 | echo serialize($final); |
---|
1296 | } |
---|
1297 | |
---|
1298 | function get_visible_all_ldap() |
---|
1299 | { |
---|
1300 | $bo = CreateObject('contactcenter.bo_ldap_manager'); |
---|
1301 | $ldap_query = $bo->srcs; |
---|
1302 | return $ldap_query[1]['visible']; |
---|
1303 | } |
---|
1304 | |
---|
1305 | |
---|
1306 | /*! |
---|
1307 | |
---|
1308 | @function get_group_data |
---|
1309 | @abstract Returns all the information of a given Group |
---|
1310 | @author Nilton Emilio Buhrer Neto |
---|
1311 | |
---|
1312 | @param (integer) $id The id to get information |
---|
1313 | |
---|
1314 | */ |
---|
1315 | function get_group_data($id) |
---|
1316 | { |
---|
1317 | $this->bo->catalog = CreateObject('contactcenter.bo_group_manager'); |
---|
1318 | $fields = $this->bo->catalog->get_fields(true); |
---|
1319 | $data = $this->bo->catalog->get_single_entry($id,$fields); |
---|
1320 | |
---|
1321 | if($id) { |
---|
1322 | // get All Contacts by group. |
---|
1323 | $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id); |
---|
1324 | } |
---|
1325 | |
---|
1326 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
1327 | |
---|
1328 | $all_contacts = $boGroup->get_all_contacts('only_email'); |
---|
1329 | |
---|
1330 | $contact_options = ""; |
---|
1331 | if(count($all_contacts)) { |
---|
1332 | foreach($all_contacts as $idx => $contact) { |
---|
1333 | $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']." (".$contact['connection_value'].")</OPTION>"; |
---|
1334 | } |
---|
1335 | } |
---|
1336 | $data['contact_list'] = $contact_options; |
---|
1337 | $data['result'] = 'ok'; |
---|
1338 | |
---|
1339 | echo serialize($data); |
---|
1340 | } |
---|
1341 | |
---|
1342 | /*! |
---|
1343 | |
---|
1344 | @function get_full_data |
---|
1345 | @abstract Returns all the information of a given Entry |
---|
1346 | @author Raphael Derosso Pereira |
---|
1347 | |
---|
1348 | @param (integer) $id The id to get information |
---|
1349 | |
---|
1350 | */ |
---|
1351 | function get_full_data($id,$catalog='bo_people_catalog') |
---|
1352 | { |
---|
1353 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
1354 | $this->bo->catalog = CreateObject('contactcenter.'.$catalog); |
---|
1355 | $fields = $this->bo->catalog->get_fields(true); |
---|
1356 | $fields['photo'] = false; |
---|
1357 | $entry = $this->bo->catalog->get_single_entry($id,$fields); |
---|
1358 | |
---|
1359 | if (is_bool($entry['given_names'])) |
---|
1360 | { |
---|
1361 | $data['result'] = 'false'; |
---|
1362 | echo serialize($data); |
---|
1363 | return; |
---|
1364 | } |
---|
1365 | |
---|
1366 | $date = explode('-', $entry['birthdate']); |
---|
1367 | $j = 0; |
---|
1368 | for ($i = 0; $i < 5; $i+=2) |
---|
1369 | { |
---|
1370 | switch($dateformat{$i}) |
---|
1371 | { |
---|
1372 | case 'Y': |
---|
1373 | $birthdate[$j] = $date[0]; |
---|
1374 | break; |
---|
1375 | |
---|
1376 | case 'm': |
---|
1377 | case 'M': |
---|
1378 | $birthdate[$j] = $date[1]; |
---|
1379 | break; |
---|
1380 | |
---|
1381 | case 'd': |
---|
1382 | $birthdate[$j] = $date[2]; |
---|
1383 | } |
---|
1384 | $j++; |
---|
1385 | } |
---|
1386 | $datecount = 0; |
---|
1387 | |
---|
1388 | $data['result'] = 'ok'; |
---|
1389 | $data['cc_full_add_contact_id'] = $id; |
---|
1390 | |
---|
1391 | /* Personal Data */ |
---|
1392 | $data['personal']['cc_pd_photo'] = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id; |
---|
1393 | $data['personal']['cc_pd_alias'] = $entry['alias']; |
---|
1394 | $data['personal']['cc_pd_given_names'] = $entry['given_names']; |
---|
1395 | $data['personal']['cc_pd_family_names'] = $entry['family_names']; |
---|
1396 | $data['personal']['cc_pd_full_name'] = $entry['names_ordered']; |
---|
1397 | $data['personal']['cc_pd_suffix'] = $entry['id_suffix']; |
---|
1398 | $data['personal']['cc_pd_birthdate_0'] = $birthdate[0]; |
---|
1399 | $data['personal']['cc_pd_birthdate_1'] = $birthdate[1]; |
---|
1400 | $data['personal']['cc_pd_birthdate_2'] = $birthdate[2]; |
---|
1401 | //$data['personal']['cc_pd_sex'] = $entry['sex'] === 'M' ? 1 : ($entry['sex'] === 'F' ? 2 : 0); |
---|
1402 | $data['personal']['cc_pd_prefix'] = $entry['id_prefix']; |
---|
1403 | $data['personal']['cc_pd_gpg_finger_print'] = $entry['pgp_key']; |
---|
1404 | $data['personal']['cc_pd_notes'] = $entry['notes']; |
---|
1405 | |
---|
1406 | /* Addresses */ |
---|
1407 | if (is_array($entry['addresses'])) |
---|
1408 | { |
---|
1409 | $data['addresses'] = $entry['addresses']; |
---|
1410 | } |
---|
1411 | |
---|
1412 | /* Connections */ |
---|
1413 | if (is_array($entry['connections'])) |
---|
1414 | { |
---|
1415 | $data['connections'] = array(); |
---|
1416 | foreach ($entry['connections'] as $connection) |
---|
1417 | { |
---|
1418 | $type = $connection['id_type']; |
---|
1419 | $i = count($data['connections'][$type]); |
---|
1420 | $data['connections'][$type][$i]['id'] = $connection['id_connection']; |
---|
1421 | $data['connections'][$type][$i]['name'] = $connection['connection_name']; |
---|
1422 | $data['connections'][$type][$i]['value'] = $connection['connection_value']; |
---|
1423 | $data['connections'][$type][$i]['is_default'] = $connection['connection_is_default']; |
---|
1424 | } |
---|
1425 | } |
---|
1426 | // print_r($data); |
---|
1427 | |
---|
1428 | /* Relations */ |
---|
1429 | |
---|
1430 | echo serialize($data); |
---|
1431 | } |
---|
1432 | |
---|
1433 | /*! |
---|
1434 | |
---|
1435 | @function get_contact_full_add_const |
---|
1436 | @abstract Returns all the constant fields in Contact Full Add Window to the JS |
---|
1437 | @author Raphael Derosso Pereira |
---|
1438 | */ |
---|
1439 | function get_contact_full_add_const() |
---|
1440 | { |
---|
1441 | $data = array(); |
---|
1442 | $boPeopleCatalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
1443 | $predata[] = $boPeopleCatalog -> get_all_prefixes(); |
---|
1444 | $predata[] = $boPeopleCatalog -> get_all_suffixes(); |
---|
1445 | $predata[] = $boPeopleCatalog -> get_all_addresses_types(); |
---|
1446 | $predata[] = $boPeopleCatalog -> get_all_countries(); |
---|
1447 | $predata[] = $boPeopleCatalog -> get_all_connections_types(); |
---|
1448 | //$predata[] = $this->bo->catalog->get_all_relations_types(); |
---|
1449 | |
---|
1450 | $i = 0; |
---|
1451 | foreach($predata as $data_) |
---|
1452 | { |
---|
1453 | if ($data_) |
---|
1454 | { |
---|
1455 | $data[$i] = $data_; |
---|
1456 | } |
---|
1457 | |
---|
1458 | $i++; |
---|
1459 | } |
---|
1460 | |
---|
1461 | if (count($data)) |
---|
1462 | { |
---|
1463 | echo serialize($data); |
---|
1464 | return; |
---|
1465 | } |
---|
1466 | |
---|
1467 | echo 0; |
---|
1468 | } |
---|
1469 | |
---|
1470 | /*! |
---|
1471 | |
---|
1472 | @function quick_add |
---|
1473 | @abstract Adds a new Contact using the Quick Add interface |
---|
1474 | @author Raphael Derosso Pereira |
---|
1475 | |
---|
1476 | @param string $sdata Serialized data |
---|
1477 | */ |
---|
1478 | function quick_add($sdata) |
---|
1479 | { |
---|
1480 | |
---|
1481 | $sdata = str_replace('\\"', '"', $sdata); |
---|
1482 | $new_array = unserialize($sdata); |
---|
1483 | $tdata = array(); |
---|
1484 | |
---|
1485 | foreach($new_array as $tmp) |
---|
1486 | $tdata[] = $tmp; |
---|
1487 | |
---|
1488 | if (!$tdata) |
---|
1489 | { |
---|
1490 | echo serialize(array( |
---|
1491 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
1492 | 'status' => 'abort' |
---|
1493 | )); |
---|
1494 | |
---|
1495 | return; |
---|
1496 | } |
---|
1497 | |
---|
1498 | // verifica se email já existe! |
---|
1499 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
1500 | $contact = $boGroup->verify_contact($tdata[4]); |
---|
1501 | |
---|
1502 | if($contact) |
---|
1503 | { |
---|
1504 | $str_contact = "\r\n - ".implode("\r\n - ",$contact); |
---|
1505 | |
---|
1506 | echo serialize(array( |
---|
1507 | 'msg' => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact), |
---|
1508 | 'status' => 'alreadyExists' |
---|
1509 | )); |
---|
1510 | |
---|
1511 | return; |
---|
1512 | } |
---|
1513 | |
---|
1514 | $data['alias'] = $tdata[0]; |
---|
1515 | $data['given_names'] = $tdata[1]; |
---|
1516 | $data['family_names'] = $tdata[2]; |
---|
1517 | // $data['connections']['default_phone']['id_typeof_connection'] = 1; |
---|
1518 | $data['connections']['default_phone']['connection_name'] = lang('Main'); |
---|
1519 | $data['connections']['default_phone']['connection_value'] = $tdata[3]; |
---|
1520 | // $data['connections']['default_email']['id_typeof_connection'] = 2; |
---|
1521 | $data['connections']['default_email']['connection_name'] = lang('Main'); |
---|
1522 | $data['connections']['default_email']['connection_value'] = $tdata[4]; |
---|
1523 | |
---|
1524 | $boPeople = CreateObject('contactcenter.bo_people_catalog'); |
---|
1525 | |
---|
1526 | if ($boPeople ->quick_add($data)) |
---|
1527 | { |
---|
1528 | $this->page_info['changed'] = true; |
---|
1529 | |
---|
1530 | echo serialize(array( |
---|
1531 | 'msg' => lang('Entry added with success!'), |
---|
1532 | 'status' => 'ok' |
---|
1533 | )); |
---|
1534 | } |
---|
1535 | else |
---|
1536 | { |
---|
1537 | echo serialize(array( |
---|
1538 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
1539 | 'status' => 'error' |
---|
1540 | )); |
---|
1541 | } |
---|
1542 | |
---|
1543 | $this->save_session(); |
---|
1544 | |
---|
1545 | } |
---|
1546 | |
---|
1547 | /*! |
---|
1548 | |
---|
1549 | @function add_group |
---|
1550 | @abstract Adds a new Group using the Add Group interface |
---|
1551 | @author Nilton Emilio Buhrer Neto |
---|
1552 | |
---|
1553 | @param string $sdata Serialized data |
---|
1554 | */ |
---|
1555 | function add_group($sdata) |
---|
1556 | { |
---|
1557 | $sdata = str_replace('\\"', '"', $sdata); |
---|
1558 | $tdata = unserialize($sdata); |
---|
1559 | $new_tdata = array(); |
---|
1560 | |
---|
1561 | if (!$tdata) |
---|
1562 | { |
---|
1563 | echo serialize(array( |
---|
1564 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
1565 | 'status' => 'abort' |
---|
1566 | )); |
---|
1567 | |
---|
1568 | return; |
---|
1569 | } |
---|
1570 | |
---|
1571 | foreach($tdata as $tmp) |
---|
1572 | $new_tdata[] = $tmp; |
---|
1573 | |
---|
1574 | $data['title'] = $new_tdata[0]; |
---|
1575 | $data['contact_in_list'] = $new_tdata[1]; |
---|
1576 | $data['id_group'] = $new_tdata[2]; |
---|
1577 | |
---|
1578 | $boGroup = CreateObject('contactcenter.bo_group_manager'); |
---|
1579 | $id = $boGroup -> add_group($data); |
---|
1580 | |
---|
1581 | if ($id) |
---|
1582 | { |
---|
1583 | $this->page_info['changed'] = true; |
---|
1584 | |
---|
1585 | echo serialize(array( |
---|
1586 | 'msg' => lang('Entry added with success!'), |
---|
1587 | 'status' => 'ok' |
---|
1588 | )); |
---|
1589 | } |
---|
1590 | else |
---|
1591 | { |
---|
1592 | echo serialize(array( |
---|
1593 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
1594 | 'status' => 'error' |
---|
1595 | )); |
---|
1596 | } |
---|
1597 | |
---|
1598 | $this->save_session(); |
---|
1599 | } |
---|
1600 | |
---|
1601 | /*! |
---|
1602 | |
---|
1603 | @function remove_group |
---|
1604 | @abstract Removes a group if the user has the right to do it |
---|
1605 | @author Nilton Emilio Buhrer Neto |
---|
1606 | @param (integer) $id The id to be removed |
---|
1607 | |
---|
1608 | */ |
---|
1609 | function remove_group($id) |
---|
1610 | { |
---|
1611 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
1612 | $data = array ('id_group' => $id); |
---|
1613 | if($soGroup -> delete($data)) { |
---|
1614 | echo serialize(array( |
---|
1615 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
1616 | 'status' => 'ok' |
---|
1617 | )); |
---|
1618 | } |
---|
1619 | else { |
---|
1620 | echo serialize(array( |
---|
1621 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
1622 | 'status' => 'error' |
---|
1623 | )); |
---|
1624 | } |
---|
1625 | |
---|
1626 | $this->save_session(); |
---|
1627 | } |
---|
1628 | |
---|
1629 | |
---|
1630 | function remove_all_entries (){ |
---|
1631 | |
---|
1632 | $error = false; |
---|
1633 | $this->all_entries = $this->bo->catalog->get_all_entries_ids(); |
---|
1634 | |
---|
1635 | foreach($this->all_entries as $index => $id) { |
---|
1636 | $result = $this->bo->catalog->remove_single_entry($id); |
---|
1637 | if(!$result) { |
---|
1638 | $error = true; |
---|
1639 | break; |
---|
1640 | } |
---|
1641 | } |
---|
1642 | |
---|
1643 | if(!$error) { |
---|
1644 | echo serialize(array( |
---|
1645 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
1646 | 'status' => 'ok' |
---|
1647 | )); |
---|
1648 | } |
---|
1649 | else { |
---|
1650 | echo serialize(array( |
---|
1651 | 'msg' => lang('Couldn\'t remove this entry. Inform the Site Admin!'), |
---|
1652 | 'status' => 'fail' |
---|
1653 | )); |
---|
1654 | } |
---|
1655 | |
---|
1656 | $this->save_session(); |
---|
1657 | } |
---|
1658 | |
---|
1659 | /*! |
---|
1660 | |
---|
1661 | @function remove_entry |
---|
1662 | @abstract Removes an entry if the user has the right to do it |
---|
1663 | @author Raphael Derosso Pereira |
---|
1664 | |
---|
1665 | @param (integer) $id The id to be removed |
---|
1666 | |
---|
1667 | */ |
---|
1668 | function remove_entry ($id) |
---|
1669 | { |
---|
1670 | if (!is_int($id)) |
---|
1671 | { |
---|
1672 | echo lang('Couldn\'t remove entry! Problem passing data to the server. Please inform admin!'); |
---|
1673 | return; |
---|
1674 | } |
---|
1675 | |
---|
1676 | $this->page_info['changed'] = true; |
---|
1677 | $result = $this->bo->catalog->remove_single_entry($id); |
---|
1678 | |
---|
1679 | if ($result) |
---|
1680 | { |
---|
1681 | if ($pos = array_search($id, $this->page_info['actual_entries'])) |
---|
1682 | { |
---|
1683 | unset($this->page_info['actual_entries'][$pos]); |
---|
1684 | } |
---|
1685 | |
---|
1686 | $temp = false; |
---|
1687 | reset($this->page_info['actual_entries']); |
---|
1688 | foreach($this->page_info['actual_entries'] as $t) |
---|
1689 | { |
---|
1690 | $temp[] = $t; |
---|
1691 | } |
---|
1692 | |
---|
1693 | $this->page_info['actual_entries'] = $temp; |
---|
1694 | |
---|
1695 | echo serialize(array( |
---|
1696 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
1697 | 'status' => 'ok' |
---|
1698 | )); |
---|
1699 | } |
---|
1700 | else |
---|
1701 | { |
---|
1702 | echo serialize(array( |
---|
1703 | 'msg' => lang('Couldn\'t remove this entry. Inform the Site Admin!'), |
---|
1704 | 'status' => 'fail' |
---|
1705 | )); |
---|
1706 | } |
---|
1707 | |
---|
1708 | $this->save_session(); |
---|
1709 | } |
---|
1710 | |
---|
1711 | |
---|
1712 | /*! |
---|
1713 | |
---|
1714 | @function post_full_add |
---|
1715 | @abstract Saves all the information altered/entered in the Full Add |
---|
1716 | window |
---|
1717 | @author Raphael Derosso Pereira |
---|
1718 | |
---|
1719 | */ |
---|
1720 | function post_full_add() |
---|
1721 | { |
---|
1722 | $data = $_POST['data']; |
---|
1723 | // Exceptions!!! utf8 special chars. |
---|
1724 | $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data); |
---|
1725 | $data = unserialize(str_replace('\\"', '"', $data)); |
---|
1726 | $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
1727 | |
---|
1728 | if (!is_array($data)) |
---|
1729 | { |
---|
1730 | echo serialize(array( |
---|
1731 | 'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'. |
---|
1732 | 'Please go to eGroupWare Bug Reporting page and report this bug.<br>'. |
---|
1733 | 'Sorry for the inconvenient!<br><br>'. |
---|
1734 | '<b><i>ContactCenter Developer Team</i></b></p>'), |
---|
1735 | 'status' => 'fatal' |
---|
1736 | )); |
---|
1737 | return; |
---|
1738 | } |
---|
1739 | // print_r($data); |
---|
1740 | // echo '<br><br>'; |
---|
1741 | |
---|
1742 | $replacer = $data['commercialAnd']; |
---|
1743 | unset($data['commercialAnd']); |
---|
1744 | if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"')) |
---|
1745 | { |
---|
1746 | echo serialize(array( |
---|
1747 | 'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'), |
---|
1748 | 'status' => 'fatal' |
---|
1749 | )); |
---|
1750 | |
---|
1751 | return; |
---|
1752 | } |
---|
1753 | |
---|
1754 | if ($data['id_contact']) |
---|
1755 | { |
---|
1756 | $id = $data['id_contact']; |
---|
1757 | $id_photo = $id; |
---|
1758 | unset($data['id_contact']); |
---|
1759 | } |
---|
1760 | else |
---|
1761 | { |
---|
1762 | $id_photo = '_new_'; |
---|
1763 | } |
---|
1764 | |
---|
1765 | /* |
---|
1766 | * Process Photo, if available |
---|
1767 | */ |
---|
1768 | $sleep_count = 0; |
---|
1769 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
1770 | while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y') |
---|
1771 | { |
---|
1772 | sleep(1); |
---|
1773 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
1774 | $sleep_count++; |
---|
1775 | |
---|
1776 | if ($sleep_count > 35) |
---|
1777 | { |
---|
1778 | // TODO |
---|
1779 | return; |
---|
1780 | } |
---|
1781 | } |
---|
1782 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n')); |
---|
1783 | |
---|
1784 | if (isset($this->page_info['photos'][$id_photo])) |
---|
1785 | { |
---|
1786 | if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false) |
---|
1787 | { |
---|
1788 | echo serialize(array( |
---|
1789 | 'msg' => $this->page_info['photos'][$id_photo]['msg'], |
---|
1790 | 'status' => $this->page_info['photos'][$id_photo]['status'] |
---|
1791 | )); |
---|
1792 | |
---|
1793 | return; |
---|
1794 | } |
---|
1795 | |
---|
1796 | $data['photo'] = $this->page_info['photos'][$id_photo]['content']; |
---|
1797 | unset($this->page_info['photos'][$id_photo]); |
---|
1798 | $this->save_session(); |
---|
1799 | } |
---|
1800 | |
---|
1801 | /* |
---|
1802 | * Arrange Date so it gets inserted correctly |
---|
1803 | */ |
---|
1804 | |
---|
1805 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
1806 | |
---|
1807 | $j = 0; |
---|
1808 | for ($i = 0; $i < 5; $i+=2) |
---|
1809 | { |
---|
1810 | switch($dateformat{$i}) |
---|
1811 | { |
---|
1812 | case 'Y': |
---|
1813 | $date[$j]['size'] = 4; |
---|
1814 | $date[$j]['digit'] = 'Y'; |
---|
1815 | break; |
---|
1816 | |
---|
1817 | case 'm': |
---|
1818 | case 'M': |
---|
1819 | $date[$j]['size'] = 2; |
---|
1820 | $date[$j]['digit'] = 'M'; |
---|
1821 | break; |
---|
1822 | |
---|
1823 | case 'd': |
---|
1824 | $date[$j]['size'] = 2; |
---|
1825 | $date[$j]['digit'] = 'D'; |
---|
1826 | } |
---|
1827 | $j++; |
---|
1828 | } |
---|
1829 | $datecount = 0; |
---|
1830 | |
---|
1831 | /* Verify Data and performs insertion/update */ |
---|
1832 | foreach($data as $field => $value) |
---|
1833 | { |
---|
1834 | if ($value == '' or is_null($value)) |
---|
1835 | { |
---|
1836 | unset($data[$field]); |
---|
1837 | continue; |
---|
1838 | } |
---|
1839 | |
---|
1840 | switch($field) |
---|
1841 | { |
---|
1842 | case 'alias': |
---|
1843 | case 'given_names': |
---|
1844 | case 'family_names': |
---|
1845 | case 'names_ordered': |
---|
1846 | case 'pgp_key': |
---|
1847 | case 'notes': |
---|
1848 | case 'photo': |
---|
1849 | /* Do Nothing. This is just to make sure no invalid field is passed */ |
---|
1850 | break; |
---|
1851 | |
---|
1852 | case 'id_status': |
---|
1853 | case 'id_prefix': |
---|
1854 | case 'id_suffix': |
---|
1855 | if ($data[$field] == 0) |
---|
1856 | { |
---|
1857 | unset($data[$field]); |
---|
1858 | } |
---|
1859 | break; |
---|
1860 | |
---|
1861 | case 'birthdate_0': |
---|
1862 | case 'birthdate_1': |
---|
1863 | case 'birthdate_2': |
---|
1864 | |
---|
1865 | switch($date[$datecount]['digit']) |
---|
1866 | { |
---|
1867 | case 'Y': |
---|
1868 | $date['value'][2] = (int) $data[$field]; |
---|
1869 | break; |
---|
1870 | |
---|
1871 | case 'M': |
---|
1872 | $date['value'][0] = (int) $data[$field]; |
---|
1873 | break; |
---|
1874 | |
---|
1875 | case 'D': |
---|
1876 | $date['value'][1] = (int) $data[$field]; |
---|
1877 | break; |
---|
1878 | } |
---|
1879 | unset($data[$field]); |
---|
1880 | $datecount++; |
---|
1881 | |
---|
1882 | if ($datecount != 3) |
---|
1883 | { |
---|
1884 | break; |
---|
1885 | } |
---|
1886 | |
---|
1887 | if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2])) |
---|
1888 | { |
---|
1889 | echo serialize(array( |
---|
1890 | 'msg' => lang('Invalid Date'), |
---|
1891 | 'status' => 'invalid_data' |
---|
1892 | )); |
---|
1893 | return; |
---|
1894 | } |
---|
1895 | |
---|
1896 | $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1]; |
---|
1897 | break; |
---|
1898 | |
---|
1899 | case 'sex': |
---|
1900 | if ($data[$field] !== 'M' and $data[$field] !== 'F') |
---|
1901 | { |
---|
1902 | echo serialize(array( |
---|
1903 | 'msg' => lang('Invalid Sex'), |
---|
1904 | 'status' => 'invalid_data' |
---|
1905 | )); |
---|
1906 | return; |
---|
1907 | } |
---|
1908 | break; |
---|
1909 | |
---|
1910 | |
---|
1911 | case 'addresses': |
---|
1912 | /* Insert new cities/states */ |
---|
1913 | if (isset($value['new_states'])) |
---|
1914 | { |
---|
1915 | foreach($value['new_states'] as $type => $state_info) |
---|
1916 | { |
---|
1917 | $index = 'address'.$type; |
---|
1918 | |
---|
1919 | $id_state = $this->bo->catalog->add_state($state_info); |
---|
1920 | $data['addresses'][$index]['id_state'] = $id_state; |
---|
1921 | |
---|
1922 | if ($value['new_cities'][$type]) |
---|
1923 | { |
---|
1924 | $value['new_cities'][$type]['id_state'] = $id_state; |
---|
1925 | } |
---|
1926 | } |
---|
1927 | |
---|
1928 | unset($data['addresses']['new_states']); |
---|
1929 | } |
---|
1930 | |
---|
1931 | if (isset($value['new_cities'])) |
---|
1932 | { |
---|
1933 | foreach($value['new_cities'] as $type => $city_info) |
---|
1934 | { |
---|
1935 | $index = 'address'.$type; |
---|
1936 | |
---|
1937 | $id_city = $this->bo->catalog->add_city($city_info); |
---|
1938 | $data['addresses'][$index]['id_city'] = $id_city; |
---|
1939 | } |
---|
1940 | |
---|
1941 | unset($data['addresses']['new_cities']); |
---|
1942 | } |
---|
1943 | |
---|
1944 | break; |
---|
1945 | |
---|
1946 | case 'connections': |
---|
1947 | /* Does nothing... */ |
---|
1948 | break; |
---|
1949 | |
---|
1950 | default: |
---|
1951 | echo serialize(array( |
---|
1952 | 'msg' => lang('Invalid field: ').$field, |
---|
1953 | 'status' => 'invalid_data' |
---|
1954 | )); |
---|
1955 | return; |
---|
1956 | } |
---|
1957 | } |
---|
1958 | |
---|
1959 | $code = '$id = $this->bo->catalog->'; |
---|
1960 | |
---|
1961 | if (!is_null($id) and $id !== '') |
---|
1962 | { |
---|
1963 | $code .= $code.'update_single_info($id, $data);'; |
---|
1964 | $result = array( |
---|
1965 | 'msg' => lang('Updated Successfully!'), |
---|
1966 | 'status' => 'ok' |
---|
1967 | ); |
---|
1968 | } |
---|
1969 | else |
---|
1970 | { |
---|
1971 | $code .= 'add_single_entry($data);'; |
---|
1972 | $result = array( |
---|
1973 | 'msg' => lang('Entry Added Successfully!'), |
---|
1974 | 'status' => 'ok' |
---|
1975 | ); |
---|
1976 | } |
---|
1977 | |
---|
1978 | eval($code); |
---|
1979 | |
---|
1980 | if (!($id)) |
---|
1981 | { |
---|
1982 | $result = array( |
---|
1983 | 'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'. |
---|
1984 | 'Report the problem to the Administrator.'), |
---|
1985 | 'status' => 'fail' |
---|
1986 | ); |
---|
1987 | } |
---|
1988 | |
---|
1989 | echo serialize($result); |
---|
1990 | } |
---|
1991 | |
---|
1992 | /*! |
---|
1993 | |
---|
1994 | @function post_photo |
---|
1995 | @abstract Wrapper to post a photo without reload a page. |
---|
1996 | @author Raphael Derosso Pereira |
---|
1997 | |
---|
1998 | */ |
---|
1999 | function post_photo($id) |
---|
2000 | { |
---|
2001 | //print_r($_FILES); |
---|
2002 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y')); |
---|
2003 | |
---|
2004 | if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo'])) |
---|
2005 | { |
---|
2006 | $this->page_info['photos'][$id]['status'] = 'no_upload'; |
---|
2007 | $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.'); |
---|
2008 | |
---|
2009 | $this->save_session(); |
---|
2010 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2011 | return; |
---|
2012 | } |
---|
2013 | |
---|
2014 | if (!function_exists('imagecreate')) |
---|
2015 | { |
---|
2016 | $this->page_info['photos'][$id]['status'] = 'no_GD_lib'; |
---|
2017 | $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.'); |
---|
2018 | |
---|
2019 | $this->save_session(); |
---|
2020 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2021 | return; |
---|
2022 | } |
---|
2023 | |
---|
2024 | // TODO: Get Max Size from preferences! |
---|
2025 | if ($_FILES['cc_pd_photo']['size'] > 1000000) |
---|
2026 | { |
---|
2027 | $this->page_info['photos'][$id]['status'] = 'too_large'; |
---|
2028 | $this->page_info['photos'][$id]['msg'] = lang('Image too large! ContactCenter limits the image size to 1 Mb'); |
---|
2029 | |
---|
2030 | $this->save_session(); |
---|
2031 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2032 | return; |
---|
2033 | } |
---|
2034 | |
---|
2035 | if ($_FILES['cc_pd_photo']['error']) |
---|
2036 | { |
---|
2037 | $this->page_info['photos'][$id]['status'] = 'error'; |
---|
2038 | $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']; |
---|
2039 | |
---|
2040 | $this->save_session(); |
---|
2041 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2042 | return; |
---|
2043 | } |
---|
2044 | |
---|
2045 | switch($_FILES['cc_pd_photo']['type']) |
---|
2046 | { |
---|
2047 | case 'image/jpeg': |
---|
2048 | case 'image/pjpeg': |
---|
2049 | $src_img = imagecreatefromjpeg($_FILES['cc_pd_photo']['tmp_name']); |
---|
2050 | if ($src_img == '') |
---|
2051 | { |
---|
2052 | $bogus = true; |
---|
2053 | } |
---|
2054 | break; |
---|
2055 | |
---|
2056 | case 'image/png': |
---|
2057 | case 'image/x-png': |
---|
2058 | $src_img = imagecreatefrompng($_FILES['cc_pd_photo']['tmp_name']); |
---|
2059 | if ($src_img == '') |
---|
2060 | { |
---|
2061 | $bogus = true; |
---|
2062 | } |
---|
2063 | break; |
---|
2064 | |
---|
2065 | case 'image/gif': |
---|
2066 | $src_img = imagecreatefromgif($_FILES['cc_pd_photo']['tmp_name']); |
---|
2067 | if ($src_img == '') |
---|
2068 | { |
---|
2069 | $bogus = true; |
---|
2070 | } |
---|
2071 | break; |
---|
2072 | |
---|
2073 | default: |
---|
2074 | |
---|
2075 | $this->page_info['photos'][$id]['status'] = 'invalid_image'; |
---|
2076 | $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.'); |
---|
2077 | |
---|
2078 | $this->save_session(); |
---|
2079 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2080 | return; |
---|
2081 | } |
---|
2082 | |
---|
2083 | if ($bogus) |
---|
2084 | { |
---|
2085 | $this->page_info['photos'][$id]['status'] = 'invalid_file'; |
---|
2086 | $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); |
---|
2087 | |
---|
2088 | $this->save_session(); |
---|
2089 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2090 | return; |
---|
2091 | } |
---|
2092 | |
---|
2093 | $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']); |
---|
2094 | $dst_img = imagecreatetruecolor(60, 80); |
---|
2095 | |
---|
2096 | if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1])) |
---|
2097 | { |
---|
2098 | $this->page_info['photos'][$id]['status'] = 'invalid_file'; |
---|
2099 | $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); |
---|
2100 | |
---|
2101 | $this->save_session(); |
---|
2102 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2103 | return; |
---|
2104 | } |
---|
2105 | |
---|
2106 | ob_start(); |
---|
2107 | imagepng($dst_img); |
---|
2108 | $this->page_info['photos'][$id]['content'] = ob_get_contents(); |
---|
2109 | ob_end_clean(); |
---|
2110 | |
---|
2111 | $this->page_info['photos'][$id]['status'] = 'changed'; |
---|
2112 | $this->page_info['photos'][$id]['msg'] = lang('Photo Successfully Updated!'); |
---|
2113 | |
---|
2114 | $this->save_session(); |
---|
2115 | |
---|
2116 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
2117 | |
---|
2118 | imagedestroy($src_img); |
---|
2119 | imagedestroy($dst_img); |
---|
2120 | echo 'ok'; |
---|
2121 | return; |
---|
2122 | } |
---|
2123 | |
---|
2124 | |
---|
2125 | /*! |
---|
2126 | |
---|
2127 | @function get_photo |
---|
2128 | @abstract Returns the photo to the browser |
---|
2129 | @author Raphael Derosso Pereira |
---|
2130 | |
---|
2131 | */ |
---|
2132 | function get_photo($id) |
---|
2133 | { |
---|
2134 | $fields = $this->bo->catalog->get_fields(false); |
---|
2135 | $fields['photo'] = true; |
---|
2136 | |
---|
2137 | $contact = $this->bo->catalog->get_single_entry($id, $fields); |
---|
2138 | |
---|
2139 | if (!$contact['photo']) |
---|
2140 | { |
---|
2141 | header('Content-type: image/png'); |
---|
2142 | echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png'); |
---|
2143 | return; |
---|
2144 | } |
---|
2145 | |
---|
2146 | header('Content-type: image/jpeg'); |
---|
2147 | $photo = imagecreatefromstring ($contact['photo']); |
---|
2148 | $width = imagesx($photo); |
---|
2149 | $height = imagesy($photo); |
---|
2150 | $twidth = 70; |
---|
2151 | $theight = 90; |
---|
2152 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
2153 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
2154 | imagejpeg($small_photo,"",100); |
---|
2155 | return; |
---|
2156 | } |
---|
2157 | |
---|
2158 | /*! |
---|
2159 | |
---|
2160 | @function get_states |
---|
2161 | @abstract Echos a serialized array containing all the states for the given country |
---|
2162 | @author Raphael Derosso Pereira |
---|
2163 | |
---|
2164 | @params $id_country The ID of the Country that contains the requested states |
---|
2165 | |
---|
2166 | */ |
---|
2167 | function get_states($id_country) |
---|
2168 | { |
---|
2169 | $states = $this->bo->catalog->get_all_states($id_country); |
---|
2170 | |
---|
2171 | if (!$states) |
---|
2172 | { |
---|
2173 | $result = array( |
---|
2174 | 'msg' => lang('No States found for this Country.'), |
---|
2175 | 'status' => 'empty' |
---|
2176 | ); |
---|
2177 | |
---|
2178 | echo serialize($result); |
---|
2179 | return; |
---|
2180 | } |
---|
2181 | |
---|
2182 | $result = array( |
---|
2183 | 'msg' => lang('States Successfully retrieved!'), |
---|
2184 | 'status' => 'ok' |
---|
2185 | ); |
---|
2186 | |
---|
2187 | foreach ($states as $state_info) |
---|
2188 | { |
---|
2189 | $result['data'][$state_info['id_state']] = $state_info['name']; |
---|
2190 | |
---|
2191 | if ($state_info['symbol']) |
---|
2192 | { |
---|
2193 | $result['data'][$state_info['id_state']] .= ', '.$state_info['symbol']; |
---|
2194 | } |
---|
2195 | } |
---|
2196 | |
---|
2197 | echo serialize($result); |
---|
2198 | } |
---|
2199 | |
---|
2200 | /*! |
---|
2201 | |
---|
2202 | @function get_cities |
---|
2203 | @abstract Echos a serialized array containing all the cities of a given state |
---|
2204 | @author Raphael Derosso Pereira |
---|
2205 | |
---|
2206 | @param $id_country The ID of the Country that has the specified Cities (in case the |
---|
2207 | Country doesn't have any States) |
---|
2208 | @param $id_state The ID of the State that has the Cities requested |
---|
2209 | |
---|
2210 | */ |
---|
2211 | function get_cities($id_country, $id_state=false) |
---|
2212 | { |
---|
2213 | $cities = $this->bo->catalog->get_all_cities($id_country, $id_state); |
---|
2214 | |
---|
2215 | if (!$cities) |
---|
2216 | { |
---|
2217 | $result = array( |
---|
2218 | 'msg' => lang('No Cities found for this State.'), |
---|
2219 | 'status' => 'empty' |
---|
2220 | ); |
---|
2221 | |
---|
2222 | echo serialize($result); |
---|
2223 | return; |
---|
2224 | } |
---|
2225 | |
---|
2226 | $result = array( |
---|
2227 | 'msg' => lang('Cities Successfully retrieved!'), |
---|
2228 | 'status' => 'ok' |
---|
2229 | ); |
---|
2230 | |
---|
2231 | foreach ($cities as $city_info) |
---|
2232 | { |
---|
2233 | $result['data'][$city_info['id_city']] = $city_info['name']; |
---|
2234 | } |
---|
2235 | |
---|
2236 | echo serialize($result); |
---|
2237 | } |
---|
2238 | |
---|
2239 | |
---|
2240 | /*! |
---|
2241 | |
---|
2242 | @function search |
---|
2243 | @abstract Echos a serialized array containing the IDs |
---|
2244 | of the entries that matches the search argument |
---|
2245 | @author Raphael Derosso Pereira |
---|
2246 | @author Mário César Kolling (external catalogs) |
---|
2247 | |
---|
2248 | @param string $str_data A serialized array with two informations: |
---|
2249 | $data = array( |
---|
2250 | 'search_for' => (string), |
---|
2251 | 'recursive' => (boolean), |
---|
2252 | ); |
---|
2253 | |
---|
2254 | */ |
---|
2255 | // SERPRO |
---|
2256 | function search($str_data) |
---|
2257 | { |
---|
2258 | $data = unserialize($str_data); |
---|
2259 | // It's an external catalog? |
---|
2260 | $external = $this->bo->is_external($this->page_info['actual_catalog']); |
---|
2261 | |
---|
2262 | if (!is_array($data) || !$data['search_for'] || !is_array($data['fields'])) |
---|
2263 | { |
---|
2264 | echo serialize(array( |
---|
2265 | 'msg' => lang('Invalid parameters'), |
---|
2266 | 'status' => 'abort' |
---|
2267 | )); |
---|
2268 | |
---|
2269 | return array('error' => lang('Invalid parameters')); |
---|
2270 | } |
---|
2271 | |
---|
2272 | |
---|
2273 | /* |
---|
2274 | * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly |
---|
2275 | */ |
---|
2276 | // Support search parameters with accentuation |
---|
2277 | if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && |
---|
2278 | $this->page_info['actual_catalog']['class'] != 'bo_group_manager' && |
---|
2279 | $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && |
---|
2280 | $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
2281 | { |
---|
2282 | |
---|
2283 | $data['search_for'] = utf8_encode($data['search_for']); |
---|
2284 | } |
---|
2285 | |
---|
2286 | $rules = array(); |
---|
2287 | |
---|
2288 | |
---|
2289 | if ($data['search_for'] === '*') |
---|
2290 | { |
---|
2291 | $rules = array( |
---|
2292 | 0 => array( |
---|
2293 | 'field' => $data['fields']['search'], |
---|
2294 | 'type' => 'LIKE', |
---|
2295 | 'value' => '%' |
---|
2296 | ) |
---|
2297 | ); |
---|
2298 | } |
---|
2299 | else |
---|
2300 | { |
---|
2301 | $names = explode(' ', $data['search_for']); |
---|
2302 | |
---|
2303 | if (!is_array($names)) |
---|
2304 | { |
---|
2305 | echo serialize(array( |
---|
2306 | 'msg' => lang('Invalid Search Parameter'), |
---|
2307 | 'status' => 'abort' |
---|
2308 | )); |
---|
2309 | |
---|
2310 | } |
---|
2311 | |
---|
2312 | if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && |
---|
2313 | $this->page_info['actual_catalog']['class'] != 'bo_group_manager' && |
---|
2314 | $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && |
---|
2315 | $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager' ) |
---|
2316 | { |
---|
2317 | /* |
---|
2318 | * Restrict the returned contacts search to objectClass = phpgwAccount, |
---|
2319 | * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1 |
---|
2320 | */ |
---|
2321 | $rules = array( |
---|
2322 | 0 => array( |
---|
2323 | 'field' => 'contact.object_class', |
---|
2324 | 'type' => '=', |
---|
2325 | 'value' => 'phpgwAccount' |
---|
2326 | ), |
---|
2327 | 1 => array( |
---|
2328 | 'field' => 'contact.account_status', |
---|
2329 | 'type' => 'iLIKE', |
---|
2330 | 'value' => '%' |
---|
2331 | ), |
---|
2332 | 2 => array( |
---|
2333 | 'field' => 'contact.account_visible', |
---|
2334 | 'type' => '!=', |
---|
2335 | 'value' => '-1' |
---|
2336 | ), |
---|
2337 | ); |
---|
2338 | } |
---|
2339 | |
---|
2340 | foreach ($names as $name) |
---|
2341 | { |
---|
2342 | if ($name != '') |
---|
2343 | { |
---|
2344 | array_push($rules, array( |
---|
2345 | 'field' => $data['fields']['search'], |
---|
2346 | 'type' => 'iLIKE', |
---|
2347 | 'value' => '%'.$name.'%' |
---|
2348 | )); |
---|
2349 | } |
---|
2350 | } |
---|
2351 | } |
---|
2352 | |
---|
2353 | if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' || |
---|
2354 | $this->page_info['actual_catalog']['class'] == 'bo_group_manager' || |
---|
2355 | $this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager' || |
---|
2356 | $this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager' ) |
---|
2357 | { |
---|
2358 | // Get only this attributes: dn, cn for external catalogs, |
---|
2359 | // used to restrict the attributes used in filters |
---|
2360 | $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
2361 | } |
---|
2362 | else |
---|
2363 | { |
---|
2364 | // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible |
---|
2365 | // for non-external catalogs, used to restrict the attributes used in filters |
---|
2366 | $ids = $this->bo->find(array( |
---|
2367 | $data['fields']['id'], |
---|
2368 | $data['fields']['search'], |
---|
2369 | 'contact.object_class', |
---|
2370 | //'contact.account_status', |
---|
2371 | 'contact.account_visible' |
---|
2372 | ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
2373 | } |
---|
2374 | |
---|
2375 | if (!is_array($ids) || !count($ids)) |
---|
2376 | { |
---|
2377 | $this->last_search_ids = null; |
---|
2378 | $this->save_session(); |
---|
2379 | return null; |
---|
2380 | } |
---|
2381 | |
---|
2382 | $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1); |
---|
2383 | |
---|
2384 | $ids_f = array(); |
---|
2385 | |
---|
2386 | foreach ($ids as $e_info) |
---|
2387 | { |
---|
2388 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
2389 | $ids_f[] = $e_info[$id_field]; |
---|
2390 | else |
---|
2391 | $ids_f[] = array(0=>$e_info[$id_field],1=>$e_info['perms']); |
---|
2392 | } |
---|
2393 | |
---|
2394 | return $ids_f; |
---|
2395 | } |
---|
2396 | |
---|
2397 | // CELEPAR |
---|
2398 | /* |
---|
2399 | function search($str_data) |
---|
2400 | { |
---|
2401 | $data = unserialize($str_data); |
---|
2402 | |
---|
2403 | if (!is_array($data) || !$data['search_for'] || !is_array($data['fields'])) |
---|
2404 | { |
---|
2405 | echo serialize(array( |
---|
2406 | 'msg' => lang('Invalid parameters'), |
---|
2407 | 'status' => 'abort' |
---|
2408 | )); |
---|
2409 | |
---|
2410 | return; |
---|
2411 | } |
---|
2412 | |
---|
2413 | $rules = array(); |
---|
2414 | |
---|
2415 | if ($data['search_for'] === '*') |
---|
2416 | { |
---|
2417 | $rules = array( |
---|
2418 | 0 => array( |
---|
2419 | 'field' => $data['fields']['search'], |
---|
2420 | 'type' => 'LIKE', |
---|
2421 | 'value' => '%' |
---|
2422 | ) |
---|
2423 | ); |
---|
2424 | } |
---|
2425 | else |
---|
2426 | { |
---|
2427 | $names = explode(' ', $data['search_for']); |
---|
2428 | |
---|
2429 | if (!is_array($names)) |
---|
2430 | { |
---|
2431 | echo serialize(array( |
---|
2432 | 'msg' => lang('Invalid Search Parameter'), |
---|
2433 | 'status' => 'abort' |
---|
2434 | )); |
---|
2435 | |
---|
2436 | return; |
---|
2437 | } |
---|
2438 | |
---|
2439 | foreach ($names as $name) |
---|
2440 | { |
---|
2441 | if ($name != '') |
---|
2442 | { |
---|
2443 | array_push($rules, array( |
---|
2444 | 'field' => $data['fields']['search'], |
---|
2445 | 'type' => 'iLIKE', |
---|
2446 | 'value' => '%'.$name.'%' |
---|
2447 | )); |
---|
2448 | } |
---|
2449 | } |
---|
2450 | } |
---|
2451 | |
---|
2452 | |
---|
2453 | |
---|
2454 | //$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); |
---|
2455 | |
---|
2456 | //if ($catalog['class'] === 'bo_people_catalog') |
---|
2457 | //{ |
---|
2458 | // array_push($rules, array( |
---|
2459 | // 'field' => 'contact.id_owner', |
---|
2460 | // 'type' => '=', |
---|
2461 | // 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
2462 | // )); |
---|
2463 | //} |
---|
2464 | |
---|
2465 | |
---|
2466 | $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
2467 | |
---|
2468 | if (!is_array($ids) || !count($ids)) |
---|
2469 | { |
---|
2470 | echo serialize(array( |
---|
2471 | 'msg' => lang('No Entries Found!'), |
---|
2472 | 'status' => 'empty' |
---|
2473 | )); |
---|
2474 | |
---|
2475 | return; |
---|
2476 | } |
---|
2477 | $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1); |
---|
2478 | |
---|
2479 | $ids_f = array(); |
---|
2480 | foreach ($ids as $e_info) |
---|
2481 | { |
---|
2482 | $ids_f[] = $e_info[$id_field]; |
---|
2483 | } |
---|
2484 | |
---|
2485 | echo serialize(array( |
---|
2486 | 'data' => $ids_f, |
---|
2487 | 'msg' => lang('Found %1 Entries', count($ids)), |
---|
2488 | 'status' => 'ok' |
---|
2489 | )); |
---|
2490 | |
---|
2491 | return; |
---|
2492 | }*/ |
---|
2493 | /*! |
---|
2494 | |
---|
2495 | @function get_multiple_entries |
---|
2496 | @abstract Returns an array containing the specifiend data in the default |
---|
2497 | CC UI format |
---|
2498 | @author Raphael Derosso Pereira |
---|
2499 | |
---|
2500 | @param array str_data A serialized array containing the ID's of the entries |
---|
2501 | to be taken, the fields to be taken and the rules to be used on the |
---|
2502 | retrieval: |
---|
2503 | $data = array( |
---|
2504 | 'ids' => array(...), |
---|
2505 | 'fields' => array(...), |
---|
2506 | 'rules' => array(...) |
---|
2507 | ); |
---|
2508 | |
---|
2509 | */ |
---|
2510 | function get_multiple_entries($str_data) |
---|
2511 | { |
---|
2512 | $data = unserialize($str_data); |
---|
2513 | |
---|
2514 | if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids'])) |
---|
2515 | { |
---|
2516 | return array( |
---|
2517 | 'msg' => lang('Invalid Parameters'), |
---|
2518 | 'status' => 'abort' |
---|
2519 | ); |
---|
2520 | } |
---|
2521 | |
---|
2522 | $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']); |
---|
2523 | |
---|
2524 | if (!is_array($entries) or !count($entries)) |
---|
2525 | { |
---|
2526 | return array( |
---|
2527 | 'msg' => lang('No Entries Found!'), |
---|
2528 | 'status' => 'empty' |
---|
2529 | ); |
---|
2530 | } |
---|
2531 | |
---|
2532 | return array( |
---|
2533 | 'msg' => lang('Found %1 Entries!', count($entries)), |
---|
2534 | 'status' => 'ok', |
---|
2535 | 'data' => $entries |
---|
2536 | ); |
---|
2537 | } |
---|
2538 | |
---|
2539 | /* |
---|
2540 | |
---|
2541 | @function get_all_entries |
---|
2542 | @abstract Returns the specified fields for all catalog's entries |
---|
2543 | in the default CC UI format |
---|
2544 | @author Raphael Derosso Pereira |
---|
2545 | |
---|
2546 | @params array str_data A serialized array containing the fields to |
---|
2547 | be grabbed, the maximum number of entries to be returned and a |
---|
2548 | boolean specifying if the calls refers to a new grab or to an |
---|
2549 | unfinished one. |
---|
2550 | |
---|
2551 | */ |
---|
2552 | function get_all_entries($str_data) |
---|
2553 | { |
---|
2554 | $data = unserialize($str_data); |
---|
2555 | |
---|
2556 | if (!is_array($data) or |
---|
2557 | !count($data) or |
---|
2558 | !count($data['fields']) or |
---|
2559 | !$data['maxlength'] or |
---|
2560 | (!$data['new'] and !$data['offset'])) |
---|
2561 | { |
---|
2562 | return array( |
---|
2563 | 'msg' => lang('Invalid Parameters'), |
---|
2564 | 'status' => 'abort' |
---|
2565 | ); |
---|
2566 | } |
---|
2567 | |
---|
2568 | if ($data['new']) |
---|
2569 | { |
---|
2570 | $this->all_entries = $this->bo->catalog->get_all_entries_ids(); |
---|
2571 | |
---|
2572 | $this->save_session(); |
---|
2573 | |
---|
2574 | if (!is_array($this->all_entries) or !count($this->all_entries)) |
---|
2575 | { |
---|
2576 | return array( |
---|
2577 | 'msg' => lang('No Entries Found!'), |
---|
2578 | 'status' => 'empty' |
---|
2579 | ); |
---|
2580 | } |
---|
2581 | |
---|
2582 | $data['offset'] = 0; |
---|
2583 | } |
---|
2584 | |
---|
2585 | if ($data['maxlength'] != -1) |
---|
2586 | { |
---|
2587 | $result = $this->bo->catalog->get_multiple_entries(array_slice($this->all_entries, $data['offset'], $data['maxlength']), $data['fields']); |
---|
2588 | } |
---|
2589 | else |
---|
2590 | { |
---|
2591 | $result = $this->bo->catalog->get_multiple_entries($this->all_entries, $data['fields']); |
---|
2592 | } |
---|
2593 | |
---|
2594 | $prefs = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
2595 | |
---|
2596 | $jsCode = array(); |
---|
2597 | $count = 0; |
---|
2598 | foreach ($result as $each) |
---|
2599 | { |
---|
2600 | if (!is_array($each)) |
---|
2601 | { |
---|
2602 | continue; |
---|
2603 | } |
---|
2604 | |
---|
2605 | if($this-> typeContact == 'groups') { |
---|
2606 | |
---|
2607 | foreach ($each as $field => $value) { |
---|
2608 | |
---|
2609 | if ($field === 'title') { |
---|
2610 | $optionName = '\\"'.$value.'\\"'; |
---|
2611 | |
---|
2612 | } |
---|
2613 | else if ($field === 'short_name') { |
---|
2614 | |
---|
2615 | $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");'; |
---|
2616 | $count++; |
---|
2617 | } |
---|
2618 | } |
---|
2619 | } |
---|
2620 | |
---|
2621 | else { |
---|
2622 | foreach ($each as $field => $value) { |
---|
2623 | if ($field === 'names_ordered') { |
---|
2624 | if(is_array($value)) |
---|
2625 | $value = $value[0]; |
---|
2626 | $name = '\\"'.$value.'\\"'; |
---|
2627 | } |
---|
2628 | else if ($field === 'connections') { |
---|
2629 | |
---|
2630 | foreach ($value as $connection) { |
---|
2631 | if ($connection['id_type'] == $prefs['personCardEmail']) { |
---|
2632 | $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$name.' <'.$connection['connection_value'].'>", "'.$count.'");'; |
---|
2633 | $count++; |
---|
2634 | } |
---|
2635 | } |
---|
2636 | } |
---|
2637 | } |
---|
2638 | } |
---|
2639 | } |
---|
2640 | |
---|
2641 | $jsCodeFinal = implode("\n", $jsCode); |
---|
2642 | |
---|
2643 | $nEntries = count($result); |
---|
2644 | |
---|
2645 | if (!$nEntries) |
---|
2646 | { |
---|
2647 | return array( |
---|
2648 | 'msg' => lang('Error while getting user information...'), |
---|
2649 | 'status' => 'abort' |
---|
2650 | ); |
---|
2651 | } |
---|
2652 | |
---|
2653 | return array( |
---|
2654 | 'msg' => lang('Found %1 Entries!', $nEntries), |
---|
2655 | 'status' => 'ok', |
---|
2656 | 'typeContact' => $this -> typeContact, |
---|
2657 | 'final' => $nEntries + $data['offset'] < count($this->all_entries) ? false : true, |
---|
2658 | 'offset' => $data['offset'] + $nEntries, |
---|
2659 | 'data' => $jsCodeFinal |
---|
2660 | ); |
---|
2661 | } |
---|
2662 | |
---|
2663 | /*********************************************************************\ |
---|
2664 | * Auxiliar Methods * |
---|
2665 | \*********************************************************************/ |
---|
2666 | |
---|
2667 | /*! |
---|
2668 | |
---|
2669 | @function save_session |
---|
2670 | @abstract Saves the data on the session |
---|
2671 | @author Raphael Derosso Pereira |
---|
2672 | |
---|
2673 | */ |
---|
2674 | function save_session() |
---|
2675 | { |
---|
2676 | $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info); |
---|
2677 | $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries); |
---|
2678 | } |
---|
2679 | |
---|
2680 | /*! |
---|
2681 | |
---|
2682 | @function convert_tree |
---|
2683 | @abstract Converts the tree array in the BO format to a JS tree array compatible |
---|
2684 | with the one available in eGW |
---|
2685 | @author Raphael Derosso Pereira |
---|
2686 | |
---|
2687 | @param (array) $tree The tree in the BO format |
---|
2688 | @param (string) $name The tree name |
---|
2689 | @param (string) $iconDir The dir where the icons are |
---|
2690 | @param (string) $parent The parent |
---|
2691 | */ |
---|
2692 | |
---|
2693 | function convert_tree($tree, &$iconDir, $parent='0') |
---|
2694 | { |
---|
2695 | // echo "Entrou<br>\tPai: $parent <br>"; |
---|
2696 | $rtree = array(); |
---|
2697 | |
---|
2698 | if ($parent === '0') |
---|
2699 | { |
---|
2700 | // echo 'Root!<br>'; |
---|
2701 | $rtree['0'] = array( |
---|
2702 | 'type' => 'catalog_group', |
---|
2703 | 'id' => '0', |
---|
2704 | 'pid' => 'none', |
---|
2705 | 'caption' => lang('Catalogues'), |
---|
2706 | 'class' => 'bo_catalog_group_catalog', |
---|
2707 | 'class_args' => array('_ROOT_', '$this', '$this->get_branch_by_level($this->catalog_level[0])') |
---|
2708 | ); |
---|
2709 | } |
---|
2710 | |
---|
2711 | foreach($tree as $id => $value) |
---|
2712 | { |
---|
2713 | // echo 'ID: '.$id.'<br>'; |
---|
2714 | $rtree[$parent.'.'.$id] = array( |
---|
2715 | 'type' => $value['type'], |
---|
2716 | 'id' => $parent.'.'.$id, |
---|
2717 | 'pid' => $parent, |
---|
2718 | 'caption' => $value['name'] |
---|
2719 | ); |
---|
2720 | |
---|
2721 | switch($value['type']) |
---|
2722 | { |
---|
2723 | case 'catalog_group': |
---|
2724 | case 'mixed_catalog_group': |
---|
2725 | $rtree = $rtree + $this->convert_tree($value['sub_branch'],$iconDir,$parent.'.'.$id); |
---|
2726 | break; |
---|
2727 | } |
---|
2728 | } |
---|
2729 | |
---|
2730 | if (count($rtree)) |
---|
2731 | { |
---|
2732 | return $rtree; |
---|
2733 | } |
---|
2734 | } |
---|
2735 | |
---|
2736 | function get_catalog_add_contact($id){ |
---|
2737 | |
---|
2738 | $array_participants = array(); |
---|
2739 | if(!$this->bo->catalog->src_info) { |
---|
2740 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
2741 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
2742 | } |
---|
2743 | |
---|
2744 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
2745 | $dn=$this->bo->catalog->src_info['dn']; |
---|
2746 | $justThese = array("givenname","givenname","sn","telephonenumber","mail"); |
---|
2747 | $sr = ldap_read($ds,$id, "objectClass=*",$justThese); |
---|
2748 | $info = ldap_get_entries($ds, $sr); |
---|
2749 | for($z = 0; $z < 5; $z++) { |
---|
2750 | $participant = $info[0][$justThese[$z]]; |
---|
2751 | array_push($array_participants, $participant); |
---|
2752 | } |
---|
2753 | |
---|
2754 | ldap_close($ds); |
---|
2755 | echo serialize($array_participants); |
---|
2756 | } |
---|
2757 | |
---|
2758 | function get_catalog_participants_group($id) |
---|
2759 | { |
---|
2760 | if(!$this->bo->catalog->src_info) { |
---|
2761 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
2762 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
2763 | } |
---|
2764 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
2765 | $justThese = array("description","memberuid"); |
---|
2766 | $sr = ldap_read($ds,$id, "objectClass=*",$justThese); |
---|
2767 | $info = ldap_get_entries($ds, $sr); |
---|
2768 | $member_uids = $info[0]['memberuid']; |
---|
2769 | $contact['names_ordered'] = $info[0]['description']; |
---|
2770 | $filter = ""; |
---|
2771 | for($z = 0; $z < count($member_uids); $z++) { |
---|
2772 | if($member_uids[$z]) |
---|
2773 | $filter.="(uid=".$member_uids[$z].")"; |
---|
2774 | } |
---|
2775 | $array_participants = array(); |
---|
2776 | if($filter) { |
---|
2777 | $filter = "(|".$filter.")"; |
---|
2778 | $valarray = explode(',',$id); |
---|
2779 | array_shift($valarray); |
---|
2780 | $dn = implode(',',$valarray); |
---|
2781 | $justThese = array("cn","mail"); |
---|
2782 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
2783 | $info = ldap_get_entries($ds, $sr); |
---|
2784 | for($z = 0; $z < $info['count']; $z++) { |
---|
2785 | $participant = '<font color=\'DARKBLUE\'> "'.$info[$z]['cn'][0].'" <'.$info[$z]['mail'][0].'></font><br>'; |
---|
2786 | $array_emails[$info[$z]['mail'][0]] = null; |
---|
2787 | array_push($array_participants, $participant); |
---|
2788 | } |
---|
2789 | ldap_close($ds); |
---|
2790 | } |
---|
2791 | sort($array_participants); |
---|
2792 | $innerHTML = ''; |
---|
2793 | foreach($array_participants as $index => $participant){ |
---|
2794 | $innerHTML .= $participant; |
---|
2795 | } |
---|
2796 | $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); |
---|
2797 | echo serialize($return); |
---|
2798 | } |
---|
2799 | |
---|
2800 | function get_catalog_participants_list($id) |
---|
2801 | { |
---|
2802 | |
---|
2803 | $fields = $this->bo->catalog->get_fields(false); |
---|
2804 | $fields['names_ordered'] = true; |
---|
2805 | $fields['mail_forwarding_address'] = true; |
---|
2806 | $contact = $this->bo->catalog->get_single_entry($id,$fields); |
---|
2807 | |
---|
2808 | $array_participants = array(); |
---|
2809 | $array_emails = array(); |
---|
2810 | |
---|
2811 | $filter = null; |
---|
2812 | for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) { |
---|
2813 | if(strstr($contact['mail_forwarding_address'][$z],'@')) { |
---|
2814 | $filter.="(mail=".$contact['mail_forwarding_address'][$z].")"; |
---|
2815 | $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>"; |
---|
2816 | } |
---|
2817 | else |
---|
2818 | $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>"; |
---|
2819 | } |
---|
2820 | |
---|
2821 | if($filter) { |
---|
2822 | $filter = "(|".$filter.")"; |
---|
2823 | if(!$this->bo->catalog->src_info) { |
---|
2824 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
2825 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
2826 | } |
---|
2827 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
2828 | |
---|
2829 | $dn=$this->bo->catalog->src_info['dn']; |
---|
2830 | $justThese = array("cn","mail"); |
---|
2831 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
2832 | $info = ldap_get_entries($ds, $sr); |
---|
2833 | for($z = 0; $z < $info['count']; $z++) { |
---|
2834 | $participant = '<font color=\'DARKBLUE\'> "'.$info[$z]['cn'][0].'" <'.$info[$z]['mail'][0].'></font><br>'; |
---|
2835 | $array_emails[$info[$z]['mail'][0]] = null; |
---|
2836 | array_push($array_participants, $participant); |
---|
2837 | } |
---|
2838 | |
---|
2839 | foreach($array_emails as $index => $email) |
---|
2840 | if($email) |
---|
2841 | array_push($array_participants, " ".$email."<br>"); |
---|
2842 | |
---|
2843 | ldap_close($ds); |
---|
2844 | } |
---|
2845 | sort($array_participants); |
---|
2846 | $innerHTML = ''; |
---|
2847 | foreach($array_participants as $index => $participant){ |
---|
2848 | $innerHTML .= $participant; |
---|
2849 | } |
---|
2850 | $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); |
---|
2851 | echo serialize($return); |
---|
2852 | } |
---|
2853 | |
---|
2854 | function export_contacts($typeExport){ |
---|
2855 | |
---|
2856 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
2857 | $contacts = $boGroup->get_all_contacts(); |
---|
2858 | $streamBuffer = ''; |
---|
2859 | |
---|
2860 | if(!count($contacts)) |
---|
2861 | echo null; |
---|
2862 | |
---|
2863 | switch($typeExport) { |
---|
2864 | |
---|
2865 | case 'outlook_en': |
---|
2866 | $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;". |
---|
2867 | "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n"; |
---|
2868 | foreach($contacts as $index => $object){ |
---|
2869 | $streamBuffer.= $object['names_ordered'].";".$object['connection_value'].";;;;;;".$object['phone'].";;;\r\n"; |
---|
2870 | } |
---|
2871 | break; |
---|
2872 | |
---|
2873 | case 'outlook_pt-BR': |
---|
2874 | $streamBuffer = "Nome;End. de email;Endereço residencial;". |
---|
2875 | "Cidade do endereço residencial;CEP do endereço residencial;". |
---|
2876 | "Estado;País/região do endereço residencial;Telefone residencial;". |
---|
2877 | "Rua do endereço comercial;Cidade do endereço comercial;". |
---|
2878 | "CEP do endereço comercial;Estado do endereço comercial;". |
---|
2879 | "País/região do endereço comercial;Telefone comercial;Empresa;Cargo\r\n"; |
---|
2880 | foreach($contacts as $index => $object){ |
---|
2881 | $streamBuffer.= $object['names_ordered'].";".$object['connection_value'].";;;;;;".$object['phone'].";;;;;;;;\r\n"; |
---|
2882 | } |
---|
2883 | break; |
---|
2884 | |
---|
2885 | case 'outlook2000_pt-BR': |
---|
2886 | $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",". |
---|
2887 | "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",". |
---|
2888 | "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",". |
---|
2889 | "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",". |
---|
2890 | "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",". |
---|
2891 | "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",". |
---|
2892 | "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",". |
---|
2893 | "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",". |
---|
2894 | "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",". |
---|
2895 | "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",". |
---|
2896 | "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",". |
---|
2897 | "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",". |
---|
2898 | "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",". |
---|
2899 | "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",". |
---|
2900 | "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",". |
---|
2901 | "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",". |
---|
2902 | "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",". |
---|
2903 | "\"Sexo\"\r\n"; |
---|
2904 | foreach($contacts as $index => $object){ |
---|
2905 | $streamBuffer.= ",\"".$object['names_ordered']."\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,".$object['phone'].",,,,,,,,,,,,\"".$object['connection_value']."\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; |
---|
2906 | } |
---|
2907 | break; |
---|
2908 | |
---|
2909 | case 'outlook2000_en': |
---|
2910 | $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,". |
---|
2911 | "Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,". |
---|
2912 | "Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,". |
---|
2913 | "Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,". |
---|
2914 | "Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,". |
---|
2915 | "Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,". |
---|
2916 | "Account,Anniversary,Assistant's Name,Billing Information,Birthday,Categories,Children,Directory Server,E-mail Address,". |
---|
2917 | "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,". |
---|
2918 | "Gender,Government ID Number,Hobby,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,". |
---|
2919 | "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"; |
---|
2920 | foreach($contacts as $index => $object){ |
---|
2921 | $streamBuffer.= ",".$object['names_ordered'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,".$object['phone'].",,,,,,,,,,,,".$object['connection_value'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; |
---|
2922 | } |
---|
2923 | break; |
---|
2924 | |
---|
2925 | case 'thunderbird': |
---|
2926 | $streamBuffer = "\n"; |
---|
2927 | foreach($contacts as $index => $object){ |
---|
2928 | $streamBuffer.= ",,".$object['names_ordered'].",,".$object['connection_value'].",,".$object['phone'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; |
---|
2929 | } |
---|
2930 | break; |
---|
2931 | |
---|
2932 | case 'expresso': |
---|
2933 | $streamBuffer = "Nome,Email,Telefone\r\n"; |
---|
2934 | foreach($contacts as $index => $object){ |
---|
2935 | $streamBuffer.= $object['names_ordered'].",".$object['connection_value'].",".$object['phone']."\r\n"; |
---|
2936 | } |
---|
2937 | break; |
---|
2938 | |
---|
2939 | } |
---|
2940 | |
---|
2941 | $file = "contacts_".md5(microtime()).".swp"; |
---|
2942 | $tempDir = ini_get("session.save_path"); |
---|
2943 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
2944 | if(!$f) |
---|
2945 | echo null; |
---|
2946 | |
---|
2947 | fputs($f,$streamBuffer); |
---|
2948 | fclose($f); |
---|
2949 | |
---|
2950 | echo $tempDir.'/'.$file; |
---|
2951 | } |
---|
2952 | |
---|
2953 | // Get the csv field and put into array, from php.net |
---|
2954 | function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') { |
---|
2955 | $text = trim($input_text); |
---|
2956 | if(is_string($delimiter) && is_string($text_qualifier)) { |
---|
2957 | $re_d = '\x' . dechex(ord($delimiter)); //format for regexp |
---|
2958 | $re_tq = '\x' . dechex(ord($text_qualifier)); //format for regexp |
---|
2959 | |
---|
2960 | $fields = array(); |
---|
2961 | $field_num = 0; |
---|
2962 | while(strlen($text) > 0) { |
---|
2963 | if($text{0} == $text_qualifier) { |
---|
2964 | preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches); |
---|
2965 | |
---|
2966 | $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]); |
---|
2967 | $text = trim($matches[2]); |
---|
2968 | |
---|
2969 | $fields[$field_num++] = $value; |
---|
2970 | } else { |
---|
2971 | preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches); |
---|
2972 | |
---|
2973 | $value = $matches[1]; |
---|
2974 | $text = trim($matches[2]); |
---|
2975 | |
---|
2976 | $fields[$field_num++] = $value; |
---|
2977 | } |
---|
2978 | } |
---|
2979 | return $fields; |
---|
2980 | } else |
---|
2981 | return false; |
---|
2982 | } |
---|
2983 | |
---|
2984 | function import_contacts($typeImport){ |
---|
2985 | |
---|
2986 | if($file = $_SESSION['contactcenter']['importCSV']) { |
---|
2987 | unset($_SESSION['contactcenter']['importCSV']); |
---|
2988 | $len = filesize($file); |
---|
2989 | $count = 0; |
---|
2990 | $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0); |
---|
2991 | $handle = @fopen($file, "r") or die(serialize($return['error'] = true)); |
---|
2992 | |
---|
2993 | $input_header = fgets($handle); |
---|
2994 | if ($typeImport == 'outlook') |
---|
2995 | $delim = ';'; |
---|
2996 | else if ($typeImport == 'auto') |
---|
2997 | $delim = strstr($input_header,',') ? ',' : ';'; |
---|
2998 | else |
---|
2999 | $delim = ','; |
---|
3000 | $csv_header = $this->parse_line($input_header,$delim); |
---|
3001 | $firstContact = fgets($handle); |
---|
3002 | preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv |
---|
3003 | rewind($handle); |
---|
3004 | |
---|
3005 | $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true)); |
---|
3006 | if(count($header) < 2 || count($header) > 100) { |
---|
3007 | $return['error'] = true; |
---|
3008 | $return['sizeheader'] = count($header); |
---|
3009 | echo serialize($return); |
---|
3010 | return; |
---|
3011 | } |
---|
3012 | |
---|
3013 | if ($matches[0][strlen($matches[0])-1] == ';') |
---|
3014 | $delim = ';'; |
---|
3015 | |
---|
3016 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
3017 | $boPeople = CreateObject('contactcenter.bo_people_catalog'); |
---|
3018 | switch($typeImport){ |
---|
3019 | case 'outlook2000': |
---|
3020 | $name_pos=1; |
---|
3021 | $email_pos=56; |
---|
3022 | $phone_pos=44; |
---|
3023 | break; |
---|
3024 | case 'outlook': |
---|
3025 | $name_pos=0; |
---|
3026 | $email_pos=1; |
---|
3027 | $phone_pos=7; |
---|
3028 | break; |
---|
3029 | case 'thunderbird': |
---|
3030 | $name_pos=2; |
---|
3031 | $email_pos=4; |
---|
3032 | $phone_pos=7; |
---|
3033 | break; |
---|
3034 | case 'expresso': |
---|
3035 | $name_pos=0; |
---|
3036 | $email_pos=1; |
---|
3037 | $phone_pos=2; |
---|
3038 | break; |
---|
3039 | default: |
---|
3040 | foreach($csv_header as $index => $fieldName) |
---|
3041 | { |
---|
3042 | switch(strtoupper($fieldName)){ |
---|
3043 | case 'NAME': |
---|
3044 | case 'NOME': |
---|
3045 | case 'FIRST NAME': |
---|
3046 | $name_pos = $index; |
---|
3047 | break; |
---|
3048 | case 'E-MAIL': |
---|
3049 | case 'EMAIL': |
---|
3050 | case 'E-MAIL ADDRESS': |
---|
3051 | case 'ENDEREÇO DE CORREIO ELETRÔNICO': |
---|
3052 | case 'END. DE EMAIL': |
---|
3053 | $email_pos = $index; |
---|
3054 | break; |
---|
3055 | case 'HOME PHONE': |
---|
3056 | case 'PHONE': |
---|
3057 | case 'TELEFONE': |
---|
3058 | case 'TELEFONE PRINCIPAL': |
---|
3059 | case 'TELEFONE COMERCIAL': |
---|
3060 | $phone_pos = $index; |
---|
3061 | break; |
---|
3062 | } |
---|
3063 | } |
---|
3064 | break; |
---|
3065 | } |
---|
3066 | |
---|
3067 | |
---|
3068 | while (($data = fgetcsv($handle, $len, $delim))) { |
---|
3069 | foreach ($header as $key=>$heading) |
---|
3070 | $row[$heading]=(isset($data[$key])) ? $data[$key] : ''; |
---|
3071 | |
---|
3072 | $sdata = array(); |
---|
3073 | $full_name = trim($row[$header[$name_pos]]); |
---|
3074 | $email = trim($row[$header[$email_pos]]); |
---|
3075 | $phone = trim($row[$header[$phone_pos]]); |
---|
3076 | $array_name = explode(' ', str_replace('"','',(str_replace('\'','',$full_name)))); |
---|
3077 | $sdata['given_names'] = $array_name[0]; |
---|
3078 | $array_name[0] = null; |
---|
3079 | $sdata['family_names'] = trim(implode(' ',$array_name)); |
---|
3080 | $sdata['connections']['default_email']['connection_name'] = lang('Main'); |
---|
3081 | $sdata['connections']['default_email']['connection_value'] = $email; |
---|
3082 | |
---|
3083 | $sdata['connections']['default_phone']['connection_name'] = lang('Main'); |
---|
3084 | $sdata['connections']['default_phone']['connection_value'] = $phone; |
---|
3085 | |
---|
3086 | // verifica se email já existe! |
---|
3087 | $contact = $boGroup->verify_contact($email); |
---|
3088 | |
---|
3089 | if(!$sdata['given_names'] && $email){ |
---|
3090 | $a_email = explode("@",$email); |
---|
3091 | $sdata['given_names'] = $a_email[0]; |
---|
3092 | } |
---|
3093 | |
---|
3094 | $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new']; |
---|
3095 | if($contact){ |
---|
3096 | $return['_existing']++; |
---|
3097 | } |
---|
3098 | else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { |
---|
3099 | $return['_failure']++; |
---|
3100 | $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>"; |
---|
3101 | } |
---|
3102 | else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){ |
---|
3103 | $return['_failure']++; |
---|
3104 | $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>"; |
---|
3105 | } |
---|
3106 | else |
---|
3107 | $return['_new']++; |
---|
3108 | } |
---|
3109 | fclose($handle); |
---|
3110 | unlink($file); |
---|
3111 | } |
---|
3112 | else |
---|
3113 | $return['error'] = true; |
---|
3114 | |
---|
3115 | echo serialize($return); |
---|
3116 | } |
---|
3117 | /* |
---|
3118 | function convert_tree($tree, $name, &$iconDir, $parent='0') |
---|
3119 | { |
---|
3120 | $new = null; |
---|
3121 | $code = null; |
---|
3122 | |
---|
3123 | if ($parent === '0') |
---|
3124 | { |
---|
3125 | |
---|
3126 | $code .= $name.".add(new dNode({id:'0', caption: '".lang('Catalogues')."'}),'none');\n"; |
---|
3127 | } |
---|
3128 | |
---|
3129 | foreach ($tree as $id => $value) |
---|
3130 | { |
---|
3131 | $title = $value['name']; |
---|
3132 | |
---|
3133 | switch ($value['type']) |
---|
3134 | { |
---|
3135 | case 'unknown': |
---|
3136 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption:'{$value['name']}', onFirstOpen: 'getCatalogTree(\\'{$parent}.{$id}\\');', onClick: 'getCatalogTree(\\'{$parent}.{$id}\\'); waitForTree(\\'{$parent}.{$id}\\', 0)'}),'$parent');\n"; |
---|
3137 | break; |
---|
3138 | |
---|
3139 | case 'catalog_group': |
---|
3140 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n"; |
---|
3141 | $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id); |
---|
3142 | break; |
---|
3143 | |
---|
3144 | case 'mixed_catalog_group': |
---|
3145 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n"; |
---|
3146 | |
---|
3147 | $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id); |
---|
3148 | break; |
---|
3149 | |
---|
3150 | case 'catalog': |
---|
3151 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n"; |
---|
3152 | |
---|
3153 | } |
---|
3154 | } |
---|
3155 | |
---|
3156 | return $code; |
---|
3157 | } |
---|
3158 | */ |
---|
3159 | } |
---|
3160 | |
---|
3161 | ?> |
---|