Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1497
 
1669
 
1669
 
address_book.php
_> 55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
  77 
<> 8 -  Copyright (c) 2005 osCommerce
   8+  Copyright (c) 2007 osCommerce
99 
  1010   This program is free software; you can redistribute it and/or modify
  1111   it under the terms of the GNU General Public License v2 (1991)
  1212   as published by the Free Software Foundation.
  1313 */
  1414 
<>  15+/**
   16+ * The osC_AddressBook class handles customer address book related functions
   17+ */
   18+
1519   class osC_AddressBook {
  1620 
<> 17 -    function &getListing() {
   21+/**
   22+ * Returns the address book entries for the current customer
   23+ *
   24+ * @access public
   25+ * @return array
   26+ */
   27+
   28+    public static function &getListing() {
1829       global $osC_Database, $osC_Customer;
  1930 
  2031       $Qaddresses = $osC_Database->query('select ab.address_book_id, ab.entry_firstname as firstname, ab.entry_lastname as lastname, ab.entry_company as company, ab.entry_street_address as street_address, ab.entry_suburb as suburb, ab.entry_city as city, ab.entry_postcode as postcode, ab.entry_state as state, ab.entry_zone_id as zone_id, ab.entry_country_id as country_id, z.zone_code as zone_code, c.countries_name as country_title from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id), :table_countries c where ab.customers_id = :customers_id and ab.entry_country_id = c.countries_id order by ab.entry_firstname, ab.entry_lastname');
     
 !
2738       return $Qaddresses;
  2839     }
  2940 
<> 30 -    function &getEntry($id) {
   41+/**
   42+ * Returns a specific address book entry for the current customer
   43+ *
   44+ * @param int $id The ID of the address book entry to return
   45+ * @access public
   46+ * @return array
   47+ */
   48+
   49+    public static function &getEntry($id) {
3150       global $osC_Database, $osC_Customer;
  3251 
  3352       $Qentry = $osC_Database->query('select entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id, entry_telephone, entry_fax from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
     
 !
3958       return $Qentry;
  4059     }
  4160 
<> 42 -    function checkEntry($id) {
   61+/**
   62+ * Verify the address book entry belongs to the current customer
   63+ *
   64+ * @param int $id The ID of the address book entry to verify
   65+ * @access public
   66+ * @return boolean
   67+ */
   68+
   69+    public static function checkEntry($id) {
4370       global $osC_Database, $osC_Customer;
  4471 
  4572       $Qentry = $osC_Database->query('select address_book_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
     
 !
4875       $Qentry->bindInt(':customers_id', $osC_Customer->getID());
  4976       $Qentry->execute();
  5077 
<> 51 -      if ($Qentry->numberOfRows() === 1) {
  52 -        return true;
  53 -      }
  54 -
  55 -      return false;
   78+      return ( $Qentry->numberOfRows() === 1 );
5679     }
  5780 
<> 58 -    function numberOfEntries() {
   81+/**
   82+ * Return the number of address book entries the current customer has
   83+ *
   84+ * @access public
   85+ * @return integer
   86+ */
   87+
   88+    public static function numberOfEntries() {
5989       global $osC_Database, $osC_Customer;
  6090 
  6191       static $total_entries;
  6292 
<> 63 -      if ( !is_numeric($total_entries) ) {
   93+      if ( !isset($total_entries) ) {
6494         $Qaddresses = $osC_Database->query('select count(*) as total from :table_address_book where customers_id = :customers_id');
  6595         $Qaddresses->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
  6696         $Qaddresses->bindInt(':customers_id', $osC_Customer->getID());
     
 !
72102       return $total_entries;
  73103     }
  74104 
<> 75 -    function saveEntry($data, $id = '') {
   105+/**
   106+ * Save an address book entry
   107+ *
   108+ * @param array $data An array containing the address book information
   109+ * @param int $id The ID of the address book entry to update (if this is not provided, a new address book entry is created)
   110+ * @access public
   111+ * @return boolean
   112+ */
   113+
   114+    public static function saveEntry($data, $id = '') {
76115       global $osC_Database, $osC_Customer;
  77116 
  78117       $updated_record = false;
  79118 
<> 80 -      if (is_numeric($id)) {
   119+      if ( is_numeric($id) ) {
81120         $Qab = $osC_Database->query('update :table_address_book set customers_id = :customers_id, entry_gender = :entry_gender, entry_company = :entry_company, entry_firstname = :entry_firstname, entry_lastname = :entry_lastname, entry_street_address = :entry_street_address, entry_suburb = :entry_suburb, entry_postcode = :entry_postcode, entry_city = :entry_city, entry_state = :entry_state, entry_country_id = :entry_country_id, entry_zone_id = :entry_zone_id, entry_telephone = :entry_telephone, entry_fax = :entry_fax where address_book_id = :address_book_id and customers_id = :customers_id');
  82121         $Qab->bindInt(':address_book_id', $id);
  83122         $Qab->bindInt(':customers_id', $osC_Customer->getID());
  84123       } else {
  85124         $Qab = $osC_Database->query('insert into :table_address_book (customers_id, entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_country_id, entry_zone_id, entry_telephone, entry_fax) values (:customers_id, :entry_gender, :entry_company, :entry_firstname, :entry_lastname, :entry_street_address, :entry_suburb, :entry_postcode, :entry_city, :entry_state, :entry_country_id, :entry_zone_id, :entry_telephone, :entry_fax)');
  86125       }
<>  126+
87127       $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
  88128       $Qab->bindInt(':customers_id', $osC_Customer->getID());
  89129       $Qab->bindValue(':entry_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
     
 !
101141       $Qab->bindValue(':entry_fax', (ACCOUNT_FAX > -1) ? $data['fax'] : '');
  102142       $Qab->execute();
  103143 
<> 104 -      if ($Qab->affectedRows() === 1) {
   144+      if ( $Qab->affectedRows() === 1 ) {
105145         $updated_record = true;
  106146       }
  107147 
<> 108 -      if (isset($data['primary']) && ($data['primary'] === true)) {
  109 -        if (is_numeric($id) === false) {
   148+      if ( isset($data['primary']) && ($data['primary'] === true) ) {
   149+        if ( !is_numeric($id) ) {
110150           $id = $osC_Database->nextID();
  111151         }
  112152 
<> 113 -        if (osC_AddressBook::setPrimaryAddress($id)) {
   153+        if ( osC_AddressBook::setPrimaryAddress($id) ) {
114154           $osC_Customer->setCountryID($data['country']);
  115155           $osC_Customer->setZoneID(($data['zone_id'] > 0) ? (int)$data['zone_id'] : '0');
  116156           $osC_Customer->setDefaultAddressID($id);
  117157 
<> 118 -          if ($updated_record === false) {
   158+          if ( $updated_record === false ) {
119159             $updated_record = true;
  120160           }
  121161         }
  122162       }
  123163 
<> 124 -      if ($updated_record === true) {
   164+      if ( $updated_record === true ) {
125165         return true;
  126166       }
  127167 
  128168       return false;
  129169     }
  130170 
<> 131 -    function setPrimaryAddress($id) {
   171+/**
   172+ * Set the address book entry as the primary address for the current customer
   173+ *
   174+ * @param int $id The ID of the address book entry
   175+ * @access public
   176+ * @return boolean
   177+ */
   178+
   179+    public static function setPrimaryAddress($id) {
132180       global $osC_Database, $osC_Customer;
  133181 
<> 134 -      if (is_numeric($id) && ($id > 0)) {
   182+      if ( is_numeric($id) && ($id > 0) ) {
135183         $Qupdate = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id');
  136184         $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
  137185         $Qupdate->bindInt(':customers_default_address_id', $id);
  138186         $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
  139187         $Qupdate->execute();
  140188 
<> 141 -        if ($Qupdate->affectedRows() === 1) {
  142 -          return true;
  143 -        }
   189+        return ( $Qupdate->affectedRows() === 1 );
144190       }
  145191 
  146192       return false;
  147193     }
  148194 
<> 149 -    function deleteEntry($id) {
   195+/**
   196+ * Delete an address book entry
   197+ *
   198+ * @param int $id The ID of the address book entry to delete
   199+ * @access public
   200+ * @return boolean
   201+ */
   202+
   203+    public static function deleteEntry($id) {
150204       global $osC_Database, $osC_Customer;
  151205 
  152206       $Qdelete = $osC_Database->query('delete from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
     
 !
155209       $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
  156210       $Qdelete->execute();
  157211 
<> 158 -      if ($Qdelete->affectedRows() === 1) {
  159 -        return true;
  160 -      }
  161 -
  162 -      return false;
   212+      return ( $Qdelete->affectedRows() === 1 );
<_ 163213     }
  164214   }
  165215 ?>