diff --git a/web/models/Tournament.model.php b/web/models/Tournament.model.php index 6ca84d9..ae02888 100644 --- a/web/models/Tournament.model.php +++ b/web/models/Tournament.model.php @@ -14,4 +14,17 @@ class Tournament extends Model 'logo' => ['type' => 'text', 'default' => 'https://pictshare.net/prrnrk.jpg'] ); + function isMyEvent($tournament = false) + { + if ($tournament == false) + $tournament = $this->id; + + if (!$this->exists($tournament)) + return false; + else { + if (in_array($tournament, $_SESSION['user']->data['tournaments'])) + return true; + else return false; + } + } } diff --git a/web/pages/dogs/controller.php b/web/pages/dogs/controller.php index 669559b..a29971b 100644 --- a/web/pages/dogs/controller.php +++ b/web/pages/dogs/controller.php @@ -102,7 +102,7 @@ class Dogs extends Page { $photo_error = $photo['error']; $photo_type = $photo['type']; - $allowed = ['jpg','jpeg','png']; + $allowed = ['jpg','jpeg','png','gif']; $photo_ext = strtolower(end(explode('.', $photo_name))); $photo_name = $name.'.'.$photo_ext; $photo_path = 'uploads/'.$photo_name; @@ -118,19 +118,13 @@ class Dogs extends Page { $newphoto = $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; diff --git a/web/pages/tournaments/controller.php b/web/pages/tournaments/controller.php index 348a074..86080e9 100644 --- a/web/pages/tournaments/controller.php +++ b/web/pages/tournaments/controller.php @@ -13,14 +13,14 @@ class Tournaments extends Page { { $this->addSubmenuItem('Übersicht','/tournaments','far fa-list-alt'); $this->addSubmenuItem('Turnier anlegen','/tournaments/add','fas fa-calendar-plus'); - if($_SESSION['user']->data['dogs'] && count($_SESSION['user']->data['tournaments']) > 0) + if($_SESSION['user']->data['tournaments'] && count($_SESSION['user']->data['tournaments']) > 0) { $this->addSubmenuItem('divider'); foreach($_SESSION['user']->data['tournaments'] as $tid) { $t = new Tournament(); $t->load($tid); - $this->addSubmenuItem($t->data['name'],'/dogs/overview/'.$tid,'fas fa-dog'); + $this->addSubmenuItem($t->data['name'],'/tournaments/event/'.$tid,'fas fa-dog'); } } } @@ -34,6 +34,144 @@ class Tournaments extends Page { } + function event() + { + $tid = $this->params[0]; + $t = new Tournament(); + + if(!$t->isMyEvent($tid)) + return 'Not your event :('; + + $t->load($tid); + + $this->set('tournament_id',$tid); + $this->set('tdata',$t->data); + $this->set('template','event.html'); + } + + function edit() + { + if($_REQUEST['submit']) + { + $id = $_REQUEST['tournament_id']; + $name = $_REQUEST['tournament_name']; + $date = $_REQUEST['tournament_date']; + $tournament_referee = $_REQUEST['tournament_referee']; + $tournament_duration = intval($_REQUEST['tournament_duration']); + $tournament_url = $_REQUEST['tournament_url']; + $tournament_text = $_REQUEST['tournament_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 Tournament(); + if($id) + $t->load($id); + + $t->name = $name; + $t->date = $date; + $t->duration = $tournament_duration; + $t->referee = $tournament_referee; + $t->text = $tournament_text; + $t->url = $tournament_url; + 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['dogs']); + + if(!is_array($_SESSION['user']->data['tournaments']) || !in_array($tid, $_SESSION['user']->data['tournaments'])) // new t! + { + $_SESSION['user']->data['tournaments'][] = $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('/tournaments/event/'.$tid); + } + else + { + $this->set('template', '/templates/partials/success.html'); + $this->set('successMessage', "Daten erfolgreich gespeichert"); + return; + } + + } + } + else + { + $id = $this->params[0]; + $t = new Tournament(); + $t->load($id); + $this->set('tournamentdata',$t->data); + $this->set('tournamentid',$t->id); + $this->set('template', 'edit_tournament.html'); + } + } + function maySeeThisPage() { if($_SESSION['user']) //wenn eingeloggt, kein problem return true; diff --git a/web/pages/tournaments/edit_tournament.html b/web/pages/tournaments/edit_tournament.html index 0dbb706..b8498af 100644 --- a/web/pages/tournaments/edit_tournament.html +++ b/web/pages/tournaments/edit_tournament.html @@ -4,19 +4,40 @@
- - + +
+
- - + +
+
- - + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
-
\ No newline at end of file diff --git a/web/pages/tournaments/event.html b/web/pages/tournaments/event.html new file mode 100644 index 0000000..3751aed --- /dev/null +++ b/web/pages/tournaments/event.html @@ -0,0 +1,35 @@ + + +
+
+
+
+ <?= escape($tdata['name']); ?>'s profile Picture +
+
+

+ +

    +
  • Datum:
  • + +
  • Dauer: Tag/e
  • +
  • Richter:
  • +
  • Größe: cm
  • +
  • Webseite:
  • +
+ +
+ +
+
+
+
+
+
+
+ +
+
+ diff --git a/web/pages/tournaments/list.html b/web/pages/tournaments/list.html deleted file mode 100644 index 647aec4..0000000 --- a/web/pages/tournaments/list.html +++ /dev/null @@ -1,43 +0,0 @@ -Meine Hunde - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - Bearbeiten - - Löschen -
- - - - - -
-
\ No newline at end of file