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