Merge branch 'master' of gitea.haschek.at:Crispi/dogstats

This commit is contained in:
Chris 2023-12-12 20:47:42 +01:00
commit e4604649cc
13 changed files with 623 additions and 4 deletions

View File

@ -1,7 +1,10 @@
<?php
//$ergebnisse = file_get_contents('https://www.dognow.at/ergebnisse/');
//file_put_contents('tmp/ergebnisse.html', $ergebnisse);
if(!file_exists('tmp/ergebnisse.html'))
{
$ergebnisse = file_get_contents('https://www.dognow.at/ergebnisse/');
file_put_contents('tmp/ergebnisse.html', $ergebnisse);
}
$GLOBALS['db'] = new SQLite3('data.db');
if(!$GLOBALS['db']) exit("Error loading database");
@ -177,6 +180,7 @@ function getResults($run,$event)
function analyzeResultCSV($csvfile,$run,$event)
{
if(!file_exists($csvfile)) die(" ERR: File $csvfile not found");
$csv = array_map('str_getcsv', file($csvfile));
//prepare header for database
@ -229,8 +233,10 @@ function convertPDFtoCSV($pdf,$targetname)
}
function analyze($pdf) {
echo " [i] Analyzing $pdf\n";
$cmd = "java -jar tabula-1.0.5-jar-with-dependencies.jar -f CSV $pdf";
$output = shell_exec($cmd);
//var_dump($output);
return $output;
}

Binary file not shown.

View File

@ -1,2 +1,2 @@
*
*.html
!.gitignore

2
crawler/tmp/csv/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

2
crawler/tmp/results/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -56,7 +56,9 @@ main>.container {
padding: 60px 15px 0;
}
table {
font-size: smaller;
}
.tooltipp {
position: relative;
/* making the .tooltipp span a container for the tooltipp text */

View File

@ -0,0 +1,122 @@
<?php
class Training extends Model
{
protected $dbTable = "trainings";
protected $dbFields = array(
'registered' => ['type' => 'datetime', 'required', 'unique', 'autoValMethod' => 'getDateTime'],
'name' => ['type' => 'text', 'required'],
'date' => ['type' => 'datetime','required'],
'duration' => ['type' => 'int'], //in days
'text' => ['type' => 'text'],
'url' => ['type' => 'text'], //if there is one
'logo' => ['type' => 'text', 'default' => 'https://pictshare.net/prrnrk.jpg'],
'admins' => ['type'=> 'array', 'default'=>[]],
'members' => ['type'=> 'array', 'default'=>[]],
'runs' => ['type'=> 'array', 'default'=>[]],
);
function joinUser($training = false)
{
if ($training == false)
$training = $this->id;
if (!$this->exists($training))
return false;
else {
if (!in_array($_SESSION['user']->id, $this->data['members']))
$this->data['members'][] = $_SESSION['user']->id;
if(!in_array($training,$_SESSION['user']->data['trainings']))
{
$_SESSION['user']->data['trainings'][] = $training;
$_SESSION['user']->save();
}
$this->save();
}
}
function removeUser($training = false)
{
if ($training == false)
$training = $this->id;
if (!$this->exists($training))
return false;
else {
if (in_array($_SESSION['user']->id, $this->data['members']))
$this->data['members'] = array_diff($this->data['members'],[$_SESSION['user']->id]);
if(in_array($training,$_SESSION['user']->data['trainings']))
{
$_SESSION['user']->data['trainings'] = array_diff($_SESSION['user']->data['trainings'],[$training]);
$_SESSION['user']->save();
}
$this->save();
}
}
function isMyEvent($training = false)
{
if ($training == false)
$training = $this->id;
if (!$this->exists($training))
return false;
else {
if (in_array($training, $_SESSION['user']->data['trainings']))
return true;
else return false;
}
}
function amIAdmin($training = false)
{
if ($training == false)
$training = $this->id;
if (!$this->exists($training))
return false;
else {
if (in_array($_SESSION['user']->id, $this->data['admins']))
return true;
else return false;
}
}
function getAdmins($training = false)
{
if ($training == false)
$training = $this->id;
if (!$this->exists($training))
return false;
else {
$admins = [];
foreach($this->data['admins'] as $admin)
{
$u = new User();
$u->load($admin);
$admins[] = $u->getDataFiltered();
}
return $admins;
}
}
function getMembers($training = false)
{
if ($training == false)
$training = $this->id;
if (!$this->exists($training))
return false;
else {
$members = [];
foreach($this->data['members'] as $member)
{
$u = new User();
$u->load($member);
$members[] = $u->getDataFiltered();
}
return $members;
}
}
}

View File

@ -11,6 +11,7 @@ class Smart extends Page {
function index()
{
$this->set('user', $_SESSION['user']->data);
$this->set('template', "smart.html.php");
}

View File

@ -11,6 +11,7 @@
placeholder="Suchen..."
hx-indicator="#indicator"
class="form-control" id="basic-url"
value="<?= escape($user['lastname'].' '.$user['firstname']); ?>"
>
</div>

View File

@ -0,0 +1,269 @@
<?php
class Trainings extends Page {
function setMenu()
{
$this->menu_text = 'Trainings';
$this->menu_image = 'fas fa-running';
$this->menu_priority = 1;
}
function setSubmenu()
{
$this->addSubmenuItem('Übersicht','/trainings','far fa-list-alt');
$this->addSubmenuItem('Training hinzufügen','/trainings/add','fas fa-calendar-plus');
if($_SESSION['user']->data['trainings'] && count($_SESSION['user']->data['trainings']) > 0)
{
$this->addSubmenuItem('divider');
$counter = 0;
foreach($_SESSION['user']->data['trainings'] as $tid)
{
$t = new Training();
$t->load($tid);
$this->addSubmenuItem($t->data['name'],'/trainings/event/'.$tid,'fas fa-calendar-star');
$counter++;
if ($counter === 5) {
break;
}
}
}
}
function add()
{
$this->set('template','edit_training.html');
}
function index() {
$events = $_SESSION['user']->data['trainings'];
$trainings = [];
foreach($events as $key => $eventid)
{
//var_dump($dogid);
$event = new Training();
try{
$event->load($eventid);
}
catch(Exception $e)
{
error_log("Event $eventid not found. Deleting from user");
unset($_SESSION['user']->data['training'][$key]);
$_SESSION['user']->save();
continue;
}
if($event->data)
$trainings[] = array_merge($event->data,['id'=>$eventid]);
}
if(count($_SESSION['user']->data['trainings']) > 0)
{
$this->set('trainings',$trainings);
$this->set('template', 'trainings.html');
}
}
function manage()
{
$action = $this->params[0];
$tid = $this->params[1];
$t = new Training();
if($t->exists($tid))
$t->load($tid);
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieses Turnier existiert nicht']);
switch($action)
{
case 'join':
if(in_array($tid, $_SESSION['user']->data['trainings']))
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Du bist bereits für dieses Turnier angemeldet']);
else
{
$t->joinUser($tid);
return partial('success.html', ['successTitle' => 'Erfolgreich', 'successMessage' => 'Du wurdest erfolgreich für dieses Turnier angemeldet']);
}
case 'leave':
if(!in_array($tid, $_SESSION['user']->data['trainings']))
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Du bist für dieses Turnier nicht angemeldet']);
else
{
$t->removeUser($tid);
return partial('success.html', ['successTitle' => 'Erfolgreich', 'successMessage' => 'Du wurdest erfolgreich für dieses Turnier abgemeldet']);
}
}
}
function leave()
{
}
function event()
{
$tid = $this->params[0];
$t = new Training();
if($t->exists($tid))
$t->load($tid);
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieses Turnier existiert nicht']);
$this->set('admin',$t->amIAdmin($tid));
$this->set('joined',$t->isMyEvent($tid));
$this->set('training_id',$tid);
$this->set('admins',$t->getAdmins($tid));
$this->set('members',$t->getMembers($tid));
$this->set('tdata',$t->data);
$this->set('template','event.html');
}
function edit()
{
if($_REQUEST['submit'])
{
$id = $_REQUEST['training_id'];
$name = $_REQUEST['training_name'];
$date = $_REQUEST['training_date'];
$training_referee = $_REQUEST['training_referee'];
$training_duration = intval($_REQUEST['training_duration']);
$training_url = $_REQUEST['training_url'];
$training_text = $_REQUEST['training_text'];
$newlogo = false;
if($_FILES['logo'])
{
$logo = $_FILES['logo'];
$logo_name = $logo['name'];
$logo_tmp_name = $logo['tmp_name'];
$logo_size = $logo['size'];
$logo_error = $logo['error'];
$logo_type = $logo['type'];
$allowed = ['jpg','jpeg','png','gif'];
$logo_ext = strtolower(end(explode('.', $logo_name)));
$logo_name = $name.'.'.$logo_ext;
$logo_path = 'uploads/'.$logo_name;
if(in_array($logo_ext, $allowed))
{
if($logo_error === 0)
{
if($logo_size < 10000000)
{
$answer = pictshareUploadImage($logo_tmp_name);
if($answer['status']=='ok' && in_array($answer['filetype'],['jpeg','png','gif']))
$newlogo = $answer['url'];
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen']);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Beim Upload der Datei ist ein Fehler aufgetreten']);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen']);
}
$error = false;
if(!$name || !$date )
$error = 'Bitte zumindest Name und Datum angeben';
else if(!strtotime($date))
$error = 'Das Datumm ist ungültig. Bitte die Eingabe prüfen';
if($error){
$this->set('errorMessage', $error);
$this->set('template', '/templates/partials/error.html');
return;
}
else
{
$t = new Training();
if($id)
{
if($t->exists($id))
$t->load($id);
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieses Turnier existiert nicht']);
if(!in_array($_SESSION['user']->id, $t->data['admins']))
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Du bist nicht berechtigt, dieses Turnier zu bearbeiten']);
else
$t->load($id);
}
$t->name = $name;
$t->date = $date;
$t->duration = $training_duration;
$t->referee = $training_referee;
$t->text = $training_text;
$t->url = $training_url;
if(!$t->data['admins'] || !is_array($t->data['admins'] || count($t->data['admins']) == 0))
$t->data['admins'] = [];
if(!in_array($_SESSION['user']->id, $t->data['admins']))
$t->data['admins'][] = $_SESSION['user']->id;
if($newlogo)
$t->logo = $newlogo;
try
{
$tid = $t->save();
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
return;
}
//var_dump($_SESSION['user']->data['trainings']);
if(!is_array($_SESSION['user']->data['trainings']) || !in_array($tid, $_SESSION['user']->data['trainings'])) // new t!
{
$_SESSION['user']->data['trainings'][] = $tid;
try
{
$_SESSION['user']->save();
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
return;
}
$this->redirect('/trainings/event/'.$tid);
}
else
{
$this->set('template', '/templates/partials/success.html');
$this->set('successMessage', "Daten erfolgreich gespeichert");
return;
}
}
}
else
{
$id = $this->params[0];
$t = new Training();
$t->load($id);
$this->set('trainingdata',$t->data);
$this->set('trainingid',$t->id);
$this->set('template', 'edit_training.html');
}
}
function maySeeThisPage() {
if($_SESSION['user']) //wenn eingeloggt, kein problem
return true;
else return false;
}
}

View File

@ -0,0 +1,82 @@
<div>
<h1>Training <?= $trainingid?'Bearbeiten':'Hinzufügen'; ?></h1>
<form id="trainingeditform" hx-post="/trainings/edit" hx-encoding='multipart/form-data' hx-target="#response" class="container">
<input type="hidden" name="training_id" value="<?= $trainingid; ?>">
<div class="row">
<div class="col-md">
<div class="mb-3 mb-md-4">
<label for="training_date">Datum</label>
<input type="date" value="<?= $trainingdata['date']; ?>" id="date" name="training_date" class="form-control">
</div>
<div class="mb-3 mb-md-4">
<label for="training_focus">Trainingsfokus</label>
<select class="form-select" aria-label="Trainingsfokus" id="training_focus" name="training_focus">
<option value="_none">- None -</option>
<option value="1">Parcourlauf</option>
<option value="2">Distanzarbeit</option>
<option value="3">Führtechnik</option>
<option value="4">Einzelgeräte</option>
<option value="5">Geräteunterscheidung</option>
</select>
</div>
<div class="mb-3 mb-md-4">
<label for="training_url">Video</label>
<input type="text" value="<?= $trainingdata['url']; ?>" id="training_url" name="training_url" placeholder="https://www.youtube.com/..." class="form-control">
</div>
<div class="mb-3 mb-md-4">
<label for="training_mood_barometer_human">Stimmungsbarometer Mensch</label>
<select class="form-select" aria-label="Stimmungsbarometer Mensch" id="training_mood_barometer_human" name="training_mood_barometer_human">
<option value="_none">- None -</option>
<option value="1">😕</option>
<option value="2">🙁</option>
<option value="3">😐</option>
<option value="4">😊</option>
<option value="5">🤩</option>
</select>
</div>
<div class="mb-3 mb-md-4">
<label for="training_mood_barometer_dog">Stimmungsbarometer Hund</label>
<select class="form-select" aria-label="Stimmungsbarometer Hund" id="training_mood_barometer_dog" name="training_mood_barometer_dog">
<option value="_none">- None -</option>
<option value="1">😕</option>
<option value="2">🙁</option>
<option value="3">😐</option>
<option value="4">😊</option>
<option value="5">🤩</option>
</select>
</div>
<div>
<label for="uploads">Uploads</label>
<input type="file" accept="image/png, image/jpeg, image/gif" id="uploads" class="form-control" name="photos[]" multiple>
</div>
</div>
<div class="col-md">
<div class="mb-3 mb-md-4">
<label for="training_that_worked">Das hat gut geklappt</label>
<textarea id="training_that_worked" name="training_that_worked" class="form-control" rows="4"><?= $trainingdata['text']; ?></textarea>
</div>
<div class="mb-3 mb-md-4">
<label for="training_more_excercise">Das müssen wir intensiver üben</label>
<textarea id="training_more_excercise" name="training_more_excercise" class="form-control" rows="4"><?= $trainingdata['text']; ?></textarea>
</div>
<div class="mb-3 mb-md-4">
<label for="training_text">Notizen</label>
<textarea id="training_text" name="training_text" class="form-control" rows="4"><?= $trainingdata['text']; ?></textarea>
</div>
<div class="text-end">
<button type="submit" name="submit" value="true" class="btn btn-primary text-end d-inline-block">Hinzufügen</button>
</div>
</div>
</div>
</form>
<div id="response"></div>
</div>

View File

@ -0,0 +1,111 @@
<!-- FILEPATH: /home/chris/git/trainingstats/web/pages/trainings/dog.html -->
<div class="container">
<div class="row">
<div class="col-3">
<div class="card">
<img src="<?= $tdata['logo'] ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($tdata['name']); ?>'s profile Picture">
<div class="card-body">
<h5 class="card-title"><?= escape($tdata['name']); ?></h5>
<p class="card-text">
<ul>
<li>Datum: <?= escape($tdata['date']) ?></li>
<?php if($tdata['duration']): ?><li>Dauer: <?= escape($tdata['duration']); ?> Tag/e</li> <?php endif; ?>
<?php if($tdata['referee']): ?><li>Richter: <?= escape($tdata['referee']); ?></li> <?php endif; ?>
<?php if($tdata['size']): ?><li>Größe: <?= escape($tdata['size']); ?> cm</li> <?php endif; ?>
<?php if($tdata['url']): ?><li>Webseite: <a href="<?= $tdata['url']; ?>"><?= escape($tdata['url']); ?></a></li> <?php endif; ?>
</ul>
<div class="d-flex justify-content-end">
<?php if($admin===true): ?>
<button type="button" class="btn btn-secondary" hx-get="/trainings/edit/<?= $training_id; ?>" hx-target="#main">
<i class="fas fa-edit"></i>
</button>
<?php endif; ?>
<?php if($joined===false): ?>
<button type="button" class="btn btn-secondary" hx-get="/trainings/manage/join/<?= $training_id; ?>" hx-swap="outerHTML">
<i class="fas fa-plus-circle"></i> Diesem Event beitreten
</button>
<?php elseif($admin===false): ?>
<button type="button" class="btn btn-danger" hx-get="/trainings/manage/leave/<?= $training_id; ?>" hx-swap="outerHTML" hx-confirm="Möchtest du dieses Event wirklich verlassen?">
<i class="fas fa-minus-circle"></i> Event verlassen
</button>
<?php endif; ?>
</div>
</div>
</div>
<?php if(($admins && count($admins)>1) || ($members && count($members)>0)): ?>
<div class="card p-2">
<?php if($admins && count($admins)>0): ?> <h6>Admins</h6> <?php endif; ?>
<?php foreach($admins as $adm) : ?>
<img src="https://pictshare.net/identicon/<?= $adm['email']?>" height="50" width="50" class="rounded-circle" alt="<?= escape($adm['name']); ?>" title="<?= escape($adm['firstname'].' '.$adm['lastname']); ?>">
<?php endforeach; ?>
<?php if($members && count($members)>0): ?> <hr/> <h6>Mitglieder</h6> <?php endif; ?>
<?php foreach($members as $member) : ?>
<img src="https://pictshare.net/identicon/<?= $member['email']?>" height="50" width="50" class="rounded-circle" alt="<?= escape($member['name']); ?>" title="<?= escape($member['firstname'].' '.$member['lastname']); ?>">
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="col-8" id="sitemain">
<?php if($tdata['text']): ?>
<div class="card p-2 mb-4">
<h4>Beschreibungstext</h4>
<p class="card-text">
<pre><?= escape($tdata['text']); ?></pre>
</p>
</div>
<?php endif; ?>
<div class="card p-2">
<h4>Läufe</h4>
<p class="card-text">
<?php if($admin===true): ?>
<button hx-get="/runs/add/<?= $training_id; ?>" hx-push-url="/runs/add/<?= $training_id; ?>" hx-target="#main" class="btn btn-primary"><i class="fas fa-plus-circle"></i> Lauf hinzufügen</button>
<?php endif; ?>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Bezeichnung</th>
<th>Lauf</th>
<th>Parcourlänge</th>
<th>Normzeit</th>
<th>Maxzeit</th>
<th>Richter</th>
<th>Hund</th>
</tr>
</thead>
<tbody>
<?php foreach($tdata['runs'] as $rid) : ?>
<?php
$run = new Run();
$run->load($rid);
?>
<tr>
<td><a href="/runs/overview/<?= $rid; ?>" hx-get="/runs/overview/<?= $rid; ?>" hx-push-url="/runs/overview/<?= $rid; ?>" hx-target="#main"><?= escape($run->data['name']); ?></a></td>
<td><?= escape($run->data['category']); ?></td>
<td><?= escape($run->data['length']); ?>m</td>
<td><?= escape($run->data['time_standard']); ?>s</td>
<td><?= escape($run->data['time_max']); ?>s</td>
<td><?= escape($run->data['referee']); ?></td>
<td><?= escape($run->data['dog']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</p>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,21 @@
<!-- FILEPATH: /home/chris/git/dogstats/web/pages/dogs/dog.html -->
<h1>Turnier Veranstaltungen</h1>
<p>Hier kannst du alle Veranstaltungen einsehen.</p>
<div class="trainings-list row row-cols-sm-2">
<?php foreach ($trainings as $training) : ?>
<div class="p-2">
<div class="d-flex border">
<img src="<?= $training['photo']?:'https://pictshare.net/prrnrk.jpg' ?>/130x100/forcesize" class="" alt="<?= escape($training['name']); ?>'s event Picture">
<div class="m-3">
<h3 class="h5"><a href="/trainings/event/<?= $training['id'] ?>" class="text-body link-underline link-underline-opacity-0"><?= escape($training['name']); ?></a></h3>
<p><?= date("d.m.y",strtotime($training['date'])); ?></p>
</div>
<div class="m-3 ms-auto">
<button hx-get="/training/edit/<?= $training['id'] ?>" hx-push-url="/training/edit/<?= $training['id'] ?>" hx-target="#main" class="btn btn-primary"><i class="fas fa-edit"></i></button>
<button hx-get="/training/delete/<?= $training['id'] ?>" hx-target="#main" hx-confirm="Bist du sicher, dass du <?= escape($training['name']); ?> löschen willst" class="btn btn-danger"><i class="fas fa-trash"></i></button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>