Index: trunk/extensions/CongressLookup/CongressLookup.db.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | table or to have NULL for the rep id. */ |
23 | 23 | if ( ( !$row ) || ( !$row->clz5_rep_id ) ) { |
24 | 24 | /* if we got the extra 4 digits, use them */ |
25 | | - $zip9 = intval( $zip ); |
| 25 | + $zip9 = intval( self::trimZip( $zip, 9 ) ); // remove the dash and pad if needed |
26 | 26 | if ( $zip9 >= 10000 ) { |
27 | 27 | $row = $dbr->selectRow( 'cl_zip9', 'clz9_rep_id', array( 'clz9_zip' => $zip9 ) ); |
28 | 28 | if ( $row ) { |
— | — | @@ -131,14 +131,22 @@ |
132 | 132 | */ |
133 | 133 | public static function trimZip( $zip, $length ) { |
134 | 134 | $zip = trim( $zip ); |
135 | | - if ( strlen( $zip ) < 5 ) { |
136 | | - $zip = sprintf( "%05d", $zip ); |
| 135 | + if ( strpos( $zip, '-' ) === False ) { |
| 136 | + if ( strlen( $zip ) < 5 ) { |
| 137 | + $zip = sprintf( "%05d", $zip ); |
| 138 | + } |
| 139 | + elseif ( strlen( $zip ) > 5 ) { |
| 140 | + $zip = sprintf( "%09d", $zip ); |
| 141 | + } |
137 | 142 | } |
138 | | - elseif ( strlen( $zip ) > 5 ) { |
139 | | - $zip = sprintf( "%09d", $zip ); |
| 143 | + else { |
| 144 | + $zipPieces = explode( '-', $zip, 2 ); |
| 145 | + if (! $zipPieces[1]) { |
| 146 | + $zipPieces[1] = 0; |
| 147 | + } |
| 148 | + $zip = sprintf( "%05d%04d", $zipPieces[0], $zipPieces[1] ); |
140 | 149 | } |
141 | | - $zipPieces = explode( '-', $zip, 2 ); |
142 | | - $zip = substr( $zipPieces[0], 0, $length ); |
| 150 | + $zip = substr( $zip, 0, $length ); |
143 | 151 | return $zip; |
144 | 152 | } |
145 | 153 | } |