PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-e-commerce/wpsc-includes/purchaselogs.class.php

https://github.com/AaronFernandes/aquestionof
PHP | 985 lines | 794 code | 141 blank | 50 comment | 153 complexity | 62e72f4018f0bec668f1a9daebaaff0f MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. add_action( 'wpsc_core_included', 'wpsc_instantiate_purchaselogitem' );
  3. global $wpsc_purchlog_statuses;
  4. if (!isset($wpsc_purchlog_statuses) || !count($wpsc_purchlog_statuses))
  5. wpsc_core_load_purchase_log_statuses();
  6. function wpsc_instantiate_purchaselogitem() {
  7. global $purchlogitem;
  8. if ( isset( $_REQUEST['purchaselog_id'] ) )
  9. $purchlogitem = new wpsc_purchaselogs_items( (int)$_REQUEST['purchaselog_id'] );
  10. }
  11. function wpsc_display_tracking_id(){
  12. $value = wpsc_trackingid_value();
  13. if(!empty($value))
  14. return $value;
  15. else
  16. return __('Add New','wpsc');
  17. }
  18. function wpsc_display_purchlog_howtheyfoundus() {
  19. global $purchlogitem;
  20. return esc_attr( $purchlogitem->extrainfo->find_us );
  21. }
  22. function wpsc_display_purchlog_display_howtheyfoundus() {
  23. global $purchlogitem;
  24. if ( !empty( $purchlogitem->extrainfo->find_us ) )
  25. return true;
  26. else
  27. return false;
  28. }
  29. function wpsc_check_uniquenames() {
  30. global $wpdb;
  31. $sql = 'SELECT COUNT(`id`) FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE unique_name != "" ';
  32. $check_unique_names = $wpdb->get_var( $sql );
  33. if ( $check_unique_names > 0 ) {
  34. return false;
  35. } else {
  36. return true;
  37. }
  38. }
  39. function wpsc_purchlogs_has_tracking() {
  40. global $wpdb, $wpsc_shipping_modules, $purchlogitem;
  41. $custom_shipping = get_option( 'custom_shipping_options' );
  42. if ( in_array( 'nzpost', (array)$custom_shipping ) && $purchlogitem->extrainfo->track_id != '' ) {
  43. return true;
  44. } else {
  45. return false;
  46. }
  47. }
  48. function wpsc_purchlogitem_trackid() {
  49. global $purchlogitem;
  50. return esc_attr( $purchlogitem->extrainfo->track_id );
  51. }
  52. function wpsc_purchlogitem_trackstatus() {
  53. global $wpdb, $wpsc_shipping_modules, $purchlogitem;
  54. $custom_shipping = get_option( 'custom_shipping_options' );
  55. if ( in_array( 'nzpost', (array)$custom_shipping ) && $purchlogitem->extrainfo->track_id != '' ) {
  56. $status = $wpsc_shipping_modules['nzpost']->getStatus( $purchlogitem->extrainfo->track_id );
  57. }
  58. return $status;
  59. }
  60. function wpsc_purchlogitem_trackhistory() {
  61. global $purchlogitem;
  62. $output = '<ul>';
  63. foreach ( (array)$_SESSION['wpsc_nzpost_parsed'][0]['children'][0]['children'][1]['children'] as $history ) {
  64. $outputs[] = '<li>' . $history['children'][0]['tagData'] . " : " . $history['children'][1]['tagData'] . " </li>";
  65. }
  66. $outputs = array_reverse( $outputs );
  67. foreach ( $outputs as $o ) {
  68. $output .= $o;
  69. }
  70. $output .='</ul>';
  71. return $output;
  72. }
  73. function wpsc_purchlogs_has_customfields( $id = '' ) {
  74. global $purchlogitem;
  75. if ( $id == '' ) {
  76. foreach ( (array)$purchlogitem->allcartcontent as $cartitem ) {
  77. if ( $cartitem->files != 'N;' || $cartitem->custom_message != '' ) {
  78. return true;
  79. }
  80. }
  81. return false;
  82. } else {
  83. $purchlogitem = new wpsc_purchaselogs_items( $id );
  84. foreach ( (array)$purchlogitem->allcartcontent as $cartitem ) {
  85. if ( $cartitem->files != 'N;' || $cartitem->custom_message != '' ) {
  86. return true;
  87. }
  88. }
  89. return false;
  90. }
  91. return false;
  92. }
  93. function wpsc_trackingid_value() {
  94. global $purchlogs;
  95. return esc_attr( $purchlogs->purchitem->track_id );
  96. }
  97. function wpsc_purchlogs_custommessages() {
  98. global $purchlogitem;
  99. foreach ( $purchlogitem->allcartcontent as $cartitem ) {
  100. if ( $cartitem->custom_message != '' ) {
  101. $messages[] = $cartitem->name . ' :<br />' . $cartitem->custom_message;
  102. }
  103. }
  104. return $messages;
  105. }
  106. function wpsc_purchlogs_customfiles() {
  107. global $purchlogitem;
  108. $files = array( );
  109. foreach ( $purchlogitem->allcartcontent as $cartitem ) {
  110. if ( $cartitem->files != 'N;' ) {
  111. $file = unserialize( $cartitem->files );
  112. if ( $file["mime_type"] == "image/jpeg" || $file["mime_type"] == "image/png" || $file["mime_type"] == "image/gif" ) {
  113. $image = "<a href='" . esc_url ( WPSC_USER_UPLOADS_URL . $file['file_name'] ) . "' >";
  114. $image .= "<img width='150' src='".esc_url( WPSC_USER_UPLOADS_URL . $file['file_name'] ). "' alt='' />";
  115. $image .="</a>";
  116. $files[] = $cartitem->name . ' :<br />' . $image;
  117. } else {
  118. $files[] = $cartitem->name . ' :<br />' . esc_url( $file['file_name'] );
  119. }
  120. }
  121. }
  122. return $files;
  123. }
  124. function wpsc_purchlogs_is_google_checkout() {
  125. global $purchlogs;
  126. if ( $purchlogs->purchitem->gateway == 'google' ) {
  127. return true;
  128. } else {
  129. return false;
  130. }
  131. }
  132. function wpsc_the_purch_total() {
  133. global $purchlogs;
  134. return $purchlogs->totalAmount;
  135. }
  136. function wpsc_have_purch_items() {
  137. global $purchlogs;
  138. return $purchlogs->have_purch_items();
  139. }
  140. function wpsc_the_purch_item() {
  141. global $purchlogs;
  142. if ( isset( $_SESSION['newlogs'] ) ) {
  143. $purchlogs->allpurchaselogs = $_SESSION['newlogs'];
  144. $purchlogs->purch_item_count = count( $_SESSION['newlogs'] );
  145. }
  146. return $purchlogs->the_purch_item();
  147. }
  148. function wpsc_the_purch_item_price() {
  149. global $purchlogs;
  150. if ( $purchlogs->purchitem->processed > 1 && $purchlogs->purchitem->processed != 5 ) {
  151. $purchlogs->totalAmount += $purchlogs->purchitem->totalprice;
  152. }
  153. return $purchlogs->purchitem->totalprice;
  154. }
  155. function wpsc_the_purch_item_id() {
  156. global $purchlogs;
  157. return $purchlogs->purchitem->id;
  158. }
  159. function wpsc_the_purch_item_date() {
  160. global $purchlogs;
  161. return date( 'M d Y,g:i a', $purchlogs->purchitem->date );
  162. }
  163. function wpsc_the_purch_item_name() {
  164. global $purchlogs;
  165. if ( wpsc_purchlogs_has_customfields( wpsc_the_purch_item_id() ) ) {
  166. return $purchlogs->the_purch_item_name() . '<img src="' . WPSC_CORE_IMAGES_URL . '/info_icon.jpg" title="This Purchase has custom user content" alt="exclamation icon" />';
  167. } else {
  168. return $purchlogs->the_purch_item_name();
  169. }
  170. }
  171. function wpsc_the_purch_item_details() {
  172. global $purchlogs;
  173. return $purchlogs->the_purch_item_details();
  174. }
  175. //status loop functions
  176. function wpsc_have_purch_items_statuses() {
  177. global $purchlogs;
  178. return $purchlogs->have_purch_status();
  179. }
  180. function wpsc_the_purch_status() {
  181. global $purchlogs;
  182. return $purchlogs->the_purch_status();
  183. }
  184. function wpsc_the_purch_item_statuses() {
  185. global $purchlogs;
  186. return $purchlogs->the_purch_item_statuses();
  187. }
  188. function wpsc_the_purch_item_status() {
  189. global $purchlogs;
  190. return $purchlogs->the_purch_item_status();
  191. }
  192. function wpsc_the_purch_status_id() {
  193. global $purchlogs;
  194. return $purchlogs->purchstatus['order'];
  195. }
  196. function wpsc_is_checked_status() {
  197. global $purchlogs;
  198. return $purchlogs->is_checked_status();
  199. }
  200. function wpsc_the_purch_status_name() {
  201. global $purchlogs;
  202. if ( isset( $purchlogs->purchstatus['label'] ) ) {
  203. return $purchlogs->purchstatus['label'];
  204. }
  205. }
  206. function wpsc_purchlogs_getfirstdates() {
  207. global $purchlogs;
  208. $dates = $purchlogs->getdates();
  209. $fDate = '';
  210. foreach ( $dates as $date ) {
  211. $is_selected = '';
  212. $cleanDate = date( 'M Y', $date['start'] );
  213. $value = $date["start"] . "_" . $date["end"];
  214. if ( $value == $_GET['view_purchlogs_by'] ) {
  215. $is_selected = 'selected="selected"';
  216. }
  217. $fDate .= "<option value='{$value}' {$is_selected}>" . $cleanDate . "</option>";
  218. }
  219. return $fDate;
  220. }
  221. function wpsc_change_purchlog_view( $viewby, $status='' ) {
  222. global $purchlogs;
  223. if ( $viewby == 'all' ) {
  224. $dates = $purchlogs->getdates();
  225. $purchaselogs = $purchlogs->get_purchlogs( $dates, $status );
  226. $_SESSION['newlogs'] = $purchaselogs;
  227. $purchlogs->allpurchaselogs = $purchaselogs;
  228. } elseif ( $viewby == '3mnths' ) {
  229. $dates = $purchlogs->getdates();
  230. $dates = array_slice( $dates, 0, 3 );
  231. $purchlogs->current_start_timestamp = $dates[count($dates)-1]['start'];
  232. $purchlogs->current_end_timestamp = $dates[0]['end'];
  233. $newlogs = $purchlogs->get_purchlogs( $dates, $status );
  234. $_SESSION['newlogs'] = $newlogs;
  235. $purchlogs->allpurchaselogs = $newlogs;
  236. } else {
  237. $dates = explode( '_', $viewby );
  238. $date[0]['start'] = $dates[0];
  239. $date[0]['end'] = $dates[1];
  240. $purchlogs->current_start_timestamp = $dates[0];
  241. $purchlogs->current_end_timestamp = $dates[1];
  242. $newlogs = $purchlogs->get_purchlogs( $date, $status );
  243. $_SESSION['newlogs'] = $newlogs;
  244. $purchlogs->allpurchaselogs = $newlogs;
  245. }
  246. }
  247. function wpsc_search_purchlog_view( $search ) {
  248. global $purchlogs;
  249. $newlogs = $purchlogs->search_purchlog_view( $search );
  250. $purchlogs->getDates();
  251. $purchlogs->purch_item_count = count( $newlogs );
  252. $purchlogs->allpurchaselogs = $newlogs;
  253. }
  254. function wpsc_have_purchaselog_details() {
  255. global $purchlogitem;
  256. return $purchlogitem->have_purch_item();
  257. }
  258. function wpsc_purchaselog_details_name() {
  259. global $purchlogitem;
  260. return esc_attr( stripslashes( $purchlogitem->purchitem->name ) );
  261. }
  262. function wpsc_purchaselog_details_id() {
  263. global $purchlogitem;
  264. return $purchlogitem->purchitem->id;
  265. }
  266. function wpsc_the_purchaselog_item() {
  267. global $purchlogitem;
  268. return $purchlogitem->the_purch_item();
  269. }
  270. function wpsc_purchaselog_details_SKU() {
  271. global $purchlogitem;
  272. $meta_value = wpsc_get_cartmeta( $purchlogitem->purchitem->id, 'sku' );
  273. if ( $meta_value != null ) {
  274. return esc_attr( $meta_value );
  275. } else {
  276. $meta_value = get_product_meta( $purchlogitem->purchitem->prodid, 'sku', true );
  277. if ( $meta_value != null ) {
  278. return esc_attr( $meta_value );
  279. } else {
  280. return __('N/A', 'wpsc');
  281. }
  282. }
  283. }
  284. function wpsc_purchaselog_details_quantity() {
  285. global $purchlogitem;
  286. return (int)$purchlogitem->purchitem->quantity;
  287. }
  288. function wpsc_purchaselog_details_price() {
  289. global $purchlogitem;
  290. return (float)$purchlogitem->purchitem->price;
  291. }
  292. function wpsc_purchaselog_details_shipping() {
  293. global $purchlogitem;
  294. return (int)$purchlogitem->purchitem->pnp;
  295. }
  296. function wpsc_purchaselog_details_tax() {
  297. global $purchlogitem, $wpsc_cart;
  298. return (int)$purchlogitem->purchitem->tax_charged;
  299. }
  300. function wpsc_purchaselog_details_discount() {
  301. global $purchlogitem;
  302. return (float)$purchlogitem->extrainfo->discount_value;
  303. }
  304. function wpsc_purchaselog_details_date() {
  305. global $purchlogitem;
  306. return date( 'jS M Y', $purchlogitem->extrainfo->date );
  307. }
  308. function wpsc_purchaselog_details_total() {
  309. global $purchlogitem;
  310. $total = 0;
  311. $total += ( $purchlogitem->purchitem->price * $purchlogitem->purchitem->quantity);
  312. $total += ( $purchlogitem->purchitem->pnp * $purchlogitem->purchitem->quantity);
  313. $purchlogitem->totalAmount += $total;
  314. return $total;
  315. }
  316. function wpsc_purchaselog_details_purchnumber() {
  317. global $purchlogitem;
  318. return $purchlogitem->extrainfo->id;
  319. }
  320. /*
  321. * Has Discount Data?
  322. */
  323. function wpsc_purchlog_has_discount_data() {
  324. global $purchlogitem;
  325. return!empty( $purchlogitem->extrainfo->discount_data );
  326. }
  327. /*
  328. * Returns Discount Code
  329. */
  330. function wpsc_display_purchlog_discount_data( $numeric = false ) {
  331. global $purchlogitem;
  332. return $purchlogitem->extrainfo->discount_data;
  333. }
  334. /*
  335. * Returns base shipping should make a function to calculate items shipping as well
  336. */
  337. function wpsc_display_purchlog_discount( $numeric = false ) {
  338. global $purchlogitem;
  339. $discount = $purchlogitem->extrainfo->discount_value;
  340. if ( $numeric == true ) {
  341. return $discount;
  342. } else {
  343. return wpsc_currency_display( $discount,array( 'display_as_html' => false ) );
  344. }
  345. }
  346. /*
  347. * Returns base shipping should make a function to calculate items shipping as well
  348. */
  349. function wpsc_display_purchlog_shipping( $numeric = false ) {
  350. global $purchlogitem;
  351. $base_shipping = $purchlogitem->extrainfo->base_shipping;
  352. $per_item_shipping = 0;
  353. foreach ( (array)$purchlogitem->allcartcontent as $cart_item ) {
  354. if ( $cart_item->pnp > 0 ) {
  355. $per_item_shipping += ( $cart_item->pnp * $cart_item->quantity);
  356. }
  357. }
  358. $total_shipping = $per_item_shipping + $base_shipping;
  359. if ( $numeric == true ) {
  360. return $total_shipping;
  361. } else {
  362. return wpsc_currency_display( $total_shipping,array( 'display_as_html' => false ) );
  363. }
  364. }
  365. /**
  366. * @description: returns taxes as set in purchase log
  367. * @param: numeric - if set will return unformatted price
  368. * */
  369. function wpec_display_purchlog_taxes( $numeric=false ) {
  370. global $purchlogitem;
  371. return ($numeric) ? $purchlogitem->extrainfo->wpec_taxes_total : wpsc_currency_display( $purchlogitem->extrainfo->wpec_taxes_total,array( 'display_as_html' => false ) );
  372. }
  373. // wpec_display_purchlog_taxes
  374. function wpsc_display_purchlog_totalprice() {
  375. global $purchlogitem;
  376. $purchlogitem->totalAmount -= wpsc_display_purchlog_discount( true );
  377. $purchlogitem->totalAmount += wpsc_display_purchlog_shipping( true );
  378. $purchlogitem->totalAmount += wpec_display_purchlog_taxes( true );
  379. return wpsc_currency_display( $purchlogitem->totalAmount,array( 'display_as_html' => false ) );
  380. }
  381. function wpsc_display_purchlog_buyers_name() {
  382. global $purchlogitem;
  383. return esc_attr( htmlentities( stripslashes( $purchlogitem->userinfo['billingfirstname']['value'] ), ENT_QUOTES, 'UTF-8') ) . ' ' . esc_attr( htmlentities( stripslashes( $purchlogitem->userinfo['billinglastname']['value'] ), ENT_QUOTES, 'UTF-8') );
  384. }
  385. function wpsc_display_purchlog_buyers_email() {
  386. global $purchlogitem;
  387. return esc_attr( htmlentities( stripslashes( $purchlogitem->userinfo['billingemail']['value'] ), ENT_QUOTES, 'UTF-8') );
  388. }
  389. function wpsc_display_purchlog_buyers_address() {
  390. global $purchlogitem;
  391. if(is_numeric($purchlogitem->extrainfo->billing_region))
  392. $state = wpsc_get_region($purchlogitem->extrainfo->billing_region);
  393. else
  394. $state = $purchlogitem->userinfo['billingstate']['value'];
  395. return nl2br( esc_html( trim(htmlentities( stripslashes( $purchlogitem->userinfo['billingaddress']['value'] ), ENT_QUOTES, 'UTF-8'), "\n\r"))).'<br />'.
  396. esc_html( htmlentities( stripslashes( $state ), ENT_QUOTES, 'UTF-8') ).', '.
  397. esc_html( htmlentities( stripslashes( $purchlogitem->userinfo['billingpostcode']['value'] ), ENT_QUOTES, 'UTF-8') ).'<br />'.esc_html( htmlentities( stripslashes( $purchlogitem->extrainfo->billing_country ), ENT_QUOTES, 'UTF-8') ) ;
  398. }
  399. function wpsc_display_purchlog_buyers_phone() {
  400. global $purchlogitem;
  401. return esc_attr( htmlentities( stripslashes( $purchlogitem->userinfo['billingphone']['value'] ), ENT_QUOTES, 'UTF-8') );
  402. }
  403. function wpsc_display_purchlog_shipping_name() {
  404. global $purchlogitem;
  405. return esc_html( htmlentities( stripslashes( $purchlogitem->shippinginfo['shippingfirstname']['value'] ), ENT_QUOTES, 'UTF-8') . ' ' . htmlentities( stripslashes( $purchlogitem->shippinginfo['shippinglastname']['value'] ), ENT_QUOTES, 'UTF-8') );
  406. }
  407. function wpsc_display_purchlog_shipping_address() {
  408. global $purchlogitem;
  409. return nl2br( esc_html( trim(htmlentities( stripslashes( $purchlogitem->shippinginfo['shippingaddress']['value'] ), ENT_QUOTES, 'UTF-8'), "\n\r")) );
  410. }
  411. function wpsc_display_purchlog_shipping_city() {
  412. global $purchlogitem;
  413. return esc_attr( htmlentities( stripslashes( $purchlogitem->shippinginfo['shippingcity']['value'] ), ENT_QUOTES, 'UTF-8' ) );
  414. }
  415. function wpsc_display_purchlog_shipping_state_and_postcode() {
  416. global $purchlogitem;
  417. $state = '';
  418. if( is_numeric($purchlogitem->extrainfo->shipping_region) )
  419. $state = esc_html( wpsc_get_region($purchlogitem->extrainfo->shipping_region) );
  420. else
  421. $state = esc_html( $purchlogitem->shippinginfo['shippingstate']['value'] );
  422. if ( !empty( $purchlogitem->shippinginfo['shippingpostcode']['value'] ) ){
  423. if( empty( $state ) )
  424. $state = esc_html( $purchlogitem->shippinginfo['shippingpostcode']['value'] );
  425. else
  426. $state .= ', ' . esc_html( $purchlogitem->shippinginfo['shippingpostcode']['value'] );
  427. }
  428. return $state;
  429. }
  430. function wpsc_display_purchlog_shipping_country() {
  431. global $purchlogitem;
  432. return esc_attr( htmlentities( stripslashes( $purchlogitem->shippinginfo['shippingcountry']['value'] ), ENT_QUOTES, 'UTF-8' ) );
  433. }
  434. function wpsc_display_purchlog_shipping_method() {
  435. global $purchlogitem;
  436. return $purchlogitem->extrainfo->shipping_method;
  437. }
  438. function wpsc_display_purchlog_shipping_option() {
  439. global $purchlogitem;
  440. return $purchlogitem->extrainfo->shipping_option;
  441. }
  442. function wpsc_display_purchlog_paymentmethod() {
  443. global $purchlogitem, $nzshpcrt_gateways;
  444. $gateway_name = '';
  445. if('wpsc_merchant_testmode' == $purchlogitem->extrainfo->gateway)
  446. return 'Manual Payment';
  447. foreach ( (array)$nzshpcrt_gateways as $gateway ) {
  448. if ( $gateway['internalname'] == $purchlogitem->extrainfo->gateway )
  449. $gateway_name = $gateway['name'];
  450. }
  451. if( !empty($gateway_name) )
  452. return $gateway_name;
  453. else
  454. return $purchlogitem->extrainfo->gateway;
  455. }
  456. function wpsc_has_purchlog_shipping() {
  457. global $purchlogitem;
  458. if ( $purchlogitem->shippinginfo['shippingfirstname']['value'] != '' ) {
  459. return true;
  460. } else {
  461. return false;
  462. }
  463. }
  464. function wpsc_purchlog_is_checked_status() {
  465. global $purchlogitem, $purchlogs;
  466. if ( $purchlogs->purchstatus['order'] == $purchlogitem->extrainfo->processed ) {
  467. return 'selected="selected"';
  468. } else {
  469. return '';
  470. }
  471. }
  472. function wpsc_purchlogs_have_downloads_locked() {
  473. global $purchlogitem;
  474. $ip = $purchlogitem->have_downloads_locked();
  475. if ( $ip != '' ) {
  476. return sprintf( __( 'Release downloads locked to this IP address %s', 'wpsc' ), $ip );
  477. } else {
  478. return false;
  479. }
  480. }
  481. /* Start Order Notes (by Ben) */
  482. function wpsc_display_purchlog_notes() {
  483. global $purchlogitem;
  484. if ( isset( $purchlogitem->extrainfo->notes ) ) {
  485. return $purchlogitem->extrainfo->notes;
  486. } else {
  487. return false;
  488. }
  489. }
  490. /* End Order Notes (by Ben) */
  491. /**
  492. * WP eCommerce purchaselogs AND purchaselogs_items class
  493. *
  494. * These is the classes for the WP eCommerce purchase logs,
  495. * The purchaselogs class handles adding, removing and adjusting details in the purchaselogs,
  496. * The purchaselogs_items class handles adding, removing and adjusting individual item details in the purchaselogs,
  497. *
  498. * @package wp-e-commerce
  499. * @since 3.7
  500. * @subpackage wpsc-cart-classes
  501. */
  502. class wpsc_purchaselogs {
  503. var $earliest_timestamp;
  504. var $current_timestamp;
  505. var $earliest_year;
  506. var $current_year;
  507. var $form_data;
  508. var $purch_item_count;
  509. //individual purch log variables
  510. var $allpurchaselogs;
  511. var $currentitem = -1;
  512. var $purchitem;
  513. //used for purchase options
  514. var $currentstatus = -1;
  515. var $purch_status_count;
  516. var $allpurchaselogstatuses;
  517. //calculation of totals
  518. var $totalAmount;
  519. //used for csv
  520. var $current_start_timestamp;
  521. var $current_end_timestamp;
  522. /* Constructor function */
  523. function wpsc_purchaselogs() {
  524. $this->getall_formdata();
  525. if ( !isset( $_GET['view_purchlogs_by'] ) && !isset( $_GET['purchlogs_searchbox'] ) ) {
  526. $dates = $this->getdates();
  527. $dates = array_slice( $dates, 0, 3 );
  528. if(isset($dates[2]['start']))
  529. $this->current_start_timestamp = $dates[2]['start'];
  530. $this->current_end_timestamp = $dates[0]['end'];
  531. $newlogs = $this->get_purchlogs( $dates );
  532. $_SESSION['newlogs'] = $newlogs;
  533. $this->allpurchaselogs = $newlogs;
  534. } else {
  535. $this->getdates();
  536. if ( isset( $_GET['view_purchlogs_by'] ) && isset( $_GET['view_purchlogs_by_status'] ) ) {
  537. $status = $_GET['view_purchlogs_by_status'];
  538. $viewby = $_GET['view_purchlogs_by'];
  539. if ( $viewby == 'all' ) {
  540. $dates = $this->getdates();
  541. $purchaselogs = $this->get_purchlogs( $dates, $status );
  542. $_SESSION['newlogs'] = $purchaselogs;
  543. $this->allpurchaselogs = $purchaselogs;
  544. } elseif ( $viewby == '3mnths' ) {
  545. $dates = $this->getdates();
  546. $dates = array_slice( $dates, 0, 3 );
  547. $this->current_start_timestamp = $dates[count($dates)-1]['start'];
  548. $this->current_end_timestamp = $dates[0]['end'];
  549. $newlogs = $this->get_purchlogs( $dates, $status );
  550. $_SESSION['newlogs'] = $newlogs;
  551. $this->allpurchaselogs = $newlogs;
  552. } else {
  553. $dates = explode( '_', $viewby );
  554. $date[0]['start'] = $dates[0];
  555. $date[0]['end'] = $dates[1];
  556. $this->current_start_timestamp = $dates[0];
  557. $this->current_end_timestamp = $dates[1];
  558. $newlogs = $this->get_purchlogs( $date, $status );
  559. $_SESSION['newlogs'] = $newlogs;
  560. $this->allpurchaselogs = $newlogs;
  561. }
  562. }
  563. }
  564. $this->purch_item_count = count( $this->allpurchaselogs );
  565. $statuses = $this->the_purch_item_statuses();
  566. if ( isset( $_SESSION['newlogs'] ) ) {
  567. $this->allpurchaselogs = $_SESSION['newlogs'];
  568. $this->purch_item_count = count( $_SESSION['newlogs'] );
  569. }
  570. return;
  571. }
  572. function get_purchlogs( $dates, $status='' ) {
  573. global $wpdb;
  574. $purchlog2 = array( );
  575. if ( $status == '' || $status == '-1' ) {
  576. foreach ( (array)$dates as $date_pair ) {
  577. if ( ($date_pair['end'] >= $this->earliest_timestamp) && ($date_pair['start'] <= $this->current_timestamp) ) {
  578. $sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '" . $date_pair['start'] . "' AND '" . $date_pair['end'] . "' ORDER BY `date` DESC";
  579. $purchase_logs = $wpdb->get_results( $sql );
  580. array_push( $purchlog2, $purchase_logs );
  581. }
  582. }
  583. } else {
  584. foreach ( (array)$dates as $date_pair ) {
  585. if ( ($date_pair['end'] >= $this->earliest_timestamp) && ($date_pair['start'] <= $this->current_timestamp) ) {
  586. $sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '" . $date_pair['start'] . "' AND '" . $date_pair['end'] . "' AND `processed`='" . $status . "' ORDER BY `date` DESC";
  587. $purchase_logs = $wpdb->get_results( $sql );
  588. array_push( $purchlog2, $purchase_logs );
  589. }
  590. }
  591. }
  592. $newarray = array( );
  593. foreach ( $purchlog2 as $purch ) {
  594. if ( is_array( $purch ) ) {
  595. foreach ( $purch as $log ) {
  596. $newarray[] = $log;
  597. }
  598. } else {
  599. exit( 'Else :' . print_r( $purch ) );
  600. }
  601. }
  602. $this->allpurchaselogs = $newarray;
  603. $this->purch_item_count = count( $this->allpurchaselogs );
  604. return $newarray;
  605. }
  606. function getall_formdata() {
  607. global $wpdb;
  608. $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1';";
  609. $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
  610. $this->form_data = $form_data;
  611. return $form_data;
  612. }
  613. /*
  614. * This finds the earliest time in the shopping cart and sorts out the timestamp system for the month by month display
  615. * or if there was a filter applied use the filter to sort the dates.
  616. */
  617. function getdates() {
  618. global $wpdb, $purchlogs;
  619. $earliest_record_sql = "SELECT MIN(`date`) AS `date` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date`!=''";
  620. $earliest_record = $wpdb->get_results( $earliest_record_sql, ARRAY_A );
  621. $this->current_timestamp = time();
  622. //if there are no reccords set the date to now.
  623. $this->earliest_timestamp = ($earliest_record[0]['date'])?$earliest_record[0]['date']:time();
  624. $this->current_year = date( "Y" );
  625. $this->earliest_year = date( "Y", $this->earliest_timestamp );
  626. $j = 0;
  627. for ( $year = $this->current_year; $year >= $this->earliest_year; $year-- ) {
  628. for ( $month = 12; $month >= 1; $month-- ) {
  629. $this->start_timestamp = mktime( 0, 0, 0, $month, 1, $year );
  630. $this->end_timestamp = mktime( 0, 0, 0, ($month + 1 ), 1, $year );
  631. if ( ($this->end_timestamp >= $this->earliest_timestamp) && ($this->start_timestamp <= $this->current_timestamp) ) {
  632. $date_list[$j]['start'] = $this->start_timestamp;
  633. $date_list[$j]['end'] = $this->end_timestamp;
  634. $j++;
  635. }
  636. }
  637. }
  638. if ( is_object( $purchlogs ) ) {
  639. $purchlogs->current_start_timestamp = $purchlogs->earliest_timestamp;
  640. $purchlogs->current_end_timestamp = $purchlogs->current_timestamp;
  641. }
  642. return $date_list;
  643. }
  644. function deletelog( $deleteid ) {
  645. //change $_GET[deleteid] to $deleteid
  646. global $wpdb;
  647. if ( is_numeric( $deleteid ) ) {
  648. $delete_log_form_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='$deleteid'";
  649. $cart_content = $wpdb->get_results( $delete_log_form_sql, ARRAY_A );
  650. $wpdb->query( "DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='$deleteid'" );
  651. $wpdb->query( "DELETE FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` IN ('$deleteid')" );
  652. $wpdb->query( "DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='$deleteid' LIMIT 1" );
  653. return '<div id="message" class="updated fade"><p>' . __( 'Thanks, the purchase log record has been deleted', 'wpsc' ) . '</p></div>';
  654. }
  655. }
  656. //individual purchase log functions
  657. function next_purch_item() {
  658. $this->currentitem++;
  659. $this->purchitem = $this->allpurchaselogs[$this->currentitem];
  660. return $this->purchitem;
  661. }
  662. function the_purch_item() {
  663. $this->purchitem = $this->next_purch_item();
  664. }
  665. function have_purch_items() {
  666. if ( $this->currentitem + 1 < $this->purch_item_count ) {
  667. return true;
  668. } else if ( $this->currentitem + 1 == $this->purch_item_count && $this->purch_item_count > 0 ) {
  669. // Do some cleaning up after the loop,
  670. $this->rewind_purch_items();
  671. }
  672. return false;
  673. }
  674. function rewind_purch_items() {
  675. $this->currentitem = -1;
  676. if ( $this->purch_item_count > 0 ) {
  677. $this->purchitem = $this->allpurchaselogs[0];
  678. }
  679. }
  680. function the_purch_item_statuses() {
  681. global $wpdb, $wpsc_purchlog_statuses;
  682. $this->purch_status_count = count( $wpsc_purchlog_statuses );
  683. $this->allpurchaselogstatuses = $wpsc_purchlog_statuses;
  684. return $wpsc_purchlog_statuses;
  685. }
  686. // purchase status loop functions
  687. function next_purch_status() {
  688. $this->currentstatus++;
  689. $this->purchstatus = $this->allpurchaselogstatuses[$this->currentstatus];
  690. return $this->purchstatus;
  691. }
  692. function the_purch_status() {
  693. $this->purchstatus = $this->next_purch_status();
  694. }
  695. function have_purch_status() {
  696. if ( $this->currentstatus + 1 < $this->purch_status_count ) {
  697. return true;
  698. } else if ( $this->currentstatus + 1 == $this->purch_status_count && $this->purch_status_count > 0 ) {
  699. // Do some cleaning up after the loop,
  700. $this->rewind_purch_status();
  701. }
  702. return false;
  703. }
  704. function rewind_purch_status() {
  705. $this->currentstatus = -1;
  706. if ( $this->purch_status_count > 0 ) {
  707. $this->purchstatus = $this->allpurchaselogstatuses[0];
  708. }
  709. }
  710. function is_checked_status() {
  711. if ( isset( $this->purchstatus['order'] ) && isset( $this->purchitem->processed ) && ($this->purchstatus['order'] == $this->purchitem->processed) ) {
  712. return 'selected="selected"';
  713. } else {
  714. return '';
  715. }
  716. }
  717. function the_purch_item_name() {
  718. global $wpdb;
  719. $i = 0;
  720. if ( $this->form_data == null ) {
  721. $this->getall_formdata();
  722. }
  723. foreach ( (array)$this->form_data as $formdata ) {
  724. if ( in_array( 'billingemail', $formdata ) ) {
  725. $emailformid = $formdata['id'];
  726. }
  727. if ( in_array( 'billingfirstname', $formdata ) ) {
  728. $fNameformid = $formdata['id'];
  729. }
  730. if ( in_array( 'billinglastname', $formdata ) ) {
  731. $lNameformid = $formdata['id'];
  732. }
  733. $i++;
  734. }
  735. $sql = "SELECT value FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " WHERE log_id=" . $this->purchitem->id . " AND form_id=" . $emailformid;
  736. $email = $wpdb->get_var( $sql );
  737. $sql = "SELECT value FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " WHERE log_id=" . $this->purchitem->id . " AND form_id=" . $fNameformid;
  738. $fname = $wpdb->get_var( $sql );
  739. $sql = "SELECT value FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " WHERE log_id=" . $this->purchitem->id . " AND form_id=" . $lNameformid;
  740. $lname = $wpdb->get_var( $sql );
  741. $namestring = esc_html( $fname ) . ' ' . esc_html( $lname ) . ' (<a href="mailto:' . esc_attr( $email ) . '?subject=Message From ' . get_option( 'siteurl' ) . '">' . esc_html( $email ) . '</a>) ';
  742. if ( $fname == '' && $lname == '' && $email == '' ) {
  743. $namestring = __('N/A', 'wpsc');
  744. }
  745. return $namestring;
  746. }
  747. function the_purch_item_details() {
  748. global $wpdb;
  749. $sql = "SELECT SUM(quantity) FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid=" . $this->purchitem->id;
  750. $sum = $wpdb->get_var( $sql );
  751. return $sum;
  752. }
  753. function search_purchlog_view( $searchterm ) {
  754. global $wpdb;
  755. $sql = "SELECT DISTINCT `" . WPSC_TABLE_PURCHASE_LOGS . "` . * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` LEFT JOIN `" . WPSC_TABLE_PURCHASE_LOGS . "` ON `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id` = `" . WPSC_TABLE_PURCHASE_LOGS . "`.`id` WHERE `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`value` LIKE '%" . $wpdb->escape( $searchterm ) . "%' OR `" . WPSC_TABLE_PURCHASE_LOGS . "`.`transactid` ='" . $wpdb->escape( $searchterm )."' OR `" . WPSC_TABLE_PURCHASE_LOGS . "`.`track_id` LIKE '%" . $wpdb->escape( $searchterm )."%'";
  756. $newlogs = $wpdb->get_results( $sql );
  757. $_SESSION['newlogs'] = $newlogs;
  758. return $newlogs;
  759. }
  760. }
  761. class wpsc_purchaselogs_items {
  762. var $purchlogid;
  763. var $extrainfo;
  764. //the loop
  765. var $currentitem = -1;
  766. var $purchitem;
  767. var $allcartcontent;
  768. var $purch_item_count;
  769. //grand total
  770. var $totalAmount;
  771. //usersinfo
  772. var $userinfo;
  773. var $shippinginfo;
  774. var $customcheckoutfields = array( );
  775. function wpsc_purchaselogs_items( $id ) {
  776. $this->purchlogid = $id;
  777. $this->get_purchlog_details();
  778. }
  779. function shippingstate( $id ) {
  780. global $wpdb;
  781. if ( is_numeric( $id ) ) {
  782. $sql = "SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id=" . $id;
  783. $name = $wpdb->get_var( $sql );
  784. return $name;
  785. } else {
  786. return $id;
  787. }
  788. }
  789. function get_purchlog_details() {
  790. global $wpdb;
  791. $cartcontent = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $this->purchlogid . "" );
  792. $this->allcartcontent = $cartcontent;
  793. $sql = "SELECT DISTINCT `" . WPSC_TABLE_PURCHASE_LOGS . "` . * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` LEFT JOIN `" . WPSC_TABLE_PURCHASE_LOGS . "` ON `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id` = `" . WPSC_TABLE_PURCHASE_LOGS . "`.`id` WHERE `" . WPSC_TABLE_PURCHASE_LOGS . "`.`id`=" . $this->purchlogid;
  794. $extrainfo = $wpdb->get_results( $sql );
  795. $this->extrainfo = $extrainfo[0];
  796. $usersql = "SELECT `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`value`, `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`name`, `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`unique_name` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` LEFT JOIN `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ON `" . WPSC_TABLE_CHECKOUT_FORMS . "`.id = `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`form_id` WHERE `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id`=" . $this->purchlogid . " ORDER BY `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`checkout_order`";
  797. $userinfo = $wpdb->get_results( $usersql, ARRAY_A );
  798. foreach ( (array)$userinfo as $input_row ) {
  799. if ( stristr( $input_row['unique_name'], 'shipping' ) ) {
  800. $shippinginfo[$input_row['unique_name']] = $input_row;
  801. } elseif ( stristr( $input_row['unique_name'], 'billing' ) ) {
  802. $billingdetails[$input_row['unique_name']] = $input_row;
  803. } else {
  804. $additionaldetails[$input_row['name']] = $input_row;
  805. }
  806. }
  807. $this->userinfo = $billingdetails;
  808. $this->shippinginfo = $shippinginfo;
  809. if ( isset( $additionaldetails ) ) {
  810. $this->customcheckoutfields = $additionaldetails;
  811. }
  812. $this->purch_item_count = count( $cartcontent );
  813. }
  814. function next_purch_item() {
  815. $this->currentitem++;
  816. $this->purchitem = $this->allcartcontent[$this->currentitem];
  817. return $this->purchitem;
  818. }
  819. function the_purch_item() {
  820. $this->purchitem = $this->next_purch_item();
  821. }
  822. function have_purch_item() {
  823. if ( $this->currentitem + 1 < $this->purch_item_count ) {
  824. return true;
  825. } else if ( $this->currentitem + 1 == $this->purch_item_count && $this->purch_item_count > 0 ) {
  826. // Do some cleaning up after the loop,
  827. $this->rewind_purch_item();
  828. }
  829. return false;
  830. }
  831. function rewind_purch_item() {
  832. $this->currentitem = -1;
  833. if ( $this->purch_item_count > 0 ) {
  834. $this->purchitem = $this->allcartcontent[0];
  835. }
  836. }
  837. function have_downloads_locked() {
  838. global $wpdb;
  839. $sql = "SELECT `ip_number` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE purchid=" . $this->purchlogid;
  840. $ip_number = $wpdb->get_var( $sql );
  841. return $ip_number;
  842. }
  843. }
  844. ?>