From 99b589cd80c20b949a20796783ade51793d4481e Mon Sep 17 00:00:00 2001
From: ztk <support@ztk.me>
Date: Wed, 14 Nov 2018 11:46:12 +0100
Subject: [PATCH] first basic! implementation of frameless banner advertising.
 sponsoring platforms shall follow delivering frameless advertisings, too -
 it's the only way to go... also it intentionally limits the number of ads
 which can be clicked, especially at once, cause the previous behaviour is one
 of the big issues why paid4 became worthless, thank you. There will be
 issues, there will be bugs, please let me know, in the comments bel... at the
 git issues tracker :)

---
 adcheck.php                           |  43 ++++++
 adclick.php                           |  43 ++++++
 content/verdienen/forcedbanner_nf.php |  12 ++
 ext/ap/ads.inc.php                    | 166 ++++++++++++++++++++++
 ext/ap/ads.php                        |  47 +++++++
 ext/js/basics.js                      |   4 +
 ext/js/forcedbanner_nf.js             | 189 ++++++++++++++++++++++++++
 index.php                             |  14 +-
 install/index.php                     |  42 ++++++
 lib/datenbank.inc.php                 |  51 ++++++-
 10 files changed, 600 insertions(+), 11 deletions(-)
 create mode 100644 adcheck.php
 create mode 100644 adclick.php
 create mode 100644 content/verdienen/forcedbanner_nf.php
 create mode 100644 ext/ap/ads.inc.php
 create mode 100644 ext/ap/ads.php
 create mode 100644 ext/js/basics.js
 create mode 100644 ext/js/forcedbanner_nf.js

diff --git a/adcheck.php b/adcheck.php
new file mode 100644
index 0000000..388fc4a
--- /dev/null
+++ b/adcheck.php
@@ -0,0 +1,43 @@
+<?php
+if(!isset($_GET['data'])) exit;
+
+require ('lib/datenbank.inc.php');
+require ('lib/functions.lib.php');
+require ('lib/session.lib.php');
+require ('ext/ap/ads.inc.php');
+
+list($art, $tan) = explode('-', $_GET['data']); // yeah sorry ;)
+$art = base64_decode($art);
+$tan = base64_decode($tan);
+$kampdaten = getAdDataByArtAndTan( $art, $tan );
+
+$result_color = 'red';
+
+if( $tan == $_SESSION['current_ad']['tan'] &&
+    $art == $_SESSION['current_ad']['art'] &&
+    true == $_SESSION['current_ad']['paid']
+  )
+{
+    $result_color = 'green';
+}
+
+?><!DOCTYPE html>
+<html>
+    <head>
+        <!-- never is old spec but will be ignored by new browsers //-->
+        <meta name="referrer" content="never">
+        <meta name="referrer" content="no-referrer" />
+        <title>Hinweis</title>
+    </head>
+    <body bgcolor="<?php echo $result_color; ?>">
+
+        <?php if( 'green' == $result_color ) { ?>
+        Diese Anzeige wurde dir mit <?php echo $kampdaten['verdienst'] .' '. $pageconfig['waehrung']; ?> verg&uuml;tet.
+        <?php } else { ?>
+        Nope, das war nix
+        <?php } ?>
+
+    </body>
+</html><?php
+invalidateAlreadyRunningAd();
+?>
diff --git a/adclick.php b/adclick.php
new file mode 100644
index 0000000..9abdf60
--- /dev/null
+++ b/adclick.php
@@ -0,0 +1,43 @@
+<?php
+if(!isset($_GET['data'])) exit;
+
+require ('lib/datenbank.inc.php');
+require ('lib/functions.lib.php');
+require ('lib/session.lib.php');
+require ('ext/ap/ads.inc.php');
+
+list($art, $tan) = explode('-', $_GET['data']); // yeah sorry ;)
+$art = base64_decode($art);
+$tan = base64_decode($tan);
+
+$kampdaten = getAdDataByArtAndTan( $art, $tan );
+// TODO prevent malicious ziel urls
+
+invalidateAlreadyRunningAd();
+setCurrentRunningAd( $art, $tan );
+?><!DOCTYPE html>
+<html>
+    <head>
+        <!-- never is old spec but will be ignored by new browsers //-->
+        <meta name="referrer" content="never">
+        <meta name="referrer" content="no-referrer" />
+        <meta http-equiv="refresh" content="0; URL=<?php echo $kampdaten['ziel']; ?>">
+        <title>Anzeige</title>
+    </head>
+    <body>
+
+      <script>
+        var notified = false;
+        function notify()
+        {
+            if( false == notified )
+            {
+                notified = true;
+                window.opener.postMessage( { 'action': 'adcheck', 'art': '<?php echo $art; ?>', 'tan': '<?php echo $tan; ?>' }, '<?php echo $pageconfig['domain']; ?>');
+            }
+            return true;
+        }
+      </script>
+      <a href="<?php echo $kampdaten['ziel']; ?>" rel="noopener noreferrer nofollow" onclick="notify();" >Hier weiter, falls keine automatische Weiterleitung erfolgt.</a>
+    </body>
+</html>
diff --git a/content/verdienen/forcedbanner_nf.php b/content/verdienen/forcedbanner_nf.php
new file mode 100644
index 0000000..69119fe
--- /dev/null
+++ b/content/verdienen/forcedbanner_nf.php
@@ -0,0 +1,12 @@
+<?php
+$sperre = mysqli_fetch_array(db_query("SELECT forced_sperre FROM ".$db_prefix."_kontodaten WHERE uid = '".$_SESSION['uid']."' "));
+userstatus ();
+head ('Klickbanner');
+?>
+
+<div id="forcedbanner_display"></div>
+<input type="button" value="Neue Banner laden" id="loadAds_btn">
+
+<script src="<?php echo $pageconfig['domain']; ?>/ext/js/forcedbanner_nf.js"></script>
+<?php
+foot ();
diff --git a/ext/ap/ads.inc.php b/ext/ap/ads.inc.php
new file mode 100644
index 0000000..89007c0
--- /dev/null
+++ b/ext/ap/ads.inc.php
@@ -0,0 +1,166 @@
+<?php
+$adArten = array('forcedbanner' => 'forcedbanner',
+                );
+
+/*
+* TODO
+* nothing checks wether user landed on blacklist...
+* blacklist check is broken currently anyway
+* please fix me
+*/
+
+function invalidateAlreadyRunningAd()
+{
+    global $adArten,$ip,$db_prefix;
+    $result = false;
+
+    if( isset($_SESSION['current_ad']) )
+    {   
+        $tan = ( isset($_SESSION['current_ad']['tan']) ) ? $_SESSION['current_ad']['tan'] : false;
+        $art = ( isset($_SESSION['current_ad']['art']) ) ? $_SESSION['current_ad']['art'] : ''; 
+
+        if( false !== $tan && in_array($art, $adArten) )
+        {
+            $dbArt = $adArten[$art];
+            $kamp = db_query ("SELECT `t1`.* FROM `" . $db_prefix . "_gebuchte_werbung` AS `t1`
+                               LEFT JOIN `" . $db_prefix . "_reloads` AS `t2` ON (`t1`.`tan`=`t2`.`tan` AND (`t2`.`uid`=" . $_SESSION['uid'] . " OR `t2`.`ip`='" . $ip . "') AND `t2`.`bis` > " . time() . ")
+                               WHERE `t1`.`tan` = '" . $tan . "' AND `t2`.`tan` IS NULL AND `t1`.`werbeart` = '".$dbArt."' LIMIT 1");
+
+            if ( mysqli_num_rows( $kamp ) )
+            {
+                $result = true;
+                $forced = mysqli_fetch_assoc( $kamp );
+
+                $new_reload = time() + $forced['reload'];
+
+                db_query("INSERT INTO `" . $db_prefix . "_reloads`
+                         (`ip`,`uid`,`tan`,`bis`) VALUES 
+                         ('" . $ip . "'," . $_SESSION['uid'] . ",'" . $tan . "'," . $new_reload . ")");
+            }   
+        }   
+        unset( $_SESSION['current_ad'] );
+    }
+    return $result;
+}
+
+function setCurrentRunningAd( $art, $tan )
+{
+    $_SESSION['current_ad']['tan'] = $tan;
+    $_SESSION['current_ad']['art'] = $art;
+    $_SESSION['current_ad']['time'] = time();
+    $_SESSION['current_ad']['paid'] = false;
+}
+
+function handleAdPayout( $forced )
+{
+    global $dbArten, $ip, $db_prefix;
+
+    db_query("UPDATE ".$db_prefix."_kontodaten  SET klicks = klicks + 1, kv = kv + ".$forced['verdienst'].", fc_klicks = fc_klicks + 1 WHERE uid = '".$_SESSION['uid']."'"); // Hier Zusatz für Fakeschutz  
+    kontobuchung ('+', $forced['verdienst'], create_code(14), $_SESSION['uid'], 1, 'Forcedbannerverdienst');
+    refumsatz ($forced['verdienst'], $_SESSION['uid']);
+    rallysystem ($_SESSION['uid'], '1', $forced['verdienst']);
+    bilanz($forced['preis'], $forced['verdienst'],'Werbebereich','Forcedbannerklick');
+    $new_reload = time() + $forced['reload'];
+    db_query("INSERT INTO " . $db_prefix . "_reloads (ip,uid,tan,bis) VALUES ('" . $ip . "'," . $_SESSION['uid'] . ",'" . $forced['tan'] . "'," . $new_reload . ")");
+    db_query("UPDATE " . $db_prefix . "_gebuchte_werbung SET menge = menge - 1 WHERE tan='" . $forced['tan'] . "'");
+
+}
+
+function checkAdOk( $art, $tan )
+{
+    global $dbArten, $ip, $db_prefix, $sql_open;
+    $result = array('checkResult' => false);
+
+    $sql = "SELECT `t1`.* FROM `" . $db_prefix . "_gebuchte_werbung` AS `t1`
+            LEFT JOIN `" . $db_prefix . "_reloads` AS `t2` ON (`t1`.`tan`=`t2`.`tan` AND (`t2`.`uid`=" . $_SESSION['uid'] . " OR `t2`.`ip`='" . $ip . "') AND `t2`.`bis` > " . time() . ")
+            WHERE `t1`.`tan` = ? AND `t2`.`tan` IS NULL AND `t1`.`werbeart` = ? LIMIT 1";
+    $statement = mysqli_stmt_init( $sql_open );
+    mysqli_stmt_prepare( $statement, $sql );
+
+    mysqli_stmt_bind_param( $statement, "ss", $tan, $art );
+    if( mysqli_stmt_execute( $statement ) )
+    {
+
+        mysqli_stmt_store_result( $statement );
+
+        if ( mysqli_stmt_num_rows( $statement ) > 0 )
+        {
+
+            $timepassed = ( time() - $_SESSION['current_ad']['time'] ) +1;
+
+            $rows = db_fetch( $statement );
+            $forced = $row[0];
+            $result['data'] = $forced;
+
+            if( $timepassed >= $forced['aufendhalt'] )
+            {
+                handleAdPayout( $forced );
+                $_SESSION['current_ad']['paid'] = true;
+                $result['checkResult'] = true;
+            }
+        }
+    }
+    mysqli_stmt_close( $statement );
+    return $result;
+}
+
+function getNewAdData( $dbArt )
+{
+    global $ip,$db_prefix;
+    $result = array('count' => 0, 'data' => array() );
+
+    $banner_sql = 'SELECT t1.*
+                    FROM ' . $db_prefix . '_gebuchte_werbung t1
+                    LEFT JOIN ' . $db_prefix . '_userblacklist t4 ON t4.uid = ' . $_SESSION['uid'] . ' 
+                    LEFT JOIN ' . $db_prefix . '_fb_blacklist AS t3 ON t3.kid = t1.kid AND t3.werbeart=t1.werbeart
+                    LEFT JOIN ' . $db_prefix . '_reloads t2
+                    ON (t1.tan = t2.tan AND (t2.uid = ' . $_SESSION['uid'] . ' OR t2.ip = "' . $ip . '") AND t2.bis >= ' . time() . ')
+                    WHERE
+                    (t3.kid IS NULL OR LOCATE(t3.sponsor, t1.ziel) = 0) AND 
+                    t2.tan IS NULL AND
+                    t1.werbeart = "'.$dbArt.'" AND
+                    t1.menge > 0 AND
+                    t1.status = 1 AND
+                    t1.verdienst > 0 AND
+                    t1.sponsor != ' . $_SESSION['uid'] . ' 
+                    ORDER BY t1.verdienst DESC LIMIT 3';
+    $banner_res = db_query( $banner_sql );
+    $banner_c   = mysqli_num_rows( $banner_res );
+
+    $result['count'] = $banner_c;
+
+    if( 0 < $banner_c )
+    {   
+        while( $banner = mysqli_fetch_assoc( $banner_res ) )
+            $result['data'][] = $banner;
+    }
+
+    return $result;
+
+}
+
+function getAdDataByArtAndTan( $art, $tan )
+{
+    global $db_prefix, $sql_open;
+    $row = false;
+    $sql = 'SELECT `uid`, `tan`, `kid`, `ziel`, `banner`, `verdienst`, `preis`, `aufendhalt`, `menge`, `reload`, `sponsor`, `werbeart`, `status` FROM `' . $db_prefix . '_gebuchte_werbung` WHERE `tan` = ? AND `werbeart` = ? LIMIT 1';
+
+    $statement = mysqli_prepare( $sql_open, $sql );
+
+    mysqli_stmt_bind_param( $statement, "ss", $tan, $art );
+    if( mysqli_stmt_execute( $statement ) )
+    {
+        mysqli_stmt_store_result( $statement );
+        if ( mysqli_stmt_num_rows( $statement ) > 0 )
+        {
+            $rows = db_fetch( $statement );
+            $row = $rows[0]; // should be there ... > 0
+        }
+    }
+    mysqli_stmt_close( $statement );
+    return $row;
+    
+    //return array( 'uid' => $uid, 'tan' => $tan, 'kid' => $kid, 'ziel' => $ziel, 'banner' => $banner, 'verdienst' => $verdienst, 'preis' => $preis, 'aufendhalt' => $aufendhalt,
+    //                 'menge' =>  $menge, 'reload' => $reload, 'sponsor' => $sponsor, 'werbeart' => $werbeart, 'status' => $status );
+
+}
diff --git a/ext/ap/ads.php b/ext/ap/ads.php
new file mode 100644
index 0000000..d1ab5ab
--- /dev/null
+++ b/ext/ap/ads.php
@@ -0,0 +1,47 @@
+<?php
+ini_set('display_errors', '1');
+require ('../../lib/datenbank.inc.php');
+require ('../../lib/functions.lib.php');
+require ('../../lib/session.lib.php');
+userstatus();
+require ('ads.inc.php');
+
+$sperre_sql = "SELECT `forced_sperre` FROM `".$db_prefix."_kontodaten` WHERE `uid` = ".$_SESSION['uid'];
+$sperre_res = db_query($sperre_sql);
+$sperre     = mysqli_fetch_assoc( $sperre_res );
+
+
+if( 0 == $sperre['forced_sperre'] )
+{
+    $result = array( 'count' => 0, 'data' => array() );
+
+    if( isset($_POST['action']) )
+    {
+        switch( $_POST['action'] )
+        {
+            case 'getNewAdData':
+                invalidateAlreadyRunningAd();
+                if( isset($_POST['adArt']) )
+                {
+                    if( in_array($_POST['adArt'], $adArten) )
+                    {
+                        $dbArt = $adArten[$_POST['adArt']];
+                        $result = getNewAdData( $dbArt );
+                    }
+                }
+            break;
+
+            case 'checkAdOk':
+                if( isset( $_POST['art'] ) && isset( $_POST['tan'] ) )
+                    $result = checkAdOk( $_POST['art'], $_POST['tan'] );
+            break;
+
+            case 'invalidateAd':
+                $result = invalidateAlreadyRunningAd();
+            break;
+        }
+    }
+
+    echo json_encode($result);
+
+}
diff --git a/ext/js/basics.js b/ext/js/basics.js
new file mode 100644
index 0000000..9696b81
--- /dev/null
+++ b/ext/js/basics.js
@@ -0,0 +1,4 @@
+function sleep(ms)
+{
+    return new Promise(resolve => setTimeout(resolve, ms));
+}
diff --git a/ext/js/forcedbanner_nf.js b/ext/js/forcedbanner_nf.js
new file mode 100644
index 0000000..bd2a067
--- /dev/null
+++ b/ext/js/forcedbanner_nf.js
@@ -0,0 +1,189 @@
+
+$( document ).ready( function()
+    {
+        var adFenster = new Array();
+
+        window.addEventListener("message", function(event)
+            {
+                if ( pageconfig['domain'] != event.origin )
+                {
+                    return;
+                }
+                console.log(event.data);
+                var art = event.data['art'],
+                    tan = event.data['tan'],
+                    action = event.data['action'];
+                
+                if( 'adcheck' == action )
+                {
+                    console.log('okokok');
+                    adFenster[art][tan]['opened'] = true;
+
+                }
+            }   
+        );
+
+        function checkAdOk( art, tan )
+        {
+            console.log('checkadok');
+            if( false == adFenster[art][tan]['checked'] && false == adFenster[art][tan]['window'].closed )
+            {
+                var pdata = window.btoa(art) + '-' + window.btoa(tan)
+                adFenster[art][tan]['checked'] = true;
+                $.post( "ext/ap/ads.php",
+                    {
+                        'action': "checkAdOk",
+                        'art': art,
+                        'tan': tan
+                    },
+                    function(data, status)
+                    {
+                        window.open(pageconfig['domain']+'/adcheck.php?data='+pdata, art+'-'+tan, "height=120,width=200");
+                    }
+                );
+            }
+        }
+
+        /*
+        * if u do something wrong, sorry no matter which ad was active, invalidate 
+        */
+        function invalidateAd( art, tan )
+        {
+            console.log('invalidatead');
+            adFenster[art][tan]['checked'] = true;
+            var pdata = window.btoa(art) + '-' + window.btoa(tan)
+            $.post( "ext/ap/ads.php",
+                {
+                    'action': "invalidateAd"
+                },
+                function(data, status)
+                {
+                    window.open(pageconfig['domain']+'/adcheck.php?data='+pdata, art+'-'+tan, "height=120,width=200");
+                }
+            );
+
+
+        }
+
+        async function startAdCountdown( art, tan, sec )
+        {
+            console.log('startadcountdown');
+            let timer = setInterval( () =>
+                {
+                    console.log('checktimer');
+                    if( true == adFenster[art][tan]['checked'] )
+                    {
+                        clearInterval(timer);
+                    } else {
+                        if( document.hasFocus() )
+                        {
+                            invalidateAd( art, tan );
+                            clearInterval(timer);
+                        }
+                        if ( 'undefined' == adFenster[art][tan]['window'].closed || adFenster[art][tan]['window'].closed )
+                        {
+                            invalidateAd( art, tan );
+                            clearInterval(timer);
+                        }
+                    }
+                },
+                100
+            );
+            await sleep(sec * 1000);
+            checkAdOk( art, tan );
+        }
+
+
+        /*
+        * communicates with ad window, placing detection of actual click
+        */
+        function openAdWindow( art, tan, sec )
+        {
+            if ( 'undefined' == typeof adFenster[art] || (! adFenster[art] instanceof Array ) )
+            {
+                adFenster[art] = new Array();
+            }
+
+            if ( 'undefined' == typeof adFenster[art][tan] || (! adFenster[art][tan] instanceof Array ) )
+            {
+                adFenster[art][tan] = new Array();
+            }
+
+            if( ( 'undefined' == adFenster[art][tan]['window'] || null == adFenster[art][tan]['window'] ) || adFenster[art][tan]['window'].closed )
+            {
+                var data = window.btoa(art) + '-' + window.btoa(tan);
+                adFenster[art][tan]['window'] = window.open( pageconfig['domain'] + '/adclick.php?data='+data, "_blank" );
+
+                adFenster[art][tan]['window'].focus();
+                adFenster[art][tan]['opened'] = false;
+                adFenster[art][tan]['checked']= false;
+                console.log('meh');
+                adFenster[art][tan]['window'].onbeforeunload = function()
+                {   console.log('startadcountdowncall');
+                    startAdCountdown( art, tan, sec );
+                }
+            }
+        }
+
+
+        /*
+        * gets executed after loading ads for every ad loaded
+        */
+        function displayForcedBanner( data )
+        {
+            // {"count":1,"data":{"uid":"0","tan":"BxrPvnPbs8j7D1bNAL28KNQVxr4Szijb","kid":"0","ziel":"https:\/\/ztk.me","banner":"https:\/\/ztk.me","verdienst":"10.00","preis":"0.00","aufendhalt":"0","menge":"99999","reload":"3600","sponsor":"administrator","werbeart":"forcedbanner","status":"1"}}
+            var html = '<li class="list-group-item" data-tan="'+ data.tan + '" data-art="' + data.werbeart + '" data-sec="'+ data.aufendhalt + '"><img src="' + data.banner + '" style="min-width:60px; min-height:10px; cursor:pointer;" /></li>';
+            $( "#forcedbanner_display_grp" ).append( html );
+        }
+
+
+        /*
+        * gets executed on click on ad
+        */
+        $( "#forcedbanner_display" ).on('click', function(e)
+            {
+                var elem = $( e.target ).closest( "li" );
+                var sec = elem.data('sec');
+                var tan = elem.data('tan');
+                var art = elem.data('art');
+                if (typeof tan !== typeof undefined && tan !== false)
+                {
+                    if (typeof art !== typeof undefined && art !== false)
+                    {
+                        if (typeof sec !== typeof undefined && sec !== false)
+                        {
+                            $(elem).remove();
+                            openAdWindow( art, tan, sec );
+                        }
+                    }
+                }
+            }
+        );
+
+        /*
+        * gets executed first, loads available ads and prepares the bootstrap <ul>-list for display
+        */
+        function loadAds( art )
+        {
+            $.post( "ext/ap/ads.php",
+                {
+                    'action': "getNewAdData",
+                    'adArt' : art
+                },
+                function(data, status)
+                {
+                    var useData = jQuery.parseJSON( data );
+                    if( 0 < useData.count )
+                    {
+                        $( "#forcedbanner_display" ).html('<ul class="list-group" id="forcedbanner_display_grp"></ul>');
+                        useData.data.forEach( displayForcedBanner );
+                    }
+                }
+            );
+        }
+
+        $( "#loadAds_btn").on('click', function(e) { loadAds( 'forcedbanner' ) } );
+
+        loadAds( 'forcedbanner' );
+    }
+);
diff --git a/index.php b/index.php
index 5a30a96..b6c69e3 100644
--- a/index.php
+++ b/index.php
@@ -36,9 +36,7 @@ if (mysqli_num_rows($start_reload) != 0) {
 	$datetime = "2014-09-21 20:33:28";
 }
 $ts = strtotime($datetime);
-?>
-
-<!DOCTYPE html>
+?><!DOCTYPE html>
 <html lang='de'>
     <head>
         <title><?php echo $pageconfig['seitenname'];?></title>
@@ -53,13 +51,17 @@ $ts = strtotime($datetime);
 		<link href="css/bootstrap.min.css" rel="stylesheet"> 
 		<script src="http://code.jquery.com/jquery-latest.js"></script>
 		<script type="text/javascript" src="js/tcal.js"></script> 
-		<script language="JavaScript" src="js/slider.js"></script>
+		<script type="text/javascript" src="js/slider.js"></script>
 		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-		<script src="js/bootstrap.min.js"></script>
+		<script type="text/javascript" src="js/bootstrap.min.js"></script>
+    <script type="text/javascript" src="ext/js/basics.js"></script>
 		<script type="text/javascript" src="js/start_countdown.js"></script>
     </head>
     <body>
-	
+    <script>
+        var pageconfig = new Array();
+        pageconfig['domain'] = '<?php echo $pageconfig['domain']; ?>';
+    </script>
 	<?php 
 	if(!empty($meldung['meldung'])){
 	?>
diff --git a/install/index.php b/install/index.php
index fffc7c2..70db8ce 100644
--- a/install/index.php
+++ b/install/index.php
@@ -426,6 +426,48 @@ if(isset($_POST['datenbank_anlegen'])){
 			return 0;
 		}
 	}
+
+/*
+* taken from  nieprzeklinaj at gmail dot com
+* http://php.net/manual/de/mysqli-stmt.bind-result.php
+*/
+function db_fetch($result)
+{   
+    $array = array();
+   
+    if($result instanceof mysqli_stmt)
+    {   
+        $result->store_result();
+    
+        $variables = array();
+        $data = array();
+        $meta = $result->result_metadata();
+    
+        while($field = $meta->fetch_field())
+            $variables[] = &$data[$field->name]; // pass by reference
+    
+        call_user_func_array(array($result, 'bind_result'), $variables);
+    
+        $i=0;
+        while($result->fetch())
+        {
+            $array[$i] = array();
+            foreach($data as $k=>$v)
+                $array[$i][$k] = $v;
+            $i++;
+
+            // don\'t know why, but when I tried $array[] = $data, I got the same one result in all rows
+        }
+    }
+    elseif($result instanceof mysqli_result)
+    {
+        while($row = $result->fetch_assoc())
+            $array[] = $row;
+    }
+
+    return $array;
+}
+
 	
 	function pw_erstellen($pw){
 		global $pw_zusatz;
diff --git a/lib/datenbank.inc.php b/lib/datenbank.inc.php
index c671594..e015e84 100644
--- a/lib/datenbank.inc.php
+++ b/lib/datenbank.inc.php
@@ -1,19 +1,19 @@
 	<?php
 	$db_host = "localhost";
 	// Mysql User
-	$db_user = "vms_suee2";
+	$db_user = "";
 	// Mysql PW
-	$db_pass = "lTxyJyZtmSQvaV6M";
+	$db_pass = "";
 	// Datenbank
-	$db_base = "vms_suee2";
+	$db_base = "";
 	//Datenbank Prefix
 	$db_prefix = "vms";
 	
 	//Passwort zusatz
-	$pw_zusatz = 'fg65en';
+	$pw_zusatz = '';
 	
 	// Verschlüsselungspasswort
-	$ver_schluessel = 'libh5476H6G4v0TB';
+	$ver_schluessel = '';
 	
 	//Datenbankverbindung herstellen
 	$sql_open = @mysqli_connect($db_host, $db_user, $db_pass, $db_base) or die('Verbindung zum Mysql Server fehlgeschlagen! <br>Tipp: <a href="http://www.vms-tutorial.de/wiki//Lib/Functions">http://www.vms-tutorial.de/wiki//Lib/Functions</a>');
@@ -50,6 +50,47 @@
 		}
 		
 	}
+
+/*
+* taken from  nieprzeklinaj at gmail dot com
+* http://php.net/manual/de/mysqli-stmt.bind-result.php
+*/
+function db_fetch($result)
+{   
+    $array = array();
+   
+    if($result instanceof mysqli_stmt)
+    {
+        $result->store_result();
+       
+        $variables = array();
+        $data = array();
+        $meta = $result->result_metadata();
+       
+        while($field = $meta->fetch_field())
+            $variables[] = &$data[$field->name]; // pass by reference
+       
+        call_user_func_array(array($result, 'bind_result'), $variables);
+       
+        $i=0;
+        while($result->fetch())
+        {
+            $array[$i] = array();
+            foreach($data as $k=>$v)
+                $array[$i][$k] = $v;
+            $i++;
+           
+            // don't know why, but when I tried $array[] = $data, I got the same one result in all rows
+        }
+    }
+    elseif($result instanceof mysqli_result)
+    {
+        while($row = $result->fetch_assoc())
+            $array[] = $row;
+    }
+   
+    return $array;
+}
 	
 	function pw_erstellen($pw){
 		global $pw_zusatz;
-- 
GitLab