Quick Search:

View

Revision:

Diff

Diff from 1843 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/oscommerce2/trunk/catalog/address_book_process.php

Annotated File View

hpdl
477
1 <?php
2 /*
hpdl
1739
3   $Id: address_book_process.php 1843 2008-12-12 13:32:10Z hpdl $
hpdl
477
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1843
8   Copyright (c) 2008 osCommerce
hpdl
477
9
10   Released under the GNU General Public License
11 */
12
13   require('includes/application_top.php');
14
15   if (!tep_session_is_registered('customer_id')) {
16     $navigation->set_snapshot();
17     tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
18   }
19
20 // needs to be included earlier to set the success message in the messageStack
21   require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADDRESS_BOOK_PROCESS);
22
hpdl
1843
23   if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'deleteconfirm') && isset($HTTP_GET_VARS['delete']) && is_numeric($HTTP_GET_VARS['delete']) && isset($HTTP_GET_VARS['formid']) && ($HTTP_GET_VARS['formid'] == md5($sessiontoken))) {
hpdl
477
24     tep_db_query("delete from " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$HTTP_GET_VARS['delete'] . "' and customers_id = '" . (int)$customer_id . "'");
25
26     $messageStack->add_session('addressbook', SUCCESS_ADDRESS_BOOK_ENTRY_DELETED, 'success');
27
28     tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
29   }
30
31 // error checking when updating or adding an entry
32   $process = false;
hpdl
1843
33   if (isset($HTTP_POST_VARS['action']) && (($HTTP_POST_VARS['action'] == 'process') || ($HTTP_POST_VARS['action'] == 'update')) && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken)) {
hpdl
477
34     $process = true;
35     $error = false;
36
37     if (ACCOUNT_GENDER == 'true') $gender = tep_db_prepare_input($HTTP_POST_VARS['gender']);
38     if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);
39     $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
40     $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);
41     $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']);
42     if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']);
43     $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
44     $city = tep_db_prepare_input($HTTP_POST_VARS['city']);
45     $country = tep_db_prepare_input($HTTP_POST_VARS['country']);
46     if (ACCOUNT_STATE == 'true') {
47       if (isset($HTTP_POST_VARS['zone_id'])) {
48         $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
49       } else {
50         $zone_id = false;
51       }
52       $state = tep_db_prepare_input($HTTP_POST_VARS['state']);
53     }
54
55     if (ACCOUNT_GENDER == 'true') {
56       if ( ($gender != 'm') && ($gender != 'f') ) {
57         $error = true;
58
59         $messageStack->add('addressbook', ENTRY_GENDER_ERROR);
60       }
61     }
62
63     if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
64       $error = true;
65
66       $messageStack->add('addressbook', ENTRY_FIRST_NAME_ERROR);
67     }
68
69     if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
70       $error = true;
71
72       $messageStack->add('addressbook', ENTRY_LAST_NAME_ERROR);
73     }
74
75     if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
76       $error = true;
77
78       $messageStack->add('addressbook', ENTRY_STREET_ADDRESS_ERROR);
79     }
80
81     if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
82       $error = true;
83
84       $messageStack->add('addressbook', ENTRY_POST_CODE_ERROR);
85     }
86
87     if (strlen($city) < ENTRY_CITY_MIN_LENGTH) {
88       $error = true;
89
90       $messageStack->add('addressbook', ENTRY_CITY_ERROR);
91     }
92
93     if (!is_numeric($country)) {
94       $error = true;
95
96       $messageStack->add('addressbook', ENTRY_COUNTRY_ERROR);
97     }
98
99     if (ACCOUNT_STATE == 'true') {
100       $zone_id = 0;
101       $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'");
102       $check = tep_db_fetch_array($check_query);
103       $entry_state_has_zones = ($check['total'] > 0);
104       if ($entry_state_has_zones == true) {
hpdl
1598
105         $zone_query = tep_db_query("select distinct zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name = '" . tep_db_input($state) . "' or zone_code = '" . tep_db_input($state) . "')");
hpdl
477
106         if (tep_db_num_rows($zone_query) == 1) {
107           $zone = tep_db_fetch_array($zone_query);
108           $zone_id = $zone['zone_id'];
109         } else {
110           $error = true;
111
112           $messageStack->add('addressbook', ENTRY_STATE_ERROR_SELECT);
113         }
114       } else {
115         if (strlen($state) < ENTRY_STATE_MIN_LENGTH) {
116           $error = true;
117
118           $messageStack->add('addressbook', ENTRY_STATE_ERROR);
119         }
120       }
121     }
122
123     if ($error == false) {
124       $sql_data_array = array('entry_firstname' => $firstname,
125                               'entry_lastname' => $lastname,
126                               'entry_street_address' => $street_address,
127                               'entry_postcode' => $postcode,
128                               'entry_city' => $city,
129                               'entry_country_id' => (int)$country);
130
131       if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
132       if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;
133       if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
134       if (ACCOUNT_STATE == 'true') {
135         if ($zone_id > 0) {
136           $sql_data_array['entry_zone_id'] = (int)$zone_id;
137           $sql_data_array['entry_state'] = '';
138         } else {
139           $sql_data_array['entry_zone_id'] = '0';
140           $sql_data_array['entry_state'] = $state;
141         }
142       }
143
144       if ($HTTP_POST_VARS['action'] == 'update') {
hpdl
1766
145         $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");
146         if (tep_db_num_rows($check_query) == 1) {
147           tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array, 'update', "address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "' and customers_id ='" . (int)$customer_id . "'");
hpdl
477
148
149 // reregister session variables
hpdl
1766
150           if ( (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) || ($HTTP_GET_VARS['edit'] == $customer_default_address_id) ) {
151             $customer_first_name = $firstname;
152             $customer_country_id = $country;
153             $customer_zone_id = (($zone_id > 0) ? (int)$zone_id : '0');
154             $customer_default_address_id = (int)$HTTP_GET_VARS['edit'];
hpdl
477
155
hpdl
1766
156             $sql_data_array = array('customers_firstname' => $firstname,
157                                     'customers_lastname' => $lastname,
158                                     'customers_default_address_id' => (int)$HTTP_GET_VARS['edit']);
hpdl
477
159
hpdl
1766
160             if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender;
hpdl
477
161
hpdl
1766
162             tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . (int)$customer_id . "'");
163           }
164
165           $messageStack->add_session('addressbook', SUCCESS_ADDRESS_BOOK_ENTRY_UPDATED, 'success');
hpdl
477
166         }
167       } else {
hpdl
1766
168         if (tep_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) {
169           $sql_data_array['customers_id'] = (int)$customer_id;
170           tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
hpdl
477
171
hpdl
1766
172           $new_address_book_id = tep_db_insert_id();
hpdl
477
173
174 // reregister session variables
hpdl
1766
175           if (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) {
176             $customer_first_name = $firstname;
177             $customer_country_id = $country;
178             $customer_zone_id = (($zone_id > 0) ? (int)$zone_id : '0');
179             if (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) $customer_default_address_id = $new_address_book_id;
hpdl
477
180
hpdl
1766
181             $sql_data_array = array('customers_firstname' => $firstname,
182                                     'customers_lastname' => $lastname);
hpdl
477
183
hpdl
1766
184             if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender;
185             if (isset($HTTP_POST_VARS['primary']) && ($HTTP_POST_VARS['primary'] == 'on')) $sql_data_array['customers_default_address_id'] = $new_address_book_id;
hpdl
477
186
hpdl
1766
187             tep_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . (int)$customer_id . "'");
188
189             $messageStack->add_session('addressbook', SUCCESS_ADDRESS_BOOK_ENTRY_UPDATED, 'success');
190           }
hpdl
477
191         }
192       }
193
194       tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
195     }
196   }
197
198   if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) {
199     $entry_query = tep_db_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 from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "'");
200
201     if (!tep_db_num_rows($entry_query)) {
202       $messageStack->add_session('addressbook', ERROR_NONEXISTING_ADDRESS_BOOK_ENTRY);
203
204       tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
205     }
206
207     $entry = tep_db_fetch_array($entry_query);
208   } elseif (isset($HTTP_GET_VARS['delete']) && is_numeric($HTTP_GET_VARS['delete'])) {
209     if ($HTTP_GET_VARS['delete'] == $customer_default_address_id) {
210       $messageStack->add_session('addressbook', WARNING_PRIMARY_ADDRESS_DELETION, 'warning');
211
212       tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
213     } else {
214       $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 . "'");
215       $check = tep_db_fetch_array($check_query);
216
217       if ($check['total'] < 1) {
218         $messageStack->add_session('addressbook', ERROR_NONEXISTING_ADDRESS_BOOK_ENTRY);
219
220         tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
221       }
222     }
223   } else {
224     $entry = array();
225   }
226
227   if (!isset($HTTP_GET_VARS['delete']) && !isset($HTTP_GET_VARS['edit'])) {
228     if (tep_count_customer_address_book_entries() >= MAX_ADDRESS_BOOK_ENTRIES) {
229       $messageStack->add_session('addressbook', ERROR_ADDRESS_BOOK_FULL);
230
231       tep_redirect(tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
232     }
233   }
234
235   $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
236   $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));
237
238   if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) {
239     $breadcrumb->add(NAVBAR_TITLE_MODIFY_ENTRY, tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'edit=' . $HTTP_GET_VARS['edit'], 'SSL'));
240   } elseif (isset($HTTP_GET_VARS['delete']) && is_numeric($HTTP_GET_VARS['delete'])) {
241     $breadcrumb->add(NAVBAR_TITLE_DELETE_ENTRY, tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $HTTP_GET_VARS['delete'], 'SSL'));
242   } else {
243     $breadcrumb->add(NAVBAR_TITLE_ADD_ENTRY, tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL'));
244   }
245 ?>
246 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
247 <html <?php echo HTML_PARAMS; ?>>
248 <head>
249 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
250 <title><?php echo TITLE; ?></title>
251 <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
252 <link rel="stylesheet" type="text/css" href="stylesheet.css">
253 <?php
254   if (!isset($HTTP_GET_VARS['delete'])) {
255     include('includes/form_check.js.php');
256   }
257 ?>
258 </head>
259 <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
260 <!-- header //-->
261 <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
262 <!-- header_eof //-->
263
264 <!-- body //-->
265 <table border="0" width="100%" cellspacing="3" cellpadding="3">
266   <tr>
267     <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
268 <!-- left_navigation //-->
269 <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
270 <!-- left_navigation_eof //-->
271     </table></td>
272 <!-- body_text //-->
hpdl
1843
273     <td width="100%" valign="top"><?php if (!isset($HTTP_GET_VARS['delete'])) echo tep_draw_form('addressbook', tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, (isset($HTTP_GET_VARS['edit']) ? 'edit=' . $HTTP_GET_VARS['edit'] : ''), 'SSL'), 'post', 'onSubmit="return check_form(addressbook);"', true); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">
hpdl
477
274       <tr>
275         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
276           <tr>
277             <td class="pageHeading"><?php if (isset($HTTP_GET_VARS['edit'])) { echo HEADING_TITLE_MODIFY_ENTRY; } elseif (isset($HTTP_GET_VARS['delete'])) { echo HEADING_TITLE_DELETE_ENTRY; } else { echo HEADING_TITLE_ADD_ENTRY; } ?></td>
278             <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_address_book.gif', (isset($HTTP_GET_VARS['edit']) ? HEADING_TITLE_MODIFY_ENTRY : HEADING_TITLE_ADD_ENTRY), HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
279           </tr>
280         </table></td>
281       </tr>
282       <tr>
283         <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
284       </tr>
285 <?php
286   if ($messageStack->size('addressbook') > 0) {
287 ?>
288       <tr>
289         <td><?php echo $messageStack->output('addressbook'); ?></td>
290       </tr>
291       <tr>
292         <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
293       </tr>
294 <?php
295   }
296
297   if (isset($HTTP_GET_VARS['delete'])) {
298 ?>
299       <tr>
300         <td class="main"><b><?php echo DELETE_ADDRESS_TITLE; ?></b></td>
301       </tr>
302       <tr>
303         <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
304           <tr class="infoBoxContents">
305             <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
306               <tr>
307                 <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
308                 <td class="main" width="50%" valign="top"><?php echo DELETE_ADDRESS_DESCRIPTION; ?></td>
309                 <td align="right" width="50%" valign="top"><table border="0" cellspacing="0" cellpadding="2">
310                   <tr>
311                     <td class="main" align="center" valign="top"><b><?php echo SELECTED_ADDRESS; ?></b><br><?php echo tep_image(DIR_WS_IMAGES . 'arrow_south_east.gif'); ?></td>
312                     <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
313                     <td class="main" valign="top"><?php echo tep_address_label($customer_id, $HTTP_GET_VARS['delete'], true, ' ', '<br>'); ?></td>
314                     <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
315                   </tr>
316                 </table></td>
317               </tr>
318             </table></td>
319           </tr>
320         </table></td>
321       </tr>
322       <tr>
323         <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
324       </tr>
325       <tr>
326         <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
327           <tr class="infoBoxContents">
328             <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
329               <tr>
330                 <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
331                 <td><?php echo '<a href="' . tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL') . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
hpdl
1843
332                 <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $HTTP_GET_VARS['delete'] . '&action=deleteconfirm&formid=' . md5($sessiontoken), 'SSL') . '">' . tep_image_button('button_delete.gif', IMAGE_BUTTON_DELETE) . '</a>'; ?></td>
hpdl
477
333                 <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
334               </tr>
335             </table></td>
336           </tr>
337         </table></td>
338       </tr>
339 <?php
340   } else {
341 ?>
342       <tr>
343         <td><?php include(DIR_WS_MODULES . 'address_book_details.php'); ?></td>
344       </tr>
345       <tr>
346         <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
347       </tr>
348 <?php
349     if (isset($HTTP_GET_VARS['edit']) && is_numeric($HTTP_GET_VARS['edit'])) {
350 ?>
351       <tr>
352         <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
353           <tr class="infoBoxContents">
354             <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
355               <tr>
356                 <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
357                 <td><?php echo '<a href="' . tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL') . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
358                 <td align="right"><?php echo tep_draw_hidden_field('action', 'update') . tep_draw_hidden_field('edit', $HTTP_GET_VARS['edit']) . tep_image_submit('button_update.gif', IMAGE_BUTTON_UPDATE); ?></td>
359                 <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
360               </tr>
361             </table></td>
362           </tr>
363         </table></td>
364       </tr>
365 <?php
366     } else {
367       if (sizeof($navigation->snapshot) > 0) {
368         $back_link = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
369       } else {
370         $back_link = tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL');
371       }
372 ?>
373       <tr>
374         <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
375           <tr class="infoBoxContents">
376             <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
377               <tr>
378                 <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
379                 <td><?php echo '<a href="' . $back_link . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
380                 <td align="right"><?php echo tep_draw_hidden_field('action', 'process') . tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
381                 <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
382               </tr>
383             </table></td>
384           </tr>
385         </table></td>
386       </tr>
387
388 <?php
389     }
390   }
391 ?>
392     </table><?php if (!isset($HTTP_GET_VARS['delete'])) echo '</form>'; ?></td>
393 <!-- body_text_eof //-->
394     <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
395 <!-- right_navigation //-->
396 <?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
397 <!-- right_navigation_eof //-->
398     </table></td>
399   </tr>
400 </table>
401 <!-- body_eof //-->
402
403 <!-- footer //-->
404 <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
405 <!-- footer_eof //-->
406 <br>
407 </body>
408 </html>
409 <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>