Rename mask parameter into source
[misc/kostenrechnung] / lib / general.php
index f088db0..fa250f8 100644 (file)
@@ -1,5 +1,21 @@
 <?php
 
+function check_session()
+{
+  if (!empty($_POST['login']) && !empty($_POST['passwd'])) {
+    require_once('lib/login.php');
+    if (check_passwd()) {
+      header('Location: ./');
+      exit();
+    }
+  }
+
+  if (empty($_SESSION['sys']['login']) && empty($_GET['login'])) {
+    header('Location: ./?login=true');
+    exit();
+  }
+}
+
 function sanitise_filename($file)
 {
   return str_replace('./','x',$file);
@@ -26,6 +42,19 @@ function connect_db()
   pg_connect($dsn);
 }
 
+function query_db($sql)
+{
+  $sth = pg_query($sql);
+
+  if ($sth === false) return false;
+
+  $result = array();
+  while ($row = pg_fetch_assoc($sth))
+    $result[] = $row;
+
+  return $result;
+}
+
 function load_js($jsfiles, $jscode)
 {
   $ret = '';
@@ -40,6 +69,11 @@ function load_js($jsfiles, $jscode)
 
 function process()
 {
+  if (!empty($_GET['login'])) {
+    require_once('lib/login.php');
+    return mask_login();
+  }
+
   if (!empty($_GET['mask'])) {
     require_once('lib/mask.php');
     return mask($_GET['mask']);
@@ -55,4 +89,28 @@ function process()
   return $ret;
 }
 
+function debug_log($text)
+{
+  global $debug_info;
+
+  $debug_info .= '<br>' . $text;
+}
+
+function debug_info()
+{
+  global $jsfiles;
+  global $debug_info;
+
+  if (DEBUG !== true) return '';
+
+  $jsfiles[] = 'lib/debug_joey.js';
+
+  $html = '<div style="background: #DDD; margin: 5px; padding-left: 4px; border: 1px solid #AAA;clear:both;">';
+  $html .= "\n<pre>\n\$_SESSION = " . var_export($_SESSION,true) . "\n";
+  $html .= "\n\$_COOKIE = " . var_export($_COOKIE,true) . "\n</pre>\n";
+  $html .= $debug_info;
+  $html .= '</div>';
+  return $html;
+}
+
 ?>