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