Finish framework, include W3.css build web site via templates and jQuery
[infodrom/musiikki-web.git] / html / index.php
index 0b228f7..d308bf3 100644 (file)
@@ -1,5 +1,21 @@
 <?php
 require_once(__DIR__.'/../class/autoloader.class.php');
 
-$template = new Template('index');
-echo $template->render([]);
+if ($_SERVER['REQUEST_METHOD'] == 'GET') {
+    $template = new Template('index');
+    echo $template->render([]);
+} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
+    $method = $_POST['action'] . 'Action';
+
+    header('Content-type: application/json; charset=UTF-8');
+    $data = AJAX::$method($_POST);
+    $return = json_encode($data);
+
+    if ($return === false) {
+       error_log('Return ' . var_export($data,true));
+       $return = json_encode(array('status' => false, 'error' => 'Rückgabedaten können nicht kodiert werden.'));
+    }
+
+    echo $return;
+
+}
\ No newline at end of file