-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathview_cart.php
215 lines (179 loc) · 7.28 KB
/
view_cart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
session_start();
error_reporting(0);
include ('./config.php');
$total=0;
$albcounter=0;
$trkcounter=0;
$albprice=$downloadCartAlbumPrice;
$trkprice=$downloadCartTrackPrice;
$orderid=microtime(true);
$_SESSION['cart_id']=$orderid;
if (isset($_GET['delete_album'])&&is_numeric($_GET['delete_album'])){
unset($_SESSION['cart']['album'][$_GET['delete_album']]);
$_SESSION['cart']['album']=array_values($_SESSION['cart']['album'] ?? Array());
}
if (isset($_GET['delete_track'])&&is_numeric($_GET['delete_track'])){
unset($_SESSION['cart']['track'][$_GET['delete_track']]);
$_SESSION['cart']['track']=array_values($_SESSION['cart']['track'] ?? Array());
}
?><!DOCTYPE html><html>
<head>
<link rel="shortcut icon" href="<?php echo $favicon;?>" />
<link rel="stylesheet" href="//<?php echo $server; ?>/style.css" type="text/css" media="screen" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="charset" value="utf-8" />
<title>In your cart</title>
<?php
if ($isDownloadCartNameYourPrice){ ?>
<script>
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL Version 3 or later
function initot(){
return parseFloat(document.getElementById('init_total').value);
}
function maxmax(){
mytotal=document.getElementById('total');
myftotal=parseFloat(mytotal.value);
mytotal.value=myftotal+(parseFloat('0.2')*parseFloat(initot()));
round_total();
}
function max_(){
mytotal=document.getElementById('total');
myftotal=parseFloat(mytotal.value);
mytotal.value=myftotal+(parseFloat('0.05')*parseFloat(initot()));
round_total();
}
function minmin(){
mytotal=document.getElementById('total');
myftotal=parseFloat(mytotal.value);
mytotal.value=myftotal-(parseFloat('0.2')*parseFloat(initot()));
round_total();
}
function min_(){
mytotal=document.getElementById('total');
myftotal=parseFloat(mytotal.value);
mytotal.value=myftotal-(parseFloat('0.05')*parseFloat(initot()));
round_total();
}
function round_total(){
mytotal=document.getElementById('total');
myftotal=parseFloat(mytotal.value);
myftotal=parseFloat(myftotal*100);
myftotal=parseFloat(Math.round(myftotal));
myftotal=parseFloat(myftotal/100);
if (myftotal<0){
myftotal=0
}
mytotal.value=myftotal;
}
function floor_tot(){
mytotal=document.getElementById('total');
myftotal=parseFloat(mytotal.value);
myftotal=Math.floor(myftotal);
mytotal.value=myftotal;
}
function compute_total(){
if (document.getElementById('total')!=null){
if (!isNaN(parseFloat(document.getElementById('total').value))){
document.getElementById('amount').value=document.getElementById('total').value.replace(',','.');
if (parseFloat(document.getElementById('amount').value)>0){
document.getElementById('paypal_form').submit();
}
else {
document.getElementById('dl').click();
}
}
else{
alert('please enter a numeric value with a dot ( . ) for decimal separation');
}
}
}
// @license-end
</script>
<?php } else { ?>
<script>
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL Version 3 or later
function compute_total(){
document.getElementById('paypal_form').submit();
}
// @license-end
</script>
<?php } ?>
</head>
<body>
<a href="./">< Go back to the site</a><br/>
<h1>In your cart</h1>
<?php echo count($_SESSION['cart']['album'] ?? Array());?>
albums and
<?php echo count($_SESSION['cart']['track'] ?? Array());?>
individual tracks
<h2>Albums : </h2>
<?php
foreach ($_SESSION['cart']['album'] as $alb){
echo '<h4 style="display:inline;">'.$alb['title'].'</h4><span style="float:right;">';
echo count($alb['tracklist'] ?? Array()).' tracks';
$total=$total+$albprice;
echo ' <a href="?delete_album='.$albcounter.'">X Delete</a></span>';
echo '<hr/>';
$albcounter++;
}
?>
<h2>Tracks : </h2>
<?php
foreach ($_SESSION['cart']['track'] as $trk){
echo '<h4 style="display:inline;">'.$trk['title'].'</h4> by <strong>'.$trk['artist'].'</strong><br/>On <em>'.$trk['album'].'</em><span style="float:right;">';
$total=$total+$trkprice;
echo ' <a href="?delete_track='.$trkcounter.'">X Delete</a></span>';
echo '<hr/>';
$trkcounter++;
}
echo '<hr/> '.count($_SESSION['cart']['album'] ?? Array()).' times '.htmlspecialchars($downloadCartCurrency.' '.$albprice).' (full albums) plus '.count($_SESSION['cart']['track'] ?? Array()).' times '.htmlspecialchars($downloadCartCurrency.' '.$trkprice).' (individual tracks)';
echo '<span style="float:right;"><strong>TOTAL: </strong>';
$payment=true;
if (count($_SESSION['cart']['album'] ?? Array())>0 || count($_SESSION['cart']['track'] ?? Array())>0) {//we got more than 0 item in the cart, let's go
if ($isDownloadCartNameYourPrice){
echo 'Choose what you want to pay<br/>';
echo '<a href="javascript:void(0);" onclick="minmin()">[--]</a> <a href="javascript:void(0);" onclick="min_()">[-]</a>';
echo htmlspecialchars($downloadCartCurrency). ' ';
echo' <input id="total" style="text-align:right;" size="7" type="text" readonly value="';
echo htmlspecialchars($total);
echo '">';
echo '<input id="init_total" type="hidden" value="'.htmlspecialchars($total).'"/>';
echo '<a href="javascript:void(0);" onclick="max_()">[+]</a> <a href="javascript:void(0);" onclick="maxmax()">[++]</a><br/><span style="float:right;font-size:84%;">Name your price, no minimum <a href="javascript:void(0);" onclick="floor_tot()">remove decimals</a></span>';
}
else{
echo htmlspecialchars($downloadCartCurrency). ' ';
echo htmlspecialchars($total);
}
}
else {//we got 0 item in the cart, display a warning
echo '<strong>You got 0 items in your download cart. Please <a href="./">go back and browse the site</a> to select songs or albums that you want to download, and try again then. </strong>';
if ($isDownloadCartNameYourPrice){
echo '<h3>The price is only a suggested donation. You pay what you want, including 0. It\'s "<strong>Name your price, no minimum</strong>".</h3>';
}
$payment=false;
}
echo '</span>';
if ($payment) {
?>
<hr/>
<button style="float:right;" onClick="compute_total();" type="button">Proceed to payment</button>
<form id="paypal_form" name="_xclick" action="https://www.paypal.com/fr/cgi-bin/webscr" method="post" >
<input type="hidden" id="cmd" name="cmd" value="_xclick" />
<input type="hidden" name="custom" value="<?php echo microtime(true);?>"/>
<input type="hidden" name="business" value="<?php echo htmlspecialchars($downloadCartPaypalAddress);?>" />
<input type="hidden" name="item_name" value="<?php echo htmlspecialchars($sitename); ?> - D/l Order <?php echo $orderid ?>" />
<input type="hidden" name="currency_code" value="<?php echo htmlspecialchars($downloadCartCurrency);?>" />
<input type="hidden" id="amount" name="amount" value="<?php echo htmlspecialchars($total);?>" />
<input type="hidden" name="return" value="http://<?php echo htmlspecialchars($server);?>/download-page.php"/>
<input type="hidden" name="rm" value="1"/>
<input type="hidden" name="cancel_return" value="http://<?php echo htmlspecialchars($server);?>"/>
</form>
<?php
}
if ($isDownloadCartNameYourPrice){ ?>
<a id="dl" href="download_page.php"></a>
<?php } ?>
</body>
</html>