previewgift.pl
148 lines of code
1
#!/usr/local/bin/perl
2
3
# FOR THE MOMENT, GIFTS ARE DISABLED...
4
5
# must have's!
6
use strict;
7
use warnings;
8
use CGI::Carp qw(fatalsToBrowser);
9
use DBI;
10
use URI::Escape;
11
12
use lib "/var/www/html/Pm";
13
14
use Date qw(isNew get_today expand_date isBeforeToday isAfterToday);
15
use Html qw(pre_html_header header);
16
use Bc_chef qw(cookie_get);
17
use Bc_misc qw(get_param commafied shorten_str);
18
use Bc_sql qw(sql_execute
19
              get_constant
20
21
              $DB
22
              $QUERY_PAGE
23
             );
24
25
my $DEBUG = 0;
26
my $DEBUG_PP = 0;
27
my $PP_server = "www.paypal.com";
28
my $PP_server = "www.paypal.com";
29
my $email = "jamroll1976\@gmail.com";
30
if ($DEBUG_PP) {
31
  $PP_server = "www.sandbox.paypal.com";
32
  $email = "jamroll1976-facilitator\@gmail.com";
33
}
34
35
my $gid = get_param("gid");
36
37
my $sql = "select * from gifts where ID = " . $DB->quote($gid);
38
my $ref = sql_execute($sql, "previewgift.pl");
39
my $available = 1;
40
41
# aha! this grabs the gifts in the database.
42
# this is mostly correct.  if the date in the
43
# expires column for this gift has passed, then
44
# the gift should not be displayed, or at least
45
# it should not be purchasable.  Must enhance
46
# pp_ipn.pl to reflect this, too!  eek.
47
48
my $giftDescHeight = "120px";
49
my $giftWidth = "200px";
50
51
my $output = pre_html_header() . header("Gift Preview", "", "", "\" style=\"margin: 0px 0px 0px 2px; padding: 0px;", "A small script to preview a gift's contents");
52
53
if (isBeforeToday($ref->{expires}) and $ref->{expires} ne "1901-01-01") {
54
  $available = 0;
55
}
56
57
if ($available) {
58
  $output .= "<table align=center border=0 cellpadding=0 cellspacing=0 style='overflow-x: hidden; overflow-y: hidden; max-width: $giftWidth; max-height: $giftDescHeight; min-width: $giftWidth; min-height: $giftDescHeight;'><tr><td align=center valign=top height=1 colspan=3>\n";
59
60
  if ($DEBUG) {
61
    $output .= "    id: $ref->{ID}<br>\n";
62
    $output .= "    $ref->{filename}<br>\n";
63
    $output .= "    $ref->{date_added}<br>\n";
64
    $output .= "    " . get_today("db", 1) . ": " . isNew($ref->{date_added}) . "<br>\n";
65
  } else {
66
    $output .= "  <table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td>\n";
67
    my $shortened = shorten_str($ref->{name}, 18);
68
    $output .= "    <b>$shortened</b>\n";
69
    if (isNew($ref->{date_added}) or
70
        $ref->{expires} ne "1901-01-01") {
71
      $output .= "  </td><td width=5></td><td width=1><div class=subnavbar style='margin: 2px 5px 0px 0px; padding: 0px 0px 0px 0px; white-space: nowrap;'> \n";
72
      if (isNew($ref->{date_added})) { $output .= "    <sup><img src='images/site/new.png' height=16 title='Gift recently added to the store!'></sup>\n"; }
73
      if ($ref->{expires} ne "1901-01-01") {
74
        $output .= "    <sup><img src='images/site/timeline.png' height=16 title='This gift disappears forever " . expand_date($ref->{expires}) . "!'></sup>\n";
75
      }
76
      $output .= " </div>\n";
77
    }
78
    $output .= "  </td></tr></table>\n";
79
    $output .= "</td></tr><tr><td height=2 colspan=3>\n";
80
    $output .= "</td></tr><tr><td valign=top width=50 onclick='document.location.reload();' onmouseover=\"this.style.cursor='default';\"><div class='subnavbar' style='white-space: nowrap;'>\n";
81
    my $cost = $ref->{cost_dollars};
82
    my ($dollars, $pennies) = split(/\./, $cost);
83
    if ($pennies >= 1 and $pennies <= 9) { $pennies .= "0"; }
84
    if (not $pennies) { $pennies = "00"; }
85
    $pennies = "<sup> " . $pennies . "</sup>\n";
86
    $cost = $dollars . "." . $pennies;
87
    $output .= "  \$<small> </small><b>$cost<br></b>or<b>\n";
88
    $output .= "  $ref->{cost_points}</b><img src='images/orange/coin_single_gold.png' height=16>\n";
89
    $output .= "</div></td></form><td width=5></td><td align=center valign=center>\n";
90
91
    if ($ref->{filename} !~ /\./) {
92
      # it's a reference to another gift ID!
93
      my $item_sql = "select * from gifts where ID = " . $DB->quote($ref->{filename});
94
      my $results = sql_execute($item_sql, "previewgift.pl");
95
      if (ref $results eq "HASH") {
96
        # now, show it...
97
        $output .= "  <img src='images/$results->{filename}' height=16> x " . commafied($ref->{quantity}) . "\n";
98
      } else {
99
        # invalid gift ID?
100
        $output .= "  <img src='images/404.png' height=16> x " . commafied($ref->{quantity}) . "\n";
101
      }
102
    } else {
103
      # now, show it...
104
      $output .= "  <img src='images/$ref->{filename}' height=16> x " . commafied($ref->{quantity}) . "\n";
105
    }
106
107
    if ($ref->{filename2} !~ /\./ and $ref->{filename2} ne "") {
108
      # it's a reference to another gift ID! (a giftbox item)
109
      my $item_sql = "select * from gifts where ID = " . $DB->quote($ref->{filename2});
110
      my $results = sql_execute($item_sql, "previewgift.pl");
111
      if (ref $results eq "HASH") {
112
        # now, show it...
113
        $output .= "  <img src='images/$results->{filename}' height=16> x " . commafied($ref->{quantity2}) . "\n";
114
      } else {
115
        # invalid gift ID?
116
        $output .= "  <img src='images/404.png' height=16> x " . commafied($ref->{quantity2}) . "\n";
117
      }
118
    }
119
  }
120
121
  $output .= "</td></tr><tr><td colspan=3 height=8>\n";
122
  $output .= "</td></tr><tr><form action='https://$PP_server/cgi-bin/webscr' method=post target=_top><td align=center colspan=3>\n";
123
  $output .= "  <input type=hidden name='cmd' value='_xclick'>\n";
124
  $output .= "  <input type=hidden name='custom' value='" . get_login($db) . "'>\n";
125
  $output .= "  <input type=hidden name='business' value='$email'>\n";
126
  $output .= "  <input type=hidden name='currency_code' value='CAD'>\n";
127
  $output .= "  <input type=hidden name='amount' value='$ref->{cost_dollars}'>\n";
128
  $output .= "  <input type=hidden name='item_name' value='$ref->{name}'>\n";
129
  $output .= "  <input type=hidden name='item_number' value='$ref->{ID}'>\n";
130
  $output .= "  <input type=hidden name='no_shipping' value='1'>\n";
131
  $output .= "  <input type=hidden name='undefined_quantity' value='1'>\n";
132
  $output .= "  <input type=hidden name='notify_url' value='https://www.night-stand.ca/pp_ipn.pl'>\n";
133
  $output .= "  <input type=hidden name='return' value='https://www.night-stand.ca/?$QUERY_PAGE=" . get_constant("STORE_PAGE") . "'>\n";
134
  $output .= "  <input type=hidden name='cancel_return' value='https://www.night-stand.ca/?$QUERY_PAGE=" . get_constant("STORE_PAGE") . "'>\n";
135
  $output .= "  <b>Buy with <button><img src='images/grey/paypal_fulllogo.png' height=20 title='PayPal'></button>\n";
136
  $output .= "  or <button onclick=\"\" type=button><img src='images/orange/coin_single_gold.png' height=20 title='Coins'></button></b>\n";
137
  $output .= "</td></form></tr></table>\n";
138
} else {
139
  $output .= "<table align=center border=0 cellpadding=0 cellspacing=0 style=\"height: $giftDescHeight; width: $giftWidth;\"><tr><td align=center>\n";
140
  $output .= "  <b>$ref->{name}</b> is no longer available for purchase\n";
141
  $output .= "</td></tr></table>\n";
142
}
143
144
$output .= "</body>\n</html>\n";
145
146
print $output;
147
148
exit 1;