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

global $DEBUG;
//$DEBUG=1;

if($DEBUG){
  echo "kunden_leistungen_upd.php: start<br>\n";
}

include_once( "auth.php" );
include_once( "../include/cron_functions.php" );
include_once( "../include/module.Database.php" );
include_once( "../include/class.SQLFieldSet.php" );

$timestamp = time();

$datenausdbholen = "nein"; 
## wenn fehler in den daten aus dem vorhergehenden formular, 
## sollen die daten nicht neu aus der datenbank geholt werden, 
## sondern die eingaben erhalten bleiben

## eingaben prüfen

if (istleer($speicherplatz)) { $speicherplatz = 0; }
if (istleer($maxkb)) { $maxkb = 0; }
if (istleer($maxpop)) { $maxpop = 0; }
if (istleer($maxemail)) { $maxemail = 0; }
if (istleer($maxautoresponder)) { $maxautoresponder = 0; }
if (istleer($maxftp)) { $maxftp = 0; }
if (istleer($maxtransfer)) { $maxtransfer = 0; }
if (istleer($maxsubdomains)) { $maxsubdomains = 0; }
if (istleer($maxmysql)) { $maxmysql = 0; }
if (istleer($fehlerseiten)) { $fehlerseiten = 0; }
if (istleer($pwschutz)) { $pwschutz = 0; }
if (istleer($statistik)) { $statistik = 0; }
if (istleer($perl)) { $perl = 0; }
if (istleer($modpython)) { $modpython = 0; }
if (istleer($stdcgi)) { $stdcgi = 0; }
if (!$maxcronjobs) { $maxcronjobs = 0; }
if (!$maxmaillist) { $maxmaillist = 0; }

## speicherplatz
if (!ereg("^(0|-?[1-9][0-9]*)$",$maxkb))
{
  $fehlertext = ltext("kuleup_error1");
  include("kunden_neu2.php");
  exit();
}
## //

## MB/GB in KB bei "max. Speicherplatz vom Anbieter" umwandeln
if (($maxkb <> -1) && ($kbtyp == 'MB'))
{
  $maxkb2 = $maxkb * 1024;
}else{ 
  $maxkb2 = $maxkb;
}
## /MB/GB in KB bei "max. Speicherplatz vom Anbieter" umwandeln

if ((($maxkb2 < 1) && ($maxkb2 <> -1))|| ($maxkb2 > 2147283647) || ($maxkb2 < -1))
{
  $fehlertext = ltext("kuleup_error2");
  include("kunden_neu2.php");
  exit();
}

if (($maxpop > 8388607) || ($maxpop < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxpop)))
{
  $fehlertext = ltext("kuleup_error3");
  include("kunden_neu2.php");
  exit();
}

if (($maxemail > 8388607) || ($maxemail < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxemail)))
{
  $fehlertext = ltext("kuleup_error4");
  include("kunden_neu2.php");
  exit();
}

# wenn email < pop dann fehler
if ((($maxemail < $maxpop) && ($maxpop > 0) && ($maxemail <> -1)) || (($maxpop == -1) && ($maxemail <> -1)))
{
  $fehlertext = ltext("kuleup_error5");
  include("kunden_neu2.php");
  exit();
}
# /wenn email < pop dann fehler


if (($maxautoresponder > 8388607) || ($maxautoresponder < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxautoresponder)))
{
  $fehlertext = ltext("kuleup_error6");
  include("kunden_neu2.php");
  exit();
}

# wenn email < autoresponder dann fehler
if ((($maxemail < $maxautoresponder) && ($maxautoresponder > 0) && ($maxemail <> -1)) || (($maxautoresponder == -1) && ($maxemail <> -1)))
{
  $fehlertext = ltext("kuleup_error7");
  include("kunden_neu2.php");
  exit();
}
# /wenn email < autoresponder dann fehler


if (($maxftp > 8388607) || ($maxftp < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxftp)))
{
  $fehlertext = ltext("kuleup_error8");
  include("kunden_neu2.php");
  exit();
}
if (($maxtransfer < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxtransfer)))
{
	$fehlertext = ltext("kuleup_error9");
	include("kunden_neu2.php");
	exit();
}

## MB/GB in KB bei "max. transfer vom Anbieter" umwandeln
if ($maxtransfer <> -1)
{
  $maxtransfer2 = $maxtransfer * 1024;
}
else
{
	$maxtransfer2 = $maxtransfer;
}
## /MB/GB in KB bei "max. transfer vom Anbieter" umwandeln

if ($maxtransfer2 > 2147283647)
{
  $fehlertext = ltext("kuleup_error10");
  include("kunden_neu2.php");
  exit();
}

#if($DEBUG){
#  echo "maxsubdomains: $maxsubdomains<br>\n";
#}
if (($maxsubdomains > 8388607) || ($maxsubdomains < -1) || 
    (!ereg("^(0|-?[1-9][0-9]*)$",$maxsubdomains)))
{
  $fehlertext = ltext("kuleup_error11");
  include("kunden_neu2.php");
  exit();
}
#if($DEBUG){
#  echo "maxmysql: $maxmysql<br>\n";
#}

if (($maxmysql > 32767) || ($maxmysql < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxmysql))){
  $fehlertext = ltext("kuleup_error12");
  include("kunden_neu2.php");
  exit();
}

if (($maxcronjobs < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxcronjobs))){
  $fehlertext = ltext("kuleup_error36");
  include("kunden_neu2.php");
  exit();
}



if(!$wildcard)
  $wildcard='0';

if ( $wildcard < -1 || !ereg( "^(0|-?[1-9][0-9]*)$", $wildcard ) ){
  $fehlertext = ltext("kuleup_error47");
  include("kunden_neu2.php");
  exit();
}

if(!$atdomains)
  $atdomains='0';

if ( $atdomains < -1 || !ereg( "^(0|-?[1-9][0-9]*)$", $atdomains ) ){
  $fehlertext = ltext("kuleup_error48");
  include("kunden_neu2.php");
  exit();
}





if (($maxmaillist < -1) || (!ereg("^(0|-?[1-9][0-9]*)$",$maxmaillist))){
  $fehlertext = ltext("kuleup_error42");
  include("kunden_neu2.php");
  exit();
}

if($DEBUG){
  echo "shell: $shell, scponly: $scponly<br>\n";
}

if (isset($shell)){
  if($shell==2){
    $shell=0;
    $scponly=1;
  }else{
    $scponly=0;
  }
}else{
  $shell=0;
  $scponly=0;
}

if($DEBUG){
  echo "shell: $shell, ftp: $ftp<br>\n";
}

if (($shell == 1) && ($ftp == 0)){
  $fehlertext = ltext("kuleup_error13");
  db_close();
  include("kunden_neu2.php");
  exit();
}

db_connect($db_host, $db_user, $db_pass);

$loUser = new SQLString($PHP_AUTH_USER);
$id = safe_query2( "SELECT * FROM anbieter WHERE anbieter = ?", $loUser);
$serverkann = db_fetch_array($id);

$skmaxpop = $serverkann["maxpop"];
$skmaxkb = $serverkann["maxkb"];
$skmaxemail = $serverkann["maxemail"];
$skmaxautoresponder = $serverkann["maxautoresponder"];
$skmaxftp = $serverkann["maxftp"];
$skmaxsubdomains = $serverkann["maxsubdomains"];
$skmaxwildcards = $serverkann["maxwildcards"];
$skmaxwildcardslimit = $serverkann["maxwildcardslimit"];
$skmaxatdomains = $serverkann["maxatdomains"];
$skmaxmysql = $serverkann["maxmysql"];
$skmaxcronjobs = $serverkann["maxcronjobs"];
$skmaxmaillist = $serverkann['maxmaillist'];

$skmaxkblimit = $serverkann["maxkblimit"];
$skmaxpoplimit = $serverkann["maxpoplimit"];
$skmaxemaillimit = $serverkann["maxemaillimit"];
$skmaxautoresponderlimit = $serverkann["maxautoresponderlimit"];
$skmaxftplimit = $serverkann["maxftplimit"];
$skmaxsubdomainslimit = $serverkann["maxsubdomainslimit"];
$skmaxatdomainslimit = $serverkann["maxatdomainslimit"];
$skmaxmysqllimit = $serverkann["maxmysqllimit"];
$skmaxcronjobslimit = $serverkann["maxcronjobslimit"];
$skmaxmaillistlimit = $serverkann['maxmaillistlimit'];

##
$skphp = $serverkann["php"];
if ($skphp == 0) { $php = 0; }

$skperl = $serverkann["perl"];
if ($skperl == 0) { $perl = 0; $stdcgi = 0; }

$skmodpython = $serverkann["modpython"];
if ($skmodpython==0) { $modpython = 0; }

$skssi = $serverkann["ssi"];
if ($skssi == 0) { $ssi = 0; }

$skssl = $serverkann["cssl"];
if ($skssl == 0) { $ssl = 0; }

$skfrontpage = $serverkann["frontpage"];
if ($skfrontpage == 0) { $frontpage = 0; }

$skshell = $serverkann["shell"];
if ($skshell == 0) { $shell = 0; }

$skscponly = $serverkann["scponly"];
if ($skscponly == 0) { $scponly = 0; }

$skstatistik = $serverkann["statistik"];
if ($skstatistik == 0) { $statistik = 0; }

$skpwschutz = $serverkann["pwschutz"];
if ($skpwschutz == 0) { $pwschutz = 0; }

$skfehlerseiten = $serverkann["fehlerseiten"];
if ($skfehlerseiten == 0) { $fehlerseiten = 0; }

$skwebftp = $serverkann["webftp"];
if ($skwebftp == 0) { $webftp = 0; }

$skwebmail = $serverkann["webmail"];
if ($skwebmail == 0) { $webmail = 0; }

$skstdcgi = $serverkann["stdcgi"];
if ($skstdcgi == 0) { $stdcgi = 0; }

$skspamfilter = $serverkann["spamfilter"];
if($skspamfilter == 0 || $skmaxpop ==0 || $maxpop == 0){
	$spamfilter = 0;
}

$loKunde = new SQLString( $kunde );

# checken, ob pop3,email,ftp,subdomains,mysql schon verwendet wird
$id = safe_query2( "select account from pop3 where kunde=? and anbieter=?", $loKunde, $loUser);
$pop3verwendet = db_num_rows($id);
$id = safe_query2( "select kunde from email where kunde=? and anbieter=?", $loKunde, $loUser);
$emailverwendet = db_num_rows($id);
$id = safe_query2( "select kunde from autoresponder where kunde=? and anbieter=?", $loKunde, $loUser);
$autoresponderverwendet = db_num_rows($id);
$id = safe_query2( "select account from ftp where kunde=? and anbieter=?", $loKunde, $loUser);
$ftpverwendet = db_num_rows($id);
$id = safe_query2( "select domain from domains where kunde=? and anbieter=? and richtigedomain=0", $loKunde, $loUser);
$subdomainsverwendet = db_num_rows($id);
$id = safe_query2( "select domain from domains where kunde=? and anbieter=? and domain like '*.%'", $loKunde, $loUser);
$wildcardsverwendet = db_num_rows($id);
$id = safe_query2( "SELECT COUNT(*) AS cnt FROM atdomains, domains WHERE atdomains.id_from=domains.id AND domains.kunde=?",
									 $loKunde );
$werte = db_fetch_array($id);
$atdomainsvw = $werte["cnt"];
$id = safe_query2( "SELECT COUNT(*) AS cnt FROM maillist INNER JOIN domains ON (domains.id = maillist.domain_id) ".
									 "WHERE maillist.neu <=1 AND domains.kunde=? AND domains.anbieter=?", $loKunde, $loUser);
$werte = db_fetch_array($id);
$maillistvw = $werte['cnt'];

$cronjobsvw = count_cron_jobs_user($kunde);

##anzahl mysqldbs
$id = safe_query2( "select count(datenbank) as mysql from mysql_datenbanken where kunde = ?", $loKunde );
$werte = db_fetch_array($id);
$mysqlverwendet = $werte["mysql"];
##anzahl mysqldbs


if (($pop3verwendet > $maxpop) && ($maxpop <> -1)){
  $fehlertext = ltext("kuleup_error14",array($pop3verwendet));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($emailverwendet > $maxemail) && ($maxemail <> -1)){
  $fehlertext = ltext("kuleup_error15",array($emailverwendet));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($autoresponderverwendet > $maxautoresponder) && ($maxautoresponder <> -1)){
  $fehlertext = ltext("kuleup_error16",array($autoresponderverwendet));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($ftpverwendet > $maxftp) && ($maxftp <> -1)){
  $fehlertext = ltext("kuleup_error17",array($ftpverwendet));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($ftp == 0) && ($maxftp != 0)){
  $fehlertext = ltext("kuleup_error18");
  db_close();
  include("kunden_neu2.php");
  exit();
}

#if ($DEBUG){
#  echo "subdomainsverwendet: $subdomainsverwendet, maxsubdomains: $maxsubdomains<br>\n";
#}

if (($subdomainsverwendet > $maxsubdomains) && ($maxsubdomains <> -1)){
  $fehlertext = ltext("kuleup_error19",array($subdomainsverwendet));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($mysqlverwendet > $maxmysql) && ($maxmysql <> -1)){
  $fehlertext = ltext("kuleup_error20",array($mysqlverwendet));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($cronjobsvw > $maxcronjobs) && ($maxcronjobs <> -1)){
  $fehlertext = ltext("kuleup_error37",array($cronjobsvw));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($maillistvw > $maxmaillist) && ($maxmaillist <> -1)){
  $fehlertext = ltext("kuleup_error43",array($maillistvw));
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($wildcardsverwendet > $wildcard) && ($wildcard <> -1))  // only possible with manual db-entries
{
  $fehlertext = ltext("kuleup_error21");
  db_close();
  include("kunden_neu2.php");
  exit();
}

if (($php == 0) && ($phpupload == 1)){
  $fehlertext = ltext("kuleup_error35");
  db_close();
  include("kunden_neu2.php");
  exit();
}

# /checken, ob pop3,email,ftp,subdomains,mysql schon verwendet wird

## speicher überschritten?
$id  = safe_query2( "select sum(maxkb) as kbvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2( "select maxkb from kunden where kunde = ? and anbieter=?", $loKunde, $loUser);
$werte = db_fetch_array($id);
$werte2 = db_fetch_array($id2);
$kbvergeben = $werte["kbvergeben"] - $werte2["maxkb"];
if ((($skmaxkb < ($kbvergeben + $maxkb2)) && ($skmaxkblimit == 1)) || 
    (($maxkb2 == -1) && ($skmaxkblimit == 1))){
  $nurnoch = $skmaxkb - $kbvergeben;
  $fehlertext = ltext("kuleup_error22",array($nurnoch));
  db_close();
  include("kunden_neu2.php");
  exit();
}
## //


## pop3 überschritten?
$id  = safe_query2( "select sum(maxpop) as popvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2( "select maxpop from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$popvergeben = $werte["popvergeben"] - $werte2["maxpop"];
if ((($skmaxpop < ($popvergeben + $maxpop)) && ($skmaxpoplimit == 1)) 
    || (($maxpop == -1) && ($skmaxpoplimit == 1))){
  $nurnoch = $skmaxpop - $popvergeben;
  $fehlertext = ltext("kuleup_error23",array($nurnoch));
  db_close();
  include("kunden_neu2.php");
  exit();
}
## //





/* -------------------- wildcard sub-domains -------------------- */
if ( $skmaxwildcardslimit && $skmaxwildcards != -1 )
{
    $id = safe_query2( "select domain from domains where kunde<>? and anbieter=? and domain like '*.%'", 
											 $loKunde, $loUser );
    $other = db_num_rows($id);
    if ( $wildcard==-1 || $other + $wildcard > $skmaxwildcards )
    {
	$fehlertext = ltext("kuleup_error24");
	db_close();
	include("kunden_neu2.php");
	exit();
    }
}
/* -------------------- end wildcard sub-domains -------------------- */ 





/* -------------------- at domains -------------------- */
if(!$atdomains) $atdomains=0;

if ( $skmaxatdomainslimit ){
  if ( $skmaxatdomains != -1 ){
    $sql="SELECT SUM(maxatdomains) AS other FROM kunden WHERE anbieter = " . 
		db_full_quote($PHP_AUTH_USER) .
		" AND kunde <> " . db_full_quote($kunde);
    $id = db_query ( $sql );
    $werte = db_fetch_array($id);
    $other= $werte["other"];
    if ( $atdomains == -1 || $werte["other"]+$atdomains > $skmaxatdomains ){
      $fehlertext = ltext( "kuleup_error46", array( $skmaxatdomains-$werte["other"] ) );
      db_close();
      include("kunden_neu2.php");
      exit();
    }
  }
}
if ( $atdomains != -1 && $atdomainsvw > $atdomains ){
  $fehlertext = ltext( "kuleup_error45", array($atdomainsvw) );
  db_close();
  include("kunden_neu2.php");
  exit();
}
/* -------------------- end at domains -------------------- */

#if($DEBUG){
#  echo "maxsubdomains: $maxsubdomains, wildcard: $wildcard<br>\n";
#}
if (($maxsubdomains == 0) && ($wildcard == 1)){
  $fehlertext = ltext("kuleup_error25");
  db_close();
  include("kunden_neu2.php");
  exit();
}

## email überschritten?
$id  = safe_query2( "select sum(maxemail) as emailvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2( "select maxemail from kunden where kunde = ? and anbieter=?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$emailvergeben = $werte["emailvergeben"] - $werte2["maxemail"];
if ((($skmaxemail < ($emailvergeben + $maxemail)) && ($skmaxemaillimit == 1)) || 
    (($maxemail == -1) && ($skmaxemaillimit == 1))){
  $nurnoch = $skmaxemail - $emailvergeben;
  $fehlertext = ltext("kuleup_error26",array($nurnoch));
  db_close();
  include("kunden_neu2.php");
  exit();
}
## //

## autoresponder überschritten?
$id  = safe_query2( "select sum(maxautoresponder) as autorespondervergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2( "select maxautoresponder from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$autorespondervergeben = $werte["autorespondervergeben"] - $werte2["maxautoresponder"];
if ((($skmaxautoresponder < ($autorespondervergeben + $maxautoresponder)) && ($skmaxautoresponderlimit == 1)) || (($maxautoresponder == -1) && ($skmaxautoresponderlimit == 1)))
{
	$nurnoch = $skmaxautoresponder - $autorespondervergeben;
	$fehlertext = ltext("kuleup_error27",array($nurnoch));
	db_close();
	include("kunden_neu2.php");
	exit();
}
## //


## ftp überschritten?
$id  = safe_query2( "select sum(maxftp) as ftpvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2( "select maxftp from kunden where kunde = ? and anbieter=?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$ftpvergeben = $werte["ftpvergeben"] - $werte2["maxftp"];
if ((($skmaxftp < ($ftpvergeben + $maxftp)) && ($skmaxftplimit == 1)) || (($maxftp == -1) && ($skmaxftplimit == 1)))
{
	$nurnoch = $skmaxftp - $ftpvergeben;
	$fehlertext = ltext("kuleup_error28",array($nurnoch));
	db_close();
	include("kunden_neu2.php");
	exit();
}
## //

## subdomains überschritten?
$id  = safe_query2("select sum(maxsubdomains) as subdomainsvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2("select maxsubdomains from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$subdomainsvergeben = $werte["subdomainsvergeben"] - $werte2["maxsubdomains"];
if ((($skmaxsubdomains < ($subdomainsvergeben + $maxsubdomains)) && ($skmaxsubdomainslimit == 1)) || (($maxsubdomains == -1) && ($skmaxsubdomainslimit == 1)))
{
	$nurnoch = $skmaxsubdomains - $subdomainsvergeben;
	$fehlertext = ltext("kuleup_error29",array($nurnoch));
	db_close();
	include("kunden_neu2.php");
	exit();
}
## //

## mysql überschritten?
$id  = safe_query2( "select sum(maxmysql) as mysqlvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2( "select maxmysql from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$mysqlvergeben = $werte["mysqlvergeben"] - $werte2["maxmysql"];
if ((($skmaxmysql < ($mysqlvergeben + $maxmysql)) && ($skmaxmysqllimit == 1)) || (($maxmysql == -1) && ($skmaxmysqllimit == 1)))
{
	//echo "ba";
	$nurnoch = $skmaxmysql - $mysqlvergeben;
	$fehlertext = ltext("kuleup_error30",array($nurnoch));
	db_close();
	include("kunden_neu2.php"); //echo "ba";
	exit();
}
## //

## cron jobs
$id  = safe_query2("select sum(maxcronjobs) as cronjobsvergeben from kunden where anbieter = ?", $loUser);
$id2 = safe_query2("select maxcronjobs from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
//echo "select sum(maxcronjobs) as cronjobsvergeben from kunden where anbieter = '$PHP_AUTH_USER'";
$cronjobsvergeben = $werte["cronjobsvergeben"] - $werte2["maxcronjobs"];
if ((($skmaxcronjobs < ($cronjobsvergeben + $maxcronjobs)) && ($skmaxcronjobslimit == 1)) || (($maxcronjobs == -1) && ($skmaxcronjobslimit == 1)))
{
	//echo "aaa";
	$nurnoch = $skmaxcronjobs - $cronjobsvergeben;
	$fehlertext = ltext("kuleup_error38",array($nurnoch));
	db_close();
	include("kunden_neu2.php");
	exit();
}
## //

## mailing lists
$id  = safe_query2("select sum(maxmaillist) as mlsum from kunden where anbieter = ?", $loUser);
$id2 = safe_query2("select maxmaillist from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte2 = db_fetch_array($id2);
$werte = db_fetch_array($id);
$mlsum = $werte["mlsum"] - $werte2["maxmaillist"];
if ((($skmaxmaillist < ($mlsum + $maxmaillist)) && ($skmaxmaillistlimit == 1)) || (($maxmaillist == -1) && ($skmaxmaillistlimit == 1)))
{
	//echo "aaa";
	$nurnoch = $skmaxmaillist - $mlsum;
	$fehlertext = ltext("kuleup_error44",array($nurnoch));
	db_close();
	include("kunden_neu2.php");
	exit();
}
## //

if (($stdcgi == 1) && ($perl != 1))
{
	$fehlertext = ltext("kuleup_error31");
	db_close();
	include("kunden_neu2.php");
	exit();
}


## Fehlerseiten, Passwortschutz
$id = safe_query2( "select fehlerseiten, pwschutz from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte = db_fetch_array($id);
$altfehlerseiten = $werte["fehlerseiten"];
$altpwschutz = $werte["pwschutz"];

$id = safe_query2( "select domain from domains where kunde=? and anbieter=? and richtigedomain=3 and frontpage=1",
									 $loKunde, $loUser);
if (db_num_rows($id) > 0)
{
	$frontpage = 1;
}

if ($altfehlerseiten <> $fehlerseiten)
{
	if (($frontpage == 1) && ($fehlerseiten == 1))
	{
		$fehlertext = ltext("kuleup_error32");
		db_close();
		include("kunden_neu2.php");
		exit();
	}
	elseif ($fehlerseiten == 0)
	{
		$id = safe_query2( "select pfad from fehlermeldungen where kunde=?", $loUser);
		while ($werte = db_fetch_array($id))
		{
			$pfad = $werte["pfad"];
			safe_query2( "insert into htaccess (kunde, pfad) VALUES (?, ?)", $loKunde, new SQLString($pfad) );
		}
		safe_query2( "delete from fehlermeldungen where kunde=?", $loKunde );
		db_query("update allgemein set htaccess = 1");
	}
}

if ($altpwschutz <> $pwschutz)
{
	if (($frontpage == 1) && ($pwschutz == 1))
	{
		$fehlertext = ltext("kuleup_error33");
		db_close();
		include("kunden_neu2.php");
		exit();	 
	}
	elseif ($pwschutz == 0)
	{
		$id = safe_query2( "select pfad from pwschutz where kunde=?", $loKunde);
		while ($werte = db_fetch_array($id))
		{
			$pfad = $werte["pfad"];
			safe_query2( "insert into htaccess (kunde, pfad) VALUES (?, ?)", $loKunde, new SQLString($pfad) );
		}
		safe_query2( "delete from pwschutz where kunde=?", $loKunde );
		db_query("update allgemein set htaccess = 1");
	}
}
## //

## Scponly
$id=safe_query2( "select scponly from kunden where kunde=?", $loKunde);
$werte = db_fetch_array($id);
$altscponly = $werte["scponly"];
if ($scponly <> $altscponly && $scponly){
  $scponly=2;
}
## /Scponly

## Perl & Webalizer
$id = safe_query2( "select perl, statistik from kunden where kunde=?", $loKunde);
$werte = db_fetch_array($id);
$altperl = $werte["perl"];
$altstatistik = $werte["statistik"];

if (($perl <> $altperl))
{
	$idperl = safe_query( "select neu, loeschen from perl where kunde=?", $loKunde );
	$werte = db_fetch_array($idperl);
	$neuperl = $werte["neu"];
	$loeschenperl = $werte["loeschen"];
	if (db_num_rows($idperl) > 0)
	{
		if ((($perl == 0) && ($neuperl == 1)) || (($perl == 1) && ($loeschenperl == 1)))
		{
			safe_query2( "delete from perl where kunde=?", $loKunde );
		}
		elseif ($perl == 1)
		{
			safe_query2( "update perl set loeschen=0, neu=1 where kunde = ?", $loKunde);
			safe_query2( "update allgemein set perl=1" );
		}
		elseif ($perl == 0)
		{
			safe_query2( "update perl set loeschen='1', neu='0' where kunde = ?", $loKunde);
			db_query("update allgemein set perl=1");
		}
	}
	elseif ($perl == 1)
	{
		safe_query2( "insert into perl (kunde, loeschen, neu, anbieter) VALUES (?, 0, 1, ?)", $loKunde, $loUser);
		db_query("update allgemein set perl=1, httpd=1");
	}
	elseif ($perl == 0)
	{
		safe_query2( "insert into perl (kunde, loeschen, neu, anbieter) VALUES (?, 1, 0, ?)", $loKunde, $loUser);
		db_query("update allgemein set perl=1, httpd=1");	 
	}
}

if ($statistik <> $altstatistik)
{
	$idwebalizer = safe_query2( "select neu, loeschen from webalizer where kunde=?", $loKunde);
	$werte = db_fetch_array($idwebalizer);
	$neustatistik = $werte["neu"];
	$loeschenstatistik = $werte["loeschen"];
	if (db_num_rows($idwebalizer) > 0)
	{
		if ((($statistik == 0) && ($neustatistik == 1)) || (($statistik == 1) && ($loeschenstatistik == 1)))
		{
			safe_query2( "delete from webalizer where kunde=?", $loKunde, $loUser);
		}
		elseif ($statistik == 1)
		{
			safe_query2( "update webalizer set loeschen=0, neu=1 where kunde = ?", $loKunde );
			db_query( "update allgemein set webalizer=1");
		}
		elseif ($statistik == 0)
		{
			safe_query2( "update webalizer set loeschen=1, neu=0 where kunde = ?", $loKunde);
			db_query("update allgemein set webalizer=1");
		}
	}
	elseif ($statistik == 1)
	{
		safe_query2( "insert into webalizer (kunde, loeschen, neu, anbieter) VALUES (?, 0, 1, ?)", $loKunde, $loUser);
		db_query("update allgemein set webalizer=1, httpd=1");
	}
	elseif ($statistik == 0)
	{
		safe_query2( "insert into webalizer (kunde, loeschen, neu, anbieter) VALUES (?, 1, 0, ?)", $loKunde, $loUser);
		db_query("update allgemein set webalizer=1, httpd=1");
	}
}

db_query("update allgemein set quota=1, newpwd=1, adduser=1");
if ($stdcgi == 1)
{
	db_query("update allgemein set stdcgi=1");
}
## /Perl & Webalizer

## DirectoryListing kann wert '2' haben, wenn vom kunden aktiviert

$id = safe_query2( "select dirlist from kunden where kunde=?", $loKunde);
$werte = db_fetch_array($id);
$kunde_dirlist = $werte["dirlist"];
if (($kunde_dirlist == 2) && ($dirlist == 1))
{ 
	$dirlist = 2;
}

if ( $perl && ( $altperl == 2 ) ) {
	$perl = 2;
}


## wenn phpupload aktiviert wird, dann webserver reloaden
$id = safe_query2( "select phpupload, coldfusion from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte = db_fetch_array($id);
if ( ($werte["phpupload"] != $phpupload) || ($werte["coldfusion"] != $coldfusion ) )
{
	db_query("update allgemein set httpd = 1");
}

$id = safe_query2( "select spamfilter from kunden where kunde = ? and anbieter = ?", $loKunde, $loUser);
$werte = db_fetch_array($id);
if ( ($werte["spamfilter"] != $spamfilter))
	{
	 db_query("update allgemein set spamupdate = 1");
	}

if(!$coldfusion )
  $coldfusion ='0';

$loFields = new SQLFieldSet( array( 'maxpop' => $maxpop,
																		'maxkb' => $maxkb2,
																		'maxmysql' => $maxmysql,
																		'maxemail' => $maxemail,
																		'maxautoresponder' => $maxautoresponder,
																		'maxftp' => $maxftp,
																		'maxtransfer' => $maxtransfer2,
																		'maxsubdomains' => $maxsubdomains,
																		'maxcronjobs' => $maxcronjobs,
																		'php' => $php,
																		'ftp' => $ftp,
																		'wildcard' => $wildcard,
																		'maxatdomains' => $atdomains,
																		'frontpage' => $frontpage,
																		'perl' => $perl,
																		'modpython' => $modpython,
																		'ssi' => $ssi,
																		'shell' => $shell,
																		'scponly' => $scponly,
																		'statistik' => $statistik,
																		'pwschutz' => $pwschutz,
																		'fehlerseiten' => $fehlerseiten,
																		'webftp' => $webftp,
																		'webmail' => $webmail,
																		'stdcgi' => $stdcgi,
																		'quota' => 1,
																		'lastchange' => $timestamp,
																		'phpupload' => $phpupload,
																		'wap' => $wap,
																		'coldfusion' => $coldfusion,
																		'dirlist' => $dirlist,
																		'spamfilter' => $spamfilter,
																		'maxidn' => -1,
																		'maxmaillist' => $maxmaillist
																		)
														 );

## // eingaben überprüfen
$sql = "UPDATE kunden SET ".$loFields->getSQLUpdate()." WHERE kunde = ? AND anbieter = ?";
if($DEBUG){
  echo "sql: $sql<br>\n";
}
safe_query2( $sql, new SQLString($kunde), new SQLString($PHP_AUTH_USER) );
$fehlertitel = ltext("kuleup_errortitle");
$fehlertext = ltext("kuleup_error34");
db_close();
include("kunden_aendern.php");
exit();

?>
