Displays an error message when attachment are too large in the X.net bulk email sender.
[platal.git] / modules / admin.php
index a9eddc6..da2bce9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -47,6 +47,7 @@ class AdminModule extends PLModule
             'admin/wiki'                   => $this->make_hook('wiki', AUTH_MDP, 'admin'),
             'admin/ipwatch'                => $this->make_hook('ipwatch', AUTH_MDP, 'admin'),
             'admin/icons'                  => $this->make_hook('icons', AUTH_MDP, 'admin'),
+            'admin/accounts'               => $this->make_hook('accounts', AUTH_MDP, 'admin'),
         );
     }
 
@@ -362,6 +363,7 @@ class AdminModule extends PLModule
         }
 
         // Loads the user identity using the environment.
+        $user = null;
         if ($login) {
             $user = User::get($login);
         } else if (Env::has('user_id')) {
@@ -551,6 +553,10 @@ class AdminModule extends PLModule
                     // however suits our needs.
                     if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') {
                         kill_sessions();
+
+                        // Also serve a reminder to the admin: disabling an account
+                        // does not deactivate email forwarding.
+                        $page->trigWarning("N'oubliez pas, le cas échéant, de désactiver les redirections et le compte GoogleApps de l'utilisateur.");
                     }
 
                     // Updates the user profile with the new values.
@@ -567,6 +573,12 @@ class AdminModule extends PLModule
                         user_reindex($user->id());
                         $new_fields = XDB::query($watch_query, $user->id())->fetchOneAssoc();
 
+                        // Redacts the password in the notification, to avoid transmitting
+                        // sensitive information by email.
+                        $new_fields['password'] = ($old_fields['password'] != $new_fields['password'] ? 'new' : 'old');
+                        $old_fields['password'] = 'old';
+
+                        // Notifies the admins of the profile update.
                         $mailer = new PlMailer("admin/useredit.mail.tpl");
                         $mailer->assign("admin", S::user()->login());
                         $mailer->assign("user", $user->login());
@@ -602,14 +614,6 @@ class AdminModule extends PLModule
                                 $account->set_password($pass_encrypted);
                             }
                         }
-
-                        // If the update did disable the user account, disables
-                        // the Google Apps account as well.
-                        if ($new_fields['perms'] == 'disabled' && $new_fields['perms'] != $old_fields['perms']) {
-                            require_once 'googleapps.inc.php';
-                            $account = new GoogleAppsAccount($user);
-                            $account->suspend();
-                        }
                     }
 
 
@@ -621,6 +625,7 @@ class AdminModule extends PLModule
 
                 // User re-registration.
                 case "u_kill":
+                    require_once('user.func.inc.php');
                     user_clear_all_subs($user->id());
                     $globals->updateNbIns();
                     $page->trigSuccess("'" . $user->id() . "' a été désinscrit !");
@@ -661,7 +666,11 @@ class AdminModule extends PLModule
                 "SELECT  alias
                    FROM  virtual
              INNER JOIN  virtual_redirect USING (vid)
-                  WHERE  type = 'user' AND redirect LIKE CONCAT({?}, '@%')", $user->id()));
+                  WHERE  type = 'user' AND (redirect = {?} OR redirect = {?})",
+                $user->forlifeEmail(),
+                // TODO: remove this über-ugly hack. The issue is that you need
+                // to remove all @m4x.org addresses in virtual_redirect first.
+                $user->login() . '@' . $globals->mail->domain2));
 
         $page->assign('aliases', XDB::iterator(
                 "SELECT  alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
@@ -685,16 +694,19 @@ class AdminModule extends PLModule
         $page->assign('bans', $bans);
     }
 
-    function getHruid($line, $key)
+    function getHruid($line, $key, $relation)
     {
-        var_dump($line);
-        if (!isset($line['nom']) || !isset($line['prenom']) || !isset($line['promo'])) {
-            return null;
+        $prenom = CSVImporter::getValue($line, 'prenom', $relation['prenom']);
+        $nom = CSVImporter::getValue($line, 'nom', $relation['nom']);
+        $promo = CSVImporter::getValue($line, 'promo', $relation['promo']);
+
+        if ($prenom != 'NULL' && $nom != 'NULL' && $promo != 'NULL') {
+            return make_forlife($prenom, $nom, $promo);
         }
-        return make_forlife($line['prenom'], $line['nom'], $line['promo']);
+        return null;
     }
 
-    function getMatricule($line, $key)
+    function getMatricule($line, $key, $relation)
     {
         $mat = $line['matricule'];
         $year = intval(substr($mat, 0, 3));
@@ -1239,6 +1251,19 @@ class AdminModule extends PLModule
         sort($icons);
         $page->assign('icons', $icons);
     }
+
+    function handler_accounts(&$page)
+    {
+        $page->changeTpl('admin/accounts.tpl');
+        $page->assign('disabled', XDB::iterator('SELECT  u.nom, u.prenom, u.promo, u.comment, u.hruid
+                                                   FROM  auth_user_md5 AS u
+                                                  WHERE  perms = \'disabled\'
+                                               ORDER BY  nom, prenom'));
+        $page->assign('admins', XDB::iterator('SELECT  u.nom, u.prenom, u.promo, u.hruid
+                                                 FROM  auth_user_md5 AS u
+                                                WHERE  perms = \'admin\'
+                                             ORDER BY  nom, prenom'));
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: