First Version
This commit is contained in:
6
homepage/mams/.htaccess
Normal file
6
homepage/mams/.htaccess
Normal file
@@ -0,0 +1,6 @@
|
||||
AuthType Basic
|
||||
AuthName "tempDirectory"
|
||||
AuthUserFile /users/cwsvjudo/www/.htusers
|
||||
#AuthGroupFile /users/cwsvjudo/www/.htgroups
|
||||
Require user marko
|
||||
#Require group admin
|
||||
64
homepage/mams/index.php
Normal file
64
homepage/mams/index.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once("./local/cwsvJudo.config.php");
|
||||
require_once("./lib/db.php");
|
||||
|
||||
$dbConnection = getPdoDbConnection(
|
||||
$cwsvJudoConfig["db"]["host"],
|
||||
$cwsvJudoConfig["db"]["name"],
|
||||
$cwsvJudoConfig["db"]["user"],
|
||||
$cwsvJudoConfig["db"]["password"]
|
||||
);
|
||||
|
||||
$judokas = getJudokasInTraining($dbConnection, "inTraining");
|
||||
|
||||
$lastAttendances = getLastAttendances($dbConnection);
|
||||
$lastAttendancesAssocArray = array();
|
||||
foreach($lastAttendances as $a){
|
||||
if(!isset($lastAttendances[$a['date']]))
|
||||
$lastAttendancesAssocArray[$a['date']] = array();
|
||||
$lastAttendancesAssocArray[$a['date']][] = array( $a );
|
||||
}
|
||||
|
||||
if($_POST['action']){
|
||||
giveJudokasAttendence($dbConnection, $_POST['attandanceDate'], $_POST['judokaIdsInTraining']);
|
||||
}
|
||||
|
||||
$dateLastWendsday = new DateTime("last wednesday");
|
||||
$dateLastFriday = new DateTime("last friday");
|
||||
$lastTrainingDay = min($dateLastWendsday, $dateLastFriday);
|
||||
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<form action="./index.php" method="POST">
|
||||
<input id="giveAttendanceAction" name="action" value="giveAttendance" type="hidden" />
|
||||
<input id="attendenceDate" name="attandanceDate" value="<?php echo($lastTrainingDay->format("Y-m-d"));?>" />
|
||||
<select name="judokaIdsInTraining[]" id="judokaIdsInTraining" multiple>
|
||||
<?php foreach($judokas as $j) echo("<option value=\"".$j['userId']."\">".$j['vorname']." ".$j['name']."</option>");?>
|
||||
</select>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<?php foreach($lastAttendancesAssocArray as $date => $attendees);{
|
||||
echo("<h2>".$date."</h2>");
|
||||
echo("<table>");
|
||||
echo("<tr>");
|
||||
echo("<th>name</th>");
|
||||
echo("<th>vorname</th>");
|
||||
echo("<th>PLZ</th>");
|
||||
echo("<th>Telefon</th>");
|
||||
echo("<th>eMail</th>");
|
||||
echo("</tr>");
|
||||
foreach($attendees as $a){
|
||||
echo("<tr>");
|
||||
echo("<td>".$a[0]['name']."</td>");
|
||||
echo("<td>".$a[0]['vorname']."</td>");
|
||||
echo("<td>".$a[0]['corona_PLZ']."</td>");
|
||||
echo("<td>".$a[0]['corona_telephon']."</td>");
|
||||
echo("<td>".$a[0]['corona_eMail']."</td>");
|
||||
echo("</tr>");
|
||||
}
|
||||
echo("</table>");
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
126
homepage/mams/lib/db.php
Normal file
126
homepage/mams/lib/db.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
// get a Connection to the database
|
||||
function getPdoDbConnection($hostname, $dbName, $user, $password){
|
||||
try{
|
||||
$dbConnection = new PDO(
|
||||
'mysql:host='.$hostname.';dbname='.$dbName,
|
||||
$user,
|
||||
$password
|
||||
);
|
||||
}
|
||||
catch(PDOException $dbError){
|
||||
echo( "Error whilst getting a dbConnection!: " . $dbError->getMessage() );
|
||||
}
|
||||
return $dbConnection;
|
||||
}
|
||||
|
||||
function createDb($dbConnection){
|
||||
<<<SQL
|
||||
CREATE TABLE `cwsvjudo`.`anwesenheit` (
|
||||
`id` INT UNSIGNED NOT NULL ,
|
||||
`userId` INT UNSIGNED NOT NULL ,
|
||||
`date` DATE NOT NULL DEFAULT CURRENT_TIMESTAMP ,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB;
|
||||
ALTER TABLE `cwsvjudo`.`anwesenheit` ADD UNIQUE `attandence` (`userId`, `id`);
|
||||
SQL;
|
||||
}
|
||||
|
||||
/// perform a pdo-query
|
||||
///
|
||||
/// @param aDbConnection
|
||||
/// @param $aQueryString
|
||||
/// @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
|
||||
function dbQuery($aDbConnection, $aQueryString, $aBindArray = array(), $someOptions = array()){
|
||||
// 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 m Wettkampfplaner sind ja z.B.
|
||||
/// als UTF8 in latin1(?) gespeichert.
|
||||
/// @toDo: Die Standardwerte sollten vielleicht aus einer config
|
||||
/// kommen, nicht hardcoded
|
||||
try{
|
||||
$pdoStatement = $aDbConnection->prepare( $aQueryString );
|
||||
foreach( $aBindArray as $bindName => $bind ){
|
||||
$pdoStatement->bindValue(
|
||||
$bindName,
|
||||
$bind['value'],
|
||||
(isset($bind['data_type'])?$bind['data_type']:PDO::PARAM_STR)
|
||||
);
|
||||
}
|
||||
$pdoResult = $pdoStatement->execute();
|
||||
|
||||
//if(!$pdoResult)
|
||||
//echo("Strange! \"".$aQueryString."\" failed without exception!");
|
||||
|
||||
if($someOptions['dontFetch']){
|
||||
$ret = NULL;
|
||||
}
|
||||
else{
|
||||
$ret = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
catch(PDOException $db_error){
|
||||
print "Error!: " . $db_error->getMessage() . "<br/>";
|
||||
return null;
|
||||
}
|
||||
// Zeichensatzkonvertierung
|
||||
if( is_array($ret) ){
|
||||
foreach($ret as &$entry){
|
||||
array_walk(
|
||||
$entry,
|
||||
function (&$value, $key, $someOptions) {
|
||||
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
||||
},
|
||||
$someOptions
|
||||
);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getLastAttendances($db){
|
||||
$query = <<<SQL
|
||||
SELECT date, vorname, name, corona_PLZ, corona_telephon, corona_eMail
|
||||
FROM `cwsvjudo`.`anwesenheit`
|
||||
JOIN `cwsvjudo`.`wkParticipo_Users`
|
||||
ON `cwsvjudo`.`anwesenheit`.`userId` = `cwsvjudo`.`wkParticipo_Users`.`id`
|
||||
ORDER BY `date` DESC, `name`;
|
||||
SQL;
|
||||
$params = array();
|
||||
$options = array();
|
||||
$ret = dbQuery($db, $query, $params, $options);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getJudokasInTraining($dbConnection, $attributeName){
|
||||
$query = <<<SQL
|
||||
SELECT userId, name, vorname
|
||||
FROM `cwsvjudo`.`wkParticipo_Users`
|
||||
JOIN `cwsvjudo`.`wkParticipo_user<=>userAttributes`
|
||||
ON `cwsvjudo`.`wkParticipo_Users`.`id` =`cwsvjudo`.`wkParticipo_user<=>userAttributes`.`userId`
|
||||
WHERE `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`attributeId` IN (
|
||||
SELECT `id` FROM `cwsvjudo`.`wkParticipo_userAttributes` WHERE `name` = :attributeName
|
||||
);
|
||||
SQL;
|
||||
$params = array(
|
||||
':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR)
|
||||
);
|
||||
return dbQuery($dbConnection, $query, $params);
|
||||
}
|
||||
|
||||
function giveJudokasAttendence($dbConnection, $date, $ids){
|
||||
$values = array();
|
||||
foreach( $ids as $id){
|
||||
array_push( $values, "(\"".$date."\", ".$id.")");;
|
||||
}
|
||||
$query = "INSERT INTO `cwsvjudo`.`anwesenheit` (`date`, `userId`) VALUES ".join(",", $values).";";
|
||||
dbQuery($dbConnection, $query, array(), ['dontFetch' => true]);
|
||||
}
|
||||
?>
|
||||
6
homepage/mams/local/cwsvJudo.config.php
Normal file
6
homepage/mams/local/cwsvJudo.config.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$cwsvJudoConfig["db"]["host"] = "localhost";
|
||||
$cwsvJudoConfig["db"]["name"] = "cwsvjudo";
|
||||
$cwsvJudoConfig["db"]["user"] = "cwsvjudo";
|
||||
$cwsvJudoConfig["db"]["password"] = "***REMOVED***";
|
||||
?>
|
||||
Reference in New Issue
Block a user