Error checking addCoronaUser, some modularization
This commit is contained in:
@@ -1,74 +1,48 @@
|
||||
<?php
|
||||
require_once("./local/cwsvJudo.config.php");
|
||||
require_once("./lib/db.php");
|
||||
require_once("./lib/api.php");
|
||||
require_once("./local/cwsvJudo.config.php");
|
||||
require_once("./lib/db.php");
|
||||
require_once("./lib/api.php");
|
||||
|
||||
$dbConnection = getPdoDbConnection(
|
||||
$cwsvJudoConfig["db"]["host"],
|
||||
$cwsvJudoConfig["db"]["name"],
|
||||
$cwsvJudoConfig["db"]["user"],
|
||||
$cwsvJudoConfig["db"]["password"]
|
||||
);
|
||||
$dbConnection = getPdoDbConnection(
|
||||
$cwsvJudoConfig["db"]["host"],
|
||||
$cwsvJudoConfig["db"]["name"],
|
||||
$cwsvJudoConfig["db"]["user"],
|
||||
$cwsvJudoConfig["db"]["password"]
|
||||
);
|
||||
|
||||
processPostData($dbConnection, $_POST);
|
||||
processPostData($dbConnection, $_POST);
|
||||
|
||||
$judokas = getUsersWithAttribute($dbConnection, "inTraining");
|
||||
$judokas = getUsersWithAttribute($dbConnection, "inTraining");
|
||||
|
||||
$lastAttendances = getLastAttendances($dbConnection);
|
||||
$lastAttendancesAssocArray = array();
|
||||
foreach($lastAttendances as $a){
|
||||
if(!array_key_exists( $a['date'], $lastAttendancesAssocArray)){
|
||||
$lastAttendancesAssocArray[$a['date']] = array();
|
||||
$lastAttendances = getLastAttendances($dbConnection);
|
||||
$lastAttendancesAssocArray = array();
|
||||
foreach($lastAttendances as $a){
|
||||
if(!array_key_exists( $a['date'], $lastAttendancesAssocArray)){
|
||||
$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>
|
||||
<header>
|
||||
<!-- Compiled and minified 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 -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/@materializecss/materialize@1.1.0-alpha/dist/js/materialize.min.js"></script>
|
||||
|
||||
<!-- Inits for materializecss-->
|
||||
<script>
|
||||
options={};
|
||||
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>
|
||||
<!-- Compiled and minified 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 -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/@materializecss/materialize@1.1.0-alpha/dist/js/materialize.min.js"></script>
|
||||
<!-- Inits for materializecss-->
|
||||
<?php include_once("lib/mams/materializeInit.php");?>
|
||||
<!--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>
|
||||
<!-- sidenav for mams-->
|
||||
<?php include_once("lib/mams/sidenav.php");?>
|
||||
<h2 id="addAttendences">Anwesenheiten hinzufügen</h2>
|
||||
|
||||
<form action="./index.php" method="POST">
|
||||
@@ -97,7 +71,7 @@ $lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
||||
<input placeholder="Name" name="name" type="text" />
|
||||
<input placeholder="Vorname" name="vorname" 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 type="submit" value="Neuen Corona-User eintragen" />
|
||||
</form>
|
||||
|
||||
@@ -10,12 +10,16 @@ function processPostData($db, $post, $redirectLocation = "."){
|
||||
}
|
||||
if($post['action'] == "addCoronaUser"){
|
||||
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['vorname'], "name")
|
||||
// && isValid($post['corona_telephon'], "phonenumber")
|
||||
// && isValid($post['corona_eMail'], "email")
|
||||
){
|
||||
){
|
||||
addCoronaUser(
|
||||
$db,
|
||||
$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!
|
||||
// $regexName="/^[A-Z][a-zA-Z]*$/";
|
||||
$regexPlz ="/^[0-9]{5}$/";
|
||||
if($type == "plz" )
|
||||
return preg_match($regexPlz, $toValidate) > 0;
|
||||
if($type == "name")
|
||||
return preg_match($regexName, $toValidate) > 0;
|
||||
if($type == "phonenumber" )
|
||||
return validate_phone_number($toValidate);
|
||||
if($type == "email")
|
||||
return filter_var($toValidate, FILTER_VALIDATE_EMAIL);
|
||||
|
||||
switch( $type ){
|
||||
case "plz":
|
||||
return preg_match($regexPlz, $toValidate) > 0;
|
||||
case "phonenumber":
|
||||
return validate_phone_number($toValidate);
|
||||
case "email":
|
||||
return filter_var($toValidate, FILTER_VALIDATE_EMAIL);
|
||||
default:
|
||||
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