Files
cwsvJudo/homepage/wkParticipo/addStarter.php

185 lines
7.4 KiB
PHP

<?php
require_once('./local/db.php.inc');
require_once('./local/wkParticipoConf.php.inc');
require_once('./auth.php');
require_once('./lib/wkParticipoLib.inc.php');
$message = array();
// $meldungsBox = array();
$meldungsBox = "";
if( empty($_POST) ){
$message['error'] .= "Weder userId noch eventId übergeben!";
}
else{
if( !isset($_POST['f']['eventId']) ){
$message['error'] .= "Fehlende eventId (".$_POST['f']['eventId'].") (POST: ".var_export($_POST, true).")<br />";
}
else{
$mysqlConn = @new mysqli($db_server, $db_user, $db_password, $db_name);
if ($mysqlConn->connect_error) {
$message['error'] .= "Datenbankverbindung fehlgeschlagen: ".$mysqlConn->connect_error."<br /";
}
else{
$wkEventData = getWkEventData($mysqlConn, $_POST['f']['eventId']);
if( date("Y-m-d") > $wkEventData['meldefrist']){
$message['error'] .= "Die Meldefrist ist bereits abgelaufen!<br />";
}
else{
// Wenn keine userId übergeben wird, biete alle Kinder an
// Wenn die Art des Startes nicht mit angegeben ist, auch nachfragen
if( !isset($_POST['f']['userId']) || !isset($_POST['f']['type'])){
$kinderDaten = getUsersKidsData($mysqlConn, $_SESSION['user']['userId']);
//print_r($kinderDaten);
foreach($kinderDaten as $kind){
$meldungsBox .= "<div id=\"meldungsBox\">Meldung<ul>";
$meldungsBox .= "<li>F&uuml;r Starter: ".mb_convert_encoding($kind['name'], 'UTF-8', 'ISO-8859-1').", ".mb_convert_encoding($kind['vorname'], 'UTF-8', 'ISO-8859-1')."</li></ul>";
$meldungsBox .= "<form action=\"./addStarter.php\" method=\"post\">";
$meldungsBox .= "<input type=\"hidden\" name=\"f[eventId]\" id=\"eventId\" ".(isset($_POST['f']['eventId']) ? " value=\"" . htmlspecialchars($_POST['f']['eventId']) . "\"" : "") ." />";
$meldungsBox .= "<input type=\"hidden\" name=\"f[userId]\" id=\"userId\" " .(isset($kind['id']) ? " value=\"".htmlspecialchars($kind['id'])."\"" : "")."/>";
$meldungsBox .= "<select name=\"f[type]\"><option value=\"1\" selected>als Starter</option><option value=\"2\">als Zuschauer</option><option value=\"3\">keine Teilnahme</option></select>";
if( getUsersMeldeStatus($mysqlConn, $_POST['f']['eventId'], $kind['id']) ){
$meldungsBox .= "<div>Bereits gemeldet</div>";
}
else{
if( date("Y-m-d") > $wkEventData['meldefrist']){
$meldungsBox .= "<div>Die Meldefrist ist bereits abgelaufen!</div>";
}
else{
$meldungsBox .= "<button type=\"submit\" name=\"submit\">Melden</button>";
}
}
$meldungsBox .= "</form></div><hr />";
}
}
else{
// @todo hier müsste das Auslösen der Meldung
$userData = getUserData($mysqlConn, $_SESSION['user']['userId']);
$starterData = getUserData($mysqlConn, $_POST['f']['userId']);
// $wkData = getWkData($mysqlConn, $eventData['wkId']);
if(
!in_array(
$_POST['f']['userId'],
explode(',', getUserData($mysqlConn, $_SESSION['user']['userId'])['kinder'])
)
){
$message['error'] .= "Es fehlt die Berechtigung diesen Starter zu melden!<br />";
}
else{
$message = createStarterForEvent($mysqlConn, $_POST['f']['eventId'], $_POST['f']['userId'], $_POST['f']['type']);
if( isset($message['success']) ){
$notificationMail['to'] = $userData['eMail'];
$notificationMail['subject'] = "=?UTF-8?B?".base64_encode("Meldebestätigung")."?=";
$notificationMail['message'] = mb_convert_encoding($starterData['name'], 'UTF-8', 'ISO-8859-1') . ", " . mb_convert_encoding($starterData['vorname'], 'UTF-8', 'ISO-8859-1') . " zum Wettkampf " . mb_convert_encoding($wkEventData['Veranstaltung'], 'UTF-8', 'ISO-8859-1') . " gemeldet. Diese Mail wurde automatisch vom Wettkampfplaner bei der Meldung versandt.";
$notificationMail['headers'] = "From: noreply.wettkampflaner@cwsvjudo.bplaced.net\r\n".
"Reply-To: cwsvjudo@arcor.de\r\n".
"X-Mailer: PHP/".phpversion()."\r\n".
"Content-Type: text/plain; charset=UTF-8";
if(!empty($notificationMail['to'])){
mail ( $notificationMail['to'] , $notificationMail['subject'] , $notificationMail['message'], $notificationMail['headers'] );
}
$notificationMail['to'] = $wkParticipoConf['adminEmail'];
if(!empty($notificationMail['to'])){
mail ( $notificationMail['to'] , $notificationMail['subject'] , $notificationMail['message'], $notificationMail['headers'] );
}
}
}
}
}
}
$mysqlConn->close();
}
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Wettkampfplaner - Meldung</title>
<style>
<?php
$css = file_get_contents( $basePath."/pages/desktop/wkParticipo/wkParticipo.css");
echo(colorThemeCss($_SESSION['user']['userConfig']['colors']));
echo($css);
?>
</style>
</head>
<body>
<?php echo $login_status; ?>
<hr />
<?php
if( isset($message['success']) ){
?>
<?php echo $userData['name'].", ".$userData['vorname'];?> zum Wettkampf <?php echo mb_convert_encoding($wkEventData['Veranstaltung'], 'UTF-8', 'ISO-8859-1');?> gemeldet!<br />
<?php
}
else{
echo htmlRetMessage($message);
}
?>
<h1><?php echo(mb_convert_encoding($wkEventData['Veranstaltung'], 'UTF-8', 'ISO-8859-1'))?></h1>
<?php if( !empty($meldungsBox) ) echo($meldungsBox);?>
<nav>
<ul>
<li>
<a href="./index.php">
<div>zur Übersicht zurück</div>
</a>
</li>
<?php
if( isset($message['success']) ){
?>
<li>
<a href="./showWkEvent.php?eventId=<?php echo $wkEventData['id'];?>">
<div>
<?php echo "Detailansicht ".mb_convert_encoding($wkEventData['Veranstaltung'], 'UTF-8', 'ISO-8859-1');?>
</div>
</a>
</li>
<?php
}
?>
</ul>
</nav>
<!--
<div style="border: solid black"><?php echo var_export($wkEventData, true);?></div>
<div style="border: solid black"><?php echo var_export($userData, true);?></div>
<div style="border: solid black"><?php echo var_export($_SESSION, true);?></div>
<div style="border: solid black"><?php echo var_export($_POST, true);?></div>
<div id="meldungsBox">
Manuelle Meldung
<ul>
<li>F&uuml;r Wettkampf: <?php echo isset($wkEventData['Veranstaltung']) ? mb_convert_encoding($wkEventData['Veranstaltung'], 'UTF-8', 'ISO-8859-1') : "<fehlende Wettkampfdaten>" ?></li>
<li>F&uuml;r Starter: <?php echo isset($userData['vorname']) ? mb_convert_encoding($userData['vorname'], 'UTF-8', 'ISO-8859-1') : "<fehlender Vorname>" ?></li>
</ul>
<form action="./addStarterDev.php" method="post">
<fieldset>
<legend>Meldungsdaten</legend>
<div>
<label for="eventId">eventId</label>
<input type="text" name="f[eventId]" id="eventId" <?php echo isset($_POST['f']['eventId']) ? "value=\"".htmlspecialchars($_POST['f']['eventId'])."\"" : "" ?> />
</div>
<div>
<label for="userId">userId</label>
<input type="<?php echo isset($_POST['f']['userId']) ? "disabled" : "text" ?>" name="f[userId]" id="userId" <?php echo isset($_POST['f']['userId']) ? "value=\"".htmlspecialchars($_POST['f']['userId'])."\"" : "" ?> />
</div>
</fieldset>
<fieldset>
<div><button type="submit" name="submit" value="Meldung">Meldung</button></div>
</fieldset>
</form>
</div>
-->
</body>
</html>