/tags/3.6.9/wp-shopping-cart/widgets/donations_widget.php

https://github.com/evadne/wp-e-commerce · PHP · 77 lines · 70 code · 7 blank · 0 comment · 10 complexity · 2dc97d904b07afd6261223e5ebdeb492 MD5 · raw file

  1. <?php
  2. function widget_donations($args) {
  3. global $wpdb, $table_prefix;
  4. extract($args);
  5. $options = get_option('wpsc-nzshpcrt_donations');
  6. $title = empty($options['title']) ? __(TXT_WPSC_DONATIONS) : $options['title'];
  7. $donation_count = $wpdb->get_var("SELECT COUNT(*) AS `count` FROM `".$wpdb->prefix."product_list` WHERE `donation` IN ('1') AND `active` IN ('1')");
  8. if($donation_count > 0) {
  9. echo $before_widget;
  10. $full_title = $before_title . $title . $after_title;
  11. echo $full_title;
  12. nzshpcrt_donations();
  13. echo $after_widget;
  14. }
  15. }
  16. function nzshpcrt_donations($input = null) {
  17. global $wpdb;
  18. $siteurl = get_option('siteurl');
  19. $sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `donation` IN ('1') AND `active` IN ('1')";
  20. $products = $wpdb->get_results($sql,ARRAY_A);
  21. if($products != null) {
  22. $output = "<div><div>";
  23. foreach($products as $product) {
  24. $output .= "<strong>".$product['name']."</strong><br />";
  25. if($product['image'] != null) {
  26. $output .= "<img src='".WPSC_THUMBNAIL_URL.$product['image']."' title='".$product['name']."' alt='".$product['name']."' /><br />";
  27. }
  28. $output .= $product['description']."<br />";
  29. $output .= "<form id='specials' name='$num' method='post' action='#' onsubmit='submitform(this);return false;' >";
  30. $variations_processor = new nzshpcrt_variations;
  31. $output .= $variations_processor->display_product_variations($product['id']);
  32. $output .= "<input type='hidden' name='prodid' value='".$product['id']."'/>";
  33. $output .= "<input type='hidden' name='item' value='".$product['id']."' />";
  34. $currency_sign_location = get_option('currency_sign_location');
  35. $currency_type = get_option('currency_type');
  36. $currency_symbol = $wpdb->get_var("SELECT `symbol_html` FROM `".$wpdb->prefix."currency_list` WHERE `id`='".$currency_type."' LIMIT 1") ;
  37. $output .= "<label for='donation_price_".$product['id']."'>".TXT_WPSC_DONATION.":</label> $currency_symbol<input type='text' id='donation_price_".$product['id']."' name='donation_price' value='".number_format($product['price'],2)."' size='6' /><br />";
  38. $output .= "<input type='submit' name='Buy' value='".TXT_WPSC_ADDTOCART."' />";
  39. $output .= "</form>";
  40. }
  41. $output .= "</div></div>";
  42. } else {
  43. $output = '';
  44. }
  45. echo $input.$output;
  46. }
  47. function widget_donations_control() {
  48. $option_name = 'wpsc-nzshpcrt_donations'; // because I want to only change this to reuse the code.
  49. $options = $newoptions = get_option($option_name);
  50. if ( isset($_POST[$option_name]) ) {
  51. $newoptions['title'] = strip_tags(stripslashes($_POST[$option_name]));
  52. }
  53. if ( $options != $newoptions ) {
  54. $options = $newoptions;
  55. update_option($option_name, $options);
  56. }
  57. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  58. echo "<p>\n\r";
  59. echo " <label for='{$option_name}'>"._e('Title:')."<input class='widefat' id='{$option_name}' name='{$option_name}' type='text' value='{$title}' /></label>\n\r";
  60. echo "</p>\n\r";
  61. }
  62. function widget_donations_init() {
  63. if(function_exists('register_sidebar_widget')) {
  64. register_sidebar_widget(TXT_WPSC_DONATIONS, 'widget_donations');
  65. register_widget_control(TXT_WPSC_DONATIONS, 'widget_donations_control');
  66. }
  67. return;
  68. }
  69. add_action('plugins_loaded', 'widget_donations_init');
  70. ?>