Page 1 of 1

Who's in jail?

Posted: Wed Feb 12, 2014 2:52 pm
by njfrlng
Im trying to wrap my head around how to make a module.

Im trying to make a module that shows who is in jail.

Im copying the users online module, but it looks like it pulls that information directly from the users table. (Via the online column)

I don't see anywhere in the databases a spot where jail time is stored.... If im understanding correctly, jail is a variable?

How would I pull that info?

Re: Who's in jail?

Posted: Wed Feb 12, 2014 2:57 pm
by njfrlng
my understanding, which is probably wrong is that I could simply change the FROM table to whatever table stores jail info.

$selectOnlineUsers = $db->Execute("SELECT * FROM `users` WHERE online='yes'");

Re: Who's in jail?

Posted: Wed Feb 12, 2014 3:10 pm
by a_bertrand
The jail "flag" is not in the user table. It is stored in a so called "UserVariable" which uses the user_variables table.

Re: Who's in jail?

Posted: Wed Feb 12, 2014 3:17 pm
by njfrlng
ive been through the user_vars but have no idea which var_id is the jail "flag".

When i go to the variables table (Which I'm assuming would define the var and its var_id) it says its empty.

http://prntscr.com/2rtgap

Re: Who's in jail?

Posted: Wed Feb 12, 2014 3:19 pm
by a_bertrand
it's an auto defined "define" keyword... so use jail ;)
BTW check out the jail module, the lib.php file, and it should be pretty clear.

Re: Who's in jail?

Posted: Wed Feb 12, 2014 3:21 pm
by njfrlng
I shall give that a shot!

Re: Who's in jail?

Posted: Wed Feb 12, 2014 4:26 pm
by njfrlng
I take it this is incorrect:

echo "<table class='plainTable'>";
echo "<tr valign='top'><td width='1%'><img src='{$webBaseDir}modules/jail/images/jail.jpg'></td>";
echo "<td><img src='{$webBaseDir}images/separator.gif' width='10'></td><td>";

if (! IsInJail())
{
TableHeader("Visiting the jail");
echo Translate("You will end up here if you commit some crime. Therefore think twice!");
TableFooter();
}
else
{
TableHeader("Jail Time");
echo Translate("Did something bad? Well you will have to wait %s in jail.", TimeInterval(time(), intval(GetUserVariable(jail))));
TableFooter();
}

TableHeader("Jailed Users");

echo "<table class='plainTable'>";

echo '<th>Username</th>';
echo '<th>Time Left</th>';

$selectJailedUsers = $db->Execute("SELECT * FROM `user_variables` WHERE value='jail'");

if($selectJailedUsers->EOF){
ErrorMessage("No users in jail currently!");
} else {
foreach ($selectJailedUsers as $results) {

echo '<tr><td>';
echo '['.trim($results[0].']'.$results[1]);
echo '</td><td>';
echo date('d/m/Y g:i:s A', strtotime(trim($results[5])));
echo '</td><td>';
}
}

echo "</td></tr></table>";

Re: Who's in jail?

Posted: Wed Feb 12, 2014 4:28 pm
by njfrlng
it works if i use the users table and select something from there.

I'm not getting my head around this variable stuff.

Do I not even need to pull from the user_variables table to show jailed users?

Re: Who's in jail?

Posted: Wed Feb 12, 2014 5:59 pm
by a_bertrand
Maybe so ? ;)

Code: Select all

$selectJailedUsers = $db->Execute("SELECT * FROM `user_variables` WHERE variable_id=?",jail);

Re: Who's in jail?

Posted: Wed Feb 12, 2014 6:01 pm
by njfrlng
Not sure if that works, might try later. But I ended up getting it to work this way:

Code: Select all

$result = $db->Execute("select users.username, user_variables.value
        from users left join user_variables on user_variables.user_id = users.id
        where user_variables.variable_id = ? and user_variables.value > ?", jail, time());

if (! $result->EOF)
{
    TableHeader("Who's in Jail?");
    echo "<table class='plainTable'>";
echo '<th>Username</th>';
echo '<th>Time Left</th>';

    $row = 0;
    while (! $result->EOF)
    {
        if ($row % 2 == 0)
            echo "<tr class='evenLine'>";
        else
            echo "<tr class='oddLine'>";
        echo "<td>{$result->fields[0]}</td>";
        echo "<td>" . TimeInterval(time(), intval($result->fields[1])) . "</td>";
        echo "</tr>";
        $result->MoveNext();
        $row ++;
    }
  
}
$result->Close();

  echo "</table>";
http://prntscr.com/2ruzbj

Now i just need to add a way to bust people out