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