Improve AJAX backend by use of ModuleAJAXBackend
[infodrom.org/service.infodrom.org] / src / future.php
index 1cf7bcb..779f700 100644 (file)
@@ -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;