- <?php
- session_start();
- ################################################
- # Script by Rifke for the osrose compunity
- # index.php
- # date: 05 August 2009
- ################################################
- ############ MySQL connection remove if you already have one #############
- mysql_connect('localhost:3306', 'root', '****');
- mysql_select_db('roseon');
- ############ Settings ############
- $cmd['add_points'] = 'zully'; // You can choise between zully and dpts (donation points!)
- $cmd['amount'] = 9; // Amount to be added
- $cmd['page_type'] = '?'; // ? or & => ? for main page & for a sub page!
- $cmd['time_out'] = (3600 * 24); // Time in seconds to get another point in voting! Default: 24 hours...
- $cmd['refresh_rate'] = 4; // Time to refferer to the voting website
- $cmd['vote_site'][] = array('http://www.google.be', 'http://www.google.be/intl/en_com/images/logo_plain.png'); // eg: array('http://www.votesite1.com', 'http://yoursite.com/votesite1.jpg');
- $cmd['vote_site'][] = array('http://www.yahoo.com', 'http://l.yimg.com/a/i/ww/beta/y3.gif'); // eg: array('http://www.votesite2.com', 'http://yoursite.com/votesite2.jpg');
- $cmd['vote_site'][] = array('http://www.yebol.com/', 'http://www.yebol.com/icons/f_logo.gif'); // eg: array('http://www.votesite3.com', 'http://yoursite.com/votesite3.jpg');
- // A tiny login screen!
- if ( ($_SERVER['REQUEST_METHOD'] == 'POST') ) {
- $sql = "SELECT id FROM accounts WHERE username = '%s' AND password = '%s';";
- $sql = sprintf($sql, mysql_real_escape_string($_POST['user_name']), md5($_POST['password']));
- $res = @mysql_query($sql);
- if ( $res === false ) {
- echo '<p class="error_block">Problem with loggin in</p>';
- } elseif ( mysql_num_rows($res) == 0 ) {
- echo '<p class="error_block">Invalid combination username/password</p>';
- } else {
- echo '<p class="ok_block">Valid login</p>';
- $_SESSION['user_account_id'] = mysql_result($res, 0);
- }
- }
- if ( isset($_SESSION['user_account_id']) ) {
- #echo 'Welcome: ' . $_SESSION['user_account_id'] . '<br />';
- } else {
- echo '
- <form action="" method="post">
- User name: <input type="text" name="user_name" id="user_name">
- Password: <input type="password" name="password" id="password">
- <input type="submit" name="login" id="login" value="login">
- </form>
- ';
- }
- # Start with the vote for points
- if ( isset($_GET['vote_site']) ) {
- # Check if the vote site exist
- if ( isset($cmd['vote_site'][$_GET['vote_site']]) ) {
- # check the 'if login'
- if ( isset($_SESSION['user_account_id']) && ctype_digit($_SESSION['user_account_id']) ) {
- # First get the voting times from database
- $sql = "SELECT donation FROM accounts WHERE id = %d;";
- $sql = sprintf($sql, $_SESSION['user_account_id']);
- $res = @mysql_query($sql);
- if ( $res === false ) {
- echo '<strong>Warning:</strong> due a problem with our database we could not check if you have already voted or not. please try again later.';
- } else {
- # now we we get the value from the database using mysql_result
- $voting_times = mysql_result($res, 0);
- # Now we have our times stored in a variable... Each voting site is seperated by a ; so we extract every time using the php function explode
- # This wil result in an array with the values... With an index starting at 0.. The first value in the array (postition 0) would be our first
- # voting site!
- $voting_times_array = explode(';',$voting_times);
- # now we need to get the current time in seconds. That can be accompished by mktime(), a build in php function.
- $current_time = mktime();
- # now we have our current time stored an a variable, we need to check it with the value stored in $voting_times_array and the corresponding
- # voting website.
- if ( $current_time < @$voting_times_array[ $_GET['vote_site'] ] ) {
- # our current time is 'lower' than the stored value, so the user is still in cooldown. And can not receive any points for voting!
- # Therefor we will print a warning message that he is still on cooldown. And we will print a message saying he/she has still hours:minutes:seconds to go
- $resulting_time = $voting_times_array[ $_GET['vote_site'] ] - $current_time;
- $cooldown = date('h:n:s', $resulting_time);
- echo '<strong>Warning:</strong> We have detected that you still have ' . $cooldown . ' to go before you receive credit again.';
- } else {
- # the user is not on cooldown, so we can suggest he/she can vote agian
- # Now we have to store the current time + time_out in the voting_times_array at the corresponding voting_site id
- $voting_times_array[ $_GET['vote_site'] ] = $current_time + $cmd['time_out'];
- # Now $voting_times_array contains the new time for that voting site we have to rewrite the times back to the databse, including the
- # updated points! So basicly we have to glue the array back together, we can accomplish that using the implode feater of php
- $sql = 'UPDATE accounts SET %1$s = %1$s + %2$d, donation='%4$s' WHERE id = %3$d;';
- $sql = sprintf($sql, ( $cmd['add_points'] == 'dpts' ? 'nb_donation' : 'zulystorage'), $cmd['amount'], $_SESSION['user_account_id'], implode(';',$voting_times_array));
- $res = @mysql_query($sql);
- if ( $res === false ) {
- echo '<strong>Warning:</strong> due a problem with our database we could not add your voting credit.';
- } else {
- echo '<strong>Congratulations:</strong> you have received credit for your voting.';
- }
- }
- }
- } else {
- # This message will only be triggerd when the user is not logged on. Or has an invalid account id.
- echo '<strong>Warning:</strong> We have detected that you are not logged on. If you were logged on you would have recieved credit for your voting';
- }
- # The user will always be redirected even if it failed the above things... So a user can also vote when he is not logged on!
- echo 'We will direct you in ' . $cmd['refresh_rate'] . ' seconds, if nothing hapens please click <a href="'.$cmd['vote_site'][$_GET['vote_site']][0].'">here</a>!';
- echo '<meta http-equiv="refresh" content="'.$cmd['refresh_rate'].'; URL=' . $cmd['vote_site'][$_GET['vote_site']][0] . '">';
- } else {
- echo 'The clicked voting site does not exist! Please try again!';
- }
- }
- ############ Print voting sites ############
- if ( @is_array($cmd['vote_site']) ) {
- // print sites
- echo '<br />';
- foreach ( $cmd['vote_site'] as $id => $vote_site ) {
- list($http,$img) = $vote_site;
- echo '<a href="' . ( $cmd['page_type'] == '&' ? $_SERVER['REQUEST_URI'].'&' : $cmd['page_type'] ) . 'vote_site=' . $id . '" target="_blank"><img src="' . $img . '" border="0" /></a> ';
- }
- } else {
- echo 'Your voting sites are NOT configured correctly! Please check them again! or visit <a href="http://forum.dev-osrose.com/index.php">os Rose development</a> for more information!';
- }
- ?>
how i can make my voting script for points gives union points ??
heres the script
Tnx