From: Stéphane Jacob Date: Fri, 16 Jul 2010 09:32:41 +0000 (+0200) Subject: Notifies admin when an account has been modified (Closes #1182). X-Git-Tag: xorg/1.0.1~343 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=01f78cbb9740f7278fb0eee65d2758cb39fc85f7;p=platal.git Notifies admin when an account has been modified (Closes #1182). Signed-off-by: Stéphane Jacob --- diff --git a/modules/admin.php b/modules/admin.php index 3c0cb27..5f3ba19 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -462,17 +462,43 @@ class AdminModule extends PLModule } } if (!empty($to_update)) { - // TODO: fetch the initial values of the fields, and eventually send - // a summary of the changes to an admin. + $res = XDB::query('SELECT * + FROM accounts + WHERE uid = {?}', $user->id()); + $oldValues = $res->fetchAllAssoc(); + $oldValues = $oldValues[0]; + $set = array(); + $diff = array(); foreach ($to_update as $k => $value) { - $set[] = XDB::format($k . ' = {?}', $value); + $value = XDB::format('{?}', $value); + $set[] = $k . ' = ' . $value; + $diff[$k] = array($oldValues[$k], trim($value, "'")); + unset($oldValues[$k]); } XDB::execute('UPDATE accounts SET ' . implode(', ', $set) . ' WHERE uid = ' . XDB::format('{?}', $user->id())); $page->trigSuccess('Données du compte mise à jour avec succès'); $user = User::getWithUID($user->id()); + + /* Formats the $diff and send it to the site administrators. The rules are the folowing: + * -formats: password, token, weak_password + */ + foreach (array('password', 'token', 'weak_password') as $key) { + if (isset($diff[$key])) { + $diff[$key] = array('old value', 'new value'); + } else { + $oldValues[$key] = 'old value'; + } + } + + $mail = new PlMailer('admin/useredit.mail.tpl'); + $mail->assign('admin', S::user()->hruid); + $mail->assign('hruid', $user->hruid); + $mail->assign('diff', $diff); + $mail->assign('oldValues', $oldValues); + $mail->send(); } // }}} diff --git a/templates/admin/useredit.mail.tpl b/templates/admin/useredit.mail.tpl index e576392..ad35662 100644 --- a/templates/admin/useredit.mail.tpl +++ b/templates/admin/useredit.mail.tpl @@ -26,24 +26,17 @@ {to addr=#to#} {subject text="INTERVENTION de $admin"} {elseif $mail_part eq 'wiki'} -{if $deletion} -L'utilisateur {$user} a été désinscrit de plat/al. -{else} -Le profil du camarade {$old.prenom} {$old.nom} ({$old.promo}) a été édité.\\ + +Le compte de l'utilisateur {$hruid} a été édité.\\ Les champs suivants ont été changés : -{foreach from=$old item=value key=field} -{if $value neq $new[$field]} -* '''{$field}''' : {$value} -> {$new[$field]} -{/if} +{foreach from=$diff item=values key=field} +* '''{$field}''' : {$values.0} -> {$values.1} {/foreach} Et ceux qui n'ont pas changé : -{foreach from=$old item=value key=field} -{if $value eq $new[$field]} +{foreach from=$oldValues item=value key=field} * '''{$field}''' : {$value} -{/if} {/foreach} {/if} -{/if} {* vim:set et sw=2 sts=2 sws=2: *}