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