PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-installer.php

https://github.com/AaronFernandes/aquestionof
PHP | 802 lines | 595 code | 129 blank | 78 comment | 125 complexity | d07546c449de00c292cb0e65e5b60ca1 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. function wpsc_auto_update() {
  3. global $wpdb;
  4. include( WPSC_FILE_PATH . '/wpsc-updates/updating_tasks.php' );
  5. wpsc_create_or_update_tables();
  6. wpsc_create_upload_directories();
  7. wpsc_product_files_htaccess();
  8. wpsc_check_and_copy_files();
  9. $wpsc_version = get_option( 'wpsc_version' );
  10. $wpsc_minor_version = get_option( 'wspc_minor_version' );
  11. if ( $wpsc_version === false )
  12. add_option( 'wpsc_version', WPSC_VERSION, '', 'yes' );
  13. else
  14. update_option( 'wpsc_version', WPSC_VERSION );
  15. if ( $wpsc_minor_version === false )
  16. add_option( 'wpsc_minor_version', WPSC_MINOR_VERSION, '', 'yes' );
  17. else
  18. update_option( 'wpsc_minor_version', WPSC_MINOR_VERSION );
  19. if ( version_compare( $wpsc_version, '3.8', '<' ) )
  20. update_option( 'wpsc_needs_update', true );
  21. else
  22. update_option( 'wpsc_needs_update', false );
  23. }
  24. function wpsc_install() {
  25. global $wpdb, $user_level, $wp_rewrite, $wp_version, $wpsc_page_titles;
  26. $table_name = $wpdb->prefix . "wpsc_product_list";
  27. $first_install = false;
  28. $result = mysql_list_tables( DB_NAME );
  29. $tables = array();
  30. while ( $row = mysql_fetch_row( $result ) )
  31. $tables[] = $row[0];
  32. if ( !in_array( $table_name, $tables ) ) {
  33. $first_install = true;
  34. add_option( 'wpsc_purchaselogs_fixed', true );
  35. }
  36. if ( !$first_install )
  37. wpsc_regenerate_thumbnails();
  38. // run the create or update code here.
  39. wpsc_create_or_update_tables();
  40. wpsc_create_upload_directories();
  41. if ( !wp_get_schedule( "wpsc_hourly_cron_tasks" ) )
  42. wp_schedule_event( time(), 'hourly', 'wpsc_hourly_cron_tasks' );
  43. if ( !wp_get_schedule( "wpsc_daily_cron_tasks" ) )
  44. wp_schedule_event( time(), 'daily', 'wpsc_daily_cron_tasks' );
  45. // All code to add new database tables and columns must be above here
  46. $wpsc_version = get_option( 'wpsc_version', 0 );
  47. $wpsc_minor_version = get_option( 'wspc_minor_version', 0 );
  48. if ( $wpsc_version === false )
  49. add_option( 'wpsc_version', WPSC_VERSION, '', 'yes' );
  50. else
  51. update_option( 'wpsc_version', WPSC_VERSION );
  52. if ( $wpsc_minor_version === false )
  53. add_option( 'wpsc_minor_version', WPSC_MINOR_VERSION, '', 'yes' );
  54. else
  55. update_option( 'wpsc_minor_version', WPSC_MINOR_VERSION );
  56. if ( version_compare( $wpsc_version, '3.8', '<' ) )
  57. update_option( 'wpsc_needs_update', true );
  58. else
  59. update_option( 'wpsc_needs_update', false );
  60. if('' == get_option('show_subcatsprods_in_cat'))
  61. update_option('show_subcatsprods_in_cat',0);
  62. if('' == get_option('wpsc_share_this'))
  63. update_option('wpsc_share_this',0);
  64. if('' == get_option('wpsc_crop_thumbnails'))
  65. update_option('wpsc_crop_thumbnails',0);
  66. if('' == get_option('wpsc_products_per_page'))
  67. update_option('wpsc_products_per_page',0);
  68. if('' == get_option('wpsc_force_ssl'))
  69. update_option('wpsc_force_ssl',0);
  70. if('' == get_option('use_pagination'))
  71. update_option('use_pagination',0);
  72. if('' == get_option('hide_name_link'))
  73. update_option('hide_name_link',0);
  74. if('' == get_option('wpsc_enable_comments'))
  75. update_option('wpsc_enable_comments',0);
  76. if('' == get_option('multi_add'))
  77. update_option('multi_add',0);
  78. if('' == get_option('hide_addtocart_button'))
  79. update_option('hide_addtocart_button',0);
  80. if('' == get_option('wpsc_addtocart_or_buynow'))
  81. update_option('wpsc_addtocart_or_buynow',0);
  82. add_option( 'show_thumbnails', 1, '', "yes" );
  83. add_option( 'show_thumbnails_thickbox', 1, '', "yes" );
  84. add_option( 'product_list_url', '', '', 'yes' );
  85. add_option( 'shopping_cart_url', '', '', 'yes' );
  86. add_option( 'checkout_url', '', '', 'yes' );
  87. add_option( 'transact_url', '', '', 'yes' );
  88. add_option( 'payment_gateway', '','', 'yes' );
  89. $default_payment_gateways_names = array(
  90. 'chronopay' => '',
  91. 'google' => '',
  92. 'wpsc_merchant_paypal_express' => '',
  93. 'wpsc_merchant_paypal_pro' => '',
  94. 'wpsc_merchant_paypal_standard' => ''
  95. );
  96. $existing_payment_gateways_names = get_option( 'payment_gateway_names' );
  97. $new_payment_gatewats_name = array_merge($default_payment_gateways_names, (array)$existing_payment_gateways_names);
  98. update_option( 'payment_gateway_names', $new_payment_gatewats_name );
  99. if ( function_exists( 'register_sidebar' ) )
  100. add_option( 'cart_location', '4','', 'yes' );
  101. else
  102. add_option( 'cart_location', '1', '', 'yes' );
  103. add_option( 'currency_type', '156','', 'yes' );
  104. add_option( 'currency_sign_location', '3', '', 'yes' );
  105. add_option( 'gst_rate', '1','', 'yes' );
  106. add_option( 'max_downloads', '1','', 'yes' );
  107. add_option( 'display_pnp', '1', '', 'yes' );
  108. add_option( 'display_specials', '1', '', 'yes' );
  109. add_option( 'do_not_use_shipping', '1', '', 'yes' );
  110. add_option( 'postage_and_packaging', '0','', 'yes' );
  111. add_option( 'purch_log_email', '', '', 'yes' );
  112. add_option( 'return_email', '', '', 'yes' );
  113. add_option( 'terms_and_conditions', '', '', 'yes' );
  114. add_option( 'google_key', 'none', '', 'yes' );
  115. add_option( 'google_id', 'none', '', 'yes' );
  116. add_option( 'default_brand', 'none', '', 'yes' );
  117. add_option( 'wpsc_default_category', 'all', '', 'yes' );
  118. add_option( 'product_view', 'default', "", 'yes' );
  119. add_option( 'add_plustax', 'default', "", '1' );
  120. add_option( 'nzshpcrt_first_load', '0', "", 'yes' );
  121. if ( !((get_option( 'show_categorybrands' ) > 0) && (get_option( 'show_categorybrands' ) < 3)) )
  122. update_option( 'show_categorybrands', 2 );
  123. // PayPal options
  124. add_option( 'paypal_business', '', '', 'yes' );
  125. add_option( 'paypal_url', '', '', 'yes' );
  126. add_option( 'paypal_ipn', '1', '', 'yes' );
  127. add_option( 'paypal_multiple_business', '', '', 'yes' );
  128. add_option( 'paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr" );
  129. add_option( 'product_ratings', '0', '', 'yes' );
  130. add_option( 'wpsc_email_receipt', __( 'Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.
  131. You ordered these items:
  132. %product_list%%total_shipping%%total_price%', 'wpsc' ), '', 'yes' );
  133. add_option( 'wpsc_email_admin', __( '%product_list%%total_shipping%%total_price%', 'wpsc' ), '','yes' );
  134. add_option( 'wpsc_selected_theme', 'default', '', 'yes' );
  135. add_option( 'product_image_height', 148);
  136. add_option( 'product_image_width', 148);
  137. add_option( 'category_image_height', 148 );
  138. add_option( 'category_image_width', 148 );
  139. add_option( 'single_view_image_height', 148 );
  140. add_option( 'single_view_image_width', 148 );
  141. add_option( 'wpsc_gallery_image_height', 31 );
  142. add_option( 'wpsc_gallery_image_width', 31 );
  143. add_option( 'wpsc_thousands_separator', ',' );
  144. add_option( 'wpsc_decimal_separator', '.' );
  145. add_option( 'custom_gateway_options', array('wpsc_merchant_testmode'), '', 'yes' );
  146. add_option( 'wpsc_category_url_cache', array(), '', 'yes' );
  147. // add in some default tax settings
  148. add_option( 'wpec_taxes_inprice', 'exclusive' );
  149. add_option( 'wpec_taxes_product', 'replace' );
  150. add_option( 'wpec_taxes_logic', 'billing' );
  151. wpsc_product_files_htaccess();
  152. /*
  153. * This part creates the pages and automatically puts their URLs into the options page.
  154. * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
  155. */
  156. $post_date = date( "Y-m-d H:i:s" );
  157. $post_date_gmt = gmdate( "Y-m-d H:i:s" );
  158. $pages = array(
  159. 'products-page' => array(
  160. 'name' => 'products-page',
  161. 'title' => __( 'Products Page', 'wpsc' ),
  162. 'tag' => '[productspage]',
  163. 'option' => 'product_list_url'
  164. ),
  165. 'checkout' => array(
  166. 'name' => 'checkout',
  167. 'title' => __( 'Checkout', 'wpsc' ),
  168. 'tag' => '[shoppingcart]',
  169. 'option' => 'shopping_cart_url'
  170. ),
  171. 'transaction-results' => array(
  172. 'name' => 'transaction-results',
  173. 'title' => __( 'Transaction Results', 'wpsc' ),
  174. 'tag' => '[transactionresults]',
  175. 'option' => 'transact_url'
  176. ),
  177. 'your-account' => array(
  178. 'name' => 'your-account',
  179. 'title' => __( 'Your Account', 'wpsc' ),
  180. 'tag' => '[userlog]',
  181. 'option' => 'user_account_url'
  182. )
  183. );
  184. //indicator. if we will create any new pages we need to flush.. :)
  185. $newpages = false;
  186. //get products page id. if there's no products page then create one
  187. $products_page_id = $wpdb->get_var("SELECT id FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $pages['products-page']['tag'] . "%' AND `post_type` != 'revision'");
  188. if( empty($products_page_id) ){
  189. $products_page_id = wp_insert_post( array(
  190. 'post_title' => $pages['products-page']['title'],
  191. 'post_type' => 'page',
  192. 'post_name' => $pages['products-page']['name'],
  193. 'comment_status'=> 'closed',
  194. 'ping_status' => 'closed',
  195. 'post_content' => $pages['products-page']['tag'],
  196. 'post_status' => 'publish',
  197. 'post_author' => 1,
  198. 'menu_order' => 0
  199. ));
  200. $newpages = true;
  201. }
  202. update_option( $pages['products-page']['option'], _get_page_link($products_page_id) );
  203. //done. products page created. no we can unset products page data and create all other pages.
  204. //unset products page
  205. unset($pages['products-page']);
  206. //create other pages
  207. foreach( (array)$pages as $page ){
  208. //check if page exists and get it's ID
  209. $page_id = $wpdb->get_var("SELECT id FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%' AND `post_type` != 'revision'");
  210. //if there's no page - create
  211. if( empty($page_id) ){
  212. $page_id = wp_insert_post( array(
  213. 'post_title' => $page['title'],
  214. 'post_type' => 'page',
  215. 'post_name' => $page['name'],
  216. 'comment_status'=> 'closed',
  217. 'ping_status' => 'closed',
  218. 'post_content' => $page['tag'],
  219. 'post_status' => 'publish',
  220. 'post_author' => 1,
  221. 'menu_order' => 0,
  222. 'post_parent' => $products_page_id
  223. ));
  224. $newpages = true;
  225. }
  226. //update option
  227. update_option( $page['option'], get_permalink( $page_id ) );
  228. //also if this is shopping_cart, then update checkout url option
  229. if ( $page['option'] == 'shopping_cart_url' )
  230. update_option( 'checkout_url', get_permalink( $page_id ) );
  231. }
  232. //if we have created any new pages, then flush... do we need to do this? probably should be removed
  233. if ( $newpages ) {
  234. wp_cache_delete( 'all_page_ids', 'pages' );
  235. $wp_rewrite->flush_rules();
  236. }
  237. // Product categories, temporarily register them to create first default category if none exist
  238. // @todo: investigate those require once lines and move them to right place (not from here, but from their original location, which seems to be wrong, since i cant access wpsc_register_post_types and wpsc_update_categorymeta here) - Vales <v.bakaitis@gmail.com>
  239. require_once( WPSC_FILE_PATH . '/wpsc-core/wpsc-functions.php' );
  240. wpsc_register_post_types();
  241. $category_list = get_terms( 'wpsc_product_category', 'hide_empty=0&parent=0' );
  242. if ( count( $category_list ) == 0 ) {
  243. require_once( WPSC_FILE_PATH . '/wpsc-includes/meta.functions.php' );
  244. $new_category = wp_insert_term( __( 'Product Category', 'wpsc' ), 'wpsc_product_category', "parent=0" );
  245. $category_id = $new_category['term_id'];
  246. $term = get_term_by( 'id', $new_category['term_id'], 'wpsc_product_category' );
  247. $url_name = $term->slug;
  248. $wp_rewrite->flush_rules();
  249. wpsc_update_categorymeta( $category_id, 'nice-name', $url_name );
  250. wpsc_update_categorymeta( $category_id, 'description', __( "This is a description", 'wpsc' ) );
  251. wpsc_update_categorymeta( $category_id, 'image', '' );
  252. wpsc_update_categorymeta( $category_id, 'fee', '0' );
  253. wpsc_update_categorymeta( $category_id, 'active', '1' );
  254. wpsc_update_categorymeta( $category_id, 'order', '0' );
  255. }
  256. }
  257. /*
  258. Code borrowed with much gratitude from Viper007Bond. Thanks for writing a great plugin, Alex!
  259. We've basically just removed the admin interface, we're just going to be hooking into the regeneration functions when new custom sizes are made or when the plugin is updated. Fancy!
  260. **************************************************************************
  261. Plugin Name: Regenerate Thumbnails
  262. Plugin URI: http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/
  263. Description: Allows you to regenerate all thumbnails after changing the thumbnail sizes.
  264. Version: 2.0.3
  265. Author: Viper007Bond
  266. Author URI: http://www.viper007bond.com/
  267. **************************************************************************
  268. Copyright (C) 2008 Viper007Bond
  269. *************************************************************************
  270. */
  271. function wpsc_regenerate_thumbnails() {
  272. global $wpdb;
  273. if( !ini_get('safe_mode') ) set_time_limit(250);
  274. if ( !function_exists( 'wp_generate_attachment_metadata' ) ) {
  275. require_once ( ABSPATH . 'wp-admin/includes/image.php' );
  276. }
  277. // Just query for the IDs (specifically those that have products for parents) only to reduce memory usage
  278. $images = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'" );
  279. foreach ( $images as $image ) {
  280. $id = $image->ID;
  281. $post_parent_type = get_post_type( $image->post_parent );
  282. if ("wpsc-product" == $post_parent_type) {
  283. $fullsizepath = get_attached_file( $id );
  284. if ( false === $fullsizepath || !file_exists($fullsizepath) )
  285. die ("Could not find path specified!");
  286. if ( wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) ) ) {
  287. $success = true;
  288. } else {
  289. $success = false;
  290. }
  291. }
  292. }
  293. }
  294. function wpsc_product_files_htaccess() {
  295. if ( !is_file( WPSC_FILE_DIR . ".htaccess" ) ) {
  296. $htaccess = "order deny,allow\n\r";
  297. $htaccess .= "deny from all\n\r";
  298. $htaccess .= "allow from none\n\r";
  299. $filename = WPSC_FILE_DIR . ".htaccess";
  300. $file_handle = @ fopen( $filename, 'w+' );
  301. @ fwrite( $file_handle, $htaccess );
  302. @ fclose( $file_handle );
  303. @ chmod( $file_handle, 0665 );
  304. }
  305. }
  306. function wpsc_check_and_copy_files() {
  307. $upload_path = 'wp-content/plugins/' . WPSC_DIR_NAME;
  308. $wpsc_dirs['files']['old'] = ABSPATH . "{$upload_path}/files/";
  309. $wpsc_dirs['files']['new'] = WPSC_FILE_DIR;
  310. $wpsc_dirs['previews']['old'] = ABSPATH . "{$upload_path}/preview_clips/";
  311. $wpsc_dirs['previews']['new'] = WPSC_PREVIEW_DIR;
  312. // I don't include the thumbnails directory in this list, as it is a subdirectory of the images directory and is moved along with everything else
  313. $wpsc_dirs['images']['old'] = ABSPATH . "{$upload_path}/product_images/";
  314. $wpsc_dirs['images']['new'] = WPSC_IMAGE_DIR;
  315. $wpsc_dirs['categories']['old'] = ABSPATH . "{$upload_path}/category_images/";
  316. $wpsc_dirs['categories']['new'] = WPSC_CATEGORY_DIR;
  317. $incomplete_file_transfer = false;
  318. foreach ( $wpsc_dirs as $wpsc_dir ) {
  319. if ( is_dir( $wpsc_dir['old'] ) ) {
  320. $files_in_dir = glob( $wpsc_dir['old'] . "*" );
  321. $stat = stat( $wpsc_dir['new'] );
  322. if ( count( $files_in_dir ) > 0 ) {
  323. foreach ( $files_in_dir as $file_in_dir ) {
  324. $file_name = str_replace( $wpsc_dir['old'], '', $file_in_dir );
  325. if ( @ rename( $wpsc_dir['old'] . $file_name, $wpsc_dir['new'] . $file_name ) ) {
  326. if ( is_dir( $wpsc_dir['new'] . $file_name ) ) {
  327. $perms = $stat['mode'] & 0000775;
  328. } else {
  329. $perms = $stat['mode'] & 0000665;
  330. }
  331. @ chmod( ($wpsc_dir['new'] . $file_name ), $perms );
  332. } else {
  333. $incomplete_file_transfer = true;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. if ( $incomplete_file_transfer == true ) {
  340. add_option( 'wpsc_incomplete_file_transfer', 'default', "", 'true' );
  341. }
  342. }
  343. function wpsc_create_upload_directories() {
  344. // Create the required folders
  345. $folders = array(
  346. WPSC_UPLOAD_DIR,
  347. WPSC_FILE_DIR,
  348. WPSC_PREVIEW_DIR,
  349. WPSC_IMAGE_DIR,
  350. WPSC_THUMBNAIL_DIR,
  351. WPSC_CATEGORY_DIR,
  352. WPSC_USER_UPLOADS_DIR,
  353. WPSC_CACHE_DIR,
  354. WPSC_UPGRADES_DIR,
  355. WPSC_THEMES_PATH
  356. );
  357. foreach ( $folders as $folder ) {
  358. wp_mkdir_p( $folder );
  359. @ chmod( $folder, 0775 );
  360. }
  361. }
  362. function wpsc_copy_themes_to_uploads() {
  363. $old_theme_path = WPSC_CORE_THEME_PATH;
  364. $new_theme_path = WPSC_THEMES_PATH;
  365. $new_dir = @ opendir( $new_theme_path );
  366. $num = 0;
  367. $file_names = array( );
  368. while ( ($file = @ readdir( $new_dir )) !== false ) {
  369. if ( is_dir( $new_theme_path . $file ) && ($file != "..") && ($file != ".") ) {
  370. $file_names[] = $file;
  371. }
  372. }
  373. if ( count( $file_names ) < 1 ) {
  374. $old_dir = @ opendir( $old_theme_path );
  375. while ( ($file = @ readdir( $old_dir )) !== false ) {
  376. if ( is_dir( $old_theme_path . $file ) && ($file != "..") && ($file != ".") ) {
  377. @ wpsc_recursive_copy( $old_theme_path . $file, $new_theme_path . $file );
  378. }
  379. }
  380. }
  381. }
  382. /**
  383. * wpsc_create_or_update_tables count function,
  384. * * @return boolean true on success, false on failure
  385. */
  386. function wpsc_create_or_update_tables( $debug = false ) {
  387. global $wpdb;
  388. // creates or updates the structure of the shopping cart tables
  389. include( WPSC_FILE_PATH . '/wpsc-updates/database_template.php' );
  390. $template_hash = sha1( serialize( $wpsc_database_template ) );
  391. // Filter for adding to or altering the wpsc database template, make sure you return the array your function gets passed, else you will break updating the database tables
  392. $wpsc_database_template = apply_filters( 'wpsc_alter_database_template', $wpsc_database_template );
  393. $failure_reasons = array( );
  394. $upgrade_failed = false;
  395. foreach ( (array)$wpsc_database_template as $table_name => $table_data ) {
  396. // check that the table does not exist under the correct name, then checkk if there was a previous name, if there was, check for the table under that name too.
  397. if ( !$wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) && (!isset( $table_data['previous_names'] ) || (isset( $table_data['previous_names'] ) && !$wpdb->get_var( "SHOW TABLES LIKE '{$table_data['previous_names']}'" )) ) ) {
  398. //if the table does not exixt, create the table
  399. $constructed_sql_parts = array( );
  400. $constructed_sql = "CREATE TABLE `{$table_name}` (\n";
  401. // loop through the columns
  402. foreach ( (array)$table_data['columns'] as $column => $properties ) {
  403. $constructed_sql_parts[] = "`$column` $properties";
  404. }
  405. // then through the indexes
  406. foreach ( (array)$table_data['indexes'] as $properties ) {
  407. $constructed_sql_parts[] = "$properties";
  408. }
  409. $constructed_sql .= implode( ",\n", $constructed_sql_parts );
  410. $constructed_sql .= "\n) ENGINE=MyISAM";
  411. // if mySQL is new enough, set the character encoding
  412. if ( method_exists( $wpdb, 'db_version' ) && version_compare( $wpdb->db_version(), '4.1', '>=' ) ) {
  413. $constructed_sql .= " CHARSET=utf8";
  414. }
  415. $constructed_sql .= ";";
  416. if ( !$wpdb->query( $constructed_sql ) ) {
  417. $upgrade_failed = true;
  418. $failure_reasons[] = $wpdb->last_error;
  419. }
  420. if ( isset( $table_data['actions']['after']['all'] ) && is_callable( $table_data['actions']['after']['all'] ) ) {
  421. $table_data['actions']['after']['all']();
  422. }
  423. } else {
  424. // check to see if the new table name is in use
  425. if ( !$wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) && (isset( $table_data['previous_names'] ) && $wpdb->get_var( "SHOW TABLES LIKE '{$table_data['previous_names']}'" )) ) {
  426. $wpdb->query( "ALTER TABLE `{$table_data['previous_names']}` RENAME TO `{$table_name}`;" );
  427. $failure_reasons[] = $wpdb->last_error;
  428. }
  429. //check to see if the table needs updating
  430. $existing_table_columns = array( );
  431. //check and possibly update the character encoding
  432. if ( method_exists( $wpdb, 'db_version' ) && version_compare( $wpdb->db_version(), '4.1', '>=' ) ) {
  433. $table_status_data = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table_name'", ARRAY_A );
  434. if ( $table_status_data['Collation'] != 'utf8_general_ci' ) {
  435. $wpdb->query( "ALTER TABLE `$table_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" );
  436. }
  437. }
  438. if ( isset( $table_data['actions']['before']['all'] ) && is_callable( $table_data['actions']['before']['all'] ) ) {
  439. $table_data['actions']['before']['all']();
  440. }
  441. //get the column list
  442. $existing_table_column_data = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table_name`", ARRAY_A );
  443. foreach ( (array)$existing_table_column_data as $existing_table_column ) {
  444. $column_name = $existing_table_column['Field'];
  445. $existing_table_columns[] = $column_name;
  446. $null_match = false;
  447. if ( $existing_table_column['Null'] = 'NO' ) {
  448. if ( stristr( $table_data['columns'][$column_name], "NOT NULL" ) !== false ) {
  449. $null_match = true;
  450. }
  451. } else {
  452. if ( stristr( $table_data['columns'][$column_name], "NOT NULL" ) === false ) {
  453. $null_match = true;
  454. }
  455. }
  456. if ( isset( $table_data['columns'][$column_name] ) && ((stristr( $table_data['columns'][$column_name], $existing_table_column['Type'] ) === false) || ($null_match != true)) ) {
  457. if ( isset( $table_data['actions']['before'][$column_name] ) && is_callable( $table_data['actions']['before'][$column_name] ) ) {
  458. $table_data['actions']['before'][$column_name]( $column_name );
  459. }
  460. if ( !$wpdb->query( "ALTER TABLE `$table_name` CHANGE `$column_name` `$column_name` {$table_data['columns'][$column_name]} " ) ) {
  461. $upgrade_failed = true;
  462. $failure_reasons[] = $wpdb->last_error;
  463. }
  464. }
  465. }
  466. $supplied_table_columns = array_keys( $table_data['columns'] );
  467. // compare the supplied and existing columns to find the differences
  468. $missing_or_extra_table_columns = array_diff( $supplied_table_columns, $existing_table_columns );
  469. if ( count( $missing_or_extra_table_columns ) > 0 ) {
  470. foreach ( (array)$missing_or_extra_table_columns as $missing_or_extra_table_column ) {
  471. if ( isset( $table_data['columns'][$missing_or_extra_table_column] ) ) {
  472. //table column is missing, add it
  473. $previous_column = $supplied_table_columns[array_search( $missing_or_extra_table_column, $supplied_table_columns ) - 1];
  474. if ( $previous_column != '' ) {
  475. $previous_column = "AFTER `$previous_column`";
  476. }
  477. $constructed_sql = "ALTER TABLE `$table_name` ADD `$missing_or_extra_table_column` " . $table_data['columns'][$missing_or_extra_table_column] . " $previous_column;";
  478. if ( !$wpdb->query( $constructed_sql ) ) {
  479. $upgrade_failed = true;
  480. $failure_reasons[] = $wpdb->last_error;
  481. }
  482. // run updating functions to do more complex work with default values and the like
  483. if ( is_callable( $table_data['actions']['after'][$missing_or_extra_table_column] ) ) {
  484. $table_data['actions']['after'][$missing_or_extra_table_column]( $missing_or_extra_table_column );
  485. }
  486. }
  487. }
  488. }
  489. if ( isset( $table_data['actions']['after']['all'] ) && is_callable( $table_data['actions']['after']['all'] ) ) {
  490. $table_data['actions']['after']['all']();
  491. }
  492. // get the list of existing indexes
  493. $existing_table_index_data = $wpdb->get_results( "SHOW INDEX FROM `$table_name`", ARRAY_A );
  494. $existing_table_indexes = array( );
  495. foreach ( $existing_table_index_data as $existing_table_index ) {
  496. $existing_table_indexes[] = $existing_table_index['Key_name'];
  497. }
  498. $existing_table_indexes = array_unique( $existing_table_indexes );
  499. $supplied_table_indexes = array_keys( $table_data['indexes'] );
  500. // compare the supplied and existing indxes to find the differences
  501. $missing_or_extra_table_indexes = array_diff( $supplied_table_indexes, $existing_table_indexes );
  502. if ( count( $missing_or_extra_table_indexes ) > 0 ) {
  503. foreach ( $missing_or_extra_table_indexes as $missing_or_extra_table_index ) {
  504. if ( isset( $table_data['indexes'][$missing_or_extra_table_index] ) ) {
  505. $constructed_sql = "ALTER TABLE `$table_name` ADD " . $table_data['indexes'][$missing_or_extra_table_index] . ";";
  506. if ( !$wpdb->query( $constructed_sql ) ) {
  507. $upgrade_failed = true;
  508. $failure_reasons[] = $wpdb->last_error;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. if ( $upgrade_failed !== true ) {
  516. update_option( 'wpsc_database_check', $template_hash );
  517. return true;
  518. } else {
  519. return false;
  520. }
  521. }
  522. /**
  523. * The following functions are used exclusively in database_template.php
  524. */
  525. /**
  526. * wpsc_add_currency_list function, converts values to decimal to satisfy mySQL strict mode
  527. * * @return boolean true on success, false on failure
  528. */
  529. function wpsc_add_currency_list() {
  530. global $wpdb;
  531. require_once(WPSC_FILE_PATH . "/wpsc-updates/currency_list.php");
  532. $currency_data = $wpdb->get_var( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_CURRENCY_LIST . "`" );
  533. if ( $currency_data == 0 ) {
  534. $currency_array = explode( "\n", $currency_sql );
  535. foreach ( $currency_array as $currency_row ) {
  536. $wpdb->query( $currency_row );
  537. }
  538. }
  539. }
  540. /**
  541. * wpsc_add_region_list function, converts values to decimal to satisfy mySQL strict mode
  542. * * @return boolean true on success, false on failure
  543. */
  544. function wpsc_add_region_list() {
  545. global $wpdb;
  546. $add_regions = $wpdb->get_var( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_REGION_TAX . "`" );
  547. if ( $add_regions < 1 ) {
  548. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Alberta', '', '0')" );
  549. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'British Columbia', '', '0')" );
  550. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Manitoba', '', '0')" );
  551. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'New Brunswick', '', '0')" );
  552. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Newfoundland', '', '0')" );
  553. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Northwest Territories', '', '0')" );
  554. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Nova Scotia', '', '0')" );
  555. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Nunavut', '', '0')" );
  556. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Ontario', '', '0')" );
  557. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Prince Edward Island', '', '0')" );
  558. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Quebec', '', '0')" );
  559. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Saskatchewan', '', '0')" );
  560. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '100', 'Yukon', '', '0')" );
  561. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Alabama', 'AL', '0')" );
  562. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Alaska', 'AK', '0')" );
  563. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Arizona', 'AZ', '0')" );
  564. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Arkansas', 'AR', '0')" );
  565. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'California', 'CA', '0')" );
  566. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Colorado', 'CO', '0')" );
  567. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Connecticut', 'CT', '0')" );
  568. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Delaware', 'DE', '0')" );
  569. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Florida', 'FL', '0')" );
  570. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Georgia', 'GA', '0')" );
  571. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Hawaii', 'HI', '0')" );
  572. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Idaho', 'ID', '0')" );
  573. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Illinois', 'IL', '0')" );
  574. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Indiana', 'IN', '0')" );
  575. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Iowa', 'IA', '0')" );
  576. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Kansas', 'KS', '0')" );
  577. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Kentucky', 'KY', '0')" );
  578. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Louisiana', 'LA', '0')" );
  579. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Maine', 'ME', '0')" );
  580. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Maryland', 'MD', '0')" );
  581. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Massachusetts', 'MA', '0')" );
  582. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Michigan', 'MI', '0')" );
  583. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Minnesota', 'MN', '0')" );
  584. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Mississippi', 'MS', '0')" );
  585. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Missouri', 'MO', '0')" );
  586. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Montana', 'MT', '0')" );
  587. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Nebraska', 'NE', '0')" );
  588. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Nevada', 'NV', '0')" );
  589. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'New Hampshire', 'NH', '0')" );
  590. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'New Jersey', 'NJ', '0')" );
  591. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'New Mexico', 'NM', '0')" );
  592. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'New York', 'NY', '0')" );
  593. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'North Carolina', 'NC', '0')" );
  594. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'North Dakota', 'ND', '0')" );
  595. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Ohio', 'OH', '0')" );
  596. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Oklahoma', 'OK', '0')" );
  597. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Oregon', 'OR', '0')" );
  598. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Pennsylvania', 'PA', '0')" );
  599. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Rhode Island', 'RI', '0')" );
  600. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'South Carolina', 'SC', '0')" );
  601. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'South Dakota', 'SD', '0')" );
  602. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Tennessee', 'TN', '0')" );
  603. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Texas', 'TX', '0')" );
  604. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Utah', 'UT', '0')" );
  605. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Vermont', 'VT', '0')" );
  606. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Virginia', 'VA', '0')" );
  607. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Washington', 'WA', '0')" );
  608. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Washington DC', 'DC', '0')" );
  609. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'West Virginia', 'WV', '0')" );
  610. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Wisconsin', 'WI', '0')" );
  611. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_REGION_TAX . "` ( `country_id` , `name` ,`code`, `tax` ) VALUES ( '136', 'Wyoming', 'WY', '0')" );
  612. }
  613. if ( $wpdb->get_var( "SELECT COUNT(*) FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `code`=''" ) > 0 ) {
  614. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'AB' WHERE `name` IN('Alberta') LIMIT 1 ;" );
  615. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'BC' WHERE `name` IN('British Columbia') LIMIT 1 ;" );
  616. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'MB' WHERE `name` IN('Manitoba') LIMIT 1 ;" );
  617. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'NK' WHERE `name` IN('New Brunswick') LIMIT 1 ;" );
  618. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'NF' WHERE `name` IN('Newfoundland') LIMIT 1 ;" );
  619. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'NT' WHERE `name` IN('Northwest Territories') LIMIT 1 ;" );
  620. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'NS' WHERE `name` IN('Nova Scotia') LIMIT 1 ;" );
  621. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'ON' WHERE `name` IN('Ontario') LIMIT 1 ;" );
  622. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'PE' WHERE `name` IN('Prince Edward Island') LIMIT 1 ;" );
  623. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'PQ' WHERE `name` IN('Quebec') LIMIT 1 ;" );
  624. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'SN' WHERE `name` IN('Saskatchewan') LIMIT 1 ;" );
  625. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'YT' WHERE `name` IN('Yukon') LIMIT 1 ;" );
  626. $wpdb->query( "UPDATE `" . WPSC_TABLE_REGION_TAX . "` SET `code` = 'NU' WHERE `name` IN('Nunavut') LIMIT 1 ;" );
  627. }
  628. }
  629. /**
  630. * wpsc_add_checkout_fields function, converts values to decimal to satisfy mySQL strict mode
  631. * * @return boolean true on success, false on failure
  632. */
  633. function wpsc_add_checkout_fields() {
  634. global $wpdb;
  635. $data_forms = $wpdb->get_results( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "`", ARRAY_A );
  636. if ( $data_forms[0]['count'] == 0 ) {
  637. $sql = " INSERT INTO `" . WPSC_TABLE_CHECKOUT_FORMS . "` ( `name`, `type`, `mandatory`, `display_log`, `default`, `active`, `checkout_order`, `unique_name`) VALUES ( '" . __( 'Your billing/contact details', 'wpsc' ) . "', 'heading', '0', '0', '', '1', 1,''),
  638. ( '" . __( 'First Name', 'wpsc' ) . "', 'text', '1', '1', '', '1', 2,'billingfirstname'),
  639. ( '" . __( 'Last Name', 'wpsc' ) . "', 'text', '1', '1', '', '1', 3,'billinglastname'),
  640. ( '" . __( 'Address', 'wpsc' ) . "', 'address', '1', '0', '', '1', 4,'billingaddress'),
  641. ( '" . __( 'City', 'wpsc' ) . "', 'city', '1', '0', '', '1', 5,'billingcity'),
  642. ( '" . __( 'State', 'wpsc' ) . "', 'text', '0', '0', '', '1', 6,'billingstate'),
  643. ( '" . __( 'Country', 'wpsc' ) . "', 'country', '1', '0', '', '1', 7,'billingcountry'),
  644. ( '" . __( 'Postal Code', 'wpsc' ) . "', 'text', '0', '0', '', '1', 8,'billingpostcode'),
  645. ( '" . __( 'Email', 'wpsc' ) . "', 'email', '1', '1', '', '1', 9,'billingemail'),
  646. ( '" . __( 'Shipping Address', 'wpsc' ) . "', 'heading', '0', '0', '', '1', 10,'delivertoafriend'),
  647. ( '" . __( 'First Name', 'wpsc' ) . "', 'text', '0', '0', '', '1', 11,'shippingfirstname'),
  648. ( '" . __( 'Last Name', 'wpsc' ) . "', 'text', '0', '0', '', '1', 12,'shippinglastname'),
  649. ( '" . __( 'Address', 'wpsc' ) . "', 'address', '0', '0', '', '1', 13,'shippingaddress'),
  650. ( '" . __( 'City', 'wpsc' ) . "', 'city', '0', '0', '', '1', 14,'shippingcity'),
  651. ( '" . __( 'State', 'wpsc' ) . "', 'text', '0', '0', '', '1', 15,'shippingstate'),
  652. ( '" . __( 'Country', 'wpsc' ) . "', 'delivery_country', '0', '0', '', '1', 16,'shippingcountry'),
  653. ( '" . __( 'Postal Code', 'wpsc' ) . "', 'text', '0', '0', '', '1', 17,'shippingpostcode');";
  654. $wpdb->query( $sql );
  655. $wpdb->query( "INSERT INTO `" . WPSC_TABLE_CHECKOUT_FORMS . "` ( `name`, `type`, `mandatory`, `display_log`, `default`, `active`, `checkout_order`, `unique_name` ) VALUES ( '" . __( 'Phone', 'wpsc' ) . "', 'text', '1', '0', '', '1', '8','billingphone');" );
  656. }
  657. }
  658. function wpsc_rename_checkout_column(){
  659. global $wpdb;
  660. $sql = "SHOW COLUMNS FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` LIKE 'checkout_order'";
  661. $col = $wpdb->get_results($sql);
  662. if(empty($col)){
  663. $sql = "ALTER TABLE `" . WPSC_TABLE_CHECKOUT_FORMS . "` CHANGE `order` `checkout_order` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'";
  664. $wpdb->query($sql);
  665. }
  666. }
  667. ?>