Commit ff509ab6 authored by okhin's avatar okhin 🚴
Browse files

Merge branch 'preprod' into 'master'

Preprod

See merge request lqdn-interne/don!61
parents bb599f4f 0bd6723e
...@@ -82,7 +82,7 @@ cs-lint: ## Lint ...@@ -82,7 +82,7 @@ cs-lint: ## Lint
translations: locales/fr_FR/LC_MESSAGES/messages.mo locales/en_US/LC_MESSAGES/messages.mo ## Generate translations translations: locales/fr_FR/LC_MESSAGES/messages.mo locales/en_US/LC_MESSAGES/messages.mo ## Generate translations
messages.pot: app/*.php templates/*/*.html messages.pot: app/*.php app/view/*/*.html
[ -r $@ ] || touch $@ [ -r $@ ] || touch $@
xgettext --package-name=LQDNCampaign --package-version=2016.1 --force-po -o $@ --keyword=__ --keyword=_ --from-code=UTF-8 $^ xgettext --package-name=LQDNCampaign --package-version=2016.1 --force-po -o $@ --keyword=__ --keyword=_ --from-code=UTF-8 $^
......
...@@ -7,6 +7,7 @@ use LQDN\Command\AdminChangePasswordCommand; ...@@ -7,6 +7,7 @@ use LQDN\Command\AdminChangePasswordCommand;
use LQDN\Command\DonationValidateCommand; use LQDN\Command\DonationValidateCommand;
use LQDN\Command\DonationInvalidateCommand; use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand; use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationCreateCommand;
use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
class Admin extends Controller class Admin extends Controller
...@@ -68,15 +69,15 @@ class Admin extends Controller ...@@ -68,15 +69,15 @@ class Admin extends Controller
{ {
if ($f3->get('VERB')=='POST' && $f3->exists('POST.action')) { if ($f3->get('VERB')=='POST' && $f3->exists('POST.action')) {
switch ($f3->get('POST.action')) { switch ($f3->get('POST.action')) {
case 'valid': case 'valid':
$f3->get('container')['command_handler']->handle(new DonationValidateCommand($f3->get('POST.id'))); $f3->get('container')['command_handler']->handle(new DonationValidateCommand($f3->get('POST.id')));
break; break;
case 'invalid': case 'invalid':
$f3->get('container')['command_handler']->handle(new DonationInvalidateCommand($f3->get('POST.id'))); $f3->get('container')['command_handler']->handle(new DonationInvalidateCommand($f3->get('POST.id')));
break; break;
case 'pdf': case 'pdf':
$f3->get('container')['command_handler']->handle(new DonationResetPdfCommand($f3->get('POST.id'))); $f3->get('container')['command_handler']->handle(new DonationResetPdfCommand($f3->get('POST.id')));
break; break;
} }
} }
...@@ -143,7 +144,7 @@ class Admin extends Controller ...@@ -143,7 +144,7 @@ class Admin extends Controller
"UPDATE dons "UPDATE dons
SET status = $status SET status = $status
WHERE id = ".\Utils::asl($id) WHERE id = ".\Utils::asl($id)
); );
$db->query("UPDATE users $db->query("UPDATE users
SET total = $total, SET total = $total,
cumul = $cumul cumul = $cumul
...@@ -193,7 +194,7 @@ class Admin extends Controller ...@@ -193,7 +194,7 @@ class Admin extends Controller
"UPDATE dons "UPDATE dons
SET status = $status SET status = $status
WHERE id = ".\Utils::asl($id) WHERE id = ".\Utils::asl($id)
); );
$db->query("UPDATE users $db->query("UPDATE users
SET total = $total, SET total = $total,
cumul = $cumul cumul = $cumul
...@@ -241,8 +242,8 @@ class Admin extends Controller ...@@ -241,8 +242,8 @@ class Admin extends Controller
if ($id=='') { if ($id=='') {
// We need to check if there's already a user with this email // We need to check if there's already a user with this email
$result = $db->query("SELECT id $result = $db->query("SELECT id
FROM users FROM users
WHERE email='".\Utils::asl($email)."'"); WHERE email='".\Utils::asl($email)."'");
if ($result) { if ($result) {
// The user already exist, lets get the user_id // The user already exist, lets get the user_id
$user_id = $result->fetch(\PDO::FETCH_ASSOC); $user_id = $result->fetch(\PDO::FETCH_ASSOC);
...@@ -250,53 +251,53 @@ class Admin extends Controller ...@@ -250,53 +251,53 @@ class Admin extends Controller
} else { } else {
// Let's create the account first // Let's create the account first
$db->query("INSERT INTO users $db->query("INSERT INTO users
(email, (email,
pseudo, pseudo,
cumul, cumul,
total) total)
VALUES('".\Utils::asl($email)."', VALUES('".\Utils::asl($email)."',
'".\Utils::asl($pseudo)."', '".\Utils::asl($pseudo)."',
'".\Utils::asl($somme)."', '".\Utils::asl($somme)."',
'0')"); '0')");
$user_id = $db->lastInsertId(); $user_id = $db->lastInsertId();
} }
$db->query("INSERT INTO dons $db->query("INSERT INTO dons
(datec, (datec,
user_id, user_id,
somme, somme,
lang, lang,
abo, abo,
public, public,
status) status)
VALUES VALUES
(now(), (now(),
'".\Utils::asl($user_id)."', '".\Utils::asl($user_id)."',
'".\Utils::asl($somme)."', '".\Utils::asl($somme)."',
'".\Utils::asl($lang)."', '".\Utils::asl($lang)."',
'".\Utils::asl($abo)."', '".\Utils::asl($abo)."',
'".\Utils::asl($public)."', '".\Utils::asl($public)."',
1)"); 1)");
// Récupération de l'id pour passage en mode édition // Récupération de l'id pour passage en mode édition
$id = $db->lastInsertId(); $id = $db->lastInsertId();
} else { } else {
// We will get the ids associated to the gift first // We will get the ids associated to the gift first
$result = $db->query("SELECT adresse_id, $result = $db->query("SELECT adresse_id,
user_id user_id
FROM dons FROM dons
WHERE id = ".\Utils::asl($f3->get('POST.id'))); WHERE id = ".\Utils::asl($f3->get('POST.id')));
$result = $result->fetch(\PDO::FETCH_ASSOC); $result = $result->fetch(\PDO::FETCH_ASSOC);
// Let's update the adresse first or create the adress // Let's update the adresse first or create the adress
$db->query("UPDATE users $db->query("UPDATE users
SET email='".\Utils::asl($email)."', SET email='".\Utils::asl($email)."',
pseudo='".\Utils::asl($pseudo)."' pseudo='".\Utils::asl($pseudo)."'
WHERE id={$result['user_id']}"); WHERE id={$result['user_id']}");
$db->query("UPDATE dons $db->query("UPDATE dons
SET somme='".\Utils::asl($somme)."', SET somme='".\Utils::asl($somme)."',
lang='".\Utils::asl($lang)."', lang='".\Utils::asl($lang)."',
abo='".\Utils::asl($abo)."', abo='".\Utils::asl($abo)."',
public='".\Utils::asl($public)."', public='".\Utils::asl($public)."',
adresse_id='".$result['adresse_id']."' adresse_id='".$result['adresse_id']."'
WHERE id='".\Utils::asl($_POST['id'])."'"); WHERE id='".\Utils::asl($_POST['id'])."'");
} }
} }
} }
...@@ -304,17 +305,17 @@ class Admin extends Controller ...@@ -304,17 +305,17 @@ class Admin extends Controller
if ($id!='') { if ($id!='') {
// Récupération du don, de l'adresse et de l'utilisateur // Récupération du don, de l'adresse et de l'utilisateur
$result = $db->query("SELECT d.id AS id, $result = $db->query("SELECT d.id AS id,
u.email AS email, u.email AS email,
u.pseudo AS pseudo, u.pseudo AS pseudo,
d.somme AS somme, d.somme AS somme,
d.lang AS lang, d.lang AS lang,
d.abo AS abo, d.abo AS abo,
d.public AS public, d.public AS public,
d.adresse_id AS adresse_id, d.adresse_id AS adresse_id,
d.user_id AS user_id d.user_id AS user_id
FROM dons d FROM dons d
JOIN users u ON u.id = d.user_id JOIN users u ON u.id = d.user_id
WHERE d.id=".$id); WHERE d.id=".$id);
$don = $result->fetch(\PDO::FETCH_ASSOC); $don = $result->fetch(\PDO::FETCH_ASSOC);
} else { } else {
$don = array( $don = array(
...@@ -350,10 +351,10 @@ class Admin extends Controller ...@@ -350,10 +351,10 @@ class Admin extends Controller
} }
// Calcul des quantités // Calcul des quantités
$query = "SELECT quoi, $query = "SELECT quoi,
status, status,
COUNT(status) AS qte COUNT(status) AS qte
FROM contreparties FROM contreparties
GROUP BY quoi, status;"; GROUP BY quoi, status;";
$result = $db->query($query); $result = $db->query($query);
if ($result) { if ($result) {
foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
...@@ -366,10 +367,10 @@ class Admin extends Controller ...@@ -366,10 +367,10 @@ class Admin extends Controller
$f3->set('hoodie_t'.$i, 0); $f3->set('hoodie_t'.$i, 0);
} }
$query = "SELECT quoi, $query = "SELECT quoi,
taille, taille,
COUNT(taille) AS qte COUNT(taille) AS qte
FROM contreparties FROM contreparties
GROUP BY quoi, taille;"; GROUP BY quoi, taille;";
$result = $db->query($query); $result = $db->query($query);
if ($result) { if ($result) {
foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
...@@ -428,34 +429,34 @@ class Admin extends Controller ...@@ -428,34 +429,34 @@ class Admin extends Controller
} }
$query = "SELECT c.id, $query = "SELECT c.id,
c.datec as datec, c.datec as datec,
c.quoi as quoi, c.quoi as quoi,
c.taille as taille, c.taille as taille,
c.status as status, c.status as status,
c.user_id as user_id, c.user_id as user_id,
u.email as email, u.email as email,
u.pseudo as pseudo, u.pseudo as pseudo,
u.commentaire as commentaire, u.commentaire as commentaire,
a.nom as nom, a.nom as nom,
a.adresse as adresse, a.adresse as adresse,
a.adresse2 as adresse2, a.adresse2 as adresse2,
a.codepostal as codepostal, a.codepostal as codepostal,
a.ville as ville, a.ville as ville,
a.pays as pays a.pays as pays
FROM contreparties c FROM contreparties c
INNER JOIN users u ON c.user_id = u.id INNER JOIN users u ON c.user_id = u.id
INNER JOIN adresses a ON c.adresse_id = a.id INNER JOIN adresses a ON c.adresse_id = a.id
WHERE 1=1 "; WHERE 1=1 ";
if ($texte) { if ($texte) {
$query .= " AND (c.id like '%".$texte."%' $query .= " AND (c.id like '%".$texte."%'
OR u.pseudo like '%".$texte."%' OR u.pseudo like '%".$texte."%'
OR u.email like '%".$texte."%' OR u.email like '%".$texte."%'
OR a.nom like '%".$texte."%' OR a.nom like '%".$texte."%'
OR a.ville like '%".$texte."%' OR a.ville like '%".$texte."%'
OR a.pays like '%".$texte."%' OR a.pays like '%".$texte."%'
OR a.codepostal like '%".$texte."%' OR a.codepostal like '%".$texte."%'
OR a.adresse2 like '%".$texte."%' OR a.adresse2 like '%".$texte."%'
OR a.adresse like '%".$texte."%')"; OR a.adresse like '%".$texte."%')";
} }
switch ($quoi) { switch ($quoi) {
case 0: case 0:
...@@ -474,19 +475,19 @@ class Admin extends Controller ...@@ -474,19 +475,19 @@ class Admin extends Controller
break; break;
default: default:
$query .= " AND datec IN ( $query .= " AND datec IN (
SELECT datec SELECT datec
FROM contreparties FROM contreparties
WHERE status=1 WHERE status=1
GROUP BY user_id, datec GROUP BY user_id, datec
HAVING SUM( HAVING SUM(
CASE quoi CASE quoi
WHEN 'pibag' THEN 1 WHEN 'pibag' THEN 1
WHEN 'piplome' THEN 2 WHEN 'piplome' THEN 2
WHEN 'pishirt' THEN 4 WHEN 'pishirt' THEN 4
WHEN 'hoodie' THEN 8 WHEN 'hoodie' THEN 8
END END
)=$quoi) )=$quoi)
"; ";
} }
if ($status) { if ($status) {
$query .= " AND c.status IN (".\Utils::asl($status).") "; $query .= " AND c.status IN (".\Utils::asl($status).") ";
...@@ -501,11 +502,11 @@ class Admin extends Controller ...@@ -501,11 +502,11 @@ class Admin extends Controller
foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
if ($row['quoi']=='piplome') { if ($row['quoi']=='piplome') {
$pdf = $db->query("SELECT d.id AS id, $pdf = $db->query("SELECT d.id AS id,
a.nom AS pseudo, a.nom AS pseudo,
d.pdf AS pdf d.pdf AS pdf
FROM dons d FROM dons d
JOIN adresses a ON a.id = d.adresse_id JOIN adresses a ON a.id = d.adresse_id
WHERE d.id='".$row['taille']."'"); WHERE d.id='".$row['taille']."'");
if ($pdf) { if ($pdf) {
$pdf = $pdf->fetch(\PDO::FETCH_ASSOC); $pdf = $pdf->fetch(\PDO::FETCH_ASSOC);
} }
...@@ -635,38 +636,38 @@ class Admin extends Controller ...@@ -635,38 +636,38 @@ class Admin extends Controller
if ($id!='') { if ($id!='') {
// First, let's retrieve the adresse from the adresse_id if it exists // First, let's retrieve the adresse from the adresse_id if it exists
$result = $db->query("SELECT adresse_id $result = $db->query("SELECT adresse_id
FROM contreparties FROM contreparties
WHERE id = '".\Utils::asl($f3->get('POST.id'))."' WHERE id = '".\Utils::asl($f3->get('POST.id'))."'
AND adresse_id IS NOT NULL"); AND adresse_id IS NOT NULL");
$result = $result->fetch(\PDO::FETCH_ASSOC); $result = $result->fetch(\PDO::FETCH_ASSOC);
$adresse_id = $result['adresse_id']; $adresse_id = $result['adresse_id'];
if (!$adresse_id or $adresse_id == 0) { if (!$adresse_id or $adresse_id == 0) {
// We need to create an adresse_id // We need to create an adresse_id
$db->query("INSERT INTO adresses $db->query("INSERT INTO adresses
VALUES (nom='".\Utils::asl($nom)."', VALUES (nom='".\Utils::asl($nom)."',
adresse='".\Utils::asl($adresse)."', adresse='".\Utils::asl($adresse)."',
adresse2='".\Utils::asl($adresse2)."', adresse2='".\Utils::asl($adresse2)."',
codepostal='".\Utils::asl($codepostal)."', codepostal='".\Utils::asl($codepostal)."',
ville='".\Utils::asl($ville)."', ville='".\Utils::asl($ville)."',
pays='".\Utils::asl($pays)."')"); pays='".\Utils::asl($pays)."')");
$adresse_id = $db->lastInsertId(); $adresse_id = $db->lastInsertId();
} else { } else {
// Updating the adresses first // Updating the adresses first
$db->query("UPDATE adresses $db->query("UPDATE adresses
SET nom='".\Utils::asl($nom)."', SET nom='".\Utils::asl($nom)."',
adresse='".\Utils::asl($adresse)."', adresse='".\Utils::asl($adresse)."',
adresse2='".\Utils::asl($adresse2)."', adresse2='".\Utils::asl($adresse2)."',
codepostal='".\Utils::asl($codepostal)."', codepostal='".\Utils::asl($codepostal)."',
ville='".\Utils::asl($ville)."', ville='".\Utils::asl($ville)."',
pays='".\Utils::asl($pays)."' pays='".\Utils::asl($pays)."'
WHERE id = $adresse_id"); WHERE id = $adresse_id");
}; };
$db->query("UPDATE contreparties $db->query("UPDATE contreparties
SET quoi='".\Utils::asl($quoi)."', SET quoi='".\Utils::asl($quoi)."',
taille='".\Utils::asl($taille)."', taille='".\Utils::asl($taille)."',
status='".\Utils::asl($status)."' status='".\Utils::asl($status)."'
WHERE id='".\Utils::asl($_POST['id'])."'"); WHERE id='".\Utils::asl($_POST['id'])."'");
// We will update the comment // We will update the comment
$db->query("UPDATE users SET commentaire='".\Utils::asl($comment)."' WHERE id='".\Utils::asl($user_id)."'"); $db->query("UPDATE users SET commentaire='".\Utils::asl($comment)."' WHERE id='".\Utils::asl($user_id)."'");
} }
...@@ -693,13 +694,13 @@ class Admin extends Controller ...@@ -693,13 +694,13 @@ class Admin extends Controller
$pdfs = array(); $pdfs = array();
if ($contrepartie['quoi']=='piplome') { if ($contrepartie['quoi']=='piplome') {
$result = $db->query("SELECT d.id AS id, $result = $db->query("SELECT d.id AS id,
d.pdf AS pdf, d.pdf AS pdf,
a.nom AS nom a.nom AS nom
FROM dons d FROM dons d
INNER JOIN adresses a ON d.adresse_id = a.id INNER JOIN adresses a ON d.adresse_id = a.id
WHERE pdf<>'' WHERE pdf<>''
AND d.status IN (1,4,101) AND d.status IN (1,4,101)
AND d.user_id='".$contrepartie['user_id']."'"); AND d.user_id='".$contrepartie['user_id']."'");
if ($result) { if ($result) {
foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $pdf) { foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $pdf) {
$pdfs[] = $pdf; $pdfs[] = $pdf;
...@@ -857,7 +858,7 @@ class Admin extends Controller ...@@ -857,7 +858,7 @@ class Admin extends Controller
$query = "SELECT id, email, expiration, status FROM users WHERE identifier!='' AND identifier IS NOT NULL AND status != ''"; $query = "SELECT id, email, expiration, status FROM users WHERE identifier!='' AND identifier IS NOT NULL AND status != ''";
if ($texte!='') { if ($texte!='') {
$query .= " AND (email like '%".$texte."%' $query .= " AND (email like '%".$texte."%'
OR pseudo like '%".$texte."%')"; OR pseudo like '%".$texte."%')";
} }
if ($status!='') { if ($status!='') {
$query .= " AND status='".$status."'"; $query .= " AND status='".$status."'";
...@@ -1037,12 +1038,12 @@ class Admin extends Controller ...@@ -1037,12 +1038,12 @@ class Admin extends Controller
$db->query("UPDATE identifiers SET expiration='".$expire. "' WHERE identifier='".$identifier."'"); $db->query("UPDATE identifiers SET expiration='".$expire. "' WHERE identifier='".$identifier."'");
if ($expire_date<$today_date) { if ($expire_date<$today_date) {
$db->query("INSERT INTO dons SET $db->query("INSERT INTO dons SET
status = '103', status = '103',
datec = NOW(), datec = NOW(),
somme = 0, somme = 0,
user_id = '" .$user_id ."', user_id = '" .$user_id ."',
identifier = '" . $identifier ."', identifier = '" . $identifier ."',
cumul = 0;"); cumul = 0;");
} }
} }
} }
...@@ -1236,14 +1237,14 @@ class Admin extends Controller ...@@ -1236,14 +1237,14 @@ class Admin extends Controller
)); ));
// Pour un don récurrent, on recherche son équivalent qui peut ne pas exister // Pour un don récurrent, on recherche son équivalent qui peut ne pas exister
$result = $db->query("SELECT email $result = $db->query("SELECT email
FROM users FROM users
JOIN identifiers JOIN identifiers
ON users.id = identifiers.user_id ON users.id = identifiers.user_id
AND identifiers.identifier='".$identifier. "'"); AND identifiers.identifier='".$identifier. "'");
if ($result->rowCount() == 0) { if ($result->rowCount() == 0) {
// Identifier does not exist, we must create it. We have either a pseudo or an email. // Identifier does not exist, we must create it. We have either a pseudo or an email.
$user_field = explode("_", $identifier)[1]; $user_field = explode("_", $identifier)[1];
$user = 'asfhjk'; $user = '';
if (strpos($user_field, '@')) { if (strpos($user_field, '@')) {
// identifier is an email // identifier is an email
...@@ -1271,35 +1272,50 @@ class Admin extends Controller ...@@ -1271,35 +1272,50 @@ class Admin extends Controller
} else { } else {
$emails[$email] = 1; $emails[$email] = 1;
} }
// On a besoin de l'utilisateur
$user = $f3->get('container')['user_finder']->findByEmail($email);
// Récupération de l'id du bon abonnement // Récupération de l'id du bon abonnement
$result = $db->query("SELECT d.id AS id $stmt = $db->query("SELECT d.id AS id
FROM dons d FROM dons d
JOIN users u ON u.id = d.user_id JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "' WHERE u.email='".$email."'
AND d.status=101 AND d.status=101
AND d.id='".$transaction."' "); AND d.id=".$transaction);
print_r($result); $result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result->rowCount() > 0) { if (!$result) {
// don non trouvé en statut 101. On le crée (la banque à raison)
// statut = cumul
$f3->get('container')['command_handler']
->handle(new DonationCreateCommand(
$user['id'],
101,
$new_effect,
$amount,
0,
0
));
// Et on le récupère
$cumul = $db->lastInsertId();
$don = $f3->get('container')['donation_finder']->findById($cumul);
} else {
$cumul = $result->fetch(\PDO::FETCH_ASSOC); $cumul = $result->fetch(\PDO::FETCH_ASSOC);
$cumul = $result['id']; $cumul = $result['id'];
if ($cumul!='') { }
$result = $db->query("SELECT COUNT(1) // On regarde si le don n'as pas déjà été ajouté (en vérifiant la datec)
FROM dons d $result = $db->query("SELECT COUNT(1)
JOIN users u ON u.id = d.user_id FROM dons d
WHERE u.email='".$email. "' JOIN users u ON u.id = d.user_id
AND d.status=102 WHERE u.email='".$email. "'
AND d.datec='".$new_effect."' AND d.status=102
AND d.cumul=".$cumul." AND d.datec='".$new_effect."'
"); AND d.cumul=".$cumul."
if ($result) { ");
$combien = $result->fetch(); if ($result) {
if ($combien[0]==0) { $combien = $result->fetch();
$update ++; if ($combien[0]==0) {
// Don récurrent non comptabilisé, on l'ajoute $update ++;
$user_id = $db->query("SELECT id FROM users WHERE email='$email'"); // Don récurrent non comptabilisé, on l'ajoute
$user_id = $user_id->fetch(\PDO::FETCH_ASSOC);