forked from levelsix/MercInc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoprealestatelist.php
349 lines (303 loc) · 15.6 KB
/
shoprealestatelist.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
include_once 'topmenu.php';
include_once("classes/RealEstate.php");
include_once ('properties/constants.php');
include_once ('classes/Utils.php');
include_once ('classes/lvl6MemCache.php');
$shopREMinLevel = 4;
if(isset($_SESSION['levelError']))
{
echo $_SESSION['levelError'];
unset($_SESSION['levelError']);
exit;
}
else if ($playerLevel<$shopREMinLevel)
{
$tooLowLevelString = '<div class="natsays">
<h2>Real Estate</h2>
<p><strong>Natalie says:</strong></p>
<p>"You need more experience before you can buy properties."</p>
<p>"Come back at LVL '.$shopREMinLevel.'"</p>
<a href="'.$serverRoot.'choosemission.php" class="blackyellowbutton notready">Missions</a>
</div>';
echo $tooLowLevelString;
exit;
}
function calculatePrice($original_price, $last_purchase_price, $previouse_quantity, $quantity) {
$total_amount = 0;
for($i = $previouse_quantity; $i < ($previouse_quantity + $quantity); $i++){
$price = $original_price + (INCREASE_REAL_ESTATE_PERCENTAGE * $original_price) * $i;
$total_amount += $price;
}
return $total_amount;
}
function realEstateIsLocked($re, $playerLevel) {
if ($re->getMinLevel() == ($playerLevel + 1)) {
return true;
}
return false;
}
function displayLockedRealEstates($lockedRealEstates){
$html = '';
foreach($lockedRealEstates as $lRealEstate){
$html .= '<div class="pieceequipment realestate lockedup">
<div class="equipmentimage">
<img src="img/biglock.png" />
</div>
<div class="equipmentinfo">
<h4>'.$lRealEstate->getName().'</h4>
<h5>Unlock at LVL '.$lRealEstate->getMinLevel().'</h5>
<ul>
<li class="inactive">
<p class="inactivebutton">Buy</p>
</li>
<li class="inactive">
<p class="inactivebutton">Sell</p>
</li>
</ul>
</div>
</div>';
}
echo $html;
}
$userRealEstateIDsToQuantity = User::getUsersRealEstateIDsToQuantity($_SESSION['userID']);
if(isset($_GET['error'])){
$realEstateId = $_GET['itemID'];
$previousQuanity = $_GET['previousQuanity'];
$quantity = $_GET['quantity'];
$estate_data = RealEstate::getRealEstate($realEstateId);
$estate_name = $estate_data->getName();
$originalPrice = $estate_data->getPrice();
$realEstatePrice = $_GET['purchasePrice'];
$estPrice = $realEstatePrice * $quantity;
$diamondsArr = calculateNumDiamondsToCash($estPrice,$user->getCash(),$user->getLevel());
$notifications = '';
if($_GET['error'] == "true"){
$notifications .='<div id="notification">
<div class="needenergy">
<h2>You don\'t have the cash!</h2>
<p class="whatyouneed">You don\'t have enough cash to buy '.$quantity.'x '. $estate_name.'.</p>
<div class="refillinfo">
<h4>Recieve <span class="cost"> $'.$diamondsArr['cashForDiamonds'].'</span></h4>
<p>For <strong>'.$diamondsArr['numDiamonds'].'</strong> Diamonds</p>
</div>';
if($user->getDiamonds() >= $diamondsArr['numDiamonds'])
{
$notifications .='<div class="refillaccept">
<a href="'.$serverRoot.'backend/blackmarket.php?update_cash='.$diamondsArr['cashForDiamonds'].'&page=shoprealestatelist.php?&itemID='.$realEstateId.'&diamonds='.$diamondsArr['numDiamonds'].'&previousQuanity='.$previousQuanity.'&quantity='.$quantity.'&purchasePrice='.$realEstatePrice.'&originalPrice='.$originalPrice.'" class="greenbutton accepttrade">Accept Trade</a>
</div>';
}
else
{
$pageURL = $serverRoot.'backend/blackmarket.php?update_cash='.$diamondsArr['cashForDiamonds'].'&page=shoprealestatelist.php?&itemID='.$realEstateId.'&diamonds='.$diamondsArr['numDiamonds'].'&previousQuanity='.$previousQuanity.'&quantity='.$quantity.'&purchasePrice='.$realEstatePrice.'&originalPrice='.$originalPrice;
$redirectURL = $serverRoot.'backend/blackmarket.php?update_cash='.$diamondsArr['cashForDiamonds'].'&from=google&page='.base64_encode('shoprealestatelist.php?itemID='.$realEstateId.'&diamonds='.$diamondsArr['numDiamonds'].'&previousQuanity='.$previousQuanity.'&quantity='.$quantity.'&purchasePrice='.$realEstatePrice.'&originalPrice='.$originalPrice);
if(strtolower($_SESSION['device_os']) != 'android'){
$notifications .='<div class="refillaccept">
<a href="javascript:" onclick="purchaseDiamonds(\''.$pageURL.'\');" class="greenbutton accepttrade">Accept Trade</a></div>';
}else{
$notifications .='<div class="refillaccept">
<a href="javascript:" onclick="purchaseDiamonds(\''.$redirectURL.'\');" class="greenbutton accepttrade">Accept Trade</a></div>';
}
}
$notifications .= '</div></div>';
echo $notifications;
} else if( ($_GET['error'] == 'false') && ($_GET['action'] == 'buy')){
$previousQuanity = $_GET['previousQuanity'];
$quantity = $_GET['quantity'];
$newPrice = $originalPrice + (INCREASE_REAL_ESTATE_PERCENTAGE*$originalPrice)*($quantity+$previousQuanity);
?>
<div id="notification">
<div class="successmessage">
<h2>Success!</h2>
<form method="GET" action ="<?php echo $serverRoot; ?>backend/shoprealestateaction.php">
<input type="hidden" name="userCash" value="<?php echo $playerCash;?>" />
<input type="hidden" name="realEstateID" value="<?php echo $realEstateId;?>" />
<input type="hidden" name="purchasePrice" value="<?php echo $realEstatePrice;?>" />
<input type="hidden" name="originalPrice" value="<?php echo $originalPrice;?>" />
<input type="hidden" name="actionToDo" value="buy" />
<input type="hidden" name="previousQuanity" value="<?php echo ($previousQuanity + $quantity); ?>" />
<input type="hidden" name="originalPrice" value="<?php echo $originalPrice; ?>" />
<p class="whatyouneed">You bought <?php echo $quantity.' '.$estate_name; ?> for $<?php echo $realEstatePrice; ?>.</p>
<a class="blackbutton successbuymore" id="toggleButton">Buy more</a>
<div id="toggleSection" class="buymore" style="display:none">
<p class="buymore">Buy
<select name="quantity" onchange="calculatePrice(<?php echo $originalPrice; ?>, <?php echo $realEstatePrice;?>, <?php echo ($previousQuanity + $quantity); ?>, this.value)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="250">250</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
more for <span class="m" id="m">$<?php echo $newPrice; ?></span><input type="submit" value="Buy" /></p>
</div>
</form>
</div>
</div>
<?php
}
else if($_GET['action'] == "sell" && $_GET['error'] == "false" ) {
?>
<div id="notification">
<div class="successmessage" style="display:visible; " >
<h2>Success!</h2>
<p class="whatyouneed">You Sold <?php echo $estate_name; ?> for $<?php echo $realEstatePrice * 0.6; ?>.</p>
</div>
</div>
<?php
}
}
else if (isset($_GET['status']) && $_GET['status']== "refill") {
global $userRealEstateIDsToQuantity;
global $user;
$estateId = $_GET['itemID'];
$estate_data = RealEstate::getRealEstate($estateId);
$estate_name = $estate_data->getName();
$originalPrice = $estate_data->getPrice();
$quantity = 0;
if ($userRealEstateIDsToQuantity && array_key_exists($estateId, $userRealEstateIDsToQuantity)) {
$quantity = $userRealEstateIDsToQuantity[$estateId];
}
$estatePrice = $originalPrice + (INCREASE_REAL_ESTATE_PERCENTAGE*$originalPrice)*$quantity;
$previousQuanity = $_GET['previousQuanity'];
$buy_quantity = $_GET['quantity'];
$realEstatePrice = $_GET['purchasePrice'];
$requestURL = $serverRoot.'backend/shoprealestateaction.php?actionToDo=buy&previousQuanity='.$previousQuanity.'&quantity='.$buy_quantity.'&userCash='.$user->getCash().'&purchasePrice='.$realEstatePrice.'&realEstateID='.$estateId.'&originalPrice='.$originalPrice;
echo '
<div class="successmessage">
<p class="successfailuremessage"><span class="success line_height_3" >Congratuations! </span> You have successfully bought <span class="cost">$'.$_GET['cash'] .'</span> for <strong>'.$_GET['diamonds'].'</strong> Diamonds<a href="'.$requestURL.'" class="notification_domission">Buy Estate</a></p>
</div>';
}
$lockedRealEstates = array_values(RealEstate::getLockedRealEstate($playerLevel));
?>
<div class="equipment">
<div class="realestatetop">
<h2>Real Estate</h2>
<p>Income: <span class="income">$<?php echo $PlayerIncome; ?></span> / Upkeep: <span class="upkeep">$<?php echo $PlayerUpkeep; ?></span></p>
</div>
<div class="cashflowinfo">
<p>Cash flow: <strong>$<?php echo ($PlayerIncome - $PlayerUpkeep); ?> </strong> every 60 minutes</p>
</div>
<?php if(sizeof($lockedRealEstates) > 0){ ?>
<p class="unlock2"><span>Unlock more Real Estate at LVL <?php echo $lockedRealEstates[0]->getMinLevel(); ?></span></p>
<?php
}
?>
<?php
$realEstateIDsToRealEstates = RealEstate::getRealEstateIDsToRealEstatesVisibleInShop($playerLevel);
$num = count($realEstateIDsToRealEstates);
if ($num == 0) {
echo "No real estate available.";
} else {
$html = '';
$userRealEstateIDsToQuantity = User::getUsersRealEstateIDsToQuantity($_SESSION['userID']);
foreach ($realEstateIDsToRealEstates as $realEstateID => $realEstate) {
$quantity = 0;
if ($userRealEstateIDsToQuantity && array_key_exists($realEstateID, $userRealEstateIDsToQuantity)) {
$quantity = $userRealEstateIDsToQuantity[$realEstate->getID()];
}
$realEstatePrice = $realEstate->getPrice() + (INCREASE_REAL_ESTATE_PERCENTAGE*$realEstate->getPrice())*$quantity;
$html .= '<div class="pieceequipment realestate">
<div class="equipmentimage">
<img src="'.$realEstate->getImage().'" />
<h5>Income: <strong>$'.$realEstate->getIncome().'</strong></h5>
</div>
<div class="equipmentinfo">
<h4>'.$realEstate->getName().'</h4> ';
$html .= '<ul>
<li class="buy">$'.$realEstatePrice.'<br />
<a href="'.$serverRoot.'backend/shoprealestateaction.php?actionToDo=buy&previousQuanity='.$quantity.'&quantity=1&userCash='.$playerCash.'&purchasePrice='.$realEstatePrice.'&realEstateID='.$realEstateID.'&originalPrice='.$realEstate->getPrice().'">Buy</a>
</li>
<li class="sell">
Owned: '.$quantity.'<br />';
if ($quantity >= 1 && !realEstateIsLocked($realEstate, $playerLevel)) {
$previousPrice = $realEstatePrice - ($realEstatePrice * .1);
$html .= '<a href="'.$serverRoot.'backend/shoprealestateaction.php?
actionToDo=sell&
sellBasePrice='.$previousPrice.'&
previousQuanity='.$quantity.'&
userCash='.$playerCash.'&
purchasePrice='.($realEstate->getPrice() + (INCREASE_REAL_ESTATE_PERCENTAGE*$realEstate->getPrice()*($quantity-1))).'&
realEstateID='.$realEstateID.'">Sell</a>';
} else {
$html .= '<p class="inactivebutton">Sell</p>';
}
$html .= '</li>
</ul>
</div>
</div>';
}
echo $html;
}
displayLockedRealEstates($lockedRealEstates);
?>
</div>
<script language="javascript">
$(document).ready(function() {
$('#toggleButton').click(function() {
$('#toggleSection').toggle();
return false;
});
});
function calculatePrice(original_price, last_purchase_price, previouse_quantity, quantity) {
var total_amount = 0;
for(var i = parseInt(previouse_quantity); i < (parseInt(previouse_quantity) + parseInt(quantity)); i++){
var price = parseInt(original_price) + (<?php echo INCREASE_REAL_ESTATE_PERCENTAGE; ?> * parseInt(original_price)) * i;
total_amount += parseInt(price);
}
$('#m').html('$'+total_amount);
}
</script>
<div style="display: none;">
<div id="inline1" style=""></div>
</div>
<a class="inlinecontent abshide" href="#inline1"> </a>
<script type="text/javascript">
function purchaseDiamond(diamondToAdd)
{
<?php if(isset($_SESSION['legacy'])){ ?>
window.location = "level6://develop.com?call=purchaseDiamondsForProductId:¶m="+diamondToAdd;
//window.location = "level6://develop.com?call=purchaseDiamonds:¶m="+diamondToAdd;
<?php } else { ?>
displayAlertJS("Please update your current version to make in-app purchases");
<?php } ?>
//var path = '<?php echo $serverRoot; ?>backend/blackmarket.php?update_diamond=true'+"&diamonds="+diamondToAdd;
//window.location.href = path;
//exit;
}
function purchaseDiamonds(pageURL)
{
<?php
global $user;
$requiredDiamonds = ($diamondsArr['numDiamonds'] - $user->getDiamonds());
$diamonCost = getPurchasedNumDiamondsCost($requiredDiamonds);
?>
<?php if(strtolower($_SESSION['device_os']) != 'android'){ ?>
$('#inline1').html('<h5 class="popupweaponheader">Purchase Diamonds</h5><br/><p>You don\'t have enough Diamonds </p><p>Buy <?php echo $diamonCost['numberOfDiamonds']; ?> diamonds for $<?php echo $diamonCost['costOfDiamonds']; ?> only</p><div class="popupbuy" style="margin:10px auto 0 auto;width:80%;"> <a href="javascript:" onClick="purchase(\''+pageURL+'\');" class="blackbutton popupbuybutton">Buy</a><a href="javascript:" onClick="closePopUp()" class="blackbutton popupbuybutton">Cancel</a> </div>');
<?php } else { ?>
$('#inline1').html('<h5 class="popupweaponheader">Purchase Diamonds</h5><br/><p>You don\'t have enough Diamonds </p><p>Buy <?php echo $diamonCost['numberOfDiamonds']; ?> diamonds for only $<?php echo $diamonCost['costOfDiamonds']; ?>!</p><div class="popupbuy" style="margin:10px auto 0 auto;width:80%;"> <a href="<?php echo $serverRoot.'googlecheckout/checkout_redirect.php'; ?>?item_name=<?php echo $diamonCost['numberOfDiamonds'].' Diamonds '; ?>&item_description=<?php echo 'Buy' .$diamonCost['numberOfDiamonds'].' Diamonds for '.$diamonCost['costOfDiamonds']; ?>&diamonds_to_add=<?php echo $diamonCost['numberOfDiamonds']; ?>&price=<?php echo $diamonCost['costOfDiamonds']; ?>&udid=<?php echo $_SESSION['udid']; ?>&callback_url='+pageURL+'" class="blackbutton popupbuybutton">Buy</a><a href="javascript:" onClick="closePopUp()" class="blackbutton popupbuybutton">Cancel</a> </div>');
<?php } ?>
// <a href="javascript:" onClick="closePopUp()" class="blackbutton popupbuybutton">Cancel</a>
$('.abshide').click();
}
function closePopUp()
{
$('#fancybox-close').click();
}
function purchase(url)
{
$('#fancybox-close').click();
$('#notification').html('');
redirectURL = url;
purchaseDiamond("<?php echo $diamonCost['packageID']; ?>");
}
</script>
<?php
include_once 'footer.php';
?>