previewtheme.pl
168 lines of code
1
#!/usr/local/bin/perl
2
3
# must have's!
4
use strict;
5
use warnings;
6
use CGI::Carp qw(fatalsToBrowser);
7
use DBI;
8
use URI::Escape;
9
10
use lib "/var/www/html/Pm";
11
12
use Html qw(pre_html_header header img);
13
use Redir qw(error_redir);
14
use User qw(isUserSubscriber isUserAdmin $USER_DATA);
15
use Bc_chef qw(cookie_get cookie_delete);
16
use Bc_misc qw(get_param);
17
use Bc_sql qw(
18
              get_constant
19
              sql_execute
20
              user_exists
21
              get_login
22
23
              $QUERY_PAGE
24
              $QUERY_UID
25
              $LOGGEDIN
26
27
              $DB
28
             );
29
30
use Security qw(banned);
31
32
my $DEBUG = get_constant("DEBUG_PAYPAL");
33
if (not user_exists($LOGGEDIN) or banned($LOGGEDIN)) {
34
  my $msg =  "Access Denied";
35
  if ($DEBUG) { $msg .= " (previewtheme.pl)"; }
36
  print error_redir("/", $msg);
37
38
  exit 1;
39
}
40
41
my $BORDERS = 0;
42
my $PP_server = 'www.paypal.com'; # production IP:173.0.88.40
43
my $PP_server_ip = '173.0.88.40';
44
if ($DEBUG) {
45
  $PP_server = 'www.sandbox.paypal.com'; # sandbox IP:173.0.82.66
46
  $PP_server_ip = '173.0.82.66';
47
}
48
49
my $email = get_constant("PP_EMAIL");
50
my $tid = get_param("tid");
51
my $sql = "select * from themes where ID = " . $DB->quote($tid);
52
my $ref = sql_execute($sql, "previewtheme.pl");
53
my $available = 1;
54
55
my $e = cookie_get("e");
56
my $n = cookie_get("n");
57
my $onLoad .= "setTimeout(removeMsg, 6000);";
58
59
if (not $e and not $n) {
60
  $onLoad = "";
61
} else {
62
  print cookie_delete("e");
63
  print cookie_delete("n");
64
}
65
66
##########
67
my $output = header("Theme Preview", "?tid=$tid", "", $onLoad . "\" style=\"height: 95%;", "A small script to preview how a theme will look");
68
##########
69
70
$output .= "<table align=center border=$BORDERS cellpadding=0 cellspacing=0 height=280 width=355><tr><td align=center>\n";
71
if (ref $ref ne "HASH") {
72
  $output .= "    <div class=danger><img src=\"/images/site/arrow_prev.png\" height=24 onclick=\"reload();\"> Select a Theme</div>\n";
73
} else {
74
  $output .= "  <table align=center border=$BORDERS cellpadding=0 cellspacing=0 height=100% width=100%><tr><td valign=top align=center>\n";
75
  $output .= "    <table align=center border=$BORDERS cellpadding=0 cellspacing=0><tr><td class=subtitle>Theme Preview</td></tr></table>\n";
76
  $output .= "    <table border=$BORDERS cellpadding=0 cellspacing=0 width=1><tr><td class=notice nowrap align=center>Purchase a theme today<br>and save <b>10\%</b>!</td></tr></table>\n";
77
  $output .= "  </td></tr><tr><td align=center valign=center height=100%>\n";
78
  $output .= "  </td></tr><tr><td align=center>\n";
79
80
  $output .= "    <div id=MSGS class=";
81
  if ($e or $n) {
82
    if ($e) { $output .= "error"; } else { $output .= "notice"; }
83
    $output .= ">\n    ";
84
    $output .= "  ";
85
    if ($e) { $output .= "$e" } else { $output .= "$n"; }
86
    $output .= ">\n    ";
87
  } else {
88
    $output .= "''>";
89
  }
90
  $output .= "</div>\n";
91
  $output .= "  </td></tr><tr><td height=5>\n";
92
  $output .= "  </td></tr><tr><td align=right>\n";
93
94
  # if the user already "owns" this theme, don't show the purchase buttons!
95
  my $sql = "select * from theme_purchases where UID=" . $DB->quote(get_login()) . " and TID=" . $DB->quote($tid);
96
  my $results = sql_execute($sql, "previewtheme.pl");
97
98
  my $cost = $ref->{cost_dollars};
99
  my $cost_coins = $ref->{cost_coins};
100
101
  # here, we need to check for discounts, if any
102
  # for now, though, we're just gonna deduct 10%
103
  # i guess i could use a date scheme - wrap this in an if statement
104
  #if (get_today("", "") < "2018-01-01") {
105
    $cost = $cost - ($cost*0.1);
106
    if ($cost =~ /^([0-9])*\.[0-9]$/) { $cost .= "0"; }
107
    $cost_coins = $cost_coins - int($cost_coins*0.1);
108
  #}
109
110
  $output .= "    <table border=$BORDERS cellpadding=0 cellspacing=0 width=100%><tr>";
111
  if (ref $results ne "HASH" and not isUserAdmin($LOGGEDIN)) {
112
    $output .= "    <td align=center colspan=4>\n";
113
    $output .= "      <b class=notice>\$$cost</b> <b>(CAD)</b>\n";
114
    $output .= "      <b class=notice>$cost_coins</b> " . img("i=orange/coin_single_gold.png", "", "", "height=20 title='Coins'", "\n", 0);
115
    $output .= "    <td align=center colspan=4>\n";
116
    $output .= "      <br><br>\n";
117
    $output .= "    </td></tr><tr><td align=center valign=center nowrap>\n";
118
    $output .= "      <table border=$BORDERS cellpadding=0 cellspacing=0><tr><td>\n";
119
    if (get_constant("PP_ENALBED") eq 2) {
120
      $output .= "        <form action='https://$PP_server/cgi-bin/webscr' method=post target=_top>\n";
121
      $output .= "          <input type=hidden name='cmd' value='_xclick'>\n";
122
      $output .= "          <input type=hidden name='business' value='$email'>\n";
123
      $output .= "          <input type=hidden name='currency_code' value='CAD'>\n";
124
      $output .= "          <input type=hidden name='custom' value='$LOGGEDIN'>\n";
125
      $output .= "          <input type=hidden name='amount' value='$cost'>\n";
126
      $output .= "          <input type=hidden name='item_name' value='$ref->{name} Theme'>\n";
127
      $output .= "          <input type=hidden name='item_number' value='$ref->{ID}'>\n";
128
      $output .= "          <input type=hidden name='no_shipping' value='1'>\n";
129
      $output .= "          <input type=hidden name='notify_url' value='https://night-stand.ca/pp_ipn.pl'>\n";
130
      $output .= "          <input type=hidden name='return' value='https://night-stand.ca/?$QUERY_PAGE=" . get_constant("STORE_PAGE") . "'>\n";
131
      $output .= "          <input type=hidden name='cancel_return' value='https://night-stand.ca/?$QUERY_PAGE=" . get_constant("STORE_PAGE") . "'>\n";
132
      $output .= "          Click  <button>" . img("i=grey/paypal_fulllogo.png", "", "", "height=20 title='PayPal'", "", 0) . "</button>\n";
133
      $output .= "        </form>\n";
134
    } else {
135
      $output .= "          " . img("i=grey/paypal_fulllogo.png", "", "", "height=20 title='PayPal temporarily disabled'", "", 0) . "\n";
136
    }
137
    $output .= "      </td><td nowrap valign=bottom>\n";
138
    $output .= "        <form action='/purchasetheme.pl' method=post>\n";
139
    $output .= "          <input type=hidden name='amount' value='$cost_coins'>\n";
140
    $output .= "          <input type=hidden name='tid' value='$ref->{ID}'>\n";
141
    $output .= "           or   <button>" . img("i=orange/coin_single_gold.png", "", "", "height=20 title='Coins'", "", 0) . "</button>\n";
142
    $output .= "        </form>\n";
143
    $output .= "      </td></tr><tr><td align=center colspan=2>\n";
144
    $output .= "        to purchase theme\n";
145
    $output .= "      </td></tr></table>\n";
146
    $output .= "    </td><td nowrap valign=bottom>\n";
147
  } else {
148
    $output .= "      <small class=description>If you <b>just</b> purchased this theme, please allow <b>1 to 6 minutes</b> for delivery</small><small><br><br></small>\n";
149
    $output .= "    <td align=center valign=center>\n";
150
    $output .= "      <table border=$BORDERS cellpadding=0 cellspacing=0><tr><td class=danger>already purchased</td></tr></table>\n";
151
  }
152
153
  $output .= "      </td><td width=15></td><td align=right height=1 valign=bottom width=1>\n";
154
  $output .= "        <table border=$BORDERS cellpadding=0 cellspacing=0><tr><td class=subnavbar nowrap>\n";
155
  $output .= "          This previews how things<br>will look if you buy this<br> theme and apply it!\n";
156
  $output .= "        </td></tr></table>\n";
157
  $output .= "      </td></tr></table>\n";
158
  $output .= "    </td></tr></table>\n";
159
  $output .= "  </td></tr></table>\n";
160
}
161
162
$output .= "</td></tr></table>\n";
163
$output .= "</body>\n</html>\n";
164
165
print pre_html_header();
166
print $output;
167
168
exit 1;