Error checking addCoronaUser, some modularization
This commit is contained in:
@@ -1,74 +1,48 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once("./local/cwsvJudo.config.php");
|
require_once("./local/cwsvJudo.config.php");
|
||||||
require_once("./lib/db.php");
|
require_once("./lib/db.php");
|
||||||
require_once("./lib/api.php");
|
require_once("./lib/api.php");
|
||||||
|
|
||||||
$dbConnection = getPdoDbConnection(
|
$dbConnection = getPdoDbConnection(
|
||||||
$cwsvJudoConfig["db"]["host"],
|
$cwsvJudoConfig["db"]["host"],
|
||||||
$cwsvJudoConfig["db"]["name"],
|
$cwsvJudoConfig["db"]["name"],
|
||||||
$cwsvJudoConfig["db"]["user"],
|
$cwsvJudoConfig["db"]["user"],
|
||||||
$cwsvJudoConfig["db"]["password"]
|
$cwsvJudoConfig["db"]["password"]
|
||||||
);
|
);
|
||||||
|
|
||||||
processPostData($dbConnection, $_POST);
|
processPostData($dbConnection, $_POST);
|
||||||
|
|
||||||
$judokas = getUsersWithAttribute($dbConnection, "inTraining");
|
$judokas = getUsersWithAttribute($dbConnection, "inTraining");
|
||||||
|
|
||||||
$lastAttendances = getLastAttendances($dbConnection);
|
$lastAttendances = getLastAttendances($dbConnection);
|
||||||
$lastAttendancesAssocArray = array();
|
$lastAttendancesAssocArray = array();
|
||||||
foreach($lastAttendances as $a){
|
foreach($lastAttendances as $a){
|
||||||
if(!array_key_exists( $a['date'], $lastAttendancesAssocArray)){
|
if(!array_key_exists( $a['date'], $lastAttendancesAssocArray)){
|
||||||
$lastAttendancesAssocArray[$a['date']] = array();
|
$lastAttendancesAssocArray[$a['date']] = array();
|
||||||
|
}
|
||||||
|
array_push( $lastAttendancesAssocArray[ $a['date'] ], $a );
|
||||||
}
|
}
|
||||||
array_push( $lastAttendancesAssocArray[ $a['date'] ], $a );
|
|
||||||
}
|
|
||||||
|
|
||||||
$dateLastWendsday = new DateTime("tomorrow last wednesday");
|
|
||||||
$dateLastFriday = new DateTime("tomorrow last friday");
|
|
||||||
$lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
|
||||||
|
|
||||||
|
$dateLastWendsday = new DateTime("tomorrow last wednesday");
|
||||||
|
$dateLastFriday = new DateTime("tomorrow last friday");
|
||||||
|
$lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<header>
|
<header>
|
||||||
<!-- Compiled and minified CSS -->
|
<!-- Compiled and minified CSS -->
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@materializecss/materialize@1.1.0-alpha/dist/css/materialize.min.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@materializecss/materialize@1.1.0-alpha/dist/css/materialize.min.css">
|
||||||
<!-- Compiled and minified JavaScript -->
|
<!-- Compiled and minified JavaScript -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@materializecss/materialize@1.1.0-alpha/dist/js/materialize.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@materializecss/materialize@1.1.0-alpha/dist/js/materialize.min.js"></script>
|
||||||
|
<!-- Inits for materializecss-->
|
||||||
<!-- Inits for materializecss-->
|
<?php include_once("lib/mams/materializeInit.php");?>
|
||||||
<script>
|
<!--Let browser know website is optimized for mobile-->
|
||||||
options={};
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
var elems = document.querySelectorAll('select');
|
|
||||||
var instances = M.FormSelect.init(elems);
|
|
||||||
});
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
var elems = document.querySelectorAll('.modal');
|
|
||||||
var instances = M.Modal.init(elems, options);
|
|
||||||
});
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
var elems = document.querySelectorAll('.sidenav');
|
|
||||||
var instances = M.Sidenav.init(elems, options);
|
|
||||||
});
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
var elems = document.querySelectorAll('.collapsible');
|
|
||||||
var instances = M.Collapsible.init(elems, options);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!--Let browser know website is optimized for mobile-->
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
||||||
|
|
||||||
<title>Corona-Anwesenheitsliste der Judoka des Chemnitzer WSV</title>
|
|
||||||
</header>
|
|
||||||
<body>
|
|
||||||
<ul id="slide-out" class="sidenav">
|
|
||||||
<li><a href="#addAttendences">Anwesenheiten hinzufügen</a></li>
|
|
||||||
<li><a href="#addCoronaUser">Trainee hinzufügen</a></li>
|
|
||||||
<li><a href="#showAttendences">Anwesenheiten anzeigen</a></li>
|
|
||||||
</ul>
|
|
||||||
<a href="#" data-target="slide-out" class="sidenav-trigger" style="font-size: 2em;">☰ mams</a>
|
|
||||||
|
|
||||||
|
<title>Corona-Anwesenheitsliste der Judoka des Chemnitzer WSV</title>
|
||||||
|
</header>
|
||||||
|
<body>
|
||||||
|
<!-- sidenav for mams-->
|
||||||
|
<?php include_once("lib/mams/sidenav.php");?>
|
||||||
<h2 id="addAttendences">Anwesenheiten hinzufügen</h2>
|
<h2 id="addAttendences">Anwesenheiten hinzufügen</h2>
|
||||||
|
|
||||||
<form action="./index.php" method="POST">
|
<form action="./index.php" method="POST">
|
||||||
@@ -97,7 +71,7 @@ $lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
|||||||
<input placeholder="Name" name="name" type="text" />
|
<input placeholder="Name" name="name" type="text" />
|
||||||
<input placeholder="Vorname" name="vorname" type="text" />
|
<input placeholder="Vorname" name="vorname" type="text" />
|
||||||
<input placeholder="PLZ" name="corona_PLZ" type ="text" />
|
<input placeholder="PLZ" name="corona_PLZ" type ="text" />
|
||||||
<input placeholder="Telefon" name="corona_telephon" type="text" />
|
<input placeholder="Telefon" name="corona_telephon" type="tel" />
|
||||||
<input placeholder="eMail" name="corona_eMail" type="text" />
|
<input placeholder="eMail" name="corona_eMail" type="text" />
|
||||||
<input type="submit" value="Neuen Corona-User eintragen" />
|
<input type="submit" value="Neuen Corona-User eintragen" />
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -10,12 +10,16 @@ function processPostData($db, $post, $redirectLocation = "."){
|
|||||||
}
|
}
|
||||||
if($post['action'] == "addCoronaUser"){
|
if($post['action'] == "addCoronaUser"){
|
||||||
if(
|
if(
|
||||||
isValid($post['corona_PLZ'], "plz")
|
array_keys_exist(
|
||||||
|
$post,
|
||||||
|
['name', 'vorname', 'corona_PLZ', 'corona_telephon', 'corona_eMail']
|
||||||
|
)
|
||||||
|
&& isValid($post['corona_PLZ'], "plz")
|
||||||
|
&& isValid($post['corona_telephon'], "phonenumber")
|
||||||
|
&& isValid($post['corona_eMail'], "email")
|
||||||
// && isValid($post['name'], "name")
|
// && isValid($post['name'], "name")
|
||||||
// && isValid($post['vorname'], "name")
|
// && isValid($post['vorname'], "name")
|
||||||
// && isValid($post['corona_telephon'], "phonenumber")
|
){
|
||||||
// && isValid($post['corona_eMail'], "email")
|
|
||||||
){
|
|
||||||
addCoronaUser(
|
addCoronaUser(
|
||||||
$db,
|
$db,
|
||||||
$post['name'],
|
$post['name'],
|
||||||
@@ -114,15 +118,37 @@ function isValid($toValidate, $type){
|
|||||||
// for now we disable the name validation: what do i know how people can be called!
|
// for now we disable the name validation: what do i know how people can be called!
|
||||||
// $regexName="/^[A-Z][a-zA-Z]*$/";
|
// $regexName="/^[A-Z][a-zA-Z]*$/";
|
||||||
$regexPlz ="/^[0-9]{5}$/";
|
$regexPlz ="/^[0-9]{5}$/";
|
||||||
if($type == "plz" )
|
switch( $type ){
|
||||||
return preg_match($regexPlz, $toValidate) > 0;
|
case "plz":
|
||||||
if($type == "name")
|
return preg_match($regexPlz, $toValidate) > 0;
|
||||||
return preg_match($regexName, $toValidate) > 0;
|
case "phonenumber":
|
||||||
if($type == "phonenumber" )
|
return validate_phone_number($toValidate);
|
||||||
return validate_phone_number($toValidate);
|
case "email":
|
||||||
if($type == "email")
|
return filter_var($toValidate, FILTER_VALIDATE_EMAIL);
|
||||||
return filter_var($toValidate, FILTER_VALIDATE_EMAIL);
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Checks if multiple keys exist in an array
|
||||||
|
//!
|
||||||
|
//! @param array $array array to check for key
|
||||||
|
//! @param array|string $keys keys to check for
|
||||||
|
//!
|
||||||
|
//! @return bool true, if *all* keys are set in the array
|
||||||
|
function array_keys_exist( array $array, $keys ) {
|
||||||
|
if ( ! is_array( $keys ) ) {
|
||||||
|
$keys = func_get_args();
|
||||||
|
array_shift( $keys );
|
||||||
|
}
|
||||||
|
$count = 0;
|
||||||
|
foreach ( $keys as $key ) {
|
||||||
|
if ( isset( $array[$key] ) || array_key_exists( $key, $array ) ) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count( $keys ) === $count;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
11
homepage/mams/lib/mams/materializeInit.php
Normal file
11
homepage/mams/lib/mams/materializeInit.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
options={};
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
var elems = document.querySelectorAll('select');
|
||||||
|
var instances = M.FormSelect.init(elems);
|
||||||
|
});
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
var sideNavElems = document.querySelectorAll('.sidenav');
|
||||||
|
var sideNavInstances = M.Sidenav.init(sideNavElems, options);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
6
homepage/mams/lib/mams/sidenav.php
Normal file
6
homepage/mams/lib/mams/sidenav.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<ul id="slide-out" class="sidenav">
|
||||||
|
<li><a href="#addAttendences" class="sidenav-close">Anwesenheiten hinzufügen</a></li>
|
||||||
|
<li><a href="#addCoronaUser" class="sidenav-close">Trainee hinzufügen</a></li>
|
||||||
|
<li><a href="#showAttendences" class="sidenav-close">Anwesenheiten anzeigen</a></li>
|
||||||
|
</ul>
|
||||||
|
<a href="#" data-target="slide-out" class="sidenav-trigger" style="font-size: 2em;">☰ mams</a>
|
||||||
Reference in New Issue
Block a user