Так и было задумано изначально

Код: Выделить всё
$userdata['user_id'] == "2") //make sure they haven't voted in the last hour or if they're a mod or admin, they can continue
Код: Выделить всё
$userdata['user_level'] == "1"
Код: Выделить всё
<?php
/***************************************************************************
* karma.php
* -------------------
* edited : Monday, June 6, 2005
* copyright : (C) Nome
* email : nome@bk.ru
* version : 1.2.2
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
unset($x);
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
// Some extra script settings. You can modify them
// How long do we have to wait before giving karma points again?
$hours_past = 3; // In hours
// Do admins and moders have the permission to give karma points any time they like
// Note that now 0 = no and 1 = yes as in all other normal cases :)
$allow_up = 0;
// Posts limit before we can add karma
$min_posts = 600;
// $_GET variables
if ( isset($_GET['t']) ) { $topic_id = $_GET['t']; } else { die("Hacking attempt"); }
if ( isset($_GET['p']) ) { $post_id = $_GET['p']; } else { die("Hacking attempt"); }
if ( isset($_GET['u']) ) { $user = $_GET['u']; } else { die("Hacking attempt"); }
if ( isset($_GET['x']) ) { $x = $_GET['x']; } else { die("Hacking attempt"); }
//Taken from login.php
//
// Set page ID for session management
//
$userdata = session_pagestart($user_ip, PAGE_LOGIN);
init_userprefs($userdata);
//
// End session management
//
if(!$userdata['session_logged_in'])
{
header('Location:' . append_sid("login.$phpEx"));
}
else
{
global $db;
$sql = "select user_posts, karma_time from " . USERS_TABLE . " where user_id='$userdata[user_id]'";
$result = $db->sql_query($sql);
$array = mysql_fetch_array($result);
$time_old = $array['karma_time'];
$posts_num = $array['user_posts'];
$sql = "select user_id from " . USERS_TABLE . " where user_id='$userdata[user_id]'";//make sure no one votes for themselves
$result = $db->sql_query($sql);
$array = mysql_fetch_array($result);
$voter_id = $array[0];
if($voter_id == $user)
{
message_die(CRITICAL_MESSAGE, $lang['No_Self_Karma'] . '<br /><a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '"> ' . $lang['Return_To_Topic'] . ' </a>');
}
elseif($userdata['user_level'] !== "1")
{
if($posts_num < $min_posts) {
message_die(CRITICAL_MESSAGE, $lang['Not_Enough_Posts_For_Karma'] . '<br /><a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '"> ' . $lang['Return_To_Topic'] . ' </a>');
}
}
else
{
$allow_up = ( ( $allow_up == 1 ) && ( $userdata['user_level'] == (1||2) ) ) ? 1 : 0;
$time = time();
$diff = $time - $time_old;
if($diff >= 3600 * $hours_past || $allow_up == 1 || $userdata['user_id'] == "2") //make sure they haven't voted in the last hour or if they're a mod or admin, they can continue
{
if ($x == 'applaud')
{
$sql = "select karma_plus from " . USERS_TABLE . " where user_id='$user'"; //Find the good guy
$result = $db->sql_query($sql);
$array = mysql_fetch_array($result);
$karma = $array[0];
// We only up karma by one
$karma = $karma + 1;
// Here comes the db update
$karma_update = "update " . USERS_TABLE . " set karma_plus ='$karma' where user_id='$user'";
}
else
// If someone tries to fake the x input, that someone will get bad karma ;)
{
$sql = "select karma_plus from " . USERS_TABLE . " where user_id='$user'"; //Find the bad guy
$result = $db->sql_query($sql);
$array = mysql_fetch_array($result);
$karma = $array[0];
// We only up karma by one
$karma = $karma - 1;
// Here comes the db update
$karma_update = "update " . USERS_TABLE . " set karma_plus ='$karma' where user_id='$user'";
}
//update the database with current time() for voter
$time_update = "update " . USERS_TABLE . " set karma_time ='$time' where user_id ='$userdata[user_id]'";
$result = $db->sql_query($karma_update);
$time_result = $db->sql_query($time_update);
if($result&&$time_result) //Both gotta happen...
{
if(!isset($topic_id))
{
header('Location:' . append_sid("index.$phpEx"));
break;
}
else
{
header('Location:' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id ."#" . $post_id));
}
}
else
{
message_die(GENERAL_ERROR, $lang['Critical_Error'] . '<br /><a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '"> ' . $lang['Return_To_Topic'] . ' </a>', __LINE__, __FILE__, $sql);
}
}
else
{
message_die(CRITICAL_MESSAGE, $lang['Too_Soon'] . '<br /><a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '"> ' . $lang['Return_To_Topic'] . ' </a>');
}
}
}
?>