- der Wettkampfkalender soll nicht mehr hin und her gescrollt werden müssen geändert: src/css/cwsvJudo-2018-content.css - Funktion zum Abfragen aus der Datenbank; zum Schreibaufwand sparen geändert: wkParticipo/lib/wkParticipo-userAttribute.php - Ergänzung um Wettkampflose Event geändert: wkParticipo/lib/wkParticipoLib.inc.php - structured Data breadcrumbs für den Wettkampfkalender mit Einzelansicht geändert: wkKalender.php
1342 lines
46 KiB
PHP
1342 lines
46 KiB
PHP
<?php
|
|
$startTyp = array( '1' => "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, $someOptions = array() ){
|
|
// wir befinden uns in der Übergangsphase:
|
|
// - als Standard wird das derzeitige Verhalten definiert (ISO-8859-1
|
|
// und die Konvertierung erfolgt ausserhalb)
|
|
// - wenn einmal alle mbConvertEncoding weg sind, kann der Standard auf
|
|
// das gewünschte Verhalten umgestellt werden
|
|
if( empty($someOptions['dbCharset']) ) $someOptions['dbCharset'] = "ISO-8859-1";
|
|
//if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";// das spätere, gewünschte Verhalten
|
|
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "ISO-8859-1";
|
|
|
|
$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();
|
|
}
|
|
|
|
// var_dump($someOptions);
|
|
// var_dump($results);
|
|
// var_dump($ret);
|
|
|
|
// Zeichensatzkonvertierung
|
|
array_walk(
|
|
$ret,
|
|
function (&$value, $key, $someOptions) {
|
|
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
|
},
|
|
$someOptions
|
|
);
|
|
// var_dump($ret);
|
|
|
|
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.date, ".
|
|
"wkParticipo_Events.wkId, ".
|
|
"wkParticipo_Events.meldefrist, ".
|
|
"wkParticipo_Events.bemerkungen, ".
|
|
"wettkampfkalender.Datum, ".
|
|
"wettkampfkalender.Veranstaltung, ".
|
|
"wettkampfkalender.Altersklassen, ".
|
|
"wettkampfkalender.Ort, ".
|
|
"wettkampfkalender.Ausschreibung, ".
|
|
"wettkampfkalender.Routenplaner ".
|
|
"FROM wkParticipo_Events ".
|
|
"LEFT JOIN wettkampfkalender ".
|
|
"ON wkParticipo_Events.wkId = wettkampfkalender.lfdeNr ".
|
|
"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, $someOptions = array()){
|
|
|
|
if( empty($someOptions['dbCharset']) ) $someOptions['dbCharset'] = "ISO-8859-1";
|
|
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";
|
|
|
|
$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 ".
|
|
"LEFT 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();
|
|
|
|
// Zeichensatzkonvertierung
|
|
array_walk(
|
|
$ret,
|
|
function (&$value, $key, $someOptions) {
|
|
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
|
},
|
|
$someOptions
|
|
);
|
|
|
|
// @todo: nur temporär: fehlende Wettkampdaten aus den Metadaten ergänzen
|
|
if( empty($ret['wkId']) ){
|
|
$tmpWkEvent = json_decode($ret['bemerkungen'], true);
|
|
// var_dump($tmpWkEvent, $ret['bemerkungen']);
|
|
if(!empty($tmpWkEvent)){
|
|
// var_dump( $tmpWkEvent );
|
|
// var_dump( json_decode($aWkEvent['bemerkungen'], true) );
|
|
$ret['Datum'] = $tmpWkEvent['Datum'];
|
|
if($tmpWkEvent['Ort'])
|
|
$ret['Ort'] = $tmpWkEvent['Ort'];
|
|
if($tmpWkEvent['Routenplaner'])
|
|
$ret['Routenplaner'] = $tmpWkEvent['Routenplaner'];
|
|
$ret['Veranstaltung'] = $tmpWkEvent['Veranstaltung'];
|
|
$ret['Altersklassen'] = $tmpWkEvent['Altersklassen'];
|
|
$ret['bemerkungen'] = $tmpWkEvent['bemerkungen'];
|
|
}
|
|
}
|
|
|
|
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, $someOptions=array() ){
|
|
|
|
// wir befinden uns in der Übergangsphase:
|
|
// - als Standard wird das derzeitige Verhalten definiert (ISO-8859-1
|
|
// und die Konvertierung erfolgt ausserhalb)
|
|
// - wenn einmal alle mbConvertEncoding weg sind, kann der Standard auf
|
|
// das gewünschte Verhalten umgestellt werden
|
|
if( empty($someOptions['dbCharset']) ) $someOptions['dbCharset'] = "ISO-8859-1";
|
|
//if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";// das spätere, gewünschte Verhalten
|
|
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "ISO-8859-1";
|
|
|
|
$ret = array();
|
|
$anMysqlConn->query("USE cwsvjudo;");
|
|
$query = sprintf(
|
|
"SELECT ".
|
|
"wkParticipo_Events.id, ".
|
|
"wkParticipo_Events.date, ".
|
|
"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 ".
|
|
"LEFT JOIN wettkampfkalender ".
|
|
"ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ".
|
|
// quickhack; muss noch getestet werden
|
|
// "WHERE wettkampfkalender.Datum IS NULL OR wettkampfkalender.Datum >= CURDATE() ".
|
|
"WHERE wkParticipo_Events.date >= CURDATE() ".
|
|
// "ORDER BY wettkampfkalender.Datum;"
|
|
"ORDER BY wkParticipo_Events.date;"
|
|
);
|
|
// 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 (&$value, $key, $someOptions) {
|
|
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
|
},
|
|
$someOptions
|
|
);
|
|
array_push( $ret, $result);
|
|
}
|
|
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
|
|
///
|
|
/// - Fragt in der Zukunft liegende Wettkämpfe aus dem Wettkampfkalender ab
|
|
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, $someOptions=array() ){
|
|
|
|
// wir befinden uns in der Übergangsphase:
|
|
// - als Standard wird das derzeitige Verhalten definiert (ISO-8859-1
|
|
// und die Konvertierung erfolgt ausserhalb)
|
|
// - wenn einmal alle mbConvertEncoding weg sind, kann der Standard auf
|
|
// das gewünschte Verhalten umgestellt werden
|
|
if( empty($someOptions['dbCharset']) ) $someOptions['dbCharset'] = "ISO-8859-1";
|
|
//if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";// das spätere, gewünschte Verhalten
|
|
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "ISO-8859-1";
|
|
|
|
$ret = array();
|
|
$anMysqlConn->query("USE cwsvjudo;");
|
|
$query = sprintf(
|
|
"SELECT ".
|
|
"wkParticipo_Events.id, ".
|
|
"wkParticipo_Events.wkId, ".
|
|
"wkParticipo_Events.date, ".
|
|
"wkParticipo_Events.meldefrist, ".
|
|
"wkParticipo_Events.bemerkungen, ".
|
|
"wkParticipo_Events.kvOptions, ".
|
|
"wettkampfkalender.lfdeNr, ".
|
|
"wettkampfkalender.Datum, ".
|
|
"wettkampfkalender.Veranstaltung, ".
|
|
"wettkampfkalender.Altersklassen, ".
|
|
"wettkampfkalender.Ort, ".
|
|
"wettkampfkalender.Ausschreibung, ".
|
|
"wettkampfkalender.Routenplaner, ".
|
|
"wkParticipo_Starter.id, ".
|
|
"wkParticipo_Starter.eventId, ".
|
|
"wkParticipo_Starter.type ".
|
|
"FROM wkParticipo_Events ".
|
|
"LEFT JOIN wettkampfkalender ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ".
|
|
"LEFT JOIN wkParticipo_Starter ON wkParticipo_Starter.eventId = wkParticipo_Events.id ".
|
|
"WHERE wkParticipo_Events.date >= CURDATE() AND wkParticipo_Starter.userId = '%s' ".
|
|
// "WHERE wkParticipo_Starter.userId = '%s' ".
|
|
// "ORDER BY wettkampfkalender.Datum;",
|
|
"ORDER BY wkParticipo_Events.date;",
|
|
$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);
|
|
|
|
// Zeichensatzkonvertierung
|
|
foreach($ret as &$entry){
|
|
array_walk(
|
|
$entry,
|
|
function (&$value, $key, $someOptions) {
|
|
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
|
},
|
|
$someOptions
|
|
);
|
|
// @todo: nur temporär: fehlende Wettkampdaten aus den Metadaten ergänzen
|
|
if( empty($entry['wkId']) ){
|
|
$tmpWkEvent = json_decode($entry['bemerkungen'], true);
|
|
// var_dump($tmpWkEvent, $ret['bemerkungen']);
|
|
if(!empty($tmpWkEvent)){
|
|
// var_dump( $tmpWkEvent );
|
|
// var_dump( json_decode($aWkEvent['bemerkungen'], true) );
|
|
$entry['Datum'] = $tmpWkEvent['Datum'];
|
|
$entry['Veranstaltung'] = $tmpWkEvent['Veranstaltung'];
|
|
$entry['Altersklassen'] = $tmpWkEvent['Altersklassen'];
|
|
$entry['bemerkungen'] = $tmpWkEvent['bemerkungen'];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return $ret;
|
|
}
|
|
|
|
function getUsersWkEvents($anMysqlConn, $anUserId){
|
|
$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.lfdeNr, ".
|
|
"wettkampfkalender.Datum, ".
|
|
"wettkampfkalender.Veranstaltung, ".
|
|
"wettkampfkalender.Altersklassen, ".
|
|
"wettkampfkalender.Ort, ".
|
|
"wettkampfkalender.Ausschreibung, ".
|
|
"wettkampfkalender.Routenplaner, ".
|
|
"wkParticipo_Starter.id, ".
|
|
"wkParticipo_Starter.eventId ".
|
|
"FROM wkParticipo_Events ".
|
|
"LEFT JOIN wettkampfkalender ON wettkampfkalender.lfdeNr = wkParticipo_Events.wkId ".
|
|
"LEFT JOIN wkParticipo_Starter ON wkParticipo_Starter.eventId = wkParticipo_Events.id ".
|
|
"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)."<br />";
|
|
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!<br />";
|
|
}
|
|
return $retMessage;
|
|
}
|
|
|
|
function reseteMitfahrer($anMysqlConn, $anEventId){
|
|
$retMmessage = array();
|
|
if( (string)(int)$anEventId != $anEventId ){
|
|
$retMessage['error'] .= "Falsch formatierte eventId (".$anEventId.")<br />";
|
|
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."\"<br />";
|
|
//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."\"<br />";
|
|
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.")<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$event = getWkEventData($anMysqlConn, $anEventId);
|
|
if( empty($event) ){
|
|
$retMessage['error'] .= "eventId ".$anEventId." nicht gefunden<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$user = getUserData($anMysqlConn, $anUserId);
|
|
if( empty($event) ){
|
|
$retMessage['error'] .= "userId ".$anUserId." nicht gefunden<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
if( getUsersMeldeStatus($anMysqlConn, $anEventId, $anUserId) ){
|
|
$retMessage['notice'] .= "userId ".$anUserId." bereits bei eventId ".$anEventId." eingeschrieben<br />";
|
|
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."\"<br />";
|
|
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.")<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$event = getWkEventData($anMysqlConn, $anEventId);
|
|
if( empty($event) ){
|
|
$retMessage['error'] .= "eventId ".$anEventId." nicht gefunden<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$user = getUserData($anMysqlConn, $anUserId);
|
|
if( empty($event) ){
|
|
$retMessage['error'] .= "userId ".$anUserId." nicht gefunden<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
if( getUsersMeldeStatus($anMysqlConn, $anEventId, $anUserId) ){
|
|
$retMessage['notice'] .= "userId ".$anUserId." bereits bei eventId ".$anEventId." eingeschrieben<br />";
|
|
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."\"<br />";
|
|
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.")<br />";
|
|
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']."\"<br />";
|
|
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!<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
if( !empty($starter['fahrtId']) ){
|
|
$retMessage['error'] .= "Der Starter \"".$anStarterId."\" ist bereits in der Fahrt \"".$starterId['fahrtId']."\"<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
if( count($mitfahrerIds) >= (int)$fahrt['plaetze'] ){
|
|
$retMessage['error'] .= "Fahrt \"".$anFahrtId."\" hat keine freien Plätze mehr!<br />";
|
|
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."\"<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$retMessage['success'] .= "Starter '". $starter['id'] . "' zur Fahrt '".$fahrt['id']."' hinzugefügt!<br />";
|
|
|
|
$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."\"<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$retMessage['success'] .= "Fahrt '". $fahrt['id'] . " zum Starter '".$starter['id']."' hinzugefügt!<br />";
|
|
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 .= "<div style=\"border: 1px solid;\">";
|
|
if( !empty($anRetMessage['error']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "ERROR:<br />";
|
|
$retHtmlString .= $anRetMessage['error'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
if( !empty($anRetMessage['warning']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "WARNING:<br />";
|
|
$retHtmlString .= $anRetMessage['warning'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
if( !empty($anRetMessage['notice']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "Info:<br />";
|
|
$retHtmlString .= $anRetMessage['notice'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
if( !empty($anRetMessage['success']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "SUCCESS:<br />";
|
|
$retHtmlString .= $anRetMessage['success'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
// print_r($anRetMessage);
|
|
return $retHtmlString;
|
|
}
|
|
|
|
function updateStarterErgebnis($anMysqlConn, $anStarterId, $anMass, $somePlaces){
|
|
$retMessage = array();
|
|
if( (string)(int)$anStarterId != $anStarterId ){
|
|
$retMessage['error'] .= "Falsch formatierte StarterId (".$anStarterId.")!<br />";
|
|
return $retMessage;
|
|
}
|
|
if( (string)(float)$anMass != $anMass and $anMass != "Offen" and $anMass != "-" ){
|
|
$retMessage['error'] .= "Falsch formatierte Masse (".$anMass.")<br />";
|
|
return $retMessage;
|
|
}
|
|
$plaetze = explode(',', $somePlaces);
|
|
foreach($plaetze as $platz){
|
|
if( (string)(int)$platz != $platz ){
|
|
$message['error'] .= "Falsch formatierte Platzierungen (".$somePlaces.")<br />";
|
|
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."\"<br />";
|
|
return $retMessage;
|
|
}
|
|
|
|
$retMessage['success'] .= "Dem Starter ".$anStarterId." wurde die Masse ".$anMass." und die Platzierung ".$somePlaces." zugeordnet!<br />";
|
|
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 = "";
|
|
|
|
if( empty($aWkEvent['Datum']) )
|
|
$aWkEvent['Datum'] = "0000-00-00";
|
|
$anzPlätze = 0;
|
|
foreach($fahrten as $fahrt)
|
|
$anzPlätze += $fahrt['plaetze'];
|
|
|
|
$anzahlKaempfer = array_count_values(array_column($starters, 'type'))['1'];
|
|
$anzahlZuschauer = array_count_values(array_column($starters, 'type'))['2'];
|
|
|
|
|
|
$heuteDateTime = DateTimeImmutable::createFromFormat("Y-m-d", date("Y-m-d"));
|
|
$einschreibeDateTime = DateTimeImmutable::createFromFormat("Y-m-d", $aWkEvent['meldefrist']);
|
|
|
|
$retHtml =
|
|
"<div class=\"wkInfoCard\">".
|
|
"<time class=\"wkInfoCardDate\" datetime=\"".$aWkEvent['Datum']."\">".
|
|
"<span class=\"wkInfoCardDateWeekday\">".strftime("%a", strtotime($aWkEvent['Datum']))."</span>".
|
|
"<span class=\"wkInfoCardDateDay\">" .strftime("%d", strtotime($aWkEvent['Datum']))."</span>".
|
|
"<span class=\"wkInfoCardDateMonth\">" .utf8_encode(strftime("%b", strtotime($aWkEvent['Datum'])))."</span>".
|
|
"<span class=\"wkInfoCardDateYear\">" .strftime("%Y", strtotime($aWkEvent['Datum']))."</span>".
|
|
"</time>".
|
|
|
|
"<div class=\"wkInfoCardWkData\">".
|
|
"<div class=\"wkInfoCardWkInfo\">".
|
|
"<h3 class=\"fontWeightLighter\" >".$aWkEvent['Veranstaltung']."</h4>".
|
|
"<dl>".
|
|
"<dt>Altersklassen</dt><dd>".$aWkEvent['Altersklassen']."</dd>".
|
|
"<dt>Einschreibefrist</dt><dd>".(
|
|
empty($aWkEvent['meldefrist'])?
|
|
"fehlende Einschreibefrist"
|
|
:"<time datetime=\"" . $aWkEvent['meldefrist'] . "\">" . $aWkEvent['meldefrist'] . "</time>".
|
|
"<div class=\"wkInfoCardButtonBar flexFlowRow justifyContentFlexStart\">".
|
|
"<a class=\"wkInfoCardButton wkInfoCardButtonSuccess wkInfoCardButtonRaised\" href =\"" . addToGcalUrl( "Einschreibefrist " . $aWkEvent['Veranstaltung'], $aWkEvent['meldefrist'] ) . "\" >In Google Calendar übernehmen</a>".
|
|
"</div>"
|
|
)."</dd>".
|
|
(!empty($_SESSION['login'])?
|
|
"<dt>eingeschriebene Starter</dt><dd>".(
|
|
( $anzahlKaempfer == 0 )?
|
|
"Noch hat sich niemand für diesen Wettkampf eingeschrieben!":
|
|
$anzahlKaempfer
|
|
)."</dd>"
|
|
:"").
|
|
(!empty($_SESSION['login'])?
|
|
"<dt>eingeschriebene Zuschauer</dt><dd>".(
|
|
( $anzahlZuschauer == 0 )?
|
|
"Noch will sich niemand diesen Wettkampf anschauen!":
|
|
$anzahlZuschauer
|
|
)."</dd>"
|
|
:"").
|
|
(empty($_SESSION['login'])?
|
|
"<dd>Ein Einschreiben ist nur eingeloggt möglich!</dd>"
|
|
:"<dd><form action=\"./addStarter.php\" method=\"post\">".
|
|
"<input type=\"hidden\" name=\"f[eventId]\" value=".
|
|
( isset( $aWkEvent['id'] ) ? $aWkEvent['id'] : "").
|
|
" />".
|
|
( $heuteDateTime->modify( "+ 4 weeks") < $einschreibeDateTime?
|
|
"<button type=\"submit\" disabled>Es ist noch zu früh jemanden einzuschreiben (ab ".$einschreibeDateTime->modify( "- 4 weeks")->format("Y-m-d").")!</button>"
|
|
:( date("Y-m-d") > $aWkEvent['meldefrist']?
|
|
"<button type=\"submit\" disabled>ist die Einschreibefrist bereits abgelaufen!</button>".
|
|
"<p>Frist für das Einschreiben verpasst? Für ein nachträgliches Einschreiben mit dem Admin verständigen (<a href=\"mailto:cwsvjudo@arcor.de?Subject=" . ( rawurlencode("Meldefrist ".$aWkEvent['Veranstaltung']) ) . "\" target=\"_top\">Email an cwsvjudo@arcor.de</a>).</p>"
|
|
:"<button type=\"submit\">jmd. einschreiben</button>"
|
|
)
|
|
).
|
|
"</form></dd>"
|
|
).
|
|
"<dt" . ( ($anzPlätze<($anzKaempfer+$anzZuschauer)) ? " style=\"color: red\"" : "" ) . ">Anzahl Mitfahrgelegenheiten</dt><dd>" . $anzPlätze . "</dd>".
|
|
(empty($_SESSION['login'])?
|
|
"<dd>Das Anbieten von Mitfahrgelegenheiten ist nur eingeloggt möglich!</dd>"
|
|
:"<dd><form action=\"./addFahrt.php\" method=\"post\">".
|
|
"<input type=\"hidden\" name=\"f[eventId]\" value=\"" . ( isset( $aWkEvent['id'] ) ? $aWkEvent['id'] : "" ) . "\" />".
|
|
($aWkEvent['Datum'] > date("Y-m-d")?
|
|
"<button type=\"submit\">Mitfahr­gelegenheit anbieten</button>"
|
|
:"<button type=\"submit\" disabled>ist es leider zu spät, noch Mitfahrgelegenheiten hinzuzufügen.</button>"
|
|
).
|
|
"</form></dd>"
|
|
).
|
|
( !empty( $aWkEvent['bemerkungen'] )?
|
|
"<dt>Bemerkungen</dt><dd>" . $aWkEvent['bemerkungen'] . "</dd>"
|
|
:"").
|
|
"</dl>".
|
|
"</div>".
|
|
|
|
"<div class=\"wkInfoCardButtonBar\">".
|
|
"<a href =\"./showWkEvent.php?eventId=".$aWkEvent['id']."\" class=\"wkInfoCardButton wkInfoCardButtonSuccess wkInfoCardButtonRaised\">Detailansicht</a>".
|
|
"<a href =\"/ressourcen/phpLib/calendar.php?wkID=".$aWkEvent['wkId']."\" class=\"wkInfoCardButton wkInfoCardButtonSuccess wkInfoCardButtonRaised\">Termin als iCal</a>".
|
|
"<a href =\"".addToGcalUrl( $aWkEvent['Veranstaltung'], $aWkEvent['Datum'] )."\" class=\"wkInfoCardButton wkInfoCardButtonSuccess wkInfoCardButtonRaised\">In den Google Calendar</a>".
|
|
"</div>".
|
|
"</div>".
|
|
"</div>";
|
|
|
|
return $retHtml;
|
|
}
|
|
|
|
|
|
?>
|