Description: Just is my rendition of a random Raffle Winner Modification based on ideas and posts here at ThreadsDev.
This modication picks a random winner based on the amount of posts you enter and a date to start the contest on.
The Picked winner chosen will have to be active on your board because the date you choose means they will have to be on your board and posted since that date and have greater than the posts you enter. Also the user can not be an admin or mod.
I tried to do this up based on everyones suggestions. More checkboxes can be added and things adjusted so let me know.
Working Under: UBB.Threads 6.2-6.3-6.4
Mod Status: Finished
Any pre-requisites: None
Author(s): Omegatron
Date: 11/24/03
Credits: DeeJay, Gardener and Photopost
Files Altered: N/A
New Files: N/A
Database Altered: No
Info/Instructions: N/A
Disclaimer: Please backup every file that you intend to modify. If the modification modifies the database, it's a good idea to backup your database before doing so.
Note: If you modify your UBB.Threads code, you may be giving up your right for "official" support from Infopop.If you need official support, you'll need to restore unmodified files.
The date means that it picks one user among those who have posted at least once since the given date so if you set a date older than when your board started it will choose among all users.
Exactly the winner will not be admin mod but any other user in any other group and they will have to have posted since the date you enter and have at least how many posts you specify. This helps cut out the people who register and are not true members but lurkers. It just picks a purely random user for any raffles or prizes you are giving away.
It will not pick users who have anything written in the second extra field, why is that?
Also, I think it gives users one ticket for each post they've made, is this really how it is supposed to be? And if so, a checkbox to select only to let each user count once.
I also added a count to show how many users were in the draw, to set my mind at ease about setting the right parameters.
I changed the query code to this:
Code
<br /> $query = "SELECT COUNT(DISTINCT u.U_Username) FROM w3t_Users AS u<br /> LEFT JOIN w3t_Posts AS b ON b.B_PosterId=u.U_Number<br /> WHERE u.U_LastOn > UNIX_TIMESTAMP('$date') AND u.U_TotalPosts > '$posts' AND b.B_Posted > UNIX_TIMESTAMP('$date') AND u.U_Status != 'Banned' AND u.U_Status != 'Administrator' AND u.U_Status != 'Moderator' ORDER BY RAND() LIMIT 1";<br /> $sth = $dbh -> do_query($query);<br /><br /> list ($count) = $dbh -> fetch_array($sth);<br /><br /> $query = "SELECT DISTINCT u.U_Username FROM w3t_Users AS u<br /> LEFT JOIN w3t_Posts AS b ON b.B_PosterId=u.U_Number<br /> WHERE u.U_LastOn > UNIX_TIMESTAMP('$date') AND u.U_TotalPosts > '$posts' AND b.B_Posted > UNIX_TIMESTAMP('$date') AND u.U_Status != 'Banned' AND u.U_Status != 'Administrator' AND u.U_Status != 'Moderator' ORDER BY RAND() LIMIT 1";<br /> $sth = $dbh -> do_query($query);<br /><br /> list ($username) = $dbh -> fetch_array($sth);<br />
And changed the printing to this:
Code
<br />The Winner is<br /><br /><font size="3"><b>$username</b></font><br /><br /><br /><br /><br />There were <i>$count</i> users matching your criteria.<br />
How about a box for a specific thread? so if they post to a certain thread they will be entered. Great program... also might want to include the link to the admin menu in the directions.. Great job chuck
Making two queries like in my example isn't good either, since it goes through all posts since the given date twice it'll take some time if it's too far back in time. I think it should be possible to get a count somehow with only one query though I can't think of it right now. Of course, it could select all names and just choose the name in the php code as Michaels version does it.
Also, I tried adding a select box for different groups, but threads 6.1 fuds up arrays in posts so I didn't bother finishing it. Should work in later versions with get_input() I hope.
Code added above html:
Code
<br />// --------------------<br />// Get a list of groups<br /> $query = "SELECT G_Id, G_Name from {$config['tbprefix']}Groups ORDER BY G_Name ASC";<br /> $sth = $dbh -> do_query($query);<br /><br /> $groupoptions = "";<br /> while (list ($gid, $gname) = $dbh -> fetch_array($sth) ) {<br /> $groupoptions .= "<option value='$gid'>$gname</option>\n";<br /> }<br />
New table row, added above the submit button table row:
Code
<br /><tr><br /><td valign="top"><br /> Select users from the following groups:<br /></td><br /><td><br /><select name="groups[]" size="5" multiple="multiple"><br />$groupoptions<br /></select><br /></td><br /></tr><br />
There is no code for reading the info, since that didn't work on 6.1, but if anyone wants to do it, they have something to start with.
Selecting users who have posted in a thread sounds like a good idea too, although I'm not sure how it would be done. Adding a link to all threads where you can click to select a winner from those who have posted to it?
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.