<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once( "../include/class.SQLString.php" );
include_once("auth.php");

## mysql verbindung aufbauen
db_connect($db_host, $db_user, $db_pass);
## /mysql verbindung aufbauen

if	($anbieter == "alle") { $qanbieter = "anbieter like '%'"; }
else	{ $qanbieter = "anbieter='$anbieter'"; }

$id = db_query("select kunde from kunden where $qanbieter");
$anzahlkunden = db_num_rows($id);
$end = $start + $schritte;
$vstart = $start - $schritte;

##transferabfrage alle user
$jahr = date("Y");
$monat = date("m");
$tag = date("d");
$lmonat = $monat - 1;
if (strlen($lmonat) == "1") { $lmonat = "0".$lmonat; }
$ljahr = $jahr;
if ($lmonat == "0") 
	{
	 $lmonat = "12";
	 $ljahr--;
	}
$id2 = db_query("select (sum(ftp + web + email)) as transfer, kunde from transfer where jahr='$jahr' and monat='$monat' and geloescht='0' and $qanbieter group by kunde order by transfer desc");
while ($werte2 = db_fetch_array($id2))
	{
	 $kunde = $werte2["kunde"];
	 $arrayakttransfer[$kunde] = $werte2["transfer"];
	}
$id2 = db_query("select (sum(ftp + web + email)) as ltransfer, kunde from transfer where jahr='$ljahr' and monat='$lmonat' and geloescht='0' and $qanbieter group by kunde order by ltransfer desc");
while ($werte2 = db_fetch_array($id2))
	{
	 $kunde = $werte2["kunde"];
	 $arrayltransfer[$kunde] = $werte2["ltransfer"];
	}
##/transferabfrage alle user

#get kundenliste in richtiger reihenfolge
if (($limit != "yes") && ($db_type == "mysql")) { $qadd = " limit $start,$schritte"; }
elseif (($limit != "yes") && ($db_type != "mysql")) { $qadd = " limit $schritte,$start"; }

if	($order == "kb")
{	 $query = "select sum(kbhomedir+kbdb) as speicherplatz, kunde from kunden where $qanbieter group by kunde order by speicherplatz desc".$qadd; }
elseif  ($order == "email")
{	 $query = "select count(kunde) as emailadressen, kunde from email where $qanbieter group by kunde order by emailadressen desc".$qadd; }
elseif	($order == "pop3")
{	 $query = "select count(kunde) as pops, kunde from pop3 where $qanbieter group by kunde order by pops desc".$qadd; }
else
{	$query = "select kunde from kunden where $qanbieter order by number".$qadd; }

if ($order == "ltransfer")
	{
	 if (count($arrayltransfer) > 0) #sonst erscheint fehlermeldung
		{
		 $i = 0;
		 while ((list($kunde) = each($arrayltransfer)) && (($i < ($schritte + $start)) || ($limit == "yes")))
			{
			 if (($i >= $start) || ($limit == "yes"))
				{
				 $orderedkundenliste[] = $kunde;
				}
			 $i++;
			}
		}
	}
elseif ($order == "atransfer")
	{
	 if (count($arrayakttransfer) > 0)
		{
		 $i = 0;
		 while ((list($kunde) = each($arrayakttransfer)) && (($i < ($schritte + $start)) || ($limit == "yes")))
			{
			 if (($i >= $start) || ($limit == "yes"))
				{
				 $orderedkundenliste[] = $kunde;
				}
			 $i++;
			}
		}
	}
else
	{
	 $id = db_query($query);
	 while ($werte = db_fetch_array($id))
	 	{
		 $orderedkundenliste[] = $werte["kunde"];
		}
	}
#/ get kundenliste

$fertig = 0;
$nbg = $color_light_grey;
$overbg = $fehlerfarbe;
$overlimitusers = 0;

$i = 0;
while (($i < count($orderedkundenliste)) && (!$fertig))
	{
	 $kunde = $orderedkundenliste[$i];
	 $id = db_query("select * from kunden where kunde='$kunde' and $qanbieter");
	 $werte = db_fetch_array($id);
	 $bguser = $nbg;
	 $bgkb = $nbg;
	 $bgpop = $nbg;
	 $bgltransfer = $nbg;
	 $bgakttransfer = $nbg;
	 $useroverlimit = 0;
	 $kunde = $werte["kunde"];
	 $gesperrt = $werte["gesperrt"];

	 $maxkb = $werte["maxkb"];
	 $kbdb = $werte["kbdb"];
	 $kbhomedir = $werte["kbhomedir"];
	 $kb = $kbdb + $kbhomedir;
	 if (($kb > $maxkb) && ($maxkb != "-1")) { $bgkb = $overbg; $useroverlimit = 1; }

	 $maxpop = $werte["maxpop"];
	 $id2 = safe_query( "select kunde from pop3 where kunde = ? ", TRUE, new SQLString( $kunde ) );
	 $pop = db_num_rows($id2);
	 if (($maxpop != "-1") && ($maxpop < $pop)) { $bgpop = $overbg; $useroverlimit = 1; }

	 $maxemail = $werte["maxemail"];
	 $id2 = safe_query( "select kunde from email where kunde = ? ", TRUE, new SQLString( $kunde ) );
	 $email = db_num_rows($id2);
	 if (($maxemail != "-1") && ($maxemail < $email)) { $bgpop = $overbg; $useroverlimit = 1; }

	 $maxmysql = $werte["maxmysql"];
	 $id2 = safe_query( "select kunde from mysql_datenbanken where kunde = ? ", TRUE, new SQLString( $kunde ) );
	 $mysql = db_num_rows($id2);
	 if (($maxmysql != "-1") && ($maxmysql < $mysql)) { $bguser = $overbg; $useroverlimit = 1; }

	 $maxftp = $werte["maxftp"];
	 $id2 = safe_query( "select kunde from ftp where kunde = ? ", TRUE, new SQLString( $kunde ) );
	 $ftp = db_num_rows($id2);
	 if (($maxftp != "-1") && ($maxftp < $ftp)) { $bguser = $overbg; $useroverlimit = 1; }

	 $maxtransfer = $werte["maxtransfer"];
	 $akttransfer = $arrayakttransfer[$kunde];
	 $ltransfer = $arrayltransfer[$kunde];
	 if (($maxtransfer != "-1") && ($maxtransfer < $akttransfer)) { $bgakttransfer = $overbg; $useroverlimit = 1; }
	 if (($maxtransfer != "-1") && ($maxtransfer < $ltransfer)) { $bgltransfer = $overbg; $useroverlimit = 1; }

	 $maxsubdomains = $werte["maxsubdomains"];
	 $id2 = safe_query( "select kunde from domains where kunde = ?  and richtigedomain='0'", TRUE, new SQLString( $kunde ) );
	 $suddomains = db_num_rows($id2);
	 if (($maxsubdomains != "-1") && ($maxsubdomains < $subdomains)) { $bguser = $overbg; $useroverlimit = 1; }

	 if ($useroverlimit == "1") { $overlimitusers++; }
	 if ((($limit == "yes") && ($useroverlimit) && ($overlimitusers > $start) && ($overlimitusers <= $end)) || ($limit != "yes"))
		{
		 $tabelle[] = array(
		 "kunde" => $kunde,
		 "kb" => $kb,
		 "bgkb" => $bgkb,
		 "pop" => $pop,
		 "email" => $email,
		 "bgpop" => $bgpop,
		 "akttransfer" => $akttransfer,
		 "bgakttransfer" => $bgakttransfer,
		 "ltransfer" => $ltransfer,
		 "bgltransfer" => $bgltransfer,
		 "bguser" => $bguser,
		 "gesperrt" => $gesperrt
		 );
		}
	 if ($overlimitusers == $end) { $fertig = 1; }
	 $i++;
	}

db_close();

?>
<HTML>
<HEAD>
<META content="text/html; charset=<? echo $lang_html_charset; ?>" http-equiv=Content-Type>
<LINK href="<?=$strSkinName?>/style.css" rel=stylesheet type=text/css>
</HEAD>

<BODY bgColor=#ffffff bottomMargin=0 leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<br><? include("../fehler.inc.php"); ?>
<script>
function doChange()
{
document.forms[0].submit();
}
</script>
<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
  <TR> 
    <TD width=484> 
      <P><b><? echo ltext("stkun2_title1"); ?></b></P>


<?
if (count($tabelle) < 1)
	{
?>
 
<? echo ltext("stkun2_descr1"); ?>
<?

	} else

	{
?>

      <table  border="0" cellspacing="0">
        <tr> 
          <td ><? if ($start > 0) { ?> <b><i>&lt;&lt;</i></b> 
            <a class=data href="statistik_kunden2.php?schritte=<? echo $schritte; ?>&amp;start=<? echo $vstart; ?>&amp;limit=<? echo $limit; ?>&amp;order=<? echo $order; ?>&amp;anbieter=<? echo $anbieter; ?>"><? echo ltext("stkun2_back");?></a> 
            <? } ?></td>
          <td  align="center">&nbsp;</td>
          <td  align="right"><? if (($anzahlkunden > $end) && (($overlimitusers == $end) || ($limit != "yes"))) { ?> 
            <a class=data href="statistik_kunden2.php?schritte=<? echo $schritte; ?>&amp;start=<? echo $end; ?>&amp;limit=<? echo $limit; ?>&amp;order=<? echo $order; ?>&amp;anbieter=<? echo $anbieter; ?>"><? echo ltext("stkun2_next"); ?></a><b><i> 
            &gt;&gt;</i></b><? } ?></td>
        </tr>
      </table>
      <br>
      <table border=1 bordercolordark=#ffffff bordercolorlight=<? echo $color_dark_grey; ?> 
      cellpadding=3 cellspacing=0 width=481>
        <tr> 
          <td class="titel-3" ><? echo ltext("stkun2_cell_user"); ?></td>
          <td class="titel-3" ><? echo ltext("stkun2_cell_email"); ?></td>
          <td  class="titel-3"  align="right"><? echo ltext("stkun2_cell_traffic"); ?> 
            <? echo $monat; ?>/<? echo $jahr; ?></td>
          <td align="right" class="titel-3" ><? echo ltext("stkun2_cell_traffic"); ?>
            <? echo $lmonat; ?>/<?echo $ljahr; ?></td>
          <td align="right" class="titel-3" >
            <? echo ltext("stkun2_cell_du"); ?>
            </td>
        </tr>
<?
for ($i=0;$i < count($tabelle); $i++)
	{
$kunde = $tabelle[$i]["kunde"];
$kb = sinnv_kbwert($tabelle[$i]["kb"]);
$bgkb = $tabelle[$i]["bgkb"];
$pop = $tabelle[$i]["pop"];
$email = $tabelle[$i]["email"];
$bgpop = $tabelle[$i]["bgpop"];
$bguser = $tabelle[$i]["bguser"];
$akttransfer = sinnv_kbwert($tabelle[$i]["akttransfer"]);
$bgakttransfer = $tabelle[$i]["bgakttransfer"];
$ltransfer = sinnv_kbwert($tabelle[$i]["ltransfer"]);
$bgltransfer = $tabelle[$i]["bgltransfer"];
$gesperrt = $tabelle[$i]["gesperrt"];

?>
	<tr> 
          <td bgcolor=<? echo $bguser; ?> width=47><a class=data href="statistik_kunde2.php?kunde=<?echo $kunde; ?>"><? echo $kunde; ?></a><? if ($gesperrt > 0) { echo "<b><font color=\"red\">!</b>"; } ?></td>
          <td bgcolor=<? echo $bgpop; ?> width=82><? echo $email; ?> 
            / <? echo $pop; ?></td>
          <td width=109 bgcolor=<? echo $bgakttransfer; ?> align="right"><? echo $akttransfer; ?></td>
          <td width=109 bgcolor=<? echo $bgltransfer; ?> align="right"><? echo $ltransfer; ?></td>
          <td width=92 bgcolor=<? echo $bgkb; ?> align="right"><? echo $kb; ?></td>
        </tr>
<? }

?>
      </table>
      <br>
      <table  border="0" cellspacing="0">
        <tr> 
          <td ><? if ($start > 0) { ?> <b><i>&lt;&lt;</i></b>
            <a class=data href="statistik_kunden2.php?schritte=<? echo $schritte; ?>&amp;start=<? echo $vstart; ?>&amp;limit=<? echo $limit; ?>&amp;order=<? echo $order; ?>&amp;anbieter=<? echo $anbieter; ?>"><? echo ltext("stkun2_back"); ?></a>
            <? } ?></td>
          <td  align="center">&nbsp;</td>
          <td  align="right"><? if (($anzahlkunden > $end) && (($overlimitusers == $end) || ($limit != "yes"))) { ?> 
            <a class=data href="statistik_kunden2.php?schritte=<? echo $schritte; ?>&amp;start=<? echo $end; ?>&amp;limit=<? echo $limit; ?>&amp;order=<? echo $order; ?>&amp;anbieter=<? echo $anbieter; ?>"><? echo ltext("stkun2_next"); ?></a><b><i> 
            &gt;&gt;</i></b><? } ?></td>
        </tr>
      </table>

<? } #end elseif count(tabelle) == 0
?>
    </TD>
  </TR>
</TABLE>
</BODY>
</HTML>
