PageRenderTime 28ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

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