Stuart Wright
Well-known member
Hello folks,
so far I've outsourced all our coding to gurus like Chris Deeming but now I want to have a go myself.
I'm trying to reproduce a page from our vBulletin site which assigns tokens stored in a table to users who visit the page and then creates a link to a retailer website which applies free delivery to their shopping account. Each user is assigned a token and their userid is written into the table.
scan_tokens:
userid int(10) UNSIGNED
token char(64)
assigned timestamp
This is the old code from vBulletin which I wrote:
I'm imaginig that this is dead easy to to with a php callback on a page?
I have looked at a few other examples of Xenforo coding and as you can probably see from my coding above, what I'm used to is very different. Xenforo coding is a bit foreign to me. I have never used classes, for example.
Where do I start please?
so far I've outsourced all our coding to gurus like Chris Deeming but now I want to have a go myself.
I'm trying to reproduce a page from our vBulletin site which assigns tokens stored in a table to users who visit the page and then creates a link to a retailer website which applies free delivery to their shopping account. Each user is assigned a token and their userid is written into the table.
scan_tokens:
userid int(10) UNSIGNED
token char(64)
assigned timestamp
This is the old code from vBulletin which I wrote:
PHP:
<?php
$allowed_usergroups = array(6, 2, 7, 5, 11, 24, 25);
if ($vbulletin->userinfo['userid'] == "") { // guest
$HTML .= "<p align='center'>In order to qualify for the SCAN & AVForums loyalty programme you need to login to your AVForums account.<br>Please login (and register first if you need to) <a href='http://www.avforums.com/forums/clogin.php' target='_blank'>here</a>.</p>";
} elseif (!in_array($vbulletin->userinfo['usergroupid'],$allowed_usergroups)) {
$HTML .= "<p align='center'>In order to qualify for the SCAN & AVForums loyalty programme you need to be a member of AVForums and logged in to your activated AVForums account.<br>Please login (and register first if you need to) <a href='http://www.avforums.com' target='_blank'>here</a>.</p>";
} else {
$HTML .= "<h3 align='center'>Welcome " . $vbulletin->userinfo['username'] . ".</p>";
$sql = "SELECT token FROM scan_tokens WHERE userid = " . $vbulletin->userinfo['userid'] . " LIMIT 1";
$result = $db->query_read($sql);
if (!$result) {
$HTML .= "<p align='center'>There was a problem finding your token. Please notify AVForums admin.";
exit();
}
if (mysql_num_rows($result) == 1) {
extract(mysql_fetch_array($result,MYSQL_ASSOC));
if (strlen($token) >= 60) {
$HTML .= "<P align='center'>Good news - you qualify for the SCAN & AVForums loyalty programme!<br>Click <a href='https://secure.scan.co.uk/aspnet/myaccount/avfreecarriage.aspx?uid=$token' target='_blank'>here</a> to visit the SCAN website and log in/register to qualify for free delivery on all orders of £50 or over (excluding VAT).</p>";
}
} else { // no token found
$sql = "SELECT token FROM scan_tokens WHERE userid = 0 LIMIT 1 FOR UPDATE"; //get token and lock record for update
$result = $db->query_read($sql);
if (!$result) {
$HTML .= "<p align='center'>There was a problem assigning the Free Delivery token to your account. Please notify AVForums admin.";
exit();
}
if (mysql_num_rows($result) == 1) {
extract(mysql_fetch_array($result,MYSQL_ASSOC));
if (strlen($token) >= 60) {
$sql = "UPDATE scan_tokens SET userid = " . $vbulletin->userinfo['userid'] . " WHERE token = '$token'";
$db->query($sql); //
$HTML .= "<P align='center'>Good news - you qualify for the SCAN & AVForums loyalty programme!<br>Click <a href='https://secure.scan.co.uk/aspnet/myaccount/avfreecarriage.aspx?uid=$token' target='_blank'>here</a> to visit the SCAN website and log in/register to qualify for free delivery on all orders over £50 (excluding VAT).</p>";
}
}
}
}
?>
I'm imaginig that this is dead easy to to with a php callback on a page?
I have looked at a few other examples of Xenforo coding and as you can probably see from my coding above, what I'm used to is very different. Xenforo coding is a bit foreign to me. I have never used classes, for example.
Where do I start please?