Converting old mod seedbonus, early test stuff. Template code included to speed up post updates.
<?
try {
$stmt = new PDO("mysql:host={$dbHost};dbname={$dbName}", $dbUsername, $dbPassword);
$stmt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
die('Unable to connect to database');
}
$userid = $CURUSER['id'];
$tid = $_POST["torrentid"];
$uid = $CURUSER["class"] == "1" ? (int) $_POST["userid"] : (int) $CURUSER["id"];
$retrieve = $stmt->prepare("SELECT * FROM bonus");
$retrieve->execute();
$usertable = $stmt->prepare("SELECT * FROM users");
$usertable->execute();
if (is_valid_id($_POST['id'])) {
if (!$row || $CURUSER['seedbonus'] < $row->cost) {
autolink("bonus.php", "Demand not valid.");
}
$updateuser = $stmt->query("UPDATE users SET seedbonus = seedbonus - '$row->cost' WHERE id = :id");
$updateuser->bindValue(':id', $userid, PDO::PARAM_INT);
$updateuser->execute();
$row = $retrieve->fetch(PDO::FETCH_OBJ);
switch ($row->type) {
case 'invite':
$stmt->query("UPDATE users SET invites = invites + '$row->value' WHERE id = :id");
$stmt->bindValue(':id', $userid, PDO::PARAM_INT);
$stmt->execute();
break;
case 'traffic':
$stmt->query("UPDATE users SET uploaded = uploaded + '$row->value' WHERE id = :id");
$stmt->bindValue(':id', $userid, PDO::PARAM_INT);
$stmt->execute();
break;
case 'HnR':
if (empty($tid))
autolink("bonus.php", "You must fill the box with the id of the torrent.");
if (isset($uid) && isset($tid)) {
$res = $stmt->prepare("SELECT * FROM snatched WHERE tid = :tid AND uid = :uid AND hnr = 'yes'");
$res->bindValue(':tid', $userid, PDO::PARAM_INT);
$res->bindValue(':uid', $uid, PDO::PARAM_INT);
$res->execute();
if ($res->rowCount() < 0)
autolink("mybonus.php", "No HnR found with this information.");
$res1 = $stmt->prepare("SELECT username, class FROM users WHERE id = :uid");
$res1->bindValue(':uid', $uid, PDO::PARAM_INT);
$res1->execute();
$row1 = $res1->fetch(PDO::FETCH_OBJ);
$res2 = $stmt->prepare("SELECT name FROM torrents WHERE id = :tid");
$res2->bindValue(':tid', $tid, PDO::PARAM_INT);
$res2->execute();
$row2 = $res2->fetch(PDO::FETCH_OBJ);
$username = htmlspecialchars($row1->username);
$torname = htmlspecialchars($row2->name);
$new_modcomment = gmdate("M d Y H:i:s") . " - ";
if ($uid == $CURUSER["id"])
$new_modcomment .= "H&R on the torrent " . htmlspecialchars($row2->name) . " cleared against " . $row->cost . " points \n";
else
$new_modcomment .= "H&R on the torrent " . $row2->name . " cleared by " . $row1->username . " \n";
$modcom = sqlesc($new_modcomment);
$stmt->prepare("UPDATE users SET modcomment = CONCAT($modcom,modcomment) WHERE id = :uid");
$stmt->prepare("UPDATE snatched SET ltime = '129600', hnr = 'no' WHERE tid = :tid AND uid = :uid");
$stmt->bindValue(':tid', $userid, PDO::PARAM_INT);
$stmt->bindValue(':uid', $uid, PDO::PARAM_INT);
$stmt->execute();
}
break;
case 'other':
break;
case 'VIP':
$days = $row->value;
$class = $row1->class;
$vipuntil = ($CURUSER["vipuntil"] > "0000-00-00 00:00:00") ? $vipuntil = get_date_time(strtotime($CURUSER["vipuntil"]) + ($days * 86400)) : $vipuntil = get_date_time(gmtime() + ($days * 86400));
$oldclass = ($CURUSER["vipuntil"] > "0000-00-00 00:00:00") ? $oldclass = $CURUSER["oldclass"] : $oldclass = $CURUSER["class"];
$stmt->prepare("UPDATE users SET class = :class, oldclass = :oldclass, vipuntil = :vipuntil WHERE id = :id");
$stmt->bindValue(':class', $class, PDO::PARAM_INT);
$stmt->bindValue(':oldclass', $oldclass, PDO::PARAM_STR);
$stmt->bindValue(':vipuntil', $vipuntil, PDO::PARAM_STR);
$stmt->bindValue(':id', $userid, PDO::PARAM_INT);
$stmt->execute();
break;
}
}
while ($row = $retrieve->fetch(PDO::FETCH_OBJ)) {
echo '<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card">';
echo '<form method="post" class="cd-form floating-labels" action="/bonus.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '" />';
echo '<div class="card-action ng-scope" style="font-size:22px">';
echo "<span style=\"font-size:27px;font-weight:400;padding: 7px 5px 5px 10px;border-radius:7px;background:#C0C0C0;text-align:center;color:#FFF;box-shadow: inset 1px 5px 7px -6px #000000;margin-right:15px\">" . str_replace('Uploaded', '', $row->title) . "</span>";
echo $row->descr;
$disabled = '';
$inputmsg = 'Exchange';
if ($CURUSER['seedbonus'] < $row->cost) {
$inputmsg = 'Not Enough';
$disabled = 'disabled';
}
echo '<span style="float:right;margin-right:-125px">';
echo "<button class=\"btn btn-danger\" onclick=\"this.form.submit();\" style=\"font-size:15px\" $disabled>$inputmsg</button></span>";
echo '</div></form></article>';
}
?>
<div>You receive <?
echo $site_config['bonuspertime'];
?> points per <?
echo floor($site_config['autoclean_interval'] / 10);
?> minutes the system registers you as a seeder by torrent.</div>
<?
stdfoot();
?>
[ATTACH type="full"]5545[/ATTACH]

