From: Joey Schulze Date: Sun, 17 Jul 2016 20:28:47 +0000 (+0200) Subject: Improve AJAX backend by use of ModuleAJAXBackend X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=commitdiff_plain;h=2f10af49ec96bd3c9a2f714b085c8a2377af7c07 Improve AJAX backend by use of ModuleAJAXBackend --- diff --git a/src/ajax.php b/src/ajax.php index c8926f4..da92334 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -2,19 +2,38 @@ require_once('config.php'); require_once('future.php'); -$backend = new AJAXBackend(); - $data = array(); if (strlen($_POST['func'])) { + $backend = new AJAXBackend(); + if (method_exists($backend, $_POST['func'])) { $func = $_POST['func']; - $data = $backend->$func(); - } else { - $data = array('error' => 'Unbekannte Funktion '.$_POST['func'].'.'); + json_return($backend->$func()); + } + + $path = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])+strlen($_SERVER['SERVER_NAME'])+1); + $slash = strpos($path, '/', strpos($path, '/')+1); + + if ($slash !== false) { + $path = getcwd() . '/' . substr($path, 0, $slash) . '/' . 'moduleajaxbackend.class.php'; + + if (file_exists($path)) { + require_once($path); + $backend = new ModuleAJAXBackend(); + + if (method_exists($backend, $_POST['func'])) { + $func = $_POST['func']; + json_return($backend->$func()); + } + } } + + error_log('Unknown function '.$_POST['func']); + json_return(array('status' => false, + 'error' => 'Unknown function '.urlencode($_POST['func']).'.')); } -json_return($data); +error_log('Unknown usage'); +json_return(array('status' => false, 'error' => 'Unknown usage')); -?> diff --git a/src/future.php b/src/future.php index 1cf7bcb..779f700 100644 --- a/src/future.php +++ b/src/future.php @@ -17,16 +17,35 @@ function json_return($data) $encoded = json_encode($data); if ($encoded === false) { - error_log('Wrong encoding: ' . var_export($encoded,true)); + error_log('Return ' . var_export($result,true)); return json_encode(array('status' => false, - 'error' => 'Cannot encode return values, see server log.')); - } else { + 'error' => 'Rückgabedaten können nicht kodiert werden.')); + } else echo $encoded; - } exit(); } +function json_error($text) +{ + $data = array('status' => false, 'error' => $text); + json_return($data); +} + +function assert_iso_date($date) +{ + if (strpos($date, '.') === false) return $date; + $d = explode('.', $date); + return $d[2] . '-' . $d[1] . '-' . $d[0]; +} + +function assert_german_date($date) +{ + if (is_null($date)) return ''; + if (strpos($date, '-') === false) return $date; + $d = explode('-', $date); + return $d[2] . '.' . $d[1] . '.' . $d[0]; +} global $db; diff --git a/src/infodrom.css b/src/infodrom.css index fb6744a..450cf9d 100644 --- a/src/infodrom.css +++ b/src/infodrom.css @@ -46,6 +46,9 @@ h3.bar { font-size: 14px; background: #98c5e5; } +.jsaction { + color: #666; +} img.border { border: 2px solid #e5e5e5; }