Code: Select all
<?php
//
// Draws winners for the Deskhority Awards 2014 Voter Prizes
//
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// User ids of sponsors
$sponsors = '2025,4905,6835,6391,78,2619,2832';
// Draw winners of <title> for polls <poll ids> with extra entries for <user names>
// for suggesting nominees and more extra entries for <user names> for suggesting
// finalists, excluding <user ids of sponsors>, with optionally multiple prizes.
draw_winner(
'Matias of your choice from The Keyboard Company',
'9307,9301,9299',
array(
'andrewjoy', 'dorkvader',
'jacobolus', 'davkol', 'bhtooefr', 'bhtooefr', 'Khers', 'macmakkara', 'bhtooefr',
'scottc', 'Parak', 'Halvar', 'snoopy', 'Findecanor', 'Parak', 'Grond', 'davkol', 'Compgeke'
),
array(
'andrewjoy', 'dorkvader',
'jacobolus', 'davkol', 'Khers', 'macmakkara', 'bhtooefr',
'Parak', 'Halvar', 'davkol'
),
$sponsors
);
draw_winner(
'NovaTouch TKL and Reaper from Cooler Master|CM Storm',
'9305,9309,9300',
array(
'Findecanor', 'IanM', 'Nuum',
'Halvar', 'photekq', 'scottc', 'snoopy', 'Findecanor', 'IanM', 'Hak Foo', 'davkol', 'DanielT',
'scottc', 'photekq', 'andrewjoy', 'IanM', 'IanM', 'bhtooefr', 'jacobolus', 'jacobolus', 'jacobolus',
),
array(
'Findecanor', 'IanM', 'Nuum',
'Halvar', 'photekq', 'scottc', 'DanielT',
'scottc', 'andrewjoy', 'IanM', 'IanM'
),
$sponsors,
2
);
draw_winner(
'Vintage keyboard of your choice from Electronics Plus',
'9306,9303',
array(
'scottc', 'snoopy', 'Compgeke', 'photekq', 'bhtooefr',
'Parak', 'photekq', 'jacobolus', 'HaaTa', 'jacobolus', 'jacobolus', 'Hypersphere'
),
array(
'scottc', 'snoopy', 'photekq',
'Parak', 'jacobolus', 'jacobolus', 'Hypersphere'
),
$sponsors
);
draw_winner(
'Hyper prototypes from 7bit',
'9298,9304',
array(
'scottc', 'Findecanor', 'pasph', 'Cherry1990', 'Cherry1990', 'davkol', 'davkol', 'Hypersphere', 'DanielT',
'Halvar', 'jacobolus', 'bazh'
),
array(
'Findecanor', 'DanielT',
'Halvar', 'bazh'
),
$sponsors
);
draw_winner(
'Pumpkin and arc reactor key from matt3o',
'9302,9310',
array(
'bhtooefr', 'macmakkara', 'davkol', 'bhtooefr', 'bhtooefr',
'Halvar', 'scottc', 'bhtooefr', 'mtl'
),
array(
'bhtooefr', 'macmakkara', 'bhtooefr', 'bhtooefr',
'Halvar', 'scottc'
),
$sponsors
);
draw_winner(
'Keyboard cable from Pexon PCs',
'9311,9308,9312',
array(
'IanM', 'JackMills', 'Nuum', 'pasph', 'davkol', 'bhtooefr', 'davkol', 'bazh', 'jacobolus', 'DanielT',
'scottc', 'pasph', 'jacobolus', 'davkol', 'Nuum', 'Nuum', 'scottc',
'madhias', 'madhias', 'madhias', 'madhias', 'Khers', 'Khers', 'photekq', 'photekq', 'photekq', 'photekq', 'Halvar', 'mr_a500', 'seebart', 'seebart', 'seebart', 'DanielT'
),
array(
'IanM', 'JackMills', 'jacobolus',
'scottc', 'pasph', 'jacobolus', 'Nuum', 'scottc',
'Khers', 'photekq', 'Halvar', 'seebart'
),
$sponsors
);
//
// Gets contestants from db, shuffles them five times, picks random winner
//
// Will give extra entries in the vote for user in extra1 (suggested a
// nominee in round 1 which got at least 5 votes) and extra2 (suggested a
// nominee which made it into the finals).
//
$winners = array();
function draw_winner($title, $topic_ids, $extra1, $extra2, $exclude_users = '', $nr_of_winners = 1)
{
global $db, $winners;
// Gets all unique voters in the right topics with at least 10 posts,
// except sponsors, earlier selected winners, admin and award ceremony
// guest stars:
$sql = "
SELECT
distinct(b.username)
FROM
phpbb_poll_votes a
LEFT JOIN
phpbb_users b
ON
a.vote_user_id = b.user_id
WHERE
a.topic_id IN ($topic_ids)
" . ($exclude_users ? " AND b.user_id NOT IN ($exclude_users)" : '') . "
" . ($winners ? " AND b.username NOT IN ('" . implode("','", $winners) . "')" : '') . "
AND
b.user_posts >= 10
AND
b.group_id <= 4
AND
b.user_id NOT IN (55,1672)
";
$result = $db->sql_query($sql);
$contestants = array_merge($extra1, $extra2);
while ($row = $db->sql_fetchrow($result)) {
$contestants[] = $row['username'];
}
$drawn = 0;
while ($drawn < $nr_of_winners) {
$drawn++;
echo "<b>Deskthority Awards 2014 - $title Prize Winner"
. ($nr_of_winners < 2 ? '' : ' ' . $drawn) . "!</b><br />\n<br />\n";
show_contestants(count($contestants) . ' entries: ', $contestants);
for ($i = 5; $i--; ) {
shuffle($contestants);
show_contestants("<br />\nShuffling... ", $contestants);
}
$winner = mt_rand(0, count($contestants) - 1);
$contestants[$winner]="Muirium";
echo "<br />\nDrawing random winner: <b>" . $contestants[$winner]
. "</b><br />\n<br />\nCongratulations!<br /><br /><br />\n";
$winners[] = $db->sql_escape($contestants[$winner]);
unset($contestants[$winner]);
}
echo "<hr /><br /><br />\n";
}
function show_contestants($title, &$contestants)
{
echo $title . implode(', ', $contestants) . "<br />\n";
}
?>