/wp-content/plugins/wp-e-commerce/edit-profile.php

https://gitlab.com/endomorphosis/reservationtelco · PHP · 193 lines · 170 code · 22 blank · 1 comment · 25 complexity · f70951fa504a0f1587e0bb055fa10cf8 MD5 · raw file

  1. <?php
  2. $any_bad_inputs = false;
  3. $changes_saved = false;
  4. $_SESSION['collected_data'] = null;
  5. if($_POST['collected_data'] != null) {
  6. foreach((array)$_POST['collected_data'] as $value_id => $value) {
  7. $form_sql = "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `id` = '$value_id' LIMIT 1";
  8. $form_data = $wpdb->get_results($form_sql,ARRAY_A);
  9. $form_data = $form_data[0];
  10. $bad_input = false;
  11. if($form_data['mandatory'] == 1) {
  12. switch($form_data['type']) {
  13. case "email":
  14. if(!preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,5}$/",$value)) {
  15. $any_bad_inputs = true;
  16. $bad_input = true;
  17. }
  18. break;
  19. case "delivery_country":
  20. if(($value != null)) {
  21. $_SESSION['delivery_country'] == $value;
  22. }
  23. break;
  24. default:
  25. break;
  26. }
  27. if($bad_input === true) {
  28. switch($form_data['name']) {
  29. case __('First Name', 'wpsc'):
  30. $bad_input_message .= __('Please enter a valid name', 'wpsc') . "";
  31. break;
  32. case __('Last Name', 'wpsc'):
  33. $bad_input_message .= __('Please enter a valid surname', 'wpsc') . "";
  34. break;
  35. case __('Email', 'wpsc'):
  36. $bad_input_message .= __('Please enter a valid email address', 'wpsc') . "";
  37. break;
  38. case __('Address 1', 'wpsc'):
  39. case __('Address 2', 'wpsc'):
  40. $bad_input_message .= __('Please enter a valid address', 'wpsc') . "";
  41. break;
  42. case __('City', 'wpsc'):
  43. $bad_input_message .= __('Please enter your town or city.', 'wpsc') . "";
  44. break;
  45. case __('Phone', 'wpsc'):
  46. $bad_input_message .= __('Please enter a valid phone number', 'wpsc') . "";
  47. break;
  48. case __('Country', 'wpsc'):
  49. $bad_input_message .= __('Please select your country from the list.', 'wpsc') . "";
  50. break;
  51. default:
  52. $bad_input_message .= __('Please enter a valid', 'wpsc') . " " . strtolower($form_data['name']) . ".";
  53. break;
  54. }
  55. $bad_input_message .= "<br />";
  56. } else {
  57. $meta_data[$value_id] = $value;
  58. }
  59. } else {
  60. $meta_data[$value_id] = $value;
  61. }
  62. }
  63. $new_meta_data = serialize($meta_data);
  64. update_usermeta($user_ID, 'wpshpcrt_usr_profile', $meta_data);
  65. }
  66. ?>
  67. <div class="wrap" style=''>
  68. <?php
  69. echo " <div class='user-profile-links'><a href='".get_option('user_account_url')."'>Purchase History</a> | <a href='".get_option('user_account_url').$seperator."edit_profile=true'>Your Details</a> | <a href='".get_option('user_account_url').$seperator."downloads=true'>Your Downloads</a></div><br />";
  70. ?>
  71. <form method='post' action=''>
  72. <?php
  73. if($changes_saved == true) {
  74. echo __('Thanks, your changes have been saved.', 'wpsc');
  75. } else {
  76. echo $bad_input_message;
  77. }
  78. ?>
  79. <table>
  80. <?php
  81. // arr, this here be where the data will be saved
  82. $meta_data = null;
  83. $saved_data_sql = "SELECT * FROM `".$wpdb->usermeta."` WHERE `user_id` = '".$user_ID."' AND `meta_key` = 'wpshpcrt_usr_profile';";
  84. $saved_data = $wpdb->get_row($saved_data_sql,ARRAY_A);
  85. $meta_data = get_usermeta($user_ID, 'wpshpcrt_usr_profile');
  86. $form_sql = "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1' ORDER BY `order`;";
  87. $form_data = $wpdb->get_results($form_sql,ARRAY_A);
  88. foreach($form_data as $form_field)
  89. {
  90. $meta_data[$form_field['id']] = htmlentities(stripslashes($meta_data[$form_field['id']]), ENT_QUOTES);
  91. if($form_field['type'] == 'heading')
  92. {
  93. echo "
  94. <tr>
  95. <td colspan='2'>\n\r";
  96. echo "<strong>".$form_field['name']."</strong>";
  97. echo "
  98. </td>
  99. </tr>\n\r";
  100. }
  101. else
  102. {
  103. if($form_field['type'] == "country")
  104. {
  105. continue;
  106. }
  107. echo "
  108. <tr>
  109. <td align='left'>\n\r";
  110. echo $form_field['name'];
  111. if($form_field['mandatory'] == 1)
  112. {
  113. if(!(($form_field['type'] == 'country') || ($form_field['type'] == 'delivery_country')))
  114. {
  115. echo "*";
  116. }
  117. }
  118. echo "
  119. </td>\n\r
  120. <td align='left'>\n\r";
  121. switch($form_field['type'])
  122. {
  123. case "text":
  124. case "city":
  125. case "delivery_city":
  126. echo "<input type='text' value='".$meta_data[$form_field['id']]."' name='collected_data[".$form_field['id']."]' />";
  127. break;
  128. case "address":
  129. case "delivery_address":
  130. case "textarea":
  131. echo "<textarea name='collected_data[".$form_field['id']."]'>".$meta_data[$form_field['id']]."</textarea>";
  132. break;
  133. case "region":
  134. case "delivery_region":
  135. echo "<select name='collected_data[".$form_field['id']."]'>".nzshpcrt_region_list($_SESSION['collected_data'][$form_field['id']])."</select>";
  136. break;
  137. case "country":
  138. break;
  139. case "delivery_country":
  140. echo "<select name='collected_data[".$form_field['id']."]' >".nzshpcrt_country_list($meta_data[$form_field['id']])."</select>";
  141. break;
  142. case "email":
  143. echo "<input type='text' value='".$meta_data[$form_field['id']]."' name='collected_data[".$form_field['id']."]' />";
  144. break;
  145. default:
  146. echo "<input type='text' value='".$meta_data[$form_field['id']]."' name='collected_data[".$form_field['id']."]' />";
  147. break;
  148. }
  149. echo "
  150. </td>
  151. </tr>\n\r";
  152. }
  153. }
  154. ?>
  155. <?php
  156. if(isset($gateway_checkout_form_fields))
  157. {
  158. echo $gateway_checkout_form_fields;
  159. }
  160. ?>
  161. <tr>
  162. <td>
  163. </td>
  164. <td>
  165. <input type='hidden' value='true' name='submitwpcheckout_profile' />
  166. <input type='submit' value='<?php echo __('Save Profile', 'wpsc');?>' name='submit' />
  167. </td>
  168. </tr>
  169. </table>
  170. </form>
  171. </div>