Topic: last login

Hi,
I'm trying to make a plugin that shows me the last login of every user.
But it doesn't work very goot, it just shows me an empty table... sad

<?php
/***********************************************************************

  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)

  This file is part of PunBB.

  PunBB 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.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/


/***********************************************************************
                     DO NOT EDIT BELOW THIS LINE
/***********************************************************************/

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);


if (isset($_POST['last_login']))
{
 //datenbank abrufen und nachschauen
 mysql_connect("localhost", "hmmm", "gfdhgf") or die ("Could not connect");       //db571.1und1.de
  mysql_select_db("yszgh") or die ("database doesn't exist");
  $benutzer[]=mysql_query("SELECT username FROM forum_users" or die(mysql_error()));
  $visit[]=mysql_query("SELECT last_visit FROM forum_users" or die(mysql_error()));
  $userzahl=count($visit, COUNT_RECURSIVE);
  
  echo $benutzer;

  echo "<table border=1>
  <tr><td>Benutzername</td><td>Letzter Login</td></tr>";
  echo count($visit);
  print_r ($benutzer);
  print_r ($visit);

  for ($i=0;$i<$userzahl;$i++){
     echo "<tr><td>$benutzer[$i]</td><td>$visit[$i]</td></tr>";
     }
  echo "</table>";
  generate_admin_menu($plugin);
 
}
else
{
    generate_admin_menu($plugin);

?>
    <div class="blockform">
        <h2><span>Last Login</span></h2>
        <div class="box">
            <form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>&foo=bar">
                <div class="inform">
                    <fieldset>
                        <legend>Letzter Login</legend>
                        <div class="infldset">
                            <p>Dieses Plugin zeigt den letzten Login aller Forenmitglieder an</p>

                            <div class="fsetsubmit"><input type="submit" name="last_login" value="Last Login" tabindex="1" /></div>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

I hope anybody can help me the mistake(s) and to fix them.

I'm from Germany, so my english might be wrong sometimes. Sorry!

Re: last login

Mistakes?
1. Use the database abstraction layer
2. Learn how to properly loop through query results. Check viewtopic.php, viewforum.php, index.php, etc for examples. print_r is not an answer tongue

3

Re: last login

can somebody now put the finished plugin?

Re: last login

You joking?
This topic is like... 11 months old. Very much doubt anyone will still have it.

5

Re: last login

but maybe somebody else have something like this

Re: last login

I'm not sure this is what you are looking for but this is how I see the last online time for my users, but I have no idea where you want it. I placed mine in the userlist.php file

First open userlist.php

Find (around line 160)

$result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.' LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());

Replace with or add "u.userlist,"

$result = $db->query('SELECT u.id, u.username, u.title, u.num_posts, u.registered, u.last_visit, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.' LIMIT '.$start_from.', 50') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());

Then find (around line 168

                <tr>
                    <td class="tcl"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td>
                    <td class="tc2"><?php echo $user_title_field ?></td>
<?php if ($show_post_count): ?>                    <td class="tc3"><?php echo $user_data['num_posts'] ?></td>
<?php endif; ?>
                    <td class="tcr"><?php echo format_time($user_data['registered'], true) ?></td>
                </tr>

Replace with

                <tr>
                    <td class="tcl"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td>
                    <td class="tc2"><?php echo $user_title_field ?></td>
<?php if ($show_post_count): ?>                    <td class="tc3"><?php echo $user_data['num_posts'] ?></td>
<?php endif; ?>
                    <td class="tc1"><?php echo format_time($user_data['last_visit']) ?></td>
                    <td class="tc2"><?php echo format_time($user_data['registered'], true) ?></td>
                </tr>

Find (around line 147)

            <tr>
                <th class="tcl" scope="col"><?php echo $lang_common['Username'] ?></th>
                <th class="tc2" scope="col"><?php echo $lang_common['Title'] ?></th>
<?php if ($show_post_count): ?>                <th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
<?php endif; ?>    
                <th class="tcr" scope="col"><?php echo $lang_common['Registered'] ?></th>
            </tr>

Replace with

            <tr>
                <th class="tcl" scope="col"><?php echo $lang_common['Username'] ?></th>
                <th class="tc2" scope="col"><?php echo $lang_common['Title'] ?></th>
<?php if ($show_post_count): ?>                <th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
<?php endif; ?>    
                <th class="tc2" scope="col"><?php echo $lang_common['LastVisit'] ?></th>
                <th class="tcr" scope="col"><?php echo $lang_common['Registered'] ?></th>
            </tr>

Find

<option value="registered"<?php if ($sort_by == 'registered') echo ' selected="selected"' ?>><?php echo $lang_common['Registered'] ?></option>

After add

<option value="last_visit"<?php if ($sort_by == 'last_visit') echo ' selected="selected"' ?>><?php echo $lang_common['LastVisit'] ?></option>

Find

$sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count)) ? 'username' : $_GET['sort_by'];

Replace with

$sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && ($_GET['sort_by'] != 'last_visit' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count))) ? 'username' : $_GET['sort_by'];

Now open /lang/yourlang/common.php
Search for Registered

'Registered'            =>    'Registered',

After that line add

'LastVisit'                =>    'Last Online',

Save Upload smile

Hope that this was something you were looking for smile

Re: last login

awesome work PhaxeNor

Now I can see who the lurkers are on my site! wink