/wpsc-admin/display-sales-logs.php

  1. <?php 
  2. /** 
  3. * WP eCommerce edit and view sales page functions 
  4. * 
  5. * These are the main WPSC sales page functions 
  6. * 
  7. * @package wp-e-commerce 
  8. * @since 3.8.8 
  9. */ 
  10.  
  11. class WPSC_Purchase_Log_Page { 
  12. private $list_table; 
  13. private $output; 
  14. public $log_id = 0; 
  15.  
  16. public function __construct() { 
  17. $controller = 'default'; 
  18. $controller_method = 'controller_default'; 
  19.  
  20. // If individual purchase log, setup ID and action links. 
  21. if ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) { 
  22. $this->log_id = (int) $_REQUEST['id']; 
  23.  
  24. if ( isset( $_REQUEST['c'] ) && method_exists( $this, 'controller_' . $_REQUEST['c'] ) ) { 
  25. $controller = $_REQUEST['c']; 
  26. $controller_method = 'controller_' . $controller; 
  27. } elseif ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) { 
  28. $controller = 'item_details'; 
  29. $controller_method = 'controller_item_details'; 
  30.  
  31. $this->$controller_method(); 
  32.  
  33. private function needs_update() { 
  34. global $wpdb; 
  35.  
  36. if ( get_option( '_wpsc_purchlogs_3.8_updated' ) ) 
  37. return false; 
  38.  
  39. $c = $wpdb->get_var( "SELECT COUNT(*) FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE plugin_version IN ('3.6', '3.7')" ); 
  40. if ( $c > 0 ) 
  41. return true; 
  42.  
  43. update_option( '_wpsc_purchlogs_3.8_updated', true ); 
  44. return false; 
  45.  
  46. public function controller_upgrade_purchase_logs_3_7() { 
  47. add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_upgrade_purchase_logs_3_7' ) ); 
  48.  
  49. private function purchase_logs_fix_options( $id ) { 
  50. ?> 
  51. <select name='<?php echo $id; ?>'> 
  52. <option value='-1'><?php echo esc_html_x( 'Select an Option', 'Dropdown default when called in uniquename dropdown', 'wpsc' ); ?></option> 
  53. <option value='billingfirstname'><?php esc_html_e( 'Billing First Name', 'wpsc' ); ?></option> 
  54. <option value='billinglastname'><?php esc_html_e( 'Billing Last Name', 'wpsc' ); ?></option> 
  55. <option value='billingaddress'><?php esc_html_e( 'Billing Address', 'wpsc' ); ?></option> 
  56. <option value='billingcity'><?php esc_html_e( 'Billing City', 'wpsc' ); ?></option> 
  57. <option value='billingstate'><?php esc_html_e( 'Billing State', 'wpsc' ); ?></option> 
  58. <option value='billingcountry'><?php esc_html_e( 'Billing Country', 'wpsc' ); ?></option> 
  59. <option value='billingemail'><?php esc_html_e( 'Billing Email', 'wpsc' ); ?></option> 
  60. <option value='billingphone'><?php esc_html_e( 'Billing Phone', 'wpsc' ); ?></option> 
  61. <option value='billingpostcode'><?php esc_html_e( 'Billing Post Code', 'wpsc' ); ?></option> 
  62. <option value='shippingfirstname'><?php esc_html_e( 'Shipping First Name', 'wpsc' ); ?></option> 
  63. <option value='shippinglastname'><?php esc_html_e( 'Shipping Last Name', 'wpsc' ); ?></option> 
  64. <option value='shippingaddress'><?php esc_html_e( 'Shipping Address', 'wpsc' ); ?></option> 
  65. <option value='shippingcity'><?php esc_html_e( 'Shipping City', 'wpsc' ); ?></option> 
  66. <option value='shippingstate'><?php esc_html_e( 'Shipping State', 'wpsc' ); ?></option> 
  67. <option value='shippingcountry'><?php esc_html_e( 'Shipping Country', 'wpsc' ); ?></option> 
  68. <option value='shippingpostcode'><?php esc_html_e( 'Shipping Post Code', 'wpsc' ); ?></option> 
  69. </select> 
  70. <?php 
  71.  
  72. public function display_upgrade_purchase_logs_3_7() { 
  73. global $wpdb; 
  74. $numChanged = 0; 
  75. $numQueries = 0; 
  76. $purchlog = "SELECT DISTINCT id FROM `".WPSC_TABLE_PURCHASE_LOGS."` LIMIT 1"; 
  77. $id = $wpdb->get_var($purchlog); 
  78. $usersql = "SELECT DISTINCT `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.value, `".WPSC_TABLE_CHECKOUT_FORMS."`.* FROM `".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN `".WPSC_TABLE_SUBMITTED_FORM_DATA."` ON `".WPSC_TABLE_CHECKOUT_FORMS."`.id = `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.`form_id` WHERE `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.log_id=".$id." ORDER BY `".WPSC_TABLE_CHECKOUT_FORMS."`.`checkout_order`" ; 
  79. $formfields = $wpdb->get_results($usersql); 
  80.  
  81. if(count($formfields) < 1) { 
  82. $usersql = "SELECT DISTINCT `".WPSC_TABLE_CHECKOUT_FORMS."`.* FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `type` != 'heading'"; 
  83. $formfields = $wpdb->get_results($usersql); 
  84.  
  85. if(isset($_POST)) { 
  86. foreach($_POST as $key=>$value) { 
  87. if($value != '-1') { 
  88. $complete = $wpdb->update( 
  89. WPSC_TABLE_CHECKOUT_FORMS,  
  90. array( 
  91. 'unique_name' => $value 
  92. ),  
  93. array( 
  94. 'id' => $key 
  95. ),  
  96. '%s',  
  97. '%d' 
  98. ); 
  99. $numChanged++; 
  100. $numQueries ++; 
  101.  
  102. $sql = "UPDATE `".WPSC_TABLE_CHECKOUT_FORMS."` SET `unique_name`='delivertoafriend' WHERE `name` = '2. Shipping details'"; 
  103. $wpdb->query($sql); 
  104.  
  105. add_option('wpsc_purchaselogs_fixed', true); 
  106.  
  107. include( 'includes/purchase-logs-page/upgrade.php' ); 
  108.  
  109. public function display_upgrade_purchase_logs_3_8() { 
  110. ?> 
  111. <div class="wrap"> 
  112. <h2><?php echo esc_html( __('Sales', 'wpsc') ); ?> </h2> 
  113. <div class="updated"> 
  114. <p><?php printf( __( 'Your purchase logs have been updated! <a href="%s">Click here</a> to return.' , 'wpsc' ), esc_url( remove_query_arg( 'c' ) ) ); ?></p> 
  115. </div> 
  116. </div> 
  117. <?php 
  118.  
  119. public function controller_upgrade_purchase_logs_3_8() { 
  120. if ( $this->needs_update() ) 
  121. wpsc_update_purchase_logs(); 
  122.  
  123. add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_upgrade_purchase_logs_3_8' ) ); 
  124.  
  125. function purchase_logs_pagination() { 
  126. global $wpdb, $purchlogitem; 
  127. ?> 
  128. <span class='tablenav'><span class='tablenav-pages'><span class='pagination-links'> 
  129. <?php 
  130. $href = "#"; 
  131. $disabled = "disabled"; 
  132. if ( $this->log_id > 1 ) { 
  133. $href = $this->get_purchase_log_url( ( $this->log_id - 1 ) ); 
  134. $disabled = ''; 
  135. ?> 
  136. <a href='<?php esc_attr_e( $href ); ?>' class='prev-page <?php echo $disabled; ?>'>‹ <?php _e( 'Previous', 'wpsc' ); ?></a> 
  137. <?php 
  138.  
  139. $max_purchase_id = wpsc_max_purchase_id(); 
  140. $href = "#"; 
  141. $disabled = "disabled"; 
  142. if ( $max_purchase_id > $this->log_id ) { 
  143. $href = $this->get_purchase_log_url( ( $this->log_id + 1 ) ); 
  144. $disabled = ''; 
  145. ?> 
  146. <a href='<?php esc_attr_e( $href ); ?>' class='next-page <?php echo $disabled; ?>'><?php _e( 'Next', 'wpsc' ); ?> ›</a> 
  147.  
  148. </span></span></span> 
  149. <?php 
  150.  
  151. function purchase_logs_checkout_fields() { 
  152. global $purchlogitem; 
  153.  
  154. if ( ! empty( $purchlogitem->additional_fields ) ) { 
  155. ?> 
  156. <div class="metabox-holder"> 
  157. <div id="custom_checkout_fields" class="postbox"> 
  158. <h3 class='hndle'><?php esc_html_e( 'Additional Checkout Fields' , 'wpsc' ); ?></h3> 
  159. <div class='inside'> 
  160. <?php 
  161. foreach( (array) $purchlogitem->additional_fields as $value ) { 
  162. $value['value'] = maybe_unserialize ( $value['value'] ); 
  163. if ( is_array( $value['value'] ) ) { 
  164. ?> 
  165. <p><strong><?php echo $value['name']; ?> :</strong> <?php echo implode( stripslashes( $value['value'] ), ', ' ); ?></p> 
  166. <?php 
  167. } else { 
  168. $thevalue = esc_html( stripslashes( $value['value'] )); 
  169. if ( empty( $thevalue ) ) { 
  170. $thevalue = __( '<em>blank</em>', 'wpsc' ); 
  171. ?> 
  172. <p><strong><?php echo $value['name']; ?> :</strong> <?php echo $thevalue; ?></p> 
  173. <?php 
  174. ?> 
  175. </div> 
  176. </div> 
  177. </div> 
  178. <?php 
  179.  
  180. private function purchase_log_custom_fields() { 
  181. if( wpsc_purchlogs_has_customfields() ) {?> 
  182. <div class='metabox-holder'> 
  183. <div id='purchlogs_customfields' class='postbox'> 
  184. <h3 class='hndle'><?php esc_html_e( 'Users Custom Fields' , 'wpsc' ); ?></h3> 
  185. <div class='inside'> 
  186. <?php $messages = wpsc_purchlogs_custommessages(); ?> 
  187. <?php $files = wpsc_purchlogs_customfiles(); ?> 
  188. <?php if(count($files) > 0) { ?> 
  189. <h4><?php esc_html_e( 'Cart Items with Custom Files' , 'wpsc' ); ?>:</h4> 
  190. <?php 
  191. foreach($files as $file) { 
  192. echo $file; 
  193. }?> 
  194. <?php if(count($messages) > 0) { ?> 
  195. <h4><?php esc_html_e( 'Cart Items with Custom Messages' , 'wpsc' ); ?>:</h4> 
  196. <?php 
  197. foreach($messages as $message) { 
  198. echo esc_html( $message['title'] ) . ':<br />' . nl2br( esc_html( $message['message'] ) ); 
  199. } ?> 
  200. </div> 
  201. </div> 
  202. </div> 
  203. <?php 
  204.  
  205. private function purchase_log_cart_items() { 
  206. while( wpsc_have_purchaselog_details() ) : wpsc_the_purchaselog_item(); ?> 
  207. <tr> 
  208. <td><?php echo wpsc_purchaselog_details_name(); ?></td> <!-- NAME! --> 
  209. <td><?php echo wpsc_purchaselog_details_SKU(); ?></td> <!-- SKU! --> 
  210. <td><?php echo wpsc_purchaselog_details_quantity(); ?></td> <!-- QUANTITY! --> 
  211. <td> 
  212. <?php 
  213. echo wpsc_currency_display( wpsc_purchaselog_details_price() ); 
  214. do_action( 'wpsc_additional_sales_amount_info', wpsc_purchaselog_details_id() ); 
  215. ?> 
  216. </td> <!-- PRICE! --> 
  217. <td><?php echo wpsc_currency_display( wpsc_purchaselog_details_shipping() ); ?></td> <!-- SHIPPING! --> 
  218. <?php if( wpec_display_product_tax() ): ?> 
  219. <td><?php echo wpsc_currency_display( wpsc_purchaselog_details_tax() ); ?></td> <!-- TAX! --> 
  220. <?php endif; ?> 
  221. <!-- <td><?php echo wpsc_currency_display( wpsc_purchaselog_details_discount() ); ?></td> --> <!-- DISCOUNT! --> 
  222. <td class="amount"><?php echo wpsc_currency_display( wpsc_purchaselog_details_total() ); ?></td> <!-- TOTAL! --> 
  223. </tr> 
  224. <?php 
  225. do_action( 'wpsc_additional_sales_item_info', wpsc_purchaselog_details_id() ); 
  226. endwhile; 
  227.  
  228. public function controller_item_details() { 
  229.  
  230. if ( ! isset( $_REQUEST['id'] ) || ( isset( $_REQUEST['id'] ) && ! is_numeric( $_REQUEST['id'] ) ) ) { 
  231. wp_die( __( 'Invalid sales log ID', 'wpsc' ) ); 
  232.  
  233. global $purchlogitem; 
  234.  
  235. // TODO: seriously get rid of all these badly coded purchaselogs.class.php functions in 4.0 
  236. $purchlogitem = new wpsc_purchaselogs_items( $this->log_id ); 
  237.  
  238. $columns = array( 
  239. 'title' => __( 'Name', 'wpsc' ),  
  240. 'sku' => __( 'SKU', 'wpsc' ),  
  241. 'quantity' => __( 'Quantity', 'wpsc' ),  
  242. 'price' => __( 'Price', 'wpsc' ),  
  243. 'shipping' => __( 'Item Shipping', 'wpsc'),  
  244. ); 
  245.  
  246. if ( wpec_display_product_tax() ) { 
  247. $columns['tax'] = __( 'Item Tax', 'wpsc' ); 
  248.  
  249. $columns['total'] = __( 'Item Total', 'wpsc' ); 
  250.  
  251. register_column_headers( 'wpsc_purchase_log_item_details', $columns ); 
  252.  
  253. add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_purchase_log' ) ); 
  254.  
  255. public function controller_packing_slip() { 
  256.  
  257. if ( ! isset( $_REQUEST['id'] ) || ( isset( $_REQUEST['id'] ) && ! is_numeric( $_REQUEST['id'] ) ) ) { 
  258. wp_die( __( 'Invalid sales log ID', 'wpsc' ) ); 
  259.  
  260. global $purchlogitem; 
  261.  
  262. $purchlogitem = new wpsc_purchaselogs_items( $this->log_id ); 
  263.  
  264. $columns = array( 
  265. 'title' => __( 'Item Name', 'wpsc' ),  
  266. 'sku' => __( 'SKU', 'wpsc' ),  
  267. 'quantity' => __( 'Quantity', 'wpsc' ),  
  268. 'price' => __( 'Price', 'wpsc' ),  
  269. 'shipping' => __( 'Item Shipping', 'wpsc' ),  
  270. ); 
  271.  
  272. if ( wpec_display_product_tax() ) { 
  273. $columns['tax'] = __( 'Item Tax', 'wpsc' ); 
  274.  
  275. $columns['total'] = __( 'Item Total', 'wpsc' ); 
  276.  
  277. $cols = count( $columns ) - 2; 
  278.  
  279. register_column_headers( 'wpsc_purchase_log_item_details', $columns ); 
  280.  
  281. if ( file_exists( get_stylesheet_directory() . '/wpsc-packing-slip.php' ) ) { 
  282. $packing_slip_file = get_stylesheet_directory() . '/wpsc-packing-slip.php'; 
  283. } else { 
  284. $packing_slip_file = 'includes/purchase-logs-page/packing-slip.php'; 
  285.  
  286. $packing_slip_file = apply_filters( 'wpsc_packing_packing_slip_path', $packing_slip_file ); 
  287.  
  288. include( $packing_slip_file ); 
  289.  
  290. exit; 
  291.  
  292. public function controller_default() { 
  293. //Create an instance of our package class... 
  294. $this->list_table = new WPSC_Purchase_Log_List_Table(); 
  295. $this->process_bulk_action(); 
  296. $this->list_table->prepare_items(); 
  297. add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_list_table' ) ); 
  298.  
  299. public function display_purchase_log() { 
  300. if ( wpec_display_product_tax() ) 
  301. $cols = 5; 
  302. else 
  303. $cols = 4; 
  304. $receipt_sent = ! empty( $_GET['sent'] ); 
  305. $receipt_not_sent = isset( $_GET['sent'] ) && ! $_GET['sent']; 
  306. include( 'includes/purchase-logs-page/item-details.php' ); 
  307.  
  308. public function download_csv() { 
  309. $_REQUEST['rss_key'] = 'key'; 
  310. wpsc_purchase_log_csv(); 
  311.  
  312. public function process_bulk_action() { 
  313. global $wpdb; 
  314. $current_action = $this->list_table->current_action(); 
  315.  
  316. do_action( 'wpsc_sales_log_process_bulk_action', $current_action ); 
  317.  
  318. if ( ! $current_action || ( 'download_csv' != $current_action && empty( $_REQUEST['post'] ) ) ) { 
  319. if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { 
  320. wp_redirect( esc_url_raw( remove_query_arg( array( '_wp_http_referer', '_wpnonce', 'action', 'action2' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) ) ); 
  321. exit; 
  322.  
  323. unset( $_REQUEST['post'] ); 
  324. return; 
  325.  
  326. if ( 'download_csv' == $current_action ) { 
  327. $this->download_csv(); 
  328. exit; 
  329.  
  330. $sendback = remove_query_arg( array( 
  331. '_wpnonce',  
  332. '_wp_http_referer',  
  333. 'action',  
  334. 'action2',  
  335. 'confirm',  
  336. 'post',  
  337. 'last_paged' 
  338. ) ); 
  339.  
  340. if ( 'delete' == $current_action ) { 
  341.  
  342. // delete action 
  343. if ( empty( $_REQUEST['confirm'] ) ) { 
  344. $this->list_table->disable_search_box(); 
  345. $this->list_table->disable_bulk_actions(); 
  346. $this->list_table->disable_sortable(); 
  347. $this->list_table->disable_month_filter(); 
  348. $this->list_table->disable_views(); 
  349. $this->list_table->set_per_page(0); 
  350. add_action( 'wpsc_purchase_logs_list_table_before', array( $this, 'action_list_table_before' ) ); 
  351. return; 
  352. } else { 
  353. if ( empty( $_REQUEST['post'] ) ) 
  354. return; 
  355.  
  356. $ids = array_map( 'intval', $_REQUEST['post'] ); 
  357. $in = implode( ', ', $ids ); 
  358. $wpdb->query( "DELETE FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE id IN ($in)" ); 
  359. $wpdb->query( "DELETE FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid IN ($in)" ); 
  360. $wpdb->query( "DELETE FROM " . WPSC_TABLE_SUBMITTED_FORM_DATA . " WHERE log_id IN ($in)" ); 
  361. $claimed_query = new WPSC_Claimed_Stock( array( 'cart_id' => $in ) ); 
  362. $claimed_query->clear_claimed_stock( 0 ); 
  363.  
  364. $sendback = add_query_arg( array( 
  365. 'paged' => $_REQUEST['last_paged'],  
  366. 'deleted' => count( $_REQUEST['post'] ),  
  367. ), $sendback ); 
  368.  
  369.  
  370. // change status actions 
  371. if ( is_numeric( $current_action ) && $current_action < 7 && ! empty( $_REQUEST['post'] ) ) { 
  372.  
  373. foreach ( $_REQUEST['post'] as $id ) 
  374. wpsc_purchlog_edit_status( $id, $current_action ); 
  375.  
  376. $sendback = add_query_arg( array( 
  377. 'updated' => count( $_REQUEST['post'] ),  
  378. ), $sendback ); 
  379.  
  380. wp_redirect( esc_url_raw( $sendback ) ); 
  381. exit; 
  382.  
  383. public function action_list_table_before() { 
  384. include( 'includes/purchase-logs-page/bulk-delete-confirm.php' ); 
  385.  
  386. public function display_list_table() { 
  387. if ( ! empty( $this->output ) ) { 
  388. echo $this->output; 
  389. return; 
  390.  
  391. include( 'includes/purchase-logs-page/list-table.php' ); 
  392.  
  393. private function get_purchase_log_url( $id ) { 
  394. $location = add_query_arg( array( 
  395. 'page' => 'wpsc-purchase-logs',  
  396. 'c' => 'item_details',  
  397. 'id' => $id,  
  398. ), admin_url( 'index.php' ) ); 
  399.  
  400. return esc_url( $location ); 
  401.  
.