Base application
[infodrom.org/touren.infodrom.org] / controller / indexcontroller.class.php
diff --git a/controller/indexcontroller.class.php b/controller/indexcontroller.class.php
new file mode 100644 (file)
index 0000000..09df359
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+class IndexController extends ControllerBase implements ControllerInterface
+{
+    public function allowUnauthenticated()
+    {
+       return ['login'];
+    }
+
+    public function getNavigation()
+    {
+       if (empty($_SESSION['userid']))
+           return [];
+
+       $list = [];
+       $list[] = ['url' => $this->app->getBaseURL(),
+                  'title' => 'Home'];
+       $list[] = ['url' => $this->app->getBaseURL() . 'index/settings',
+                  'title' => 'Einstellungen'];
+       $list[] = ['url' => $this->app->getBaseURL() . 'account/logout',
+                  'title' => 'Logout'];
+
+       return $list;
+    }
+
+    public function indexAction($request, $response)
+    {
+       $base = $this->app->getBaseURL();
+       $sql = <<<EOS
+           SELECT tour.name, start_date,
+             tour_status.key = 'plan' AS plan,
+             tour_status.key = 'cancel' AS cancel,
+             '{$base}' || 'tour/' || tour.key || '/index' AS url
+           FROM tour
+           JOIN tour_member ON tour_id = tour.id
+           JOIN tour_status ON tour_status_id = tour_status.id
+           LEFT JOIN tour_date ON tour_date_id = tour_date.id
+           WHERE member_id = {$_SESSION['userid']}
+           ORDER BY year DESC, start_date DESC, plan DESC
+EOS;
+       $list = $this->db->fetchObjectList($sql);
+
+       $response->setData(Template::render('page/list', ['list' => $list]));
+    }
+
+    public function loginAction($request, $response)
+    {
+       $response->setData(Template::render('page/login',
+                                           [
+                                            'action' =>  $this->app->getBaseURL().'account/login'
+                                            ]));
+    }
+
+    public function settingsAction($request, $response)
+    {
+       $user = new Sys_User($_SESSION['userid']);
+
+       $form = new Form('settings');
+       $form->setTitle('Einstellungen');
+       $form->add(new FormElement('text', ['name' => 'email',
+                                           'title' => 'Mail-Adresse',
+                                           'help' => 'Nach Änderung muß das Passwort neu gesetzt werden',
+                                           'value' => $_SESSION['email']]));
+       $form->add(new FormElement('text', ['name' => 'mobile',
+                                           'title' => 'Mobiltelefon',
+                                           'help' => 'Nur sichtbar für Tour-Mitglieder',
+                                           'placeholder' => '0150-1234567',
+                                           'value' => $user->get('mobile')]));
+       $form->add(new FormElement('checkbox', ['name' => 'single_room',
+                                               'title' => 'Einzelzimmer gewünscht',
+                                               'help' => 'Normalerweise teilen wir uns zu zweit ein Doppelzimmer',
+                                               'checked' => $user->get('single_room')]));
+
+       $response->setData($form->toString());
+    }
+
+    public function ajaxSettings($request, $response, $data)
+    {
+       $ok = $this->db->update('sys_user',
+                               ['email' => $data['email'],
+                                'mobile' => $data['mobile'],
+                                'single_room' => isset($data['single_room']) && $data['single_room'] == '1'],
+                               'id='.$_SESSION['userid']);
+
+       if (!$ok) {
+           return $response->setError('Fehler beim Speichern');
+       }
+
+       $_SESSION['email'] = $data['email'];
+    }
+}
\ No newline at end of file