PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/modules/pages/account_edit/header_php.php

https://github.com/yama/zencart13x-ja
PHP | 186 lines | 137 code | 34 blank | 15 comment | 65 complexity | dfa38f739647b80e4d95856793ac330c MD5 | raw file
  1. <?php
  2. /**
  3. * Header code file for the customer's Account-Edit page
  4. *
  5. * @package page
  6. * @copyright Copyright 2003-2006 Zen Cart Development Team
  7. * @copyright Portions Copyright 2003 osCommerce
  8. * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9. * @version $Id: header_php.php 4825 2006-10-23 22:25:11Z drbyte $
  10. */
  11. // This should be first line of the script:
  12. $zco_notifier->notify('NOTIFY_HEADER_START_ACCOUNT_EDIT');
  13. if (!$_SESSION['customer_id']) {
  14. $_SESSION['navigation']->set_snapshot();
  15. zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  16. }
  17. require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
  18. if (isset($_POST['action']) && ($_POST['action'] == 'process')) {
  19. if (ACCOUNT_GENDER == 'true') $gender = zen_db_prepare_input($_POST['gender']);
  20. $firstname = zen_db_prepare_input($_POST['firstname']);
  21. $lastname = zen_db_prepare_input($_POST['lastname']);
  22. if (ACCOUNT_DOB == 'true') $dob = (empty($_POST['dob']) ? zen_db_prepare_input('0001-01-01 00:00:00') : zen_db_prepare_input($_POST['dob']));
  23. $email_address = zen_db_prepare_input($_POST['email_address']);
  24. $email_format = zen_db_prepare_input($_POST['email_format']);
  25. if (CUSTOMERS_REFERRAL_STATUS == '2' and $_POST['customers_referral'] != '') $customers_referral = zen_db_prepare_input($_POST['customers_referral']);
  26. $error = false;
  27. if (ACCOUNT_GENDER == 'true') {
  28. if ( ($gender != 'm') && ($gender != 'f') ) {
  29. $error = true;
  30. $messageStack->add('account_edit', ENTRY_GENDER_ERROR);
  31. }
  32. }
  33. if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
  34. $error = true;
  35. $messageStack->add('account_edit', ENTRY_FIRST_NAME_ERROR);
  36. }
  37. if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
  38. $error = true;
  39. $messageStack->add('account_edit', ENTRY_LAST_NAME_ERROR);
  40. }
  41. if (ACCOUNT_DOB == 'true') {
  42. if (ENTRY_DOB_MIN_LENGTH > 0 or !empty($_POST['dob'])) {
  43. if (substr_count($dob,'/') > 2 || checkdate((int)substr(zen_date_raw($dob), 4, 2), (int)substr(zen_date_raw($dob), 6, 2), (int)substr(zen_date_raw($dob), 0, 4)) == false) {
  44. $error = true;
  45. $messageStack->add('account_edit', ENTRY_DATE_OF_BIRTH_ERROR);
  46. }
  47. }
  48. }
  49. if (strlen($email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
  50. $error = true;
  51. $messageStack->add('account_edit', ENTRY_EMAIL_ADDRESS_ERROR);
  52. }
  53. if (!zen_validate_email($email_address)) {
  54. $error = true;
  55. $messageStack->add('account_edit', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
  56. }
  57. $check_email_query = "SELECT count(*) AS total
  58. FROM " . TABLE_CUSTOMERS . "
  59. WHERE customers_email_address = :emailAddress
  60. AND customers_id != :customersID";
  61. $check_email_query = $db->bindVars($check_email_query, ':emailAddress', $email_address, 'string');
  62. $check_email_query = $db->bindVars($check_email_query, ':customersID', $_SESSION['customer_id'], 'integer');
  63. $check_email = $db->Execute($check_email_query);
  64. if ($check_email->fields['total'] > 0) {
  65. $error = true;
  66. $messageStack->add('account_edit', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
  67. // check phpBB for duplicate email address
  68. if ($phpBB->phpbb_check_for_duplicate_email(zen_db_input($email_address)) == 'already_exists' ) {
  69. $error = true;
  70. $messageStack->add('account_edit', 'phpBB-'.ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
  71. }
  72. }
  73. if ($error == false) {
  74. //update phpBB with new email address
  75. $old_addr_check=$db->Execute("select customers_email_address from ".TABLE_CUSTOMERS." where customers_id='".(int)$_SESSION['customer_id']."'");
  76. $phpBB->phpbb_change_email(zen_db_input($old_addr_check->fields['customers_email_address']),zen_db_input($email_address));
  77. $sql_data_array = array(array('fieldName'=>'customers_firstname', 'value'=>$firstname, 'type'=>'string'),
  78. array('fieldName'=>'customers_lastname', 'value'=>$lastname, 'type'=>'string'),
  79. array('fieldName'=>'customers_email_address', 'value'=>$email_address, 'type'=>'string'),
  80. array('fieldName'=>'customers_email_format', 'value'=>$email_format, 'type'=>'string')
  81. );
  82. if ((CUSTOMERS_REFERRAL_STATUS == '2' and $customers_referral != '')) {
  83. $sql_data_array[] = array('fieldName'=>'customers_referral', 'value'=>$customers_referral, 'type'=>'string');
  84. }
  85. if (ACCOUNT_GENDER == 'true') {
  86. $sql_data_array[] = array('fieldName'=>'customers_gender', 'value'=>$gender, 'type'=>'string');
  87. }
  88. if (ACCOUNT_DOB == 'true') {
  89. if ($dob == '0001-01-01 00:00:00' or $_POST['dob'] == '') {
  90. $sql_data_array[] = array('fieldName'=>'customers_dob', 'value'=>'0001-01-01 00:00:00', 'type'=>'date');
  91. } else {
  92. $sql_data_array[] = array('fieldName'=>'customers_dob', 'value'=>zen_date_raw($_POST['dob']), 'type'=>'date');
  93. }
  94. }
  95. $where_clause = "customers_id = :customersID";
  96. $where_clause = $db->bindVars($where_clause, ':customersID', $_SESSION['customer_id'], 'integer');
  97. $db->perform(TABLE_CUSTOMERS, $sql_data_array, 'update', $where_clause);
  98. $sql = "UPDATE " . TABLE_CUSTOMERS_INFO . "
  99. SET customers_info_date_account_last_modified = now()
  100. WHERE customers_info_id = :customersID";
  101. $sql = $db->bindVars($sql, ':customersID', $_SESSION['customer_id'], 'integer');
  102. $db->Execute($sql);
  103. $where_clause = "customers_id = :customersID AND address_book_id = :customerDefaultAddressID";
  104. $where_clause = $db->bindVars($where_clause, ':customersID', $_SESSION['customer_id'], 'integer');
  105. $where_clause = $db->bindVars($where_clause, ':customerDefaultAddressID', $_SESSION['customer_default_address_id'], 'integer');
  106. $sql_data_array = array(array('fieldName'=>'entry_firstname', 'value'=>$firstname, 'type'=>'string'),
  107. array('fieldName'=>'entry_lastname', 'value'=>$lastname, 'type'=>'string'));
  108. if (ACCOUNT_GENDER == 'true') {
  109. $sql_data_array[] = array('fieldName'=>'entry_gender', 'value'=>$gender, 'type'=>'string');
  110. }
  111. $db->perform(TABLE_ADDRESS_BOOK, $sql_data_array, 'update', $where_clause);
  112. $zco_notifier->notify('NOTIFY_HEADER_ACCOUNT_EDIT_UPDATES_COMPLETE');
  113. // reset the session variables
  114. $_SESSION['customer_first_name'] = $firstname;
  115. $messageStack->add_session('account', SUCCESS_ACCOUNT_UPDATED, 'success');
  116. zen_redirect(zen_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  117. }
  118. }
  119. $account_query = "SELECT customers_gender, customers_firstname, customers_lastname,
  120. customers_dob, customers_email_address, customers_telephone,
  121. customers_fax, customers_email_format, customers_referral
  122. FROM " . TABLE_CUSTOMERS . "
  123. WHERE customers_id = :customersID";
  124. $account_query = $db->bindVars($account_query, ':customersID', $_SESSION['customer_id'], 'integer');
  125. $account = $db->Execute($account_query);
  126. if (ACCOUNT_GENDER == 'true') {
  127. if (isset($gender)) {
  128. $male = ($gender == 'm') ? true : false;
  129. } else {
  130. $male = ($account->fields['customers_gender'] == 'm') ? true : false;
  131. }
  132. $female = !$male;
  133. }
  134. // if DOB field has database default setting, show blank:
  135. $dob = ($dob == '0001-01-01 00:00:00') ? '' : $dob;
  136. $customers_referral = $account->fields['customers_referral'];
  137. if (isset($customers_email_format)) {
  138. $email_pref_html = (($customers_email_format == 'HTML') ? true : false);
  139. $email_pref_none = (($customers_email_format == 'NONE') ? true : false);
  140. $email_pref_optout = (($customers_email_format == 'OUT') ? true : false);
  141. $email_pref_text = (($email_pref_html || $email_pref_none || $email_pref_out) ? false : true); // if not in any of the others, assume TEXT
  142. } else {
  143. $email_pref_html = (($account->fields['customers_email_format'] == 'HTML') ? true : false);
  144. $email_pref_none = (($account->fields['customers_email_format'] == 'NONE') ? true : false);
  145. $email_pref_optout = (($account->fields['customers_email_format'] == 'OUT') ? true : false);
  146. $email_pref_text = (($email_pref_html || $email_pref_none || $email_pref_out) ? false : true); // if not in any of the others, assume TEXT
  147. }
  148. $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  149. $breadcrumb->add(NAVBAR_TITLE_2);
  150. // This should be last line of the script:
  151. $zco_notifier->notify('NOTIFY_HEADER_END_ACCOUNT_EDIT');
  152. ?>