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