<?php
/* FIRESHOP: Advanced Content Market System                         */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2012 by Mohamad Porhaji                                */
/* http://Firedesign.ir                                                   */
/*                                                                      */
/* This program is free software.  */
/************************************************************************/
/* $Id: counter.php,v 1.0.0.1 2012/02/18 By Mohamad Porhaji $ */
if (stristr(htmlentities($_SERVER["PHP_SELF"]), "counter.php")) {
    Header("Location: index.php");
    die();
}
@session_start();
global $db;
function FireshopnewCount($total,$todaycounts,$yescounts,$month,$year,$lastyear,$cudate,$lastmonth){
global $db;
$db->sql_query("UPDATE fireshop_counter SET total='$total', lastmonth='$lastmonth', todaycounts='$todaycounts', yescounts='$yescounts', month='$month', year='$year',lastyear='$lastyear',cdate='$cudate'");}
function zone($TheTime,$TimeZone){
$mtime = $TheTime;
$mtime += $TimeZone * 3600;
return $mtime;}
function Fireshopcounter(){
global $db;
$zone = zone(time(),0);
global $tmember;
$h = jdate("H",$zone);
$query=$db->sql_query("SELECT * FROM fireshop_counter");
$row = $db->sql_fetchrow($query);
List( $year, $month, $day ) = split("-", $row['cdate']);
list( $CurrentYear, $CurrentMonth, $CurrentDay ) = split("-", jdate( "Y-m-d",$zone) );
$CurrentDay = ($h < 12) ? ($CurrentDay-1) :  $CurrentDay;
$zone2 = zone(time(),-7);
echo "<script>//".$CurrentDay."- ".$h.": ".jdate("d",$zone2)."</script>";
$cudate                = jdate("Y-m-d");
$cudate				   = $CurrentYear."-".$CurrentMonth."-".$CurrentDay;
$total                 = $row['total'];if(empty($total)){$total=0;}
$todaycounts           = $row['todaycounts'];if(empty($todaycounts)){$todaycounts=0;}
$yescounts             = $row['yescounts'];if(empty($yescounts)){$yescounts=0;}
$monthcounts           = $row['month'];if(empty($monthcounts)){$monthcounts==0;}
$yearcounts            = $row['year'];if(empty($yearcounts)){$yearcounts=0;}
$lastyearcounts        = $row['lastyear'];if(empty($lastyearcounts)){$lastyearcounts=0;}
$lastmonthcounts       = $row['lastmonth'];if(empty($lastmonthcounts)){$lastmonthcounts=0;}
if(!defined('admin')){
++$total;
if ( $CurrentYear == $year )
{if ( $CurrentMonth == $month )
{if ( $CurrentDay == $day)
{define('counted',true);
++$todaycounts;
++$monthcounts;
++$yearcounts;
FireshopnewCount($total,$todaycounts,$yescounts,$monthcounts,$yearcounts,$lastyearcounts,$cudate,$lastmonthcounts);}
if ( $CurrentDay == ++$day )
{global $db;
define('counted',true);
$yescounts = $todaycounts;
$todaycounts = 1;
++$monthcounts;
++$yearcounts;
FireshopnewCount($total,$todaycounts,$yescounts,$monthcounts,$yearcounts,$lastyearcounts,$cudate,$lastmonthcounts);
}}
if ( $CurrentMonth == ++$month )
{
define('counted',true);
$lastmonthcounts = $monthcounts;
$monthcounts = 1;
++$todaycounts;
++$yearcounts;
FireshopnewCount($total,$todaycounts,$yescounts,$monthcounts,$yearcounts,$lastyearcounts,$cudate,$lastmonthcounts);
}}}
if ( $CurrentYear == ++$year )
{
define('counted',true);
$lastyearcounts = $yearcounts;
$yearcounts = 1;
++$monthcounts;
++$todaycounts;
FireshopnewCount($total,$todaycounts,$yescounts,$monthcounts,$yearcounts,$lastyearcounts,$cudate,$lastmonthcounts);
}
if(!defined('counted')){
FireshopnewCount($total,$todaycounts,$yescounts,$monthcounts,$yearcounts,$lastyearcounts,$cudate,$lastmonthcounts);
}global $db;
$session = @$_SERVER['REMOTE_ADDR'];
$time = time();
$time_c = $time - 1200;
$db->sql_query ("DELETE FROM `fireshop_onlines` WHERE time < $time_c");
$db->sql_query ("INSERT INTO `fireshop_onlines` (session, time) VALUES ('$session', '$time')");
$qw1 = $db->sql_query("SELECT session FROM `fireshop_onlines`");
$onlines = $db->sql_numrows ($qw1);
return  array("member" => $tmember,"onlines" => $onlines, "todayv" => $todaycounts, "yesterdayv" => $yescounts,"totalv" =>$total,"lastmonthv" =>$lastmonthcounts,"lastyearv" =>$lastyearcounts,"monthv"=>$monthcounts,"yearv"=>$yearcounts);
}$counter = Fireshopcounter();
?>