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