Commit 16e3be0d authored by Guinness's avatar Guinness Committed by Okhin

Allow to modify or delete an address

parent 590963df
...@@ -757,21 +757,44 @@ class Admin extends Controller ...@@ -757,21 +757,44 @@ class Admin extends Controller
public function adresse($f3, $args) { public function adresse($f3, $args) {
$id = ''; $id = '';
$form_name = '';
$user_id = ''; $user_id = '';
$db = $f3->get('DB'); $db = $f3->get('DB');
if ($f3->get('VERB') == 'POST') { if ($f3->get('VERB') == 'POST') {
$id = \Utils::asl($f3->get('POST.id')); $id = \Utils::asl($f3->get('POST.id'));
$form_name = $f3->get('POST.action');
} }
$result = $db->query("SELECT user_id FROM adresses WHERE id = $id"); if ($form_name == 'delete') {
$result = $result->fetch(\PDO::FETCH_ASSOC); $result = $db->query("SELECT user_id FROM adresses WHERE id = $id");
$user_id = \Utils::asl($result["user_id"]); $result = $result->fetch(\PDO::FETCH_ASSOC);
$db->query("UPDATE dons SET adresse_id = NULL $user_id = \Utils::asl($result["user_id"]);
WHERE user_id = $user_id"); $db->query("UPDATE dons SET adresse_id = NULL
$db->query("UPDATE contreparties SET adresse_id = NULL WHERE user_id = $user_id");
WHERE user_id = $user_id"); $db->query("UPDATE contreparties SET adresse_id = NULL
$db->query("DELETE FROM adresses WHERE user_id = $user_id");
WHERE id = $id" $db->query("DELETE FROM adresses
WHERE id = $id"
); );
} else {
$result = $db->query("SELECT user_id FROM adresses WHERE id = $id");
$result = $result->fetch(\PDO::FETCH_ASSOC);
$user_id = \Utils::asl($result["user_id"]);
$nom = \Utils::asl($f3->get('POST.nom'));
$adresse = \Utils::asl($f3->get('POST.adresse'));
$adresse2 = \Utils::asl($f3->get('POST.adresse2'));
$codepostal = \Utils::asl($f3->get('POST.codepostal'));
$ville = \Utils::asl($f3->get('POST.ville'));
$pays = \Utils::asl($f3->get('POST.pays'));
$db->query("UPDATE adresses SET
nom = '".$nom."',
adresse = '".$adresse."',
adresse2 = '".$adresse2."',
codepostal = '".$codepostal."',
ville = '".$ville."',
pays = '".$pays."'
WHERE id = $id"
);
}
$f3->reroute("/admin/users/$user_id"); $f3->reroute("/admin/users/$user_id");
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment