I redid seed bonus, as I didnt like the old one and it needed to be cut down a few. So here is working copy, still progressing as I go to settle features and what not.
Full compat for any edition soon.
[ATTACH type="full" alt="1.png"]5896[/ATTACH]
[ATTACH type="full" alt="2.png"]5897[/ATTACH]
Full compat for any edition soon.
[ATTACH type="full" alt="1.png"]5896[/ATTACH]
[ATTACH type="full" alt="2.png"]5897[/ATTACH]
<?
// Seed Bonus - Reworked - Sep 19, 2020
require_once '../site.php';
$db->connect();
site_header();
if (!$account->sessionLogin()) {
header(sprintf('Location: %s/siginin/', $CONFIG['base_url']));
die;
}
$errors = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = array();
$keys = array('id', 'userid', 'torrentid');
foreach ($keys as $key) {
if (!array_key_exists($key, $_POST)) {
sprintf('Seed bonus item ID %s not valid.', $key);
}
$data[$key] = $_POST[$key];
}
$res = $db->query_params('SELECT users.seedbonus, users.perk_avatar, users.username, users.slots, users.last_exchange, users.class, users.user_id, bonus.cost, bonus.descr, bonus.type, bonus.value, bonus.id FROM users, bonus WHERE users.user_id = :user_id AND bonus.id = :post_id', array('user_id' => $account->getId(), 'post_id' => $data['id'])) or die('db error');
if (!($row = $res->fetch()) || $row['seedbonus'] < $row['cost']) {
$errors []= 'Demand not valid.';
}
if (empty($errors)) {
$db->query_params("UPDATE users SET seedbonus = seedbonus - :cost WHERE user_id = :user_id", array('cost' => $row['cost'], 'user_id' => $account->getid())) or die('User bonus update failed.');
}
$types = array(
'invite' => true,
'traffic' => true,
'hnr' => true,
'slots' => true,
'vip' => true,
'last_exchange' => true,
'value' => true,
'feature' => true
);
$data_row = array();
foreach ($types as $key => $req) {
if (array_key_exists($key, $row)) {
$data_row[$key] = $row[$key];
} else if ($req) {
sprintf('Invalid type %s', $key);
}
}
if (empty($errors) || array_key_exists('id', $data)) {
if ($row['type'] == 'invite' && $data['id'] == $row['id']) {
$db->query_params("UPDATE users SET invites = invites + :value WHERE user_id = :user_id", array('value' => $row['value'], 'user_id' => $account->getid()));
echo sprintf('Your account has been <b>credited</b> for <b>%s</b> Extra Invites!', $row['value']);
}
if ($row['type'] == 'traffic' && $data['id'] == $row['id']) {
$db->query_params("UPDATE users SET uploaded = uploaded + :value, last_exchange = :bonus WHERE user_id = :user_id", array('bonus' => $row['value'], 'value' => $row['value'], 'user_id' => $account->getid()));
echo sprintf('Your account has been <b>credited</b> for <b>%s</b> bonus Upload Data!', format_size($row['value']));
}
if ($row['type'] == 'HnR' && $data['id'] == $row['id']) {
$uid = $row['class'] == '1' ? $data['userid'] : $account->getId();
if (!array_key_exists('torrentid', $data)) {
die('You must fill the box with the id of the torrent.');
}
if (isset($uid)) {
$res = $db->query_params("SELECT * FROM snatched WHERE tid = :tid AND uid = :uid AND hnr = 'yes'", array('tid' => $data['torrentid'], 'uid' => $uid));
if ($res)
die('No HnR found with this information.');
$res1 = $db->query_params("SELECT username FROM users WHERE user_id = :uid", array('uid' => $uid));
$row1 = $res1->fetch();
$res2 = $db->query_params("SELECT name FROM torrents WHERE torrent_id = :tid", array('tid' => $tid));
$row2 = $res2->fetch();
$username = html_escape($row1['username']);
$torname = html_escape($row2['name']);
// TODO: db Hit n Run logging
echo sprintf('Hit and Run has been cleared for torrent %s', $row2['name']);
if ($uid == $account->getId())
$new_modcomment .= "H&R on the torrent " . $torname . " cleared against " . $row['cost'] . " points \n";
else
$new_modcomment .= "H&R on the torrent " . $torname . " cleared by " . $account->username() . " \n";
$modcom = gmdate('d-m-Y \à H:i') . ' - ';
$db->query_params('UPDATE users SET modcomment = CONCAT(:modcom,modcomment) WHERE user_id = :user_id', array('modcom' => $modcom, 'user_id' => $uid));
$db->query_params("UPDATE snatched SET ltime = '129600', hnr = 'no' WHERE tid = :tid AND uid = :uid", array('tid' => $modcom, 'uid' => $uid));
}
}
if ($row['type'] == 'slots' && $data['id'] == $row['id']) {
$db->query_params('UPDATE users SET slots = :slots WHERE user_id = :user_id', array('slots' => $data_row['value'], 'user_id' => $account->getid()));
echo sprintf('Your account has been <b>credited</b> for <b>%s</b> Extra Download Slots!', $row['value']);
}
if ($row['type'] == 'feature' && $data['id'] == $row['id']) {
$db->query_params("UPDATE users SET perk_avatar = 'yes' WHERE user_id = :user_id", array('user_id' => $account->getid()));
echo sprintf('Your avatar has been <b>enlarged</b> to <b>%s</b> Pixels!', $row['value']);
}
}
}