<?
########## 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 (istleer($kunde))
	{
	 $fehlertext = ltext("stku1_error1");
	 db_close();
	 include("statistiken_start.php");
	 exit();
	}

$id = safe_query( "select kunde from kunden where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) > 0)
	{ #benutzername direkt eingegeben
	 db_close();
	 include("statistiken_kunde2.php");
	 exit();
	}
else
	{ #user nicht gefunden, über suchmuster versuchen
	 $id2 = safe_query( "SELECT kunde FROM kunden WHERE anbieter = ? AND ( kunde LIKE ? OR name LIKE ? OR firma LIKE ? )
			 GROUP BY kunde", TRUE, new SQLString($PHP_AUTH_USER), new SQLString("%$kunde%"), new SQLString("%$kunde%"),
			 new SQLString("%$kunde%") );
	 while ($werte = db_fetch_array($id2))
		{
		 $kunden[] = $werte["kunde"];
		}
	$id3 = safe_query( "SELECT kunde FROM domains WHERE anbieter = ? AND domain LIKE ? GROUP BY kunde", TRUE,
			new SQLString($PHP_AUTH_USER), new SQLString("%$kunde%") );
	while ($werte = db_fetch_array($id3))
		{
		 $tmp = $werte["kunde"];
		 $inarray = 0;
		 for ($i=0; $i < count($kunden); $i++)
			{
			 if ($tmp == $kunden[$i])
				{
				 $inarray = 1;
				}
			}
		 if ($inarray == 0)
			{
			 $kunden[] = $tmp;
			}
		}
	 if (count($kunden) == 0)
		{
		 $fehlertext = ltext("stku1_error2");
		 db_close();
		 include("statistiken_start.php");
		 exit();
		}
	 elseif (count($kunden) == 1)
		{
		 $kunde = $kunden[0];
		 db_close();
		 include("statistiken_kunde2.php");
		 exit();
		}
	 else #sonst sollten mehrere gefunden worden sein
		{
for ($i = 0; $i < count($kunden); $i++)
	{
	 $kunde = $kunden[$i];
	 if ((!istleer($kunde)) && ($i < 26))
	{
	 $id = safe_query( "SELECT name, firma, gesperrt FROM kunden WHERE kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	 $werte = db_fetch_array($id);
	 $name = $werte["name"];
	 $firma = $werte["firma"];
	 $gesperrt = $werte["gesperrt"];
	 if (istleer($name))
		{
		 $name = "".ltext("stku1_nousername")."";
		}
	 if (istleer($firma))
		{
		 $firma = "".ltext("stku1_nofirm")."";
		}
	 $id2 = safe_query( "select domain from domains where kunde = ?  and richtigedomain=1 and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	 $domains = "";
	 while ($werte2 = db_fetch_array($id2))
		{
		 if (!istleer($werte2["domain"]))
			{
			 $domains .= $werte2["domain"] . "<br>";
			}
		}
	 if (istleer($domains))
		{
		 $domains = "".ltext("stku1_nodomain")."";
		}
	 $tabelle[] = array("kunde" => $kunde, "name" => $name, "domains" => $domains, "gesperrt" => $gesperrt);
	 }
	}
## /kundendaten in array
db_close();
$ergebnis = 1;
$fehlertitel = ltext("stku1_errortitle");
$fehlertext = ltext("stku1_error3");
include("statistiken_start.php");
exit();
		}
	}

?>
