[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: address_book_process.php 3 2006-05-27 04:59:07Z user $ 4 5 osCMax Power E-Commerce 6 http://oscdox.com 7 8 Copyright 2008 osCMax 9 10 Released under the GNU General Public License 11 */ 12 13 // Most of this file is changed or moved to BTS - Basic Template System - format. 14 // For adding in contribution or modification - parts of this file has been moved to: catalog\templates\fallback\contents\<filename>.tpl.php as a default (sub 'fallback' with your current template to see if there is a template specife change). 15 // catalog\templates\fallback\contents\<filename>.tpl.php as a default (sub 'fallback' with your current template to see if there is a template specife change). 16 // (Sub 'fallback' with your current template to see if there is a template specific file.) 17 18 require ('includes/application_top.php'); 19 20 if (!tep_session_is_registered('customer_id')) { 21 $navigation->set_snapshot(); 22 tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); 23 } 24 25 // needs to be included earlier to set the success message in the messageStack 26 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADDRESS_BOOK_PROCESS); 27 28 if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'deleteconfirm') && isset($HTTP_GET_VARS['delete']) && is_numeric($HTTP_GET_VARS['delete'])) { 29 tep_db_query("delete from " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$HTTP_GET_VARS['delete'] . "' and customers_id = '" . (int)$customer_id . "'"); 30 31 $messageStack->add_session('addressbook', SUCCESS_ADDRESS_BOOK_ENTRY_DELETED, 'success'); 32 33 tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 34 } 35 36 // error checking when updating or adding an entry 37 $process = false; 38 // +Country-State Selector 39 $refresh = false; 40 if (isset($HTTP_POST_VARS['action']) && (($HTTP_POST_VARS['action'] == 'process') || ($HTTP_POST_VARS['action'] == 'update') || 41 ($HTTP_POST_VARS['action'] == 'refresh'))) { 42 if ($HTTP_POST_VARS['action'] != 'refresh') { $process = true; } else { $refresh = true; } 43 // -Country-State Selector 44 $error = false; 45 46 if (ACCOUNT_GENDER == 'true') $gender = tep_db_prepare_input($HTTP_POST_VARS['gender']); 47 if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']); 48 // BOF Separate Pricing Per Customer 49 if (ACCOUNT_COMPANY == 'true' && isset($HTTP_POST_VARS['company_tax_id'])) { 50 $company_tax_id = tep_db_prepare_input($HTTP_POST_VARS['company_tax_id']); 51 } 52 // EOF Separate Pricing Per Customer 53 $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']); 54 $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']); 55 $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']); 56 if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']); 57 $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']); 58 $city = tep_db_prepare_input($HTTP_POST_VARS['city']); 59 $country = tep_db_prepare_input($HTTP_POST_VARS['country']); 60 if (ACCOUNT_STATE == 'true') { 61 if (isset($HTTP_POST_VARS['zone_id'])) { 62 $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']); 63 } else { 64 $zone_id = false; 65 } 66 $state = tep_db_prepare_input($HTTP_POST_VARS['state']); 67 } 68 // BOF: MOD - Country-State Selector 69 if ($refresh) {$state = '';} 70 if ($process) { 71 // EOF: MOD - Country-State Selector 72 73 if (ACCOUNT_GENDER == 'true') { 74 if ( ($gender != 'm') && ($gender != 'f') ) { 75 $error = true; 76 77 $messageStack->add('addressbook', ENTRY_GENDER_ERROR); 78 } 79 } 80 81 if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) { 82 $error = true; 83 84 $messageStack->add('addressbook', ENTRY_FIRST_NAME_ERROR); 85 } 86 87 if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) { 88 $error = true; 89 90 $messageStack->add('addressbook', ENTRY_LAST_NAME_ERROR); 91 } 92 93 if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) { 94 $error = true; 95 96 $messageStack->add('addressbook', ENTRY_STREET_ADDRESS_ERROR); 97 } 98 99 if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) { 100 $error = true; 101 102 $messageStack->add('addressbook', ENTRY_POST_CODE_ERROR); 103 } 104 105 if (strlen($city) < ENTRY_CITY_MIN_LENGTH) { 106 $error = true; 107 108 $messageStack->add('addressbook', ENTRY_CITY_ERROR); 109 } 110 111 if (!is_numeric($country)) { 112 $error = true; 113 114 $messageStack->add('addressbook', ENTRY_COUNTRY_ERROR); 115 } 116 117 if (ACCOUNT_STATE == 'true') { 118 // BOF: MOD - Country-State Selector 119 if ($zone_id == 0) { 120 // EOF: MOD - Country-State Selector 121 if (strlen($state) < ENTRY_STATE_MIN_LENGTH) { 122 $error = true; 123 124 $messageStack->add('addressbook', ENTRY_STATE_ERROR); 125 } 126 } 127 } 128 // BOF: MOD - Country-State Selector 129 } 130 if (!$refresh) { 131 // EOF: MOD - Country-State Selector 132 if ($error == false) { 133 $sql_data_array = array('entry_firstname' => $firstname, 134 'entry_lastname' => $lastname, 135 'entry_street_address' => $street_address, 136 'entry_postcode' => $postcode, 137 'entry_city' => $city, 138 'entry_country_id' => (int)$country); 139 140 if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender; 141 if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company; 142 // BOF: MOD - Separate Pricing Per Customer 143 if (ACCOUNT_COMPANY == 'true' && tep_not_null($company_tax_id)) { 144 $sql_data_array['entry_company_tax_id'] = $company_tax_id; 145 } 146 // EOF: MOD - Separate Pricing Per Customer 147 if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb; 148 if (ACCOUNT_STATE == 'true') { 149 if ($zone_id > 0) { 150 $sql_data_array['entry_zone_id'] = (int)$zone_id; 151 $sql_data_array['entry_state'] = ''; 152 } else { 153 $sql_data_array['entry_zone_id'] = '0'; 154 $sql_data_array['entry_state'] = $state; 155 } 156 } 157 158 if ($HTTP_POST_VARS['action'] == 'update') { 159 $check_query = tep_db_query("select address_book_id from " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "' and customers_id = '" . (int)$customer_id . "' limit 1"); 160 if (tep_db_num_rows($check_query) == 1) { 161 tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array, 'update', "address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "' and customers_id ='" . (int)$customer_id . "'"); 162 // BOF: MOD - Separate Pricing Per Customer: alert shop owner of tax id number added to an account 163 if (ACCOUNT_COMPANY == 'true' && tep_not_null($company_tax_id)) { 164 $sql_data_array2['customers_group_ra'] = '1'; 165 tep_db_perform(TABLE_CUSTOMERS, $sql_data_array2, 'update', "customers_id ='" . (int)$customer_id . "'"); 166 167 // if you would *not* like to have an email when a tax id number has been entered in 168 // the appropriate field, comment out this section. The alert in admin is raised anyway 169 170 $alert_email_text = "Please note that " . $firstname . " " . $lastname . " of the company: " . $company . " has added a tax id number to his account information."; 171 tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, 'Tax id number added', $alert_email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); 172 } 173 // EOF: MOD - Separate Pricing Per Customer: alert shop owner of account created by a company 174 175 // reregister session variables 176 if ( (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) || ($HTTP_GET_VARS['edit'] == $customer_default_address_id) ) { 177 $customer_first_name = $firstname; 178 $customer_country_id = $country_id; 179 $customer_zone_id = (($zone_id > 0) ? (int)$zone_id : '0'); 180 $customer_default_address_id = (int)$HTTP_GET_VARS['edit']; 181 182 $sql_data_array = array('customers_firstname' => $firstname, 183 'customers_lastname' => $lastname, 184 'customers_default_address_id' => (int)$HTTP_GET_VARS['edit']); 185 186 if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender; 187 188 tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . (int)$customer_id . "'"); 189 } 190 191 $messageStack->add_session('addressbook', SUCCESS_ADDRESS_BOOK_ENTRY_UPDATED, 'success'); 192 } 193 } else { 194 if (tep_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) { 195 $sql_data_array['customers_id'] = (int)$customer_id; 196 tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array); 197 198 $new_address_book_id = tep_db_insert_id(); 199 200 // reregister session variables 201 if (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) { 202 $customer_first_name = $firstname; 203 $customer_country_id = $country_id; 204 $customer_zone_id = (($zone_id > 0) ? (int)$zone_id : '0'); 205 if (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) $customer_default_address_id = $new_address_book_id; 206 207 $sql_data_array = array('customers_firstname' => $firstname, 208 'customers_lastname' => $lastname); 209 210 if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender; 211 if (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) $sql_data_array['customers_default_address_id'] = $new_address_book_id; 212 213 tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . (int)$customer_id . "'"); 214 $messageStack->add_session('addressbook', SUCCESS_ADDRESS_BOOK_ENTRY_UPDATED, 'success'); 215 } 216 } 217 } 218 219 tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 220 } 221 } 222 // BOF: MOD - Country-State Selector 223 } 224 225 if ($refresh) { 226 // Recreate $entry from post values collected above 227 $entry = array( 228 'entry_firstname' => $firstname, 229 'entry_lastname' => $lastname, 230 'entry_street_address' => $street_address, 231 'entry_postcode' => $postcode, 232 'entry_city' => $city, 233 'entry_state' => "", 234 'entry_zone_id' => (int)0, 235 'entry_country_id' => (int)$country); 236 if (ACCOUNT_GENDER == 'true') $entry['entry_gender'] = $gender; 237 if (ACCOUNT_COMPANY == 'true') $entry['entry_company'] = $company; 238 if (ACCOUNT_SUBURB == 'true') $entry['entry_suburb'] = $suburb; 239 } 240 else 241 // EOF: MOD - Country-State Selector 242 if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) { 243 // BOF: MOD - Separate Pricing Per Customer 244 $entry_query = tep_db_query("select entry_gender, entry_company, entry_company_tax_id, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "'"); 245 // EOF: MOD - Separate Pricing Per Customer 246 if (!tep_db_num_rows($entry_query)) { 247 $messageStack->add_session('addressbook', ERROR_NONEXISTING_ADDRESS_BOOK_ENTRY); 248 249 tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 250 } 251 252 $entry = tep_db_fetch_array($entry_query); 253 } elseif (isset($HTTP_GET_VARS['delete']) && is_numeric($HTTP_GET_VARS['delete'])) { 254 if ($HTTP_GET_VARS['delete'] == $customer_default_address_id) { 255 $messageStack->add_session('addressbook', WARNING_PRIMARY_ADDRESS_DELETION, 'warning'); 256 257 tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 258 } else { 259 $check_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$HTTP_GET_VARS['delete'] . "' and customers_id = '" . (int)$customer_id . "'"); 260 $check = tep_db_fetch_array($check_query); 261 262 if ($check['total'] < 1) { 263 $messageStack->add_session('addressbook', ERROR_NONEXISTING_ADDRESS_BOOK_ENTRY); 264 265 tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 266 } 267 } 268 } else { 269 $entry = array(); 270 // BOF: MOD - Country-State Selector 271 if (!isset($country)) $country = DEFAULT_COUNTRY; 272 $entry['entry_country_id'] = $country; 273 // EOF: MOD - Country-State Selector 274 } 275 276 if (!isset($HTTP_GET_VARS['delete']) && !isset($HTTP_GET_VARS['edit'])) { 277 if (tep_count_customer_address_book_entries() >= MAX_ADDRESS_BOOK_ENTRIES) { 278 $messageStack->add_session('addressbook', ERROR_ADDRESS_BOOK_FULL); 279 280 tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 281 } 282 } 283 284 $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL')); 285 $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL')); 286 287 if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) { 288 $breadcrumb->add(NAVBAR_TITLE_MODIFY_ENTRY, tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit=' . $HTTP_GET_VARS['edit'], 'SSL')); 289 } elseif (isset($HTTP_GET_VARS['delete']) && is_numeric($HTTP_GET_VARS['delete'])) { 290 $breadcrumb->add(NAVBAR_TITLE_DELETE_ENTRY, tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $HTTP_GET_VARS['delete'], 'SSL')); 291 } else { 292 $breadcrumb->add(NAVBAR_TITLE_ADD_ENTRY, tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL')); 293 } 294 295 $content = CONTENT_ADDRESS_BOOK_PROCESS; 296 $javascript = $content . '.php'; 297 298 include (bts_select('main', $content_template)); // BTSv1.5 299 300 require (DIR_WS_INCLUDES . 'application_bottom.php'); 301 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |