<?php
/* ====================
[BEGIN_COT_EXT]
Hooks=global
Order=9
[END_COT_EXT]
==================== */

defined('COT_CODE') or die('Wrong URL');

require_once cot_incfile('whosonline', 'plug');

$sys['whosonline_all_count'] = $sys['whosonline_reg_count'] + $sys['whosonline_vis_count'];
$out['whosonline'] = ($cfg['disablewhosonline']) ? '' : cot_declension($sys['whosonline_reg_count'], $Ls['Members']).(!$cfg['plugin']['whosonline']['disable_guests'] ? ', '.cot_declension($sys['whosonline_vis_count'], $Ls['Guests']) : '');

if (COT_AJAX && $usr['id'] > 0)
{
    $whsupd = (empty($sys['online_location']) ? array(
              'online_ip' => $usr['ip'],
							'online_name' => $usr['name'],
							'online_lastseen' => (int)$sys['now'],
							'online_userid' => (int)$usr['id'],
							'online_shield' => 0,
							'online_hammer' => 0
  			 ) : array(
              'online_lastseen' => $sys['now'],
							'online_hammer' => (int)$sys['online_hammer']
  			 ));

		if ($db->query("SELECT COUNT(*) FROM $db_online WHERE online_userid=".$usr['id'].' LIMIT 1')->fetchColumn() > 0)
		{
      $db->update($db_online, $whsupd, "online_userid=".$usr['id']);
		}
		else
		{
      $db->insert($db_online, $whsupd);
		}
}