Пример #1
0
                 }
             } else {
                 $previousSeasonBest = 0;
                 $perfSeason = 0;
             }
         }
     }
     //}
 }
 if (!empty($_POST[$p])) {
     if ($_POST[$t] == 'time') {
         $secflag = false;
         if (substr($_POST[$p], 0, 2) >= 60) {
             $secflag = true;
         }
         $pt = new PerformanceTime($_POST[$p], $secflag);
         $perf = $pt->getPerformance();
         $ps = new PerformanceTime($previousSeasonBest, $secflag);
         $perfSeason = $ps->getPerformance();
     } else {
         $pa = new PerformanceAttempt($_POST[$p]);
         $perf = $pa->getPerformance();
         $ps = new PerformanceAttempt($previousSeasonBest);
         $perfSeason = $ps->getPerformance();
     }
     if ($perf == NULL) {
         // invalid performance
         $perf = 0;
     }
     if ($perfSeason == NULL) {
         // invalid performance
Пример #2
0
 function validate($performance, $info, $secFlag = false)
 {
     require './lib/cl_performance.lib.php';
     // validate result
     $perf = new PerformanceTime($performance, $secFlag);
     $this->performance = $perf->getPerformance();
     if (is_null($this->performance)) {
         $GLOBALS['AA_ERROR'] = $GLOBALS['strErrInvalidResult'] . $performance;
     }
     $this->info = $GLOBALS['cfgResultsInfoFill'];
     return 0;
 }
Пример #3
0
             $nbr = AA_getNextStartnbr($nbr);
         }
     }
 }
 if (!$_POST['techDisc']) {
     $group = '';
 }
 if (empty($_POST['perf'])) {
     $perf = 0;
 } else {
     if ($_POST['techDisc']) {
         $perf = new PerformanceAttempt($_POST['perf']);
         $perf->performance = $perf->getPerformance();
         $perf = $perf->getPerformance();
     } else {
         $perf = new PerformanceTime($_POST['perf'], false);
         $perf->performance = $perf->getPerformance();
         $perf = $perf->getPerformance();
     }
 }
 $quali = $_POST['quali'];
 if (empty($_POST['quali'])) {
     $quali = 0;
 }
 // add
 mysql_query("INSERT INTO teamsm SET\r\n\t\t\t\t\tName = '" . $_POST['name'] . "'\r\n\t\t\t\t\t, xKategorie = " . $_POST['category'] . "\r\n\t\t\t\t\t, xVerein = " . $_POST['club'] . "\r\n\t\t\t\t\t, xWettkampf = " . $_POST['event'] . "\r\n                    , Startnummer = " . $nbr . " \r\n                    , Gruppe = '" . $group . "'\r\n                    , Quali = " . $quali . "    \r\n                    , Leistung = " . $perf . "   \r\n\t\t\t\t\t, xMeeting = " . $_COOKIE['meeting_id'] . "");
 if (mysql_errno() > 0) {
     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
 } else {
     $xTeam = mysql_insert_id();
 }
Пример #4
0
 function processDiscipline($event, $disctype, $catname, $discname, $windmeas, $list)
 {
     global $rFrom, $rTo, $limitRank, $date;
     require 'config.inc.php';
     $teams = array();
     // team array
     $countRes = 3;
     // results per team counting
     $order_perf = "";
     $order_perf_sort = "";
     $valid_result = "";
     if ($disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow]) {
         $order_perf = "DESC";
         $order_perf_sort = "DESC";
     } else {
         if ($disctype == $cfgDisciplineType[$strDiscTypeJump]) {
             if ($windmeas == 1) {
                 // with wind
                 $order_perf = "DESC, r.Info ASC";
                 $order_perf_sort = "DESC";
             } else {
                 // without wind
                 $order_perf = "DESC";
                 $order_perf_sort = "DESC";
             }
         } else {
             if ($disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                 $order_perf = "DESC";
                 $order_perf_sort = "DESC";
                 $valid_result = " AND (r.Info LIKE '%O%' OR r.Leistung < 0)";
             } else {
                 $order_perf = "ASC";
                 $order_perf_sort = "ASC";
             }
         }
     }
     $sql_leistung = $order_perf == 'ASC' ? "r.Leistung" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, r.Leistung) * -1), r.Leistung)";
     $sql = "\r\n        SELECT\r\n            ts.xTeamsm\r\n            , ts.Name\r\n            , v.Name\r\n            , at.Name\r\n            , at.Vorname\r\n            , a.Startnummer\r\n            , " . $sql_leistung . " AS leistung_neu\r\n            , at.xAthlet\r\n            , r.Leistung \r\n            , ss.Rang\r\n        FROM\r\n            teamsm AS ts\r\n            LEFT JOIN verein AS v ON (v.xVerein = ts.xVerein)\r\n            LEFT JOIN teamsmathlet AS tsa ON (tsa.xTeamsm = ts.xTeamsm)\r\n            LEFT JOIN anmeldung AS a ON (a.xAnmeldung = tsa.xAnmeldung)\r\n            LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n            LEFT jOIN start AS st ON (st.xAnmeldung = tsa.xAnmeldung)\r\n            LEFT JOIN serienstart AS ss ON (ss.xStart = st.xStart )\r\n            LEFT JOIN resultat AS r ON ( r.xSerienstart = ss.xSerienstart)\r\n            LEFT JOIN serie AS se ON (ss.xSerie = se.xSerie)\r\n            LEFT JOIN runde as ru ON (se.xRunde = ru.xRunde)  \r\n        WHERE\r\n            ts.xWettkampf = {$event}       \r\n            AND st.xWettkampf = {$event}  \r\n            AND ru.Datum LIKE '" . $date . "'  \r\n            {$valid_result}    \r\n        ORDER BY\r\n            ts.xTeamsm\r\n            , leistung_neu {$order_perf}\r\n    ";
     $res = mysql_query($sql);
     if (mysql_errno() > 0) {
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $team = 0;
         // current team
         $c = 0;
         // count results
         $athletes = array();
         $teams_notValid = array();
         // team array
         while ($row = mysql_fetch_array($res)) {
             $row_res[6] = $row_res[6] == 1 || $row_res[6] == 2 || $row_res[6] == 3 || $row_res[6] == 4 ? $row_res[6] * -1 : ($row_res[6] == 9 ? -99 : $row_res[6]);
             if (isset($athletes[$row[7]])) {
                 continue;
             } else {
                 $athletes[$row[7]] = 1;
             }
             if ($team != $row[0]) {
                 if ($team > 0) {
                     $countAthl = count($teams[$team]['athletes']);
                     if ($countAthl < $countRes) {
                         $teams[$team]['perf'] = 0;
                         $teams[$team]['perfTot'] = 0;
                         $teams[$team]['rankTot'] = 0;
                         $teams[$team]['perfBest'] = 0;
                         $teams[$team]['rankBest'] = 0;
                         $teams[$team]['perfNotValid'] = 0;
                         $teams_notValid[$team]['club'] = $teams[$team]['club'];
                         $teams_notValid[$team]['name'] = $teams[$team]['name'];
                         $teams_notValid[$team]['perf'] = 0;
                         $teams_notValid[$team]['athletes'] = $teams[$team]['athletes'];
                     } else {
                         $notValidPerf = false;
                         $countNotValid = 0;
                         foreach ($teams[$team]['athletes'] as $key => $val) {
                             if ($pos = strpos($val, "-1") || ($pos = strpos($val, "-2") || ($pos = strpos($val, "-3") || ($pos = strpos($val, "-4"))))) {
                                 $notValidPerf = true;
                                 $countNotValid++;
                             }
                         }
                         if (!$notValidPerf) {
                             $teams[$team]['perf'] /= $countRes;
                         } else {
                             $countValid = $countRes - $countNotValid;
                             if (isset($teams[$team]['athletes'][3])) {
                                 if ($pos = strpos($teams[$team]['athletes'][0], "-1") || ($pos = strpos($teams[$team]['athletes'][0], "-2") || ($pos = strpos($teams[$team]['athletes'][0], "-3") || ($pos = strpos($teams[$team]['athletes'][0], "-4"))))) {
                                     $tmp_at = $teams[$team]['athletes'][0];
                                     $teams[$team]['athletes'][0] = substr($teams[$team]['athletes'][3], 1, -1);
                                     list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][0]);
                                     $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                                 } elseif ($pos = strpos($teams[$team]['athletes'][1], "-1") || ($pos = strpos($teams[$team]['athletes'][1], "-2") || ($pos = strpos($teams[$team]['athletes'][1], "-3") || ($pos = strpos($teams[$team]['athletes'][1], "-4"))))) {
                                     $tmp_at = $teams[$team]['athletes'][1];
                                     $teams[$team]['athletes'][1] = substr($teams[$team]['athletes'][3], 1, -1);
                                     list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][1]);
                                     $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                                 } elseif ($pos = strpos($teams[$team]['athletes'][2], "-1") || ($pos = strpos($teams[$team]['athletes'][2], "-2") || ($pos = strpos($teams[$team]['athletes'][2], "-3") || ($pos = strpos($teams[$team]['athletes'][2], "-4"))))) {
                                     $tmp_at = $teams[$team]['athletes'][2];
                                     $teams[$team]['athletes'][2] = substr($teams[$team]['athletes'][3], 1, -1);
                                     list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][2]);
                                     $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                                 }
                                 if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeNone']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrack']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrackNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeDistance']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeRelay']]) {
                                     $perf = new PerformanceTime($atPerf, $secFlag);
                                     $atPerf = $perf->getPerformance();
                                 } else {
                                     if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJump']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJumpNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeThrow']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeHigh']]) {
                                         $perf = new PerformanceAttempt($performance);
                                         $atPerf = $perf->getPerformance();
                                     }
                                 }
                                 if ($countNotValid == 2) {
                                     $teams[$team]['perf'] += $atPerf;
                                     $teams[$team]['perf'] = $teams[$team]['perf'] / $countNotValid;
                                 } elseif ($countNotValid == 1) {
                                     $teams[$team]['perf'] += $atPerf;
                                     $teams[$team]['perf'] = $teams[$team]['perf'] / $countRes;
                                     $notValidPerf = false;
                                 } elseif ($countNotValid == 3) {
                                     $teams[$team]['perf'] += $atPerf;
                                 }
                             }
                         }
                         if ($order_perf == 'ASC') {
                             if ($notValidPerf) {
                                 $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                                 $teams[$team]['perf'] = 99999999;
                             }
                         } else {
                             if ($notValidPerf) {
                                 $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                             }
                         }
                     }
                 }
                 $team = $row[0];
                 $teams[$team]['club'] = $row[2];
                 $teams[$team]['name'] = $row[1];
                 $c = 0;
             }
             $perf = 0;
             $perf_print = 0;
             $rank = 0;
             $asc = true;
             if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                 $perf = $row[6];
                 $asc = false;
                 if ($row[8] >= 0) {
                     $perf_print = AA_formatResultMeter($row[6]);
                 } else {
                     $perf_print = $perf * -1;
                 }
             } else {
                 $perf = ceil($row[6] / 10) * 10;
                 // round up 1000
                 $asc = true;
                 if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                     $perf_print = AA_formatResultTime($row[6], true, true);
                 } else {
                     $perf_print = AA_formatResultTime($row[6], true);
                 }
             }
             $rank = $row[9];
             if ($c < $countRes) {
                 $teams[$team]['perf'] += $perf;
                 $teams[$team]['perfTot'] += $perf;
                 $teams[$team]['rankTot'] += $rank;
                 if ($asc) {
                     if ($perf < $teams[$team]['perfBest'] || $teams[$team]['perfBest'] == 0) {
                         $teams[$team]['perfBest'] = $perf;
                         $teams[$team]['rankBest'] = $rank;
                     }
                 } else {
                     if ($perf > $teams[$team]['perfBest']) {
                         $teams[$team]['perfBest'] = $perf;
                         $teams[$team]['rankBest'] = $rank;
                     }
                 }
                 $teams[$team]['athletes'][] = "{$row['3']} {$row['4']}, {$perf_print}";
             } else {
                 $teams[$team]['athletes'][] = "[{$row['3']} {$row['4']}, {$perf_print}]";
             }
             $c++;
         }
         if ($team > 0) {
             // calc last team
             $countAthl = count($teams[$team]['athletes']);
             if ($countAthl < $countRes) {
                 $teams[$team]['perf'] = 0;
                 $teams[$team]['perfNotValid'] = 0;
                 $teams_notValid[$team]['club'] = $teams[$team]['club'];
                 $teams_notValid[$team]['name'] = $teams[$team]['name'];
                 $teams_notValid[$team]['perf'] = 0;
                 $teams_notValid[$team]['athletes'] = $teams[$team]['athletes'];
             } else {
                 $notValidPerf = false;
                 $countNotValid = 0;
                 foreach ($teams[$team]['athletes'] as $key => $val) {
                     if ($pos = strpos($val, "-1") || ($pos = strpos($val, "-2") || ($pos = strpos($val, "-3") || ($pos = strpos($val, "-4"))))) {
                         $notValidPerf = true;
                         $countNotValid++;
                     }
                 }
                 if (!$notValidPerf) {
                     $teams[$team]['perf'] /= $countRes;
                 } else {
                     $countValid = $countRes - $countNotValid;
                     if (isset($teams[$team]['athletes'][3])) {
                         if ($pos = strpos($teams[$team]['athletes'][0], "-1") || ($pos = strpos($teams[$team]['athletes'][0], "-2") || ($pos = strpos($teams[$team]['athletes'][0], "-3") || ($pos = strpos($teams[$team]['athletes'][0], "-4"))))) {
                             $tmp_at = $teams[$team]['athletes'][0];
                             $teams[$team]['athletes'][0] = substr($teams[$team]['athletes'][3], 1, -1);
                             list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][0]);
                             $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                         } elseif ($pos = strpos($teams[$team]['athletes'][1], "-1") || ($pos = strpos($teams[$team]['athletes'][1], "-2") || ($pos = strpos($teams[$team]['athletes'][1], "-3") || ($pos = strpos($teams[$team]['athletes'][1], "-4"))))) {
                             $tmp_at = $teams[$team]['athletes'][1];
                             $teams[$team]['athletes'][1] = substr($teams[$team]['athletes'][3], 1, -1);
                             list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][1]);
                             $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                         } elseif ($pos = strpos($teams[$team]['athletes'][2], "-1") || ($pos = strpos($teams[$team]['athletes'][2], "-2") || ($pos = strpos($teams[$team]['athletes'][2], "-3") || ($pos = strpos($teams[$team]['athletes'][2], "-4"))))) {
                             $tmp_at = $teams[$team]['athletes'][2];
                             $teams[$team]['athletes'][2] = substr($teams[$team]['athletes'][3], 1, -1);
                             list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][2]);
                             $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                         }
                         if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeNone']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrack']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrackNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeDistance']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeRelay']]) {
                             $perf = new PerformanceTime($atPerf, $secFlag);
                             $atPerf = $perf->getPerformance();
                         } else {
                             if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJump']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJumpNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeThrow']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeHigh']]) {
                                 $perf = new PerformanceAttempt($performance);
                                 $atPerf = $perf->getPerformance();
                             }
                         }
                         if ($countNotValid == 2) {
                             $teams[$team]['perf'] += $atPerf;
                             $teams[$team]['perf'] = $teams[$team]['perf'] / $countNotValid;
                         } elseif ($countNotValid == 1) {
                             $teams[$team]['perf'] += $atPerf;
                             $teams[$team]['perf'] = $teams[$team]['perf'] / $countRes;
                             $notValidPerf = false;
                         } elseif ($countNotValid == 3) {
                             $teams[$team]['perf'] += $atPerf;
                         }
                     }
                 }
                 if ($order_perf == 'ASC') {
                     if ($notValidPerf) {
                         $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                         $teams[$team]['perf'] = 99999999;
                     }
                 } else {
                     if ($notValidPerf) {
                         $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                     }
                 }
             }
         }
         $teams_valid = array();
         foreach ($teams as $k => $arr_team) {
             if (!isset($teams_notValid[$k]['name'])) {
                 $teams_valid[$k]['name'] = $teams[$k]['name'];
                 $teams_valid[$k]['club'] = $teams[$k]['club'];
                 $teams_valid[$k]['perf'] = $teams[$k]['perf'];
                 $teams_valid[$k]['perfTot'] = $teams[$k]['perfTot'];
                 $teams_valid[$k]['rankTot'] = $teams[$k]['rankTot'];
                 $teams_valid[$k]['perfBest'] = $teams[$k]['perfBest'];
                 $teams_valid[$k]['rankBest'] = $teams[$k]['rankBest'];
                 $teams_valid[$k]['perfNotValid'] = $teams[$k]['perfNotValid'];
                 $teams_valid[$k]['athletes'] = $teams[$k]['athletes'];
             }
         }
         $teams = $teams_valid;
         //
         // print team ranking
         //
         if (count($teams) > 0) {
             $list->printSubTitle($catname, $discname, "");
             $list->startList();
             $list->printHeaderLine();
             usort($teams, "cmp_{$order_perf_sort}");
             // sort by performance
             $teams = array_merge($teams, $teams_notValid);
             $rank = 1;
             // initialize rank
             $r = 0;
             // start value for ranking
             $p = 0;
             foreach ($teams as $team) {
                 $r++;
                 if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                     // limit ranks if set (export)
                     continue;
                 }
                 if ($team['perf'] > 0) {
                     $rank = $r;
                 } else {
                     $rank = '';
                 }
                 if ($team['perf'] == 99999999) {
                     $team['perf'] = $team['perfNotValid'];
                 }
                 $perf = 0;
                 if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                     $perf = AA_formatResultMeter($team['perf']);
                 } else {
                     if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                         $perf = AA_formatResultTime($team['perf'], true, true);
                     } else {
                         $perf = AA_formatResultTime($team['perf'], true);
                     }
                 }
                 if ($perf == 0 || !empty($team['perfNotValid'])) {
                     $rank = '';
                 }
                 $list->printLine($rank, $team['name'], $team['club'], $perf);
                 // print each athlete with result for team
                 $tmp = "";
                 foreach ($team['athletes'] as $athlete) {
                     $end = "";
                     list($name, $perfNotValid) = split(',', $athlete);
                     if (strpos($perfNotValid, "]")) {
                         $perfNotValid = substr($perfNotValid, 0, -1);
                         $end = "]";
                     }
                     if ($perfNotValid == $cfgInvalidResult['DNS']['code']) {
                         $perfNotValid = $cfgInvalidResult['DNS']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     } elseif ($perfNotValid == $cfgInvalidResult['DNF']['code']) {
                         $perfNotValid = $cfgInvalidResult['DNF']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     } elseif ($perfNotValid == $cfgInvalidResult['DSQ']['code']) {
                         $perfNotValid = $cfgInvalidResult['DSQ']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     } elseif ($perfNotValid == $cfgInvalidResult['NRS']['code']) {
                         $perfNotValid = $cfgInvalidResult['NRS']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     }
                     //$list->printInfo($athlete);
                     $tmp .= $athlete . " / ";
                 }
                 $list->printInfo(substr($tmp, 0, -2));
                 $p = $team['perf'];
                 // keep current performance
                 $keep_team = $team;
                 // keep current performance
             }
             $list->endList();
         }
     }
 }
Пример #5
0
 $licnr_keep = 0;
 $perfSeason = 0;
 while ($row_start = mysql_fetch_array($res_start)) {
     // get performance from base data
     $perf = 0;
     $sql = "SELECT season_effort, notification_effort \r\n\t\t\t\t\t  FROM base_performance \r\n\t\t\t\t LEFT JOIN base_athlete USING(id_athlete) \r\n\t\t\t\t\t WHERE base_athlete.license = " . $row_start['License'] . " \r\n\t\t\t\t\t   AND base_performance.discipline = " . $row_start['DiszCode'] . " \r\n\t\t\t\t\t   AND season = '" . $saison . "';";
     $res = mysql_query($sql);
     $rowPerf = mysql_fetch_array($res);
     $perf = $rowPerf['notification_effort'];
     // best effort current or previous year (Indoor: best of both / Outdoor: best of outdoor)
     $perfSeason = $rowPerf['season_effort'];
     if ($row_start['Typ'] == $cfgDisciplineType[$strDiscTypeTrack] || $row_start['Typ'] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row_start['Typ'] == $cfgDisciplineType[$strDiscTypeRelay] || $row_start['Typ'] == $cfgDisciplineType[$strDiscTypeDistance]) {
         // disciplines track
         $pt = new PerformanceTime(trim($perf));
         $perf = $pt->getPerformance();
         $ps = new PerformanceTime(trim($perfSeason));
         $perfSeason = $ps->getPerformance();
     } else {
         $perf = ltrim($perf, "0") * 100;
         $perfSeason = ltrim($perfSeason, "0") * 100;
     }
     if (empty($perf)) {
         $perf = 0.0;
     }
     if (empty($perfSeason)) {
         $perfSeason = 0;
     }
     if ($perf != NULL) {
         // invalid performance
         $sql = "UPDATE start SET \r\n\t\t\t\t  Bestleistung = {$perf}\r\n                 , VorjahrLeistung = {$perfSeason}\r\n\t\t\t\t , BaseEffort = 'y'\r\n\t\t\t\t WHERE xStart = " . $row_start['xStart'];
         //echo " <br>$sql";
Пример #6
0
function XML_regZLV_start($parser, $name, $attr)
{
    global $bCombined, $arr_noCat;
    global $strBaseAthleteNotFound, $strLicenseNr;
    global $cfgDisciplineType, $strDiscTypeTrack, $strDiscTypeTrackNoWind, $strDiscTypeRelay, $strDiscTypeDistance, $strNoSuchCategory;
    global $cfgCombinedDef, $cfgCombinedWO;
    if ($name == "ATHLETE") {
        $regNr = $attr['ANMELDENR'];
        $license = $attr['LIZENZNR'];
        $name = $attr['NAME'];
        $firstname = $attr['VORNAME'];
        $birth = $attr['GEBDAT'];
        $arr_birth = explode(".", $birth);
        $birthdate = $arr_birth[2] . "-" . $arr_birth[1] . "-" . $arr_birth[0];
        $birthyear = $arr_birth[2];
        $club = $attr['VEREIN'];
        $sex = $attr['GESCHLECHT'];
        $nationality = $attr['NATIONALITAET'];
        $cat = $attr['KATEGORIE'];
        $group = $attr['GRUPPENR'];
        $starttime = $attr['STARTZEIT'];
        $license_paid = $attr['BEZ'];
        if ($license_paid == '') {
            $license_paid = 'n';
        }
        $registerNr = $attr['ANMELDENR'];
        $meetingDate = '';
        $discode = 0;
        if ($license > 0) {
            // check if event exist for this cateory and select event to get all generated events ids
            $sql = "SELECT \r\n                            w.xWettkampf,\r\n                            w.Mehrkampfcode,\r\n                            m.DatumVon \r\n                    FROM\r\n                            wettkampf as w\r\n                            LEFT JOIN kategorie as k on (w.xKategorie = k.xKategorie)\r\n                            LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d on (w.xDisziplin = d.xDisziplin)\r\n                            LEFT JOIN meeting AS m ON (m.xMeeting = w.xMeeting)\r\n                    WHERE \r\n                            w.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                            AND k.Code = '" . $cat . "'";
            $res = mysql_query($sql);
            if (mysql_errno() > 0) {
                AA_printErrorMsg("xml-1-" . mysql_errno() . ": " . mysql_error());
            }
            if (mysql_num_rows($res) > 0) {
                while ($row_dis = mysql_fetch_assoc($res)) {
                    $xDis[] = $row_dis['xWettkampf'];
                    if ($row_dis['Mehrkampfcode'] > 0) {
                        $discode = $row_dis['Mehrkampfcode'];
                        // same for all combined disciplines
                    }
                    $meetingDate = $row_dis['DatumVon'];
                }
                $athlete_id = 0;
                $sql2 = "SELECT TRIM(lastname) AS lastname, \r\n                                        TRIM(firstname) AS firstname, \r\n                                        substring(birth_date, 1,4) AS jahrgang, \r\n                                        license, \r\n                                        TRIM(sex) AS sex, \r\n                                        nationality, \r\n                                        birth_date, \r\n                                        account_code, \r\n                                        second_account_code,\r\n                                        id_athlete,\r\n                                        license_paid \r\n                                 FROM base_athlete \r\n                                 WHERE license = '" . $license . "';";
                $query2 = mysql_query($sql2);
                if (mysql_errno() > 0) {
                    AA_printErrorMsg("xml-2-" . mysql_errno() . ": " . mysql_error());
                } else {
                    if ($query2 && mysql_num_rows($query2) == 1) {
                        // athlete exist in base data
                        $row2 = mysql_fetch_assoc($query2);
                        $club = $row2['account_code'];
                        $club2 = $row2['second_account_code'];
                        $athlete_id = $row2['id_athlete'];
                        $result2 = mysql_query("SELECT xVerein FROM verein WHERE xCode = '" . $club . "'");
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg("xml-3-" . mysql_errno() . ": " . mysql_error());
                        } else {
                            $rowClub1 = mysql_fetch_array($result2);
                            $club = $rowClub1[0];
                            if (!empty($club2)) {
                                $result2 = mysql_query("SELECT xVerein FROM verein WHERE xCode = '" . $club2 . "'");
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg("xml-4-" . mysql_errno() . ": " . mysql_error());
                                    $club2 = 0;
                                    // prevents from insert error in next statement
                                } else {
                                    $rowClub2 = mysql_fetch_array($result2);
                                    $club2 = $rowClub2[0];
                                }
                            } else {
                                $club2 = 0;
                            }
                        }
                        mysql_free_result($result2);
                        // check if athlete exist        // check if athlete is already in "athlet" table
                        $sql4 = "SELECT xAthlet FROM athlet WHERE Lizenznummer = '" . $license . "'";
                        $query4 = mysql_query($sql4);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg("xml-5-" . mysql_errno() . ": " . mysql_error());
                        }
                        if (mysql_num_rows($query4) > 0) {
                            $row4 = mysql_fetch_assoc($query4);
                            $sql3 = "UPDATE athlet \r\n                                                    SET Name = '" . trim($row2['lastname']) . "', \r\n                                                    Vorname = '" . trim($row2['firstname']) . "', \r\n                                                    Jahrgang = '" . trim($row2['jahrgang']) . "', \r\n                                                    Geschlecht = '" . trim($row2['sex']) . "', \r\n                                                    Land = '" . trim($row2['nationality']) . "', \r\n                                                    Geburtstag = '" . trim($row2['birth_date']) . "', \r\n                                                    xVerein = '" . trim($club) . "', \r\n                                                    xVerein2 = '" . trim($club2) . "', \r\n                                                    Lizenznummer = '" . trim($license) . "',\r\n                                                    Bezahlt = '" . trim($row2['license_paid']) . "',\r\n                                                    Manuell = 0   \r\n                                             WHERE (Lizenznummer = '" . trim($license) . "' \r\n                                                    OR (Name = '" . trim($row2['lastname']) . "' \r\n                                                    AND Vorname = '" . trim($row2['firstname']) . "' \r\n                                                    AND Jahrgang = '" . trim($row2['jahrgang']) . "' \r\n                                                    AND xVerein = '" . trim($club) . "'));";
                            $query3 = mysql_query($sql3);
                            $xAthlete = $row4['xAthlet'];
                        } else {
                            // if club is valid
                            // insert athlete from base data
                            if (is_numeric($club)) {
                                $sql = "INSERT INTO athlet \r\n                                                            (Name, Vorname, Jahrgang, \r\n                                                            Lizenznummer, Geschlecht, Land, \r\n                                                            Geburtstag, xVerein, xVerein2, Bezahlt, Lizenztyp)\r\n                                                        SELECT \r\n                                                            TRIM(lastname), TRIM(firstname), substring(birth_date, 1,4), \r\n                                                            license, TRIM(sex), nationality, \r\n                                                            birth_date, '{$club}', '{$club2}', license_paid, '1'\r\n                                                        FROM\r\n                                                            base_athlete\r\n                                                        WHERE\r\n                                                            license = {$license}";
                                mysql_query($sql);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg("xml-6-" . mysql_errno() . ": " . mysql_error());
                                } else {
                                    $xAthlete = mysql_insert_id();
                                }
                            }
                        }
                        if ($xAthlete > 0) {
                            // check if already registered
                            $result = mysql_query("SELECT xAnmeldung FROM anmeldung WHERE xAthlet = {$xAthlete} AND xMeeting = " . $_COOKIE['meeting_id'] . "");
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-7-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                // get license category from base data
                                $res = mysql_query("    \r\n                                                        SELECT k.xKategorie FROM\r\n                                                            kategorie as k\r\n                                                            LEFT JOIN base_athlete as b on (k.Code = b.license_cat)\r\n                                                        WHERE b.license = " . $license);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg("xml-8-" . mysql_errno() . ": " . mysql_error());
                                } else {
                                    $row = mysql_fetch_array($res);
                                    $xCat = $row[0];
                                    if ($xCat != '') {
                                        if (mysql_num_rows($result) == 0) {
                                            // not yet registered
                                            // insert
                                            mysql_query("INSERT INTO anmeldung SET\r\n                                                                Startnummer = 0\r\n                                                                , Bezahlt = '" . $row2['license_paid'] . "'\r\n                                                                , Gruppe = '" . $group . "'  \r\n                                                                , xAthlet = {$xAthlete}\r\n                                                                , xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                                                                , xKategorie = {$xCat}\r\n                                                                , Anmeldenr_ZLV = {$registerNr}");
                                            if (mysql_errno() > 0) {
                                                AA_printErrorMsg("xml-9-" . mysql_errno() . ": " . mysql_error());
                                            } else {
                                                $xReg = mysql_insert_id();
                                            }
                                        } else {
                                            // update
                                            $row = mysql_fetch_array($result);
                                            mysql_query("Update anmeldung SET\r\n                                                                Startnummer = 0\r\n                                                                , Bezahlt = '" . $row2['license_paid'] . "'  \r\n                                                                 , Gruppe = '" . $group . "'   \r\n                                                                , xAthlet = {$xAthlete}\r\n                                                                , xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                                                                , xKategorie = {$xCat}\r\n                                                                , Anmeldenr_ZLV = {$registerNr}\r\n                                                                WHERE xAnmeldung = {$row['0']}");
                                            if (mysql_errno() > 0) {
                                                AA_printErrorMsg("xml-10-" . mysql_errno() . ": " . mysql_error());
                                            } else {
                                                $xReg = $row[0];
                                            }
                                        }
                                    } else {
                                        $result2 = mysql_query("SELECT license_cat \r\n                                                                        FROM base_athlete\r\n                                                                        WHERE license = {$license};");
                                        $row2 = mysql_fetch_array($result2);
                                        $license_cat = $row2[0];
                                        AA_printErrorMsg(str_replace('%cat%', $license_cat, $strNoSuchCategory));
                                    }
                                }
                                // only combined events for ZLV
                                // effort are points, saved on registration
                                $sql = "SELECT notification_effort \r\n                                                        FROM base_performance\r\n                                                        WHERE id_athlete = {$athlete_id}\r\n                                                        AND    discipline = {$discode}";
                                $res_effort = mysql_query($sql);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg("xml-11-" . mysql_errno() . ": " . mysql_error());
                                } else {
                                    if (mysql_num_rows($res_effort) > 0) {
                                        $row_effort = mysql_fetch_assoc($res_effort);
                                        $effort = $row_effort['notification_effort'];
                                        mysql_query("UPDATE anmeldung SET\r\n                                                                            BestleistungMK = '{$effort}'\r\n                                                                            , xMeeting = " . $_COOKIE['meeting_id'] . "  \r\n                                                                     WHERE\r\n                                                                            xAnmeldung = {$xReg}");
                                        if (mysql_errno() > 0) {
                                            AA_printErrorMsg("xml-12-" . mysql_errno() . ": " . mysql_error());
                                        }
                                    }
                                }
                                if ($xReg > 0) {
                                    // check if athlete alredy starts for this discipline(s)
                                    foreach ($xDis as $xDis1) {
                                        // because we can get multiple disciplines (combined event),
                                        // it is nessesary to determinate distype and discode for each discipline
                                        // (catcode won't change)
                                        $res_distype = mysql_query("\r\n                                                    SELECT d.Typ, d.Code, d.Appellzeit, d.Stellzeit FROM \r\n                                                            disziplin_" . $_COOKIE['language'] . " as d\r\n                                                            LEFT JOIN wettkampf as w ON (w.xDisziplin = d.xDisziplin)\r\n                                                    WHERE \r\n                                                        w.xWettkampf = {$xDis1}");
                                        if (mysql_errno() > 0) {
                                            AA_printErrorMsg("xml-13-" . mysql_errno() . ": " . mysql_error());
                                        } else {
                                            $row_distype = mysql_fetch_Array($res_distype);
                                            $distype = $row_distype[0];
                                            $temp_discode = $row_distype[1];
                                        }
                                        $result = mysql_query("SELECT xStart FROM start WHERE xAnmeldung = {$xReg} and xWettkampf = {$xDis1}");
                                        if (mysql_errno() > 0) {
                                            AA_printErrorMsg("xml-14-" . mysql_errno() . ": " . mysql_error());
                                        } else {
                                            if (mysql_num_rows($result) == 0) {
                                                // not yet starting, add start
                                                $saison = $_SESSION['meeting_infos']['Saison'];
                                                if ($saison == '') {
                                                    $saison = "O";
                                                    //if no saison is set take outdoor
                                                }
                                                $sql = "SELECT\r\n                                                                        base_performance.notification_effort\r\n                                                                    FROM\r\n                                                                        athletica.base_performance\r\n                                                                        INNER JOIN athletica.disziplin_" . $_COOKIE['language'] . " AS d \r\n                                                                        ON (base_performance.discipline = d.Code)\r\n                                                                        INNER JOIN athletica.wettkampf \r\n                                                                        ON (d.xDisziplin = wettkampf.xDisziplin)\r\n                                                                    WHERE (base_performance.id_athlete ={$athlete_id}\r\n                                                                        AND wettkampf.xWettkampf ={$xDis1}\r\n                                                                        AND wettkampf.xMeeting =" . $_COOKIE['meeting_id'] . "\r\n                                                                        AND base_performance.season ='I')";
                                                $res_effort = mysql_query($sql);
                                                if (mysql_errno() > 0) {
                                                    AA_printErrorMsg("xml-15-" . mysql_errno() . ": " . mysql_error());
                                                } else {
                                                    if (mysql_num_rows($res_effort) > 0) {
                                                        $row_effort = mysql_fetch_assoc($res_effort);
                                                        $effort = $row_effort['notification_effort'];
                                                    }
                                                    //
                                                    // convert effort
                                                    //
                                                    if ($distype == $cfgDisciplineType[$strDiscTypeTrack] || $distype == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $distype == $cfgDisciplineType[$strDiscTypeRelay] || $distype == $cfgDisciplineType[$strDiscTypeDistance]) {
                                                        $pt = new PerformanceTime($effort);
                                                        $perf = $pt->getPerformance();
                                                    } else {
                                                        //echo $bigger;
                                                        $pa = new PerformanceAttempt($effort);
                                                        $perf = $pa->getPerformance();
                                                        //$perf = (ltrim($effort,"0"))*100;
                                                    }
                                                    if ($perf == NULL) {
                                                        // invalid performance
                                                        $perf = 0;
                                                    }
                                                    mysql_query("INSERT INTO start SET\r\n                                                                            xWettkampf = {$xDis1}   \r\n                                                                            , Bezahlt = '{$license_paid}'\r\n                                                                            , xAnmeldung = {$xReg}   \r\n                                                                            , Bestleistung = '" . $perf . "' \r\n                                                                            , BaseEffort = 'y'");
                                                    if (mysql_errno() > 0) {
                                                        AA_printErrorMsg("xml-16-" . mysql_errno() . ": " . mysql_error());
                                                    }
                                                }
                                            }
                                        }
                                        // update group in round for every event
                                        $sql_r = "SELECT Gruppe FROM runde WHERE xWettkampf = " . $xDis1;
                                        $res_r = mysql_query($sql_r);
                                        if (mysql_errno() > 0) {
                                            AA_printErrorMsg("xml-16a-" . mysql_errno() . ": " . mysql_error());
                                        } else {
                                            if (mysql_num_rows($res_r) > 0) {
                                                while ($row_r = mysql_fetch_row($res_r)) {
                                                    $arr_row[] = $row_r[0];
                                                }
                                                if ($arr_row[0] == "") {
                                                    //update group in round for every event
                                                    $sql_r = "UPDATE IGNORE runde SET Gruppe = '" . $group . "' WHERE xWettkampf = " . $xDis1;
                                                    mysql_query($sql_r);
                                                    if (mysql_errno() > 0) {
                                                        AA_printErrorMsg("xml-17-" . mysql_errno() . ": " . mysql_error());
                                                    }
                                                } elseif (!in_array($group, $arr_row)) {
                                                    $stdEtime = strtotime($row_distype[2]);
                                                    // hold standard delay for enrolement time
                                                    $stdMtime = strtotime($row_distype[3]);
                                                    // and manipulation time
                                                    list($hr, $min) = AA_formatEnteredTime($starttime);
                                                    $tmp = strtotime($hr . ":" . $min . ":00");
                                                    $tmp = $tmp - $stdEtime;
                                                    $appellTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                                    $tmp = strtotime($hr . ":" . $min . ":00");
                                                    $tmp = $tmp - $stdMtime;
                                                    $putTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                                    //insert group in round for every event
                                                    $sql_r = "INSERT INTO runde SET\r\n                                                                                Datum = '" . $meetingDate . "', \r\n                                                                                Startzeit =  '" . $starttime . "', \r\n                                                                                Appellzeit=  '" . $appellTime . "', \r\n                                                                                Stellzeit=  '" . $putTime . "',                                                                                 \r\n                                                                                Gruppe = '" . $group . "', \r\n                                                                                xRundentyp = 8, \r\n                                                                                xWettkampf = " . $xDis1;
                                                    mysql_query($sql_r);
                                                    if (mysql_errno() > 0) {
                                                        AA_printErrorMsg("xml-18-" . mysql_errno() . ": " . mysql_error());
                                                    }
                                                }
                                            } else {
                                                $stdEtime = strtotime($row_distype[2]);
                                                // hold standard delay for enrolement time
                                                $stdMtime = strtotime($row_distype[3]);
                                                // and manipulation time
                                                list($hr, $min) = AA_formatEnteredTime($starttime);
                                                $tmp = strtotime($hr . ":" . $min . ":00");
                                                $tmp = $tmp - $stdEtime;
                                                $appellTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                                $tmp = strtotime($hr . ":" . $min . ":00");
                                                $tmp = $tmp - $stdMtime;
                                                $putTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                                //insert group in round for every event
                                                $sql_r = "INSERT INTO runde SET\r\n                                                                                Datum = '" . $meetingDate . "', \r\n                                                                                Startzeit =  '" . $starttime . "', \r\n                                                                                Appellzeit=  '" . $appellTime . "', \r\n                                                                                Stellzeit=  '" . $putTime . "',                                                                                 \r\n                                                                                Gruppe = '" . $group . "', \r\n                                                                                xRundentyp = 8, \r\n                                                                                xWettkampf = " . $xDis1;
                                                mysql_query($sql_r);
                                                if (mysql_errno() > 0) {
                                                    AA_printErrorMsg("xml-18I-" . mysql_errno() . ": " . mysql_error());
                                                }
                                            }
                                        }
                                    }
                                    // enf foreach
                                }
                                // end xReg > 0
                            }
                        }
                        // end xAthlete > 0
                    } else {
                        // athlete with this license not in base
                        if (!in_array($license, $arr_noCat)) {
                            $arr_noCat['lic'][] = $license;
                        }
                    }
                }
            } else {
                // category not in meeting
                if (!in_array($cat, $arr_noCat)) {
                    $arr_noCat['cat'][] = $cat;
                }
            }
        } else {
            // license = 0
            // select event to get all generated events ids
            $sql = "SELECT \r\n                        w.xWettkampf,\r\n                        w.Mehrkampfcode,\r\n                        k.xKategorie,\r\n                        m.DatumVon   \r\n                    FROM\r\n                        wettkampf as w\r\n                        LEFT JOIN kategorie as k on (w.xKategorie = k.xKategorie )\r\n                        LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d on (w.xDisziplin = d.xDisziplin)\r\n                        LEFT JOIN meeting AS m ON (m.xMeeting = w.xMeeting)  \r\n                    WHERE \r\n                        w.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                        AND k.Kurzname = '" . $cat . "'";
            $res = mysql_query($sql);
            if (mysql_num_rows($res) >= 1) {
                while ($row_dis = mysql_fetch_assoc($res)) {
                    $xDis[] = $row_dis['xWettkampf'];
                    if ($row_dis['Mehrkampfcode'] > 0) {
                        $discode = $row_dis['Mehrkampfcode'];
                        // same for all combined disciplines
                    }
                    $catnr = $row_dis['xKategorie'];
                    $meetingDate = $row_dis['DatumVon'];
                }
                $result2 = mysql_query("SELECT xVerein FROM verein WHERE xCode = '" . $club . "'");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg("xml-19-" . mysql_errno() . ": " . mysql_error());
                } else {
                    $rowClub1 = mysql_fetch_array($result2);
                    $clubnr = $rowClub1[0];
                }
                mysql_free_result($result2);
                // if club is valid
                // insert athlete from base data
                if (is_numeric($clubnr)) {
                    $name = mysql_real_escape_string(str_replace("\r", "\n", trim(utf8_decode($name))));
                    $firstname = mysql_real_escape_string(str_replace("\r", "\n", trim(utf8_decode($firstname))));
                    // if athlet exist
                    $sql = "SELECT * FROM athlet WHERE Name= '" . $name . "' AND Vorname = '" . $firstname . "' AND Geburtstag = '" . $birthdate . "'";
                    $res = mysql_query($sql);
                    if (mysql_errno() > 0) {
                        AA_printErrorMsg("xml-20-" . mysql_errno() . ": " . mysql_error());
                    } else {
                        $row = mysql_fetch_array($res);
                        if (mysql_num_rows($res) == 0) {
                            $sql = "INSERT IGNORE INTO athlet SET\r\n                                                                Name = '" . $name . "',\r\n                                                                Vorname = '" . $firstname . "',  \r\n                                                                Jahrgang = '" . $birthyear . "', \r\n                                                                Lizenznummer = 0 , \r\n                                                                Geschlecht = '" . $sex . "', \r\n                                                                Land = '" . $nationality . "', \r\n                                                                Geburtstag = '" . $birthdate . "',\r\n                                                                Athleticagen = 'n',   \r\n                                                                xVerein = '" . $clubnr . "',  \r\n                                                                Bezahlt = '" . $license_paid . "', \r\n                                                                Lizenztyp = 3";
                            mysql_query($sql);
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-21-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                $xAthlete = mysql_insert_id();
                            }
                        } else {
                            $sql = "UPDATE athlet SET                                                                 \r\n                                                    Jahrgang = '" . $birthyear . "', \r\n                                                    Geschlecht = '" . $sex . "', \r\n                                                    Land = '" . $nationality . "',  \r\n                                                    xVerein = '" . $clubnr . "',  \r\n                                                    Bezahlt = '" . $license_paid . "'\r\n                                                    WHERE Name= '" . $name . "' AND Vorname = '" . $firstname . "' AND Geburtstag = '" . $birthdate . "'";
                            mysql_query($sql);
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-22-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                $xAthlete = $row[0];
                            }
                        }
                    }
                } else {
                    // club not found
                    if (!in_array($license, $arr_noCat)) {
                        $arr_noCat['club'][] = $club;
                    }
                }
            }
            // end athlete found
            if ($xAthlete > 0) {
                // check if already registered
                $result = mysql_query("SELECT xAnmeldung FROM anmeldung WHERE xAthlet = {$xAthlete} AND xMeeting = " . $_COOKIE['meeting_id'] . "");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg("xml-23-" . mysql_errno() . ": " . mysql_error());
                } else {
                    if (mysql_num_rows($result) == 0) {
                        // not yet registered
                        if ($catnr != '') {
                            mysql_query("INSERT INTO anmeldung SET\r\n                                                        Startnummer = 0\r\n                                                        , Bezahlt = '{$license_paid}'\r\n                                                        , xAthlet = {$xAthlete}\r\n                                                        , xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                                                        , xKategorie = {$catnr}\r\n                                                        , Anmeldenr_ZLV = {$registerNr}");
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-24-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                $xReg = mysql_insert_id();
                            }
                        }
                    } else {
                        // registered
                        $row = mysql_fetch_array($result);
                        mysql_query("Update anmeldung SET\r\n                                                                Startnummer = 0\r\n                                                                , Bezahlt = '{$license_paid}'\r\n                                                                , xAthlet = {$xAthlete}\r\n                                                                , xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                                                                , xKategorie = {$xCat}\r\n                                                                , Anmeldenr_ZLV = {$registerNr}\r\n                                                                WHERE xAnmeldung = {$row['0']}");
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg("xml-25-" . mysql_errno() . ": " . mysql_error());
                        } else {
                            $xReg = $row[0];
                        }
                    }
                    if ($xReg > 0) {
                        // check if athlete alredy starts for this discipline(s)
                        foreach ($xDis as $xDis1) {
                            // because we can get multiple disciplines (combined event),
                            // it is nessesary to determinate distype and discode for each discipline
                            // (catcode won't change)
                            $res_distype = mysql_query("\r\n                                                    SELECT d.Typ, d.Code, d.Appellzeit, d.Stellzeit FROM \r\n                                                            disziplin_" . $_COOKIE['language'] . " as d\r\n                                                            LEFT JOIN wettkampf as w  ON (w.xDisziplin = d.xDisziplin)\r\n                                                    WHERE w.xWettkampf = {$xDis1}");
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-26-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                $row_distype = mysql_fetch_Array($res_distype);
                                $distype = $row_distype[0];
                                $temp_discode = $row_distype[1];
                            }
                            $result = mysql_query("SELECT xStart FROM start WHERE xAnmeldung = {$xReg} and xWettkampf = {$xDis1}");
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-27-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                if (mysql_num_rows($result) == 0) {
                                    // not yet starting, add start
                                    $saison = $_SESSION['meeting_infos']['Saison'];
                                    if ($saison == '') {
                                        $saison = "O";
                                        //if no saison is set take outdoor
                                    }
                                    mysql_query("INSERT INTO start SET\r\n                                                                            xWettkampf = {$xDis1}\r\n                                                                            , Bezahlt = '{$license_paid}'\r\n                                                                            , xAnmeldung = {$xReg}\r\n                                                                            ");
                                    if (mysql_errno() > 0) {
                                        AA_printErrorMsg("xml-28-" . mysql_errno() . ": " . mysql_error());
                                    }
                                }
                            }
                            // update group in round for every event
                            $sql_r = "SELECT Gruppe FROM runde WHERE xWettkampf = " . $xDis1;
                            $res_r = mysql_query($sql_r);
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-28a-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                if (mysql_num_rows($res_r) > 0) {
                                    while ($row_r = mysql_fetch_row($res_r)) {
                                        $arr_row[] = $row_r[0];
                                    }
                                    if ($arr_row[0] == "") {
                                        //update group in round for every event
                                        $sql_r = "UPDATE IGNORE runde SET Gruppe = " . $group . " WHERE xWettkampf = " . $xDis1;
                                        mysql_query($sql_r);
                                        if (mysql_errno() > 0) {
                                            AA_printErrorMsg("xml-29-" . mysql_errno() . ": " . mysql_error());
                                        }
                                    } elseif (!in_array($group, $arr_row)) {
                                        $stdEtime = strtotime($row_distype[2]);
                                        // hold standard delay for enrolement time
                                        $stdMtime = strtotime($row_distype[3]);
                                        // and manipulation time
                                        list($hr, $min) = AA_formatEnteredTime($starttime);
                                        $tmp = strtotime($hr . ":" . $min . ":00");
                                        $tmp = $tmp - $stdEtime;
                                        $appellTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                        $tmp = strtotime($hr . ":" . $min . ":00");
                                        $tmp = $tmp - $stdMtime;
                                        $putTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                        //insert group in round for every event
                                        $sql_r = "INSERT INTO runde SET\r\n                                                                                Datum = '" . $meetingDate . "', \r\n                                                                                Startzeit =  '" . $starttime . "', \r\n                                                                                Appellzeit=  '" . $appellTime . "', \r\n                                                                                Stellzeit=  '" . $putTime . "',                                                                                 \r\n                                                                                Gruppe = '" . $group . "', \r\n                                                                                xRundentyp = 8, \r\n                                                                                xWettkampf = " . $xDis1;
                                        mysql_query($sql_r);
                                        if (mysql_errno() > 0) {
                                            AA_printErrorMsg("xml-30-" . mysql_errno() . ": " . mysql_error());
                                        }
                                    }
                                } else {
                                    $stdEtime = strtotime($row_distype[2]);
                                    // hold standard delay for enrolement time
                                    $stdMtime = strtotime($row_distype[3]);
                                    // and manipulation time
                                    list($hr, $min) = AA_formatEnteredTime($starttime);
                                    $tmp = strtotime($hr . ":" . $min . ":00");
                                    $tmp = $tmp - $stdEtime;
                                    $appellTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                    $tmp = strtotime($hr . ":" . $min . ":00");
                                    $tmp = $tmp - $stdMtime;
                                    $putTime = floor($tmp / 3600) . ":" . floor($tmp % 3600 / 60);
                                    //insert group in round for every event
                                    $sql_r = "INSERT INTO runde SET\r\n                                                                                Datum = '" . $meetingDate . "', \r\n                                                                                Startzeit =  '" . $starttime . "', \r\n                                                                                Appellzeit=  '" . $appellTime . "', \r\n                                                                                Stellzeit=  '" . $putTime . "',                                                                                 \r\n                                                                                Gruppe = '" . $group . "', \r\n                                                                                xRundentyp = 8, \r\n                                                                                xWettkampf = " . $xDis1;
                                    mysql_query($sql_r);
                                    if (mysql_errno() > 0) {
                                        AA_printErrorMsg("xml-18I-" . mysql_errno() . ": " . mysql_error());
                                    }
                                }
                            }
                            // end foreach
                        }
                    }
                    // end xReg > 0
                }
            }
            // end xAthlete > 0
        }
    }
    // end ATHLETE
    if ($name == "ANMELDUNG") {
        $regNr = $attr['ANMELDENR'];
        $team = $attr['MANNSCHAFT'];
        $cat = $attr['KATEGORIE'];
        $license = $attr['LIZENZNR'];
        $group = $attr['GRUPPENR'];
        $club = $attr['VEREIN'];
        $registerNr = $attr['ANMELDENR'];
        $sql = "SELECT id_athlete FROM base_athlete WHERE license = '" . $license . "';";
        $query = mysql_query($sql);
        if (mysql_errno() > 0) {
            AA_printErrorMsg("xml-31-" . mysql_errno() . ": " . mysql_error());
        } else {
            if (mysql_num_rows($query) > 0 || $license == '') {
                // athlete not in base
                if (!in_array($cat, $arr_noCat)) {
                    // get the eventnumber of this meeting for generating a team id in the form eventnumber999 (xxxxxx999)
                    $res = mysql_query("SELECT xControl FROM meeting WHERE xMeeting = " . $_COOKIE['meeting_id']);
                    if (mysql_errno() > 0) {
                        AA_printErrorMsg("xml-32-" . mysql_errno() . ": " . mysql_error());
                    } else {
                        $row = mysql_fetch_array($res);
                        $eventnr = $row[0];
                        if (empty($eventnr)) {
                            $idcounter = "";
                        } else {
                            mysql_free_result($res);
                            $arrid = array();
                            $res = mysql_query("select max(xStaffel) from staffel where xStaffel like '{$eventnr}%'");
                            $row = mysql_fetch_array($res);
                            $arrid[] = $row[0];
                            $res = mysql_query("select max(xTeam) from team where xTeam like '{$eventnr}%'");
                            $row = mysql_fetch_array($res);
                            $arrid[] = $row[0];
                            $res = mysql_query("select max(id_relay) from base_relay where id_relay like '{$eventnr}%'");
                            $row = mysql_fetch_array($res);
                            $arrid[] = $row[0];
                            $res = mysql_query("select max(id_svm) from base_svm where id_svm like '{$eventnr}%'");
                            $row = mysql_fetch_array($res);
                            $arrid[] = $row[0];
                            rsort($arrid);
                            $biggestId = $arrid[0];
                            if ($biggestId == 0 || strlen($biggestId) != 9) {
                                $idcounter = "001";
                            } else {
                                $idcounter = substr($biggestId, 6, 3);
                                $idcounter++;
                                $idcounter = sprintf("%03d", $idcounter);
                            }
                            $xTeamSQL = ", xTeam = " . $eventnr . $idcounter . ", Athleticagen ='y' ";
                        }
                    }
                    $sql = "SELECT xKategorie FROM kategorie WHERE Kurzname = '" . $cat . "'";
                    $res = mysql_query($sql);
                    if (mysql_errno() > 0) {
                        AA_printErrorMsg("xml-33-" . mysql_errno() . ": " . mysql_error());
                    } else {
                        $row = mysql_fetch_row($res);
                        $catnr = $row[0];
                        $sql = "SELECT xVerein FROM verein WHERE xCode = '" . $club . "'";
                        $res = mysql_query($sql);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg("xml-34-" . mysql_errno() . ": " . mysql_error());
                        } else {
                            $row = mysql_fetch_row($res);
                            $clubnr = $row[0];
                            if ($license > 0) {
                                $sql_a = "SELECT \r\n                                        an.xAnmeldung\r\n                                  FROM\r\n                                        athlet AS a\r\n                                        LEFT JOIN anmeldung AS an ON (a.xAthlet = an.xAthlet)\r\n                                  WHERE\r\n                                        a.Lizenznummer = " . $license . "\r\n                                        AND an.xMeeting = " . $_COOKIE['meeting_id'];
                            } else {
                                $sql_a = "SELECT \r\n                                        an.xAnmeldung\r\n                                  FROM\r\n                                        athlet AS a\r\n                                        LEFT JOIN anmeldung AS an ON (a.xAthlet = an.xAthlet)\r\n                                  WHERE\r\n                                        an.Anmeldenr_ZLV = " . $registerNr . "\r\n                                        AND an.xMeeting = " . $_COOKIE['meeting_id'];
                            }
                            $result = mysql_query($sql_a);
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg("xml-35-" . mysql_errno() . ": " . mysql_error());
                            } else {
                                if (mysql_num_rows($result) >= 1) {
                                    $row_a = mysql_fetch_row($result);
                                    $sql = "SELECT xTeam FROM team WHERE Name = '" . $team . "' AND xMeeting=" . $_COOKIE['meeting_id'] . " AND xKategorie = " . $catnr . " AND xVerein=" . $clubnr;
                                    $res = mysql_query($sql);
                                    if (mysql_num_rows($res) > 0) {
                                        $row = mysql_fetch_array($res);
                                        $xTeam = $row[0];
                                    } else {
                                        if ($clubnr > 0) {
                                            // no club exist --> error msg in ATHLETE
                                            $sql = "INSERT IGNORE INTO team SET \r\n                                                        Name=\"" . $team . "\"\r\n                                                        , xMeeting=" . $_COOKIE['meeting_id'] . "\r\n                                                        , xKategorie = " . $catnr . "\r\n                                                        , xVerein=" . $clubnr . $xTeamSQL;
                                            mysql_query($sql);
                                            if (mysql_errno() > 0) {
                                                AA_printErrorMsg("xml-36-" . mysql_errno() . ": " . mysql_error());
                                            } else {
                                                $xTeam = mysql_insert_id();
                                                // get new ID
                                            }
                                        }
                                    }
                                    $sql = "UPDATE anmeldung SET xTeam = '" . $xTeam . "', Gruppe = '" . $group . "' WHERE xAnmeldung = " . $row_a[0] . " AND xMeeting = " . $_COOKIE['meeting_id'];
                                    $res = mysql_query($sql);
                                    if (mysql_errno() > 0) {
                                        AA_printErrorMsg("xml-37-" . mysql_errno() . ": " . mysql_error());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // end ANMELDUNG
}