<?php 

require( 'app/admin/vendor/autoload.php' );


$dotenv = \Dotenv\Dotenv::createMutable( "app/admin/" );
$dotenv->load();



$GLOBALS['db'] = new \App\Providers\DBMySql(
    $_ENV['DB_HOST'],
    $_ENV['DB_NAME'],
    $_ENV['DB_USER'],
    $_ENV['DB_PASS']
);




function checklogin()
{
	if ( !isset($_SESSION['user_id']) ) {
		$message = "Veuillez vous connectez.";
		return header("Location:/message.php?type=danger&message=$message");
	}
}



function getSolde($transactions)
{

    $solde = 0;

    foreach ($transactions as $trans) {
        if ( $trans->trans_type == 'plus' ) {
            $solde += $trans->trans_amount;
        } else {
            $solde -= $trans->trans_amount;
        }
    }
    
    return $solde;

}


