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