[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)); |
---|
[285] | 486 | |
---|
[2] | 487 | if (!($tree[$child] = $this->bo->get_catalog_tree($level))) |
---|
| 488 | { |
---|
| 489 | return array( |
---|
| 490 | 'msg' => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'), |
---|
| 491 | 'status' => 'fatal' |
---|
| 492 | ); |
---|
| 493 | } |
---|
[284] | 494 | // Deals with timeout and returns the generated message to the browser |
---|
| 495 | else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg'])) |
---|
| 496 | { |
---|
| 497 | $tmp = array( |
---|
| 498 | 'msg' => $tree[$child]['msg'], |
---|
| 499 | 'status' => 'fatal' |
---|
| 500 | ); |
---|
| 501 | unset($tree[$child]); |
---|
| 502 | return $tmp; |
---|
| 503 | } |
---|
[2] | 504 | } |
---|
[285] | 505 | |
---|
[2] | 506 | $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png'); |
---|
| 507 | $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png')); |
---|
[285] | 508 | |
---|
[284] | 509 | // Deals with error messages from the server and returns them to the browser |
---|
| 510 | if ($tree['msg']) |
---|
| 511 | { |
---|
| 512 | $msg = $tree['msg']; |
---|
| 513 | unset($tree['msg']); |
---|
| 514 | } |
---|
| 515 | |
---|
[2] | 516 | $tree_js = $this->convert_tree($tree, $folderImageDir, $parent); |
---|
[284] | 517 | |
---|
| 518 | // Return status = ok, or else return generated message to the browser |
---|
| 519 | if (!$msg) |
---|
| 520 | { |
---|
| 521 | return array( |
---|
| 522 | 'data' => $tree_js, |
---|
| 523 | 'msg' => lang('Catalog Tree Successfully taken!'), |
---|
| 524 | 'status' => 'ok' |
---|
| 525 | ); |
---|
| 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
| 529 | return array( |
---|
| 530 | 'data' => $tree_js, |
---|
| 531 | 'msg' => $msg, |
---|
| 532 | 'status' => 'error' |
---|
| 533 | ); |
---|
| 534 | } |
---|
[2] | 535 | } |
---|
[285] | 536 | |
---|
[2] | 537 | /*! |
---|
[285] | 538 | |
---|
[2] | 539 | @function get_actual_catalog |
---|
| 540 | @abstract Returns the actual selected Catalog |
---|
| 541 | @author Raphael Derosso Pereira |
---|
| 542 | |
---|
| 543 | */ |
---|
| 544 | function get_actual_catalog() |
---|
[285] | 545 | { |
---|
[2] | 546 | $level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0'); |
---|
[285] | 547 | |
---|
[2] | 548 | if ($level) |
---|
| 549 | { |
---|
| 550 | return array( |
---|
| 551 | 'status' => 'ok', |
---|
| 552 | 'data' => $level |
---|
| 553 | ); |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | return array( |
---|
| 557 | 'status' => 'fatal', |
---|
| 558 | 'msg' => lang('Couldn\'t get the actual catalog.'), |
---|
| 559 | ); |
---|
| 560 | } |
---|
[285] | 561 | |
---|
[2] | 562 | /*! |
---|
[285] | 563 | |
---|
[2] | 564 | @function get_cards_data |
---|
| 565 | @abstract Returns the information that is placed on the cards |
---|
| 566 | @author Raphael Derosso Pereira |
---|
[285] | 567 | |
---|
[2] | 568 | @param string $letter The first letter to be searched |
---|
[285] | 569 | @param (int) $page The page to be taken |
---|
[2] | 570 | @param (str) $ids The ids to be taken in case of search |
---|
| 571 | |
---|
| 572 | TODO: This function is not well done. It must be rewritten |
---|
| 573 | using the new array 'msg','status','data' schema. |
---|
| 574 | */ |
---|
| 575 | function get_cards_data($letter, $page, $ids) |
---|
| 576 | { |
---|
[285] | 577 | if( $ids ) |
---|
| 578 | $_SESSION['ids'] = $ids; |
---|
[284] | 579 | |
---|
| 580 | // It's an external catalog? |
---|
| 581 | $external = $this->bo->is_external($this->page_info['actual_catalog']); |
---|
[2] | 582 | //echo $page."\n"; |
---|
| 583 | if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or |
---|
[285] | 584 | ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or |
---|
[2] | 585 | $this->page_info['changed'])) |
---|
| 586 | { |
---|
| 587 | unset($ids); |
---|
| 588 | $this->page_info['changed'] = false; |
---|
[503] | 589 | |
---|
[2] | 590 | switch ($this->page_info['actual_catalog']['class']) |
---|
| 591 | { |
---|
[752] | 592 | case 'bo_shared_people_manager': |
---|
| 593 | case 'bo_people_catalog': |
---|
[503] | 594 | $field_name = 'id_contact'; |
---|
| 595 | |
---|
| 596 | if ($letter !== 'number') |
---|
| 597 | { |
---|
| 598 | $find_restric[0] = array( |
---|
| 599 | 0 => array( |
---|
| 600 | 'field' => 'contact.names_ordered', |
---|
| 601 | 'type' => 'iLIKE', |
---|
| 602 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
[752] | 603 | ) |
---|
[503] | 604 | ); |
---|
[752] | 605 | if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){ |
---|
| 606 | $find_restric[0][1] = array( |
---|
| 607 | 'field' => 'contact.id_owner', |
---|
| 608 | 'type' => '=', |
---|
| 609 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 610 | ); |
---|
| 611 | } |
---|
[503] | 612 | } |
---|
| 613 | else |
---|
| 614 | { |
---|
| 615 | $find_restric[0] = array( |
---|
| 616 | 0 => array( |
---|
| 617 | 'type' => 'branch', |
---|
| 618 | 'value' => 'OR', |
---|
| 619 | 'sub_branch' => array( |
---|
| 620 | 0 => array( |
---|
| 621 | 'field' => 'contact.names_ordered', |
---|
| 622 | 'type' => 'LIKE', |
---|
| 623 | 'value' => '0%' |
---|
| 624 | ), |
---|
| 625 | 1 => array( |
---|
| 626 | 'field' => 'contact.names_ordered', |
---|
| 627 | 'type' => 'LIKE', |
---|
| 628 | 'value' => '1%' |
---|
| 629 | ), |
---|
| 630 | 2 => array( |
---|
| 631 | 'field' => 'contact.names_ordered', |
---|
| 632 | 'type' => 'LIKE', |
---|
| 633 | 'value' => '2%' |
---|
| 634 | ), |
---|
| 635 | 3 => array( |
---|
| 636 | 'field' => 'contact.names_ordered', |
---|
| 637 | 'type' => 'LIKE', |
---|
| 638 | 'value' => '3%' |
---|
| 639 | ), |
---|
| 640 | 4 => array( |
---|
| 641 | 'field' => 'contact.names_ordered', |
---|
| 642 | 'type' => 'LIKE', |
---|
| 643 | 'value' => '4%' |
---|
| 644 | ), |
---|
| 645 | 5 => array( |
---|
| 646 | 'field' => 'contact.names_ordered', |
---|
| 647 | 'type' => 'LIKE', |
---|
| 648 | 'value' => '5%' |
---|
| 649 | ), |
---|
| 650 | 6 => array( |
---|
| 651 | 'field' => 'contact.names_ordered', |
---|
| 652 | 'type' => 'LIKE', |
---|
| 653 | 'value' => '6%' |
---|
| 654 | ), |
---|
| 655 | 7 => array( |
---|
| 656 | 'field' => 'contact.names_ordered', |
---|
| 657 | 'type' => 'LIKE', |
---|
| 658 | 'value' => '7%' |
---|
| 659 | ), |
---|
| 660 | 8 => array( |
---|
| 661 | 'field' => 'contact.names_ordered', |
---|
| 662 | 'type' => 'LIKE', |
---|
| 663 | 'value' => '8%' |
---|
| 664 | ), |
---|
| 665 | 9 => array( |
---|
| 666 | 'field' => 'contact.names_ordered', |
---|
| 667 | 'type' => 'LIKE', |
---|
| 668 | 'value' => '9%' |
---|
[752] | 669 | ), |
---|
| 670 | ), |
---|
[503] | 671 | ) |
---|
| 672 | ); |
---|
| 673 | } |
---|
[2] | 674 | |
---|
[752] | 675 | if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){ |
---|
| 676 | $find_restric[0][1] = array( |
---|
| 677 | 'field' => 'contact.id_owner', |
---|
| 678 | 'type' => '=', |
---|
| 679 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
[2] | 680 | ); |
---|
| 681 | } |
---|
[285] | 682 | |
---|
[752] | 683 | |
---|
[2] | 684 | $find_field[0] = array('contact.id_contact','contact.names_ordered'); |
---|
[285] | 685 | |
---|
[2] | 686 | $find_other[0] = array( |
---|
| 687 | 'order' => 'contact.names_ordered' |
---|
| 688 | ); |
---|
[285] | 689 | |
---|
[2] | 690 | break; |
---|
[285] | 691 | |
---|
[2] | 692 | case 'bo_global_ldap_catalog': |
---|
[285] | 693 | |
---|
[2] | 694 | $field_name = 'id_contact'; |
---|
| 695 | |
---|
| 696 | if ($letter !== 'number') |
---|
| 697 | { |
---|
| 698 | $find_restric[0] = array( |
---|
| 699 | 0 => array( |
---|
| 700 | 'field' => 'contact.names_ordered', |
---|
| 701 | 'type' => 'iLIKE', |
---|
| 702 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
[284] | 703 | ), |
---|
| 704 | /* |
---|
| 705 | * Restrict the returned contacts in a "first letter" search |
---|
| 706 | * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, |
---|
[880] | 707 | * phpgwAccountVisible != -1 |
---|
[284] | 708 | */ |
---|
| 709 | 1 => array( |
---|
| 710 | 'field' => 'contact.object_class', |
---|
| 711 | 'type' => '=', |
---|
| 712 | 'value' => 'phpgwAccount' |
---|
| 713 | ), |
---|
| 714 | 2 => array( |
---|
| 715 | 'field' => 'contact.account_status', |
---|
| 716 | 'type' => 'iLIKE', |
---|
| 717 | 'value' => '%' |
---|
| 718 | ), |
---|
| 719 | 3 => array( |
---|
| 720 | 'field' => 'contact.account_visible', |
---|
| 721 | 'type' => '!=', |
---|
| 722 | 'value' => '-1' |
---|
[880] | 723 | ) |
---|
[2] | 724 | ); |
---|
[284] | 725 | // If not external catalog get only phpgwAccountType = u ou l |
---|
| 726 | if (!$external) |
---|
| 727 | { |
---|
| 728 | $find_restric[0][5] = array( |
---|
| 729 | 'type' => 'branch', |
---|
| 730 | 'value' => 'OR', |
---|
| 731 | 'sub_branch' => array( |
---|
| 732 | 0 => array( |
---|
| 733 | 'field' => 'contact.account_type', |
---|
| 734 | 'type' => '=', |
---|
| 735 | 'value' => 'u' |
---|
| 736 | ), |
---|
[285] | 737 | 1 => array( |
---|
[284] | 738 | 'field' => 'contact.account_type', |
---|
| 739 | 'type' => '=', |
---|
[418] | 740 | 'value' => 'i' |
---|
| 741 | ), |
---|
| 742 | 2 => array( |
---|
| 743 | 'field' => 'contact.account_type', |
---|
| 744 | 'type' => '=', |
---|
[284] | 745 | 'value' => 'l' |
---|
[880] | 746 | ), |
---|
| 747 | 3 => array( |
---|
| 748 | 'field' => 'contact.account_type', |
---|
| 749 | 'type' => '=', |
---|
| 750 | 'value' => 'g' |
---|
[284] | 751 | ) |
---|
[2] | 752 | ) |
---|
[284] | 753 | ); |
---|
| 754 | } |
---|
[2] | 755 | } |
---|
| 756 | else |
---|
| 757 | { |
---|
| 758 | $find_restric[0] = array( |
---|
[284] | 759 | /* |
---|
| 760 | * Restrict the returned contacts in a "first number" search |
---|
| 761 | * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, |
---|
[880] | 762 | * phpgwAccountVisible != -1 |
---|
[284] | 763 | */ |
---|
[2] | 764 | 0 => array( |
---|
[284] | 765 | 'field' => 'contact.object_class', |
---|
| 766 | 'type' => '=', |
---|
| 767 | 'value' => 'phpgwAccount' |
---|
| 768 | ), |
---|
| 769 | 1 => array( |
---|
| 770 | 'field' => 'contact.account_status', |
---|
| 771 | 'type' => 'iLIKE', |
---|
| 772 | 'value' => '%' |
---|
| 773 | ), |
---|
| 774 | 2 => array( |
---|
| 775 | 'field' => 'contact.account_visible', |
---|
| 776 | 'type' => '!=', |
---|
| 777 | 'value' => '-1' |
---|
| 778 | ), |
---|
| 779 | 3 => array( |
---|
[2] | 780 | 'type' => 'branch', |
---|
| 781 | 'value' => 'OR', |
---|
| 782 | 'sub_branch' => array( |
---|
| 783 | 0 => array( |
---|
| 784 | 'field' => 'contact.names_ordered', |
---|
| 785 | 'type' => 'LIKE', |
---|
| 786 | 'value' => '0%' |
---|
| 787 | ), |
---|
| 788 | 1 => array( |
---|
| 789 | 'field' => 'contact.names_ordered', |
---|
| 790 | 'type' => 'LIKE', |
---|
| 791 | 'value' => '1%' |
---|
| 792 | ), |
---|
| 793 | 2 => array( |
---|
| 794 | 'field' => 'contact.names_ordered', |
---|
| 795 | 'type' => 'LIKE', |
---|
| 796 | 'value' => '2%' |
---|
| 797 | ), |
---|
| 798 | 3 => array( |
---|
| 799 | 'field' => 'contact.names_ordered', |
---|
| 800 | 'type' => 'LIKE', |
---|
| 801 | 'value' => '3%' |
---|
| 802 | ), |
---|
| 803 | 4 => array( |
---|
| 804 | 'field' => 'contact.names_ordered', |
---|
| 805 | 'type' => 'LIKE', |
---|
| 806 | 'value' => '4%' |
---|
| 807 | ), |
---|
| 808 | 5 => array( |
---|
| 809 | 'field' => 'contact.names_ordered', |
---|
| 810 | 'type' => 'LIKE', |
---|
| 811 | 'value' => '5%' |
---|
| 812 | ), |
---|
| 813 | 6 => array( |
---|
| 814 | 'field' => 'contact.names_ordered', |
---|
| 815 | 'type' => 'LIKE', |
---|
| 816 | 'value' => '6%' |
---|
| 817 | ), |
---|
| 818 | 7 => array( |
---|
| 819 | 'field' => 'contact.names_ordered', |
---|
| 820 | 'type' => 'LIKE', |
---|
| 821 | 'value' => '7%' |
---|
| 822 | ), |
---|
| 823 | 8 => array( |
---|
| 824 | 'field' => 'contact.names_ordered', |
---|
| 825 | 'type' => 'LIKE', |
---|
| 826 | 'value' => '8%' |
---|
| 827 | ), |
---|
| 828 | 9 => array( |
---|
| 829 | 'field' => 'contact.names_ordered', |
---|
| 830 | 'type' => 'LIKE', |
---|
| 831 | 'value' => '9%' |
---|
| 832 | ), |
---|
| 833 | ), |
---|
| 834 | ), |
---|
| 835 | ); |
---|
[284] | 836 | // If not external catalog get only phpgwAccountType = u ou l |
---|
| 837 | if (!$external) |
---|
| 838 | { |
---|
| 839 | $find_restric[0][5] = array( |
---|
| 840 | 'type' => 'branch', |
---|
| 841 | 'value' => 'OR', |
---|
| 842 | 'sub_branch' => array( |
---|
| 843 | 0 => array( |
---|
| 844 | 'field' => 'contact.account_type', |
---|
| 845 | 'type' => '=', |
---|
| 846 | 'value' => 'u' |
---|
| 847 | ), |
---|
[418] | 848 | 1 => array( |
---|
| 849 | 'field' => 'contact.account_type', |
---|
| 850 | 'type' => '=', |
---|
| 851 | 'value' => 'i' |
---|
| 852 | ), |
---|
[880] | 853 | 2 => array( |
---|
[284] | 854 | 'field' => 'contact.account_type', |
---|
| 855 | 'type' => '=', |
---|
[880] | 856 | 'value' => 'l' |
---|
| 857 | ), |
---|
| 858 | 3 => array( |
---|
[284] | 859 | 'field' => 'contact.account_type', |
---|
| 860 | 'type' => '=', |
---|
[880] | 861 | 'value' => 'g' |
---|
[284] | 862 | ) |
---|
[880] | 863 | |
---|
[2] | 864 | ) |
---|
[284] | 865 | ); |
---|
| 866 | } |
---|
[2] | 867 | } |
---|
[284] | 868 | |
---|
| 869 | if (!$external) |
---|
| 870 | { |
---|
| 871 | // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible |
---|
| 872 | // for non-external catalogs, used to restrict the attributes used in filters |
---|
| 873 | $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type', |
---|
[304] | 874 | 'contact.object_class',/*'contact.account_status',*/'contact.account_visible'); |
---|
[284] | 875 | } |
---|
| 876 | else |
---|
| 877 | { |
---|
| 878 | // Get only this attributes: dn, cn for external catalogs, |
---|
| 879 | // used to restrict the attributes used in filters |
---|
| 880 | $find_field[0] = array('contact.id_contact','contact.names_ordered'); |
---|
| 881 | } |
---|
[285] | 882 | |
---|
[2] | 883 | $find_other[0] = array( |
---|
| 884 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
| 885 | //'limit' => $this->page_info['n_cards'], |
---|
| 886 | 'order' => 'contact.names_ordered' |
---|
| 887 | ); |
---|
[285] | 888 | |
---|
[2] | 889 | break; |
---|
[285] | 890 | |
---|
[2] | 891 | case 'bo_company_manager': |
---|
| 892 | $field_name = 'id_company'; |
---|
[285] | 893 | |
---|
[2] | 894 | $find_field[0] = array('company.id_company','company.company_name'); |
---|
[285] | 895 | |
---|
[2] | 896 | $find_other[0] = array( |
---|
| 897 | //'offset' => (($page-1)*$this->page_info['n_cards']), |
---|
| 898 | //'limit' => $this->page_info['n_cards'], |
---|
| 899 | 'order' => 'company.company_name' |
---|
| 900 | ); |
---|
[285] | 901 | |
---|
[2] | 902 | $find_restric[0] = array( |
---|
| 903 | 0 => array( |
---|
| 904 | 'field' => 'company.company_name', |
---|
| 905 | 'type' => 'iLIKE', |
---|
| 906 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
| 907 | ) |
---|
| 908 | ); |
---|
[285] | 909 | |
---|
[2] | 910 | break; |
---|
| 911 | |
---|
| 912 | case 'bo_group_manager': |
---|
[752] | 913 | case 'bo_shared_group_manager': |
---|
| 914 | |
---|
[2] | 915 | $field_name = 'id_group'; |
---|
[285] | 916 | |
---|
[2] | 917 | if ($letter !== 'number') { |
---|
[285] | 918 | |
---|
[2] | 919 | $find_restric[0] = array( |
---|
| 920 | 0 => array( |
---|
| 921 | 'field' => 'group.title', |
---|
| 922 | 'type' => 'iLIKE', |
---|
| 923 | 'value' => $letter !== 'all' ? $letter.'%' : '%' |
---|
| 924 | ) |
---|
| 925 | ); |
---|
| 926 | } |
---|
| 927 | else { |
---|
[285] | 928 | |
---|
[2] | 929 | $find_restric[0] = array( |
---|
| 930 | 0 => array( |
---|
| 931 | 'field' => 'group.title', |
---|
| 932 | 'type' => 'LIKE', |
---|
[285] | 933 | 'value' => '0%' |
---|
[2] | 934 | ) |
---|
[285] | 935 | ); |
---|
[2] | 936 | } |
---|
[285] | 937 | |
---|
[752] | 938 | if($this->page_info['actual_catalog']['class'] == 'bo_group_manager'){ |
---|
| 939 | array_push($find_restric[0], array( |
---|
[2] | 940 | 'field' => 'group.owner', |
---|
| 941 | 'type' => '=', |
---|
[285] | 942 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
[752] | 943 | ) |
---|
| 944 | ); |
---|
| 945 | } |
---|
[285] | 946 | |
---|
| 947 | $find_field[0] = array('group.id_group','group.title','group.short_name'); |
---|
[2] | 948 | $find_other[0] = array( |
---|
| 949 | 'order' => 'group.title' |
---|
[752] | 950 | ); |
---|
[2] | 951 | break; |
---|
[752] | 952 | |
---|
[2] | 953 | case 'bo_catalog_group_catalog': |
---|
| 954 | $this->page_info['actual_entries'] = false; |
---|
[285] | 955 | |
---|
[2] | 956 | $this->page_info['actual_letter'] = $letter; |
---|
| 957 | $this->page_info['actual_page'] = 0; |
---|
[285] | 958 | |
---|
[2] | 959 | $this->save_session(); |
---|
| 960 | $final[0] = 0; |
---|
[285] | 961 | $final[1] = $this->typeContact; |
---|
| 962 | echo serialize($final); |
---|
[2] | 963 | return; |
---|
| 964 | |
---|
| 965 | } |
---|
[285] | 966 | |
---|
[2] | 967 | $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0]); |
---|
[752] | 968 | |
---|
[2] | 969 | $n_entries = count($result); |
---|
[285] | 970 | |
---|
[2] | 971 | if ($n_entries) |
---|
| 972 | { |
---|
| 973 | //echo 'N_entries: '.$n_entries.'<br>'; |
---|
| 974 | $this->page_info['n_pages'] = ceil($n_entries/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1)); |
---|
| 975 | } |
---|
| 976 | else |
---|
| 977 | { |
---|
| 978 | $this->page_info['n_pages'] = 0; |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | if (!$result) |
---|
| 982 | { |
---|
[752] | 983 | |
---|
[2] | 984 | $this->page_info['actual_entries'] = false; |
---|
[285] | 985 | |
---|
[2] | 986 | $this->page_info['actual_letter'] = $letter; |
---|
| 987 | $this->page_info['actual_page'] = 0; |
---|
[285] | 988 | |
---|
| 989 | $this->save_session(); |
---|
[2] | 990 | $final[0] = 0; |
---|
[285] | 991 | $final[1] = $this->typeContact; |
---|
| 992 | echo serialize($final); |
---|
[2] | 993 | return; |
---|
| 994 | } |
---|
| 995 | else |
---|
| 996 | { |
---|
| 997 | unset($this->page_info['actual_entries']); |
---|
| 998 | foreach ($result as $id => $value) |
---|
| 999 | { |
---|
[752] | 1000 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
[503] | 1001 | $this->page_info['actual_entries'][] = $value[$field_name]; |
---|
| 1002 | else |
---|
[752] | 1003 | $this->page_info['actual_entries'][] = array(0=>$value[$field_name],1=>$value['perms'],2=>$value['owner']); |
---|
[285] | 1004 | } |
---|
| 1005 | //print_r($this->page_info['actual_entries']); |
---|
[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? |
---|
| 1188 | $contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields); |
---|
| 1189 | |
---|
| 1190 | |
---|
[2] | 1191 | if (!is_array($contacts) or !count($contacts)) |
---|
| 1192 | { |
---|
| 1193 | $final[0] = 0; |
---|
| 1194 | $final[1] = $this -> typeContact; |
---|
| 1195 | echo serialize($final); |
---|
| 1196 | return; |
---|
| 1197 | } |
---|
[285] | 1198 | |
---|
[2] | 1199 | $i = 0; |
---|
[284] | 1200 | foreach($contacts as $index => $contact) |
---|
[2] | 1201 | { |
---|
[284] | 1202 | /* |
---|
[285] | 1203 | * TODO: Os timeouts de conexão foram retirados, ver se será necessário retornar essa funcionalidade, e, |
---|
| 1204 | * neste caso, terminar a implementação das mensagens de retorno. |
---|
[284] | 1205 | */ |
---|
| 1206 | if ($index !== 'error'){ |
---|
| 1207 | $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none'; |
---|
| 1208 | $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none'; |
---|
| 1209 | $final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none'; |
---|
[2] | 1210 | |
---|
[284] | 1211 | /* Select the correct Email and Telephone to be shown */ |
---|
| 1212 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
[285] | 1213 | |
---|
[284] | 1214 | if (!is_array($preferences)) |
---|
[2] | 1215 | { |
---|
[284] | 1216 | $preferences['personCardEmail'] = 1; |
---|
| 1217 | $preferences['personCardPhone'] = 2; |
---|
| 1218 | } |
---|
| 1219 | if ($contact['connections']) |
---|
| 1220 | { |
---|
| 1221 | $default_email_found = false; |
---|
| 1222 | $default_phone_found = false; |
---|
| 1223 | foreach($contact['connections'] as $conn_info) |
---|
[2] | 1224 | { |
---|
[284] | 1225 | if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found) |
---|
[2] | 1226 | { |
---|
[284] | 1227 | if ($conn_info['connection_is_default']) |
---|
| 1228 | { |
---|
| 1229 | $default_email_found = true; |
---|
| 1230 | } |
---|
| 1231 | $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; |
---|
[2] | 1232 | } |
---|
[284] | 1233 | else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found) |
---|
[2] | 1234 | { |
---|
[284] | 1235 | if ($conn_info['connection_is_default']) |
---|
| 1236 | { |
---|
| 1237 | $default_phone_found = true; |
---|
| 1238 | } |
---|
[285] | 1239 | 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] | 1240 | $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>"; |
---|
[285] | 1241 | } |
---|
[284] | 1242 | $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; |
---|
| 1243 | } |
---|
[2] | 1244 | } |
---|
| 1245 | } |
---|
[285] | 1246 | |
---|
[284] | 1247 | if (!$final[3][$i][3]) |
---|
| 1248 | { |
---|
| 1249 | $final[3][$i][3] = 'none'; |
---|
| 1250 | } |
---|
| 1251 | |
---|
| 1252 | if (!$final[3][$i][4]) |
---|
| 1253 | { |
---|
| 1254 | $final[3][$i][4] = 'none'; |
---|
| 1255 | } |
---|
| 1256 | |
---|
| 1257 | $final[3][$i][5] = $contact['alias']?$contact['alias']:'none'; |
---|
| 1258 | $final[3][$i][6] = $ids[$i]; |
---|
| 1259 | |
---|
[880] | 1260 | // If contact is a public list or a group, then load the forwarding addresses. |
---|
| 1261 | if($contact['account_type'][0] == 'l' || $contact['account_type'][0] == 'g') |
---|
| 1262 | $final[3][$i][7] = ($contact['account_type'][0] == 'l' ? 'list' : 'group'); |
---|
[503] | 1263 | |
---|
[752] | 1264 | if($this->page_info['actual_catalog']['class']=='bo_shared_people_manager') { |
---|
[503] | 1265 | $final[3][$i][8] = $perms[$i]; |
---|
[752] | 1266 | $final[3][$i][9] = lang('Shared').": ".$owner_names[$owners[$i]]['cn']; |
---|
[503] | 1267 | } |
---|
[284] | 1268 | |
---|
| 1269 | $final[4][$i] = $contact['photo'] ? 1 : 0; |
---|
| 1270 | $i++; |
---|
[2] | 1271 | } |
---|
[284] | 1272 | else |
---|
[2] | 1273 | { |
---|
[284] | 1274 | // coloca mensagem de erro no vetor que retorna para o browser |
---|
[2] | 1275 | } |
---|
[284] | 1276 | } |
---|
| 1277 | $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; |
---|
| 1278 | $final[5] = '<span class="link" onclick="'.$lnk_compose; |
---|
[2] | 1279 | |
---|
| 1280 | |
---|
| 1281 | $this->page_info['actual_letter'] = $letter; |
---|
| 1282 | $this->page_info['actual_page'] = $page; |
---|
[285] | 1283 | |
---|
| 1284 | $this->save_session(); |
---|
[2] | 1285 | echo serialize($final); |
---|
| 1286 | return; |
---|
| 1287 | } |
---|
[285] | 1288 | |
---|
[2] | 1289 | $this->page_info['actual_letter'] = $letter; |
---|
| 1290 | $this->page_info['actual_page'] = $page; |
---|
[285] | 1291 | |
---|
[2] | 1292 | $this->save_session(); |
---|
[285] | 1293 | |
---|
[2] | 1294 | $final[0] = 0; |
---|
| 1295 | $final[1] = $this -> typeContact; |
---|
| 1296 | echo serialize($final); |
---|
| 1297 | } |
---|
[285] | 1298 | |
---|
| 1299 | function get_visible_all_ldap() |
---|
| 1300 | { |
---|
| 1301 | $bo = CreateObject('contactcenter.bo_ldap_manager'); |
---|
| 1302 | $ldap_query = $bo->srcs; |
---|
| 1303 | return $ldap_query[1]['visible']; |
---|
| 1304 | } |
---|
[284] | 1305 | |
---|
[285] | 1306 | |
---|
[2] | 1307 | /*! |
---|
[285] | 1308 | |
---|
[2] | 1309 | @function get_group_data |
---|
| 1310 | @abstract Returns all the information of a given Group |
---|
| 1311 | @author Nilton Emilio Buhrer Neto |
---|
[285] | 1312 | |
---|
[2] | 1313 | @param (integer) $id The id to get information |
---|
[285] | 1314 | |
---|
| 1315 | */ |
---|
[1280] | 1316 | function get_group_data($id,$shared_from=null) |
---|
[2] | 1317 | { |
---|
| 1318 | $this->bo->catalog = CreateObject('contactcenter.bo_group_manager'); |
---|
| 1319 | $fields = $this->bo->catalog->get_fields(true); |
---|
| 1320 | $data = $this->bo->catalog->get_single_entry($id,$fields); |
---|
[285] | 1321 | |
---|
| 1322 | if($id) { |
---|
[2] | 1323 | // get All Contacts by group. |
---|
[285] | 1324 | $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id); |
---|
[2] | 1325 | } |
---|
[285] | 1326 | |
---|
[2] | 1327 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
[285] | 1328 | |
---|
[1280] | 1329 | $all_contacts = $boGroup->get_all_contacts('only_email',$shared_from); |
---|
[285] | 1330 | |
---|
| 1331 | $contact_options = ""; |
---|
| 1332 | if(count($all_contacts)) { |
---|
| 1333 | foreach($all_contacts as $idx => $contact) { |
---|
| 1334 | $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']." (".$contact['connection_value'].")</OPTION>"; |
---|
| 1335 | } |
---|
| 1336 | } |
---|
[752] | 1337 | $data['contact_list'] = $contact_options; |
---|
| 1338 | $data['result'] = 'ok'; |
---|
| 1339 | |
---|
[285] | 1340 | echo serialize($data); |
---|
| 1341 | } |
---|
| 1342 | |
---|
[2] | 1343 | /*! |
---|
[285] | 1344 | |
---|
[2] | 1345 | @function get_full_data |
---|
| 1346 | @abstract Returns all the information of a given Entry |
---|
| 1347 | @author Raphael Derosso Pereira |
---|
[285] | 1348 | |
---|
[2] | 1349 | @param (integer) $id The id to get information |
---|
[285] | 1350 | |
---|
[2] | 1351 | */ |
---|
[503] | 1352 | function get_full_data($id,$catalog='bo_people_catalog') |
---|
[2] | 1353 | { |
---|
| 1354 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
[503] | 1355 | $this->bo->catalog = CreateObject('contactcenter.'.$catalog); |
---|
[2] | 1356 | $fields = $this->bo->catalog->get_fields(true); |
---|
| 1357 | $fields['photo'] = false; |
---|
| 1358 | $entry = $this->bo->catalog->get_single_entry($id,$fields); |
---|
| 1359 | |
---|
| 1360 | if (is_bool($entry['given_names'])) |
---|
| 1361 | { |
---|
| 1362 | $data['result'] = 'false'; |
---|
| 1363 | echo serialize($data); |
---|
| 1364 | return; |
---|
| 1365 | } |
---|
| 1366 | |
---|
| 1367 | $date = explode('-', $entry['birthdate']); |
---|
| 1368 | $j = 0; |
---|
| 1369 | for ($i = 0; $i < 5; $i+=2) |
---|
| 1370 | { |
---|
| 1371 | switch($dateformat{$i}) |
---|
| 1372 | { |
---|
| 1373 | case 'Y': |
---|
| 1374 | $birthdate[$j] = $date[0]; |
---|
| 1375 | break; |
---|
| 1376 | |
---|
| 1377 | case 'm': |
---|
| 1378 | case 'M': |
---|
| 1379 | $birthdate[$j] = $date[1]; |
---|
| 1380 | break; |
---|
| 1381 | |
---|
| 1382 | case 'd': |
---|
| 1383 | $birthdate[$j] = $date[2]; |
---|
| 1384 | } |
---|
| 1385 | $j++; |
---|
| 1386 | } |
---|
| 1387 | $datecount = 0; |
---|
[285] | 1388 | |
---|
[2] | 1389 | $data['result'] = 'ok'; |
---|
| 1390 | $data['cc_full_add_contact_id'] = $id; |
---|
| 1391 | |
---|
| 1392 | /* Personal Data */ |
---|
| 1393 | $data['personal']['cc_pd_photo'] = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id; |
---|
| 1394 | $data['personal']['cc_pd_alias'] = $entry['alias']; |
---|
| 1395 | $data['personal']['cc_pd_given_names'] = $entry['given_names']; |
---|
| 1396 | $data['personal']['cc_pd_family_names'] = $entry['family_names']; |
---|
| 1397 | $data['personal']['cc_pd_full_name'] = $entry['names_ordered']; |
---|
| 1398 | $data['personal']['cc_pd_suffix'] = $entry['id_suffix']; |
---|
| 1399 | $data['personal']['cc_pd_birthdate_0'] = $birthdate[0]; |
---|
| 1400 | $data['personal']['cc_pd_birthdate_1'] = $birthdate[1]; |
---|
| 1401 | $data['personal']['cc_pd_birthdate_2'] = $birthdate[2]; |
---|
| 1402 | //$data['personal']['cc_pd_sex'] = $entry['sex'] === 'M' ? 1 : ($entry['sex'] === 'F' ? 2 : 0); |
---|
| 1403 | $data['personal']['cc_pd_prefix'] = $entry['id_prefix']; |
---|
| 1404 | $data['personal']['cc_pd_gpg_finger_print'] = $entry['pgp_key']; |
---|
| 1405 | $data['personal']['cc_pd_notes'] = $entry['notes']; |
---|
| 1406 | |
---|
| 1407 | /* Addresses */ |
---|
| 1408 | if (is_array($entry['addresses'])) |
---|
| 1409 | { |
---|
| 1410 | $data['addresses'] = $entry['addresses']; |
---|
| 1411 | } |
---|
| 1412 | |
---|
| 1413 | /* Connections */ |
---|
| 1414 | if (is_array($entry['connections'])) |
---|
| 1415 | { |
---|
| 1416 | $data['connections'] = array(); |
---|
| 1417 | foreach ($entry['connections'] as $connection) |
---|
| 1418 | { |
---|
| 1419 | $type = $connection['id_type']; |
---|
| 1420 | $i = count($data['connections'][$type]); |
---|
| 1421 | $data['connections'][$type][$i]['id'] = $connection['id_connection']; |
---|
| 1422 | $data['connections'][$type][$i]['name'] = $connection['connection_name']; |
---|
| 1423 | $data['connections'][$type][$i]['value'] = $connection['connection_value']; |
---|
| 1424 | $data['connections'][$type][$i]['is_default'] = $connection['connection_is_default']; |
---|
| 1425 | } |
---|
| 1426 | } |
---|
| 1427 | // print_r($data); |
---|
| 1428 | |
---|
| 1429 | /* Relations */ |
---|
[285] | 1430 | |
---|
[2] | 1431 | echo serialize($data); |
---|
| 1432 | } |
---|
| 1433 | |
---|
| 1434 | /*! |
---|
| 1435 | |
---|
| 1436 | @function get_contact_full_add_const |
---|
| 1437 | @abstract Returns all the constant fields in Contact Full Add Window to the JS |
---|
| 1438 | @author Raphael Derosso Pereira |
---|
| 1439 | */ |
---|
| 1440 | function get_contact_full_add_const() |
---|
| 1441 | { |
---|
| 1442 | $data = array(); |
---|
| 1443 | $boPeopleCatalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
| 1444 | $predata[] = $boPeopleCatalog -> get_all_prefixes(); |
---|
| 1445 | $predata[] = $boPeopleCatalog -> get_all_suffixes(); |
---|
| 1446 | $predata[] = $boPeopleCatalog -> get_all_addresses_types(); |
---|
| 1447 | $predata[] = $boPeopleCatalog -> get_all_countries(); |
---|
| 1448 | $predata[] = $boPeopleCatalog -> get_all_connections_types(); |
---|
| 1449 | //$predata[] = $this->bo->catalog->get_all_relations_types(); |
---|
| 1450 | |
---|
| 1451 | $i = 0; |
---|
| 1452 | foreach($predata as $data_) |
---|
| 1453 | { |
---|
| 1454 | if ($data_) |
---|
| 1455 | { |
---|
| 1456 | $data[$i] = $data_; |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | $i++; |
---|
| 1460 | } |
---|
| 1461 | |
---|
| 1462 | if (count($data)) |
---|
| 1463 | { |
---|
| 1464 | echo serialize($data); |
---|
| 1465 | return; |
---|
| 1466 | } |
---|
[285] | 1467 | |
---|
[2] | 1468 | echo 0; |
---|
| 1469 | } |
---|
[285] | 1470 | |
---|
[2] | 1471 | /*! |
---|
[285] | 1472 | |
---|
[2] | 1473 | @function quick_add |
---|
| 1474 | @abstract Adds a new Contact using the Quick Add interface |
---|
| 1475 | @author Raphael Derosso Pereira |
---|
[285] | 1476 | |
---|
[2] | 1477 | @param string $sdata Serialized data |
---|
| 1478 | */ |
---|
| 1479 | function quick_add($sdata) |
---|
| 1480 | { |
---|
[285] | 1481 | |
---|
[2] | 1482 | $sdata = str_replace('\\"', '"', $sdata); |
---|
| 1483 | $new_array = unserialize($sdata); |
---|
| 1484 | $tdata = array(); |
---|
[285] | 1485 | |
---|
[2] | 1486 | foreach($new_array as $tmp) |
---|
| 1487 | $tdata[] = $tmp; |
---|
[285] | 1488 | |
---|
[2] | 1489 | if (!$tdata) |
---|
| 1490 | { |
---|
| 1491 | echo serialize(array( |
---|
| 1492 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
| 1493 | 'status' => 'abort' |
---|
| 1494 | )); |
---|
[285] | 1495 | |
---|
[2] | 1496 | return; |
---|
| 1497 | } |
---|
[285] | 1498 | |
---|
| 1499 | // verifica se email já existe! |
---|
[2] | 1500 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
| 1501 | $contact = $boGroup->verify_contact($tdata[4]); |
---|
[285] | 1502 | |
---|
[2] | 1503 | if($contact) |
---|
[285] | 1504 | { |
---|
[2] | 1505 | $str_contact = "\r\n - ".implode("\r\n - ",$contact); |
---|
[285] | 1506 | |
---|
[2] | 1507 | echo serialize(array( |
---|
| 1508 | 'msg' => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact), |
---|
| 1509 | 'status' => 'alreadyExists' |
---|
| 1510 | )); |
---|
[285] | 1511 | |
---|
| 1512 | return; |
---|
[2] | 1513 | } |
---|
| 1514 | |
---|
| 1515 | $data['alias'] = $tdata[0]; |
---|
| 1516 | $data['given_names'] = $tdata[1]; |
---|
| 1517 | $data['family_names'] = $tdata[2]; |
---|
| 1518 | // $data['connections']['default_phone']['id_typeof_connection'] = 1; |
---|
| 1519 | $data['connections']['default_phone']['connection_name'] = lang('Main'); |
---|
| 1520 | $data['connections']['default_phone']['connection_value'] = $tdata[3]; |
---|
| 1521 | // $data['connections']['default_email']['id_typeof_connection'] = 2; |
---|
| 1522 | $data['connections']['default_email']['connection_name'] = lang('Main'); |
---|
| 1523 | $data['connections']['default_email']['connection_value'] = $tdata[4]; |
---|
| 1524 | |
---|
| 1525 | $boPeople = CreateObject('contactcenter.bo_people_catalog'); |
---|
| 1526 | |
---|
| 1527 | if ($boPeople ->quick_add($data)) |
---|
[285] | 1528 | { |
---|
[2] | 1529 | $this->page_info['changed'] = true; |
---|
[285] | 1530 | |
---|
[2] | 1531 | echo serialize(array( |
---|
| 1532 | 'msg' => lang('Entry added with success!'), |
---|
| 1533 | 'status' => 'ok' |
---|
| 1534 | )); |
---|
| 1535 | } |
---|
| 1536 | else |
---|
| 1537 | { |
---|
| 1538 | echo serialize(array( |
---|
| 1539 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
| 1540 | 'status' => 'error' |
---|
| 1541 | )); |
---|
| 1542 | } |
---|
| 1543 | |
---|
[285] | 1544 | $this->save_session(); |
---|
| 1545 | |
---|
[2] | 1546 | } |
---|
| 1547 | |
---|
| 1548 | /*! |
---|
[285] | 1549 | |
---|
[2] | 1550 | @function add_group |
---|
| 1551 | @abstract Adds a new Group using the Add Group interface |
---|
| 1552 | @author Nilton Emilio Buhrer Neto |
---|
[285] | 1553 | |
---|
[2] | 1554 | @param string $sdata Serialized data |
---|
| 1555 | */ |
---|
| 1556 | function add_group($sdata) |
---|
| 1557 | { |
---|
| 1558 | $sdata = str_replace('\\"', '"', $sdata); |
---|
| 1559 | $tdata = unserialize($sdata); |
---|
| 1560 | $new_tdata = array(); |
---|
[285] | 1561 | |
---|
[2] | 1562 | if (!$tdata) |
---|
| 1563 | { |
---|
| 1564 | echo serialize(array( |
---|
| 1565 | 'msg' => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'), |
---|
| 1566 | 'status' => 'abort' |
---|
| 1567 | )); |
---|
[285] | 1568 | |
---|
[2] | 1569 | return; |
---|
| 1570 | } |
---|
[285] | 1571 | |
---|
[2] | 1572 | foreach($tdata as $tmp) |
---|
| 1573 | $new_tdata[] = $tmp; |
---|
[285] | 1574 | |
---|
| 1575 | $data['title'] = $new_tdata[0]; |
---|
[2] | 1576 | $data['contact_in_list'] = $new_tdata[1]; |
---|
| 1577 | $data['id_group'] = $new_tdata[2]; |
---|
[285] | 1578 | |
---|
[2] | 1579 | $boGroup = CreateObject('contactcenter.bo_group_manager'); |
---|
| 1580 | $id = $boGroup -> add_group($data); |
---|
[285] | 1581 | |
---|
[2] | 1582 | if ($id) |
---|
| 1583 | { |
---|
| 1584 | $this->page_info['changed'] = true; |
---|
[285] | 1585 | |
---|
[2] | 1586 | echo serialize(array( |
---|
| 1587 | 'msg' => lang('Entry added with success!'), |
---|
| 1588 | 'status' => 'ok' |
---|
| 1589 | )); |
---|
| 1590 | } |
---|
| 1591 | else |
---|
| 1592 | { |
---|
| 1593 | echo serialize(array( |
---|
| 1594 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
| 1595 | 'status' => 'error' |
---|
| 1596 | )); |
---|
| 1597 | } |
---|
| 1598 | |
---|
| 1599 | $this->save_session(); |
---|
| 1600 | } |
---|
| 1601 | |
---|
| 1602 | /*! |
---|
[285] | 1603 | |
---|
[2] | 1604 | @function remove_group |
---|
| 1605 | @abstract Removes a group if the user has the right to do it |
---|
[285] | 1606 | @author Nilton Emilio Buhrer Neto |
---|
[2] | 1607 | @param (integer) $id The id to be removed |
---|
[285] | 1608 | |
---|
[2] | 1609 | */ |
---|
| 1610 | function remove_group($id) |
---|
[285] | 1611 | { |
---|
| 1612 | $soGroup = CreateObject('contactcenter.so_group'); |
---|
[2] | 1613 | $data = array ('id_group' => $id); |
---|
| 1614 | if($soGroup -> delete($data)) { |
---|
| 1615 | echo serialize(array( |
---|
| 1616 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
| 1617 | 'status' => 'ok' |
---|
[285] | 1618 | )); |
---|
[2] | 1619 | } |
---|
| 1620 | else { |
---|
| 1621 | echo serialize(array( |
---|
| 1622 | 'msg' => lang('Problems on adding your Contact. No Contact added!'), |
---|
| 1623 | 'status' => 'error' |
---|
| 1624 | )); |
---|
| 1625 | } |
---|
| 1626 | |
---|
[285] | 1627 | $this->save_session(); |
---|
[2] | 1628 | } |
---|
| 1629 | |
---|
| 1630 | |
---|
| 1631 | function remove_all_entries (){ |
---|
[285] | 1632 | |
---|
[2] | 1633 | $error = false; |
---|
| 1634 | $this->all_entries = $this->bo->catalog->get_all_entries_ids(); |
---|
| 1635 | |
---|
| 1636 | foreach($this->all_entries as $index => $id) { |
---|
| 1637 | $result = $this->bo->catalog->remove_single_entry($id); |
---|
| 1638 | if(!$result) { |
---|
| 1639 | $error = true; |
---|
[285] | 1640 | break; |
---|
[2] | 1641 | } |
---|
| 1642 | } |
---|
| 1643 | |
---|
| 1644 | if(!$error) { |
---|
| 1645 | echo serialize(array( |
---|
| 1646 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
| 1647 | 'status' => 'ok' |
---|
| 1648 | )); |
---|
[285] | 1649 | } |
---|
[2] | 1650 | else { |
---|
| 1651 | echo serialize(array( |
---|
| 1652 | 'msg' => lang('Couldn\'t remove this entry. Inform the Site Admin!'), |
---|
| 1653 | 'status' => 'fail' |
---|
| 1654 | )); |
---|
| 1655 | } |
---|
| 1656 | |
---|
| 1657 | $this->save_session(); |
---|
| 1658 | } |
---|
| 1659 | |
---|
| 1660 | /*! |
---|
[285] | 1661 | |
---|
[2] | 1662 | @function remove_entry |
---|
| 1663 | @abstract Removes an entry if the user has the right to do it |
---|
| 1664 | @author Raphael Derosso Pereira |
---|
[285] | 1665 | |
---|
[2] | 1666 | @param (integer) $id The id to be removed |
---|
[285] | 1667 | |
---|
[2] | 1668 | */ |
---|
| 1669 | function remove_entry ($id) |
---|
| 1670 | { |
---|
| 1671 | if (!is_int($id)) |
---|
| 1672 | { |
---|
| 1673 | echo lang('Couldn\'t remove entry! Problem passing data to the server. Please inform admin!'); |
---|
| 1674 | return; |
---|
| 1675 | } |
---|
[285] | 1676 | |
---|
[2] | 1677 | $this->page_info['changed'] = true; |
---|
| 1678 | $result = $this->bo->catalog->remove_single_entry($id); |
---|
[285] | 1679 | |
---|
[2] | 1680 | if ($result) |
---|
| 1681 | { |
---|
| 1682 | if ($pos = array_search($id, $this->page_info['actual_entries'])) |
---|
| 1683 | { |
---|
| 1684 | unset($this->page_info['actual_entries'][$pos]); |
---|
| 1685 | } |
---|
[285] | 1686 | |
---|
[2] | 1687 | $temp = false; |
---|
| 1688 | reset($this->page_info['actual_entries']); |
---|
| 1689 | foreach($this->page_info['actual_entries'] as $t) |
---|
| 1690 | { |
---|
| 1691 | $temp[] = $t; |
---|
| 1692 | } |
---|
[285] | 1693 | |
---|
[2] | 1694 | $this->page_info['actual_entries'] = $temp; |
---|
| 1695 | |
---|
| 1696 | echo serialize(array( |
---|
| 1697 | 'msg' => lang('Removed Entry ID '.$id.'!'), |
---|
| 1698 | 'status' => 'ok' |
---|
| 1699 | )); |
---|
| 1700 | } |
---|
| 1701 | else |
---|
| 1702 | { |
---|
| 1703 | echo serialize(array( |
---|
| 1704 | 'msg' => lang('Couldn\'t remove this entry. Inform the Site Admin!'), |
---|
| 1705 | 'status' => 'fail' |
---|
| 1706 | )); |
---|
| 1707 | } |
---|
[285] | 1708 | |
---|
[2] | 1709 | $this->save_session(); |
---|
| 1710 | } |
---|
| 1711 | |
---|
[285] | 1712 | |
---|
[2] | 1713 | /*! |
---|
[285] | 1714 | |
---|
[2] | 1715 | @function post_full_add |
---|
| 1716 | @abstract Saves all the information altered/entered in the Full Add |
---|
| 1717 | window |
---|
| 1718 | @author Raphael Derosso Pereira |
---|
| 1719 | |
---|
| 1720 | */ |
---|
| 1721 | function post_full_add() |
---|
| 1722 | { |
---|
[285] | 1723 | $data = $_POST['data']; |
---|
| 1724 | // Exceptions!!! utf8 special chars. |
---|
| 1725 | $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data); |
---|
| 1726 | $data = unserialize(str_replace('\\"', '"', $data)); |
---|
[2] | 1727 | $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog'); |
---|
| 1728 | |
---|
| 1729 | if (!is_array($data)) |
---|
| 1730 | { |
---|
| 1731 | echo serialize(array( |
---|
| 1732 | 'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'. |
---|
| 1733 | 'Please go to eGroupWare Bug Reporting page and report this bug.<br>'. |
---|
| 1734 | 'Sorry for the inconvenient!<br><br>'. |
---|
| 1735 | '<b><i>ContactCenter Developer Team</i></b></p>'), |
---|
| 1736 | 'status' => 'fatal' |
---|
| 1737 | )); |
---|
| 1738 | return; |
---|
| 1739 | } |
---|
| 1740 | // print_r($data); |
---|
| 1741 | // echo '<br><br>'; |
---|
| 1742 | |
---|
| 1743 | $replacer = $data['commercialAnd']; |
---|
| 1744 | unset($data['commercialAnd']); |
---|
| 1745 | if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"')) |
---|
| 1746 | { |
---|
| 1747 | echo serialize(array( |
---|
| 1748 | 'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'), |
---|
| 1749 | 'status' => 'fatal' |
---|
| 1750 | )); |
---|
[285] | 1751 | |
---|
[2] | 1752 | return; |
---|
| 1753 | } |
---|
| 1754 | |
---|
| 1755 | if ($data['id_contact']) |
---|
| 1756 | { |
---|
| 1757 | $id = $data['id_contact']; |
---|
| 1758 | $id_photo = $id; |
---|
| 1759 | unset($data['id_contact']); |
---|
| 1760 | } |
---|
| 1761 | else |
---|
| 1762 | { |
---|
| 1763 | $id_photo = '_new_'; |
---|
| 1764 | } |
---|
[285] | 1765 | |
---|
| 1766 | /* |
---|
| 1767 | * Process Photo, if available |
---|
[2] | 1768 | */ |
---|
| 1769 | $sleep_count = 0; |
---|
| 1770 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
| 1771 | while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y') |
---|
| 1772 | { |
---|
| 1773 | sleep(1); |
---|
| 1774 | $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter'); |
---|
| 1775 | $sleep_count++; |
---|
| 1776 | |
---|
| 1777 | if ($sleep_count > 35) |
---|
| 1778 | { |
---|
| 1779 | // TODO |
---|
| 1780 | return; |
---|
| 1781 | } |
---|
| 1782 | } |
---|
| 1783 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n')); |
---|
[285] | 1784 | |
---|
[2] | 1785 | if (isset($this->page_info['photos'][$id_photo])) |
---|
| 1786 | { |
---|
| 1787 | if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false) |
---|
| 1788 | { |
---|
| 1789 | echo serialize(array( |
---|
| 1790 | 'msg' => $this->page_info['photos'][$id_photo]['msg'], |
---|
| 1791 | 'status' => $this->page_info['photos'][$id_photo]['status'] |
---|
| 1792 | )); |
---|
| 1793 | |
---|
| 1794 | return; |
---|
| 1795 | } |
---|
| 1796 | |
---|
| 1797 | $data['photo'] = $this->page_info['photos'][$id_photo]['content']; |
---|
| 1798 | unset($this->page_info['photos'][$id_photo]); |
---|
| 1799 | $this->save_session(); |
---|
| 1800 | } |
---|
[285] | 1801 | |
---|
[2] | 1802 | /* |
---|
| 1803 | * Arrange Date so it gets inserted correctly |
---|
| 1804 | */ |
---|
[285] | 1805 | |
---|
[2] | 1806 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
[285] | 1807 | |
---|
[2] | 1808 | $j = 0; |
---|
| 1809 | for ($i = 0; $i < 5; $i+=2) |
---|
| 1810 | { |
---|
| 1811 | switch($dateformat{$i}) |
---|
| 1812 | { |
---|
| 1813 | case 'Y': |
---|
| 1814 | $date[$j]['size'] = 4; |
---|
| 1815 | $date[$j]['digit'] = 'Y'; |
---|
| 1816 | break; |
---|
| 1817 | |
---|
| 1818 | case 'm': |
---|
| 1819 | case 'M': |
---|
| 1820 | $date[$j]['size'] = 2; |
---|
| 1821 | $date[$j]['digit'] = 'M'; |
---|
| 1822 | break; |
---|
| 1823 | |
---|
| 1824 | case 'd': |
---|
| 1825 | $date[$j]['size'] = 2; |
---|
| 1826 | $date[$j]['digit'] = 'D'; |
---|
| 1827 | } |
---|
| 1828 | $j++; |
---|
| 1829 | } |
---|
| 1830 | $datecount = 0; |
---|
| 1831 | |
---|
| 1832 | /* Verify Data and performs insertion/update */ |
---|
| 1833 | foreach($data as $field => $value) |
---|
| 1834 | { |
---|
| 1835 | if ($value == '' or is_null($value)) |
---|
| 1836 | { |
---|
| 1837 | unset($data[$field]); |
---|
| 1838 | continue; |
---|
| 1839 | } |
---|
[285] | 1840 | |
---|
[2] | 1841 | switch($field) |
---|
| 1842 | { |
---|
| 1843 | case 'alias': |
---|
| 1844 | case 'given_names': |
---|
| 1845 | case 'family_names': |
---|
| 1846 | case 'names_ordered': |
---|
| 1847 | case 'pgp_key': |
---|
| 1848 | case 'notes': |
---|
| 1849 | case 'photo': |
---|
| 1850 | /* Do Nothing. This is just to make sure no invalid field is passed */ |
---|
| 1851 | break; |
---|
[285] | 1852 | |
---|
[2] | 1853 | case 'id_status': |
---|
| 1854 | case 'id_prefix': |
---|
| 1855 | case 'id_suffix': |
---|
| 1856 | if ($data[$field] == 0) |
---|
| 1857 | { |
---|
| 1858 | unset($data[$field]); |
---|
| 1859 | } |
---|
| 1860 | break; |
---|
[285] | 1861 | |
---|
[2] | 1862 | case 'birthdate_0': |
---|
| 1863 | case 'birthdate_1': |
---|
| 1864 | case 'birthdate_2': |
---|
[285] | 1865 | |
---|
[2] | 1866 | switch($date[$datecount]['digit']) |
---|
| 1867 | { |
---|
| 1868 | case 'Y': |
---|
| 1869 | $date['value'][2] = (int) $data[$field]; |
---|
| 1870 | break; |
---|
| 1871 | |
---|
| 1872 | case 'M': |
---|
| 1873 | $date['value'][0] = (int) $data[$field]; |
---|
| 1874 | break; |
---|
| 1875 | |
---|
| 1876 | case 'D': |
---|
| 1877 | $date['value'][1] = (int) $data[$field]; |
---|
| 1878 | break; |
---|
| 1879 | } |
---|
| 1880 | unset($data[$field]); |
---|
| 1881 | $datecount++; |
---|
| 1882 | |
---|
| 1883 | if ($datecount != 3) |
---|
| 1884 | { |
---|
| 1885 | break; |
---|
| 1886 | } |
---|
[285] | 1887 | |
---|
[2] | 1888 | if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2])) |
---|
| 1889 | { |
---|
| 1890 | echo serialize(array( |
---|
| 1891 | 'msg' => lang('Invalid Date'), |
---|
| 1892 | 'status' => 'invalid_data' |
---|
| 1893 | )); |
---|
| 1894 | return; |
---|
| 1895 | } |
---|
[285] | 1896 | |
---|
[2] | 1897 | $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1]; |
---|
| 1898 | break; |
---|
| 1899 | |
---|
| 1900 | case 'sex': |
---|
| 1901 | if ($data[$field] !== 'M' and $data[$field] !== 'F') |
---|
| 1902 | { |
---|
| 1903 | echo serialize(array( |
---|
| 1904 | 'msg' => lang('Invalid Sex'), |
---|
| 1905 | 'status' => 'invalid_data' |
---|
| 1906 | )); |
---|
| 1907 | return; |
---|
| 1908 | } |
---|
| 1909 | break; |
---|
| 1910 | |
---|
| 1911 | |
---|
| 1912 | case 'addresses': |
---|
| 1913 | /* Insert new cities/states */ |
---|
| 1914 | if (isset($value['new_states'])) |
---|
| 1915 | { |
---|
| 1916 | foreach($value['new_states'] as $type => $state_info) |
---|
| 1917 | { |
---|
| 1918 | $index = 'address'.$type; |
---|
[285] | 1919 | |
---|
[2] | 1920 | $id_state = $this->bo->catalog->add_state($state_info); |
---|
| 1921 | $data['addresses'][$index]['id_state'] = $id_state; |
---|
| 1922 | |
---|
| 1923 | if ($value['new_cities'][$type]) |
---|
| 1924 | { |
---|
| 1925 | $value['new_cities'][$type]['id_state'] = $id_state; |
---|
| 1926 | } |
---|
| 1927 | } |
---|
| 1928 | |
---|
| 1929 | unset($data['addresses']['new_states']); |
---|
| 1930 | } |
---|
| 1931 | |
---|
| 1932 | if (isset($value['new_cities'])) |
---|
| 1933 | { |
---|
| 1934 | foreach($value['new_cities'] as $type => $city_info) |
---|
| 1935 | { |
---|
| 1936 | $index = 'address'.$type; |
---|
[285] | 1937 | |
---|
[2] | 1938 | $id_city = $this->bo->catalog->add_city($city_info); |
---|
| 1939 | $data['addresses'][$index]['id_city'] = $id_city; |
---|
| 1940 | } |
---|
| 1941 | |
---|
| 1942 | unset($data['addresses']['new_cities']); |
---|
| 1943 | } |
---|
| 1944 | |
---|
| 1945 | break; |
---|
| 1946 | |
---|
| 1947 | case 'connections': |
---|
| 1948 | /* Does nothing... */ |
---|
| 1949 | break; |
---|
| 1950 | |
---|
| 1951 | default: |
---|
| 1952 | echo serialize(array( |
---|
| 1953 | 'msg' => lang('Invalid field: ').$field, |
---|
| 1954 | 'status' => 'invalid_data' |
---|
| 1955 | )); |
---|
| 1956 | return; |
---|
| 1957 | } |
---|
| 1958 | } |
---|
| 1959 | |
---|
| 1960 | $code = '$id = $this->bo->catalog->'; |
---|
| 1961 | |
---|
| 1962 | if (!is_null($id) and $id !== '') |
---|
| 1963 | { |
---|
| 1964 | $code .= $code.'update_single_info($id, $data);'; |
---|
| 1965 | $result = array( |
---|
| 1966 | 'msg' => lang('Updated Successfully!'), |
---|
| 1967 | 'status' => 'ok' |
---|
| 1968 | ); |
---|
| 1969 | } |
---|
| 1970 | else |
---|
| 1971 | { |
---|
| 1972 | $code .= 'add_single_entry($data);'; |
---|
| 1973 | $result = array( |
---|
| 1974 | 'msg' => lang('Entry Added Successfully!'), |
---|
| 1975 | 'status' => 'ok' |
---|
| 1976 | ); |
---|
| 1977 | } |
---|
[285] | 1978 | |
---|
[2] | 1979 | eval($code); |
---|
| 1980 | |
---|
| 1981 | if (!($id)) |
---|
| 1982 | { |
---|
| 1983 | $result = array( |
---|
| 1984 | 'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'. |
---|
| 1985 | 'Report the problem to the Administrator.'), |
---|
| 1986 | 'status' => 'fail' |
---|
| 1987 | ); |
---|
| 1988 | } |
---|
| 1989 | |
---|
| 1990 | echo serialize($result); |
---|
| 1991 | } |
---|
| 1992 | |
---|
| 1993 | /*! |
---|
[285] | 1994 | |
---|
[2] | 1995 | @function post_photo |
---|
| 1996 | @abstract Wrapper to post a photo without reload a page. |
---|
| 1997 | @author Raphael Derosso Pereira |
---|
| 1998 | |
---|
| 1999 | */ |
---|
| 2000 | function post_photo($id) |
---|
| 2001 | { |
---|
| 2002 | //print_r($_FILES); |
---|
| 2003 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y')); |
---|
[285] | 2004 | |
---|
[2] | 2005 | if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo'])) |
---|
| 2006 | { |
---|
| 2007 | $this->page_info['photos'][$id]['status'] = 'no_upload'; |
---|
| 2008 | $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.'); |
---|
[285] | 2009 | |
---|
[2] | 2010 | $this->save_session(); |
---|
| 2011 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2012 | return; |
---|
| 2013 | } |
---|
| 2014 | |
---|
| 2015 | if (!function_exists('imagecreate')) |
---|
| 2016 | { |
---|
| 2017 | $this->page_info['photos'][$id]['status'] = 'no_GD_lib'; |
---|
| 2018 | $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] | 2019 | |
---|
[2] | 2020 | $this->save_session(); |
---|
| 2021 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2022 | return; |
---|
| 2023 | } |
---|
| 2024 | |
---|
| 2025 | // TODO: Get Max Size from preferences! |
---|
| 2026 | if ($_FILES['cc_pd_photo']['size'] > 1000000) |
---|
| 2027 | { |
---|
| 2028 | $this->page_info['photos'][$id]['status'] = 'too_large'; |
---|
| 2029 | $this->page_info['photos'][$id]['msg'] = lang('Image too large! ContactCenter limits the image size to 1 Mb'); |
---|
| 2030 | |
---|
| 2031 | $this->save_session(); |
---|
| 2032 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2033 | return; |
---|
| 2034 | } |
---|
| 2035 | |
---|
| 2036 | if ($_FILES['cc_pd_photo']['error']) |
---|
| 2037 | { |
---|
| 2038 | $this->page_info['photos'][$id]['status'] = 'error'; |
---|
| 2039 | $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']; |
---|
| 2040 | |
---|
| 2041 | $this->save_session(); |
---|
| 2042 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2043 | return; |
---|
| 2044 | } |
---|
[285] | 2045 | |
---|
[2] | 2046 | switch($_FILES['cc_pd_photo']['type']) |
---|
| 2047 | { |
---|
| 2048 | case 'image/jpeg': |
---|
| 2049 | case 'image/pjpeg': |
---|
| 2050 | $src_img = imagecreatefromjpeg($_FILES['cc_pd_photo']['tmp_name']); |
---|
| 2051 | if ($src_img == '') |
---|
| 2052 | { |
---|
| 2053 | $bogus = true; |
---|
| 2054 | } |
---|
| 2055 | break; |
---|
| 2056 | |
---|
| 2057 | case 'image/png': |
---|
| 2058 | case 'image/x-png': |
---|
| 2059 | $src_img = imagecreatefrompng($_FILES['cc_pd_photo']['tmp_name']); |
---|
| 2060 | if ($src_img == '') |
---|
| 2061 | { |
---|
| 2062 | $bogus = true; |
---|
| 2063 | } |
---|
| 2064 | break; |
---|
| 2065 | |
---|
| 2066 | case 'image/gif': |
---|
| 2067 | $src_img = imagecreatefromgif($_FILES['cc_pd_photo']['tmp_name']); |
---|
| 2068 | if ($src_img == '') |
---|
| 2069 | { |
---|
| 2070 | $bogus = true; |
---|
| 2071 | } |
---|
| 2072 | break; |
---|
| 2073 | |
---|
| 2074 | default: |
---|
[285] | 2075 | |
---|
[2] | 2076 | $this->page_info['photos'][$id]['status'] = 'invalid_image'; |
---|
| 2077 | $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.'); |
---|
| 2078 | |
---|
| 2079 | $this->save_session(); |
---|
| 2080 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2081 | return; |
---|
| 2082 | } |
---|
| 2083 | |
---|
| 2084 | if ($bogus) |
---|
| 2085 | { |
---|
| 2086 | $this->page_info['photos'][$id]['status'] = 'invalid_file'; |
---|
| 2087 | $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); |
---|
[285] | 2088 | |
---|
[2] | 2089 | $this->save_session(); |
---|
| 2090 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2091 | return; |
---|
| 2092 | } |
---|
[285] | 2093 | |
---|
[2] | 2094 | $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']); |
---|
| 2095 | $dst_img = imagecreatetruecolor(60, 80); |
---|
[285] | 2096 | |
---|
[2] | 2097 | if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1])) |
---|
| 2098 | { |
---|
| 2099 | $this->page_info['photos'][$id]['status'] = 'invalid_file'; |
---|
| 2100 | $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); |
---|
[285] | 2101 | |
---|
[2] | 2102 | $this->save_session(); |
---|
| 2103 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2104 | return; |
---|
| 2105 | } |
---|
[285] | 2106 | |
---|
[2] | 2107 | ob_start(); |
---|
| 2108 | imagepng($dst_img); |
---|
| 2109 | $this->page_info['photos'][$id]['content'] = ob_get_contents(); |
---|
| 2110 | ob_end_clean(); |
---|
| 2111 | |
---|
| 2112 | $this->page_info['photos'][$id]['status'] = 'changed'; |
---|
| 2113 | $this->page_info['photos'][$id]['msg'] = lang('Photo Successfully Updated!'); |
---|
| 2114 | |
---|
| 2115 | $this->save_session(); |
---|
[285] | 2116 | |
---|
[2] | 2117 | $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); |
---|
| 2118 | |
---|
| 2119 | imagedestroy($src_img); |
---|
| 2120 | imagedestroy($dst_img); |
---|
| 2121 | echo 'ok'; |
---|
| 2122 | return; |
---|
| 2123 | } |
---|
| 2124 | |
---|
| 2125 | |
---|
| 2126 | /*! |
---|
| 2127 | |
---|
| 2128 | @function get_photo |
---|
| 2129 | @abstract Returns the photo to the browser |
---|
| 2130 | @author Raphael Derosso Pereira |
---|
| 2131 | |
---|
| 2132 | */ |
---|
| 2133 | function get_photo($id) |
---|
| 2134 | { |
---|
| 2135 | $fields = $this->bo->catalog->get_fields(false); |
---|
| 2136 | $fields['photo'] = true; |
---|
[285] | 2137 | |
---|
[2] | 2138 | $contact = $this->bo->catalog->get_single_entry($id, $fields); |
---|
| 2139 | |
---|
| 2140 | if (!$contact['photo']) |
---|
| 2141 | { |
---|
| 2142 | header('Content-type: image/png'); |
---|
| 2143 | echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png'); |
---|
| 2144 | return; |
---|
| 2145 | } |
---|
[285] | 2146 | |
---|
[2] | 2147 | header('Content-type: image/jpeg'); |
---|
| 2148 | $photo = imagecreatefromstring ($contact['photo']); |
---|
| 2149 | $width = imagesx($photo); |
---|
| 2150 | $height = imagesy($photo); |
---|
[16] | 2151 | $twidth = 70; |
---|
| 2152 | $theight = 90; |
---|
[2] | 2153 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
| 2154 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
| 2155 | imagejpeg($small_photo,"",100); |
---|
| 2156 | return; |
---|
| 2157 | } |
---|
[285] | 2158 | |
---|
[2] | 2159 | /*! |
---|
[285] | 2160 | |
---|
[2] | 2161 | @function get_states |
---|
| 2162 | @abstract Echos a serialized array containing all the states for the given country |
---|
| 2163 | @author Raphael Derosso Pereira |
---|
| 2164 | |
---|
| 2165 | @params $id_country The ID of the Country that contains the requested states |
---|
| 2166 | |
---|
| 2167 | */ |
---|
| 2168 | function get_states($id_country) |
---|
| 2169 | { |
---|
| 2170 | $states = $this->bo->catalog->get_all_states($id_country); |
---|
| 2171 | |
---|
| 2172 | if (!$states) |
---|
| 2173 | { |
---|
| 2174 | $result = array( |
---|
| 2175 | 'msg' => lang('No States found for this Country.'), |
---|
| 2176 | 'status' => 'empty' |
---|
| 2177 | ); |
---|
| 2178 | |
---|
| 2179 | echo serialize($result); |
---|
| 2180 | return; |
---|
| 2181 | } |
---|
[285] | 2182 | |
---|
[2] | 2183 | $result = array( |
---|
| 2184 | 'msg' => lang('States Successfully retrieved!'), |
---|
| 2185 | 'status' => 'ok' |
---|
| 2186 | ); |
---|
[285] | 2187 | |
---|
[2] | 2188 | foreach ($states as $state_info) |
---|
| 2189 | { |
---|
| 2190 | $result['data'][$state_info['id_state']] = $state_info['name']; |
---|
| 2191 | |
---|
| 2192 | if ($state_info['symbol']) |
---|
| 2193 | { |
---|
| 2194 | $result['data'][$state_info['id_state']] .= ', '.$state_info['symbol']; |
---|
| 2195 | } |
---|
| 2196 | } |
---|
| 2197 | |
---|
| 2198 | echo serialize($result); |
---|
| 2199 | } |
---|
| 2200 | |
---|
| 2201 | /*! |
---|
| 2202 | |
---|
| 2203 | @function get_cities |
---|
| 2204 | @abstract Echos a serialized array containing all the cities of a given state |
---|
| 2205 | @author Raphael Derosso Pereira |
---|
| 2206 | |
---|
| 2207 | @param $id_country The ID of the Country that has the specified Cities (in case the |
---|
| 2208 | Country doesn't have any States) |
---|
| 2209 | @param $id_state The ID of the State that has the Cities requested |
---|
| 2210 | |
---|
| 2211 | */ |
---|
| 2212 | function get_cities($id_country, $id_state=false) |
---|
| 2213 | { |
---|
| 2214 | $cities = $this->bo->catalog->get_all_cities($id_country, $id_state); |
---|
| 2215 | |
---|
| 2216 | if (!$cities) |
---|
| 2217 | { |
---|
| 2218 | $result = array( |
---|
| 2219 | 'msg' => lang('No Cities found for this State.'), |
---|
| 2220 | 'status' => 'empty' |
---|
| 2221 | ); |
---|
| 2222 | |
---|
| 2223 | echo serialize($result); |
---|
| 2224 | return; |
---|
| 2225 | } |
---|
[285] | 2226 | |
---|
[2] | 2227 | $result = array( |
---|
| 2228 | 'msg' => lang('Cities Successfully retrieved!'), |
---|
| 2229 | 'status' => 'ok' |
---|
| 2230 | ); |
---|
[285] | 2231 | |
---|
[2] | 2232 | foreach ($cities as $city_info) |
---|
| 2233 | { |
---|
| 2234 | $result['data'][$city_info['id_city']] = $city_info['name']; |
---|
| 2235 | } |
---|
[285] | 2236 | |
---|
[2] | 2237 | echo serialize($result); |
---|
| 2238 | } |
---|
| 2239 | |
---|
| 2240 | |
---|
| 2241 | /*! |
---|
[285] | 2242 | |
---|
[2] | 2243 | @function search |
---|
| 2244 | @abstract Echos a serialized array containing the IDs |
---|
| 2245 | of the entries that matches the search argument |
---|
| 2246 | @author Raphael Derosso Pereira |
---|
[285] | 2247 | @author Mário César Kolling (external catalogs) |
---|
[2] | 2248 | |
---|
| 2249 | @param string $str_data A serialized array with two informations: |
---|
| 2250 | $data = array( |
---|
| 2251 | 'search_for' => (string), |
---|
| 2252 | 'recursive' => (boolean), |
---|
| 2253 | ); |
---|
| 2254 | |
---|
| 2255 | */ |
---|
[285] | 2256 | // SERPRO |
---|
[2] | 2257 | function search($str_data) |
---|
| 2258 | { |
---|
| 2259 | $data = unserialize($str_data); |
---|
[284] | 2260 | // It's an external catalog? |
---|
| 2261 | $external = $this->bo->is_external($this->page_info['actual_catalog']); |
---|
[285] | 2262 | |
---|
| 2263 | if (!is_array($data) || !$data['search_for'] || !is_array($data['fields'])) |
---|
| 2264 | { |
---|
| 2265 | echo serialize(array( |
---|
| 2266 | 'msg' => lang('Invalid parameters'), |
---|
| 2267 | 'status' => 'abort' |
---|
| 2268 | )); |
---|
| 2269 | |
---|
| 2270 | return array('error' => lang('Invalid parameters')); |
---|
| 2271 | } |
---|
[2] | 2272 | |
---|
[285] | 2273 | |
---|
[284] | 2274 | /* |
---|
| 2275 | * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly |
---|
| 2276 | */ |
---|
| 2277 | // Support search parameters with accentuation |
---|
| 2278 | if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && |
---|
[503] | 2279 | $this->page_info['actual_catalog']['class'] != 'bo_group_manager' && |
---|
[752] | 2280 | $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && |
---|
| 2281 | $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
[284] | 2282 | { |
---|
| 2283 | |
---|
| 2284 | $data['search_for'] = utf8_encode($data['search_for']); |
---|
| 2285 | } |
---|
[285] | 2286 | |
---|
| 2287 | $rules = array(); |
---|
| 2288 | |
---|
| 2289 | |
---|
| 2290 | if ($data['search_for'] === '*') |
---|
| 2291 | { |
---|
| 2292 | $rules = array( |
---|
| 2293 | 0 => array( |
---|
| 2294 | 'field' => $data['fields']['search'], |
---|
| 2295 | 'type' => 'LIKE', |
---|
| 2296 | 'value' => '%' |
---|
| 2297 | ) |
---|
| 2298 | ); |
---|
| 2299 | } |
---|
| 2300 | else |
---|
| 2301 | { |
---|
| 2302 | $names = explode(' ', $data['search_for']); |
---|
| 2303 | |
---|
| 2304 | if (!is_array($names)) |
---|
| 2305 | { |
---|
| 2306 | echo serialize(array( |
---|
| 2307 | 'msg' => lang('Invalid Search Parameter'), |
---|
| 2308 | 'status' => 'abort' |
---|
| 2309 | )); |
---|
| 2310 | |
---|
| 2311 | } |
---|
[284] | 2312 | |
---|
| 2313 | if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && |
---|
[503] | 2314 | $this->page_info['actual_catalog']['class'] != 'bo_group_manager' && |
---|
[752] | 2315 | $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && |
---|
| 2316 | $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager' ) |
---|
[284] | 2317 | { |
---|
| 2318 | /* |
---|
| 2319 | * Restrict the returned contacts search to objectClass = phpgwAccount, |
---|
[880] | 2320 | * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1 |
---|
[284] | 2321 | */ |
---|
| 2322 | $rules = array( |
---|
| 2323 | 0 => array( |
---|
| 2324 | 'field' => 'contact.object_class', |
---|
| 2325 | 'type' => '=', |
---|
| 2326 | 'value' => 'phpgwAccount' |
---|
| 2327 | ), |
---|
| 2328 | 1 => array( |
---|
| 2329 | 'field' => 'contact.account_status', |
---|
| 2330 | 'type' => 'iLIKE', |
---|
| 2331 | 'value' => '%' |
---|
| 2332 | ), |
---|
| 2333 | 2 => array( |
---|
| 2334 | 'field' => 'contact.account_visible', |
---|
| 2335 | 'type' => '!=', |
---|
| 2336 | 'value' => '-1' |
---|
| 2337 | ), |
---|
| 2338 | ); |
---|
| 2339 | } |
---|
[285] | 2340 | |
---|
| 2341 | foreach ($names as $name) |
---|
| 2342 | { |
---|
| 2343 | if ($name != '') |
---|
| 2344 | { |
---|
| 2345 | array_push($rules, array( |
---|
| 2346 | 'field' => $data['fields']['search'], |
---|
| 2347 | 'type' => 'iLIKE', |
---|
| 2348 | 'value' => '%'.$name.'%' |
---|
| 2349 | )); |
---|
| 2350 | } |
---|
| 2351 | } |
---|
| 2352 | } |
---|
[284] | 2353 | |
---|
| 2354 | if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' || |
---|
[503] | 2355 | $this->page_info['actual_catalog']['class'] == 'bo_group_manager' || |
---|
[752] | 2356 | $this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager' || |
---|
| 2357 | $this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager' ) |
---|
[2] | 2358 | { |
---|
[284] | 2359 | // Get only this attributes: dn, cn for external catalogs, |
---|
| 2360 | // used to restrict the attributes used in filters |
---|
| 2361 | $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
[2] | 2362 | } |
---|
[284] | 2363 | else |
---|
| 2364 | { |
---|
| 2365 | // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible |
---|
| 2366 | // for non-external catalogs, used to restrict the attributes used in filters |
---|
| 2367 | $ids = $this->bo->find(array( |
---|
| 2368 | $data['fields']['id'], |
---|
| 2369 | $data['fields']['search'], |
---|
| 2370 | 'contact.object_class', |
---|
[304] | 2371 | //'contact.account_status', |
---|
[284] | 2372 | 'contact.account_visible' |
---|
| 2373 | ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
| 2374 | } |
---|
[2] | 2375 | |
---|
[285] | 2376 | if (!is_array($ids) || !count($ids)) |
---|
| 2377 | { |
---|
[284] | 2378 | $this->last_search_ids = null; |
---|
| 2379 | $this->save_session(); |
---|
| 2380 | return null; |
---|
[285] | 2381 | } |
---|
[2] | 2382 | |
---|
[285] | 2383 | $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1); |
---|
| 2384 | |
---|
| 2385 | $ids_f = array(); |
---|
[2] | 2386 | |
---|
[285] | 2387 | foreach ($ids as $e_info) |
---|
| 2388 | { |
---|
[752] | 2389 | if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager') |
---|
[503] | 2390 | $ids_f[] = $e_info[$id_field]; |
---|
| 2391 | else |
---|
| 2392 | $ids_f[] = array(0=>$e_info[$id_field],1=>$e_info['perms']); |
---|
[285] | 2393 | } |
---|
[284] | 2394 | |
---|
| 2395 | return $ids_f; |
---|
[2] | 2396 | } |
---|
[285] | 2397 | |
---|
| 2398 | // CELEPAR |
---|
| 2399 | /* |
---|
| 2400 | function search($str_data) |
---|
| 2401 | { |
---|
| 2402 | $data = unserialize($str_data); |
---|
[2] | 2403 | |
---|
[285] | 2404 | if (!is_array($data) || !$data['search_for'] || !is_array($data['fields'])) |
---|
| 2405 | { |
---|
| 2406 | echo serialize(array( |
---|
| 2407 | 'msg' => lang('Invalid parameters'), |
---|
| 2408 | 'status' => 'abort' |
---|
| 2409 | )); |
---|
| 2410 | |
---|
| 2411 | return; |
---|
| 2412 | } |
---|
| 2413 | |
---|
| 2414 | $rules = array(); |
---|
| 2415 | |
---|
| 2416 | if ($data['search_for'] === '*') |
---|
| 2417 | { |
---|
| 2418 | $rules = array( |
---|
| 2419 | 0 => array( |
---|
| 2420 | 'field' => $data['fields']['search'], |
---|
| 2421 | 'type' => 'LIKE', |
---|
| 2422 | 'value' => '%' |
---|
| 2423 | ) |
---|
| 2424 | ); |
---|
| 2425 | } |
---|
| 2426 | else |
---|
| 2427 | { |
---|
| 2428 | $names = explode(' ', $data['search_for']); |
---|
| 2429 | |
---|
| 2430 | if (!is_array($names)) |
---|
| 2431 | { |
---|
| 2432 | echo serialize(array( |
---|
| 2433 | 'msg' => lang('Invalid Search Parameter'), |
---|
| 2434 | 'status' => 'abort' |
---|
| 2435 | )); |
---|
| 2436 | |
---|
| 2437 | return; |
---|
| 2438 | } |
---|
| 2439 | |
---|
| 2440 | foreach ($names as $name) |
---|
| 2441 | { |
---|
| 2442 | if ($name != '') |
---|
| 2443 | { |
---|
| 2444 | array_push($rules, array( |
---|
| 2445 | 'field' => $data['fields']['search'], |
---|
| 2446 | 'type' => 'iLIKE', |
---|
| 2447 | 'value' => '%'.$name.'%' |
---|
| 2448 | )); |
---|
| 2449 | } |
---|
| 2450 | } |
---|
| 2451 | } |
---|
| 2452 | |
---|
| 2453 | |
---|
| 2454 | |
---|
| 2455 | //$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); |
---|
| 2456 | |
---|
| 2457 | //if ($catalog['class'] === 'bo_people_catalog') |
---|
| 2458 | //{ |
---|
| 2459 | // array_push($rules, array( |
---|
| 2460 | // 'field' => 'contact.id_owner', |
---|
| 2461 | // 'type' => '=', |
---|
| 2462 | // 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 2463 | // )); |
---|
| 2464 | //} |
---|
| 2465 | |
---|
| 2466 | |
---|
| 2467 | $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); |
---|
| 2468 | |
---|
| 2469 | if (!is_array($ids) || !count($ids)) |
---|
| 2470 | { |
---|
| 2471 | echo serialize(array( |
---|
| 2472 | 'msg' => lang('No Entries Found!'), |
---|
| 2473 | 'status' => 'empty' |
---|
| 2474 | )); |
---|
| 2475 | |
---|
| 2476 | return; |
---|
| 2477 | } |
---|
| 2478 | $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1); |
---|
| 2479 | |
---|
| 2480 | $ids_f = array(); |
---|
| 2481 | foreach ($ids as $e_info) |
---|
| 2482 | { |
---|
| 2483 | $ids_f[] = $e_info[$id_field]; |
---|
| 2484 | } |
---|
| 2485 | |
---|
| 2486 | echo serialize(array( |
---|
| 2487 | 'data' => $ids_f, |
---|
| 2488 | 'msg' => lang('Found %1 Entries', count($ids)), |
---|
| 2489 | 'status' => 'ok' |
---|
| 2490 | )); |
---|
| 2491 | |
---|
| 2492 | return; |
---|
| 2493 | }*/ |
---|
[2] | 2494 | /*! |
---|
| 2495 | |
---|
| 2496 | @function get_multiple_entries |
---|
| 2497 | @abstract Returns an array containing the specifiend data in the default |
---|
| 2498 | CC UI format |
---|
| 2499 | @author Raphael Derosso Pereira |
---|
| 2500 | |
---|
[285] | 2501 | @param array str_data A serialized array containing the ID's of the entries |
---|
[2] | 2502 | to be taken, the fields to be taken and the rules to be used on the |
---|
| 2503 | retrieval: |
---|
| 2504 | $data = array( |
---|
| 2505 | 'ids' => array(...), |
---|
| 2506 | 'fields' => array(...), |
---|
| 2507 | 'rules' => array(...) |
---|
| 2508 | ); |
---|
| 2509 | |
---|
| 2510 | */ |
---|
| 2511 | function get_multiple_entries($str_data) |
---|
| 2512 | { |
---|
| 2513 | $data = unserialize($str_data); |
---|
[285] | 2514 | |
---|
[2] | 2515 | if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids'])) |
---|
| 2516 | { |
---|
| 2517 | return array( |
---|
| 2518 | 'msg' => lang('Invalid Parameters'), |
---|
| 2519 | 'status' => 'abort' |
---|
| 2520 | ); |
---|
| 2521 | } |
---|
| 2522 | |
---|
| 2523 | $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']); |
---|
[285] | 2524 | |
---|
[2] | 2525 | if (!is_array($entries) or !count($entries)) |
---|
| 2526 | { |
---|
| 2527 | return array( |
---|
| 2528 | 'msg' => lang('No Entries Found!'), |
---|
| 2529 | 'status' => 'empty' |
---|
| 2530 | ); |
---|
| 2531 | } |
---|
| 2532 | |
---|
| 2533 | return array( |
---|
| 2534 | 'msg' => lang('Found %1 Entries!', count($entries)), |
---|
| 2535 | 'status' => 'ok', |
---|
| 2536 | 'data' => $entries |
---|
| 2537 | ); |
---|
| 2538 | } |
---|
| 2539 | |
---|
| 2540 | /* |
---|
| 2541 | |
---|
| 2542 | @function get_all_entries |
---|
[285] | 2543 | @abstract Returns the specified fields for all catalog's entries |
---|
[2] | 2544 | in the default CC UI format |
---|
| 2545 | @author Raphael Derosso Pereira |
---|
| 2546 | |
---|
[285] | 2547 | @params array str_data A serialized array containing the fields to |
---|
[2] | 2548 | be grabbed, the maximum number of entries to be returned and a |
---|
| 2549 | boolean specifying if the calls refers to a new grab or to an |
---|
| 2550 | unfinished one. |
---|
| 2551 | |
---|
| 2552 | */ |
---|
| 2553 | function get_all_entries($str_data) |
---|
| 2554 | { |
---|
| 2555 | $data = unserialize($str_data); |
---|
[285] | 2556 | |
---|
| 2557 | if (!is_array($data) or |
---|
| 2558 | !count($data) or |
---|
| 2559 | !count($data['fields']) or |
---|
[2] | 2560 | !$data['maxlength'] or |
---|
| 2561 | (!$data['new'] and !$data['offset'])) |
---|
| 2562 | { |
---|
| 2563 | return array( |
---|
| 2564 | 'msg' => lang('Invalid Parameters'), |
---|
| 2565 | 'status' => 'abort' |
---|
| 2566 | ); |
---|
| 2567 | } |
---|
| 2568 | |
---|
| 2569 | if ($data['new']) |
---|
| 2570 | { |
---|
| 2571 | $this->all_entries = $this->bo->catalog->get_all_entries_ids(); |
---|
| 2572 | |
---|
| 2573 | $this->save_session(); |
---|
| 2574 | |
---|
| 2575 | if (!is_array($this->all_entries) or !count($this->all_entries)) |
---|
| 2576 | { |
---|
| 2577 | return array( |
---|
| 2578 | 'msg' => lang('No Entries Found!'), |
---|
| 2579 | 'status' => 'empty' |
---|
| 2580 | ); |
---|
| 2581 | } |
---|
| 2582 | |
---|
| 2583 | $data['offset'] = 0; |
---|
| 2584 | } |
---|
[285] | 2585 | |
---|
[2] | 2586 | if ($data['maxlength'] != -1) |
---|
| 2587 | { |
---|
| 2588 | $result = $this->bo->catalog->get_multiple_entries(array_slice($this->all_entries, $data['offset'], $data['maxlength']), $data['fields']); |
---|
| 2589 | } |
---|
| 2590 | else |
---|
| 2591 | { |
---|
| 2592 | $result = $this->bo->catalog->get_multiple_entries($this->all_entries, $data['fields']); |
---|
| 2593 | } |
---|
| 2594 | |
---|
| 2595 | $prefs = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
[285] | 2596 | |
---|
[2] | 2597 | $jsCode = array(); |
---|
| 2598 | $count = 0; |
---|
| 2599 | foreach ($result as $each) |
---|
| 2600 | { |
---|
| 2601 | if (!is_array($each)) |
---|
| 2602 | { |
---|
| 2603 | continue; |
---|
| 2604 | } |
---|
| 2605 | |
---|
[285] | 2606 | if($this-> typeContact == 'groups') { |
---|
| 2607 | |
---|
[2] | 2608 | foreach ($each as $field => $value) { |
---|
[285] | 2609 | |
---|
[2] | 2610 | if ($field === 'title') { |
---|
| 2611 | $optionName = '\\"'.$value.'\\"'; |
---|
[285] | 2612 | |
---|
[2] | 2613 | } |
---|
| 2614 | else if ($field === 'short_name') { |
---|
[285] | 2615 | |
---|
[2] | 2616 | $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");'; |
---|
[285] | 2617 | $count++; |
---|
| 2618 | } |
---|
[2] | 2619 | } |
---|
| 2620 | } |
---|
[285] | 2621 | |
---|
| 2622 | else { |
---|
[2] | 2623 | foreach ($each as $field => $value) { |
---|
| 2624 | if ($field === 'names_ordered') { |
---|
| 2625 | if(is_array($value)) |
---|
| 2626 | $value = $value[0]; |
---|
| 2627 | $name = '\\"'.$value.'\\"'; |
---|
| 2628 | } |
---|
| 2629 | else if ($field === 'connections') { |
---|
[285] | 2630 | |
---|
[2] | 2631 | foreach ($value as $connection) { |
---|
| 2632 | if ($connection['id_type'] == $prefs['personCardEmail']) { |
---|
| 2633 | $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$name.' <'.$connection['connection_value'].'>", "'.$count.'");'; |
---|
| 2634 | $count++; |
---|
| 2635 | } |
---|
| 2636 | } |
---|
| 2637 | } |
---|
| 2638 | } |
---|
| 2639 | } |
---|
| 2640 | } |
---|
| 2641 | |
---|
| 2642 | $jsCodeFinal = implode("\n", $jsCode); |
---|
[285] | 2643 | |
---|
[2] | 2644 | $nEntries = count($result); |
---|
[285] | 2645 | |
---|
[2] | 2646 | if (!$nEntries) |
---|
| 2647 | { |
---|
| 2648 | return array( |
---|
| 2649 | 'msg' => lang('Error while getting user information...'), |
---|
| 2650 | 'status' => 'abort' |
---|
| 2651 | ); |
---|
| 2652 | } |
---|
| 2653 | |
---|
| 2654 | return array( |
---|
| 2655 | 'msg' => lang('Found %1 Entries!', $nEntries), |
---|
| 2656 | 'status' => 'ok', |
---|
| 2657 | 'typeContact' => $this -> typeContact, |
---|
| 2658 | 'final' => $nEntries + $data['offset'] < count($this->all_entries) ? false : true, |
---|
| 2659 | 'offset' => $data['offset'] + $nEntries, |
---|
| 2660 | 'data' => $jsCodeFinal |
---|
| 2661 | ); |
---|
| 2662 | } |
---|
[285] | 2663 | |
---|
[2] | 2664 | /*********************************************************************\ |
---|
| 2665 | * Auxiliar Methods * |
---|
| 2666 | \*********************************************************************/ |
---|
| 2667 | |
---|
| 2668 | /*! |
---|
[285] | 2669 | |
---|
[2] | 2670 | @function save_session |
---|
| 2671 | @abstract Saves the data on the session |
---|
| 2672 | @author Raphael Derosso Pereira |
---|
[285] | 2673 | |
---|
[2] | 2674 | */ |
---|
| 2675 | function save_session() |
---|
| 2676 | { |
---|
| 2677 | $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info); |
---|
| 2678 | $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries); |
---|
| 2679 | } |
---|
| 2680 | |
---|
| 2681 | /*! |
---|
[285] | 2682 | |
---|
[2] | 2683 | @function convert_tree |
---|
| 2684 | @abstract Converts the tree array in the BO format to a JS tree array compatible |
---|
| 2685 | with the one available in eGW |
---|
| 2686 | @author Raphael Derosso Pereira |
---|
[285] | 2687 | |
---|
[2] | 2688 | @param (array) $tree The tree in the BO format |
---|
| 2689 | @param (string) $name The tree name |
---|
| 2690 | @param (string) $iconDir The dir where the icons are |
---|
| 2691 | @param (string) $parent The parent |
---|
| 2692 | */ |
---|
| 2693 | |
---|
| 2694 | function convert_tree($tree, &$iconDir, $parent='0') |
---|
| 2695 | { |
---|
| 2696 | // echo "Entrou<br>\tPai: $parent <br>"; |
---|
| 2697 | $rtree = array(); |
---|
| 2698 | |
---|
| 2699 | if ($parent === '0') |
---|
| 2700 | { |
---|
| 2701 | // echo 'Root!<br>'; |
---|
| 2702 | $rtree['0'] = array( |
---|
| 2703 | 'type' => 'catalog_group', |
---|
| 2704 | 'id' => '0', |
---|
| 2705 | 'pid' => 'none', |
---|
| 2706 | 'caption' => lang('Catalogues'), |
---|
| 2707 | 'class' => 'bo_catalog_group_catalog', |
---|
| 2708 | 'class_args' => array('_ROOT_', '$this', '$this->get_branch_by_level($this->catalog_level[0])') |
---|
| 2709 | ); |
---|
| 2710 | } |
---|
| 2711 | |
---|
| 2712 | foreach($tree as $id => $value) |
---|
| 2713 | { |
---|
| 2714 | // echo 'ID: '.$id.'<br>'; |
---|
| 2715 | $rtree[$parent.'.'.$id] = array( |
---|
| 2716 | 'type' => $value['type'], |
---|
| 2717 | 'id' => $parent.'.'.$id, |
---|
| 2718 | 'pid' => $parent, |
---|
| 2719 | 'caption' => $value['name'] |
---|
| 2720 | ); |
---|
[285] | 2721 | |
---|
[2] | 2722 | switch($value['type']) |
---|
| 2723 | { |
---|
| 2724 | case 'catalog_group': |
---|
| 2725 | case 'mixed_catalog_group': |
---|
| 2726 | $rtree = $rtree + $this->convert_tree($value['sub_branch'],$iconDir,$parent.'.'.$id); |
---|
| 2727 | break; |
---|
| 2728 | } |
---|
| 2729 | } |
---|
| 2730 | |
---|
| 2731 | if (count($rtree)) |
---|
| 2732 | { |
---|
| 2733 | return $rtree; |
---|
| 2734 | } |
---|
| 2735 | } |
---|
| 2736 | |
---|
| 2737 | function get_catalog_add_contact($id){ |
---|
| 2738 | |
---|
| 2739 | $array_participants = array(); |
---|
[13] | 2740 | if(!$this->bo->catalog->src_info) { |
---|
| 2741 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
| 2742 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
[2] | 2743 | } |
---|
[285] | 2744 | |
---|
| 2745 | $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] | 2746 | $dn=$this->bo->catalog->src_info['dn']; |
---|
| 2747 | $justThese = array("givenname","givenname","sn","telephonenumber","mail"); |
---|
[285] | 2748 | $sr = ldap_read($ds,$id, "objectClass=*",$justThese); |
---|
| 2749 | $info = ldap_get_entries($ds, $sr); |
---|
[13] | 2750 | for($z = 0; $z < 5; $z++) { |
---|
[285] | 2751 | $participant = $info[0][$justThese[$z]]; |
---|
[13] | 2752 | array_push($array_participants, $participant); |
---|
| 2753 | } |
---|
| 2754 | |
---|
| 2755 | ldap_close($ds); |
---|
[2] | 2756 | echo serialize($array_participants); |
---|
[285] | 2757 | } |
---|
| 2758 | |
---|
[880] | 2759 | function get_catalog_participants_group($id) |
---|
| 2760 | { |
---|
| 2761 | if(!$this->bo->catalog->src_info) { |
---|
| 2762 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
| 2763 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
| 2764 | } |
---|
| 2765 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
| 2766 | $justThese = array("description","memberuid"); |
---|
| 2767 | $sr = ldap_read($ds,$id, "objectClass=*",$justThese); |
---|
| 2768 | $info = ldap_get_entries($ds, $sr); |
---|
| 2769 | $member_uids = $info[0]['memberuid']; |
---|
| 2770 | $contact['names_ordered'] = $info[0]['description']; |
---|
| 2771 | $filter = ""; |
---|
| 2772 | for($z = 0; $z < count($member_uids); $z++) { |
---|
| 2773 | if($member_uids[$z]) |
---|
| 2774 | $filter.="(uid=".$member_uids[$z].")"; |
---|
| 2775 | } |
---|
| 2776 | $array_participants = array(); |
---|
| 2777 | if($filter) { |
---|
[962] | 2778 | $filter = "(|".$filter.")"; |
---|
[904] | 2779 | $valarray = explode(',',$id); |
---|
| 2780 | array_shift($valarray); |
---|
| 2781 | $dn = implode(',',$valarray); |
---|
[880] | 2782 | $justThese = array("cn","mail"); |
---|
| 2783 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
| 2784 | $info = ldap_get_entries($ds, $sr); |
---|
| 2785 | for($z = 0; $z < $info['count']; $z++) { |
---|
| 2786 | $participant = '<font color=\'DARKBLUE\'> "'.$info[$z]['cn'][0].'" <'.$info[$z]['mail'][0].'></font><br>'; |
---|
| 2787 | $array_emails[$info[$z]['mail'][0]] = null; |
---|
| 2788 | array_push($array_participants, $participant); |
---|
| 2789 | } |
---|
| 2790 | ldap_close($ds); |
---|
| 2791 | } |
---|
| 2792 | sort($array_participants); |
---|
| 2793 | $innerHTML = ''; |
---|
| 2794 | foreach($array_participants as $index => $participant){ |
---|
| 2795 | $innerHTML .= $participant; |
---|
| 2796 | } |
---|
| 2797 | $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); |
---|
| 2798 | echo serialize($return); |
---|
| 2799 | } |
---|
| 2800 | |
---|
[285] | 2801 | function get_catalog_participants_list($id) |
---|
[2] | 2802 | { |
---|
[285] | 2803 | |
---|
| 2804 | $fields = $this->bo->catalog->get_fields(false); |
---|
[2] | 2805 | $fields['names_ordered'] = true; |
---|
[285] | 2806 | $fields['mail_forwarding_address'] = true; |
---|
| 2807 | $contact = $this->bo->catalog->get_single_entry($id,$fields); |
---|
| 2808 | |
---|
[2] | 2809 | $array_participants = array(); |
---|
| 2810 | $array_emails = array(); |
---|
[880] | 2811 | |
---|
[2] | 2812 | $filter = null; |
---|
[285] | 2813 | for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) { |
---|
[2] | 2814 | if(strstr($contact['mail_forwarding_address'][$z],'@')) { |
---|
| 2815 | $filter.="(mail=".$contact['mail_forwarding_address'][$z].")"; |
---|
| 2816 | $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>"; |
---|
[285] | 2817 | } |
---|
| 2818 | else |
---|
[2] | 2819 | $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>"; |
---|
[285] | 2820 | } |
---|
| 2821 | |
---|
[2] | 2822 | if($filter) { |
---|
[285] | 2823 | $filter = "(|".$filter.")"; |
---|
[2] | 2824 | if(!$this->bo->catalog->src_info) { |
---|
| 2825 | $ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
| 2826 | $this->bo->catalog->src_info = $ldap->srcs[1]; |
---|
| 2827 | } |
---|
[880] | 2828 | $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); |
---|
| 2829 | |
---|
[2] | 2830 | $dn=$this->bo->catalog->src_info['dn']; |
---|
| 2831 | $justThese = array("cn","mail"); |
---|
[285] | 2832 | $sr = ldap_search($ds,$dn, $filter,$justThese); |
---|
| 2833 | $info = ldap_get_entries($ds, $sr); |
---|
[2] | 2834 | for($z = 0; $z < $info['count']; $z++) { |
---|
[24] | 2835 | $participant = '<font color=\'DARKBLUE\'> "'.$info[$z]['cn'][0].'" <'.$info[$z]['mail'][0].'></font><br>'; |
---|
[285] | 2836 | $array_emails[$info[$z]['mail'][0]] = null; |
---|
| 2837 | array_push($array_participants, $participant); |
---|
[2] | 2838 | } |
---|
[285] | 2839 | |
---|
[2] | 2840 | foreach($array_emails as $index => $email) |
---|
[285] | 2841 | if($email) |
---|
| 2842 | array_push($array_participants, " ".$email."<br>"); |
---|
| 2843 | |
---|
[2] | 2844 | ldap_close($ds); |
---|
| 2845 | } |
---|
| 2846 | sort($array_participants); |
---|
[285] | 2847 | $innerHTML = ''; |
---|
[24] | 2848 | foreach($array_participants as $index => $participant){ |
---|
| 2849 | $innerHTML .= $participant; |
---|
| 2850 | } |
---|
[285] | 2851 | $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); |
---|
[24] | 2852 | echo serialize($return); |
---|
[285] | 2853 | } |
---|
| 2854 | |
---|
[2] | 2855 | function export_contacts($typeExport){ |
---|
| 2856 | |
---|
| 2857 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
| 2858 | $contacts = $boGroup->get_all_contacts(); |
---|
| 2859 | $streamBuffer = ''; |
---|
| 2860 | |
---|
| 2861 | if(!count($contacts)) |
---|
| 2862 | echo null; |
---|
[285] | 2863 | |
---|
[2] | 2864 | switch($typeExport) { |
---|
| 2865 | |
---|
| 2866 | case 'outlook_en': |
---|
| 2867 | $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;". |
---|
[285] | 2868 | "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n"; |
---|
[293] | 2869 | foreach($contacts as $index => $object){ |
---|
| 2870 | $streamBuffer.= $object['names_ordered'].";".$object['connection_value'].";;;;;;".$object['phone'].";;;\r\n"; |
---|
[2] | 2871 | } |
---|
| 2872 | break; |
---|
[285] | 2873 | |
---|
[2] | 2874 | case 'outlook_pt-BR': |
---|
[285] | 2875 | $streamBuffer = "Nome;End. de email;Endereço residencial;". |
---|
| 2876 | "Cidade do endereço residencial;CEP do endereço residencial;". |
---|
| 2877 | "Estado;País/região do endereço residencial;Telefone residencial;". |
---|
| 2878 | "Rua do endereço comercial;Cidade do endereço comercial;". |
---|
| 2879 | "CEP do endereço comercial;Estado do endereço comercial;". |
---|
| 2880 | "País/região do endereço comercial;Telefone comercial;Empresa;Cargo\r\n"; |
---|
[293] | 2881 | foreach($contacts as $index => $object){ |
---|
| 2882 | $streamBuffer.= $object['names_ordered'].";".$object['connection_value'].";;;;;;".$object['phone'].";;;;;;;;\r\n"; |
---|
[2] | 2883 | } |
---|
| 2884 | break; |
---|
[285] | 2885 | |
---|
[15] | 2886 | case 'outlook2000_pt-BR': |
---|
| 2887 | $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",". |
---|
[285] | 2888 | "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",". |
---|
| 2889 | "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",". |
---|
| 2890 | "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",". |
---|
| 2891 | "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",". |
---|
| 2892 | "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",". |
---|
[15] | 2893 | "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",". |
---|
| 2894 | "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",". |
---|
| 2895 | "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",". |
---|
[285] | 2896 | "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",". |
---|
| 2897 | "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",". |
---|
| 2898 | "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",". |
---|
| 2899 | "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",". |
---|
| 2900 | "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",". |
---|
| 2901 | "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",". |
---|
| 2902 | "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",". |
---|
| 2903 | "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",". |
---|
[15] | 2904 | "\"Sexo\"\r\n"; |
---|
[293] | 2905 | foreach($contacts as $index => $object){ |
---|
| 2906 | $streamBuffer.= ",\"".$object['names_ordered']."\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,".$object['phone'].",,,,,,,,,,,,\"".$object['connection_value']."\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; |
---|
[15] | 2907 | } |
---|
| 2908 | break; |
---|
[285] | 2909 | |
---|
[15] | 2910 | case 'outlook2000_en': |
---|
| 2911 | $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,". |
---|
| 2912 | "Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,". |
---|
| 2913 | "Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,". |
---|
| 2914 | "Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,". |
---|
| 2915 | "Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,". |
---|
| 2916 | "Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,". |
---|
| 2917 | "Account,Anniversary,Assistant's Name,Billing Information,Birthday,Categories,Children,Directory Server,E-mail Address,". |
---|
| 2918 | "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,". |
---|
| 2919 | "Gender,Government ID Number,Hobby,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,". |
---|
| 2920 | "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] | 2921 | foreach($contacts as $index => $object){ |
---|
| 2922 | $streamBuffer.= ",".$object['names_ordered'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,".$object['phone'].",,,,,,,,,,,,".$object['connection_value'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; |
---|
[15] | 2923 | } |
---|
| 2924 | break; |
---|
[285] | 2925 | |
---|
[2] | 2926 | case 'thunderbird': |
---|
[285] | 2927 | $streamBuffer = "\n"; |
---|
[293] | 2928 | foreach($contacts as $index => $object){ |
---|
| 2929 | $streamBuffer.= ",,".$object['names_ordered'].",,".$object['connection_value'].",,".$object['phone'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; |
---|
[2] | 2930 | } |
---|
| 2931 | break; |
---|
[285] | 2932 | |
---|
| 2933 | case 'expresso': |
---|
[16] | 2934 | $streamBuffer = "Nome,Email,Telefone\r\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 | |
---|
[2] | 2940 | } |
---|
| 2941 | |
---|
| 2942 | $file = "contacts_".md5(microtime()).".swp"; |
---|
| 2943 | $tempDir = ini_get("session.save_path"); |
---|
| 2944 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
| 2945 | if(!$f) |
---|
| 2946 | echo null; |
---|
[285] | 2947 | |
---|
[2] | 2948 | fputs($f,$streamBuffer); |
---|
| 2949 | fclose($f); |
---|
| 2950 | |
---|
| 2951 | echo $tempDir.'/'.$file; |
---|
| 2952 | } |
---|
| 2953 | |
---|
[285] | 2954 | // Get the csv field and put into array, from php.net |
---|
| 2955 | function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') { |
---|
| 2956 | $text = trim($input_text); |
---|
| 2957 | if(is_string($delimiter) && is_string($text_qualifier)) { |
---|
| 2958 | $re_d = '\x' . dechex(ord($delimiter)); //format for regexp |
---|
| 2959 | $re_tq = '\x' . dechex(ord($text_qualifier)); //format for regexp |
---|
| 2960 | |
---|
| 2961 | $fields = array(); |
---|
| 2962 | $field_num = 0; |
---|
| 2963 | while(strlen($text) > 0) { |
---|
| 2964 | if($text{0} == $text_qualifier) { |
---|
| 2965 | preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches); |
---|
| 2966 | |
---|
| 2967 | $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]); |
---|
| 2968 | $text = trim($matches[2]); |
---|
| 2969 | |
---|
| 2970 | $fields[$field_num++] = $value; |
---|
| 2971 | } else { |
---|
| 2972 | preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches); |
---|
| 2973 | |
---|
| 2974 | $value = $matches[1]; |
---|
| 2975 | $text = trim($matches[2]); |
---|
| 2976 | |
---|
| 2977 | $fields[$field_num++] = $value; |
---|
| 2978 | } |
---|
| 2979 | } |
---|
| 2980 | return $fields; |
---|
| 2981 | } else |
---|
| 2982 | return false; |
---|
| 2983 | } |
---|
[16] | 2984 | |
---|
[2] | 2985 | function import_contacts($typeImport){ |
---|
[276] | 2986 | |
---|
[285] | 2987 | if($file = $_SESSION['contactcenter']['importCSV']) { |
---|
| 2988 | unset($_SESSION['contactcenter']['importCSV']); |
---|
[2] | 2989 | $len = filesize($file); |
---|
| 2990 | $count = 0; |
---|
| 2991 | $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0); |
---|
[276] | 2992 | $handle = @fopen($file, "r") or die(serialize($return['error'] = true)); |
---|
[285] | 2993 | |
---|
| 2994 | $input_header = fgets($handle); |
---|
| 2995 | if ($typeImport == 'outlook') |
---|
| 2996 | $delim = ';'; |
---|
| 2997 | else if ($typeImport == 'auto') |
---|
| 2998 | $delim = strstr($input_header,',') ? ',' : ';'; |
---|
| 2999 | else |
---|
| 3000 | $delim = ','; |
---|
| 3001 | $csv_header = $this->parse_line($input_header,$delim); |
---|
| 3002 | $firstContact = fgets($handle); |
---|
| 3003 | preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv |
---|
| 3004 | rewind($handle); |
---|
| 3005 | |
---|
[2] | 3006 | $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true)); |
---|
[15] | 3007 | if(count($header) < 2 || count($header) > 100) { |
---|
[2] | 3008 | $return['error'] = true; |
---|
| 3009 | $return['sizeheader'] = count($header); |
---|
| 3010 | echo serialize($return); |
---|
| 3011 | return; |
---|
| 3012 | } |
---|
[285] | 3013 | |
---|
| 3014 | if ($matches[0][strlen($matches[0])-1] == ';') |
---|
| 3015 | $delim = ';'; |
---|
| 3016 | |
---|
| 3017 | $boGroup = CreateObject('contactcenter.bo_group'); |
---|
| 3018 | $boPeople = CreateObject('contactcenter.bo_people_catalog'); |
---|
[15] | 3019 | switch($typeImport){ |
---|
| 3020 | case 'outlook2000': |
---|
[16] | 3021 | $name_pos=1; |
---|
| 3022 | $email_pos=56; |
---|
| 3023 | $phone_pos=44; |
---|
[15] | 3024 | break; |
---|
[16] | 3025 | case 'outlook': |
---|
| 3026 | $name_pos=0; |
---|
| 3027 | $email_pos=1; |
---|
| 3028 | $phone_pos=7; |
---|
| 3029 | break; |
---|
[15] | 3030 | case 'thunderbird': |
---|
[16] | 3031 | $name_pos=2; |
---|
| 3032 | $email_pos=4; |
---|
[19] | 3033 | $phone_pos=7; |
---|
[15] | 3034 | break; |
---|
[285] | 3035 | case 'expresso': |
---|
[16] | 3036 | $name_pos=0; |
---|
| 3037 | $email_pos=1; |
---|
| 3038 | $phone_pos=2; |
---|
[285] | 3039 | break; |
---|
| 3040 | default: |
---|
| 3041 | foreach($csv_header as $index => $fieldName) |
---|
| 3042 | { |
---|
[575] | 3043 | switch(strtoupper($fieldName)){ |
---|
| 3044 | case 'NAME': |
---|
| 3045 | case 'NOME': |
---|
| 3046 | case 'FIRST NAME': |
---|
[285] | 3047 | $name_pos = $index; |
---|
| 3048 | break; |
---|
[575] | 3049 | case 'E-MAIL': |
---|
| 3050 | case 'EMAIL': |
---|
| 3051 | case 'E-MAIL ADDRESS': |
---|
| 3052 | case 'ENDEREÇO DE CORREIO ELETRÔNICO': |
---|
| 3053 | case 'END. DE EMAIL': |
---|
[285] | 3054 | $email_pos = $index; |
---|
| 3055 | break; |
---|
[575] | 3056 | case 'HOME PHONE': |
---|
| 3057 | case 'PHONE': |
---|
| 3058 | case 'TELEFONE': |
---|
| 3059 | case 'TELEFONE PRINCIPAL': |
---|
| 3060 | case 'TELEFONE COMERCIAL': |
---|
[285] | 3061 | $phone_pos = $index; |
---|
| 3062 | break; |
---|
| 3063 | } |
---|
[575] | 3064 | } |
---|
[285] | 3065 | break; |
---|
[15] | 3066 | } |
---|
[285] | 3067 | |
---|
[276] | 3068 | |
---|
[2] | 3069 | while (($data = fgetcsv($handle, $len, $delim))) { |
---|
| 3070 | foreach ($header as $key=>$heading) |
---|
| 3071 | $row[$heading]=(isset($data[$key])) ? $data[$key] : ''; |
---|
[285] | 3072 | |
---|
[2] | 3073 | $sdata = array(); |
---|
[16] | 3074 | $full_name = trim($row[$header[$name_pos]]); |
---|
| 3075 | $email = trim($row[$header[$email_pos]]); |
---|
| 3076 | $phone = trim($row[$header[$phone_pos]]); |
---|
[2] | 3077 | $array_name = explode(' ', str_replace('"','',(str_replace('\'','',$full_name)))); |
---|
| 3078 | $sdata['given_names'] = $array_name[0]; |
---|
| 3079 | $array_name[0] = null; |
---|
| 3080 | $sdata['family_names'] = trim(implode(' ',$array_name)); |
---|
| 3081 | $sdata['connections']['default_email']['connection_name'] = lang('Main'); |
---|
[16] | 3082 | $sdata['connections']['default_email']['connection_value'] = $email; |
---|
[2] | 3083 | |
---|
[16] | 3084 | $sdata['connections']['default_phone']['connection_name'] = lang('Main'); |
---|
| 3085 | $sdata['connections']['default_phone']['connection_value'] = $phone; |
---|
[285] | 3086 | |
---|
| 3087 | // verifica se email já existe! |
---|
[2] | 3088 | $contact = $boGroup->verify_contact($email); |
---|
[285] | 3089 | |
---|
| 3090 | if(!$sdata['given_names'] && $email){ |
---|
| 3091 | $a_email = explode("@",$email); |
---|
| 3092 | $sdata['given_names'] = $a_email[0]; |
---|
| 3093 | } |
---|
[2] | 3094 | |
---|
[285] | 3095 | $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new']; |
---|
[2] | 3096 | if($contact){ |
---|
| 3097 | $return['_existing']++; |
---|
[285] | 3098 | } |
---|
[2] | 3099 | else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { |
---|
| 3100 | $return['_failure']++; |
---|
[285] | 3101 | $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>"; |
---|
[16] | 3102 | } |
---|
[284] | 3103 | else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){ |
---|
[285] | 3104 | $return['_failure']++; |
---|
| 3105 | $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>"; |
---|
[2] | 3106 | } |
---|
| 3107 | else |
---|
| 3108 | $return['_new']++; |
---|
[285] | 3109 | } |
---|
[2] | 3110 | fclose($handle); |
---|
[15] | 3111 | unlink($file); |
---|
[2] | 3112 | } |
---|
| 3113 | else |
---|
| 3114 | $return['error'] = true; |
---|
| 3115 | |
---|
| 3116 | echo serialize($return); |
---|
| 3117 | } |
---|
| 3118 | /* |
---|
| 3119 | function convert_tree($tree, $name, &$iconDir, $parent='0') |
---|
| 3120 | { |
---|
| 3121 | $new = null; |
---|
| 3122 | $code = null; |
---|
[285] | 3123 | |
---|
[2] | 3124 | if ($parent === '0') |
---|
| 3125 | { |
---|
| 3126 | |
---|
| 3127 | $code .= $name.".add(new dNode({id:'0', caption: '".lang('Catalogues')."'}),'none');\n"; |
---|
| 3128 | } |
---|
[285] | 3129 | |
---|
[2] | 3130 | foreach ($tree as $id => $value) |
---|
| 3131 | { |
---|
| 3132 | $title = $value['name']; |
---|
| 3133 | |
---|
| 3134 | switch ($value['type']) |
---|
[285] | 3135 | { |
---|
[2] | 3136 | case 'unknown': |
---|
[285] | 3137 | $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] | 3138 | break; |
---|
[285] | 3139 | |
---|
[2] | 3140 | case 'catalog_group': |
---|
[285] | 3141 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n"; |
---|
[2] | 3142 | $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id); |
---|
| 3143 | break; |
---|
| 3144 | |
---|
| 3145 | case 'mixed_catalog_group': |
---|
| 3146 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n"; |
---|
| 3147 | |
---|
| 3148 | $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id); |
---|
| 3149 | break; |
---|
[285] | 3150 | |
---|
[2] | 3151 | case 'catalog': |
---|
| 3152 | $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n"; |
---|
[285] | 3153 | |
---|
[2] | 3154 | } |
---|
| 3155 | } |
---|
[285] | 3156 | |
---|
[2] | 3157 | return $code; |
---|
| 3158 | } |
---|
| 3159 | */ |
---|
| 3160 | } |
---|
| 3161 | |
---|
| 3162 | ?> |
---|