Commit 5acaa592 authored by okhin's avatar okhin 🚴

Function merge is working

parent 4b6a8a0c
Pipeline #2550 failed with stages
in 96 minutes and 15 seconds
......@@ -881,6 +881,75 @@ class Admin extends Controller
$f3->reroute("/admin/users/$user_id");
}
public function user_merge($f3, $args)
{
$id = array_key_exists('id', $args) ? \Utils::asl($args['id']) : '';
$f3->set('id', $id);
if($f3->get('VERB') == 'GET') {
$merger = $f3->get('container')['user_finder']->findById($id);
$email_merged = \Utils::asl($f3->get('GET.merged'));
$user = $f3->get('container')['user_finder']->findById($id);
$merged = $f3->get('container')['user_finder']->findByEmail($email_merged);
// Now, we're going to list all pledges and counterparts of merged user
// to display them to the admin.
$counterparts = $f3->get('container')['counterpart_finder']->findByUserId($merged['id']);
$donations = $f3->get('container')['donation_finder']->findByUserId($merged['id']);
// Augment the context
$f3->set('merger', $merger);
$f3->set('merged', $merged);
$f3->set('total', (int)$merged['total'] + (int)$merger['total']);
$f3->set('cumul', (int)$merged['cumul'] + (int)$merger['cumul']);
$f3->set('counterparts', $counterparts);
$f3->set('donations', $donations);
$f3->set('block_content', 'backend/fusion_user.html');
} else if($f3->get('VERB') == 'POST') {
$merger_id = \Utils::asl($f3->get('POST.merger_id'));
$merged_id = \Utils::asl($f3->get('POST.merged_id'));
// Retrieving the associated users
$merger = $f3->get('container')['user_finder']->findById($merger_id);
$merged = $f3->get('container')['user_finder']->findById($merged_id);
// Update total and cumul values
$f3->get('container')['command_handler']->handle(new UserUpdateByAdminCommand($merger_id,
$merger['pseudo'],
$merger['email'],
$merger['commentaire'] + $merged['commentaire'],
(int) $merger['total'] + (int) $merged['total'],
(int) $merger['cumul'] + (int) $merged['cumul']));
$db = $f3->get('DB');
// Now, let's change all counterparts of merged
$db->query("UPDATE contreparties
SET user_id = '" . $merger_id ."'
WHERE user_id = '" . $merged_id ."'");
// The donations
$db->query("UPDATE dons
SET user_id = '" . $merger_id ."'
WHERE user_id = '" . $merged_id ."'");
// The identifiers
$db->query("UPDATE identifiers
SET user_id = '" . $merger_id . "'
WHERE user_id = '" . $merged_id . "'");
// The adresses
$db->query("UPDATE adresses
SET user_id = '" . $merger_id . "'
WHERE user_id = '" . $merged_id . "'");
// Remove the merged user
$db->query("DELETE FROM users WHERE id = '" . $merged_id . "'");
// Reroute to the merger
$f3->reroute('/admin/users/'.$merger_id);
};
}
public function user($f3, $args)
{
$id = array_key_exists('id', $args) ? \Utils::asl($args['id']) : '';
......
......@@ -45,6 +45,7 @@ GET|POST @users:/admin/users=Controller\Admin->users
POST @add_user:/admin/users/add=Controller\Admin->user
GET @user_info:/admin/users/@id=Controller\Admin->user
POST @modify_user:/admin/users/@id=Controller\Admin->user
GET|POST @fusion_user:/admin/users/fusion/@id=Controller\Admin->user_merge
POST @adresse:/admin/adresses=Controller\Admin->adresse
......
<section id="fusion">
<h2>Fusion de deux utilisateurs</h2>
<p> Fusionner l'utilisateur #{{ @merged.id }} avec l'utilisateur #{{ @merger.id }}</p>
<h3>Utilisateur {{ @merger.pseudo }} après fusion&nbsp;:</h3>
<dl>
<dt>Pseudo</dt>
<dd>{{ @merger.pseudo }}</dd>
<dt>Email</dt>
<dd>{{ @merger.email }}</dd>
<dt>Total</dt>
<dd>{{ @total }}</dd>
<dt>Cumul</dt>
<dd>{{ @cumul }}</dd>
</dl>
</section>
<section id="counterparts">
<h2>Les contreparties suivantes seront ajoutées à {{ @merger.pseudo }}</h2>
<table>
<thead>
<tr>
<th>Id</th>
<th>Id du parent</th>
<th>Date</th>
<th>Quoi</th>
<th>Taille/Piplome</th>
<th>Statut</th>
<th>Commentaire</th>
</tr>
</thead>
<tbody>
<repeat group="{{ @counterparts }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td>{{ @row.parent }}</td>
<td>{{ @row.datec }}</td>
<td>{{ @row.quoi }}</td>
<td>
<check if="{{ @row.quoi=='piplome' }}">
<true>
<a href="{{ @PIPLOME_URL }}{{ @row.pdf_url }}.pdf">{{ @row.pdf_url }}</a>
({{ @row.pdf_nom }})
</true>
<false>
<check if="{{ @row.quoi=='pibag' }}">
<true>
&nbsp;
</true>
<false>
{{ @atailles[@row.taille] }}
</false>
</check>
</false>
</check>
</td>
<td>
{{ @row.status }}
</td>
<td>
{{ @row.commentaire }}
</td>
</repeat>
</tr>
</tbody>
</table>
</section>
<section id="donations">
<h2>Les dons suivants seront ajoutés à {{ @merger.pseudo }}</h2>
<table>
<thead>
<th>Id</th>
<th>Date</th>
<th>Don</th>
<th>Adresse</th>
<th>PDF</th>
<th>Statut</th>
</thead>
<tbody>
<repeat group="{{ @donations }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td class="inline">{{ @row.datec }}</td>
<td>{{ @row.somme }}</td>
<td>{{ @row.pdf }}</td>
<td class="inline">{{ @row.status }}</td>
</tr>
</repeat>
</tbody>
</table>
</section>
<section id="form">
<h2>Fusionner les utilisateurs #{{ @merger.id }} et #{{ @merged.id }}&nbsp;</h2>
<form name="merge" method="POST" action="{{ 'fusion_user' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" id="merger_id" name="merger_id" value="{{ @merger.id }}" />
<input type="hidden" id="merged_id" name="merged_id" value="{{ @merged.id }}" />
<input type="submit" value="Fusionner les utilisateurs" />
</form>
</section>
<section id="ajout">
<check if="{{ @id>0 }}">
<true>
<h2>Modification d'un utilisateur</h2>
</true>
<false>
<h2>Ajout d'un utilisateur</h2>
</false>
</check>
<form name="f" method="POST" action="{{ 'modify_user' | alias }}">
<input type="hidden" name="id" id="id" value="{{ @id }}" />
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<check if="{{ @id>0 }}">
<true>
<h2>Modification d'un utilisateur</h2>
</true>
<false>
<h2>Ajout d'un utilisateur</h2>
</false>
</check>
<form name="f" method="POST" action="{{ 'modify_user' | alias }}">
<input type="hidden" name="id" id="id" value="{{ @id }}" />
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<label for="pseudo">Pseudo</label>
<input type="text" id="pseudo" name="pseudo" size="30" value="{{ @user.pseudo }}" />
<br />
<label for="pseudo">Pseudo</label>
<input type="text" id="pseudo" name="pseudo" size="30" value="{{ @user.pseudo }}" />
<br />
<label for="email">Email</label>
<input type="text" id="email" name="email" size="30" value="{{ @user.email }}" />
<br />
<label for="email">Email</label>
<input type="text" id="email" name="email" size="30" value="{{ @user.email }}" />
<br />
<label for="commentaire">Commentaire</label>
<textarea type="textarea" id="commentaire" name="commentaire" cols="30" rows="2">{{ @user.commentaire }}</textarea>
<br />
<label for="commentaire">Commentaire</label>
<textarea type="textarea" id="commentaire" name="commentaire" cols="30" rows="2">{{ @user.commentaire }}</textarea>
<br />
<check if="{{ @id>0 }}">
<true>
<label for="total">Total de dons cumulés</label>
<check if="{{ @id>0 }}">
<true>
<label for="total">Total de dons cumulés</label>
<input type="text" id="total" name="total" size="30" value="{{ @user.total }}" />
<br />
<br />
<label for="cumul">Cumul disponible pour les contreparties</label>
<label for="cumul">Cumul disponible pour les contreparties</label>
<input type="text" id="cumul" name="cumul" size="30" value="{{ @user.cumul }}" />
<br />
<br />
<input type="submit" value="Modifier cet utilisateur" />
</true>
<false>
<input type="submit" value="Ajouter cet utilisateur" />
</false>
</check>
</form>
<br />
</section>
<section id="fusion">
<h2>Fusionner cet utilisateur avec un autre</h2>
<form name="merge_{{@id}}" method="GET" action="{{ 'fusion_user' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" name="id" id="id" value="{{ @@user.id }}" />
<label for="merge_adresse">Adresse mail du compte à fusionner avec celui-ci</label>
<input type="text" id="merged" name="merged" size="30" />
<input type="submit" value="Modifier cet utilisateur" />
</true>
<false>
<input type="submit" value="Ajouter cet utilisateur" />
</false>
</check>
</form>
<br />
<input type="submit" value="Prévisualiser les changements avant fusion." />
</form>
</section>
<section id="adresses">
<h2>Adresse postale de cet utilisateur</h2>
<h2>Adresse postale de cet utilisateur</h2>
<check if="@@user.adresse">
<form name="addr_{{@id }}" method="POST" action="{{ 'adresse' |alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
......@@ -81,7 +93,7 @@
<input type="submit" value="Modifier l'adresse" />
</form>
<form name="del_addr_{{@id}}" method="POST" action="{{ 'adresse' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" name="id" id="id" value="{{ @@user.adresse.id }}" />
<input type="hidden" name="action" id="action" value="delete" />
<input type="submit" value="Effacer l'adresse" />
......@@ -89,168 +101,168 @@
</check>
</section>
<section id="contreparties">
<check if="{{ count(@user.contreparties) > 0}}">
<true>
<h2>Contreparties de cet utilisateur</h2>
<table cellspacing="0" cellpadding="0">
<theader>
<th>Id</th>
<th>Id du parent</th>
<th>Date</th>
<th>Quoi</th>
<th>Taille/Piplome</th>
<th>Adresse</th>
<th>Statut</th>
<th>Actions</th>
</theader>
<tbody>
<repeat group="{{ @user.contreparties }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td>{{ @row.parent }}</td>
<td>{{ @row.datec }}</td>
<td>{{ @row.quoi }}</td>
<td>
<check if="{{ @row.quoi=='piplome' }}">
<true>
<a href="{{ @PIPLOME_URL }}{{ @row.pdf_url }}.pdf">{{ @row.pdf_url }}</a>
({{ @row.pdf_nom }})
</true>
<false>
<check if="{{ @row.quoi=='pibag' }}">
<true>
&nbsp;
</true>
<false>
{{ @TAILLES[@row.taille] }}
</false>
</check>
</false>
</check>
</td>
<td>
<check if="{{ @row.adresse_id != null }}">
<true>
{{ @@user.adresses[@row.adresse_id].nom }}
</true>
<false>
-
</false>
</check>
</td>
<td class="inline">{{ @CT_STATUTS[@row.status] }}</td>
<td>
<a href="{{ 'edit_counterpart', 'id='.@row.id | alias }}">Editer</a>
<check if="{{ @row.status!=1 }}" >
-
<span class="lien" onclick="asked({{ @row.id }})">Demandé</span>
</check>
<check if="{{ @row.status!=2 }}" >
-
<span class="lien" onclick="sent({{ @row.id }})">Envoyé</span>
</check>
<check if="{{ @row.status!=3 }}" >
-
<span class="lien" onclick="npai({{ @row.id }})">NPAI</span>
</check>
<check if="{{ @row.status!=99 }}" >
-
<span class="lien" onclick="canceled({{ @row.id }})">Annulé</span>
</check>
<check if="{{ @row.quoi=='piplome' }}" >
-
<span class="lien" onclick="pdf({{ @row.pdf_id }})">PDF</span>
</check>
</td>
</tr>
</repeat>
</tbody>
</table>
</true>
<false>
<h2>Pas de contreparties associées à cet utilisateur</h2>
</false>
</check>
<check if="{{ count(@user.contreparties) > 0}}">
<true>
<h2>Contreparties de cet utilisateur</h2>
<table cellspacing="0" cellpadding="0">
<theader>
<th>Id</th>
<th>Id du parent</th>
<th>Date</th>
<th>Quoi</th>
<th>Taille/Piplome</th>
<th>Adresse</th>
<th>Statut</th>
<th>Actions</th>
</theader>
<tbody>
<repeat group="{{ @user.contreparties }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td>{{ @row.parent }}</td>
<td>{{ @row.datec }}</td>
<td>{{ @row.quoi }}</td>
<td>
<check if="{{ @row.quoi=='piplome' }}">
<true>
<a href="{{ @PIPLOME_URL }}{{ @row.pdf_url }}.pdf">{{ @row.pdf_url }}</a>
({{ @row.pdf_nom }})
</true>
<false>
<check if="{{ @row.quoi=='pibag' }}">
<true>
&nbsp;
</true>
<false>
{{ @TAILLES[@row.taille] }}
</false>
</check>
</false>
</check>
</td>
<td>
<check if="{{ @row.adresse_id != null }}">
<true>
{{ @@user.adresses[@row.adresse_id].nom }}
</true>
<false>
-
</false>
</check>
</td>
<td class="inline">{{ @CT_STATUTS[@row.status] }}</td>
<td>
<a href="{{ 'edit_counterpart', 'id='.@row.id | alias }}">Editer</a>
<check if="{{ @row.status!=1 }}" >
-
<span class="lien" onclick="asked({{ @row.id }})">Demandé</span>
</check>
<check if="{{ @row.status!=2 }}" >
-
<span class="lien" onclick="sent({{ @row.id }})">Envoyé</span>
</check>
<check if="{{ @row.status!=3 }}" >
-
<span class="lien" onclick="npai({{ @row.id }})">NPAI</span>
</check>
<check if="{{ @row.status!=99 }}" >
-
<span class="lien" onclick="canceled({{ @row.id }})">Annulé</span>
</check>
<check if="{{ @row.quoi=='piplome' }}" >
-
<span class="lien" onclick="pdf({{ @row.pdf_id }})">PDF</span>
</check>
</td>
</tr>
</repeat>
</tbody>
</table>
</true>
<false>
<h2>Pas de contreparties associées à cet utilisateur</h2>
</false>
</check>
</section>
<section id="dons">
<check if="{{ count(@user.dons) > 0 }}">
<true>
<h2>Dons associés à cet utilisateur</h2>
</true>
<table cellspacing="0" cellpadding="0">
<theader>
<th>ID</th>
<th>Date</th>
<th>Don</th>
<th>PDF</th>
<th>Statut</th>
<th>Actions</th>
</theader>
<tbody>
<repeat group="{{ @user.dons }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td class="inline">{{ @row.datec }}</td>
<td>{{ @row.somme }}</td>
<td>
<check if="{{ @row.pdf == '' }}">
<check if="{{ count(@user.dons) > 0 }}">
<true>
<h2>Dons associés à cet utilisateur</h2>
</true>
<table cellspacing="0" cellpadding="0">
<theader>
<th>ID</th>
<th>Date</th>
<th>Don</th>
<th>PDF</th>
<th>Statut</th>
<th>Actions</th>
</theader>
<tbody>
<repeat group="{{ @user.dons }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td class="inline">{{ @row.datec }}</td>
<td>{{ @row.somme }}</td>
<td>
<check if="{{ @row.pdf == '' }}">
<true>
<a href="/cron/piplome/{{ @row.id }}">PDF</a>
</true>
<false>
<a href="{{ PIPLOME_URL }}/{{ @row.pdf }}.pdf" target="_blank">PDF</a>
</false>
</check>
</td>
<td class="inline">{{ @DONS_STATUTS[@row.status] }}</td>
<td>
<a href="{{ 'edit_support', 'id='.@row.id | alias }}">Editer</a>
-
<check if="{{ @row.status==0 || @row.status==100 }}" >
<true>
<a href="/cron/piplome/{{ @row.id }}">PDF</a>
<a href="{{ 'validate_support', 'id='.@row.id | alias }}">Valider</a>
</true>
<false>
<a href="{{ PIPLOME_URL }}/{{ @row.pdf }}.pdf" target="_blank">PDF</a>
<a href="{{ 'invalidate_support', 'id='.@row.id | alias }}">Invalider</a>
-
</false>
</check>
</td>
<td class="inline">{{ @DONS_STATUTS[@row.status] }}</td>
<td>
<a href="{{ 'edit_support', 'id='.@row.id | alias }}">Editer</a>
-
<check if="{{ @row.status==0 || @row.status==100 }}" >
<true>
<a href="{{ 'validate_support', 'id='.@row.id | alias }}">Valider</a>
</true>
<false>
<a href="{{ 'invalidate_support', 'id='.@row.id | alias }}">Invalider</a>
-
</false>
</check>
</td>
</tr>
</repeat>
</tbody>
</table>
</true>
<false>
<h2>Pas de dons enregistrés pour cet utilisateur</h2>
</false>
</check>
</check>
</td>
</tr>
</repeat>
</tbody>
</table>
</true>
<false>
<h2>Pas de dons enregistrés pour cet utilisateur</h2>
</false>
</check>
</section>
<script type="text/javascript">
document.forms['f'].nom.focus();
document.forms['f'].nom.focus();
function select_span() {
if (document.forms['f'].quoi.value=='piplome') {
$('#quoi_pdf').show();
$('#quoi_taille').hide();
} else {
$('#quoi_pdf').hide();
$('#quoi_taille').show();
}
select_taille();
if (document.forms['f'].quoi.value=='piplome') {
$('#quoi_pdf').show();
$('#quoi_taille').hide();
} else {
$('#quoi_pdf').hide();
$('#quoi_taille').show();
}
select_taille();
}
function select_taille() {
if (document.forms['f'].quoi.value=='piplome') {
document.forms['f'].taille.value = document.forms['f'].url.value;
} else {
document.forms['f'].taille.value = document.forms['f'].size.value;
}
if (document.forms['f'].quoi.value=='piplome') {
document.forms['f'].taille.value = document.forms['f'].url.value;
} else {
document.forms['f'].taille.value = document.forms['f'].size.value;
}
}
window.onload = function() {
select_span();
select_taille();
select_span();
select_taille();
};
</script>
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