ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/functions/functions_customers.php
Go to the documentation of this file.
00001 <?php
00012 // NOTE: these are from catalog functions_customers for now
00013 
00015 // Returns the address_format_id for the given country
00016 // TABLES: countries;
00017   function zen_get_address_format_id($country_id) {
00018     global $db;
00019     $address_format_query = "select address_format_id as format_id
00020                              from " . TABLE_COUNTRIES . "
00021                              where countries_id = '" . (int)$country_id . "'";
00022 
00023     $address_format = $db->Execute($address_format_query);
00024 
00025     if ($address_format->RecordCount() > 0) {
00026       return $address_format->fields['format_id'];
00027     } else {
00028       return '1';
00029     }
00030   }
00031 
00033 // Return a formatted address
00034 // TABLES: address_format
00035   function zen_address_format($address_format_id, $address, $html, $boln, $eoln) {
00036     global $db;
00037     $address_format_query = "select address_format as format
00038                              from " . TABLE_ADDRESS_FORMAT . "
00039                              where address_format_id = '" . (int)$address_format_id . "'";
00040 
00041     $address_format = $db->Execute($address_format_query);
00042     $company = zen_output_string_protected($address['company']);
00043     if (isset($address['firstname']) && zen_not_null($address['firstname'])) {
00044       $firstname = zen_output_string_protected($address['firstname']);
00045       $lastname = zen_output_string_protected($address['lastname']);
00046     } elseif (isset($address['name']) && zen_not_null($address['name'])) {
00047       $firstname = zen_output_string_protected($address['name']);
00048       $lastname = '';
00049     } else {
00050       $firstname = '';
00051       $lastname = '';
00052     }
00053     $street = zen_output_string_protected($address['street_address']);
00054     $suburb = zen_output_string_protected($address['suburb']);
00055     $city = zen_output_string_protected($address['city']);
00056     $state = zen_output_string_protected($address['state']);
00057     if (isset($address['country_id']) && zen_not_null($address['country_id'])) {
00058       $country = zen_get_country_name($address['country_id']);
00059 
00060       if (isset($address['zone_id']) && zen_not_null($address['zone_id'])) {
00061         $state = zen_get_zone_code($address['country_id'], $address['zone_id'], $state);
00062       }
00063     } elseif (isset($address['country']) && zen_not_null($address['country'])) {
00064       if (is_array($address['country'])) {
00065         $country = zen_output_string_protected($address['country']['countries_name']);
00066       } else {
00067       $country = zen_output_string_protected($address['country']);
00068       }
00069     } else {
00070       $country = '';
00071     }
00072     $postcode = zen_output_string_protected($address['postcode']);
00073     $zip = $postcode;
00074 
00075     if ($html) {
00076 // HTML Mode
00077       $HR = '<hr />';
00078       $hr = '<hr />';
00079       if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults
00080         $CR = '<br />';
00081         $cr = '<br />';
00082         $eoln = $cr;
00083       } else { // Use values supplied
00084         $CR = $eoln . $boln;
00085         $cr = $CR;
00086       }
00087     } else {
00088 // Text Mode
00089       $CR = $eoln;
00090       $cr = $CR;
00091       $HR = '----------------------------------------';
00092       $hr = '----------------------------------------';
00093     }
00094 
00095     $statecomma = '';
00096     $streets = $street;
00097     if ($suburb != '') $streets = $street . $cr . $suburb;
00098     if ($country == '') {
00099       if (is_array($address['country'])) {
00100         $country = zen_output_string_protected($address['country']['countries_name']);
00101       } else {
00102       $country = zen_output_string_protected($address['country']);
00103       }
00104     }
00105     if ($state != '') $statecomma = $state . ', ';
00106 
00107     $fmt = $address_format->fields['format'];
00108     eval("\$address_out = \"$fmt\";");
00109 
00110     if ( (ACCOUNT_COMPANY == 'true') && (zen_not_null($company)) ) {
00111       $address_out = $company . $cr . $address_out;
00112     }
00113 
00114     return $address_out;
00115   }
00116 
00118 // Return a formatted address
00119 // TABLES: customers, address_book
00120   function zen_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") {
00121     global $db;
00122     $address_query = "select entry_firstname as firstname, entry_lastname as lastname,
00123                              entry_company as company, entry_street_address as street_address,
00124                              entry_suburb as suburb, entry_city as city, entry_postcode as postcode,
00125                              entry_state as state, entry_zone_id as zone_id,
00126                              entry_country_id as country_id
00127                       from " . TABLE_ADDRESS_BOOK . "
00128                       where customers_id = '" . (int)$customers_id . "'
00129                       and address_book_id = '" . (int)$address_id . "'";
00130 
00131     $address = $db->Execute($address_query);
00132 
00133     $format_id = zen_get_address_format_id($address->fields['country_id']);
00134     return zen_address_format($format_id, $address->fields, $html, $boln, $eoln);
00135   }
00136 
00137   // look up customers default or primary address
00138   function zen_get_customers_address_primary($customer_id) {
00139     global $db;
00140 
00141     $lookup_customers_primary_address_query = "SELECT customers_default_address_id
00142                                               from " . TABLE_CUSTOMERS . "
00143                                               WHERE customers_id = '" . (int)$customer_id . "'";
00144 
00145     $lookup_customers_primary_address = $db->Execute($lookup_customers_primary_address_query);
00146 
00147     return $lookup_customers_primary_address->fields['customers_default_address_id'];
00148   }
00149 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations