-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrairie.php
More file actions
174 lines (146 loc) · 4.63 KB
/
librairie.php
File metadata and controls
174 lines (146 loc) · 4.63 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
function userID(){
$userBDD = file_get_contents("./Datasets/User.txt");
return explode(';', $userBDD)[0];
}
function accountInfoConstructor(){
$existing = getAccountsFromUser();
sort($existing);
$accountID = 0;
foreach($existing as $tested){
if ($tested[1] == $accountID){
$accountID ++;
} else {
break;
}
}
return userID() . ";" . $accountID . ";" . $_POST["nom"] . ";" . $_POST["type"] . ";" . $_POST["solde"] . ";" . $_POST["devise"] . ";" . $_POST["budget"];
}
function validform() {
if (sizeof(getAccountsFromUser()) >= 10) {
echo "<div class='validationform'><p>Vous ne pouvez pas créer plus de 10 compte</p></div>";
}
else {
fileAppendLine('Account', accountInfoConstructor());
echo '<div class="validationform"><p>Votre compte ' . $_POST["type"] . ' "' . $_POST["nom"] . '" a bien été créé</p></div>';
}
}
function VerificationForm(){
$_POST["solde"] = intval($_POST["solde"]);
$_POST["budget"] = intval($_POST["budget"]);
$formValide = is_int($_POST["solde"]) && is_int($_POST["budget"]);
if ($formValide){
validForm();
}
}
function getFileContent( $fileName ) {
$fileString = file_get_contents( "./Datasets/$fileName.txt" );
$fileArray = explode( "\n", $fileString );
$data = [];
foreach( $fileArray as $value ):
// Leave the current iteration if value is empty
if( strlen( $value ) == 0 ) continue;
// Push data inside array
array_push( $data, explode( ';', $value ) );
endforeach;
return $data;
}
function getAccountsFromUser(){
$AccountsBDD = getFileContent('Account');
$Accounts = [];
foreach($AccountsBDD as $value ){
if( $value[0] == userID() ){
array_push($Accounts, $value);
}
}
return $Accounts;
}
function getOpeFromAccount($Account){
$OpeBDD = getFileContent('Operation');
$Opes = [];
foreach($Opes as $value ){
if( $value[0] == userID() && $value[1] == $Account){
array_push($Opes, $value);
}
}
return $Opes;
}
function fileAppendLine($file, $content){
file_put_contents("./Datasets/$file.txt", "$content\n", FILE_APPEND);
}
function deleteAccount($userID){
if (file_get_contents('./Datasets/User.txt') != ""){
$file = file("./Datasets/User.txt");
$file = array_diff($file, [$userID]);
file_put_contents("./Datasets/User.txt", $file);
}
}
function creationTable($titre, $listTitres, $listContent, $cible)
{
echo "<table class='container creation'>
<tr>
<CAPTION class='title'>$titre</CAPTION>";
foreach ($listTitres as $titre) {
echo "<th>$titre</th>";
}
echo "</tr>";
foreach ($listContent as $subject) {
echo "<tr>";
foreach ($subject as $info) {
echo "<td>$info</td>";
}
echo "<td><a href='$cible'>+</a></td></tr>";
}
echo '</table>';
}
function list_accounts(){
$titres = array('Nom', 'Type', 'Budget', 'Solde', 'Devise');
$unorganized = getAccountsFromUser();
$content = [];
foreach ($unorganized as $in){
$organized = array($in[2], $in[3], $in[6], $in[4], $in[5]);
array_push($content, $organized);
}
$cible = './compte.php';
creationTable('Mes Comptes', $titres, $content, $cible);
}
function list_operations($t){
$titres = array('Nom', 'Type', 'Budget', 'Solde', 'Devise');
$unorganized = getAccountsFromUser();
$content = [];
foreach ($unorganized as $in){
$organized = array($in[2], $in[3], $in[6], $in[4], $in[5]);
array_push($content, $organized);
}
$cible = './compte.php';
creationTable('Mes Comptes', $titres, $content, $cible);
}
/*function list_operations($Account){
$titres = array('Nom', 'Catégorie', 'Montant', 'Date');
$unorganized = getOpeFromAccount($Account[1]);
$content = [];
foreach ($unorganized as $in){
$category = opeType($in[3]);
$organized = array($in[4], $category[1], $category[0] . $in[5], $in[6]);
array_push($content, $organized);
}
$cible = './operation.php';
creationTable($Account[2], $titres, $content, $cible);
}*/
function opeType($typeID){
$typesBDD = getFileContent('Category');
$type = array(' ', 'Inconnu');
foreach ($typesBDD as $value){
if ($typeID == $value[0]){
$type[1] = $value[1];
switch ($value[2]) {
case 'credit':
$type[0] = '+';
case 'debit':
$type[0] = '-';
}
}
}
return $type;
}
?>