Commit 0bd91f82 authored by Guinness's avatar Guinness Committed by okhin

Validate, invalidate, PFD data in admin user page.

Refers #26

Modify the pledges, and acces the pdf.
parent 7cfc2e76
......@@ -109,6 +109,98 @@ class Admin extends Controller
$f3->set('block_content', 'backend/dons.html');
}
public function validate($f3, $args) {
$id = '';
$error = '';
$db = $f3->get('DB');
if ($f3->get('VERB')=='GET') {
if ($f3->exists('PARAMS.id')) {
$id = $f3->get('PARAMS.id');
} else {
$error= 'Pas d\'id associé à ce don';
}
if ($id != '') {
$result = $db->query("SELECT status,
somme,
adresse_id,
user_id
FROM dons
WHERE id = ".\Utils::asl($id));
$result = $result->fetch(\PDO::FETCH_ASSOC);
$user_amount = $db->query("SELECT total, cumul FROM users
WHERE id = ".\Utils::asl($result['user_id']));
$user_amount = $user_amount->fetch(\PDO::FETCH_ASSOC);
}
if ($result['status'] >= 100) {
$status = 101;
} else {
$status = 1;
}
$total = $user_amount['total'] + $result['somme'];
$cumul = $user_amount['total'] + $result['somme'];
}
if ($error != '') {
} else {
$db->query("UPDATE dons
SET status = $status
WHERE id = ".\Utils::asl($id)
);
$db->query("UPDATE users
SET total = $total,
cumul = $cumul
WHERE id = ".\Utils::asl($result['user_id']));
}
$f3->reroute("/admin/users/".$result['user_id']);
}
public function invalidate($f3, $args) {
$id = '';
$error = '';
$db = $f3->get('DB');
if ($f3->get('VERB')=='GET') {
if ($f3->exists('PARAMS.id')) {
$id = $f3->get('PARAMS.id');
} else {
$error= 'Pas d\'id associé à ce don';
}
if ($id != '') {
$result = $db->query("SELECT status,
somme,
adresse_id,
user_id
FROM dons
WHERE id = ".\Utils::asl($id));
$result = $result->fetch(\PDO::FETCH_ASSOC);
$user_amount = $db->query("SELECT total, cumul FROM users
WHERE id = ".\Utils::asl($result['user_id']));
$user_amount = $user_amount->fetch(\PDO::FETCH_ASSOC);
}
if ($result['status'] >= 100) {
$status = 100;
} else {
$status = 0;
}
$total = $user_amount['total'] - $result['somme'];
$cumul = $user_amount['total'] - $result['somme'];
if ($cumul < 0) {
$error = "Impossible d'invalider, une contrepartie a été demandée";
}
}
if ($error != '') {
} else {
$db->query("UPDATE dons
SET status = $status
WHERE id = ".\Utils::asl($id)
);
$db->query("UPDATE users
SET total = $total,
cumul = $cumul
WHERE id = ".\Utils::asl($result['user_id']));
}
$f3->reroute("/admin/users/".$result['user_id']);
}
public function support($f3, $args)
{
$id = '';
......
......@@ -27,6 +27,8 @@ GET|POST @admin:/admin=Controller\Admin->show
GET @add_support:/admin/support/add=Controller\Admin->support
GET @edit_support:/admin/support/edit/@id=Controller\Admin->support
POST @modify_support:/admin/support/edit=Controller\Admin->support
GET @invalidate_support:/admin/support/invalidate/@id=Controller\Admin->invalidate
GET @validate_support:/admin/support/validate/@id=Controller\Admin->validate
GET|POST @admin_accounts:/admin/accounts=Controller\Admin->accounts
......
......@@ -209,12 +209,17 @@
-
<check if="{{ @row.status==0 || @row.status==100 }}" >
<true>
<span class="lien" onclick="valid({{ @row.id }})">Valider</span>
<a href="{{ 'validate_support', 'id='.@row.id | alias }}">Valider</a>
</true>
<false>
<span class="lien" onclick="invalid({{ @row.id }})">Invalider</span>
<a href="{{ 'invalidate_support', 'id='.@row.id | alias }}">Invalider</a>
-
<span class="lien" onclick="pdf({{ @row.id }})">PDF</span>
<check if="{{ @row.pdf == '' }}">
<a href="/cron/piplome/{{ @row.id }}">PDF</a>
<false>
<a href="{{ PIPLOME_URL }}/{{ @row.pdf }}.pdf" target="_blank">PDF</a>
</false>
</check>
</false>
</check>
</td>
......
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