The following files exists in this folder. Click to view.
functions.php28 lines UTF-8 Unix (LF)
<?php
date_default_timezone_set('CET');
function add($filename, $account, $type, $amount){ //Lägger till en transaktion i transaktions arrayen i ett visste konto i användarens personliga fil.
$file_in = "accounts/".$filename.".json";
$userfile = json_decode(file_get_contents($file_in), true);
foreach ($userfile['accounts'] as &$a){
if($a['name'] == $account){
$transactions = $a['transactions'];
$balance = 0;
for($i = 0; $i <= (count($transactions)-1); $i+=3){
$balance += $transactions[$i+2];
}
if(($balance + $amount) < 0){
header('location: home.php');
exit;
}
array_push($transactions, $type, date("Y-m-d"), (int)$amount);
$a['transactions'] = $transactions;
}
}
$file = fopen($file_in, "w");
fwrite($file, json_encode($userfile, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
fclose($file);
}
?>