<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: counter.php,v 1.6.2.2 2004/04/18 12:45:41 ajvwaay Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* 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.       */
/************************************************************************/

/* Get the Browser data */

global $mpnTables;

if((ereg("Nav", getenv("HTTP_USER_AGENT"))) || (ereg("Gold", getenv("HTTP_USER_AGENT"))) || (ereg("X11", getenv("HTTP_USER_AGENT"))) || (ereg("Mozilla", getenv("HTTP_USER_AGENT"))) || (ereg("Netscape", getenv("HTTP_USER_AGENT"))) AND (!ereg("MSIE", getenv("HTTP_USER_AGENT")))) $browser = "Netscape";
elseif(ereg("MSIE", getenv("HTTP_USER_AGENT"))) $browser = "MSIE";
elseif(ereg("Lynx", getenv("HTTP_USER_AGENT"))) $browser = "Lynx";
elseif(ereg("Opera", getenv("HTTP_USER_AGENT"))) $browser = "Opera";
elseif(ereg("WebTV", getenv("HTTP_USER_AGENT"))) $browser = "WebTV";
elseif(ereg("Konqueror", getenv("HTTP_USER_AGENT"))) $browser = "Konqueror";
elseif((eregi("bot", getenv("HTTP_USER_AGENT"))) || (ereg("Google", getenv("HTTP_USER_AGENT"))) || (ereg("Slurp", getenv("HTTP_USER_AGENT"))) || (ereg("Scooter", getenv("HTTP_USER_AGENT"))) || (eregi("Spider", getenv("HTTP_USER_AGENT"))) || (eregi("Infoseek", getenv("HTTP_USER_AGENT")))) $browser = "Bot";
else $browser = "Other";

/* Get the Operating System data */
if(ereg("Win", getenv("HTTP_USER_AGENT"))) $os = "Windows";
elseif((ereg("Mac", getenv("HTTP_USER_AGENT"))) || (ereg("PPC", getenv("HTTP_USER_AGENT")))) $os = "Mac";
elseif(ereg("Linux", getenv("HTTP_USER_AGENT"))) $os = "Linux";
elseif(ereg("FreeBSD", getenv("HTTP_USER_AGENT"))) $os = "FreeBSD";
elseif(ereg("SunOS", getenv("HTTP_USER_AGENT"))) $os = "SunOS";
elseif(ereg("IRIX", getenv("HTTP_USER_AGENT"))) $os = "IRIX";
elseif(ereg("BeOS", getenv("HTTP_USER_AGENT"))) $os = "BeOS";
elseif(ereg("OS/2", getenv("HTTP_USER_AGENT"))) $os = "OS/2";
elseif(ereg("AIX", getenv("HTTP_USER_AGENT"))) $os = "AIX";
else $os = "Other";

/* Save on the databases the obtained values */

mysql_query("UPDATE ".$mpnTables['counter']." SET count = count + 1 WHERE ( type = 'total' and var = 'hits' ) or ( var = '$browser' and type = 'browser' ) or ( var = '$os' and type = 'os' )" );


/* 4nStats Per-Day-Counter */

  $xydate=date("dmY");

  $xyval=mysql_query("SELECT * from ".$mpnTables['4nstats_datecnt']." WHERE date = '$xydate'" );
  $ttemp = @mysql_fetch_array($xyval);

  $happend = $ttemp['hits'];

  if ($happend == "" || $happend == false || ! $happend )
  {
     mysql_query("INSERT INTO ".$mpnTables['4nstats_datecnt']." ( date, hits ) VALUES ( '$xydate', '1' )");
  }
  else
  {
    mysql_query( "UPDATE ".$mpnTables['4nstats_datecnt']." SET hits = hits + 1 WHERE date = '$xydate'" );
  }

  /* 4nStats Per-Hour-Counter */
  $xyhour=date("G");
  mysql_query("UPDATE ".$mpnTables['4nstats_hourcnt']." SET hits=hits+1 WHERE hour='$xyhour'");

  /* N4nStats Weekday-Counter */
  $xyweekday=date("w");
  mysql_query("UPDATE ".$mpnTables['4nstats_weekcnt']." SET hits=hits+1 WHERE weekday='$xyweekday'");

  /* 4nStats Month-Counter */
  $xymonth=date("m");
  mysql_query("UPDATE ".$mpnTables['4nstats_monthcnt']." SET hits=hits+1 WHERE month='$xymonth'");
?>
