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