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