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