View sourcecode

The following files exists in this folder. Click to view.

functions.php

28 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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$typedate("Y-m-d"), (int)$amount);
            
$a['transactions'] = $transactions;
        }
    }

    
$file fopen($file_in"w");
    
fwrite($filejson_encode($userfileJSON_UNESCAPED_UNICODE JSON_PRETTY_PRINT));
    
fclose($file);
}

?>