I am attempting to code a karma mod for phpBB that acts similar to the one we have here, but only returns one number
example : -20
instead of : +100 / -120
For some reason, I always returns the code that generates an HTML page of
Foo
return to index
I'm probably missing something really obvious and stupid
so here goes
Code:
<?php
#
#Karma mod-
#
$x = $_GET['x']; // applaud or smite
if($x == "applaud")
{
$x = 1;
}
else
{
$x = -1;
}
$user = $_GET['u']; //Username of victim
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
global $db;
$sql = "select karma_time from " . USERS_TABLE . " where user_id='$userdata['user_id']'"; //get last time user tried a karma vote
$result = $db->sql_query($sql);
$time_old = mysql_fetch_array($result);
$time = time();
$diff = $time - $time_old;
if($diff >= 3600) //make sure they haven't voted in the last hour
{
$sql = "select karma from " . USERS_TABLE . " where username='$user'"; //find the victim
$result = $db->sql_query($sql);
$array = mysql_fetch_array($result);
$karma = $array[0];
$karma += $x; //change the karma based on appluad or smite.
//update the database with current time() for voter
$karma_update = "update" . USERS_TABLE . " set karma = '$karma' where username= '$user'";
$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...
{
echo "<HTML>";
echo "<p>Foo</p>";
echo "<a href=index.php>Return to index</a>";
echo "</HTML>";
return;
}
else
{
echo "<HTML>";
echo "<a href=index.php>Return to index</a>";
echo "</HTML>";
return;
}
}
else
{
echo "<HTML>";
echo "Too soon from last karma vote, <a href=index.php>Return to forums</a>";
echo "</HTML>";
}
?>
also, i can get the number to show up in the user's profile but when i put this:
Code:
Karma: {KARMA}<br /><a href="../../../karma.php?x=applaud&u={postrow.POSTER_NAME}">appluad</a> / <a href="../../../karma.php?x=smite&u={postrow.POSTER_NAME}">smite</a><br />
in the same line after this:
{postrow.POSTER_POSTS}<br />
in
templates/x/viewtopic_body.tpl
where KARMA is something i defined in includes/usercp_viewprofile.php:
Code:
$sql = "select karma from " . USERS_TABLE . " where username='$profiledata[username]'";
$result = $db->sql_query($sql);
$array = mysql_fetch_array($result);
$karma = $array[0];
then I have
Code:
'KARMA' => $karma,
after
Code:
'JOINED' => create_date($lang['DATE_FORMAT'], $profiledata['user_regdate'], $board_config['board_timezone']),
Thanks for your help and bearing with my stupidity
:P
PS
I'm also going to add something to make sure the "victim" and voter aren't the same person
Bookmarks