mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-04-29 18:59:21 +02:00
You can now view shop offers without being logged in.
(This is also configurable if config.php if you don't want this behavior).
This commit is contained in:
parent
1b93b11f2c
commit
f47e12a610
@ -890,6 +890,7 @@
|
||||
// If useDB is set to true, player can shop in-game as well using Znote LUA shop system plugin.
|
||||
$config['shop'] = array(
|
||||
'enabled' => false,
|
||||
'loginToView' => false, // Do user need to login to see the shop offers?
|
||||
'enableShopConfirmation' => true, // Verify that user wants to buy with popup
|
||||
'useDB' => false, // Fetch offers from database, or the below config array
|
||||
'showImage' => true,
|
||||
|
158
shop.php
158
shop.php
@ -1,6 +1,5 @@
|
||||
<?php require_once 'engine/init.php';
|
||||
protect_page();
|
||||
include 'layout/overall/header.php';
|
||||
include 'layout/overall/header.php';
|
||||
|
||||
if (isset($_GET['callback']) && $_GET['callback'] === 'processing') {
|
||||
echo '<script>alert("Seu pagamento está sendo processado pelo PagSeguro...");</script>';
|
||||
@ -8,64 +7,69 @@ if (isset($_GET['callback']) && $_GET['callback'] === 'processing') {
|
||||
|
||||
// Import from config:
|
||||
$shop = $config['shop'];
|
||||
if ($shop['loginToView'] === true) protect_page();
|
||||
$loggedin = user_logged_in();
|
||||
|
||||
$shop_list = $config['shop_offers'];
|
||||
|
||||
if (!empty($_POST['buy']) && $_SESSION['shop_session'] == $_POST['session']) {
|
||||
$time = time();
|
||||
$player_points = (int)$user_znote_data['points'];
|
||||
$cid = (int)$user_data['id'];
|
||||
// Sanitizing post, setting default buy value
|
||||
$buy = false;
|
||||
$post = (int)$_POST['buy'];
|
||||
|
||||
foreach ($shop_list as $key => $value) {
|
||||
if ($key === $post) {
|
||||
$buy = $value;
|
||||
if ($loggedin === true) {
|
||||
if (!empty($_POST['buy']) && $_SESSION['shop_session'] == $_POST['session']) {
|
||||
$time = time();
|
||||
$player_points = (int)$user_znote_data['points'];
|
||||
$cid = (int)$user_data['id'];
|
||||
// Sanitizing post, setting default buy value
|
||||
$buy = false;
|
||||
$post = (int)$_POST['buy'];
|
||||
|
||||
foreach ($shop_list as $key => $value) {
|
||||
if ($key === $post) {
|
||||
$buy = $value;
|
||||
}
|
||||
}
|
||||
if ($buy === false) die("Error: Shop offer ID mismatch.");
|
||||
|
||||
// Verify that user can afford this offer.
|
||||
if ($player_points >= $buy['points']) {
|
||||
$data = mysql_select_single("SELECT `points` FROM `znote_accounts` WHERE `account_id`='$cid';");
|
||||
if (!$data) die("0: Account is not converted to work with Znote AAC");
|
||||
$old_points = $data['points'];
|
||||
if ((int)$old_points != (int)$player_points) die("1: Failed to equalize your points.");
|
||||
// Remove points if they can afford
|
||||
// Give points to user
|
||||
$expense_points = $buy['points'];
|
||||
$new_points = $old_points - $expense_points;
|
||||
$update_account = mysql_update("UPDATE `znote_accounts` SET `points`='$new_points' WHERE `account_id`='$cid'");
|
||||
|
||||
$data = mysql_select_single("SELECT `points` FROM `znote_accounts` WHERE `account_id`='$cid';");
|
||||
$verify = $data['points'];
|
||||
if ((int)$old_points == (int)$verify) die("2: Failed to equalize your points.". var_dump((int)$old_points, (int)$verify, $new_points, $expense_points));
|
||||
|
||||
// Do the magic (insert into db, or change sex etc)
|
||||
// If type is 2 or 3
|
||||
if ($buy['type'] == 2) {
|
||||
// Add premium days to account
|
||||
user_account_add_premdays($cid, $buy['count']);
|
||||
echo '<font color="green" size="4">You now have '.$buy['count'].' additional days of premium membership.</font>';
|
||||
} else if ($buy['type'] == 3) {
|
||||
// Character Gender
|
||||
mysql_insert("INSERT INTO `znote_shop_orders` (`account_id`, `type`, `itemid`, `count`, `time`) VALUES ('$cid', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '$time')");
|
||||
echo '<font color="green" size="4">You now have access to change character gender on your characters. Visit <a href="myaccount.php">My Account</a> to select character and change the gender.</font>';
|
||||
} else if ($buy['type'] == 4) {
|
||||
// Character Name
|
||||
mysql_insert("INSERT INTO `znote_shop_orders` (`account_id`, `type`, `itemid`, `count`, `time`) VALUES ('$cid', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '$time')");
|
||||
echo '<font color="green" size="4">You now have access to change character name on your characters. Visit <a href="myaccount.php">My Account</a> to select character and change the name.</font>';
|
||||
} else {
|
||||
mysql_insert("INSERT INTO `znote_shop_orders` (`account_id`, `type`, `itemid`, `count`, `time`) VALUES ('$cid', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '$time')");
|
||||
echo '<font color="green" size="4">Your order is ready to be delivered. Write this command in-game to get it: [!shop].<br>Make sure you are in depot and can carry it before executing the command!</font>';
|
||||
}
|
||||
|
||||
// No matter which type, we will always log it.
|
||||
mysql_insert("INSERT INTO `znote_shop_logs` (`account_id`, `player_id`, `type`, `itemid`, `count`, `points`, `time`) VALUES ('$cid', '0', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '". $buy['points'] ."', '$time')");
|
||||
|
||||
} else echo '<font color="red" size="4">You need more points, this offer cost '.$buy['points'].' points.</font>';
|
||||
//var_dump($buy);
|
||||
//echo '<font color="red" size="4">'. $_POST['buy'] .'</font>';
|
||||
}
|
||||
if ($buy === false) die("Error: Shop offer ID mismatch.");
|
||||
|
||||
// Verify that user can afford this offer.
|
||||
if ($player_points >= $buy['points']) {
|
||||
$data = mysql_select_single("SELECT `points` FROM `znote_accounts` WHERE `account_id`='$cid';");
|
||||
if (!$data) die("0: Account is not converted to work with Znote AAC");
|
||||
$old_points = $data['points'];
|
||||
if ((int)$old_points != (int)$player_points) die("1: Failed to equalize your points.");
|
||||
// Remove points if they can afford
|
||||
// Give points to user
|
||||
$expense_points = $buy['points'];
|
||||
$new_points = $old_points - $expense_points;
|
||||
$update_account = mysql_update("UPDATE `znote_accounts` SET `points`='$new_points' WHERE `account_id`='$cid'");
|
||||
|
||||
$data = mysql_select_single("SELECT `points` FROM `znote_accounts` WHERE `account_id`='$cid';");
|
||||
$verify = $data['points'];
|
||||
if ((int)$old_points == (int)$verify) die("2: Failed to equalize your points.". var_dump((int)$old_points, (int)$verify, $new_points, $expense_points));
|
||||
|
||||
// Do the magic (insert into db, or change sex etc)
|
||||
// If type is 2 or 3
|
||||
if ($buy['type'] == 2) {
|
||||
// Add premium days to account
|
||||
user_account_add_premdays($cid, $buy['count']);
|
||||
echo '<font color="green" size="4">You now have '.$buy['count'].' additional days of premium membership.</font>';
|
||||
} else if ($buy['type'] == 3) {
|
||||
// Character Gender
|
||||
mysql_insert("INSERT INTO `znote_shop_orders` (`account_id`, `type`, `itemid`, `count`, `time`) VALUES ('$cid', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '$time')");
|
||||
echo '<font color="green" size="4">You now have access to change character gender on your characters. Visit <a href="myaccount.php">My Account</a> to select character and change the gender.</font>';
|
||||
} else if ($buy['type'] == 4) {
|
||||
// Character Name
|
||||
mysql_insert("INSERT INTO `znote_shop_orders` (`account_id`, `type`, `itemid`, `count`, `time`) VALUES ('$cid', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '$time')");
|
||||
echo '<font color="green" size="4">You now have access to change character name on your characters. Visit <a href="myaccount.php">My Account</a> to select character and change the name.</font>';
|
||||
} else {
|
||||
mysql_insert("INSERT INTO `znote_shop_orders` (`account_id`, `type`, `itemid`, `count`, `time`) VALUES ('$cid', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '$time')");
|
||||
echo '<font color="green" size="4">Your order is ready to be delivered. Write this command in-game to get it: [!shop].<br>Make sure you are in depot and can carry it before executing the command!</font>';
|
||||
}
|
||||
|
||||
// No matter which type, we will always log it.
|
||||
mysql_insert("INSERT INTO `znote_shop_logs` (`account_id`, `player_id`, `type`, `itemid`, `count`, `points`, `time`) VALUES ('$cid', '0', '". $buy['type'] ."', '". $buy['itemid'] ."', '". $buy['count'] ."', '". $buy['points'] ."', '$time')");
|
||||
|
||||
} else echo '<font color="red" size="4">You need more points, this offer cost '.$buy['points'].' points.</font>';
|
||||
//var_dump($buy);
|
||||
//echo '<font color="red" size="4">'. $_POST['buy'] .'</font>';
|
||||
}
|
||||
|
||||
if ($shop['enabled']) {
|
||||
@ -73,19 +77,23 @@ if ($shop['enabled']) {
|
||||
|
||||
<h1>Shop Offers</h1>
|
||||
<?php
|
||||
if (!empty($_POST['buy']) && $_SESSION['shop_session'] == $_POST['session']) {
|
||||
if ($user_znote_data['points'] >= $buy['points']) {
|
||||
?><td>You have <?php echo (int)($user_znote_data['points'] - $buy['points']); ?> points. (<a href="buypoints.php">Buy points</a>).</td><?php
|
||||
if ($loggedin === true) {
|
||||
if (!empty($_POST['buy']) && $_SESSION['shop_session'] == $_POST['session']) {
|
||||
if ($user_znote_data['points'] >= $buy['points']) {
|
||||
?><td>You have <?php echo (int)($user_znote_data['points'] - $buy['points']); ?> points. (<a href="buypoints.php">Buy points</a>).</td><?php
|
||||
} else {
|
||||
?><td>You have <?php echo $user_znote_data['points']; ?> points. (<a href="buypoints.php">Buy points</a>).</td><?php
|
||||
}
|
||||
} else {
|
||||
?><td>You have <?php echo $user_znote_data['points']; ?> points. (<a href="buypoints.php">Buy points</a>).</td><?php
|
||||
}
|
||||
if ($config['shop_auction']['characterAuction']) {
|
||||
?>
|
||||
<p>Interested in buying characters? View the <a href="auctionChar.php">character auction page!</a></p>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?><td>You have <?php echo $user_znote_data['points']; ?> points. (<a href="buypoints.php">Buy points</a>).</td><?php
|
||||
}
|
||||
if ($config['shop_auction']['characterAuction']) {
|
||||
?>
|
||||
<p>Interested in buying characters? View the <a href="auctionChar.php">character auction page!</a></p>
|
||||
<?php
|
||||
?><p>You need to be logged in to use the shop.</p><?php
|
||||
}
|
||||
|
||||
$outfitsIds = array(136,137,138,139,140,141,142,147,148,149,150,155,156,157,158,252,269,270,279,288,324,336,366,431,433,464,466,471,513,514,542,128,129,130,131,132,133,134,143,144,145,146,151,152,153,154,251,268,273,278,289,325,335,367,430,432,463,465,472,512,516,541);
|
||||
@ -197,7 +205,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<?php if ($config['shop']['showImage']) { ?><td>Image:</td><?php } ?>
|
||||
<td>Count:</td>
|
||||
<td>Points:</td>
|
||||
<td>Action:</td>
|
||||
<?php if ($loggedin === true): ?><td>Action:</td><?php endif; ?>
|
||||
</tr>
|
||||
<?php foreach ($category_items as $key => $offers): ?>
|
||||
<tr class="special">
|
||||
@ -207,6 +215,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<?php endif; ?>
|
||||
<td><?php echo $offers['count']; ?>x</td>
|
||||
<td><?php echo $offers['points']; ?></td>
|
||||
<?php if ($loggedin === true): ?>
|
||||
<td>
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="buy" value="<?php echo (int)$key; ?>">
|
||||
@ -214,6 +223,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<input type="submit" value=" PURCHASE " class="needconfirmation" data-item-name="<?php echo $offers['description']; ?>" data-item-cost="<?php echo $offers['points']; ?>">
|
||||
</form>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@ -224,7 +234,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<?php if ($config['shop']['showImage']) { ?><td>Image:</td><?php } ?>
|
||||
<td>Duration:</td>
|
||||
<td>Points:</td>
|
||||
<td>Action:</td>
|
||||
<?php if ($loggedin === true): ?><td>Action:</td><?php endif; ?>
|
||||
</tr>
|
||||
<?php foreach ($category_premium as $key => $offers): ?>
|
||||
<tr class="special">
|
||||
@ -234,6 +244,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<?php endif; ?>
|
||||
<td><?php echo $offers['count']; ?> Days</td>
|
||||
<td><?php echo $offers['points']; ?></td>
|
||||
<?php if ($loggedin === true): ?>
|
||||
<td>
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="buy" value="<?php echo (int)$key; ?>">
|
||||
@ -241,6 +252,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<input type="submit" value=" PURCHASE " class="needconfirmation" data-item-name="<?php echo $offers['description']; ?>" data-item-cost="<?php echo $offers['points']; ?>">
|
||||
</form>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@ -250,7 +262,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<td>Description:</td>
|
||||
<?php if ($config['shop']['showImage']) { ?><td>Image:</td><?php } ?>
|
||||
<td>Points:</td>
|
||||
<td>Action:</td>
|
||||
<?php if ($loggedin === true): ?><td>Action:</td><?php endif; ?>
|
||||
</tr>
|
||||
<?php foreach ($category_outfits as $key => $offers): ?>
|
||||
<tr class="special">
|
||||
@ -259,6 +271,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<td><img src="<?php echo $config['show_outfits']['imageServer']; ?>?id=<?php echo $offers['itemid']; ?>&addons=<?php echo $offers['count']; ?>&head=<?php echo rand(1, 132); ?>&body=<?php echo rand(1, 132); ?>&legs=<?php echo rand(1, 132); ?>&feet=<?php echo rand(1, 132); ?>" alt="img"></td>
|
||||
<?php endif; ?>
|
||||
<td><?php echo $offers['points']; ?></td>
|
||||
<?php if ($loggedin === true): ?>
|
||||
<td>
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="buy" value="<?php echo (int)$key; ?>">
|
||||
@ -266,6 +279,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<input type="submit" value=" PURCHASE " class="needconfirmation" data-item-name="<?php echo $offers['description']; ?>" data-item-cost="<?php echo $offers['points']; ?>">
|
||||
</form>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@ -275,7 +289,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<td>Description:</td>
|
||||
<?php if ($config['show_outfits']['shop']) { ?><td>Image:</td><?php } ?>
|
||||
<td>Points:</td>
|
||||
<td>Action:</td>
|
||||
<?php if ($loggedin === true): ?><td>Action:</td><?php endif; ?>
|
||||
</tr>
|
||||
<?php foreach ($category_mounts as $key => $offers): ?>
|
||||
<tr class="special">
|
||||
@ -284,6 +298,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<td><img src="<?php echo $config['show_outfits']['imageServer']; ?>?id=<?php echo $outfitsIds[rand(0,count($outfitsIds)-1)]; ?>&addons=<?php echo rand(1, 3); ?>&head=<?php echo rand(1, 132); ?>&body=<?php echo rand(1, 132); ?>&legs=<?php echo rand(1, 132); ?>&feet=<?php echo rand(1, 132); ?>&mount=<?php echo $offers['itemid']; ?>&direction=2" alt="img"></td>
|
||||
<?php endif; ?>
|
||||
<td><?php echo $offers['points']; ?></td>
|
||||
<?php if ($loggedin === true): ?>
|
||||
<td>
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="buy" value="<?php echo (int)$key; ?>">
|
||||
@ -291,6 +306,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<input type="submit" value=" PURCHASE " class="needconfirmation" data-item-name="<?php echo $offers['description']; ?>" data-item-cost="<?php echo $offers['points']; ?>">
|
||||
</form>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
@ -301,7 +317,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<?php if ($config['shop']['showImage']) { ?><td>Image:</td><?php } ?>
|
||||
<td>Count/duration:</td>
|
||||
<td>Points:</td>
|
||||
<td>Action:</td>
|
||||
<?php if ($loggedin === true): ?><td>Action:</td><?php endif; ?>
|
||||
</tr>
|
||||
<?php foreach ($category_misc as $key => $offers): ?>
|
||||
<tr class="special">
|
||||
@ -315,6 +331,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<td><?php echo $offers['count']; ?>x</td>
|
||||
<?php endif; ?>
|
||||
<td><?php echo $offers['points']; ?></td>
|
||||
<?php if ($loggedin === true): ?>
|
||||
<td>
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="buy" value="<?php echo (int)$key; ?>">
|
||||
@ -322,6 +339,7 @@ foreach ($shop_list as $key => $offer) {
|
||||
<input type="submit" value=" PURCHASE " class="needconfirmation" data-item-name="<?php echo $offers['description']; ?>" data-item-cost="<?php echo $offers['points']; ?>">
|
||||
</form>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user