"Kämpfer", '2' => "Zuschauer", '3' => "keine Teilnahme" ); function getEventsStarterData($anMysqlConn, $anEventId){ $ret = array(); if( (string)(int)$anEventId != $anEventId ) return $ret; $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wkParticipo_Starter.id, ". "wkParticipo_Starter.eventId, ". "wkParticipo_Starter.userId, ". "wkParticipo_Starter.fahrtId, ". "wkParticipo_Starter.masse, ". "wkParticipo_Starter.platz, ". "wkParticipo_Users.id, ". "wkParticipo_Users.vorname, ". "wkParticipo_Users.name, ". "wkParticipo_Events.id, ". "wkParticipo_Events.wkId, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.bemerkungen, ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Routenplaner ". "FROM wkParticipo_Starter ". "JOIN wkParticipo_Users ON wkParticipo_Users.id = wkParticipo_Starter.userId ". "JOIN wkParticipo_Events ON wkParticipo_Events.id = wkParticipo_Starter.eventId ". "JOIN wettkampfkalender ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "WHERE wkParticipo_Events.id = '%s';", $anMysqlConn->real_escape_string($anEventId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getStarterForEvent($anMysqlConn, $anEventId){ if( (string)(int)$anEventId == $anEventId ){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE eventId='%s';", $anMysqlConn->real_escape_string($anEventId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); } return $ret; } function getKaempferForEvent($anMysqlConn, $anEventId){ if( (string)(int)$anEventId == $anEventId ){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE eventId='%s' AND type='%s';", $anMysqlConn->real_escape_string($anEventId), $anMysqlConn->real_escape_string("1") ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); } return $ret; } function getZuschauerForEvent($anMysqlConn, $anEventId){ if( (string)(int)$anEventId == $anEventId ){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE eventId='%s' AND type='%s';", $anMysqlConn->real_escape_string($anEventId), $anMysqlConn->real_escape_string("2") ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); } return $ret; } function getFahrtenForEvent($anMysqlConn, $anEventId){ $ret = array(); if( (string)(int)$anEventId != $anEventId ) return $ret; $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wkParticipo_Fahrten.id, ". "wkParticipo_Fahrten.eventId, ". "wkParticipo_Fahrten.fahrerId, ". "wkParticipo_Fahrten.plaetze, ". "wkParticipo_Fahrten.mitfahrer, ". "wkParticipo_Users.vorname, ". "wkParticipo_Users.name ". "FROM wkParticipo_Fahrten ". "JOIN wkParticipo_Users ON wkParticipo_Users.id = wkParticipo_Fahrten.fahrerId ". "WHERE wkParticipo_Fahrten.eventId = '%s';", $anMysqlConn->real_escape_string($anEventId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; if( (string)(int)$anEventId == $anEventId ){ $query = sprintf( "SELECT * FROM wkParticipo_Fahrten WHERE eventId='%s';", $anMysqlConn->real_escape_string($anEventId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); } return $ret; } function getMitfahrer($anMysqlConn, $anFahrtId){ $ret = array(); $fahrt = getFahrtData($anMysqlConn, $anFahrtId); $mitfahrerIds = array(); if( !empty($fahrt['mitfahrer']) ) $mitfahrerIds = explode(',', $fahrt['mitfahrer']); foreach($mitfahrerIds as $mitfahrerId){ $starter = getStarterData($anMysqlConn, $mitfahrerId); $user = getUserData($anMysqlConn, $starter['userId']); array_push($ret, $user); } return $ret; } function getUsers($anMysqlConn){ $ret = array(); $query = sprintf( "SELECT * FROM wkParticipo_Users;" ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersStarts($anMysqlConn, $anUserId){ if( (string)(int)$anUserId == $anUserId ){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE userId='%s';", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); } return $ret; } function getUsersFahrten($anMysqlConn, $anUserId){ if( (string)(int)$anUserId == $anUserId ){ $query = sprintf( "SELECT * FROM wkParticipo_Fahrten WHERE fahrerId='%s';", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); } return $ret; } function getUsersWk($anMysqlConn, $anUserId){ $ret = array(); if( (string)(int)$anUserId == $anUserId ){ $starts = getUsersStarts($anMysqlConn, $anUserId); foreach( $starts as $start){ $query = sprintf( "SELECT * FROM wkParticipo_Events WHERE id='%s';", $anMysqlConn->real_escape_string($start['eventId']) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ){ array_push( $ret, getWkData($anMysqlConn, $result['wkId'])); } } } return $ret; } function getUserData($anMysqlConn, $anUserId){ $ret = array(); if( (string)(int)$anUserId == $anUserId ){ $query = sprintf( "SELECT * FROM wkParticipo_Users WHERE id='%s';", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = $results->fetch_assoc(); } return $ret; } function getStarterData($anMysqlConn, $anStarterId){ $ret = array(); if( (string)(int)$anStarterId == $anStarterId ){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE id='%s';", $anMysqlConn->real_escape_string($anStarterId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = $results->fetch_assoc(); } return $ret; } function getFahrtData($anMysqlConn, $anFahrtId){ $ret = array(); if( (string)(int)$anFahrtId == $anFahrtId ){ $query = sprintf( "SELECT * FROM wkParticipo_Fahrten WHERE id='%s';", $anMysqlConn->real_escape_string($anFahrtId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = $results->fetch_assoc(); } return $ret; } function getEventData($anMysqlConn, $anEventId){ $ret = array(); if( (string)(int)$anEventId != $anEventId ) return $ret; $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wkParticipo_Events.id, ". "wkParticipo_Events.wkId, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.bemerkungen, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Ausschreibung, ". "wettkampfkalender.Routenplaner ". "FROM wkParticipo_Events ". "JOIN wettkampfkalender ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "WHERE wkParticipo_Events.id = '%s';", $anMysqlConn->real_escape_string($anEventId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); /// @ToDo: Anzahl Ergebnise auf ==1 testen $ret = $results->fetch_assoc(); return $ret; } /// Daten eines einzelnen wkEvents via eventId abfragen /// /// Ein wkEvent ist ein Event (welches nur die ID des Wettkampfes im /// Wettkampfkalender enthält) erweitert um die Daten des Wettkampfes /// selber. /// Der Rückgabewert sollte vor Verwendung (und zur Fehlerbeheandlung) /// auf NULL und/oder leeres Array getestet werden. /// function getWkEventData($anMysqlConn, $anEventId){ $ret = array(); if( (string)(int)$anEventId != $anEventId ) return $ret; $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wkParticipo_Events.id, ". "wkParticipo_Events.wkId, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.bemerkungen, ". "wkParticipo_Events.kvOptions, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Ausschreibung, ". "wettkampfkalender.Routenplaner ". "FROM wkParticipo_Events ". "JOIN wettkampfkalender ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "WHERE wkParticipo_Events.id = '%s';", $anMysqlConn->real_escape_string($anEventId) ); $results = $anMysqlConn->query($query); // if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); // Für eine detailierte Fehlermeldung zum Debuggen if( !$results ) return NULL; // Bei einem Fehler bei der Abfrage soll NULL zurückgeliefert werden // Da wir über den Primary Key abfragen, wird maximal ein Ergebnis geliefert $ret = $results->fetch_assoc(); // Bei einem leeren Ergebnis (NULL oder leeres Array) soll ein leeres Array zurückgeliefert werden if( empty($ret) ) return array(); array_walk( $ret, function (&$entry) { $entry = iconv("ISO-8859-1", "UTF-8", $entry); } ); return $ret; } /// Daten aller kommenden wkEvents abfragen /// /// Ein wkEvent ist ein Event (welches nur die ID des Wettkampfes im /// Wettkampfkalender enthält) erweitert um die Daten des Wettkampfes /// selber. /// Der Rückgabewert sollte vor Verwendung (und zur Fehlerbeheandlung) /// auf NULL und/oder leeres Array getestet werden. /// function getCommingWkEvents($anMysqlConn){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wkParticipo_Events.id, ". "wkParticipo_Events.wkId, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.bemerkungen, ". "wkParticipo_Events.kvOptions, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Ausschreibung, ". "wettkampfkalender.Routenplaner ". "FROM wkParticipo_Events ". "JOIN wettkampfkalender ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "WHERE wettkampfkalender.Datum >= CURDATE() ". "ORDER BY wettkampfkalender.Datum;" ); // echo($query);die(); $results = $anMysqlConn->query($query); // Bei einem Fehler bei der Abfrage soll NULL zurückgeliefert werden if( !$results ){ echo("No Results: ".$anMysqlConn->error); return NULL; } // Bei einem leeren Ergebnis (NULL oder leeres Array) soll ein leeres Array zurückgeliefert werden if( empty($results) ) return array(); while( $result = $results->fetch_assoc() ){ array_walk( $result, function (&$entry) { $entry = iconv("ISO-8859-1", "UTF-8", $entry); } ); array_push( $ret, $result); } //echo("Results: "); print_r($ret); return $ret; } /// Abfrage der Daten eines Wettkampfes via ID /// Da über den primary key abgefragt wird, erfolgt keine Kontrolle, ob /// nur ein Ergebnis geliefert wurde function getWkData($anMysqlConn, $anWkId){ $query = sprintf( "SELECT * FROM wettkampfkalender WHERE lfdeNr='%s';", $anMysqlConn->real_escape_string($anWkId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = $results->fetch_assoc(); return $ret; } function getAllEvents($anMysqlConn){ $query = sprintf( "SELECT * FROM wkParticipo_Events ORDER BY meldefrist DESC;" ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } /// Alle Userdaten abfragen function getAllUsers($anMysqlConn){ $query = sprintf( "SELECT * FROM wkParticipo_Users;" ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getThisWeeksMeldefristen($anMysqlConn){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wkParticipo_Events.id, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.wkId ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "WHERE wkParticipo_Events.meldefrist <= DATE_ADD(CURDATE(), INTERVAL 1 WEEK) AND wkParticipo_Events.meldefrist >= CURDATE() ". "ORDER BY wkParticipo_Events.meldefrist;" ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } /// Zukünftige Wettkämpfe abfragen function getCommingWk($anMysqlConn){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT lfdeNr, Datum, Veranstaltung, Altersklassen ". "FROM wettkampfkalender ". "WHERE wettkampfkalender.Datum >= CURDATE() ". "ORDER BY wettkampfkalender.Datum ASC;" ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getStarterInfo($anMysqlConn, $anStarterId){ $ret = array(); if( (string)(int)$anStarterId != $anStarterId ) return $ret; $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wkParticipo_Events.id, ". "wkParticipo_Events.wkId, ". "wkParticipo_Starter.id, ". "wkParticipo_Starter.eventId, ". "wkParticipo_Starter.masse, ". "wkParticipo_Starter.platz ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "JOIN wkParticipo_Starter ". "ON wkParticipo_Starter.eventId = wkParticipo_Events.id ". "WHERE wkParticipo_Starter.id = '%s';", $anMysqlConn->real_escape_string($anStarterId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getCommingFahrten($anMysqlConn){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wkParticipo_Events.id, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.wkId, ". "wkParticipo_Fahrten.id, ". "wkParticipo_Fahrten.eventId, ". "wkParticipo_Fahrten.FahrerId, ". "wkParticipo_Fahrten.plaetze, ". "wkParticipo_Fahrten.mitfahrer ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "JOIN wkParticipo_Fahrten ". "ON wkParticipo_Events.id = wkParticipo_Fahrten.eventId ". "WHERE wettkampfkalender.Datum >= CURDATE() ". "ORDER BY wettkampfkalender.Datum;" ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersCommingFahrten($anMysqlConn, $anUserId){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Routenplaner, ". "wkParticipo_Events.id, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.wkId, ". "wkParticipo_Fahrten.id, ". "wkParticipo_Fahrten.eventId, ". "wkParticipo_Fahrten.FahrerId, ". "wkParticipo_Fahrten.plaetze, ". "wkParticipo_Fahrten.mitfahrer ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "JOIN wkParticipo_Fahrten ". "ON wkParticipo_Events.id = wkParticipo_Fahrten.eventId ". "WHERE wettkampfkalender.Datum >= CURDATE() AND wkParticipo_Fahrten.FahrerId = '%s' ". "ORDER BY wettkampfkalender.Datum;", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersCommingWkEvents($anMysqlConn, $anUserId){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Routenplaner, ". "wkParticipo_Events.id, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.wkId, ". "wkParticipo_Starter.id, ". "wkParticipo_Starter.eventId, ". "wkParticipo_Starter.type ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "JOIN wkParticipo_Starter ". "ON wkParticipo_Starter.eventId = wkParticipo_Events.id ". "WHERE wettkampfkalender.Datum >= CURDATE() AND wkParticipo_Starter.userId = '%s' ". "ORDER BY wettkampfkalender.Datum;", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersWkEvents($anMysqlConn, $anUserId){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Routenplaner, ". "wkParticipo_Events.id, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.wkId, ". "wkParticipo_Starter.id, ". "wkParticipo_Starter.eventId ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "JOIN wkParticipo_Starter ". "ON wkParticipo_Starter.eventId = wkParticipo_Events.id ". // "WHERE wettkampfkalender.Datum >= CURDATE() AND wkParticipo_Starter.userId = '%s' ". "WHERE wkParticipo_Starter.userId = '%s' ". "ORDER BY wettkampfkalender.Datum;", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersErgebnisse($anMysqlConn, $anUserId){ $ret = array(); $anMysqlConn->query("USE cwsvjudo;"); $query = sprintf( "SELECT ". "wettkampfkalender.lfdeNr, ". "wettkampfkalender.Datum, ". "wettkampfkalender.Veranstaltung, ". "wettkampfkalender.Altersklassen, ". "wettkampfkalender.Ort, ". "wettkampfkalender.Routenplaner, ". "wkParticipo_Events.id, ". "wkParticipo_Events.meldefrist, ". "wkParticipo_Events.wkId, ". "wkParticipo_Starter.id, ". "wkParticipo_Starter.eventId ,". "wkParticipo_Starter.masse ,". "wkParticipo_Starter.platz ". "FROM wettkampfkalender ". "JOIN wkParticipo_Events ". "ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ". "JOIN wkParticipo_Starter ". "ON wkParticipo_Starter.eventId = wkParticipo_Events.id ". "WHERE wettkampfkalender.Datum <= CURDATE() AND wkParticipo_Starter.userId = '%s' ". "ORDER BY wettkampfkalender.Datum;", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersMeldungen($anMysqlConn, $anUserId){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE userId='%s';", $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return $ret; } function getUsersMeldeStatus($anMysqlConn, $anEventId, $anUserId){ $query = sprintf( "SELECT * FROM wkParticipo_Starter WHERE eventId='%s' AND userId='%s';", $anMysqlConn->real_escape_string($anEventId), $anMysqlConn->real_escape_string($anUserId) ); $results = $anMysqlConn->query($query); if( !$results ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $ret = array(); while( $result = $results->fetch_assoc() ) array_push( $ret, $result); return !empty($ret); } function doMeldung($anMysqlConn, $anEventId, $anUserId){ if( !in_array( $anUserId, explode(',', getUserData($mysqli, $_SESSION['user']['userId'])['kinder']) ) ) return "Sie dürfen diesen Starter nicht melden!"; $query = sprintf( "SELECT id FROM wkParticipo_Starter WHERE eventId='%s' AND userId='%s';", $mysqli->real_escape_string($_POST['f']['eventId']), $mysqli->real_escape_string($_POST['f']['userId']) ); $starterResults = $mysqli->query($query); if( !$starterResults ) die("ERR: Fehler bei Datenbankabfrage (".$query.")!\n"); $starterResult = $starterResults->fetch_array(); if( $mysqli->affected_rows >= 1 ) return "ERR: Offenbar bereits gemeldet!"; $query = sprintf( "INSERT INTO wkParticipo_Starter (eventId, userId) values (%s, %s);", $mysqli->real_escape_string($_POST['f']['eventId']), $mysqli->real_escape_string($_POST['f']['userId']) ); $result = $mysqli->query($query); if(!$result){ echo "Fehler bei der Meldung: " . mysql_error(); die(); } $message['success'] = "Neuer Starter userId " . $_POST['f']['userId'] . " für eventId " . $_POST['f']['eventId']; return true; } function verteileMitfahrer($anMysqlConn, $anEventId){ $retMessage = array(); if( (string)(int)$anEventId == $anEventId ){ $starterData = getStarterForEvent($anMysqlConn, $anEventId); $fahrtenData = getFahrtenForEvent($anMysqlConn, $anEventId); // Bereits zugeordnete Starter ignorieren // kontrollieren, ob der Starter auch wirklich in der Fahrt eingetragen ist foreach( $starterData as $key => $starter ){ if( !empty($starter['fahrtId']) ){ $fahrt = getFahrtData($anMysqlConn, $starter['fahrtId']); $mitfahrerIds = array(); if( !empty($fahrt['mitfahrer']) ) $mitfahrerIds = explode(',', $fahrt['mitfahrer']); if( in_array($starter['id'], $mitfahrerIds) ) unset($starterData[$key]); else{ // Sollte die Fahrt beim Starter eingetragen sein, aber nicht bei der Fahrt als Mitfahrer, lösche sie $query = sprintf( "UPDATE wkParticipo_Starter SET fahrtId='%s' WHERE id='%s';", $anMysqlConn->real_escape_string( "" ), $anMysqlConn->real_escape_string( $starter['id'] ) ); $result = $anMysqlConn->query($query); if($anMysqlConn->affected_rows != 1){ $retMessage['error'] .= "Fehler beim Ausführen des sqlRequestes \"".$query."\"\n"; return $retMessage; } } } } foreach( $fahrtenData as $key => $fahrt ){ $mitfahrerIds = array(); if( !empty($fahrt['mitfahrer']) ) $mitfahrerIds = explode(',', $fahrt['mitfahrer']); // Überbelegte Fahrten trimmen while( count($mitfahrerIds) > (int)$fahrt['plaetze'] ){ $starterId = array_pop($mitfahrerIds); $query = sprintf( "UPDATE wkParticipo_Starter SET fahrtId='%s' WHERE id='%s';", $anMysqlConn->real_escape_string( "" ), $anMysqlConn->real_escape_string( $starterId ) ); $result = $anMysqlConn->query($query); if($anMysqlConn->affected_rows != 1){ $retMessage['error'] .= "verteileMitfahrer: Fehler beim Ausführen des sqlRequestes \"".$query."\", Fahrt: ".$fahrt['id']." Plätze: ".$fahrt['plaetze'].", Mitfahrer: ".implode('|', $mitfahrerIds)."
"; return $retMessage; } array_push($starterData, getStarterData($anMysqlConn, $starterId) ); } $query = sprintf( "UPDATE wkParticipo_Fahrten SET mitfahrer='%s' WHERE id='%s';", $anMysqlConn->real_escape_string( empty($mitfahrerIds) ? "" : implode(',', $mitfahrerIds) ), $anMysqlConn->real_escape_string( $fahrt['id'] ) ); $result = $anMysqlConn->query($query); if($anMysqlConn->affected_rows > 1){ $retMessage['error'] .= "verteileMittfahrer: Fehler beim Ausführen des sqlRequestes \"".$query."\"\n"; return $retMessage; } // volle Fahrten entfernen if( count($mitfahrerIds) >= (int)$fahrt['plaetze'] ){ unset($fahrtenData[$key]); } } uasort($starterData, function ($a, $b){ return ( (int)$a['id'] < (int)$b['id'] ? 1 : -1 ); }); uasort($fahrtenData, function ($a, $b){ return ( (int)$a['plaetze'] > (int)$b['plaetze'] ? 1 : -1 ); }); while( !empty($starterData) and !empty($fahrtenData) ){ echo "Starter:"; print_r($starterData); echo "\n"; echo "Fahrten:"; print_r($fahrtenData); echo "\n\n"; $fahrt = array_pop($fahrtenData); $starter = array_pop($starterData); $tempMessage = addMitfahrerToFahrt($anMysqlConn, $starter['id'], $fahrt['id']); $retMessage['warning'] .= $tempMessage['warning']; $retMessage['error'] .= $tempMessage['warning']; $retMessage['success'] .= $tempMessage['success']; $fahrt = getFahrtData($anMysqlConn, $fahrt['id']); $mitfahrerIds = array(); if( !empty($fahrt['mitfahrer']) ) $mitfahrerIds = explode(',', $fahrt['mitfahrer']); if( count($mitfahrerIds) < (int)$fahrt['plaetze'] ){ array_push( $fahrtenData, $fahrt ); } } if( !empty($starterData) ) $retMessage['warning'] .= "Achtung: nicht zugeordnete Starter!
"; } return $retMessage; } function reseteMitfahrer($anMysqlConn, $anEventId){ $retMmessage = array(); if( (string)(int)$anEventId != $anEventId ){ $retMessage['error'] .= "Falsch formatierte eventId (".$anEventId.")
"; return $retMessage; } $query = sprintf( "UPDATE wkParticipo_Starter SET fahrtId=NULL WHERE eventId='%s'", $anMysqlConn->real_escape_string( $anEventId ) ); $result = $anMysqlConn->query($query); if( !$result ){ $retMessage['error'] .= "Fehler beim Ausführen des sqlRequestes \"".$query."\"
"; //return $retMessage; } $query = sprintf( "UPDATE wkParticipo_Fahrten SET mitfahrer='%s' WHERE eventId='%s'", $anMysqlConn->real_escape_string( "" ), $anMysqlConn->real_escape_string( $anEventId ) ); $result = $anMysqlConn->query($query); if( !$result ){ $retMessage['error'] .= "Fehler beim Ausführen des sqlRequestes \"".$query."\"
"; return $retMessage; } return $retMessage; } // einem Event einen neuen Starter hinzufügen /* function createStarterForEvent($anMysqlConn, $anEventId, $anUserId){ $retMessage = array(); if( (string)(int)$anEventId != $anEventId or (string)(int)$anUserId != $anUserId ){ $retMessage['error'] .= "Falsch formatierte eventId (".$anEventId.") oder userId (".$anUserId.")
"; return $retMessage; } $event = getEventData($anMysqlConn, $anEventId); if( empty($event) ){ $retMessage['error'] .= "eventId ".$anEventId." nicht gefunden
"; return $retMessage; } $user = getUserData($anMysqlConn, $anUserId); if( empty($event) ){ $retMessage['error'] .= "userId ".$anUserId." nicht gefunden
"; return $retMessage; } if( getUsersMeldeStatus($anMysqlConn, $anEventId, $anUserId) ){ $retMessage['notice'] .= "userId ".$anUserId." bereits bei eventId ".$anEventId." eingeschrieben
"; return $retMessage; } $query = sprintf( "INSERT INTO wkParticipo_Starter (eventId, userId) values (%s, %s);", $anMysqlConn->real_escape_string($anEventId), $anMysqlConn->real_escape_string($anUserId) ); $result = $anMysqlConn->query($query); if(!$result){ $retMessage['error'] .= "Fehler \"".mysql_error()."\" bei der sqlQuery \"".$query."\"
"; return $retMessage; } $retMessage['success'] = "Neuer Starter userId " . $anUserId . " für eventId " . $anEventId . " hinzugefügt"; return $retMessage; } */ /// Einen Starter per userId mit typeId zu einem Event per eventId hinzufügen /// Es erfolgt keine Überprüfung der Meldeberechtigung! function createStarterForEvent($anMysqlConn, $anEventId, $anUserId, $aTypeId = "1"){ $retMessage = array(); if( (string)(int)$anEventId != $anEventId or (string)(int)$anUserId != $anUserId ){ $retMessage['error'] .= "Falsch formatierte eventId (".$anEventId.") oder userId (".$anUserId.")
"; return $retMessage; } $event = getEventData($anMysqlConn, $anEventId); if( empty($event) ){ $retMessage['error'] .= "eventId ".$anEventId." nicht gefunden
"; return $retMessage; } $user = getUserData($anMysqlConn, $anUserId); if( empty($event) ){ $retMessage['error'] .= "userId ".$anUserId." nicht gefunden
"; return $retMessage; } if( getUsersMeldeStatus($anMysqlConn, $anEventId, $anUserId) ){ $retMessage['notice'] .= "userId ".$anUserId." bereits bei eventId ".$anEventId." eingeschrieben
"; return $retMessage; } $query = sprintf( "INSERT INTO wkParticipo_Starter (eventId, userId, type) values (%s, %s, %s);", $anMysqlConn->real_escape_string($anEventId), $anMysqlConn->real_escape_string($anUserId), $anMysqlConn->real_escape_string($aTypeId) ); $result = $anMysqlConn->query($query); if(!$result){ $retMessage['error'] .= "Fehler \"".mysql_error()."\" bei der sqlQuery \"".$query."\"
"; return $retMessage; } $retMessage['success'] = "Neuer Starter userId " . $anUserId . " als Typ ".$aTypeId." für eventId " . $anEventId . " hinzugefügt"; return $retMessage; } function addMitfahrerToFahrt($anMysqlConn, $anStarterId, $anFahrtId){ $retMmessage = array(); if( (string)(int)$anStarterId != $anStarterId or (string)(int)$anFahrtId != $anFahrtId ){ $retMessage['error'] .= "Falsch formatierte starterId (".$anStartId.") oder fahrtId (".$anFahrtId.")
"; return $retMessage; } $fahrt = getFahrtData($anMysqlConn, $anFahrtId); $starter = getStarterData($anMysqlConn, $anStarterId); if( empty($fahrt) or empty($starter) or ($fahrt['eventId'] != $starter['eventId']) ){ $retMessage['error'] .= "eventId von Fahrt und Starter passen nicht: fahrtId['eventId']=\"".$fahrt['eventId']."\", starterId['eventId']=\"".$starter['eventId']."\"
"; return $retMessage; } $mitfahrerIds = array(); if( !empty($fahrt['mitfahrer']) ) $mitfahrerIds = explode(',', $fahrt['mitfahrer']); if( in_array( $anStarterId, $mitfahrerIds) ){ $message['warning'] .= "Starter '".$anStarterId."' bereits in Fahrt '".$anFahrtId."' eingeschrieben!
"; return $retMessage; } if( !empty($starter['fahrtId']) ){ $retMessage['error'] .= "Der Starter \"".$anStarterId."\" ist bereits in der Fahrt \"".$starterId['fahrtId']."\"
"; return $retMessage; } if( count($mitfahrerIds) >= (int)$fahrt['plaetze'] ){ $retMessage['error'] .= "Fahrt \"".$anFahrtId."\" hat keine freien Plätze mehr!
"; return $retMessage; } array_push( $mitfahrerIds, $starter['id'] ); $query = sprintf( "UPDATE wkParticipo_Fahrten SET mitfahrer='%s' WHERE id='%s';", $anMysqlConn->real_escape_string( implode(',', $mitfahrerIds) ), $anMysqlConn->real_escape_string( $fahrt['id'] ) ); $result = $anMysqlConn->query($query); if($anMysqlConn->affected_rows != 1){ $retMessage['error'] .= "verteileMitfahrer: Fehler beim Ausführen des sqlRequestes \"".$query."\"
"; return $retMessage; } $retMessage['success'] .= "Starter '". $starter['id'] . "' zur Fahrt '".$fahrt['id']."' hinzugefügt!
"; $query = sprintf( "UPDATE wkParticipo_Starter SET fahrtId='%s' WHERE id='%s';", $anMysqlConn->real_escape_string( $fahrt['id'] ), $anMysqlConn->real_escape_string( $starter['id'] ) ); $result = $anMysqlConn->query($query); if($anMysqlConn->affected_rows != 1){ $retMessage['error'] .= "Fehler beim Ausführen des sqlRequestes \"".$query."\"
"; return $retMessage; } $retMessage['success'] .= "Fahrt '". $fahrt['id'] . " zum Starter '".$starter['id']."' hinzugefügt!
"; return $retMessage; } /// Einer Fahrt einen Mitfahrer entziehen function shrinkFahrt($anMysqlConn, $fahrtId){ $retMessage = array(); if( (string)(int)$fahrtId == $fahrtId ){ $fahrt = getFahrtData($anMysqlConn, $fahrtId); } } // Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben function htmlRetMessage($anRetMessage){ $retHtmlString = ""; if( !empty($anRetMessage) ){ $retHtmlString .= "
"; if( !empty($anRetMessage['error']) ){ $retHtmlString .= "
"; $retHtmlString .= "ERROR:
"; $retHtmlString .= $anRetMessage['error']; $retHtmlString .= "
"; } if( !empty($anRetMessage['warning']) ){ $retHtmlString .= "
"; $retHtmlString .= "WARNING:
"; $retHtmlString .= $anRetMessage['warning']; $retHtmlString .= "
"; } if( !empty($anRetMessage['notice']) ){ $retHtmlString .= "
"; $retHtmlString .= "Info:
"; $retHtmlString .= $anRetMessage['notice']; $retHtmlString .= "
"; } if( !empty($anRetMessage['success']) ){ $retHtmlString .= "
"; $retHtmlString .= "SUCCESS:
"; $retHtmlString .= $anRetMessage['success']; $retHtmlString .= "
"; } $retHtmlString .= "
"; } // print_r($anRetMessage); return $retHtmlString; } function updateStarterErgebnis($anMysqlConn, $anStarterId, $anMass, $somePlaces){ $retMessage = array(); if( (string)(int)$anStarterId != $anStarterId ){ $retMessage['error'] .= "Falsch formatierte StarterId (".$anStarterId.")!
"; return $retMessage; } if( (string)(float)$anMass != $anMass and $anMass != "Offen" and $anMass != "-" ){ $retMessage['error'] .= "Falsch formatierte Masse (".$anMass.")
"; return $retMessage; } $plaetze = explode(',', $somePlaces); foreach($plaetze as $platz){ if( (string)(int)$platz != $platz ){ $message['error'] .= "Falsch formatierte Platzierungen (".$somePlaces.")
"; return $retMessage; } } $query = sprintf( "UPDATE wkParticipo_Starter SET masse='%s', platz='%s' WHERE id='%s';", $anMysqlConn->real_escape_string( $anMass ), $anMysqlConn->real_escape_string( $somePlaces ), $anMysqlConn->real_escape_string( $anStarterId ) ); $result = $anMysqlConn->query($query); if($anMysqlConn->affected_rows != 1){ $retMessage['error'] .= "updateStarterErgebnis: Fehler beim Ausführen des sqlRequestes \"".$query."\"
"; return $retMessage; } $retMessage['success'] .= "Dem Starter ".$anStarterId." wurde die Masse ".$anMass." und die Platzierung ".$somePlaces." zugeordnet!
"; return $retMessage; } /// Die KinderDaten eines Users abfragen function getUsersKidsData($anMysqlConn, $anUserId){ $retArray = array(); if( (string)(int)$anUserId != $anUserId ) return $retArray; $query = sprintf( "SELECT kinder FROM wkParticipo_Users WHERE id='%s';", $anMysqlConn->real_escape_string( $anUserId ) ); $results = $anMysqlConn->query($query); if($anMysqlConn->affected_rows != 1) return $retArray; $kinderIds = explode(',', $results->fetch_array()['kinder']); foreach($kinderIds as $kindId){ array_push( $retArray, getUserData($anMysqlConn, $kindId) ); } return $retArray; }; // geklaut von function addToGcalUrl( $name, $date, $location = false ) { // calculate the start and end dates, convert to ISO format $startdate = date('Ymd',strtotime($date)); $enddate = date('Ymd',strtotime($startdate . ' + 1 day')); // build the url $url = 'http://www.google.com/calendar/event?action=TEMPLATE'; $url .= '&text=' . rawurlencode($name); $url .= '&dates=' . $startdate . '/' . $enddate; if ($location) { $url .= '&location=' . rawurlencode($location); } // build the link output return $url; } ///--- /// ///--- /// Erzeugen des htmlCodes der Infobox für ein wkEvent function htmlWkEvent($aWkEvent, $starters, $fahrten){ $retHtml = ""; $retHtml .= "
". $aWkEvent['Veranstaltung'] ."
"; $retHtml .= "
Wettkampfdaten
    "; $retHtml .= "
  • Datum: "; if( empty($aWkEvent['Datum']) ){ $retHtml .= "fehlendes Datum"; } else{ $retHtml .= " In Google Calendar eintragen"; } $retHtml .= "
  • "; $retHtml .= "
  • Einschreibefrist: "; if( empty($aWkEvent['meldefrist']) ){ $retHtml .= "fehlende Einschreibefrist"; } else{ $retHtml .= " In Google Calendar eintragen"; } $retHtml .= "
  • "; $retHtml .= "
  • Wettkampf: "; if( empty($aWkEvent['Veranstaltung']) ){ $retHtml .= "fehlender Wettkampfname"; } else{ $retHtml .= $aWkEvent['Veranstaltung']; } $retHtml .= "
  • "; $retHtml .= "
  • Altersklassen: "; if( empty( $aWkEvent['Altersklassen'] ) ){ $retHtml .= "fehlende Altersklassen"; } else{ $retHtml .= $aWkEvent['Altersklassen']; } $retHtml .= "
  • "; if( !empty($_SESSION['login']) ){ // $starters = getStarterForEvent($mysqlConn, $aWkEvent['id']); $retHtml .= "
  • angemeldete Starter: "; if( empty($starters) ){ $retHtml .= "Noch hat sich niemand für diesen Wettkampf gemeldet!"; } else{ $retHtml .= count($starters); } $retHtml .= "
  • "; // $fahrten = getFahrtenForEvent($mysqlConn, $aWkEvent['id']); $anzPlätze = 0; foreach($fahrten as $fahrt) $anzPlätze += $fahrt['plaetze']; $retHtml .= "Anzahl Plätze: " . $anzPlätze . ""; if( !empty( $aWkEvent['bemerkungen'] ) ){ $retHtml .= "
  • Bemerkungen: " . $aWkEvent['bemerkungen'] . "
  • "; } } $retHtml .= "
"; $retHtml .= ""; $retHtml .= "
"; if (empty($_SESSION['login'])){ $retHtml .= "Ein Einschreiben ist nur eingeloggt möglich!"; } else{ $retHtml .= "Für diesen Wettkampf ..."; $retHtml .= "
"; $retHtml .= ""; if( date("Y-m-d") > $aWkEvent['meldefrist'] ){ $retHtml .= ""; $retHtml .= "

Frist für das Einschreiben verpasst? Für ein nachträgliches Eintragen mit dem Admin verständigen (Email an cwsvjudo@arcor.de).

"; } else{ $retHtml .= ""; } $retHtml .= "
"; $retHtml .= "
"; $retHtml .= ""; if($aWkEvent['Datum'] > date("Y-m-d")){ $retHtml .= ""; } else{ $retHtml .= ""; } $retHtml .= "
"; } $retHtml .= "
"; return $retHtml; } ?>