Commit bb599f4f authored by okhin's avatar okhin 🚴

Merging the change on prod done by @Mindiell

parent 33731eaf
Pipeline #2251 passed with stages
in 1 minute and 42 seconds
......@@ -86,8 +86,10 @@ class Admin extends Controller
$status = $f3->exists('POST.status') ? $f3->get('POST.status') : '';
$limit = $f3->exists('POST.limite') ? (int) $f3->get('POST.limite') : 50;
$page = $f3->exists('POST.page') ? (int) $f3->get('POST.page') : 1;
$date1 = $f3->exists('POST.date1') ? (string) $f3->get('POST.date1') . " 00:00:00" : '';
$date2 = $f3->exists('POST.date2') ? (string) $f3->get('POST.date2') . " 00:00:00" : date("Y-m-d H:i:s");
$results = $f3->get('container')['donation_finder']->adminSearch($text, $sum, $public, $status, $limit, $page);
$results = $f3->get('container')['donation_finder']->adminSearch($text, $sum, $public, $status, $date1, $date2, $limit, $page);
$f3->set('row_count', count($results));
$f3->set('texte', $text);
......@@ -96,6 +98,8 @@ class Admin extends Controller
$f3->set('page', $page);
$f3->set('public', $public);
$f3->set('status', $status);
$f3->set('date1', substr($date1, 0, 10));
$f3->set('date2', substr($date2, 0, 10));
$f3->set('data', $results);
$f3->set('piplome_url', PIPLOME_URL);
......@@ -924,23 +928,10 @@ class Admin extends Controller
public function banque($f3, $args)
{
$f3->set('class_cbs', 'on');
$f3->set('class_verif', 'off');
$f3->set('class_update', 'off');
$message = '';
$error = '';
$result = '';
if ($f3->get('VERB')=='POST') {
switch ($f3->get('POST.tab')) {
case 'verif':
$f3->set('class_cbs', 'off');
$f3->set('class_verif', 'on');
break;
case 'update':
$f3->set('class_cbs', 'off');
$f3->set('class_update', 'on');
break;
}
if ($_FILES['file']['tmp_name']=='') {
$message = "Merci de sélectionner un fichier.";
} else {
......@@ -1233,6 +1224,7 @@ class Admin extends Controller
// On ne s'intéresse qu'aux dons récurrents
if ($identifier!='') {
$total ++;
$email = '';
$time_struct = strptime($effect, "%d/%m/%Y %H:%M:%S");
$new_effect = strftime("%Y-%m-%d %H:%M:%S", mktime(
$time_struct['tm_hour']+1,
......@@ -1248,71 +1240,92 @@ class Admin extends Controller
JOIN identifiers
ON users.id = identifiers.user_id
AND identifiers.identifier='".$identifier. "'");
if ($result) {
if ($result->rowCount() == 0) {
// Identifier does not exist, we must create it. We have either a pseudo or an email.
$user_field = explode("_", $identifier)[1];
$user = 'asfhjk';
if (strpos($user_field, '@')) {
// identifier is an email
$user = $f3->get('container')['user_finder']->findByEmail($user_field);
} else {
// identifier is a pseudo
$user = $f3->get('container')['user_finder']->findByPseudo($user_field);
}
if ($user) {
$db->query("INSERT INTO identifiers(user_id, identifier) VALUES ('".$user['id']."', '".$identifier."')");
$email = $user['email'];
} else {
// No user, let's add to the errors
$sans_cumul[] = $user_field;
continue;
}
} else {
$email = $result->fetch(\PDO::FETCH_ASSOC);
$email = $email['email'];
// On stocke l'email pour comptabiliser les dons
if (array_key_exists($email, $emails)) {
$emails[$email] ++;
//echo $new_effect . ' - ' . $identifier.' : '.$email.' => '.$combien[0].'<br />';
} else {
$emails[$email] = 1;
}
// Récupération de l'id du bon abonnement
$result = $db->query("SELECT d.id AS id
FROM dons d
JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "'
AND d.status=101
AND d.id='".$transaction."' ");
if ($result) {
$cumul = $result->fetch(\PDO::FETCH_ASSOC);
$cumul = $cumul['id'];
if ($cumul!='') {
$result = $db->query("SELECT COUNT(1)
FROM dons d
JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "'
AND d.status=102
AND d.datec='".$new_effect."'
AND d.cumul=".$cumul."
");
if ($result) {
$combien = $result->fetch();
if ($combien[0]==0) {
$update ++;
// Don récurrent non comptabilisé, on l'ajoute
$user_id = $db->query("SELECT id FROM users WHERE email='$email'");
$user_id = $user_id->fetch(\PDO::FETCH_ASSOC);
$user_id = $user_id['id'];
$query = "INSERT INTO dons (status,
datec,
somme,
user_id,
cumul,
identifier)
VALUES (
102,
'".$new_effect."',
".$amount.",
'".$user_id."',
'".$cumul."',
'".$identifier."')";
if (!$testing) {
$db->query($query);
// On met alors à jour le cumul et le total de l'utilisateur concerné
$result = $db->query("UPDATE users
SET cumul=cumul+".$amount.",
total=total+".$amount."
WHERE id='".$user_id."'");
}
} else {
$comptabilise[] = $identifier;
}
if (array_key_exists($email, $emails)) {
$emails[$email] ++;
} else {
$emails[$email] = 1;
}
// Récupération de l'id du bon abonnement
$result = $db->query("SELECT d.id AS id
FROM dons d
JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "'
AND d.status=101
AND d.id='".$transaction."' ");
print_r($result);
if ($result->rowCount() > 0) {
$cumul = $result->fetch(\PDO::FETCH_ASSOC);
$cumul = $result['id'];
if ($cumul!='') {
$result = $db->query("SELECT COUNT(1)
FROM dons d
JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "'
AND d.status=102
AND d.datec='".$new_effect."'
AND d.cumul=".$cumul."
");
if ($result) {
$combien = $result->fetch();
if ($combien[0]==0) {
$update ++;
// Don récurrent non comptabilisé, on l'ajoute
$user_id = $db->query("SELECT id FROM users WHERE email='$email'");
$user_id = $user_id->fetch(\PDO::FETCH_ASSOC);
$user_id = $user_id['id'];
$query = "INSERT INTO dons (status,
datec,
somme,
user_id,
cumul,
identifier)
VALUES (
102,
'".$new_effect."',
".$amount.",
'".$user_id."',
'".$cumul."',
'".$identifier."')";
if (!$testing) {
$db->query($query);
// On met alors à jour le cumul et le total de l'utilisateur concerné
$result = $db->query("UPDATE users
SET cumul=cumul+".$amount.",
total=total+".$amount."
WHERE id='".$user_id."'");
}
} else {
$comptabilise[] = $identifier;
}
} else {
$sans_cumul[] = $email;
}
} else {
$sans_cumul[] = $email;
}
}
}
......
......@@ -108,7 +108,7 @@ class Campaign extends Controller
$user = $f3->get('container')['user_finder']->findByEmail(\Utils::asl($email));
if (len($user) > 0) {
if (count($user) > 0) {
// We have an existing user, we should try to login with the provided password
// or 403.
$mapper = new \DB\SQL\Mapper($f3->get('DB'), 'users');
......@@ -117,6 +117,9 @@ class Campaign extends Controller
if (!$login) {
$f3->error(403);
}
$email = $user['email'];
$user_id = $user['id'];
$cumul_id = $user['cumul'];
} else {
// The user does not exist, so let's create it
$result = $db->query("INSERT INTO users (pseudo, email, hash)
......
......@@ -5,15 +5,7 @@
<check if="{{@error}}"><p class="error">{{@error | raw}}</p></check>
<check if="{{@message}}"><p class="message">{{@message | raw}}</p></check>
<section>
<ul>
<li class="clickable" onclick="show_hide('cbs', ['verif', 'update']);">Dates d'expiration des CB</li>
<li class="clickable" onclick="show_hide('verif', ['cbs', 'update']);">Vérification des dons</li>
<li class="clickable" onclick="show_hide('update', ['verif', 'cbs']);">Mise à jour des dons</li>
</ul>
</section>
<section id="cbs" class="{{@class_cbs}}">
<section id="cbs">
<h3 >Mise à jour des dates d'expiration des CB</h3>
<form enctype="multipart/form-data" name="f" method="POST" action="{{ 'banque' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
......@@ -24,7 +16,7 @@
</form>
</section>
<section id="verif" class="{{@class_verif}}">
<section id="verif">
<h3>Vérification des dons</h3>
<form enctype="multipart/form-data" name="f" method="POST" action="{{ 'banque' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
......@@ -35,7 +27,7 @@
</form>
</section>
<section id="update" class="{{@class_update}}">
<section id="update">
<h3>Mise à jour des dons</h3>
<form enctype="multipart/form-data" name="f" method="POST" action="{{ 'banque' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
......
<include href="backend/header.html" />
<include href="backend/toolbar.html" />
<include href="{{ @block_content }}" />
<!-- <include href="backend/footer.html" /> <!-- No need for scripts right now -->
<!-- <include href="backend/footer.html" /> -->
......@@ -31,8 +31,15 @@
<option value="4,101" <check if="{{ @status=='4,101' }}">selected</check> >Récurrent validé</option>
</select>
<label for="date1">Depuis le</label>
<input type="date" id="date1" name="date1" value="{{ @date1 }}" />
<label for="date2">Jusqu'au</label>
<input type="date" id="date2" name="date2" value="{{ @date2 }}" />
<label for="limite">Limite</label>
<input type="text" id="limite" name="limite" size="3" value="{{ @limite }}" />
<label for="page">Page</label>
<input type="text" id="page" name="page" size="3" value="{{ @page }}" />
......
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