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