PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-admin/admin.php

https://github.com/AaronFernandes/aquestionof
PHP | 915 lines | 647 code | 130 blank | 138 comment | 106 complexity | 9c0b45c6b1fb2bb8665e2a2934f236f2 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. * WP eCommerce Main Admin functions
  4. *
  5. * These are the main WPSC Admin functions
  6. *
  7. * @package wp-e-commerce
  8. * @since 3.7
  9. */
  10. // admin includes
  11. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-update.page.php' );
  12. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-items.page.php' );
  13. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-upgrades.page.php' );
  14. require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/display-items-functions.php' );
  15. require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/product-functions.php' );
  16. require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/save-data.functions.php' );
  17. require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/updating-functions.php' );
  18. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-coupons.php' );
  19. require_once( WPSC_FILE_PATH . '/wpsc-includes/purchaselogs.class.php' );
  20. require_once( WPSC_FILE_PATH . '/wpsc-includes/theming.class.php' );
  21. require_once( WPSC_FILE_PATH . '/wpsc-admin/ajax-and-init.php' );
  22. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-options-settings.page.php' );
  23. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-sales-logs.php' );
  24. if ( ( isset( $_SESSION['wpsc_activate_debug_page'] ) && ( $_SESSION['wpsc_activate_debug_page'] == true ) ) || ( defined( 'WPSC_ADD_DEBUG_PAGE' ) && ( constant( 'WPSC_ADD_DEBUG_PAGE' ) == true ) ) )
  25. require_once( WPSC_FILE_PATH . '/wpsc-admin/display-debug.page.php' );
  26. //settings pages include
  27. require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/settings-pages/general.php' );
  28. if ( !get_option( 'wpsc_checkout_form_sets' ) ) {
  29. $form_sets = array( 'Default Checkout Forms' );
  30. update_option( 'wpsc_checkout_form_sets', $form_sets );
  31. }
  32. /**
  33. * wpsc_query_vars_product_list sets the ordering for the edit-products page list
  34. * @access public
  35. *
  36. * @since 3.8
  37. * @param $vars (array) - default query arguments
  38. * @return $vars (array) - modified query arguments
  39. */
  40. function wpsc_query_vars_product_list($vars){
  41. global $current_screen;
  42. if('wpsc-product' != $current_screen->post_type) return $vars;
  43. $vars['posts_per_archive_page'] = 0;
  44. if(is_admin() && isset($vars['orderby'])){
  45. $vars['orderby'] = 'date';
  46. $vars['order'] = 'desc';
  47. $vars['nopaging'] = false;
  48. $posts_per_page = (int)get_user_option( 'edit_wpsc_product_per_page' );
  49. $vars['posts_per_page'] = ( $posts_per_page )?$posts_per_page:20;
  50. }
  51. if( 'dragndrop' == get_option('wpsc_sort_by') ){
  52. $vars['orderby'] = 'menu_order title';
  53. $vars['order'] = 'desc';
  54. $vars['nopaging'] = true;
  55. }
  56. return $vars;
  57. }
  58. /**
  59. * setting the screen option to between 1 and 999
  60. * @access public
  61. *
  62. * @since 3.8
  63. * @param $status
  64. * @param $option (string) name of option being saved
  65. * @param $value (string) value of option being saved
  66. * @return $value after changes...
  67. */
  68. function wpsc_set_screen_option($status, $option, $value){
  69. if( in_array($option, array ("edit_wpsc_variation_per_page","edit_wpsc_product_per_page" )) ){
  70. if ( "edit_wpsc_variation_per_page" == $option ){
  71. global $user_ID;
  72. update_user_option($user_ID,'edit_wpsc-variation_per_page',$value);
  73. }
  74. return $value;
  75. }
  76. }
  77. add_filter('set-screen-option', 'wpsc_set_screen_option', 99, 3);
  78. /**
  79. * When rearranging the products for drag and drop it is easiest to arrange them when they are all on the same page...
  80. * @access public (wp-admin)
  81. *
  82. * @since 3.8
  83. * @param $per_page (int) number of products per page
  84. * @param $post_type (string) name of current post type
  85. * @return $per_page after changes...
  86. */
  87. function wpsc_drag_and_drop_ordering($per_page, $post_type){
  88. global $wpdb;
  89. if('wpsc-product' == $post_type ){
  90. if( 'dragndrop' == get_option('wpsc_sort_by')){
  91. $per_page = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type`='wpsc-product' AND `post_parent`=0");
  92. }else{
  93. $_post_type = str_replace('-', '_', $post_type);
  94. $edit_per_page = 'edit_' . $_post_type . '_per_page';
  95. $per_page = ((int) get_user_option( $edit_per_page ))?(int) get_user_option( $edit_per_page ):$per_page;
  96. }
  97. return $per_page;
  98. }else{
  99. return $per_page;
  100. }
  101. }
  102. add_filter( 'request', 'wpsc_query_vars_product_list' );
  103. add_filter('edit_posts_per_page' , 'wpsc_drag_and_drop_ordering', 10, 2 );
  104. /**
  105. * Checks whether to display or hide the update wp-e-commerce link
  106. *
  107. * @access public
  108. *
  109. * @since 3.8
  110. * @return boolean true - show link, false- hide link
  111. */
  112. function wpsc_show_update_link() {
  113. global $wpdb;
  114. // Check if old product_list table exists
  115. // If it exists AND get_option wpsc_upgrade_complete is not true then return true
  116. $sql = 'SHOW TABLES LIKE "'.$wpdb->prefix.'wpsc_product_list"';
  117. $var = $wpdb->get_var( $sql );
  118. if ( !empty( $var ) && false == get_option( 'wpsc_hide_update' ) )
  119. return true;
  120. else
  121. return false;
  122. }
  123. /**
  124. * wpsc_admin_pages function, all the definitons of admin pages are stores here.
  125. * No parameters, returns nothing
  126. *
  127. * Fairly standard wordpress plugin API stuff for adding the admin pages, rearrange the order to rearrange the pages
  128. * The bits to display the options page first on first use may be buggy, but tend not to stick around long enough to be identified and fixed
  129. * if you find bugs, feel free to fix them.
  130. *
  131. * If the permissions are changed here, they will likewise need to be changed for the other sections of the admin that either use ajax
  132. * or bypass the normal download system.
  133. */
  134. function wpsc_admin_pages() {
  135. // Code to enable or disable the debug page
  136. if ( isset( $_GET['wpsc_activate_debug_page'] ) ) {
  137. if ( 'true' == $_GET['wpsc_activate_debug_page'] ) {
  138. $_SESSION['wpsc_activate_debug_page'] = true;
  139. } else if ( 'false' == $_GET['wpsc_activate_debug_page'] ) {
  140. $_SESSION['wpsc_activate_debug_page'] = false;
  141. }
  142. }
  143. // Add to Dashboard
  144. $page_hooks[] = $purchase_log_page = add_submenu_page( 'index.php', __( 'Store Sales', 'wpsc' ), __( 'Store Sales', 'wpsc' ), 'administrator', 'wpsc-sales-logs', 'wpsc_display_sales_logs' );
  145. if ( wpsc_show_update_link() )
  146. $page_hooks[] = add_submenu_page( 'index.php', __( 'Update Store', 'wpsc' ), __( 'Store Update', 'wpsc' ), 'administrator', 'wpsc-update', 'wpsc_display_update_page' );
  147. $page_hooks[] = add_submenu_page( 'index.php', __( 'Store Upgrades', 'wpsc' ), __( 'Store Upgrades', 'wpsc' ), 'administrator', 'wpsc-upgrades', 'wpsc_display_upgrades_page' );
  148. // Set the base page for Products
  149. $products_page = 'edit.php?post_type=wpsc-product';
  150. $page_hooks[] = $edit_coupons_page = add_submenu_page( $products_page , __( 'Coupons', 'wpsc' ), __( 'Coupons', 'wpsc' ), 'administrator', 'wpsc-edit-coupons', 'wpsc_display_coupons_page' );
  151. // Add Settings pages
  152. $page_hooks[] = $edit_options_page = add_options_page( __( 'Store Settings', 'wpsc' ), __( 'Store', 'wpsc' ), 'administrator', 'wpsc-settings', 'wpsc_display_settings_page' );
  153. add_action( 'admin_print_scripts-' . $edit_options_page , 'wpsc_print_admin_scripts' );
  154. // Debug Page
  155. if ( ( defined( 'WPSC_ADD_DEBUG_PAGE' ) && ( WPSC_ADD_DEBUG_PAGE == true ) ) || ( isset( $_SESSION['wpsc_activate_debug_page'] ) && ( true == $_SESSION['wpsc_activate_debug_page'] ) ) )
  156. $page_hooks[] = add_options_page( __( 'Store Debug', 'wpsc' ), __( 'Store Debug', 'wpsc' ), 'administrator', 'wpsc-debug', 'wpsc_debug_page' );
  157. $header = '<p><strong>' . __( 'For More Information', 'wpsc' ) . '</strong></p>';
  158. add_contextual_help( 'toplevel_page_wpsc-sales-logs', $header . __( "<a target='_blank' href='http://getshopped.org/resources/docs/building-your-store/sales/'>About the Sales Page</a>", 'wpsc' ) );
  159. add_contextual_help( 'toplevel_page_wpsc-edit-products', $header . __( "<a target='_blank' href='http://getshopped.org/resources/docs/building-your-store/products'>About the Products Page</a>", 'wpsc' ) );
  160. add_contextual_help( 'products_page_wpsc-edit-groups', $header . __( "<a target='_blank' href='http://getshopped.org/resources/docs/building-your-store/categories/'>About the Categories Page</a>", 'wpsc' ) );
  161. add_contextual_help( 'products_page_edit-tags', $header . __( "<a target='_blank' href='http://getshopped.org/resources/docs/building-your-store/variations/'>About the Variations Page</a>", 'wpsc' ) );
  162. add_contextual_help( 'settings_page_wpsc-settings', $header . __( "<a target='_blank' href='http://getshopped.org/resources/docs/store-settings/general/'>General Settings</a><br /> <a target='_blank' href='http://getshopped.org/resources/docs/store-settings/checkout/'>Checkout Options</a> <br />", 'wpsc' ) );
  163. add_contextual_help( 'products_page_wpsc-edit-coupons', $header . __( "<a target='_blank' href='http://getshopped.org/resources/docs/building-your-store/marketing'>Marketing Options</a><br />", 'wpsc' ) );
  164. $page_hooks = apply_filters( 'wpsc_additional_pages', $page_hooks, $products_page );
  165. do_action( 'wpsc_add_submenu' );
  166. // Include the javascript and CSS for this page
  167. // This is so important that I can't even express it in one line
  168. foreach ( $page_hooks as $page_hook ) {
  169. add_action( 'load-' . $page_hook, 'wpsc_admin_include_css_and_js_refac' );
  170. switch ( $page_hook ) {
  171. case $edit_options_page :
  172. add_action( 'load-' . $page_hook, 'wpsc_admin_include_optionspage_css_and_js' );
  173. break;
  174. case $purchase_log_page :
  175. add_action( 'admin_head', 'wpsc_product_log_rss_feed' );
  176. break;
  177. case $edit_coupons_page :
  178. add_action( 'load-' . $page_hook, 'wpsc_admin_include_coupon_js' );
  179. break;
  180. }
  181. }
  182. // Some updating code is run from here, is as good a place as any, and better than some
  183. if ( ( null == get_option( 'wpsc_trackingid_subject' ) ) && ( null == get_option( 'wpsc_trackingid_message' ) ) ) {
  184. update_option( 'wpsc_trackingid_subject', __( 'Product Tracking Email', 'wpsc' ) );
  185. update_option( 'wpsc_trackingid_message', __( "Track & Trace means you may track the progress of your parcel with our online parcel tracker, just login to our website and enter the following Tracking ID to view the status of your order.\n\nTracking ID: %trackid%\n", 'wpsc' ) );
  186. }
  187. return;
  188. }
  189. function wpsc_product_log_rss_feed() {
  190. echo "<link type='application/rss+xml' href='" . get_option( 'siteurl' ) . "/wp-admin/index.php?rss=true&amp;rss_key=key&amp;action=purchase_log&amp;type=rss' title='WP e-Commerce Purchase Log RSS' rel='alternate'/>";
  191. }
  192. function wpsc_admin_include_coupon_js() {
  193. // Variables
  194. $siteurl = get_option( 'siteurl' );
  195. $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
  196. // Coupon CSS
  197. wp_enqueue_style( 'wp-e-commerce-admin_2.7', WPSC_URL . '/wpsc-admin/css/settingspage.css', false, false, 'all' );
  198. wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
  199. // Coupon JS
  200. wp_enqueue_script( 'wp-e-commerce-admin-parameters', $siteurl . '/wp-admin/admin.php?wpsc_admin_dynamic_js=true', false, $version_identifier );
  201. wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
  202. wp_enqueue_script( 'datepicker-ui', WPSC_CORE_JS_URL . '/ui.datepicker.js', array( 'jquery-ui-core' ), $version_identifier );
  203. wp_enqueue_script( 'wp-e-commerce-admin_legacy', WPSC_URL . '/wpsc-admin/js/admin-legacy.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'datepicker-ui' ), $version_identifier );
  204. }
  205. /**
  206. * wpsc_admin_css_and_js function, includes the wpsc_admin CSS and JS
  207. * No parameters, returns nothing
  208. */
  209. function wpsc_admin_include_css_and_js( ) {
  210. $siteurl = get_option( 'siteurl' );
  211. if ( is_ssl ( ) )
  212. $siteurl = str_replace( "http://", "https://", $siteurl );
  213. wp_admin_css( 'dashboard' );
  214. //wp_admin_css( 'media' );
  215. $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
  216. wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
  217. wp_enqueue_script( 'wp-e-commerce-admin-parameters', $siteurl . '/wp-admin/admin.php?wpsc_admin_dynamic_js=true', false, $version_identifier );
  218. wp_enqueue_script( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/js/admin.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), $version_identifier, false );
  219. wp_enqueue_script( 'wp-e-commerce-legacy-ajax', WPSC_URL . '/wpsc-admin/js/ajax.js', false, $version_identifier ); // needs removing
  220. wp_enqueue_script( 'wp-e-commerce-variations', WPSC_URL . '/wpsc-admin/js/variations.js', array( 'jquery' ), $version_identifier );
  221. wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
  222. wp_enqueue_style( 'wp-e-commerce-admin-dynamic', $siteurl . "/wp-admin/admin.php?wpsc_admin_dynamic_css=true", false, $version_identifier, 'all' );
  223. // Prototype breaks dragging and dropping, I need it gone
  224. wp_deregister_script( 'prototype' );
  225. // remove the old javascript and CSS, we want it no more, it smells bad
  226. remove_action( 'admin_head', 'wpsc_admin_css' );
  227. // Localize scripts
  228. wp_localize_script( 'wp-e-commerce-admin', 'wpsc_adminL10n', array(
  229. 'unsaved_changes_detected' => __( 'Unsaved changes have been detected. Click OK to lose these changes and continue.', 'wpsc' ),
  230. 'dragndrop_set' => ( get_option( 'wpsc_sort_by' ) == 'dragndrop' ? 'true' : 'false' ),
  231. 'l10n_print_after' => 'try{convertEntities(wpsc_adminL10n);}catch(e){};'
  232. ) );
  233. }
  234. /**
  235. * wpsc_admin_include_optionspage_css_and_js function, includes the wpsc_admin CSS and JS for the specific options page
  236. * No parameters, returns nothing
  237. */
  238. function wpsc_admin_include_optionspage_css_and_js() {
  239. $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
  240. wp_enqueue_script( 'wp-e-commerce-js-ajax', WPSC_URL . '/wpsc-core/js/ajax.js', false, $version_identifier );
  241. wp_enqueue_script( 'wp-e-commerce-js-ui-tabs', WPSC_URL . '/wpsc-admin/js/jquery-ui.js', false, $version_identifier );
  242. wp_enqueue_script( 'wp-e-commerce-js-dimensions', WPSC_URL . '/wpsc-admin/js/dimensions.js', false, $version_identifier );
  243. wp_enqueue_style( 'wp-e-commerce-admin_2.7', WPSC_URL . '/wpsc-admin/css/settingspage.css', false, false, 'all' );
  244. wp_enqueue_style( 'wp-e-commerce-ui-tabs', WPSC_URL . '/wpsc-admin/css/jquery.ui.tabs.css', false, $version_identifier, 'all' );
  245. }
  246. function wpsc_meta_boxes() {
  247. global $post;
  248. $pagename = 'wpsc-product';
  249. remove_meta_box( 'wpsc-variationdiv', 'wpsc-product', 'core' );
  250. //if a variation page do not show these metaboxes
  251. if ( is_object( $post ) && $post->post_parent == 0 ) {
  252. add_meta_box( 'wpsc_product_variation_forms', __('Variations', 'wpsc'), 'wpsc_product_variation_forms', $pagename, 'normal', 'high' );
  253. add_meta_box( 'wpsc_product_external_link_forms', __('Off Site Product link', 'wpsc'), 'wpsc_product_external_link_forms', $pagename, 'normal', 'high' );
  254. } else if( is_object( $post ) && $post->post_status == "inherit" ) {
  255. remove_meta_box( 'tagsdiv-product_tag', 'wpsc-product', 'core' );
  256. remove_meta_box( 'wpsc_product_external_link_forms', 'wpsc-product', 'core' );
  257. remove_meta_box( 'wpsc_product_categorydiv', 'wpsc-product', 'core' );
  258. }
  259. add_meta_box( 'wpsc_price_control_forms', __('Price Control', 'wpsc'), 'wpsc_price_control_forms', $pagename, 'side', 'low' );
  260. add_meta_box( 'wpsc_stock_control_forms', __('Stock Control', 'wpsc'), 'wpsc_stock_control_forms', $pagename, 'side', 'low' );
  261. add_meta_box( 'wpsc_product_taxes_forms', __('Taxes', 'wpsc'), 'wpsc_product_taxes_forms', $pagename, 'side', 'low' );
  262. add_meta_box( 'wpsc_additional_desc', __('Additional Description', 'wpsc'), 'wpsc_additional_desc', $pagename, 'normal', 'high' );
  263. add_meta_box( 'wpsc_product_download_forms', __('Product Download', 'wpsc'), 'wpsc_product_download_forms', $pagename, 'normal', 'high' );
  264. add_meta_box( 'wpsc_product_image_forms', __('Product Images', 'wpsc'), 'wpsc_product_image_forms', $pagename, 'normal', 'high' );
  265. add_meta_box( 'wpsc_product_shipping_forms', __('Shipping', 'wpsc'), 'wpsc_product_shipping_forms', $pagename, 'normal', 'high' );
  266. add_meta_box( 'wpsc_product_advanced_forms', __('Advanced Settings', 'wpsc'), 'wpsc_product_advanced_forms', $pagename, 'normal', 'high' );
  267. }
  268. add_action( 'admin_footer', 'wpsc_meta_boxes' );
  269. add_action( 'admin_head', 'wpsc_admin_include_css_and_js' );
  270. add_action( 'admin_head', 'wpsc_admin_include_css_and_js_refac' );
  271. add_action( 'admin_enqueue_scripts', 'wpsc_admin_include_css_and_js_refac' );
  272. function wpsc_admin_include_css_and_js_refac( $pagehook ) {
  273. global $post_type, $current_screen;
  274. $siteurl = get_option( 'siteurl' );
  275. if ( is_ssl ( ) )
  276. $siteurl = str_replace( "http://", "https://", $siteurl );
  277. wp_admin_css( 'dashboard' );
  278. if($current_screen->id == 'dashboard_page_wpsc-sales-logs'){
  279. // jQuery
  280. wp_enqueue_script( 'jquery' );
  281. wp_enqueue_script( 'jquery-ui-draggable' );
  282. wp_enqueue_script( 'jquery-ui-droppable' );
  283. wp_enqueue_script( 'jquery-ui-sortable' );
  284. // Metaboxes
  285. wp_enqueue_script( 'common' );
  286. wp_enqueue_script( 'wp-lists' );
  287. wp_enqueue_script( 'postbox' );
  288. }
  289. $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
  290. $pages = array( 'index.php', 'options-general.php', 'edit.php', 'post.php', 'post-new.php' );
  291. if ( ( in_array( $pagehook, $pages ) && $post_type == 'wpsc-product' ) || $current_screen->id == 'edit-wpsc_product_category' || $current_screen->id == 'dashboard_page_wpsc-sales-logs' || $current_screen->id == 'settings_page_wpsc-settings' || $current_screen->id == 'wpsc-product_page_wpsc-edit-coupons' ) {
  292. wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
  293. wp_enqueue_script( 'wp-e-commerce-admin-parameters', $siteurl . '/wp-admin/admin.php?wpsc_admin_dynamic_js=true', false, $version_identifier );
  294. wp_enqueue_script( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/js/admin.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), $version_identifier, false );
  295. wp_enqueue_script( 'wp-e-commerce-legacy-ajax', WPSC_URL . '/wpsc-admin/js/ajax.js', false, $version_identifier ); // needs removing
  296. wp_enqueue_script( 'wp-e-commerce-variations', WPSC_URL . '/wpsc-admin/js/variations.js', array( 'jquery' ), $version_identifier );
  297. wp_enqueue_script( 'inline-edit-post' );
  298. wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
  299. wp_enqueue_style( 'wp-e-commerce-admin-dynamic', $siteurl . "/wp-admin/admin.php?wpsc_admin_dynamic_css=true", false, $version_identifier, 'all' );
  300. // Localize scripts
  301. wp_localize_script( 'wp-e-commerce-admin', 'wpsc_adminL10n', array(
  302. 'unsaved_changes_detected' => __( 'Unsaved changes have been detected. Click OK to lose these changes and continue.', 'wpsc' ),
  303. 'dragndrop_set' => ( get_option( 'wpsc_sort_by' ) == 'dragndrop' ? 'true' : 'false' ),
  304. 'l10n_print_after' => 'try{convertEntities(wpsc_adminL10n);}catch(e){};'
  305. ) );
  306. }
  307. if ( 'dashboard_page_wpsc-upgrades' == $pagehook )
  308. wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
  309. wp_deregister_script( 'prototype' );
  310. // remove the old javascript and CSS, we want it no more, it smells bad
  311. remove_action( 'admin_head', 'wpsc_admin_css' );
  312. }
  313. function wpsc_admin_dynamic_js() {
  314. header( 'Content-Type: text/javascript' );
  315. header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) + 12 ), date( 'Y' ) ) ) . '' );
  316. header( 'Cache-Control: public, must-revalidate, max-age=86400' );
  317. header( 'Pragma: public' );
  318. $siteurl = get_option( 'siteurl' );
  319. $hidden_boxes = get_option( 'wpsc_hidden_box' );
  320. $form_types1 = get_option( 'wpsc_checkout_form_fields' );
  321. $unique_names1 = get_option( 'wpsc_checkout_unique_names' );
  322. $form_types = '';
  323. foreach ( (array)$form_types1 as $form_type ) {
  324. $form_types .= "<option value='" . $form_type . "'>" . $form_type . "</option>";
  325. }
  326. $unique_names = "<option value='-1'>" . __('Select a Unique Name', 'wpsc') . "</option>";
  327. foreach ( (array)$unique_names1 as $unique_name ) {
  328. $unique_names.= "<option value='" . $unique_name . "'>" . $unique_name . "</option>";
  329. }
  330. $hidden_boxes = implode( ',', (array)$hidden_boxes );
  331. echo "var base_url = '" . $siteurl . "';\n\r";
  332. echo "var WPSC_URL = '" . WPSC_URL . "';\n\r";
  333. echo "var WPSC_IMAGE_URL = '" . WPSC_IMAGE_URL . "';\n\r";
  334. echo "var WPSC_DIR_NAME = '" . WPSC_DIR_NAME . "';\n\r";
  335. echo "var WPSC_IMAGE_URL = '" . WPSC_IMAGE_URL . "';\n\r";
  336. // LightBox Configuration start
  337. echo "var fileLoadingImage = '" . WPSC_CORE_IMAGES_URL . "/loading.gif';\n\r";
  338. echo "var fileBottomNavCloseImage = '" . WPSC_CORE_IMAGES_URL . "/closelabel.gif';\n\r";
  339. echo "var fileThickboxLoadingImage = '" . WPSC_CORE_IMAGES_URL . "/loadingAnimation.gif';\n\r";
  340. echo "var resizeSpeed = 9;\n\r";
  341. echo "var borderSize = 10;\n\r";
  342. echo "var hidden_boxes = '" . $hidden_boxes . "';\n\r";
  343. echo "var IS_WP27 = '" . IS_WP27 . "';\n\r";
  344. echo "var TXT_WPSC_DELETE = '" . __( 'Delete', 'wpsc' ) . "';\n\r";
  345. echo "var TXT_WPSC_TEXT = '" . __( 'Text', 'wpsc' ) . "';\n\r";
  346. echo "var TXT_WPSC_EMAIL = '" . __( 'Email', 'wpsc' ) . "';\n\r";
  347. echo "var TXT_WPSC_COUNTRY = '" . __( 'Country', 'wpsc' ) . "';\n\r";
  348. echo "var TXT_WPSC_TEXTAREA = '" . __( 'Textarea', 'wpsc' ) . "';\n\r";
  349. echo "var TXT_WPSC_HEADING = '" . __( 'Heading', 'wpsc' ) . "';\n\r";
  350. echo "var TXT_WPSC_COUPON = '" . __( 'Coupon', 'wpsc' ) . "';\n\r";
  351. echo "var HTML_FORM_FIELD_TYPES =\" " . $form_types . "; \" \n\r";
  352. echo "var HTML_FORM_FIELD_UNIQUE_NAMES = \" " . $unique_names . "; \" \n\r";
  353. echo "var TXT_WPSC_LABEL = '" . __( 'Label', 'wpsc' ) . "';\n\r";
  354. echo "var TXT_WPSC_LABEL_DESC = '" . __( 'Label Description', 'wpsc' ) . "';\n\r";
  355. echo "var TXT_WPSC_ITEM_NUMBER = '" . __( 'Item Number', 'wpsc' ) . "';\n\r";
  356. echo "var TXT_WPSC_LIFE_NUMBER = '" . __( 'Life Number', 'wpsc' ) . "';\n\r";
  357. echo "var TXT_WPSC_PRODUCT_CODE = '" . __( 'Product Code', 'wpsc' ) . "';\n\r";
  358. echo "var TXT_WPSC_PDF = '" . __( 'PDF', 'wpsc' ) . "';\n\r";
  359. echo "var TXT_WPSC_AND_ABOVE = '" . __( ' and above', 'wpsc' ) . "';\n\r";
  360. echo "var TXT_WPSC_IF_PRICE_IS = '" . __( 'If price is ', 'wpsc' ) . "';\n\r";
  361. echo "var TXT_WPSC_IF_WEIGHT_IS = '" . __( 'If weight is ', 'wpsc' ) . "';\n\r";
  362. exit();
  363. }
  364. if ( isset( $_GET['wpsc_admin_dynamic_js'] ) && ( $_GET['wpsc_admin_dynamic_js'] == 'true' ) ) {
  365. add_action( "admin_init", 'wpsc_admin_dynamic_js' );
  366. }
  367. function wpsc_admin_dynamic_css() {
  368. header( 'Content-Type: text/css' );
  369. header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) + 12 ), date( 'Y' ) ) ) . '' );
  370. header( 'Cache-Control: public, must-revalidate, max-age=86400' );
  371. header( 'Pragma: public' );
  372. $flash = 0;
  373. $flash = apply_filters( 'flash_uploader', $flash );
  374. if ( $flash = 1 ) {
  375. ?>
  376. div.flash-image-uploader {
  377. display: block;
  378. }
  379. div.browser-image-uploader {
  380. display: none;
  381. }
  382. <?php
  383. } else {
  384. ?>
  385. div.flash-image-uploader {
  386. display: none;
  387. }
  388. div.browser-image-uploader {
  389. display: block;
  390. }
  391. <?php
  392. }
  393. exit();
  394. }
  395. if ( isset( $_GET['wpsc_admin_dynamic_css'] ) && ( $_GET['wpsc_admin_dynamic_css'] == 'true' ) ) {
  396. add_action( "admin_init", 'wpsc_admin_dynamic_css' );
  397. }
  398. add_action( 'admin_menu', 'wpsc_admin_pages' );
  399. function wpsc_admin_latest_activity() {
  400. global $wpdb;
  401. $totalOrders = $wpdb->get_var( "SELECT COUNT(*) FROM `" . WPSC_TABLE_PURCHASE_LOGS . "`" );
  402. /*
  403. * This is the right hand side for the past 30 days revenue on the wp dashboard
  404. */
  405. echo "<div id='leftDashboard'>";
  406. echo "<strong class='dashboardHeading'>" . __( 'Current Month', 'wpsc' ) . "</strong><br />";
  407. echo "<p class='dashboardWidgetSpecial'>";
  408. // calculates total amount of orders for the month
  409. $year = date( "Y" );
  410. $month = date( "m" );
  411. $start_timestamp = mktime( 0, 0, 0, $month, 1, $year );
  412. $end_timestamp = mktime( 0, 0, 0, ( $month + 1 ), 0, $year );
  413. $sql = "SELECT COUNT(*) FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '$start_timestamp' AND '$end_timestamp' AND `processed` IN (2,3,4) ORDER BY `date` DESC";
  414. $currentMonthOrders = $wpdb->get_var( $sql );
  415. //calculates amount of money made for the month
  416. $currentMonthsSales = wpsc_currency_display( admin_display_total_price( $start_timestamp, $end_timestamp ) );
  417. echo $currentMonthsSales;
  418. echo "<span class='dashboardWidget'>" . _x( 'Sales', 'the total value of sales in dashboard widget', 'wpsc' ) . "</span>";
  419. echo "</p>";
  420. echo "<p class='dashboardWidgetSpecial'>";
  421. echo "<span class='pricedisplay'>";
  422. echo $currentMonthOrders;
  423. echo "</span>";
  424. echo "<span class='dashboardWidget'>" . _n( 'Order', 'Orders', $currentMonthOrders, 'wpsc' ) . "</span>";
  425. echo "</p>";
  426. echo "<p class='dashboardWidgetSpecial'>";
  427. //calculates average sales amount per order for the month
  428. if ( $currentMonthOrders > 0 ) {
  429. $monthsAverage = ( (int)admin_display_total_price( $start_timestamp, $end_timestamp ) / (int)$currentMonthOrders );
  430. echo wpsc_currency_display( $monthsAverage );
  431. }
  432. //echo "</span>";
  433. echo "<span class='dashboardWidget'>" . __( 'Avg Order', 'wpsc' ) . "</span>";
  434. echo "</p>";
  435. echo "</div>";
  436. /*
  437. * This is the left side for the total life time revenue on the wp dashboard
  438. */
  439. echo "<div id='rightDashboard' >";
  440. echo "<strong class='dashboardHeading'>" . __( 'Total Income', 'wpsc' ) . "</strong><br />";
  441. echo "<p class='dashboardWidgetSpecial'>";
  442. echo wpsc_currency_display( admin_display_total_price() );
  443. echo "<span class='dashboardWidget'>" . _x( 'Sales', 'the total value of sales in dashboard widget', 'wpsc' ) . "</span>";
  444. echo "</p>";
  445. echo "<p class='dashboardWidgetSpecial'>";
  446. echo "<span class='pricedisplay'>";
  447. echo $totalOrders;
  448. echo "</span>";
  449. echo "<span class='dashboardWidget'>" . _n( 'Order', 'Orders', $totalOrders, 'wpsc' ) . "</span>";
  450. echo "</p>";
  451. echo "<p class='dashboardWidgetSpecial'>";
  452. //calculates average sales amount per order for the month
  453. if ( ( admin_display_total_price() > 0 ) && ( $totalOrders > 0 ) ) {
  454. $totalAverage = ( (int)admin_display_total_price() / (int)$totalOrders );
  455. } else {
  456. $totalAverage = 0;
  457. }
  458. echo wpsc_currency_display( $totalAverage );
  459. //echo "</span>";
  460. echo "<span class='dashboardWidget'>" . __( 'Avg Order', 'wpsc' ) . "</span>";
  461. echo "</p>";
  462. echo "</div>";
  463. echo "<div style='clear:both'></div>";
  464. }
  465. add_action( 'wpsc_admin_pre_activity', 'wpsc_admin_latest_activity' );
  466. /*
  467. * Dashboard Widget Setup
  468. * Adds the dashboard widgets if the user is an admin
  469. * Since 3.6
  470. */
  471. function wpsc_dashboard_widget_setup() {
  472. if ( is_admin() && current_user_can( 'manage_options' ) ) {
  473. $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
  474. // Enqueue the styles and scripts necessary
  475. wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
  476. wp_enqueue_script( 'datepicker-ui', WPSC_URL . "/wpsc-core/js/ui.datepicker.js", array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), $version_identifier );
  477. // Add the dashboard widgets
  478. wp_add_dashboard_widget( 'wpsc_dashboard_news', __( 'Getshopped News' , 'wpsc' ), 'wpsc_dashboard_news' );
  479. wp_add_dashboard_widget( 'wpsc_dashboard_widget', __( 'Sales Summary', 'wpsc' ), 'wpsc_dashboard_widget' );
  480. wp_add_dashboard_widget( 'wpsc_quarterly_dashboard_widget', __( 'Sales by Quarter', 'wpsc' ), 'wpsc_quarterly_dashboard_widget' );
  481. wp_add_dashboard_widget( 'wpsc_dashboard_4months_widget', __( 'Sales by Month', 'wpsc' ), 'wpsc_dashboard_4months_widget' );
  482. // Sort the Dashboard widgets so ours it at the top
  483. global $wp_meta_boxes;
  484. $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
  485. // Backup and delete our new dashbaord widget from the end of the array
  486. $wpsc_widget_backup = array( 'wpsc_dashboard_news' => $normal_dashboard['wpsc_dashboard_news'] );
  487. $wpsc_widget_backup += array( 'wpsc_dashboard_widget' => $normal_dashboard['wpsc_dashboard_widget'] );
  488. $wpsc_widget_backup += array( 'wpsc_quarterly_dashboard_widget' => $normal_dashboard['wpsc_quarterly_dashboard_widget'] );
  489. $wpsc_widget_backup += array( 'wpsc_dashboard_4months_widget' => $normal_dashboard['wpsc_dashboard_4months_widget'] );
  490. unset( $normal_dashboard['wpsc_dashboard_news'] );
  491. unset( $normal_dashboard['wpsc_dashboard_widget'] );
  492. unset( $normal_dashboard['wpsc_quarterly_dashboard_widget'] );
  493. unset( $normal_dashboard['wpsc_dashboard_4months_widget'] );
  494. // Merge the two arrays together so our widget is at the beginning
  495. $sorted_dashboard = array_merge( $wpsc_widget_backup, $normal_dashboard );
  496. // Save the sorted array back into the original metaboxes
  497. $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
  498. }
  499. }
  500. /*
  501. * Registers the widgets on the WordPress Dashboard
  502. */
  503. add_action( 'wp_dashboard_setup', 'wpsc_dashboard_widget_setup' );
  504. function wpsc_dashboard_news() {
  505. $rss = fetch_feed( 'http://getshopped.org/category/wp-e-commerce-plugin/' );
  506. $args = array( 'show_author' => 1, 'show_date' => 1, 'show_summary' => 1, 'items'=>3 );
  507. wp_widget_rss_output( $rss, $args );
  508. }
  509. function wpsc_get_quarterly_summary() {
  510. (int)$firstquarter = get_option( 'wpsc_first_quart' );
  511. (int)$secondquarter = get_option( 'wpsc_second_quart' );
  512. (int)$thirdquarter = get_option( 'wpsc_third_quart' );
  513. (int)$fourthquarter = get_option( 'wpsc_fourth_quart' );
  514. (int)$finalquarter = get_option( 'wpsc_final_quart' );
  515. $results[] = admin_display_total_price( $thirdquarter + 1, $fourthquarter );
  516. $results[] = admin_display_total_price( $secondquarter + 1, $thirdquarter );
  517. $results[] = admin_display_total_price( $firstquarter + 1, $secondquarter );
  518. $results[] = admin_display_total_price( $finalquarter, $firstquarter );
  519. return $results;
  520. }
  521. function wpsc_quarterly_dashboard_widget() {
  522. if ( get_option( 'wpsc_business_year_start' ) == false ) {
  523. ?>
  524. <form action='' method='post'>
  525. <label for='date_start'><?php _e( 'Financial Year End' , 'wpsc' ); ?>: </label>
  526. <input id='date_start' type='text' class='pickdate' size='11' value='<?php echo get_option( 'wpsc_last_date' ); ?>' name='add_start' />
  527. <!--<select name='add_start[day]'>
  528. <?php
  529. for ( $i = 1; $i <= 31; ++$i ) {
  530. $selected = '';
  531. if ( $i == date( "d" ) ) {
  532. $selected = "selected='selected'";
  533. }
  534. echo "<option $selected value='$i'>$i</option>";
  535. }
  536. ?>
  537. </select>
  538. <select name='add_start[month]'>
  539. <?php
  540. for ( $i = 1; $i <= 12; ++$i ) {
  541. $selected = '';
  542. if ( $i == (int)date( "m" ) ) {
  543. $selected = "selected='selected'";
  544. }
  545. echo "<option $selected value='$i'>" . date( "M", mktime( 0, 0, 0, $i, 1, date( "Y" ) ) ) . "</option>";
  546. }
  547. ?>
  548. </select>
  549. <select name='add_start[year]'>
  550. <?php
  551. for ( $i = date( "Y" ); $i <= ( date( "Y" ) + 12 ); ++$i ) {
  552. $selected = '';
  553. if ( $i == date( "Y" ) ) {
  554. $selected = "selected='true'";
  555. }
  556. echo "<option $selected value='$i'>" . $i . "</option>";
  557. }
  558. ?>
  559. </select>-->
  560. <input type='hidden' name='wpsc_admin_action' value='wpsc_quarterly' />
  561. <input type='submit' class='button primary' value='Submit' name='wpsc_submit' />
  562. </form>
  563. <?php
  564. if ( get_option( 'wpsc_first_quart' ) != '' ) {
  565. $firstquarter = get_option( 'wpsc_first_quart' );
  566. $secondquarter = get_option( 'wpsc_second_quart' );
  567. $thirdquarter = get_option( 'wpsc_third_quart' );
  568. $fourthquarter = get_option( 'wpsc_fourth_quart' );
  569. $finalquarter = get_option( 'wpsc_final_quart' );
  570. $revenue = wpsc_get_quarterly_summary();
  571. $currsymbol = wpsc_get_currency_symbol();
  572. foreach ( $revenue as $rev ) {
  573. if ( $rev == '' ) {
  574. $totals[] = '0.00';
  575. } else {
  576. $totals[] = $rev;
  577. }
  578. }
  579. ?>
  580. <div id='box'>
  581. <p class='atglance'>
  582. <span class='wpsc_quart_left'><?php _e( 'At a Glance' , 'wpsc' ); ?></span>
  583. <span class='wpsc_quart_right'><?php _e( 'Revenue' , 'wpsc' ); ?></span>
  584. </p>
  585. <div style='clear:both'></div>
  586. <p class='quarterly'>
  587. <span class='wpsc_quart_left'><strong>01</strong>&nbsp; (<?php echo date( 'M Y', $thirdquarter ) . ' - ' . date( 'M Y', $fourthquarter ); ?>)</span>
  588. <span class='wpsc_quart_right'><?php echo $currsymbol . ' ' . $totals[0]; ?></span></p>
  589. <p class='quarterly'>
  590. <span class='wpsc_quart_left'><strong>02</strong>&nbsp; (<?php echo date( 'M Y', $secondquarter ) . ' - ' . date( 'M Y', $thirdquarter ); ?>)</span>
  591. <span class='wpsc_quart_right'><?php echo $currsymbol . ' ' . $totals[1]; ?></span></p>
  592. <p class='quarterly'>
  593. <span class='wpsc_quart_left'><strong>03</strong>&nbsp; (<?php echo date( 'M Y', $firstquarter ) . ' - ' . date( 'M Y', $secondquarter ); ?>)</span>
  594. <span class='wpsc_quart_right'><?php echo $currsymbol . ' ' . $totals[2]; ?></span></p>
  595. <p class='quarterly'>
  596. <span class='wpsc_quart_left'><strong>04</strong>&nbsp; (<?php echo date( 'M Y', $finalquarter ) . ' - ' . date( 'M Y', $firstquarter ); ?>)</span>
  597. <span class='wpsc_quart_right'><?php echo $currsymbol . ' ' . $totals[3]; ?></span>
  598. </p>
  599. <div style='clear:both'></div>
  600. </div>
  601. <?php
  602. }
  603. }
  604. }
  605. function wpsc_dashboard_widget() {
  606. if ( current_user_can( 'manage_options' ) ) {
  607. do_action( 'wpsc_admin_pre_activity' );
  608. do_action( 'wpsc_admin_post_activity' );
  609. }
  610. }
  611. /*
  612. * END - Dashboard Widget for 2.7
  613. */
  614. /*
  615. * Dashboard Widget Last Four Month Sales.
  616. */
  617. function wpsc_dashboard_4months_widget() {
  618. global $wpdb;
  619. $this_year = date( "Y" ); //get current year and month
  620. $this_month = date( "n" );
  621. $months[] = mktime( 0, 0, 0, $this_month - 3, 1, $this_year ); //generate unix time stamps fo 4 last months
  622. $months[] = mktime( 0, 0, 0, $this_month - 2, 1, $this_year );
  623. $months[] = mktime( 0, 0, 0, $this_month - 1, 1, $this_year );
  624. $months[] = mktime( 0, 0, 0, $this_month, 1, $this_year );
  625. $products = $wpdb->get_results( "SELECT `cart`.`prodid`,
  626. `cart`.`name`
  627. FROM `" . WPSC_TABLE_CART_CONTENTS . "` AS `cart`
  628. INNER JOIN `" . WPSC_TABLE_PURCHASE_LOGS . "` AS `logs`
  629. ON `cart`.`purchaseid` = `logs`.`id`
  630. WHERE `logs`.`processed` >= 2
  631. AND `logs`.`date` >= " . $months[0] . "
  632. GROUP BY `cart`.`prodid`
  633. ORDER BY SUM(`cart`.`price` * `cart`.`quantity`) DESC
  634. LIMIT 4", ARRAY_A ); //get 4 products with top income in 4 last months.
  635. $timeranges[0]["start"] = mktime( 0, 0, 0, $this_month - 3, 1, $this_year ); //make array of time ranges
  636. $timeranges[0]["end"] = mktime( 0, 0, 0, $this_month - 2, 1, $this_year );
  637. $timeranges[1]["start"] = mktime( 0, 0, 0, $this_month - 2, 1, $this_year );
  638. $timeranges[1]["end"] = mktime( 0, 0, 0, $this_month - 1, 1, $this_year );
  639. $timeranges[2]["start"] = mktime( 0, 0, 0, $this_month - 1, 1, $this_year );
  640. $timeranges[2]["end"] = mktime( 0, 0, 0, $this_month, 1, $this_year );
  641. $timeranges[3]["start"] = mktime( 0, 0, 0, $this_month, 1, $this_year );
  642. $timeranges[3]["end"] = mktime();
  643. $prod_data = array( );
  644. foreach ( (array)$products as $product ) { //run through products and get each product income amounts and name
  645. $sale_totals = array( );
  646. foreach ( $timeranges as $timerange ) { //run through time ranges of product, and get its income over each time range
  647. $prodsql = "SELECT
  648. SUM(`cart`.`price` * `cart`.`quantity`) AS sum
  649. FROM `" . WPSC_TABLE_CART_CONTENTS . "` AS `cart`
  650. INNER JOIN `" . WPSC_TABLE_PURCHASE_LOGS . "` AS `logs`
  651. ON `cart`.`purchaseid` = `logs`.`id`
  652. WHERE `logs`.`processed` >= 2
  653. AND `logs`.`date` >= " . $timerange["start"] . "
  654. AND `logs`.`date` < " . $timerange["end"] . "
  655. AND `cart`.`prodid` = " . $product['prodid'] . "
  656. GROUP BY `cart`.`prodid`"; //get the amount of income that current product has generaterd over current time range
  657. $sale_totals[] = $wpdb->get_var( $prodsql ); //push amount to array
  658. }
  659. $prod_data[] = array(
  660. 'sale_totals' => $sale_totals,
  661. 'product_name' => $product['name'] ); //result: array of 2: $prod_data[0] = array(income)
  662. $sums = array( ); //reset array //$prod_data[1] = product name
  663. }
  664. $tablerow = 1;
  665. ob_start();
  666. ?>
  667. <div style="padding-bottom:15px; "><?php _e('Last four months of sales on a per product basis:', 'wpsc'); ?></div>
  668. <table style="width:100%" border="0" cellspacing="0">
  669. <tr style="font-style:italic; color:#666;" height="20">
  670. <td colspan="2" style=" font-family:\'Times New Roman\', Times, serif; font-size:15px; border-bottom:solid 1px #000;"><?php _e('At a Glance', 'wpsc'); ?></td>
  671. <?php foreach ( $months as $mnth ): ?>
  672. <td align="center" style=" font-family:\'Times New Roman\'; font-size:15px; border-bottom:solid 1px #000;"><?php echo date( "M", $mnth ); ?></td>
  673. <?php endforeach; ?>
  674. </tr>
  675. <?php foreach ( (array)$prod_data as $sales_data ): ?>
  676. <tr height="20">
  677. <td width="20" style="font-weight:bold; color:#008080; border-bottom:solid 1px #000;"><?php echo $tablerow; ?></td>
  678. <td style="border-bottom:solid 1px #000;width:60px"><?php echo $sales_data['product_name']; ?></td>
  679. <?php foreach ( $sales_data['sale_totals'] as $amount ): ?>
  680. <td align="center" style="border-bottom:solid 1px #000;"><?php echo wpsc_currency_display($amount); ?></td>
  681. <?php endforeach; ?>
  682. </tr>
  683. <?php
  684. $tablerow++;
  685. endforeach; ?>
  686. </table>
  687. <?php
  688. ob_end_flush();
  689. }
  690. //Modification to allow for multiple column layout
  691. function wpec_two_columns( $columns, $screen ) {
  692. if ( $screen == 'toplevel_page_wpsc-edit-products' )
  693. $columns['toplevel_page_wpsc-edit-products'] = 2;
  694. return $columns;
  695. }
  696. add_filter( 'screen_layout_columns', 'wpec_two_columns', 10, 2 );
  697. function wpsc_fav_action( $actions ) {
  698. $actions['post-new.php?post_type=wpsc-product'] = array( 'New Product', 'manage_options' );
  699. return $actions;
  700. }
  701. add_filter( 'favorite_actions', 'wpsc_fav_action' );
  702. function wpsc_print_admin_scripts() {
  703. wp_enqueue_script( 'wp-e-commerce-dynamic', get_bloginfo( 'url' ) . "/index.php?wpsc_user_dynamic_js=true" );
  704. }
  705. /**
  706. * wpsc_update_permalinks update the product pages permalinks when WordPress permalinks are changed
  707. *
  708. * @public
  709. *
  710. * @3.8
  711. * @returns nothing
  712. */
  713. function wpsc_update_permalinks( $return = '' ) {
  714. wpsc_update_page_urls( true );
  715. return $return;
  716. }
  717. /**
  718. * wpsc_ajax_ie_save save changes made using inline edit
  719. *
  720. * @public
  721. *
  722. * @3.8
  723. * @returns nothing
  724. */
  725. function wpsc_ajax_ie_save() {
  726. $product_post_type = get_post_type_object( 'wpsc-product' );
  727. if ( !current_user_can( $product_post_type->cap->edit_posts ) ) {
  728. echo '({"error":"' . __( 'Error: you don\'t have required permissions to edit this product', 'wpsc' ) . '", "id": "'. $_POST['id'] .'"})';
  729. die();
  730. }
  731. $product = array(
  732. 'ID' => $_POST['id'],
  733. 'post_title' => $_POST['title']
  734. );
  735. $id = wp_update_post( $product );
  736. if ( $id > 0 ) {
  737. //need parent meta to know which weight unit we are using
  738. $post = get_post( $id );
  739. $parent_meta = get_product_meta($post->post_parent, 'product_metadata', true );
  740. $product_meta = get_product_meta( $product['ID'], 'product_metadata', true );
  741. if ( is_numeric( $_POST['weight'] ) || empty( $_POST['weight'] ) ){
  742. $product_meta['weight'] = wpsc_convert_weight($_POST['weight'], $parent_meta['weight_unit'], 'pound', true);
  743. $product_meta['weight_unit'] = $parent_meta['weight_unit'];
  744. }
  745. update_product_meta( $product['ID'], 'product_metadata', $product_meta );
  746. update_product_meta( $product['ID'], 'price', (float)$_POST['price'] );
  747. update_product_meta( $product['ID'], 'special_price', (float)$_POST['special_price'] );
  748. update_product_meta( $product['ID'], 'sku', $_POST['sku'] );
  749. if ( !is_numeric($_POST['stock']) )
  750. update_product_meta( $product['ID'], 'stock', '' );
  751. else
  752. update_product_meta( $product['ID'], 'stock', absint( $_POST['stock'] ) );
  753. $post = get_post( $id );
  754. $meta = get_product_meta( $id, 'product_metadata', true );
  755. $price = get_product_meta( $id, 'price', true );
  756. $special_price = get_product_meta( $id, 'special_price', true );
  757. $sku = get_product_meta( $id, 'sku', true );
  758. $sku = ( $sku )?$sku:__('N/A', 'wpsc');
  759. $stock = get_product_meta( $id, 'stock', true );
  760. $stock = ( $stock === '' )?__('N/A', 'wpsc'):$stock;
  761. $results = array( 'id' => $id, 'title' => $post->post_title, 'weight' => wpsc_convert_weight($meta['weight'], 'pound', $parent_meta['weight_unit']), 'price' => wpsc_currency_display( $price ), 'special_price' => wpsc_currency_display( $special_price ), 'sku' => $sku, 'stock' => $stock );
  762. echo '(' . json_encode( $results ) . ')';
  763. die();
  764. } else {
  765. echo '({"error":"' . __( 'Error updating product', 'wpsc' ) . '", "id": "'. $_POST['id'] .'"})';
  766. }
  767. die();
  768. }
  769. function wpsc_add_meta_boxes(){
  770. add_meta_box( 'dashboard_right_now', __('Current Month', 'wpsc'), 'wpsc_right_now', 'dashboard_page_wpsc-sales-logs', 'top' );
  771. }
  772. function wpsc_check_permalink_notice(){
  773. ?>
  774. <div id="notice" class="error fade"><p>
  775. <?php printf( __( 'Due to a problem in WordPress Permalinks and Custom Post Types, WP e-Commerce encourages you to refresh your permalinks a second time. (for a more geeky explanation visit <a href="%s">trac</a>)' , 'wpsc' ), 'http://core.trac.wordpress.org/ticket/16736' ); ?>
  776. </p></div>
  777. <?php
  778. }
  779. add_action( 'permalink_structure_changed' , 'wpsc_check_permalink_notice' );
  780. add_action( 'permalink_structure_changed' , 'wpsc_update_permalinks' );
  781. /* add_action( 'get_sample_permalink_html' , 'wpsc_update_permalinks' ); // this just seems unnecessary and produces PHP notices */
  782. add_action( 'wp_ajax_category_sort_order', 'wpsc_ajax_set_category_order' );
  783. add_action( 'wp_ajax_wpsc_ie_save', 'wpsc_ajax_ie_save' );
  784. add_action('in_admin_header', 'wpsc_add_meta_boxes');
  785. ?>