Notifies admin when an account has been modified (Closes #1182).
authorStéphane Jacob <sj@m4x.org>
Fri, 16 Jul 2010 09:32:41 +0000 (11:32 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 16 Jul 2010 09:32:41 +0000 (11:32 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/admin.php
templates/admin/useredit.mail.tpl

index 3c0cb27..5f3ba19 100644 (file)
@@ -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();
         }
         // }}}
 
index e576392..ad35662 100644 (file)
 {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: *}