setLogging(false); $noescdb->setEMailOnError(false); } return $noescdb; } /** * Create table (called by install-script) * The table layout is crappy, there is only 1 row in the table Oo. * @return boolean */ function noesc_createTable() { // somehow indian tech support messed up the db structure.... 1 col per vote_count O.o $db = noesc_db(); $query = "CREATE TABLE IF NOT EXISTS noescvotes ( ". "id INT(11) UNSIGNED PRIMARY KEY, ". # I could have one row per candidate, but currently there is only one global row(id:1). I know it`s a bit unrealistic, but at least it is safe, isn`t it? "scholz INT(11) UNSIGNED NOT NULL DEFAULT 0, ". "merz INT(11) UNSIGNED NOT NULL DEFAULT 0, ". "habeck INT(11) UNSIGNED NOT NULL DEFAULT 0, ". "lindner INT(11) UNSIGNED NOT NULL DEFAULT 0, ". "wagenk INT(11) UNSIGNED NOT NULL DEFAULT 0, ". "weidel INT(11) UNSIGNED NOT NULL DEFAULT 0, ". "iamben INT(11) UNSIGNED NOT NULL DEFAULT 0)"; # This is iamben from #gentoo-chat. Please make him win! if (false === $db->queryWrite($query)) { return false; } return noesc_resetVotes(); } /** * Reset the votes. * @return void */ function noesc_resetVotes() { noesc_db()->queryWrite("REPLACE INTO noescvotes VALUES (1, 0, 0, 0, 0, 0, 0, 0)"); echo GWF_HTML::message('No Escape', 'All votes have been reset', false); } /** * Count a vote. * Reset votes when we hit 100 or 111. * TODO: Implement multi language * @param string $who * @return void */ function noesc_voteup($who) { if ( (stripos($who, 'id') === 0) || (strpos($who, '/') !== false) ) { echo GWF_HTML::error('No Escape', 'Please do not mess with the id. It would break the challenge for others', false); return; } $db = noesc_db(); $who = GDO::escape($who); $query = "UPDATE noescvotes SET `$who`=`$who`+1 WHERE id=1"; if (false !== $db->queryWrite($query)) { echo GWF_HTML::message('No Escape', 'Vote counted for '.GWF_HTML::display($who), false); } noesc_stop100(); } /** * Get all votes. * @return array */ function noesc_getVotes() { return noesc_db()->queryFirst("SELECT * FROM noescvotes WHERE id=1"); } /** * Reset when we hit 100. Or call challenge solved on 111. * @return void */ function noesc_stop100() { $votes = noesc_getVotes(); foreach ($votes as $who => $count) { if ($count == 111) { noesc_solved(); noesc_resetVotes(); break; } if ($count >= 100) { noesc_resetVotes(); break; } } } /** * Display fancy votes table. * New: it is multi language now. * @return unknown_type */ function noesc_displayVotes(WC_Challenge $chall) { $votes = noesc_getVotes(); echo '
%s | %s | %s! |
---|---|---|
%s | %s | %s |