diff --git a/web/css/dogstats.css b/web/css/dogstats.css index 2d41245..dff5a4c 100644 --- a/web/css/dogstats.css +++ b/web/css/dogstats.css @@ -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 */ diff --git a/web/models/Training.model.php b/web/models/Training.model.php new file mode 100644 index 0000000..ae4ad68 --- /dev/null +++ b/web/models/Training.model.php @@ -0,0 +1,122 @@ + ['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; + } + } +} diff --git a/web/pages/trainings/controller.php b/web/pages/trainings/controller.php new file mode 100644 index 0000000..c422b86 --- /dev/null +++ b/web/pages/trainings/controller.php @@ -0,0 +1,269 @@ +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; + } + +} \ No newline at end of file diff --git a/web/pages/trainings/edit_training.html b/web/pages/trainings/edit_training.html new file mode 100644 index 0000000..28ccd50 --- /dev/null +++ b/web/pages/trainings/edit_training.html @@ -0,0 +1,82 @@ +
+

Training

+ +
+ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/web/pages/trainings/training.html b/web/pages/trainings/training.html new file mode 100644 index 0000000..2e05297 --- /dev/null +++ b/web/pages/trainings/training.html @@ -0,0 +1,111 @@ + + +
+
+
+
+ <?= escape($tdata['name']); ?>'s profile Picture +
+
+

+

    +
  • Datum:
  • + +
  • Dauer: Tag/e
  • +
  • Richter:
  • +
  • Größe: cm
  • +
  • Webseite:
  • +
+ + +
+ + + + + + + + + +
+
+
+ + 1) || ($members && count($members)>0)): ?> +
+ 0): ?>
Admins
+ + <?= escape($adm['name']); ?> + + + 0): ?>
Mitglieder
+ + <?= escape($member['name']); ?> + +
+ +
+
+ +
+

Beschreibungstext

+

+

+

+
+ + +
+

Läufe

+

+ + + + +

+ + + + + + + + + + + + + + + load($rid); + ?> + + + + + + + + + + + +
BezeichnungLaufParcourlängeNormzeitMaxzeitRichterHund
data['name']); ?>data['category']); ?>data['length']); ?>mdata['time_standard']); ?>sdata['time_max']); ?>sdata['referee']); ?>data['dog']); ?>
+
+

+ +
+
+ +
+
+ diff --git a/web/pages/trainings/trainings.html b/web/pages/trainings/trainings.html new file mode 100644 index 0000000..539fcc7 --- /dev/null +++ b/web/pages/trainings/trainings.html @@ -0,0 +1,21 @@ + +

Turnier Veranstaltungen

+

Hier kannst du alle Veranstaltungen einsehen.

+
+ +
+
+ <?= escape($training['name']); ?>'s event Picture +
+

+

+
+
+ + +
+
+
+ +
+