$a5 = mysql_query($a4);
}
// SPIELER MIT FALSCHEM BESITZER RUNTER ENDE
// ALTE AUKTIONEN BEENDEN UND VERTRAEGE ABSCHLIESSEN ANFANG
$sql1 = "SELECT spieler, besitzer, bieter_highest, betrag_highest, autorestart FROM " . $prefix . "transfermarkt WHERE ende < " . time();
$sql2 = mysql_query($sql1);
while ($sql3 = mysql_fetch_assoc($sql2)) {
    if ($sql3['bieter_highest'] != 'keiner') {
        $sql6 = "DELETE FROM " . $prefix . "transfermarkt WHERE spieler = '" . $sql3['spieler'] . "'";
        $sql7 = mysql_query($sql6);
        // WEITERE SPIELERDATEN HOLEN ANFANG
        $getmanager1 = "SELECT vorname, nachname, marktwert, spiele_verein, staerke FROM " . $prefix . "spieler WHERE ids = '" . $sql3['spieler'] . "'";
        $getmanager2 = mysql_query($getmanager1);
        $getmanager3 = mysql_fetch_assoc($getmanager2);
        // WEITERE SPIELERDATEN HOLEN ENDE
        $vertragsende = endOfDay(getTimestamp('+29 days'));
        // 29 Tage
        $neuesGehalt = round(pow($sql3['betrag_highest'] / 1000, 1.385 + 0.006 * 3));
        $sql4 = "UPDATE " . $prefix . "spieler SET transfermarkt = 0, leiher = 'keiner', vertrag = " . $vertragsende . ", gehalt = " . $neuesGehalt . ", startelf_Liga = 0, startelf_Pokal = 0, startelf_Cup = 0, startelf_Test = 0, spiele_verein = 0, moral = 100, frische = " . getRegularFreshness(GameTime::getMatchDay()) . ", team = '" . $sql3['bieter_highest'] . "' WHERE ids = '" . $sql3['spieler'] . "'";
        $sql5 = mysql_query($sql4);
        $move1 = "INSERT INTO " . $prefix . "transfers (spieler, besitzer, bieter, datum, gebot, damaligerWert, spiele_verein, damaligeStaerke) VALUES ('" . $sql3['spieler'] . "', '" . $sql3['besitzer'] . "', '" . $sql3['bieter_highest'] . "', " . time() . ", " . $sql3['betrag_highest'] . ", " . $getmanager3['marktwert'] . ", " . $getmanager3['spiele_verein'] . ", " . $getmanager3['staerke'] . ")";
        $move2 = mysql_query($move1);
        if ($move2 !== FALSE) {
            // TRANSFERSTEUER ANFANG
            $transfersteuer = round($sql3['betrag_highest'] * 0.05);
            $kontoabzug = round($sql3['betrag_highest'] * 1.05);
            $buch1 = "INSERT INTO " . $prefix . "buchungen (team, verwendungszweck, betrag, zeit) VALUES ('" . $sql3['bieter_highest'] . "', 'Transfersteuer', -" . $transfersteuer . ", " . time() . ")";
            $buch2 = mysql_query($buch1);
            // TRANSFERSTEUER ENDE
            $sql4 = "UPDATE " . $prefix . "teams SET konto = konto-" . $kontoabzug . " WHERE ids = '" . $sql3['bieter_highest'] . "'";
            $sql5 = mysql_query($sql4);
<?php

if (!isset($_GET['mode'])) {
    include 'zzserver.php';
}
define('COMPUTER_MINIMUM_KONTOSTAND', 20000000);
$in_14_tagen = endOfDay(getTimestamp('+14 days'));
$ligaToKlasse = array();
$lig1a = "SELECT ids, name FROM " . $prefix . "ligen";
$lig1b = mysql_query($lig1a);
while ($lig1c = mysql_fetch_assoc($lig1b)) {
    $ligaToKlasse[$lig1c['ids']] = substr($lig1c['name'], -1);
}
$demoTeamID1 = "SELECT team FROM " . $prefix . "users WHERE ids = '" . CONFIG_DEMO_USER . "'";
$demoTeamID2 = mysql_query($demoTeamID1);
$sqlIsDemoTeam = "";
if (mysql_num_rows($demoTeamID2) == 1) {
    $demoTeamID3 = mysql_result($demoTeamID2, 0);
    $sqlIsDemoTeam = " OR ids = '" . mysql_real_escape_string($demoTeamID3) . "'";
}
$urlaub1 = "SELECT user, team FROM " . $prefix . "urlaub WHERE ende > " . time();
$urlaub2 = mysql_query($urlaub1);
$urlaub_string = "('LEER', ";
$beurlaubte_teams = array();
while ($urlaub3 = mysql_fetch_assoc($urlaub2)) {
    if ($urlaub3['user'] != CONFIG_DEMO_USER) {
        $urlaub_string .= "'" . $urlaub3['user'] . "', ";
        $beurlaubte_teams[] = $urlaub3['team'];
    }
}
$urlaub_string = substr($urlaub_string, 0, -2);
    return round(pow(M_E, $rand), 1);
}
function choosePosition()
{
    if (Chance_Percent(12)) {
        return 'T';
    } elseif (Chance_Percent(24)) {
        return 'S';
    } elseif (Chance_Percent(50)) {
        return 'M';
    } else {
        return 'A';
    }
}
// KONFIGURATION ANFANG
$in_33_tagen = endOfDay(getTimestamp('+33 days'));
$spieltage_mit_aktion = array(3, 6, 9, 12, 15, 18, 21);
if (!in_array(GameTime::getMatchDay(), $spieltage_mit_aktion)) {
    exit;
}
$datum_stamp = mktime(0, 0, 0, date('m', time()), date('d', time()), date('Y', time()));
$datum_stamp_alt = getTimestamp('-36 hours', $datum_stamp);
// vor 1,5 Tagen
$vor1 = "SELECT name FROM " . $prefix . "namen_pool WHERE typ = 1";
$vor2 = mysql_query($vor1);
$vor2a = mysql_num_rows($vor2) - 1;
$vornamen = array();
while ($vor3 = mysql_fetch_assoc($vor2)) {
    $vornamen[] = $vor3['name'];
}
$nach1 = "SELECT name FROM " . $prefix . "namen_pool WHERE typ = 2";
</p>
<?php 
    setTaskDone('finance_prognosis');
    // WERTE INITIALISIEREN ANFANG
    $ausgaben_jugendtrainer = 0;
    $fitnesstrainer3 = 0;
    $physiotherapeut = 0;
    $abloesesteuer3 = 0;
    $sponsor_einkommen = 0;
    $leihPraemien_ein = 0;
    $leihPraemien_aus = 0;
    $sonstiges_aus = 0;
    $sonstiges_ein = 0;
    $ausgaben_stadion = 0;
    // WERTE INITIALISIEREN ENDE
    $buchungsBeginn = endOfDay(getTimestamp('-' . GameTime::getMatchDay() . ' days'));
    $spe1 = "SELECT verwendungszweck, SUM(betrag), AVG(betrag) FROM " . $prefix . "buchungen WHERE team = '" . $cookie_team . "' AND zeit > " . $buchungsBeginn . " AND betrag != 0 GROUP BY verwendungszweck";
    $spe2 = mysql_query($spe1);
    while ($spe3 = mysql_fetch_assoc($spe2)) {
        switch ($spe3['verwendungszweck']) {
            case 'Sponsoring':
                if (GameTime::getMatchDay() != 0) {
                    $sponsor_einkommen = $spe3['AVG(betrag)'] * 22;
                }
                break;
            case 'Transfersteuer':
                $abloesesteuer3 = -$spe3['SUM(betrag)'];
                break;
            case 'Regenerations-Camp':
                $fitnesstrainer3 = -$spe3['SUM(betrag)'];
                break;
    if (!isset($playerData['vertrag'])) {
        throw new Exception('Property "vertrag" not set in player data');
    } elseif (!isset($playerData['wiealt'])) {
        throw new Exception('Property "wiealt" not set in player data');
    } elseif (!isset($playerData['moral'])) {
        throw new Exception('Property "moral" not set in player data');
    } else {
        return $playerData['vertrag'] < getTimestamp('+' . $durationDays . ' days') && ($playerData['wiealt'] + GAME_DAYS_TO_REAL_DAYS_RATIO * $durationDays) / 365 < 35 && $playerData['moral'] >= getMinMoraleRequired($durationDays);
    }
}
if (isset($_POST['laufzeit']) && isset($_POST['spieler'])) {
    $laufzeit = intval(trim($_POST['laufzeit']));
    $spieler_id = mysql_real_escape_string(trim(strip_tags($_POST['spieler'])));
    if ($laufzeit == 22 || $laufzeit == 44 || $laufzeit == 66) {
        if ($cookie_id != CONFIG_DEMO_USER) {
            $laufzeit_end = endOfDay(getTimestamp('+' . $laufzeit . ' days'));
            $ina = "SELECT marktwert, wiealt, vertrag, moral FROM " . $prefix . "spieler WHERE ids = '" . $spieler_id . "' AND team = '" . $cookie_team . "'";
            $inb = mysql_query($ina);
            if (mysql_num_rows($inb) == 0) {
                exit;
            }
            $inc = mysql_fetch_assoc($inb);
            if (isContractOptionAvailable($inc, $laufzeit)) {
                $pLevels = getPercentageLevels(round($inc['wiealt'] / 365));
                switch ($laufzeit) {
                    case 22:
                        $percentageLevel = $pLevels[0];
                        break;
                    case 44:
                        $percentageLevel = $pLevels[1];
                        break;