-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
194 lines (182 loc) · 8.09 KB
/
user.php
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
require_once("config.php");
require_once("functions.php");
if ($_SERVER['REQUEST_METHOD'] == "GET") {
if (isGetSet("user") && isGetSet("objets")) {
$user = User::loadUserWithId(test_input($_GET['user']));
if (is_a($user, "User")) {
$objMan = new ObjectManager();
$result = $objMan->loadObjectsFromUser($user);
switch ($result) {
case 0: {
echo test_input(json($objMan));
}
break;
case 1:
echo "{}";
break;
case 2:
echo '{"Code" : "' . $CODE['CODE_19']['Code'] . '", "Message" : "' . $CODE['CODE_19']['Message'] . '"}';
break;
}
} else {
echo '{"Code" : "' . $CODE['CODE_2']['Code'] . '", "Message" : "' . $CODE['CODE_2']['Message'] . '"}';
}
} else if (isGetSet("user")) {
$user = User::loadUserWithId(test_input($_GET['user']));
if (is_a($user, "User")) {
echo test_input(json($user));
} else {
echo '{"Code" : "' . $CODE['CODE_2']['Code'] . '", "Message" : "' . $CODE['CODE_2']['Message'] . '"}';
}
}
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isGetSet("action") && $_GET['action'] == "update") {
if (isPostSet('iduser')) {
$user = User::loadUserWithId(test_input($_POST['iduser']));
if (is_a($user, "User")) {
$nbModif = 0;
if (isPostSet('name')) {
$user->setName(test_input($_POST['name']));
$nbModif++;
}
if (isPostSet('firstname')) {
$user->setFName(test_input($_POST['firstname']));
$nbModif++;
}
if (isPostSet('codepostal')) {
$user->setCodePostal(test_input($_POST['codepostal']));
$nbModif++;
}
if (isPostSet('email')) {
$user->setEmail(test_input($_POST['email']));
$nbModif++;
}
if (isPostSet('city')) {
$user->setCity(test_input($_POST['city']));
$nbModif++;
}
if (isPostSet('alloweddrop')) {
$baisse = test_input($_POST['alloweddrop']);
$baisse = $baisse == 'true' || $baisse == 1;
$user->setDrop($baisse);
$nbModif++;
}
if (isPostSet('address')) {
$user->setAddress(test_input($_POST['address']));
$nbModif++;
}
if (isPostSet('phone')) {
$user->setPhone(test_input($_POST['phone']));
$nbModif++;
}
if (isPostSet('rang')) {
$user->setRank(test_input($_POST['rang']));
$nbModif++;
}
if ($nbModif > 0) {
if ($user->updateUser()) {
echo '{"Code" : "' . $CODE['CODE_0']['Code'] . '", "Message" : "' . $CODE['CODE_0']['Message'] . '"}';
} else {
echo '{"Code" : "' . $CODE['CODE_4']['Code'] . '", "Message" : "' . $CODE['CODE_4']['Message'] . '"}';
}
} else {
echo '{"Code" : "' . $CODE['CODE_17']['Code'] . '", "Message" : "' . $CODE['CODE_17']['Message'] . '"}';
}
} else {
echo '{"Code" : "' . $CODE['CODE_2']['Code'] . '", "Message" : "' . $CODE['CODE_2']['Message'] . '"}';
}
} else {
echo '{"Code" : "' . $CODE['CODE_1']['Code'] . '", "Message" : "' . $CODE['CODE_1']['Message'] . '"}';
}
} else if (isGetSet("action") && $_GET['action'] == "insert") {
//var_dump($_POST);
if (!isPostSet('name') || !isPostSet('firstname')) {
echo '{"Code" : "' . $CODE['CODE_3']['Code'] . '", "Message" : "' . $CODE['CODE_3']['Message'] . '"}';
} else {
$name = $fName = $cp = $email = $login = $mdp = $address = $ville = $telephone = $baisse = $rang = "";
if (isPostSet('name')) {
$name = test_input($_POST['name']);
}
if (isPostSet('firstname')) {
$fName = test_input($_POST['firstname']);
}
if (isPostSet('codepostal')) {
$cp = test_input($_POST['codepostal']);
}
if (isPostSet('email')) {
$email = test_input($_POST['email']);
}
if (isPostSet('login')) {
$login = test_input($_POST['login']);
} else {
$login = $name . $fName;
$test = User::checkUserName($login);
$cpt = $test;
$login2 = "";
while ($test != 0) {
$cpt++;
$login2 = $login . $cpt;
$test = User::checkUserName($login2);
}
if (!empty($login2))
$login .= $cpt;
}
if (isPostSet('password')) {
$mdp = test_input($_POST['password']);
} else {
$mdp = $name . $fName;
}
if (isPostSet('city')) {
$ville = test_input($_POST['city']);
}
if (isPostSet('alloweddrop')) {
$baisse = test_input($_POST['alloweddrop']);
$baisse = $baisse == 'true' || $baisse == 1;
}
if (isPostSet('address')) {
$address = test_input($_POST['address']);
}
if (isPostSet('phone')) {
$telephone = test_input($_POST['phone']);
}
if (isPostSet('rank')) {
$rang = test_input($_POST['rank']);
} else {
$rang = 1;
}
$user = User::createUser($name, $fName, $address, $cp, $ville, $telephone, $baisse, $rang, $email);
if ($user->insertIntoDb($login, $mdp)) {
$user = User::loadFromBd($login, $mdp);
$id = 0;
if (is_a($user, "User")) {
$id = $user->id();
}
echo '{"Code" : "' . $CODE['CODE_0']['Code'] . '", "Message" : "' . $CODE['CODE_0']['Message'] . '", "iduser" : "' . $id . '"}';
} else
echo '{"Code" : "' . $CODE['CODE_5']['Code'] . '", "Message" : "' . $CODE['CODE_5']['Message'] . '"}';
}
} else if (isGetSet("action") && $_GET['action'] == "updatepwd") {
if (isPostSet('iduser')) {
$user = User::loadUserWithId(test_input($_POST['iduser']));
if (is_a($user, "User")) {
if (isPostSet('password')) {
$user->setPassword(test_input($_POST['password']));
if ($user->updatePassword()) {
echo '{"Code" : "' . $CODE['CODE_0']['Code'] . '", "Message" : "' . $CODE['CODE_0']['Message'] . '"}';
} else {
echo '{"Code" : "' . $CODE['CODE_4']['Code'] . '", "Message" : "' . $CODE['CODE_4']['Message'] . '"}';
}
} else {
echo '{"Code" : "' . $CODE['CODE_6']['Code'] . '", "Message" : "' . $CODE['CODE_6']['Message'] . '"}';
}
} else {
echo '{"Code" : "' . $CODE['CODE_2']['Code'] . '", "Message" : "' . $CODE['CODE_2']['Message'] . '"}';
}
} else {
echo '{"Code" : "' . $CODE['CODE_1']['Code'] . '", "Message" : "' . $CODE['CODE_1']['Message'] . '"}';
}
}
} else {
echo '{"Code" : "' . $CODE['CODE_501']['Code'] . '", "Message" : "' . $CODE['CODE_501']['Message'] . '"}';
}