diff --git a/homepage/cwsvJudo/wkParticipo/lib/wkParticipo-user.php b/homepage/cwsvJudo/wkParticipo/lib/wkParticipo-user.php deleted file mode 100644 index 62a2de0..0000000 --- a/homepage/cwsvJudo/wkParticipo/lib/wkParticipo-user.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/homepage/cwsvJudo/wkParticipo/lib/wkParticipoLib.php.inc b/homepage/cwsvJudo/wkParticipo/lib/wkParticipoLib.php.inc deleted file mode 100644 index c79bb91..0000000 --- a/homepage/cwsvJudo/wkParticipo/lib/wkParticipoLib.php.inc +++ /dev/null @@ -1,1256 +0,0 @@ - "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 einschreiben!"; - - - $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 eingeschrieben!"; - - $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 beim Einschreiben: " . 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 .= "
  • "; - $retHtml .= "
  • Einschreibefrist: "; - if( empty($aWkEvent['meldefrist']) ){ - $retHtml .= "fehlende Einschreibefrist"; - } - else{ -// $retHtml .= " In Google Calendar eintragen"; - $retHtml .= ""; - } - $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 .= "
  • eingeschriebene Starter: "; - if( empty($starters) ){ - $retHtml .= "Noch hat sich niemand für diesen Wettkampf eingeschrieben!"; - } - 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 .= "
"; - if (empty($_SESSION['login'])){ - $retHtml .= "Ein Einschreiben ist nur eingeloggt möglich!"; - } - else{ - $heuteDateTime = DateTime::createFromFormat("Y-m-d", date("Y-m-d")); - $einschreibeDateTime = DateTime::createFromFormat("Y-m-d", $aWkEvent['meldefrist']); - - $retHtml .= "Für diesen Wettkampf ..."; - $retHtml .= "
"; - $retHtml .= ""; - if( $heuteDateTime > $einschreibeDateTime ){ - $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{ - if( $heuteDateTime->modify( "+ 4 weeks") < $einschreibeDateTime ){ - $retHtml .= ""; - } - else{ - $retHtml .= ""; - } - } - $retHtml .= "
"; - $retHtml .= "
"; - $retHtml .= ""; - - if($aWkEvent['Datum'] > date("Y-m-d")){ - $retHtml .= ""; - } - else{ - $retHtml .= ""; - } - $retHtml .= "
"; - } - $retHtml .= "
"; - - $retHtml .= - ""; - - $retHtml .= "
"; - -return $retHtml; -} - - -?> diff --git a/homepage/cwsvJudo/wkParticipo/test.php b/homepage/cwsvJudo/wkParticipo/test.php deleted file mode 100644 index 3f6572c..0000000 --- a/homepage/cwsvJudo/wkParticipo/test.php +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - Wettkampfplanung der Judoka des CWSV - - - - - -

Wettkampfplanung - Übersicht

- - -

Springe zu den ...

- -
abge­gebenen Meldungen.
-
angemel­deten Mitfahr­gelegen­heiten.
-
kommenden Wett­kämpfen.
-
-connect_error) { - $message['error'] = 'Datenbankverbindung fehlgeschlagen: ' . $mysqli->connect_error; - echo $message['error']; die(); - } -?> -

Meldungen zu kommenden Wettkämpfen

- - -

- - ist derzeit bei keinem Wettkampf eingeschrieben! - -

- - -
Termin in Kalender übernehmen
-
- " /> - -
-"; - } - } -?> - -

Angemeldete Mitfahrgelegenheiten

- - Keine Mitfahrangebote gefunden - -
-

" );?>

- -
Termin in Kalender übernehmen
-
- " /> - -
-
-
- - -

Anstehende Wettkämpfe

- -

Momentan befinden sich anscheinend keine Wettkämpfe in Planung!

- -
-
- " /> - -
-
- Für diesen Wettkampf ... -
- /> - $wk['meldefrist'] ){ -?> - - - - -
-
- " /> - date("Y-m-d")){ -?> - - - - -
-
-
- -

Letzte Ergebnisse

- - -close(); -?> - - - - - diff --git a/homepage/participo/events.php b/homepage/participo/events.php index ff1f14f..0e5f5e9 100644 --- a/homepage/participo/events.php +++ b/homepage/participo/events.php @@ -1,5 +1,5 @@ @@ -9,7 +9,7 @@ include_once("events.inc.php"); - + - <?php echo($meta['title']);?> - + <?php echo($meta['title']); ?> + @@ -63,17 +63,36 @@ include_once("events.inc.php");
- +
- +
+' + . 'DatumVeranstaltungStarter' + . ''; + foreach ($eventList as $event) { + $htmlTable .= '' . $event['eventDate'] . '' . $event['eventName'] . '' . $event['userName'] . ', ' . $event['userFirstname'] . ''; + } + $htmlTable .= ''; + echo('

Aktuelle Einschreibungen

'); + echo($htmlTable); + } else { + echo($eventList ? $htmlTable : '
Keine Meldungen zu bevorstehenden Events'); + } + ?>

Übersicht anstehender Events

- +

Detailansicht kommender Wettkämpfe

- asHtmlCard());?> + asHtmlCard()); + }?>
diff --git a/homepage/participo/index.php b/homepage/participo/index.php index 5b097a7..eea3e71 100644 --- a/homepage/participo/index.php +++ b/homepage/participo/index.php @@ -1,26 +1,26 @@ @@ -123,32 +123,32 @@ echo( ], ])->htmlCode() ) -?> + ?>

Zur Information

'infoZettel', - 'title' => 'Infozettel', - 'description' => 'Online-Variante der Infozettel und Newsletter', - 'imgUrl' => 'images/info.svg', - 'actions' => [ - AppCardAction::fromArray(['caption' => 'Info', 'link' => 'infoZettel']), - ], - ])->htmlCode() . - AppCard::fromArray([ - 'link' => 'attendance', - 'title' => 'Teilnahme', - 'description' => 'Eine kleine Übersicht, wie wie oft man beim Training war', - 'imgUrl' => 'http://cwsvjudo.bplaced.net/ressourcen/graphiken/icons/calendarIcon.svg', - 'actions' => [ - AppCardAction::fromArray(['caption' => 'Anwesenheit', 'link' => 'attendance']), - ], - ])->htmlCode() -); + echo( + AppCard::fromArray([ + 'link' => 'infoZettel', + 'title' => 'Infozettel', + 'description' => 'Online-Variante der Infozettel und Newsletter', + 'imgUrl' => 'images/info.svg', + 'actions' => [ + AppCardAction::fromArray(['caption' => 'Info', 'link' => 'infoZettel']), + ], + ])->htmlCode() . + AppCard::fromArray([ + 'link' => 'attendance', + 'title' => 'Teilnahme', + 'description' => 'Eine kleine Übersicht, wie wie oft man beim Training war', + 'imgUrl' => 'http://cwsvjudo.bplaced.net/ressourcen/graphiken/icons/calendarIcon.svg', + 'actions' => [ + AppCardAction::fromArray(['caption' => 'Anwesenheit', 'link' => 'attendance']), + ], + ])->htmlCode() + ); // @todo attendanceApp?>
@@ -206,20 +206,6 @@ if (participo::isUserAdmin($userData['id'])) { ])->htmlCode() . '' ); - - echo("

Aktuelle Einschreibungen

"); - $eventList = participo::getEventStarter("2022-01-01"); - $htmlTable = null; - if($eventList){ - $htmlTable = "" - ."" - .""; - foreach($eventList as $event){ - $htmlTable .= ""; - } - $htmlTable .= "
DatumVeranstaltungStarter
".$event['eventDate']."".$event['eventName']."".$event['userName'].", ".$event['userFirstname']."
"; - } - echo($eventList?$htmlTable:"
Keine Meldungen zu bevorstehenden Events"); } ?> NULL, 'success' => NULL, 'notice' => NULL]; + private static $message = ['error' => null, 'success' => null, 'notice' => null]; + private static $userId = null; /** * Returns the current login status - * + * * The login status is stored in the session cookie. If it is not even set it means the login is invalid. * * @return The login status or false if none is set so far */ - static public function isLoginValid(){ + public static function isLoginValid() + { return ($_SESSION['login'] ?? false); } /** * A little Box with the login status as html entity * - * @return string htmlEntity showing the login status + * @return string htmlEntity showing the login status */ - static public function htmlLoginStatus(){ - return - "
". - "Datum: ".date("Y-m-d")."
". - "Angemeldet als ".htmlspecialchars($_SESSION['user']['username']).".
". - "Sitzung beenden". - "
"; + public static function htmlLoginStatus() + { + return + '
' . + 'Datum: ' . date('Y-m-d') . '
' . + 'Angemeldet als ' . htmlspecialchars($_SESSION['user']['username']) . '.
' . + 'Sitzung beenden' . + '
'; } /** * Checks, if there already is a valid login, if not redirect to the login form * @todo rename to authenticate - * + * * @retval void */ - static public function authentificate(){ + public static function authentificate() + { session_start(); - if ( !self::isLoginValid() ) { - header("Location: login?returnToUrl=".urlencode($_SERVER['REQUEST_URI'].($_POST['fragment'] ?? "")), TRUE, 301); + if (!self::isLoginValid()) { + header('Location: login?returnToUrl=' . urlencode($_SERVER['REQUEST_URI'] . ($_POST['fragment'] ?? '')), true, 301); exit(); // should'nt matter } + participo::$userId = $_SESSION['user']['userId']; } - static public function getMessages(){return self::$message;} - static public function addMessage($type, $message){self::$message[$type] = (self::$message[$type] ?? "").$message;} + public static function getMessages() + { + return self::$message; + } + + public static function addMessage($type, $message) + { + self::$message[$type] = (self::$message[$type] ?? '') . $message; + } /** * check password for user - * + * * @param string $loginName user who wants to get in * @param string $password password for the user * * @retval true $password belongs to $loginName * @retval false otherwise */ - static public function checkCredentials($loginName, $password){ + public static function checkCredentials($loginName, $password) + { sleep(1); // just to discourage brute force attacks // Check for dbConnection - if(!dbConnector::getDbConnection()){ - self::addMessage('error', "
No DbConnection available
"); + if (!dbConnector::getDbConnection()) { + self::addMessage('error', '
No DbConnection available
'); return false; } @@ -68,33 +82,33 @@ class participo{ // @todo check for e.g., len(user)=1 // @todo getUser? $user = dbConnector::query( - "SELECT `id`, `loginName`, `pwHash`, `config` FROM `wkParticipo_Users` WHERE `loginName` = :loginName", - ['loginName' => ['value'=>$loginName, 'data_type'=>PDO::PARAM_STR]] + 'SELECT `id`, `loginName`, `pwHash`, `config` FROM `wkParticipo_Users` WHERE `loginName` = :loginName', + ['loginName' => ['value' => $loginName, 'data_type' => PDO::PARAM_STR]] ); $user = $user[0]; // If there is no such user OR the password isn't valid the login fails - if( empty($user) || !password_verify( $password, $user['pwHash'])){ + if (empty($user) || !password_verify($password, $user['pwHash'])) { sleep(5); // discourage brute force attacks - self::addMessage('error', "
Falsches Passwort oder LoginName
"); + self::addMessage('error', '
Falsches Passwort oder LoginName
'); return false; } session_start(); // case valid login: Set the session data - $_SESSION = array( + $_SESSION = [ 'login' => true, - 'user' => array( - 'username' => $user['loginName'], + 'user' => [ + 'username' => $user['loginName'], 'userId' => $user['id'], 'userConfig' => json_decode($user['config'], true) - ) - ); + ] + ]; // Logging Logins logLoginsToJsonFile($_SESSION['user']['username']); - - self::addMessage('success', "
Anmeldung erfolgreich
"); + + self::addMessage('success', '
Anmeldung erfolgreich
'); return true; } @@ -105,10 +119,11 @@ class participo{ * @retval true user with id $userId has attribute "isAdmin" * @retval false otherwise */ - static function isUserAdmin($userId){ - return self::hasUserAttribute( $userId, "isAdmin"); + public static function isUserAdmin($userId) + { + return self::hasUserAttribute($userId, 'isAdmin'); } - + /** * Checks, if a user as a certain attribute * @@ -116,7 +131,8 @@ class participo{ * @param [type] $attributeName string name of the attribute to check * @return boolean */ - static public function hasUserAttribute($userId, $attributeName){ + public static function hasUserAttribute($userId, $attributeName) + { // sqlQuery: Select the user if it has the given attribute $query = <<userAttributes`.userId, `wkParticipo_userAttributes`.name @@ -124,41 +140,45 @@ FROM `wkParticipo_user<=>userAttributes` LEFT JOIN `wkParticipo_userAttributes` ON `wkParticipo_user<=>userAttributes`.`attributeId` = `wkParticipo_userAttributes`.`id` WHERE `wkParticipo_userAttributes`.name = :attributeName AND userId=:userId; SQL; - $params = array( - ':userId' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT), - ':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR) - ); + $params = [ + ':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT], + ':attributeName' => ['value' => $attributeName, 'data_type' => PDO::PARAM_STR] + ]; $attributedUsers = dbConnector::query($query, $params); // Since the id should be unique, there should only be one result this is just for dealing with empty arrays - foreach($attributedUsers as $u) - if($u['userId']==$userId) + foreach ($attributedUsers as $u) { + if ($u['userId'] == $userId) { return true; - return false; + } + } + return false; } - - static public function getEventStarter($sinceDate=null){ - if(!$sinceDate) - $sinceDate = "CURDATE()"; - else - $sinceDate = "DATE(\"".$sinceDate."\")"; + public static function getEventStarter($sinceDate = null) + { + $userId = $_SESSION['user']['userId']; + if (!$sinceDate) { + $sinceDate = 'CURDATE()'; + } else { + $sinceDate = 'DATE("' . $sinceDate . '")'; + } $query = <<= $sinceDate + LEFT JOIN `vormundschaft` ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` +WHERE `wkParticipo_Events`.`date` >= $sinceDate AND `vormundschaft`.`userId` = $userId ORDER BY `wkParticipo_Events`.`date` DESC; SQL; - $commingStarts = dbConnector::query($query); - + $commingStarts = dbConnector::query($query); + return $commingStarts; } } @@ -166,37 +186,44 @@ SQL; /** * Action element of an MaterializeCss (App-)card */ -class AppCardAction{ +class AppCardAction +{ private $caption = null; //< Caption for the action - private $link = "."; //< link for the action + private $link = '.'; //< link for the action + /** * Constructor for the AppAction * * @param string $caption caption for the action * @param string $link link to the action */ - function __construct( $caption, $link = "." ){ + public function __construct($caption, $link = '.') + { //! @todo input sanitation - $this->link = $link; + $this->link = $link; $this->caption = $caption; } + /** * Create htmlCode for the action * * @return string with htmlCode of the action */ - function htmlCode(){ - return "link."\">".$this->caption.""; + public function htmlCode() + { + return '' . $this->caption . ''; } + /** * Create AppCardAction from assoziative array * * @param array $member array with the member values * @return AppCardAction */ - static public function fromArray($member){ + public static function fromArray($member) + { $caption = $member['caption'] ?? null; - $link = $member['link'] ?? "."; + $link = $member['link'] ?? '.'; return new AppCardAction($caption, $link); } } @@ -204,12 +231,14 @@ class AppCardAction{ /** * MaterializeCss card for an App */ -class AppCard{ - private $title = ""; //< title of the card - private $description = ""; //< description of the App +class AppCard +{ + private $title = ''; //< title of the card + private $description = ''; //< description of the App private $link = null; //< link for the card-content private $imgUrl = null; //< url for an image right under the title private $actionList = []; //< list of actions for the bottom of the card + /** * Constructor for the AppCard * @@ -219,7 +248,8 @@ class AppCard{ * @param string $imgUrl url for an image right under the title * @param array $actionList list of actions at the bottom of the card */ - function __construct($title, $description, $link=null, $imgUrl=null, $actionList=[]){ + public function __construct($title, $description, $link = null, $imgUrl = null, $actionList = []) + { //! @todo input sanitation $this->title = $title; $this->description = $description; @@ -227,41 +257,45 @@ class AppCard{ $this->imgUrl = $imgUrl; $this->actionList = $actionList; } + /** * Create htmlCode for the AppCard * * @return string html code for the AppCard */ - public function htmlCode($options=[]){ - $extraClass = $options['extraClass'] ?? ""; - $actionListCode = ""; - foreach($this->actionList as $a){ + public function htmlCode($options = []) + { + $extraClass = $options['extraClass'] ?? ''; + $actionListCode = ''; + foreach ($this->actionList as $a) { $actionListCode .= $a->htmlCode(); } return - "
". - "
". - "
". - (($this->link!=null)?("link."\">"):(""))."".$this->title."".(($this->link!=null)?(""):("")). - (($this->imgUrl!=null)?("\"".$this-title."\" style=\"display:block;margin-left:auto;margin-right:auto;max-height:10vh;\" class=\"responsive-img\" src=\"".$this->imgUrl."\" />"):("")). - "

".$this->description."

". - "
". - "
".$actionListCode."
". - "
". - "
"; + '
' . + '
' . + '
' . + (($this->link != null) ? ('') : ('')) . '' . $this->title . '' . (($this->link != null) ? ('') : ('')) . + (($this->imgUrl != null) ? ('' . $this->title . '') : ('')) . + '

' . $this->description . '

' . + '
' . + '
' . $actionListCode . '
' . + '
' . + '
'; } + /** * Create AppCard from an associative array * - * @param array $member array with member as keys and values as the member values + * @param array $member array with member as keys and values as the member values * @return AppCard from array values */ - static public function fromArray($member){ - $title = $member['title'] ?? ""; - $description = $member['description'] ?? ""; - $link = $member['link'] ?? null; - $imgUrl = $member['imgUrl'] ?? null; - $actionList = $member['actions'] ?? []; + public static function fromArray($member) + { + $title = $member['title'] ?? ''; + $description = $member['description'] ?? ''; + $link = $member['link'] ?? null; + $imgUrl = $member['imgUrl'] ?? null; + $actionList = $member['actions'] ?? []; return new AppCard($title, $description, $link, $imgUrl, $actionList); } @@ -270,55 +304,57 @@ class AppCard{ /** * Generate a html table of the last logins of the users * - * @param string $jsonFileName path to the json file with the logged logins + * @param string $jsonFileName path to the json file with the logged logins * @return string Html table of users last logins */ -function lastLoginTable($jsonFileName="lastLogins.json"){ - $lastLogins=json_decode( file_get_contents($jsonFileName), true); - $lastLoginsTable = - "". - "". - ""; - foreach( $lastLogins as $userName => $lastLogins ){ +function lastLoginTable($jsonFileName = 'lastLogins.json') +{ + $lastLogins = json_decode(file_get_contents($jsonFileName), true); + $lastLoginsTable = + '
userNamelastLogins
' . + '' . + ''; + foreach ($lastLogins as $userName => $lastLogins) { $lastLoginsTable .= - ""; + ''; } - $lastLoginsTable .= "
userNamelastLogins
".$userName."".$lastLogins['lastLogins'][0]."
' . $userName . '' . $lastLogins['lastLogins'][0] . '
"; + $lastLoginsTable .= ''; return $lastLoginsTable; } /// 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:
"; +function htmlRetMessage($anRetMessage) +{ + $retHtmlString = ''; + if (!empty($anRetMessage)) { + $retHtmlString .= '
'; + if (!empty($anRetMessage['error'])) { + $retHtmlString .= '
'; + $retHtmlString .= 'ERROR:
'; $retHtmlString .= $anRetMessage['error']; - $retHtmlString .= "
"; + $retHtmlString .= '
'; } - if( !empty($anRetMessage['warning']) ){ - $retHtmlString .= "
"; - $retHtmlString .= "WARNING:
"; + if (!empty($anRetMessage['warning'])) { + $retHtmlString .= '
'; + $retHtmlString .= 'WARNING:
'; $retHtmlString .= $anRetMessage['warning']; - $retHtmlString .= "
"; + $retHtmlString .= '
'; } - if( !empty($anRetMessage['notice']) ){ - $retHtmlString .= "
"; - $retHtmlString .= "Info:
"; + if (!empty($anRetMessage['notice'])) { + $retHtmlString .= '
'; + $retHtmlString .= 'Info:
'; $retHtmlString .= $anRetMessage['notice']; - $retHtmlString .= "
"; + $retHtmlString .= '
'; } - if( !empty($anRetMessage['success']) ){ - $retHtmlString .= "
"; - $retHtmlString .= "SUCCESS:
"; + if (!empty($anRetMessage['success'])) { + $retHtmlString .= '
'; + $retHtmlString .= 'SUCCESS:
'; $retHtmlString .= $anRetMessage['success']; - $retHtmlString .= "
"; + $retHtmlString .= '
'; } - $retHtmlString .= "
"; + $retHtmlString .= '
'; } -return $retHtmlString; + return $retHtmlString; } /** @@ -327,15 +363,16 @@ return $retHtmlString; * @param string $fileName filename of the markdown file * @return array assocative array('yaml'=>array(..), 'mdText'=>string) containing the yamlHeader as associative array and the markdown text as string */ -function loadMarkdownFile($fileName){ +function loadMarkdownFile($fileName) +{ // load the whole file $fileText = file_get_contents($fileName); // split at '---' to get ((),yamls,array) $fileParts = preg_split('/[\n]*[-]{3}[\n]/', $fileText, 3); - // not all mdfiles have a yamlHeader, so the mdText can be at different indices - $yaml=[]; - $mdText = ""; - switch( count($fileParts) ){ + // not all mdfiles have a yamlHeader, so the mdText can be at different indices + $yaml = []; + $mdText = ''; + switch(count($fileParts)) { case 1:{ $mdText = $fileParts[0]; break; @@ -348,25 +385,22 @@ function loadMarkdownFile($fileName){ default:{ $mdText = $fileText; } - } // get a title, if none is in the markdown - if(!array_key_exists('title', $yaml)){ + if (!array_key_exists('title', $yaml)) { // find the first heading, set it as header and remove it from the markdown - if( preg_match("/^#(.*)$/m", $mdText, $matches) ){ + if (preg_match('/^#(.*)$/m', $mdText, $matches)) { $yaml['title'] = $matches[1]; - $mdText = preg_replace("/^#(.*)$/m", "", $mdText, 1); - } - else{ + $mdText = preg_replace('/^#(.*)$/m', '', $mdText, 1); + } else { // fallback for the title, if not even one heading is found - $yaml['title'] = ""; + $yaml['title'] = ''; } } - return array( - 'yaml' => $yaml - , 'mdText' => $mdText - ); + return [ + 'yaml' => $yaml, 'mdText' => $mdText + ]; } /** @@ -376,20 +410,22 @@ function loadMarkdownFile($fileName){ * @param string $fileName filename to log to * @return void */ -function logLoginsToJsonFile($userName, $fileName="lastLogins.json"){ - try{ +function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json') +{ + try { $lastLogins = json_decode(file_get_contents($fileName), true); - if ($lastLogins == NULL){ + if ($lastLogins == null) { return; } - if(!array_key_exists($userName, $lastLogins)) + if (!array_key_exists($userName, $lastLogins)) { $lastLogins[$userName] = []; - if(!array_key_exists('lastLogins', $lastLogins[$userName])) + } + if (!array_key_exists('lastLogins', $lastLogins[$userName])) { $lastLogins[$userName]['lastLogins'] = []; - $lastLogins[$userName]['lastLogins'] = array_merge( array( date('Y-m-d H:i:s') ), $lastLogins[$userName]['lastLogins'] ); + } + $lastLogins[$userName]['lastLogins'] = array_merge([date('Y-m-d H:i:s')], $lastLogins[$userName]['lastLogins']); file_put_contents($fileName, json_encode($lastLogins)); - } - catch (Exception $e){ + } catch (Exception $e) { // silently ignore errors } } @@ -397,70 +433,82 @@ function logLoginsToJsonFile($userName, $fileName="lastLogins.json"){ /** * interface for connecting and communicating with a database */ -class dbConnector{ - static private $db = null; +class dbConnector +{ + private static $db = null; // connect to the database - public static function connect($hostname, $dbName, $user, $password){ - return self::setDbConnection( self::connectToPdo($hostname, $dbName, $user, $password) ); + public static function connect($hostname, $dbName, $user, $password) + { + return self::setDbConnection(self::connectToPdo($hostname, $dbName, $user, $password)); } - public static function getDbConnection(){return self::$db;} + public static function getDbConnection() + { + return self::$db; + } /// perform a pdo-query /// /// @param $aQueryString - /// @param $aBindArray e.g. array( - /// ':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT), + /// @param $aBindArray e.g. array( + /// ':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT), /// ':attributeId'=> array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT) ) /// @param $someOption - public static function query($aQueryString, $aBindArray = array(), $someOptions = array()){ + public static function query($aQueryString, $aBindArray = [], $someOptions = []) + { // Standardbelegungen - if( empty($someOptions['dbCharset' ]) ) $someOptions['dbCharset' ] = "ISO-8859-1"; - if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8"; - if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false; - - /// @toDo: Bisher wird nur die Rückgabe konvertiert. Eigentlich muss - /// doch auch die Eingabe konvertiert werden. Aber das jetzt - /// umzustellen wird schwer! Die User im Wettkampfplaner sind ja z.B. + if (empty($someOptions['dbCharset'])) { + $someOptions['dbCharset'] = 'ISO-8859-1'; + } + if (empty($someOptions['outCharset'])) { + $someOptions['outCharset'] = 'UTF-8'; + } + if (empty($someOptions['dontFetch'])) { + $someOptions['dontFetch'] = false; + } + + /// @toDo: Bisher wird nur die Rückgabe konvertiert. Eigentlich muss + /// doch auch die Eingabe konvertiert werden. Aber das jetzt + /// umzustellen wird schwer! Die User im Wettkampfplaner sind ja z.B. /// als UTF8 in latin1(?) gespeichert. - /// @toDo: Die Standardwerte sollten vielleicht aus einer config + /// @toDo: Die Standardwerte sollten vielleicht aus einer config /// kommen, nicht hardcoded - try{ - $pdoStatement = self::$db->prepare( $aQueryString ); - foreach( $aBindArray as $bindName => $bind ){ - if( $bind['data_type'] == PDO::PARAM_STR) + try { + $pdoStatement = self::$db->prepare($aQueryString); + foreach ($aBindArray as $bindName => $bind) { + if ($bind['data_type'] == PDO::PARAM_STR) { $bind['value'] = iconv( - $someOptions['outCharset'], - $someOptions['dbCharset'], + $someOptions['outCharset'], + $someOptions['dbCharset'], $bind['value'] ); + } $pdoStatement->bindValue( $bindName, $bind['value'], - (isset($bind['data_type'])?$bind['data_type']:PDO::PARAM_STR) + (isset($bind['data_type']) ? $bind['data_type'] : PDO::PARAM_STR) ); } $pdoResult = $pdoStatement->execute(); - if(!$pdoResult){ + if (!$pdoResult) { echo("Error during dbQuery!\n"); - echo("DB-Error:\n"); var_dump(self::$db->errorInfo()); + echo("DB-Error:\n"); + var_dump(self::$db->errorInfo()); } - if($someOptions['dontFetch']){ - $ret = NULL; - } - else{ + if ($someOptions['dontFetch']) { + $ret = null; + } else { $ret = $pdoStatement->fetchAll(PDO::FETCH_ASSOC); } - } - catch(PDOException $db_error){ - print "Error!: " . $db_error->getMessage() . "
"; + } catch(PDOException $db_error) { + print 'Error!: ' . $db_error->getMessage() . '
'; return null; } - + // Zeichensatzkonvertierung - if( is_array($ret) ){ - foreach($ret as &$entry){ + if (is_array($ret)) { + foreach ($ret as &$entry) { array_walk( $entry, function (&$value, $key, $someOptions) { @@ -472,56 +520,55 @@ class dbConnector{ } return $ret; } - + // get a Connection to the database - static private function connectToPdo($hostname, $dbName, $user, $password){ - $dbConnection=null; - try{ + private static function connectToPdo($hostname, $dbName, $user, $password) + { + $dbConnection = null; + try { $dbConnection = new PDO( - 'mysql:host='.$hostname.';dbname='.$dbName, - $user, + 'mysql:host=' . $hostname . ';dbname=' . $dbName, + $user, $password ); - } - catch(PDOException $dbError){ - echo( "Error whilst getting a dbConnection!: " . $dbError->getMessage() ); + } catch(PDOException $dbError) { + echo('Error whilst getting a dbConnection!: ' . $dbError->getMessage()); } return $dbConnection; } // set the dbConnection (just setting, no establishing) - private static function setDbConnection($dbConnection){ + private static function setDbConnection($dbConnection) + { $success = false; - if($dbConnection instanceof PDO){ + if ($dbConnection instanceof PDO) { self::$db = $dbConnection; $success = true; - } - else{ + } else { self::$db = null; } } - - } /** * User for the Participo system */ -class User{ +class User +{ private $id; private $loginName; private $name; private $firstName; private $dateOfBirth; private $eMail; - + public function __construct($id, $loginName, $name, $firstName, $dateOfBirth, $eMail) { $this->id = (int) id; $this->loginName = $loginName; $this->name = $name; $this->firstName = $firstName; - $this->dateOfBirth = $dateOfBirth!=null?DateTime::createFromFormat('Y-m-d', $dateOfBirth):null; + $this->dateOfBirth = $dateOfBirth != null ? DateTime::createFromFormat('Y-m-d', $dateOfBirth) : null; $this->eMail = $eMail; } @@ -531,35 +578,36 @@ class User{ * @param array $member associative array with the UserData from the dbRequest * @return User initialized user */ - public static function fromDbArray($member){ + public static function fromDbArray($member) + { return new User( - $member['id']??null, - $member['loginName']??null, - $member['name']??null, - $member['vorname']??null, - $member['gebDatum']??null, - array_key_exist('eMail', $member)?explode(',', $member['eMail']):null + $member['id'] ?? null, + $member['loginName'] ?? null, + $member['name'] ?? null, + $member['vorname'] ?? null, + $member['gebDatum'] ?? null, + array_key_exist('eMail', $member) ? explode(',', $member['eMail']) : null ); } - + /** * Export the User data into an associative array */ - function toAssoc(){ - return array( - "id" => $this->id, - "loginName"=> $this->loginName, - "name" => $this->name, - "vorname" => $this->firstName, - "gebDatum" => $this->dateOfBirth, - "eMail" => $this->eMail); + public function toAssoc() + { + return [ + 'id' => $this->id, + 'loginName' => $this->loginName, + 'name' => $this->name, + 'vorname' => $this->firstName, + 'gebDatum' => $this->dateOfBirth, + 'eMail' => $this->eMail]; } - function loadFromDb($dbConn, $id){ + public function loadFromDb($dbConn, $id) + { $this->set( loadUserDataFromDb($dbConn, $id) ); } } - -?> \ No newline at end of file diff --git a/homepage/participo/lib/participoLib/planer.php b/homepage/participo/lib/participoLib/planer.php index aa94a68..8857836 100644 --- a/homepage/participo/lib/participoLib/planer.php +++ b/homepage/participo/lib/participoLib/planer.php @@ -3,7 +3,7 @@ /** * frame for a shiai */ -class shiai +class Shiai { private $id = null; //< unique id private $date = null; //< date of the shiai @@ -90,7 +90,10 @@ class shiai } } // end class shiai -class event +/** + * Framework for a event + */ +class Event { private $id = null; //< unique id of the event in the db private $date = null; //< date for the event (@todo ranges?) @@ -98,8 +101,18 @@ class event private $deadline = null; //< until when one can register for the event private $remarks = null; //< remarks to the event (special rules) or a json object for missing data (e.g. non-shiai events) - private $shiai = null; + private $shiai = null; //< a place to load the linked shiai to (if loaded) + /** + * constructor + * + * @param int $id id in the database + * @param string $date date of the event as string in the format "YYYY-MM-DD" + * @param int $shiaiId id of the linked shiai or null if not appropriate + * @param string $deadline deadline for sign ins in the format "YYYY-MM-DD" + * @param string $remarks (json formatted) string with meta information + * @param Shiai $shiai if the shiai is loaded anyway it can be placed here. + */ public function __construct($id, $date, $shiaiId, $deadline, $remarks, $shiai) { //! @todo InputValidation @@ -112,6 +125,11 @@ class event $this->shiai = $shiai; } + /** + * Representation of an event as (materializeCss) card + * + * @return string string with the html code of the event + */ public function asHtmlCard() { return @@ -135,7 +153,8 @@ class event '' . '' . $this->date->format('Y-m-d') . '' . '' . $this->shiai->getName() . '' . - 'add' . + 'zoom_in + ' . ''; } @@ -166,8 +185,140 @@ class event shiai::fromArray(($shiai != null) ? $shiai : $member) ); } + + /// Einen Starter per userId mit typeId zu einem Event per eventId hinzufügen + /// Es erfolgt keine Überprüfung der Meldeberechtigung! + public static function addStarter($dbConnection, $starter) + { + $retMessage = []; + + $query = 'INSERT INTO `wkParticipo_Starter` (eventId, userId, type) values (:eventId, :userId, :typeId);'; + $params = [ + ':eventId' => ['value' => $starter->getEventId(), 'data_type' => PDO::PARAM_INT], + ':userId' => ['value' => $starter->getUserId(), 'data_type' => PDO::PARAM_INT], + ':typeId' => ['value' => $starter->getTypeId(), 'data_type' => PDO::PARAM_INT] + ]; + + return dbConnector::query($query, $params); + } } // end class event +abstract class StartingType +{ + const __default = null; + + const Fighter = 1; + const Audience = 2; + const NoParticipation = 3; + + /** + * convert a variable into a StartingType + * + * @param [int] $type starting type candidate + * @return int representation of the StartingType if successful converted, otherwise null + */ + public static function toStartingType($type) + { + return filter_var($type, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1, 'max_range' => 3]]); + } + + /** + * string representations of the starting type + * + * @var array array of StartingType=> its string representation + */ + public static $AsString = [1 => 'Kämpfer', 2 => 'Zuschauer', 3 => 'keine Teilnahme']; +} + +class Starter +{ + private $id = null; //< id of the event in the database + private $eventId = null; //< dbId of the event one is starting + private $typeId = null; //< type(id) of the starter + private $userId = null; //< id of the starting user + private $rideId = null; //< id of the ride where the starter can car pool + private $mass = null; //< mass in kg on the scale + private $result = null; //< result of the start (array of places if multi start) + + // Getter for the member + public function getId() + { + return $this->id; + } + + public function getEventId() + { + return $this->eventId; + } + + public function getTypeId() + { + return $this->typeId; + } + + public function getUserId() + { + return $this->userId; + } + + public function getRideId() + { + return $this->rideId; + } + + public function getMass() + { + return $this->mass; + } + + public function getResult() + { + return $this->result; + } + + /** + * Construtor + * + * @todo Document + * @todo Rethink validation: filter_var is supposed to return the converted value in case of success. But the reference didn't say anything about not success... + */ + public function __construct($id, $eventId, $typeId, $userId, $rideId, $mass, $result) + { + $this->id = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); + $this->eventId = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); + $this->typeId = StartingType::toStartingType($type); + $this->userId = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); + $this->rideId = filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); + $this->mass = filter_var($mass, FILTER_VALIDATE_FLOAT, ['options' => ['default' => null, 'min_range' => 0.0]]); + + if (is_iterable($result)) { + $this->result = []; + foreach ($result as $r) { + $r = filter_var($r, FILTER_VAR_INT, ['options' => ['default' => null, 'min_range' => 0]]); + if ($r) { + array_push($this->result, $r); + } + } + } else { + $this->$result = filter_var($r, FILTER_VAR_INT, ['options' => ['default' => null, 'min_range' => 0]]); + } + } + + // create starter from assoc array + public static function create($parameter) + { + $id = $parameter['id'] ?? null; //< id of the event in the database + $eventId = $parameter['eventId'] ?? null; //< dbId of the event one is starting + $typeId = $parameter['typeId'] ?? null; //< type(id) of the starter + $userId = $parameter['userId'] ?? null; //< id of the starting user + $rideId = $parameter['rideId'] ?? null; //< id of the ride where the starter can car pool + $mass = $parameter['mass'] ?? null; //< mass in kg on the scale + $result = $parameter['result'] ?? null; //< result of the start (array of places if multi start) + + return new Starter($id, $eventId, $typeId, $userId, $rideId, $mass, $result); + } +} + class eventPlaner { private static $db = null;