Compare commits

..

No commits in common. "main" and "refactoring_object_handling" have entirely different histories.

8 changed files with 125 additions and 317 deletions

View File

@ -1,3 +0,0 @@
CREATE TABLE `u517357132_genderwatchpro`.`topics` ( `id` VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL , `lastSave` INT NULL DEFAULT CURRENT_TIMESTAMP , `fullJSON` JSON NOT NULL , `timeWatchM` INT NOT NULL , `timeWatchW` INT NOT NULL , `timeWatchD` INT NOT NULL , `countWatchM` INT NOT NULL , `countWatchW` INT NOT NULL , `countWatchD` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
INSERT INTO `topics` (`id`, `lastSave`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD`) values ('test', 2014, '{}', 10, 10, 10, 10, 40, 10) ON DUPLICATE KEY UPDATE `id` = 'test'

View File

@ -1,73 +1,3 @@
.activeWatch {
.active {
background-color: lightgray;
}
h2 {
margin-left: 10px;
margin-top: 25px !important;
}
.table-bordered {
width: 100%;
table-layout: fixed;
text-align: center;
/*border: 1px solid #0e0017 !important;*/
}
td {
overflow-wrap: break-word;
}
button {
/*background-color: lightgray;*/
/*border: none;*/
/*color: white;*/
padding: 1% 5%;
text-align: center;
text-decoration: none;
display: inline-block;
/*font-size: 16px;*/
border-radius: 20px;
}
button, .form-group{
margin: 5px !important;
}
input {
text-align: center;
}
.stopButton, .resetButton {
width: 98% !important;
}
.form-group {
width: 98%;
}
.tableHeader {
min-width: 100px;
}
html, body {
height: 100%;
margin: 0;
}
.wrapper {
min-height: 100%;
/* Equal to height of footer */
/* But also accounting for potential margin-bottom of last child */
margin-bottom: -200px;
}
footer,
.push {
height: 200px;
}
.footer {
vertical-align: top;
text-align: left;
}

Binary file not shown.

View File

@ -1,6 +1,5 @@
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/read_write_xlsx.php';
require $_SERVER['DOCUMENT_ROOT'] . '/databaseConnection/databaseConnection.php';
$fileName = $_SERVER['DOCUMENT_ROOT'] . '/data/data.xlsx';
function objectToArray($object, $fullJSON) {
return [$object -> id,
@ -14,62 +13,43 @@ function objectToArray($object, $fullJSON) {
$object -> countWatchD];
}
$conn = getDatabaseConnection();
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "connection sucessful<br>";
function findRowIndex($id, $data) {
$rowCounter = -1;
foreach ($data as $row) {
$rowCounter ++;
if($row[0] == $id) {
return $rowCounter;
}
function saveToDatabase($contentArray, $conn) {
echo "sending Query to Database<br>";
$sql1 = "SELECT * FROM `topics` WHERE id='".$contentArray[0]."'";
$result1 = $conn->query($sql1);
echo "Select Query sent<br>";
if($result1->num_rows === 0) {
$sql = "INSERT INTO `topics` (`id`, `lastSave`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD`) values ('".$contentArray[0]."', ".$contentArray[1]." , '".$contentArray[2]."', ".$contentArray[3].", ".$contentArray[4].", ".$contentArray[5].", ".$contentArray[6].", ".$contentArray[7].", ".$contentArray[8].") ON DUPLICATE KEY UPDATE `id` = '".$contentArray[0]."'";
$result = $conn->query($sql);
echo "Insert Query sent<br> Result: " . $result;
} else {
$sql = "UPDATE `topics` SET `id`='".$contentArray[0]."',`lastSave`='".$contentArray[1]."',`fullJSON`='".$contentArray[2]."',`timeWatchM`='".$contentArray[3]."',`timeWatchW`='".$contentArray[4]."',`timeWatchD`='".$contentArray[5]."',`countWatchM`='".$contentArray[6]."',`countWatchW`='".$contentArray[7]."',`countWatchD`='".$contentArray[8]."' WHERE `id` = '".$contentArray[0]."'";
$result = $conn->query($sql);
echo "Update Query sent<br> Result: " . $result;
}
return;
}
function getFromDatabase($conn) {
$sql = "SELECT `id`, `firstSave`, `lastSave`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD` FROM `topics`";
$result = $conn->query($sql);
$dataArray = Array();
while($row = $result->fetch_assoc()) {
array_push($dataArray, [$row["id"],$row["firstSave"],$row["lastSave"],$row["fullJSON"],$row["timeWatchM"],$row["timeWatchW"],$row["timeWatchD"],$row["countWatchM"],$row["countWatchW"],$row["countWatchD"]]);
}
return $dataArray;
return $rowCounter + 1;
}
$entityBody = '{"lastSave": 0, "timeWatchM": 0, "timeWatchW": 0, "timeWatchD": 0, "countWatchM": 0, "countWatchW": 0, "countWatchD": 0, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
$entityBody = file_get_contents('php://input');
$entityBodyObject = json_decode($entityBody);
echo "POST Request received.<br>";
if(property_exists($entityBodyObject, "id")) {
if(! ($entityBodyObject->countWatchM + $entityBodyObject->countWatchW + $entityBodyObject->countWatchD === 0)){
saveToDatabase(objectToArray($entityBodyObject, $entityBody), $conn);
$data = read_xls_file($fileName);
foreach ($data as $row) {
echo "new Row: <br>";
foreach ($row as $cell) {
echo $cell." ";
}
}
$rowIndex = findRowIndex($entityBodyObject->id, $data);
$data[$rowIndex] = objectToArray($entityBodyObject, $entityBody);
write_xlsxFile($fileName, $data);
echo "<br>Data saved.<br>";
}
}
} elseif($_SERVER['REQUEST_METHOD'] === 'GET') {
download_xlsxFile(getFromDatabase($conn));
} else {
echo "invalid Request.<br> Type: ".$_SERVER['REQUEST_METHOD'];
}
$conn->close();

View File

@ -1,10 +0,0 @@
<?php
function getDatabaseConnection() {
$databaseAddress = "127.0.0.1";
$databasePort = "3306";
$databaseName = "u517357132_genderwatchpro";
$databaseUser = "u517357132_genderwatchpro";
$databasePassword = "zU!7gRHA6x";
return new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName);
}

View File

@ -1,43 +1,21 @@
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/custom.css?v=1.1">
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/bootstrap.css">
<title>Genderwatch-protocol</title>
</head>
<body>
<!-- <nav class="navbar navbar-expand-lg navbar-light bg-light">-->
<!-- <a class="navbar-brand" href="index.html">Genderwatch-protocol&nbsp;</a>-->
<!-- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="true" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>-->
<!-- <div class="navbar-collapse collapse show" id="navbarSupportedContent">-->
<!-- <ul class="navbar-nav mr-auto">-->
<!-- <li class="nav-item active"> <a class="nav-link" href="index.html">Home</a> </li>-->
<!-- <li class="nav-item"> <a class="nav-link" href="beschreibung.php">Über uns</a> </li>-->
<!-- </ul>-->
<!-- <form class="form-inline my-2 my-lg-0">-->
<!-- </form>-->
<!-- </div>-->
<!-- </nav>-->
<div class="wrapper">
<section>
<div class="container">
<h1>Genderwatch-protocol</h1>
<a href="dataCollector/dataCollector.php">Alle Daten herunterladen (anonymisiert)</a>
<h2>Aktuelles Thema</h2>
<a href="data/data.xlsx">Anonyme Daten herunterladen</a>
<h2 style="margin-left: 10px;">Aktuelles Thema</h2>
<table class="table-bordered">
<tr>
<td colspan="2">
<div class="form-group">
<input class="form-control" type="text" id="topicInput" placeholder="Thema hier eingeben">
</div>
</td>
<td>
<button class="" onclick="closeTopic()">
@ -92,12 +70,12 @@
</tr>
<tr>
<td colspan="3">
<button class="stopButton" onclick="stop()">Hört auf zu Reden, -> Stille</button>
<button class="" style="width: 98%;" onclick="stop()">Hört auf zu Reden, -> Stille</button>
</td>
</tr>
<tr>
<td colspan="3">
<button class="resetButton" onclick="resetButton()">Reset</button>
<button class="" style="width: 98%;" onclick="resetButton()">Reset</button>
</td>
</tr>
</table>
@ -113,16 +91,16 @@
<table class="table-bordered">
<thead>
<tr>
<th class="tableHeader">
<th style="min-width: 100px;">
Thema
</th>
<th class="tableHeader">
<th style="min-width: 100px;">
M
</th>
<th class="tableHeader">
<th style="min-width: 100px;">
W
</th>
<th class="tableHeader">
<th style="min-width: 100px;">
D
</th>
</tr>
@ -137,57 +115,16 @@
</div>
</section>
<div class="push"></div>
</div>
<footer class="text-center">
<div class="container footer">
<div class="row">
<table>
<tr>
<td class="footer">
<div class="col-12">
<p><span><b>Impressum</b></span><br>
Maurus Pfalzgraf<br>
<a href="mailto:info@genderwatchprotocol.com">info@genderwatchprotocol.com</a></p>
</div>
</td>
<td class="footer">
<div class="col-12">
<p><span><b>Erstellt durch</b></span><br>
Silias KLG<br>
Toggenburgstrasse 31<br>
8245 Feuerthalen<br>
<a href="https://www.silias.ch" target="_blank">www.silias.ch</a><br>
<a href="mailto:info@silias.ch">info@silias.ch</a><br>
<a href="https://gitea.silias.ch/Silias-Public/genderwatchprotocol">Projekt Repository</a>
</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</footer>
<script src="js/functions.js"></script>
<script>
try {
closedTopics = JSON.parse(localStorage.getItem("closedTopics"))
} catch (e) {
closedTopics = []
}
if(!closedTopics) {
closedTopics = []
}
try{
actualTopic = JSON.parse(localStorage.getItem("actualTopic"))
} catch (e) {
initializeNewTopic()
}
if(!actualTopic) {
initializeNewTopic()
}

View File

@ -138,9 +138,9 @@ function refreshWatch(watchIndex) {
let timeCell = document.getElementById("time-" + watchIndex)
timeCell.textContent = timeToISO(sumForWatch(actualTopic.watches[watchIndex]))
if(actualTopic.watches[watchIndex]["actions"].length !== 0 && actualTopic.watches[watchIndex]["actions"].slice(-1)[0]["type"] === "start"){
timeCell.classList.add("activeWatch")
timeCell.classList.add("active")
} else {
timeCell.classList.remove("activeWatch")
timeCell.classList.remove("active")
}
let countCell = document.getElementById("count-" + watchIndex)
countCell.textContent = countForWatch(actualTopic.watches[watchIndex]) + " Wortmeldungen"
@ -192,26 +192,10 @@ function saveActualTopicName() {
function saveActualTopic() {
//save it to LocalStorage
localStorage.setItem("actualTopic", JSON.stringify(actualTopic))
//save it to Server
fetch(document.URL + "dataCollector/dataCollector.php", {
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify({
"lastSave": new Date().getTime(),
"timeWatchM": sumForWatch(actualTopic.watches[0]),
"timeWatchW": sumForWatch(actualTopic.watches[1]),
"timeWatchD": sumForWatch(actualTopic.watches[2]),
"countWatchM": countForWatch(actualTopic.watches[0]),
"countWatchW": countForWatch(actualTopic.watches[1]),
"countWatchD": countForWatch(actualTopic.watches[2]),
"id": actualTopic.id,
"watches": actualTopic.watches
})
});
}
function saveClosedTopics() {
//save it to LocalStorage
localStorage.setItem("closedTopics", JSON.stringify(closedTopics))
}

View File

@ -1,7 +1,6 @@
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSXGen.php';
function read_xls_file($filename){
$fileContent = [];
if ($xlsx = SimpleXLSX::parse($filename)) {
@ -18,12 +17,3 @@ function write_xlsxFile($filename, $data) {
$xlsx = SimpleXLSXGen::fromArray($data);
$xlsx->saveAs($filename);
}
function download_xlsxFile($data) {
$xlsxArray = read_xls_file($_SERVER['DOCUMENT_ROOT'] ."/data/data.xlsx");
foreach ($data as $row) {
array_push($xlsxArray, $row);
}
$xlsx = SimpleXLSXGen::fromArray($xlsxArray);
$xlsx->downloadAs("data.xlsx");
}