<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  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.
  ********************************************
  Main idea from: probinson77 # http://coppermine-gallery.net/forum/index.php?topic=17308.0
  Plugin Created by Bmossavari 21/08/2006
*/

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

// Add an install & configure & uninstall actions
$thisplugin->add_action('plugin_install','online_today_install');
$thisplugin->add_action('plugin_configure','online_today_configure');
$thisplugin->add_action('plugin_uninstall','online_today_uninstall');

// Add block action
$thisplugin->add_filter('plugin_block','online_today');

function online_today_configure()
{
	echo <<< EOT
		After installation Add <strong>onlinetoday</strong> to the value of :<br />
			config => Album list view => The content of the main page
		<br />
		<form action="{$_SERVER['REQUEST_URI']}" method="post">
		<input type="submit" value="Ok !" name="ot" />
		</form>
EOT;
}

function online_today_install()
{
 global $CONFIG;
 if (isset($_POST['ot'])) {
return true;
}else {
		return 1;
	}
}

// Unnstall
function online_today_uninstall()
{
  return true;
}

function online_today($html)
{   
global $CONFIG, $matches ;

        // if you want to show the online today only to admin use this ,if statment :
		// if($matches[1] != 'onlinetoday' || !GALLERY_ADMIN_MODE)
		// if you want to show the online today to registered user use this, if statment:
		// if($matches[1] != 'onlinetoday' || !USER_ID) 
		if($matches[1] != 'onlinetoday') {
          return $matches;
        }
$result = cpg_db_query("SELECT user_id,user_lastvisit FROM {$CONFIG['TABLE_USERS']} WHERE user_lastvisit LIKE '".date("Y-m-d", mktime())
	."%'");

$first = 1;
$total = 0;
$online_today = '';
while ($row = mysql_fetch_array($result)) {
	$total++;
	$user_id = $row['user_id'];
	$user_time = substr($row['user_lastvisit'],10);
	$user_name = get_username($user_id);
	
	    if ($first == 1)
	        {
	            $comma = '';
	            $first = 0;
	        } else {
	            $comma = ', ';
	            }
	     // Remove ( {$user_time} ) from below if you want to remove time
	    $online_today .= $comma . "<a href=\"profile.php?uid={$user_id}\">{$user_name} ( {$user_time} )</a>";
}

starttable("100%", "Users Online Today ($total users)");

echo '<tr><td class="tableb">';
echo "{$online_today}</td></tr>";

endtable();

}	
?>
