Merge remote branch 'origin/platal-1.0.0'
authorStéphane Jacob <sj@m4x.org>
Sat, 17 Jul 2010 17:01:00 +0000 (19:01 +0200)
committerStéphane Jacob <sj@m4x.org>
Sat, 17 Jul 2010 17:01:00 +0000 (19:01 +0200)
1  2 
modules/admin.php

diff --combined modules/admin.php
@@@ -413,33 -413,23 +413,32 @@@ class AdminModule extends PLModul
          if (Post::has('disable_weak_access')) {
              $to_update['weak_password'] = null;
          } else if (Post::has('update_account')) {
 -            if (Post::s('full_name') != $user->fullName()) {
 -                // XXX: Update profile if a profile is associated
 -                $to_update['full_name'] = Post::s('full_name');
 -            }
 -            if (Post::s('display_name') != $user->displayName()) {
 -                // XXX: Update profile if a profile is associated
 -                $to_update['display_name'] = Post::s('display_name');
 +            if (!$user->hasProfile()) {
 +                if (Post::s('full_name') != $user->fullName()) {
 +                    $to_update['full_name'] = Post::s('full_name');
 +                }
 +                if (Post::s('display_name') != $user->displayName()) {
 +                    $to_update['display_name'] = Post::s('display_name');
 +                }
 +                if (Post::s('directory_name') != $user->directoryName()) {
 +                    $to_update['directory_name'] = Post::s('directory_name');
 +                }
              }
              if (Post::s('sex') != ($user->isFemale() ? 'female' : 'male')) {
                  $to_update['sex'] = Post::s('sex');
 +                if ($user->hasProfile()) {
 +                    XDB::execute('UPDATE  profiles
 +                                     SET  sex = {?}
 +                                   WHERE  pid = {?}',
 +                                 Post::s('sex'), $user->profile()->id());
 +                }
              }
              if (!Post::blank('hashpass')) {
                  $to_update['password'] = Post::s('hashpass');
-                 // TODO: Propagate the password update to GoogleApps, when required. Eg:
-                 // $account = new GoogleAppsAccount($user);
-                 // if ($account->active() && $account->sync_password) {
-                 //     $account->set_password($pass_encrypted);
-                 // }
+                 $account = new GoogleAppsAccount($user);
+                 if ($account->active() && $account->sync_password) {
+                     $account->set_password(Post::s('hashpass'));
+                 }
              }
              if (!Post::blank('weak_password')) {
                  $to_update['weak_password'] = Post::s('weak_password');
              }
          }
          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();
          }
          // }}}
  
          }
  
          $page->assign('user', $user);
 +        $page->assign('hasProfile', $user->hasProfile());
  
          // Displays forum bans.
          $res = XDB::query("SELECT  write_perm, read_perm, comment